Commit 78443247 authored by Jeromy's avatar Jeromy

fix up tests that started failing after changing identify code

parent 07535a64
......@@ -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 = false
u.Debug = true
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()
......
......@@ -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]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment