Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
e4934f10
Commit
e4934f10
authored
Feb 16, 2016
by
Jeromy
Browse files
add remote multiaddr from active connection to peerstore
parent
8c511da9
Changes
2
Show whitespace changes
Inline
Side-by-side
p2p/protocol/identify/id.go
View file @
e4934f10
...
@@ -82,7 +82,8 @@ func (ids *IDService) IdentifyConn(c inet.Conn) {
...
@@ -82,7 +82,8 @@ func (ids *IDService) IdentifyConn(c inet.Conn) {
log
.
Event
(
context
.
TODO
(),
"IdentifyOpenFailed"
,
c
.
RemotePeer
())
log
.
Event
(
context
.
TODO
(),
"IdentifyOpenFailed"
,
c
.
RemotePeer
())
c
.
Close
()
c
.
Close
()
return
return
}
else
{
}
bwc
:=
ids
.
Host
.
GetBandwidthReporter
()
bwc
:=
ids
.
Host
.
GetBandwidthReporter
()
s
=
mstream
.
WrapStream
(
s
,
ID
,
bwc
)
s
=
mstream
.
WrapStream
(
s
,
ID
,
bwc
)
...
@@ -92,11 +93,10 @@ func (ids *IDService) IdentifyConn(c inet.Conn) {
...
@@ -92,11 +93,10 @@ func (ids *IDService) IdentifyConn(c inet.Conn) {
log
.
Event
(
context
.
TODO
(),
"IdentifyOpenFailed"
,
c
.
RemotePeer
())
log
.
Event
(
context
.
TODO
(),
"IdentifyOpenFailed"
,
c
.
RemotePeer
())
s
.
Close
()
s
.
Close
()
return
return
}
else
{
ids
.
ResponseHandler
(
s
)
}
}
}
ids
.
ResponseHandler
(
s
)
ids
.
currmu
.
Lock
()
ids
.
currmu
.
Lock
()
ch
,
found
:=
ids
.
currid
[
c
]
ch
,
found
:=
ids
.
currid
[
c
]
delete
(
ids
.
currid
,
c
)
delete
(
ids
.
currid
,
c
)
...
@@ -190,6 +190,8 @@ func (ids *IDService) consumeMessage(mes *pb.Identify, c inet.Conn) {
...
@@ -190,6 +190,8 @@ func (ids *IDService) consumeMessage(mes *pb.Identify, c inet.Conn) {
lmaddrs
=
append
(
lmaddrs
,
maddr
)
lmaddrs
=
append
(
lmaddrs
,
maddr
)
}
}
lmaddrs
=
append
(
lmaddrs
,
c
.
RemoteMultiaddr
())
// update our peerstore with the addresses. here, we SET the addresses, clearing old ones.
// update our peerstore with the addresses. here, we SET the addresses, clearing old ones.
// We are receiving from the peer itself. this is current address ground truth.
// We are receiving from the peer itself. this is current address ground truth.
ids
.
Host
.
Peerstore
()
.
SetAddrs
(
p
,
lmaddrs
,
peer
.
ConnectedAddrTTL
)
ids
.
Host
.
Peerstore
()
.
SetAddrs
(
p
,
lmaddrs
,
peer
.
ConnectedAddrTTL
)
...
...
p2p/protocol/identify/id_test.go
View file @
e4934f10
...
@@ -38,6 +38,7 @@ func subtestIDService(t *testing.T, postDialWait time.Duration) {
...
@@ -38,6 +38,7 @@ func subtestIDService(t *testing.T, postDialWait time.Duration) {
// the IDService should be opened automatically, by the network.
// the IDService should be opened automatically, by the network.
// what we should see now is that both peers know about each others listen addresses.
// what we should see now is that both peers know about each others listen addresses.
t
.
Log
(
"test peer1 has peer2 addrs correctly"
)
testKnowsAddrs
(
t
,
h1
,
h2p
,
h2
.
Peerstore
()
.
Addrs
(
h2p
))
// has them
testKnowsAddrs
(
t
,
h1
,
h2p
,
h2
.
Peerstore
()
.
Addrs
(
h2p
))
// has them
testHasProtocolVersions
(
t
,
h1
,
h2p
)
testHasProtocolVersions
(
t
,
h1
,
h2p
)
...
@@ -49,8 +50,12 @@ func subtestIDService(t *testing.T, postDialWait time.Duration) {
...
@@ -49,8 +50,12 @@ func subtestIDService(t *testing.T, postDialWait time.Duration) {
}
}
<-
h2
.
IDService
()
.
IdentifyWait
(
c
[
0
])
<-
h2
.
IDService
()
.
IdentifyWait
(
c
[
0
])
addrs
:=
h1
.
Peerstore
()
.
Addrs
(
h1p
)
addrs
=
append
(
addrs
,
c
[
0
]
.
RemoteMultiaddr
())
// and the protocol versions.
// and the protocol versions.
testKnowsAddrs
(
t
,
h2
,
h1p
,
h1
.
Peerstore
()
.
Addrs
(
h1p
))
// has them
t
.
Log
(
"test peer2 has peer1 addrs correctly"
)
testKnowsAddrs
(
t
,
h2
,
h1p
,
addrs
)
// has them
testHasProtocolVersions
(
t
,
h2
,
h1p
)
testHasProtocolVersions
(
t
,
h2
,
h1p
)
}
}
...
@@ -58,7 +63,9 @@ func testKnowsAddrs(t *testing.T, h host.Host, p peer.ID, expected []ma.Multiadd
...
@@ -58,7 +63,9 @@ func testKnowsAddrs(t *testing.T, h host.Host, p peer.ID, expected []ma.Multiadd
actual
:=
h
.
Peerstore
()
.
Addrs
(
p
)
actual
:=
h
.
Peerstore
()
.
Addrs
(
p
)
if
len
(
actual
)
!=
len
(
expected
)
{
if
len
(
actual
)
!=
len
(
expected
)
{
t
.
Error
(
"dont have the same addresses"
)
t
.
Errorf
(
"expected: %s"
,
expected
)
t
.
Errorf
(
"actual: %s"
,
actual
)
t
.
Fatal
(
"dont have the same addresses"
)
}
}
have
:=
map
[
string
]
struct
{}{}
have
:=
map
[
string
]
struct
{}{}
...
...
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