mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-11 19:27:51 +08:00
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)
This commit is contained in:
parent
79705729f8
commit
fd086b9c48
@ -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")
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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{}
|
||||
@ -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"
|
||||
)
|
||||
|
||||
@ -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"
|
||||
)
|
||||
@ -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"
|
||||
)
|
||||
@ -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{}
|
||||
}
|
||||
|
||||
@ -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"
|
||||
)
|
||||
@ -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"
|
||||
)
|
||||
Loading…
Reference in New Issue
Block a user