Commit 94147479 authored by Brian Tiger Chow's avatar Brian Tiger Chow

use testutil peer in sess

parent 4c6a6012
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
peer "github.com/jbenet/go-ipfs/peer" peer "github.com/jbenet/go-ipfs/peer"
datastore2 "github.com/jbenet/go-ipfs/util/datastore2" datastore2 "github.com/jbenet/go-ipfs/util/datastore2"
delay "github.com/jbenet/go-ipfs/util/delay" delay "github.com/jbenet/go-ipfs/util/delay"
testutil "github.com/jbenet/go-ipfs/util/testutil"
) )
func NewSessionGenerator( func NewSessionGenerator(
...@@ -40,7 +41,11 @@ func (g *SessionGenerator) Close() error { ...@@ -40,7 +41,11 @@ func (g *SessionGenerator) Close() error {
func (g *SessionGenerator) Next() Instance { func (g *SessionGenerator) Next() Instance {
g.seq++ g.seq++
return session(g.ctx, g.net, peer.ID(g.seq)) p, err := testutil.RandPeer()
if err != nil {
panic("FIXME") // TODO change signature
}
return session(g.ctx, g.net, p)
} }
func (g *SessionGenerator) Instances(n int) []Instance { func (g *SessionGenerator) Instances(n int) []Instance {
...@@ -73,9 +78,9 @@ func (i *Instance) SetBlockstoreLatency(t time.Duration) time.Duration { ...@@ -73,9 +78,9 @@ func (i *Instance) SetBlockstoreLatency(t time.Duration) time.Duration {
// NB: It's easy make mistakes by providing the same peer ID to two different // NB: It's easy make mistakes by providing the same peer ID to two different
// sessions. To safeguard, use the SessionGenerator to generate sessions. It's // sessions. To safeguard, use the SessionGenerator to generate sessions. It's
// just a much better idea. // just a much better idea.
func session(ctx context.Context, net tn.Network, p peer.ID) Instance { func session(ctx context.Context, net tn.Network, p testutil.Peer) Instance {
adapter := net.Adapter(p) adapter := net.Adapter(p.ID())
bsdelay := delay.Fixed(0) bsdelay := delay.Fixed(0)
const kWriteCacheElems = 100 const kWriteCacheElems = 100
...@@ -87,10 +92,10 @@ func session(ctx context.Context, net tn.Network, p peer.ID) Instance { ...@@ -87,10 +92,10 @@ func session(ctx context.Context, net tn.Network, p peer.ID) Instance {
const alwaysSendToPeer = true const alwaysSendToPeer = true
bs := New(ctx, p, adapter, bstore, alwaysSendToPeer) bs := New(ctx, p.ID(), adapter, bstore, alwaysSendToPeer)
return Instance{ return Instance{
Peer: p, Peer: p.ID(),
Exchange: bs, Exchange: bs,
blockstore: bstore, blockstore: bstore,
blockstoreDelay: bsdelay, blockstoreDelay: bsdelay,
......
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