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)
Brian Tiger Chow committed
Sep 18, 2014 at 17:09 UTC
fd086b9c48f82df73e790100d3dabdfc14148a29
24 files changed
+21
-18
blockservice/blockservice.go
+3
-3
@@ -5,8 +5,8 @@ import (
5
"time"
6
7
ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
8
- bitswap "github.com/jbenet/go-ipfs/bitswap"
8
blocks "github.com/jbenet/go-ipfs/blocks"
9
+ exchange "github.com/jbenet/go-ipfs/exchange"
10
u "github.com/jbenet/go-ipfs/util"
11
12
mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
@@ -16,11 +16,11 @@ import (
16
// It uses an internal `datastore.Datastore` instance to store values.
17
type BlockService struct {
18
Datastore ds.Datastore
19
- Remote bitswap.Exchange
19
+ Remote exchange.Exchange
20
}
21
22
// NewBlockService creates a BlockService with given datastore instance.
23
-func NewBlockService(d ds.Datastore, rem bitswap.Exchange) (*BlockService, error) {
23
+func NewBlockService(d ds.Datastore, rem exchange.Exchange) (*BlockService, error) {
24
if d == nil {
25
return nil, fmt.Errorf("BlockService requires valid datastore")
26
}
core/core.go
+4
-3
@@ -10,10 +10,11 @@ import (
10
b58 "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-base58"
11
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
12
13
- bitswap "github.com/jbenet/go-ipfs/bitswap"
13
bserv "github.com/jbenet/go-ipfs/blockservice"
14
config "github.com/jbenet/go-ipfs/config"
15
ci "github.com/jbenet/go-ipfs/crypto"
16
+ exchange "github.com/jbenet/go-ipfs/exchange"
17
+ bitswap "github.com/jbenet/go-ipfs/exchange/bitswap"
18
merkledag "github.com/jbenet/go-ipfs/merkledag"
19
inet "github.com/jbenet/go-ipfs/net"
20
mux "github.com/jbenet/go-ipfs/net/mux"
@@ -47,7 +48,7 @@ type IpfsNode struct {
48
Routing routing.IpfsRouting
49
50
// the block exchange + strategy (bitswap)
50
- BitSwap bitswap.Exchange
51
+ BitSwap exchange.Exchange
52
53
// the block service, get/add blocks.
54
Blocks *bserv.BlockService
@@ -88,7 +89,7 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) {
89
net inet.Network
90
// TODO: refactor so we can use IpfsRouting interface instead of being DHT-specific
91
route *dht.IpfsDHT
91
- exchangeSession bitswap.Exchange
92
+ exchangeSession exchange.Exchange
93
)
94
95
if online {
exchange/bitswap/bitswap.go
renamed
+7
-6
@@ -7,12 +7,13 @@ import (
7
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
8
ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
9
10
- bsmsg "github.com/jbenet/go-ipfs/bitswap/message"
11
- bsnet "github.com/jbenet/go-ipfs/bitswap/network"
12
- notifications "github.com/jbenet/go-ipfs/bitswap/notifications"
13
- strategy "github.com/jbenet/go-ipfs/bitswap/strategy"
10
blocks "github.com/jbenet/go-ipfs/blocks"
11
blockstore "github.com/jbenet/go-ipfs/blockstore"
12
+ exchange "github.com/jbenet/go-ipfs/exchange"
13
+ bsmsg "github.com/jbenet/go-ipfs/exchange/bitswap/message"
14
+ bsnet "github.com/jbenet/go-ipfs/exchange/bitswap/network"
15
+ notifications "github.com/jbenet/go-ipfs/exchange/bitswap/notifications"
16
+ strategy "github.com/jbenet/go-ipfs/exchange/bitswap/strategy"
17
peer "github.com/jbenet/go-ipfs/peer"
18
u "github.com/jbenet/go-ipfs/util"
19
)
@@ -37,7 +38,7 @@ type bitswap struct {
38
blockstore blockstore.Blockstore
39
40
// routing interface for communication
40
- routing Directory
41
+ routing exchange.Directory
42
43
notifications notifications.PubSub
44
@@ -48,7 +49,7 @@ type bitswap struct {
49
}
50
51
// NewSession initializes a bitswap session.
51
-func NewSession(parent context.Context, s bsnet.NetworkService, p *peer.Peer, d ds.Datastore, directory Directory) Exchange {
52
+func NewSession(parent context.Context, s bsnet.NetworkService, p *peer.Peer, d ds.Datastore, directory exchange.Directory) exchange.Exchange {
53
54
// FIXME(brian): instantiate a concrete Strategist
55
receiver := bsnet.Forwarder{}
exchange/bitswap/message/Makefile
renamed
exchange/bitswap/message/message.go
renamed
exchange/bitswap/message/message.pb.go
renamed
exchange/bitswap/message/message.proto
renamed
exchange/bitswap/message/message_test.go
renamed
exchange/bitswap/network/forwarder.go
renamed
+1
-1
@@ -2,7 +2,7 @@ package network
2
3
import (
4
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
5
- bsmsg "github.com/jbenet/go-ipfs/bitswap/message"
5
+ bsmsg "github.com/jbenet/go-ipfs/exchange/bitswap/message"
6
peer "github.com/jbenet/go-ipfs/peer"
7
)
8
exchange/bitswap/network/forwarder_test.go
renamed
exchange/bitswap/network/interface.go
renamed
+1
-1
@@ -4,7 +4,7 @@ import (
4
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
5
netservice "github.com/jbenet/go-ipfs/net/service"
6
7
- bsmsg "github.com/jbenet/go-ipfs/bitswap/message"
7
+ bsmsg "github.com/jbenet/go-ipfs/exchange/bitswap/message"
8
netmsg "github.com/jbenet/go-ipfs/net/message"
9
peer "github.com/jbenet/go-ipfs/peer"
10
)
exchange/bitswap/network/network_adapter.go
renamed
+1
-1
@@ -5,7 +5,7 @@ import (
5
6
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
7
8
- bsmsg "github.com/jbenet/go-ipfs/bitswap/message"
8
+ bsmsg "github.com/jbenet/go-ipfs/exchange/bitswap/message"
9
netmsg "github.com/jbenet/go-ipfs/net/message"
10
peer "github.com/jbenet/go-ipfs/peer"
11
)
exchange/bitswap/notifications/notifications.go
renamed
exchange/bitswap/notifications/notifications_test.go
renamed
exchange/bitswap/offline.go
renamed
+2
-1
@@ -5,10 +5,11 @@ import (
5
"time"
6
7
blocks "github.com/jbenet/go-ipfs/blocks"
8
+ exchange "github.com/jbenet/go-ipfs/exchange"
9
u "github.com/jbenet/go-ipfs/util"
10
)
11
11
-func NewOfflineExchange() Exchange {
12
+func NewOfflineExchange() exchange.Exchange {
13
return &offlineExchange{}
14
}
15
exchange/bitswap/offline_test.go
renamed
exchange/bitswap/strategy/interface.go
renamed
+1
-1
@@ -1,7 +1,7 @@
1
package strategy
2
3
import (
4
- bsmsg "github.com/jbenet/go-ipfs/bitswap/message"
4
+ bsmsg "github.com/jbenet/go-ipfs/exchange/bitswap/message"
5
peer "github.com/jbenet/go-ipfs/peer"
6
u "github.com/jbenet/go-ipfs/util"
7
)
exchange/bitswap/strategy/ledger.go
renamed
exchange/bitswap/strategy/ledger_test.go
renamed
exchange/bitswap/strategy/math.go
renamed
exchange/bitswap/strategy/math_test.go
renamed
exchange/bitswap/strategy/strategy.go
renamed
+1
-1
@@ -3,7 +3,7 @@ package strategy
3
import (
4
"errors"
5
6
- bsmsg "github.com/jbenet/go-ipfs/bitswap/message"
6
+ bsmsg "github.com/jbenet/go-ipfs/exchange/bitswap/message"
7
"github.com/jbenet/go-ipfs/peer"
8
u "github.com/jbenet/go-ipfs/util"
9
)