Commit ccaa490c authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

better peer gen

parent e989d6fe
...@@ -13,7 +13,6 @@ import ( ...@@ -13,7 +13,6 @@ import (
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context" context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr" ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
) )
func pong(ctx context.Context, swarm *Swarm) { func pong(ctx context.Context, swarm *Swarm) {
...@@ -30,35 +29,34 @@ func pong(ctx context.Context, swarm *Swarm) { ...@@ -30,35 +29,34 @@ func pong(ctx context.Context, swarm *Swarm) {
} }
} }
func setupPeer(t *testing.T, id string, addr string) *peer.Peer { func setupPeer(t *testing.T, addr string) *peer.Peer {
tcp, err := ma.NewMultiaddr(addr) tcp, err := ma.NewMultiaddr(addr)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
mh, err := mh.FromHexString(id) sk, pk, err := ci.GenerateKeyPair(ci.RSA, 512)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
p := &peer.Peer{ID: peer.ID(mh)} id, err := peer.IDFromPubKey(pk)
sk, pk, err := ci.GenerateKeyPair(ci.RSA, 512)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
p := &peer.Peer{ID: id}
p.PrivKey = sk p.PrivKey = sk
p.PubKey = pk p.PubKey = pk
p.AddAddress(tcp) p.AddAddress(tcp)
return p return p, nil
} }
func makeSwarms(ctx context.Context, t *testing.T, peers map[string]string) []*Swarm { func makeSwarms(ctx context.Context, t *testing.T, peers map[string]string) []*Swarm {
swarms := []*Swarm{} swarms := []*Swarm{}
for key, addr := range peers { for key, addr := range peers {
local := setupPeer(t, key, addr) local := setupPeer(t, addr)
peerstore := peer.NewPeerstore() peerstore := peer.NewPeerstore()
swarm, err := NewSwarm(ctx, local, peerstore) swarm, err := NewSwarm(ctx, local, peerstore)
if err != nil { if err != nil {
......
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