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
f4ea270c
Commit
f4ea270c
authored
Nov 18, 2016
by
Jeromy
Browse files
use set protos in identify protocol knowledge gathering
parent
3a631293
Changes
2
Hide whitespace changes
Inline
Side-by-side
p2p/host/basic/basic_host_test.go
View file @
f4ea270c
...
...
@@ -241,3 +241,62 @@ func TestNewDialOld(t *testing.T) {
s
.
Close
()
}
func
TestProtoDowngrade
(
t
*
testing
.
T
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
h1
,
h2
:=
getHostPair
(
ctx
,
t
)
defer
h1
.
Close
()
defer
h2
.
Close
()
connectedOn
:=
make
(
chan
protocol
.
ID
,
16
)
h1
.
SetStreamHandler
(
"/testing/1.0.0"
,
func
(
s
inet
.
Stream
)
{
connectedOn
<-
s
.
Protocol
()
s
.
Close
()
})
s
,
err
:=
h2
.
NewStream
(
ctx
,
h1
.
ID
(),
"/testing/1.0.0"
,
"/testing"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
assertWait
(
t
,
connectedOn
,
"/testing/1.0.0"
)
if
s
.
Protocol
()
!=
"/testing/1.0.0"
{
t
.
Fatal
(
"shoould have gotten /testing"
)
}
s
.
Close
()
h1
.
Network
()
.
ConnsToPeer
(
h2
.
ID
())[
0
]
.
Close
()
time
.
Sleep
(
time
.
Millisecond
*
50
)
// allow notifications to propogate
h1
.
RemoveStreamHandler
(
"/testing/1.0.0"
)
h1
.
SetStreamHandler
(
"/testing"
,
func
(
s
inet
.
Stream
)
{
connectedOn
<-
s
.
Protocol
()
s
.
Close
()
})
h2pi
:=
h2
.
Peerstore
()
.
PeerInfo
(
h2
.
ID
())
if
err
:=
h1
.
Connect
(
ctx
,
h2pi
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
s2
,
err
:=
h2
.
NewStream
(
ctx
,
h1
.
ID
(),
"/testing/1.0.0"
,
"/testing"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
_
,
err
=
s2
.
Write
(
nil
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
assertWait
(
t
,
connectedOn
,
"/testing"
)
if
s2
.
Protocol
()
!=
"/testing"
{
t
.
Fatal
(
"shoould have gotten /testing"
)
}
s2
.
Close
()
}
p2p/protocol/identify/id.go
View file @
f4ea270c
...
...
@@ -193,7 +193,7 @@ func (ids *IDService) consumeMessage(mes *pb.Identify, c inet.Conn) {
p
:=
c
.
RemotePeer
()
// mes.Protocols
ids
.
Host
.
Peerstore
()
.
Add
Protocols
(
p
,
mes
.
Protocols
...
)
ids
.
Host
.
Peerstore
()
.
Set
Protocols
(
p
,
mes
.
Protocols
...
)
// mes.ObservedAddr
ids
.
consumeObservedAddress
(
mes
.
GetObservedAddr
(),
c
)
...
...
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