Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
e0edbe90
Unverified
Commit
e0edbe90
authored
Mar 13, 2020
by
Steven Allen
Committed by
GitHub
Mar 13, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6972 from ipfs/feat/log-identify
feat(peerlog): log protocols/versions
parents
ba285801
255fefb2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
0 deletions
+35
-0
plugin/plugins/peerlog/peerlog.go
plugin/plugins/peerlog/peerlog.go
+35
-0
No files found.
plugin/plugins/peerlog/peerlog.go
View file @
e0edbe90
...
...
@@ -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"
)
...
...
@@ -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
(),
)
...
...
@@ -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
),
)
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
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment