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

refac(exchange) rename exchange.Interface to match golang conventions

examples:

    http://golang.org/pkg/container/heap/#Interface

    http://golang.org/pkg/net/#Interface

    http://golang.org/pkg/sort/#Interface
parent fd086b9c
...@@ -16,11 +16,11 @@ import ( ...@@ -16,11 +16,11 @@ import (
// It uses an internal `datastore.Datastore` instance to store values. // It uses an internal `datastore.Datastore` instance to store values.
type BlockService struct { type BlockService struct {
Datastore ds.Datastore Datastore ds.Datastore
Remote exchange.Exchange Remote exchange.Interface
} }
// NewBlockService creates a BlockService with given datastore instance. // 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 { if d == nil {
return nil, fmt.Errorf("BlockService requires valid datastore") return nil, fmt.Errorf("BlockService requires valid datastore")
} }
......
...@@ -48,7 +48,7 @@ type IpfsNode struct { ...@@ -48,7 +48,7 @@ type IpfsNode struct {
Routing routing.IpfsRouting Routing routing.IpfsRouting
// the block exchange + strategy (bitswap) // the block exchange + strategy (bitswap)
BitSwap exchange.Exchange Exchange exchange.Interface
// the block service, get/add blocks. // the block service, get/add blocks.
Blocks *bserv.BlockService Blocks *bserv.BlockService
...@@ -89,7 +89,7 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) { ...@@ -89,7 +89,7 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) {
net inet.Network net inet.Network
// TODO: refactor so we can use IpfsRouting interface instead of being DHT-specific // TODO: refactor so we can use IpfsRouting interface instead of being DHT-specific
route *dht.IpfsDHT route *dht.IpfsDHT
exchangeSession exchange.Exchange exchangeSession exchange.Interface
) )
if online { if online {
...@@ -141,7 +141,7 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) { ...@@ -141,7 +141,7 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) {
Blocks: bs, Blocks: bs,
DAG: dag, DAG: dag,
Resolver: &path.Resolver{DAG: dag}, Resolver: &path.Resolver{DAG: dag},
BitSwap: exchangeSession, Exchange: exchangeSession,
Identity: local, Identity: local,
Routing: route, Routing: route,
}, nil }, nil
......
...@@ -18,6 +18,16 @@ import ( ...@@ -18,6 +18,16 @@ import (
u "github.com/jbenet/go-ipfs/util" 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 // TODO(brian): ensure messages are being received
// PartnerWantListMax is the bound for the number of keys we'll store per // PartnerWantListMax is the bound for the number of keys we'll store per
...@@ -38,7 +48,7 @@ type bitswap struct { ...@@ -38,7 +48,7 @@ type bitswap struct {
blockstore blockstore.Blockstore blockstore blockstore.Blockstore
// routing interface for communication // routing interface for communication
routing exchange.Directory routing Routing
notifications notifications.PubSub notifications notifications.PubSub
...@@ -49,7 +59,7 @@ type bitswap struct { ...@@ -49,7 +59,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, 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 // FIXME(brian): instantiate a concrete Strategist
receiver := bsnet.Forwarder{} receiver := bsnet.Forwarder{}
......
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
u "github.com/jbenet/go-ipfs/util" u "github.com/jbenet/go-ipfs/util"
) )
func NewOfflineExchange() exchange.Exchange { func NewOfflineExchange() exchange.Interface {
return &offlineExchange{} return &offlineExchange{}
} }
......
...@@ -4,11 +4,12 @@ import ( ...@@ -4,11 +4,12 @@ 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"
) )
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. // Block returns the block associated with a given key.
// TODO(brian): pass a context instead of a timeout // TODO(brian): pass a context instead of a timeout
...@@ -21,8 +22,3 @@ type Exchange interface { ...@@ -21,8 +22,3 @@ 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 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