Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(peerlog): log protocols/versions #6972

Merged
merged 1 commit into from
Mar 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 35 additions & 0 deletions plugin/plugins/peerlog/peerlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
core "github.com/ipfs/go-ipfs/core"
plugin "github.com/ipfs/go-ipfs/plugin"
logging "github.com/ipfs/go-log"
eventbus "github.com/libp2p/go-eventbus"
event "github.com/libp2p/go-libp2p-core/event"
network "github.com/libp2p/go-libp2p-core/network"
)

Expand Down Expand Up @@ -50,6 +52,7 @@ func (*peerLogPlugin) Start(node *core.IpfsNode) error {
}
var notifee network.NotifyBundle
notifee.ConnectedF = func(net network.Network, conn network.Conn) {
// TODO: Log transport, country, etc?
log.Infow("connected",
"peer", conn.RemotePeer().Pretty(),
)
Expand All @@ -60,6 +63,38 @@ func (*peerLogPlugin) Start(node *core.IpfsNode) error {
)
}
node.PeerHost.Network().Notify(&notifee)

sub, err := node.PeerHost.EventBus().Subscribe(
new(event.EvtPeerIdentificationCompleted),
eventbus.BufSize(1024),
Stebalien marked this conversation as resolved.
Show resolved Hide resolved
)
if err != nil {
return fmt.Errorf("failed to subscribe to identify notifications")
}
go func() {
defer sub.Close()
for e := range sub.Out() {
switch e := e.(type) {
case event.EvtPeerIdentificationCompleted:
protocols, err := node.Peerstore.GetProtocols(e.Peer)
if err != nil {
log.Errorw("failed to get protocols", "error", err)
continue
}
agent, err := node.Peerstore.Get(e.Peer, "AgentVersion")
if err != nil {
log.Errorw("failed to get agent version", "error", err)
continue
}
log.Infow(
"identified",
"peer", e.Peer.Pretty(),
"agent", agent,
"protocols", protocols,
)
}
}
}()
return nil
}

Expand Down