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
p2p
go-p2p-kad-dht
Commits
78443247
Commit
78443247
authored
Sep 01, 2014
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix up tests that started failing after changing identify code
parent
07535a64
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
17 deletions
+37
-17
dht_test.go
dht_test.go
+35
-16
routing.go
routing.go
+2
-1
No files found.
dht_test.go
View file @
78443247
...
...
@@ -4,6 +4,7 @@ import (
"testing"
ds
"github.com/jbenet/datastore.go"
identify
"github.com/jbenet/go-ipfs/identify"
peer
"github.com/jbenet/go-ipfs/peer"
swarm
"github.com/jbenet/go-ipfs/swarm"
u
"github.com/jbenet/go-ipfs/util"
...
...
@@ -27,7 +28,17 @@ func setupDHTS(n int, t *testing.T) ([]*ma.Multiaddr, []*peer.Peer, []*IpfsDHT)
for
i
:=
0
;
i
<
4
;
i
++
{
p
:=
new
(
peer
.
Peer
)
p
.
AddAddress
(
addrs
[
i
])
p
.
ID
=
peer
.
ID
([]
byte
(
fmt
.
Sprintf
(
"peer_%d"
,
i
)))
kp
,
err
:=
identify
.
GenKeypair
(
256
)
if
err
!=
nil
{
panic
(
err
)
}
p
.
PubKey
=
kp
.
Pub
p
.
PrivKey
=
kp
.
Priv
id
,
err
:=
kp
.
ID
()
if
err
!=
nil
{
panic
(
err
)
}
p
.
ID
=
id
peers
=
append
(
peers
,
p
)
}
...
...
@@ -46,8 +57,26 @@ func setupDHTS(n int, t *testing.T) ([]*ma.Multiaddr, []*peer.Peer, []*IpfsDHT)
return
addrs
,
peers
,
dhts
}
func
makePeer
(
addr
*
ma
.
Multiaddr
)
*
peer
.
Peer
{
p
:=
new
(
peer
.
Peer
)
p
.
AddAddress
(
addr
)
kp
,
err
:=
identify
.
GenKeypair
(
256
)
if
err
!=
nil
{
panic
(
err
)
}
p
.
PrivKey
=
kp
.
Priv
p
.
PubKey
=
kp
.
Pub
id
,
err
:=
kp
.
ID
()
if
err
!=
nil
{
panic
(
err
)
}
p
.
ID
=
id
return
p
}
func
TestPing
(
t
*
testing
.
T
)
{
u
.
Debug
=
fals
e
u
.
Debug
=
tru
e
addrA
,
err
:=
ma
.
NewMultiaddr
(
"/ip4/127.0.0.1/tcp/2222"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
@@ -57,13 +86,8 @@ func TestPing(t *testing.T) {
t
.
Fatal
(
err
)
}
peerA
:=
new
(
peer
.
Peer
)
peerA
.
AddAddress
(
addrA
)
peerA
.
ID
=
peer
.
ID
([]
byte
(
"peerA"
))
peerB
:=
new
(
peer
.
Peer
)
peerB
.
AddAddress
(
addrB
)
peerB
.
ID
=
peer
.
ID
([]
byte
(
"peerB"
))
peerA
:=
makePeer
(
addrA
)
peerB
:=
makePeer
(
addrB
)
neta
:=
swarm
.
NewSwarm
(
peerA
)
err
=
neta
.
Listen
()
...
...
@@ -108,13 +132,8 @@ func TestValueGetSet(t *testing.T) {
t
.
Fatal
(
err
)
}
peerA
:=
new
(
peer
.
Peer
)
peerA
.
AddAddress
(
addrA
)
peerA
.
ID
=
peer
.
ID
([]
byte
(
"peerA"
))
peerB
:=
new
(
peer
.
Peer
)
peerB
.
AddAddress
(
addrB
)
peerB
.
ID
=
peer
.
ID
([]
byte
(
"peerB"
))
peerA
:=
makePeer
(
addrA
)
peerB
:=
makePeer
(
addrB
)
neta
:=
swarm
.
NewSwarm
(
peerA
)
err
=
neta
.
Listen
()
...
...
routing.go
View file @
78443247
...
...
@@ -315,8 +315,9 @@ func (dht *IpfsDHT) FindPeer(id peer.ID, timeout time.Duration) (*peer.Peer, err
for
routeLevel
<
len
(
dht
.
routingTables
)
{
pmes
,
err
:=
dht
.
findPeerSingle
(
p
,
id
,
timeout
,
routeLevel
)
plist
:=
pmes
.
GetPeers
()
if
len
(
plist
)
==
0
{
if
plist
==
nil
||
len
(
plist
)
==
0
{
routeLevel
++
continue
}
found
:=
plist
[
0
]
...
...
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