diff --git a/blockservice/blockservice.go b/blockservice/blockservice.go index 011ad0283f2b62d57abe50f6468aa9f3e3fa8093..89136edb0267f5517fdc65cdf05ac728bd4d915c 100644 --- a/blockservice/blockservice.go +++ b/blockservice/blockservice.go @@ -16,11 +16,11 @@ import ( // It uses an internal `datastore.Datastore` instance to store values. type BlockService struct { Datastore ds.Datastore - Remote exchange.Exchange + Remote exchange.Interface } // NewBlockService creates a BlockService with given datastore instance. -func NewBlockService(d ds.Datastore, rem exchange.Exchange) (*BlockService, error) { +func NewBlockService(d ds.Datastore, rem exchange.Interface) (*BlockService, error) { if d == nil { return nil, fmt.Errorf("BlockService requires valid datastore") } diff --git a/core/core.go b/core/core.go index 69a8bab09fb3d45bce79f0c0791b08d5a30e5274..24c6dc43d9239eae7737000c8965a563eb284b6b 100644 --- a/core/core.go +++ b/core/core.go @@ -48,7 +48,7 @@ type IpfsNode struct { Routing routing.IpfsRouting // the block exchange + strategy (bitswap) - BitSwap exchange.Exchange + Exchange exchange.Interface // the block service, get/add blocks. Blocks *bserv.BlockService @@ -89,7 +89,7 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) { net inet.Network // TODO: refactor so we can use IpfsRouting interface instead of being DHT-specific route *dht.IpfsDHT - exchangeSession exchange.Exchange + exchangeSession exchange.Interface ) if online { @@ -141,7 +141,7 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) { Blocks: bs, DAG: dag, Resolver: &path.Resolver{DAG: dag}, - BitSwap: exchangeSession, + Exchange: exchangeSession, Identity: local, Routing: route, }, nil diff --git a/exchange/bitswap/bitswap.go b/exchange/bitswap/bitswap.go index 71b879f98bd0327c3e3d1a351c38a5f7d6136330..dcf095b02822a2e094f15a58e1d13b9052aad1a3 100644 --- a/exchange/bitswap/bitswap.go +++ b/exchange/bitswap/bitswap.go @@ -18,6 +18,16 @@ import ( u "github.com/jbenet/go-ipfs/util" ) +// TODO rename -> Router? +type Routing interface { + // FindProvidersAsync returns a channel of providers for the given key + // TODO replace with timeout with context + FindProvidersAsync(u.Key, int, time.Duration) <-chan *peer.Peer + + // Provide provides the key to the network + Provide(key u.Key) error +} + // TODO(brian): ensure messages are being received // PartnerWantListMax is the bound for the number of keys we'll store per @@ -38,7 +48,7 @@ type bitswap struct { blockstore blockstore.Blockstore // routing interface for communication - routing exchange.Directory + routing Routing notifications notifications.PubSub @@ -49,7 +59,7 @@ type bitswap struct { } // NewSession initializes a bitswap session. -func NewSession(parent context.Context, s bsnet.NetworkService, p *peer.Peer, d ds.Datastore, directory exchange.Directory) exchange.Exchange { +func NewSession(parent context.Context, s bsnet.NetworkService, p *peer.Peer, d ds.Datastore, directory Routing) exchange.Interface { // FIXME(brian): instantiate a concrete Strategist receiver := bsnet.Forwarder{} diff --git a/exchange/bitswap/offline.go b/exchange/bitswap/offline.go index 46b71d27b515240db72ab6ffb91e4d3037f31d02..a8dbd0f8e85d088fe853b89bcb1434cc049aca68 100644 --- a/exchange/bitswap/offline.go +++ b/exchange/bitswap/offline.go @@ -9,7 +9,7 @@ import ( u "github.com/jbenet/go-ipfs/util" ) -func NewOfflineExchange() exchange.Exchange { +func NewOfflineExchange() exchange.Interface { return &offlineExchange{} } diff --git a/exchange/interface.go b/exchange/interface.go index 73c3ba6033766482262f46c434bae462f3321a46..75eca06bf81c584459369495f731f055ecc649e4 100644 --- a/exchange/interface.go +++ b/exchange/interface.go @@ -4,11 +4,12 @@ import ( "time" blocks "github.com/jbenet/go-ipfs/blocks" - peer "github.com/jbenet/go-ipfs/peer" u "github.com/jbenet/go-ipfs/util" ) -type Exchange interface { +// Any type that implements exchange.Interface may be used as an IPFS block +// exchange protocol. +type Interface interface { // Block returns the block associated with a given key. // TODO(brian): pass a context instead of a timeout @@ -21,8 +22,3 @@ 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 -}