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
17d39398
Commit
17d39398
authored
Sep 11, 2016
by
jbenet
Browse files
identify: tests verify we have public keys
parent
83eddcae
Changes
1
Show whitespace changes
Inline
Side-by-side
p2p/protocol/identify/id_test.go
View file @
17d39398
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"testing"
"testing"
"time"
"time"
ic
"github.com/ipfs/go-libp2p-crypto"
peer
"github.com/ipfs/go-libp2p-peer"
peer
"github.com/ipfs/go-libp2p-peer"
host
"github.com/libp2p/go-libp2p/p2p/host"
host
"github.com/libp2p/go-libp2p/p2p/host"
identify
"github.com/libp2p/go-libp2p/p2p/protocol/identify"
identify
"github.com/libp2p/go-libp2p/p2p/protocol/identify"
...
@@ -41,6 +42,7 @@ func subtestIDService(t *testing.T, postDialWait time.Duration) {
...
@@ -41,6 +42,7 @@ func subtestIDService(t *testing.T, postDialWait time.Duration) {
t
.
Log
(
"test peer1 has peer2 addrs correctly"
)
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
)
testHasPublicKey
(
t
,
h1
,
h2p
,
h2
.
Peerstore
()
.
PubKey
(
h2p
))
// h1 should have h2's public key
// now, this wait we do have to do. it's the wait for the Listening side
// now, this wait we do have to do. it's the wait for the Listening side
// to be done identifying the connection.
// to be done identifying the connection.
...
@@ -57,6 +59,7 @@ func subtestIDService(t *testing.T, postDialWait time.Duration) {
...
@@ -57,6 +59,7 @@ func subtestIDService(t *testing.T, postDialWait time.Duration) {
t
.
Log
(
"test peer2 has peer1 addrs correctly"
)
t
.
Log
(
"test peer2 has peer1 addrs correctly"
)
testKnowsAddrs
(
t
,
h2
,
h1p
,
addrs
)
// has them
testKnowsAddrs
(
t
,
h2
,
h1p
,
addrs
)
// has them
testHasProtocolVersions
(
t
,
h2
,
h1p
)
testHasProtocolVersions
(
t
,
h2
,
h1p
)
testHasPublicKey
(
t
,
h2
,
h1p
,
h1
.
Peerstore
()
.
PubKey
(
h1p
))
// h1 should have h2's public key
}
}
func
testKnowsAddrs
(
t
*
testing
.
T
,
h
host
.
Host
,
p
peer
.
ID
,
expected
[]
ma
.
Multiaddr
)
{
func
testKnowsAddrs
(
t
*
testing
.
T
,
h
host
.
Host
,
p
peer
.
ID
,
expected
[]
ma
.
Multiaddr
)
{
...
@@ -95,6 +98,25 @@ func testHasProtocolVersions(t *testing.T, h host.Host, p peer.ID) {
...
@@ -95,6 +98,25 @@ func testHasProtocolVersions(t *testing.T, h host.Host, p peer.ID) {
}
}
}
}
func
testHasPublicKey
(
t
*
testing
.
T
,
h
host
.
Host
,
p
peer
.
ID
,
shouldBe
ic
.
PubKey
)
{
k
:=
h
.
Peerstore
()
.
PubKey
(
p
)
if
k
==
nil
{
t
.
Error
(
"no public key"
)
return
}
if
!
k
.
Equals
(
shouldBe
)
{
t
.
Error
(
"key mismatch"
)
return
}
p2
,
err
:=
peer
.
IDFromPublicKey
(
k
)
if
err
!=
nil
{
t
.
Error
(
"could not make key"
)
}
else
if
p
!=
p2
{
t
.
Error
(
"key does not match peerid"
)
}
}
// TestIDServiceWait gives the ID service 100ms to finish after dialing
// TestIDServiceWait gives the ID service 100ms to finish after dialing
// this is becasue it used to be concurrent. Now, Dial wait till the
// this is becasue it used to be concurrent. Now, Dial wait till the
// id service is done.
// id service is done.
...
...
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