refac(bitswap) define Directory interface
Brian Tiger Chow committed
Sep 16, 2014 at 08:31 UTC
7622c4bb173c89cbb9b6d96ce09b04699bebdb52
2 files changed
+9
-4
bitswap/bitswap.go
+3
-4
@@ -13,7 +13,6 @@ import (
13
blocks "github.com/jbenet/go-ipfs/blocks"
14
blockstore "github.com/jbenet/go-ipfs/blockstore"
15
peer "github.com/jbenet/go-ipfs/peer"
16
- routing "github.com/jbenet/go-ipfs/routing"
16
u "github.com/jbenet/go-ipfs/util"
17
)
18
@@ -40,7 +39,7 @@ type bitswap struct {
39
blockstore blockstore.Blockstore
40
41
// routing interface for communication
43
- routing routing.IpfsRouting
42
+ routing Directory
43
44
notifications notifications.PubSub
45
@@ -62,7 +61,7 @@ type bitswap struct {
61
}
62
63
// NewSession initializes a bitswap session.
65
-func NewSession(parent context.Context, s bsnet.NetworkService, p *peer.Peer, d ds.Datastore, r routing.IpfsRouting) Exchange {
64
+func NewSession(parent context.Context, s bsnet.NetworkService, p *peer.Peer, d ds.Datastore, directory Directory) Exchange {
65
66
receiver := bsnet.Forwarder{}
67
bs := &bitswap{
@@ -70,7 +69,7 @@ func NewSession(parent context.Context, s bsnet.NetworkService, p *peer.Peer, d
69
blockstore: blockstore.NewBlockstore(d),
70
partners: ledgerMap{},
71
wantList: KeySet{},
73
- routing: r,
72
+ routing: directory,
73
sender: bsnet.NewNetworkAdapter(s, &receiver),
74
haltChan: make(chan struct{}),
75
notifications: notifications.New(),
bitswap/interface.go
+6
@@ -4,6 +4,7 @@ import (
4
"time"
5
6
blocks "github.com/jbenet/go-ipfs/blocks"
7
+ peer "github.com/jbenet/go-ipfs/peer"
8
u "github.com/jbenet/go-ipfs/util"
9
)
10
@@ -20,3 +21,8 @@ type Exchange interface {
21
// whether the block was made available on the network?
22
HasBlock(blocks.Block) error
23
}
24
+
25
+type Directory interface {
26
+ FindProvidersAsync(u.Key, int, time.Duration) <-chan *peer.Peer
27
+ Provide(key u.Key) error
28
+}