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 (
// 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")
}
......
......@@ -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
......
......@@ -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{}
......
......@@ -9,7 +9,7 @@ import (
u "github.com/jbenet/go-ipfs/util"
)
func NewOfflineExchange() exchange.Exchange {
func NewOfflineExchange() exchange.Interface {
return &offlineExchange{}
}
......
......@@ -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
}
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