From e1fe4f6d60620d14bb7f2f300c30204589ca3040 Mon Sep 17 00:00:00 2001
From: Brian Tiger Chow <brian.holderchow@gmail.com>
Date: Thu, 18 Sep 2014 17:30:06 -0700
Subject: [PATCH] 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
---
 blockservice/blockservice.go |  4 ++--
 core/core.go                 |  6 +++---
 exchange/bitswap/bitswap.go  | 14 ++++++++++++--
 exchange/bitswap/offline.go  |  2 +-
 exchange/interface.go        | 10 +++-------
 5 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/blockservice/blockservice.go b/blockservice/blockservice.go
index 011ad028..89136edb 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 69a8bab0..24c6dc43 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 71b879f9..dcf095b0 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 46b71d27..a8dbd0f8 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 73c3ba60..75eca06b 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
-}
-- 
GitLab