Commit 7622c4bb authored by Brian Tiger Chow's avatar Brian Tiger Chow

refac(bitswap) define Directory interface

parent b36670df
......@@ -13,7 +13,6 @@ import (
blocks "github.com/jbenet/go-ipfs/blocks"
blockstore "github.com/jbenet/go-ipfs/blockstore"
peer "github.com/jbenet/go-ipfs/peer"
routing "github.com/jbenet/go-ipfs/routing"
u "github.com/jbenet/go-ipfs/util"
)
......@@ -40,7 +39,7 @@ type bitswap struct {
blockstore blockstore.Blockstore
// routing interface for communication
routing routing.IpfsRouting
routing Directory
notifications notifications.PubSub
......@@ -62,7 +61,7 @@ type bitswap struct {
}
// NewSession initializes a bitswap session.
func NewSession(parent context.Context, s bsnet.NetworkService, p *peer.Peer, d ds.Datastore, r routing.IpfsRouting) Exchange {
func NewSession(parent context.Context, s bsnet.NetworkService, p *peer.Peer, d ds.Datastore, directory Directory) Exchange {
receiver := bsnet.Forwarder{}
bs := &bitswap{
......@@ -70,7 +69,7 @@ func NewSession(parent context.Context, s bsnet.NetworkService, p *peer.Peer, d
blockstore: blockstore.NewBlockstore(d),
partners: ledgerMap{},
wantList: KeySet{},
routing: r,
routing: directory,
sender: bsnet.NewNetworkAdapter(s, &receiver),
haltChan: make(chan struct{}),
notifications: notifications.New(),
......
......@@ -4,6 +4,7 @@ import (
"time"
blocks "github.com/jbenet/go-ipfs/blocks"
peer "github.com/jbenet/go-ipfs/peer"
u "github.com/jbenet/go-ipfs/util"
)
......@@ -20,3 +21,8 @@ type Exchange interface {
// whether the block was made available on the network?
HasBlock(blocks.Block) error
}
type Directory interface {
FindProvidersAsync(u.Key, int, time.Duration) <-chan *peer.Peer
Provide(key u.Key) error
}
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