提交 7622c4bb 作者: Brian Tiger Chow

refac(bitswap) define Directory interface

上级 b36670df
...@@ -13,7 +13,6 @@ import ( ...@@ -13,7 +13,6 @@ import (
blocks "github.com/jbenet/go-ipfs/blocks" blocks "github.com/jbenet/go-ipfs/blocks"
blockstore "github.com/jbenet/go-ipfs/blockstore" blockstore "github.com/jbenet/go-ipfs/blockstore"
peer "github.com/jbenet/go-ipfs/peer" peer "github.com/jbenet/go-ipfs/peer"
routing "github.com/jbenet/go-ipfs/routing"
u "github.com/jbenet/go-ipfs/util" u "github.com/jbenet/go-ipfs/util"
) )
...@@ -40,7 +39,7 @@ type bitswap struct { ...@@ -40,7 +39,7 @@ type bitswap struct {
blockstore blockstore.Blockstore blockstore blockstore.Blockstore
// routing interface for communication // routing interface for communication
routing routing.IpfsRouting routing Directory
notifications notifications.PubSub notifications notifications.PubSub
...@@ -62,7 +61,7 @@ type bitswap struct { ...@@ -62,7 +61,7 @@ type bitswap struct {
} }
// NewSession initializes a bitswap session. // 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{} receiver := bsnet.Forwarder{}
bs := &bitswap{ bs := &bitswap{
...@@ -70,7 +69,7 @@ func NewSession(parent context.Context, s bsnet.NetworkService, p *peer.Peer, d ...@@ -70,7 +69,7 @@ func NewSession(parent context.Context, s bsnet.NetworkService, p *peer.Peer, d
blockstore: blockstore.NewBlockstore(d), blockstore: blockstore.NewBlockstore(d),
partners: ledgerMap{}, partners: ledgerMap{},
wantList: KeySet{}, wantList: KeySet{},
routing: r, routing: directory,
sender: bsnet.NewNetworkAdapter(s, &receiver), sender: bsnet.NewNetworkAdapter(s, &receiver),
haltChan: make(chan struct{}), haltChan: make(chan struct{}),
notifications: notifications.New(), notifications: notifications.New(),
......
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"time" "time"
blocks "github.com/jbenet/go-ipfs/blocks" blocks "github.com/jbenet/go-ipfs/blocks"
peer "github.com/jbenet/go-ipfs/peer"
u "github.com/jbenet/go-ipfs/util" u "github.com/jbenet/go-ipfs/util"
) )
...@@ -20,3 +21,8 @@ type Exchange interface { ...@@ -20,3 +21,8 @@ type Exchange interface {
// whether the block was made available on the network? // whether the block was made available on the network?
HasBlock(blocks.Block) error HasBlock(blocks.Block) error
} }
type Directory interface {
FindProvidersAsync(u.Key, int, time.Duration) <-chan *peer.Peer
Provide(key u.Key) error
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论