6
6
core "github.com/ipfs/go-ipfs/core"
7
7
plugin "github.com/ipfs/go-ipfs/plugin"
8
8
logging "github.com/ipfs/go-log"
9
+ eventbus "github.com/libp2p/go-eventbus"
10
+ event "github.com/libp2p/go-libp2p-core/event"
9
11
network "github.com/libp2p/go-libp2p-core/network"
10
12
)
11
13
@@ -50,6 +52,7 @@ func (*peerLogPlugin) Start(node *core.IpfsNode) error {
50
52
}
51
53
var notifee network.NotifyBundle
52
54
notifee .ConnectedF = func (net network.Network , conn network.Conn ) {
55
+ // TODO: Log transport, country, etc?
53
56
log .Infow ("connected" ,
54
57
"peer" , conn .RemotePeer ().Pretty (),
55
58
)
@@ -60,6 +63,38 @@ func (*peerLogPlugin) Start(node *core.IpfsNode) error {
60
63
)
61
64
}
62
65
node .PeerHost .Network ().Notify (& notifee )
66
+
67
+ sub , err := node .PeerHost .EventBus ().Subscribe (
68
+ new (event.EvtPeerIdentificationCompleted ),
69
+ eventbus .BufSize (1024 ),
70
+ )
71
+ if err != nil {
72
+ return fmt .Errorf ("failed to subscribe to identify notifications" )
73
+ }
74
+ go func () {
75
+ defer sub .Close ()
76
+ for e := range sub .Out () {
77
+ switch e := e .(type ) {
78
+ case event.EvtPeerIdentificationCompleted :
79
+ protocols , err := node .Peerstore .GetProtocols (e .Peer )
80
+ if err != nil {
81
+ log .Errorw ("failed to get protocols" , "error" , err )
82
+ continue
83
+ }
84
+ agent , err := node .Peerstore .Get (e .Peer , "AgentVersion" )
85
+ if err != nil {
86
+ log .Errorw ("failed to get protocols" , "error" , err )
87
+ continue
88
+ }
89
+ log .Infow (
90
+ "identified" ,
91
+ "peer" , e .Peer .Pretty (),
92
+ "agent" , agent ,
93
+ "protocols" , protocols ,
94
+ )
95
+ }
96
+ }
97
+ }()
63
98
return nil
64
99
}
65
100
0 commit comments