From fd086b9c48f82df73e790100d3dabdfc14148a29 Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow <brian.holderchow@gmail.com> Date: Thu, 18 Sep 2014 17:09:22 -0700 Subject: [PATCH] refac(exchange) bitswap -> exchange/bitswap Move go-ipfs/bitswap package to go-ipfs/exchange/bitswap * Delineates the difference between the generic exchange interface and implementations (eg. BitSwap protocol) Thus, the bitswap protocol can be refined without having to overthink how future exchanges will work. Aspects common to BitSwap and other exchanges can be extracted out to the exchange package in piecemeal. Future exchange implementations can be placed in sibling packages next to exchange/bitswap. (eg. exchange/multilateral) --- blockservice/blockservice.go | 6 +++--- core/core.go | 7 ++++--- {bitswap => exchange/bitswap}/bitswap.go | 13 +++++++------ {bitswap => exchange/bitswap}/message/Makefile | 0 {bitswap => exchange/bitswap}/message/message.go | 0 {bitswap => exchange/bitswap}/message/message.pb.go | 0 {bitswap => exchange/bitswap}/message/message.proto | 0 .../bitswap}/message/message_test.go | 0 {bitswap => exchange/bitswap}/network/forwarder.go | 2 +- .../bitswap}/network/forwarder_test.go | 0 {bitswap => exchange/bitswap}/network/interface.go | 2 +- .../bitswap}/network/network_adapter.go | 2 +- .../bitswap}/notifications/notifications.go | 0 .../bitswap}/notifications/notifications_test.go | 0 {bitswap => exchange/bitswap}/offline.go | 3 ++- {bitswap => exchange/bitswap}/offline_test.go | 0 {bitswap => exchange/bitswap}/strategy/interface.go | 2 +- {bitswap => exchange/bitswap}/strategy/ledger.go | 0 .../bitswap}/strategy/ledger_test.go | 0 {bitswap => exchange/bitswap}/strategy/math.go | 0 {bitswap => exchange/bitswap}/strategy/math_test.go | 0 {bitswap => exchange/bitswap}/strategy/strategy.go | 2 +- .../bitswap}/strategy/strategy_test.go | 0 {bitswap => exchange}/interface.go | 0 24 files changed, 21 insertions(+), 18 deletions(-) rename {bitswap => exchange/bitswap}/bitswap.go (92%) rename {bitswap => exchange/bitswap}/message/Makefile (100%) rename {bitswap => exchange/bitswap}/message/message.go (100%) rename {bitswap => exchange/bitswap}/message/message.pb.go (100%) rename {bitswap => exchange/bitswap}/message/message.proto (100%) rename {bitswap => exchange/bitswap}/message/message_test.go (100%) rename {bitswap => exchange/bitswap}/network/forwarder.go (92%) rename {bitswap => exchange/bitswap}/network/forwarder_test.go (100%) rename {bitswap => exchange/bitswap}/network/interface.go (95%) rename {bitswap => exchange/bitswap}/network/network_adapter.go (97%) rename {bitswap => exchange/bitswap}/notifications/notifications.go (100%) rename {bitswap => exchange/bitswap}/notifications/notifications_test.go (100%) rename {bitswap => exchange/bitswap}/offline.go (88%) rename {bitswap => exchange/bitswap}/offline_test.go (100%) rename {bitswap => exchange/bitswap}/strategy/interface.go (94%) rename {bitswap => exchange/bitswap}/strategy/ledger.go (100%) rename {bitswap => exchange/bitswap}/strategy/ledger_test.go (100%) rename {bitswap => exchange/bitswap}/strategy/math.go (100%) rename {bitswap => exchange/bitswap}/strategy/math_test.go (100%) rename {bitswap => exchange/bitswap}/strategy/strategy.go (97%) rename {bitswap => exchange/bitswap}/strategy/strategy_test.go (100%) rename {bitswap => exchange}/interface.go (100%) diff --git a/blockservice/blockservice.go b/blockservice/blockservice.go index 0b4f15b9..011ad028 100644 --- a/blockservice/blockservice.go +++ b/blockservice/blockservice.go @@ -5,8 +5,8 @@ import ( "time" ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go" - bitswap "github.com/jbenet/go-ipfs/bitswap" blocks "github.com/jbenet/go-ipfs/blocks" + exchange "github.com/jbenet/go-ipfs/exchange" u "github.com/jbenet/go-ipfs/util" mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash" @@ -16,11 +16,11 @@ import ( // It uses an internal `datastore.Datastore` instance to store values. type BlockService struct { Datastore ds.Datastore - Remote bitswap.Exchange + Remote exchange.Exchange } // NewBlockService creates a BlockService with given datastore instance. -func NewBlockService(d ds.Datastore, rem bitswap.Exchange) (*BlockService, error) { +func NewBlockService(d ds.Datastore, rem exchange.Exchange) (*BlockService, error) { if d == nil { return nil, fmt.Errorf("BlockService requires valid datastore") } diff --git a/core/core.go b/core/core.go index 3ada24f1..69a8bab0 100644 --- a/core/core.go +++ b/core/core.go @@ -10,10 +10,11 @@ import ( b58 "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-base58" ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr" - bitswap "github.com/jbenet/go-ipfs/bitswap" bserv "github.com/jbenet/go-ipfs/blockservice" config "github.com/jbenet/go-ipfs/config" ci "github.com/jbenet/go-ipfs/crypto" + exchange "github.com/jbenet/go-ipfs/exchange" + bitswap "github.com/jbenet/go-ipfs/exchange/bitswap" merkledag "github.com/jbenet/go-ipfs/merkledag" inet "github.com/jbenet/go-ipfs/net" mux "github.com/jbenet/go-ipfs/net/mux" @@ -47,7 +48,7 @@ type IpfsNode struct { Routing routing.IpfsRouting // the block exchange + strategy (bitswap) - BitSwap bitswap.Exchange + BitSwap exchange.Exchange // the block service, get/add blocks. Blocks *bserv.BlockService @@ -88,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 bitswap.Exchange + exchangeSession exchange.Exchange ) if online { diff --git a/bitswap/bitswap.go b/exchange/bitswap/bitswap.go similarity index 92% rename from bitswap/bitswap.go rename to exchange/bitswap/bitswap.go index ebbdd7b1..71b879f9 100644 --- a/bitswap/bitswap.go +++ b/exchange/bitswap/bitswap.go @@ -7,12 +7,13 @@ import ( context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context" ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go" - bsmsg "github.com/jbenet/go-ipfs/bitswap/message" - bsnet "github.com/jbenet/go-ipfs/bitswap/network" - notifications "github.com/jbenet/go-ipfs/bitswap/notifications" - strategy "github.com/jbenet/go-ipfs/bitswap/strategy" blocks "github.com/jbenet/go-ipfs/blocks" blockstore "github.com/jbenet/go-ipfs/blockstore" + exchange "github.com/jbenet/go-ipfs/exchange" + bsmsg "github.com/jbenet/go-ipfs/exchange/bitswap/message" + bsnet "github.com/jbenet/go-ipfs/exchange/bitswap/network" + notifications "github.com/jbenet/go-ipfs/exchange/bitswap/notifications" + strategy "github.com/jbenet/go-ipfs/exchange/bitswap/strategy" peer "github.com/jbenet/go-ipfs/peer" u "github.com/jbenet/go-ipfs/util" ) @@ -37,7 +38,7 @@ type bitswap struct { blockstore blockstore.Blockstore // routing interface for communication - routing Directory + routing exchange.Directory notifications notifications.PubSub @@ -48,7 +49,7 @@ type bitswap struct { } // NewSession initializes a bitswap session. -func NewSession(parent context.Context, s bsnet.NetworkService, p *peer.Peer, d ds.Datastore, directory Directory) Exchange { +func NewSession(parent context.Context, s bsnet.NetworkService, p *peer.Peer, d ds.Datastore, directory exchange.Directory) exchange.Exchange { // FIXME(brian): instantiate a concrete Strategist receiver := bsnet.Forwarder{} diff --git a/bitswap/message/Makefile b/exchange/bitswap/message/Makefile similarity index 100% rename from bitswap/message/Makefile rename to exchange/bitswap/message/Makefile diff --git a/bitswap/message/message.go b/exchange/bitswap/message/message.go similarity index 100% rename from bitswap/message/message.go rename to exchange/bitswap/message/message.go diff --git a/bitswap/message/message.pb.go b/exchange/bitswap/message/message.pb.go similarity index 100% rename from bitswap/message/message.pb.go rename to exchange/bitswap/message/message.pb.go diff --git a/bitswap/message/message.proto b/exchange/bitswap/message/message.proto similarity index 100% rename from bitswap/message/message.proto rename to exchange/bitswap/message/message.proto diff --git a/bitswap/message/message_test.go b/exchange/bitswap/message/message_test.go similarity index 100% rename from bitswap/message/message_test.go rename to exchange/bitswap/message/message_test.go diff --git a/bitswap/network/forwarder.go b/exchange/bitswap/network/forwarder.go similarity index 92% rename from bitswap/network/forwarder.go rename to exchange/bitswap/network/forwarder.go index f4eba0c1..603cd012 100644 --- a/bitswap/network/forwarder.go +++ b/exchange/bitswap/network/forwarder.go @@ -2,7 +2,7 @@ package network import ( context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context" - bsmsg "github.com/jbenet/go-ipfs/bitswap/message" + bsmsg "github.com/jbenet/go-ipfs/exchange/bitswap/message" peer "github.com/jbenet/go-ipfs/peer" ) diff --git a/bitswap/network/forwarder_test.go b/exchange/bitswap/network/forwarder_test.go similarity index 100% rename from bitswap/network/forwarder_test.go rename to exchange/bitswap/network/forwarder_test.go diff --git a/bitswap/network/interface.go b/exchange/bitswap/network/interface.go similarity index 95% rename from bitswap/network/interface.go rename to exchange/bitswap/network/interface.go index 89157b7a..70339835 100644 --- a/bitswap/network/interface.go +++ b/exchange/bitswap/network/interface.go @@ -4,7 +4,7 @@ import ( context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context" netservice "github.com/jbenet/go-ipfs/net/service" - bsmsg "github.com/jbenet/go-ipfs/bitswap/message" + bsmsg "github.com/jbenet/go-ipfs/exchange/bitswap/message" netmsg "github.com/jbenet/go-ipfs/net/message" peer "github.com/jbenet/go-ipfs/peer" ) diff --git a/bitswap/network/network_adapter.go b/exchange/bitswap/network/network_adapter.go similarity index 97% rename from bitswap/network/network_adapter.go rename to exchange/bitswap/network/network_adapter.go index f4b0a193..8914101b 100644 --- a/bitswap/network/network_adapter.go +++ b/exchange/bitswap/network/network_adapter.go @@ -5,7 +5,7 @@ import ( context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context" - bsmsg "github.com/jbenet/go-ipfs/bitswap/message" + bsmsg "github.com/jbenet/go-ipfs/exchange/bitswap/message" netmsg "github.com/jbenet/go-ipfs/net/message" peer "github.com/jbenet/go-ipfs/peer" ) diff --git a/bitswap/notifications/notifications.go b/exchange/bitswap/notifications/notifications.go similarity index 100% rename from bitswap/notifications/notifications.go rename to exchange/bitswap/notifications/notifications.go diff --git a/bitswap/notifications/notifications_test.go b/exchange/bitswap/notifications/notifications_test.go similarity index 100% rename from bitswap/notifications/notifications_test.go rename to exchange/bitswap/notifications/notifications_test.go diff --git a/bitswap/offline.go b/exchange/bitswap/offline.go similarity index 88% rename from bitswap/offline.go rename to exchange/bitswap/offline.go index d1c0fea1..46b71d27 100644 --- a/bitswap/offline.go +++ b/exchange/bitswap/offline.go @@ -5,10 +5,11 @@ import ( "time" blocks "github.com/jbenet/go-ipfs/blocks" + exchange "github.com/jbenet/go-ipfs/exchange" u "github.com/jbenet/go-ipfs/util" ) -func NewOfflineExchange() Exchange { +func NewOfflineExchange() exchange.Exchange { return &offlineExchange{} } diff --git a/bitswap/offline_test.go b/exchange/bitswap/offline_test.go similarity index 100% rename from bitswap/offline_test.go rename to exchange/bitswap/offline_test.go diff --git a/bitswap/strategy/interface.go b/exchange/bitswap/strategy/interface.go similarity index 94% rename from bitswap/strategy/interface.go rename to exchange/bitswap/strategy/interface.go index bfbfe599..8608c52c 100644 --- a/bitswap/strategy/interface.go +++ b/exchange/bitswap/strategy/interface.go @@ -1,7 +1,7 @@ package strategy import ( - bsmsg "github.com/jbenet/go-ipfs/bitswap/message" + bsmsg "github.com/jbenet/go-ipfs/exchange/bitswap/message" peer "github.com/jbenet/go-ipfs/peer" u "github.com/jbenet/go-ipfs/util" ) diff --git a/bitswap/strategy/ledger.go b/exchange/bitswap/strategy/ledger.go similarity index 100% rename from bitswap/strategy/ledger.go rename to exchange/bitswap/strategy/ledger.go diff --git a/bitswap/strategy/ledger_test.go b/exchange/bitswap/strategy/ledger_test.go similarity index 100% rename from bitswap/strategy/ledger_test.go rename to exchange/bitswap/strategy/ledger_test.go diff --git a/bitswap/strategy/math.go b/exchange/bitswap/strategy/math.go similarity index 100% rename from bitswap/strategy/math.go rename to exchange/bitswap/strategy/math.go diff --git a/bitswap/strategy/math_test.go b/exchange/bitswap/strategy/math_test.go similarity index 100% rename from bitswap/strategy/math_test.go rename to exchange/bitswap/strategy/math_test.go diff --git a/bitswap/strategy/strategy.go b/exchange/bitswap/strategy/strategy.go similarity index 97% rename from bitswap/strategy/strategy.go rename to exchange/bitswap/strategy/strategy.go index 4e9a6df3..20881156 100644 --- a/bitswap/strategy/strategy.go +++ b/exchange/bitswap/strategy/strategy.go @@ -3,7 +3,7 @@ package strategy import ( "errors" - bsmsg "github.com/jbenet/go-ipfs/bitswap/message" + bsmsg "github.com/jbenet/go-ipfs/exchange/bitswap/message" "github.com/jbenet/go-ipfs/peer" u "github.com/jbenet/go-ipfs/util" ) diff --git a/bitswap/strategy/strategy_test.go b/exchange/bitswap/strategy/strategy_test.go similarity index 100% rename from bitswap/strategy/strategy_test.go rename to exchange/bitswap/strategy/strategy_test.go diff --git a/bitswap/interface.go b/exchange/interface.go similarity index 100% rename from bitswap/interface.go rename to exchange/interface.go -- GitLab