@cryptotaxi247 / kubo / commits / 0b42d77e1

refactor(core, bitswap) split bitswap init into two steps

@jbenet

Brian Tiger Chow committed Oct 27, 2014 at 07:41 UTC 0b42d77e13a5143fba35c9cf34e9e0bd5ac61e3a
2 files changed +8 -9
core/core.go
+3 -2
@@ -15,6 +15,7 @@ import (
15 diag "github.com/jbenet/go-ipfs/diagnostics"
16 exchange "github.com/jbenet/go-ipfs/exchange"
17 bitswap "github.com/jbenet/go-ipfs/exchange/bitswap"
18 + bsnet "github.com/jbenet/go-ipfs/exchange/bitswap/network"
19 merkledag "github.com/jbenet/go-ipfs/merkledag"
20 namesys "github.com/jbenet/go-ipfs/namesys"
21 inet "github.com/jbenet/go-ipfs/net"
@@ -150,8 +151,8 @@ func NewIpfsNode(cfg *config.Config, online bool) (n *IpfsNode, err error) {
151
152 // setup exchange service
153 const alwaysSendToPeer = true // use YesManStrategy
153 - n.Exchange = bitswap.NetMessageSession(ctx, n.Identity, n.Network, exchangeService, n.Routing, n.Datastore, alwaysSendToPeer)
154 - // ok, this function call is ridiculous o/ consider making it simpler.
154 + bitswapNetwork := bsnet.NewFromIpfsNetwork(exchangeService, n.Network)
155 + n.Exchange = bitswap.New(ctx, n.Identity, bitswapNetwork, n.Routing, n.Datastore, alwaysSendToPeer)
156
157 go initConnections(ctx, n.Config, n.Peerstore, dhtRouting)
158 }
exchange/bitswap/bitswap.go
+5 -7
@@ -15,18 +15,18 @@ import (
15 bsnet "github.com/jbenet/go-ipfs/exchange/bitswap/network"
16 notifications "github.com/jbenet/go-ipfs/exchange/bitswap/notifications"
17 strategy "github.com/jbenet/go-ipfs/exchange/bitswap/strategy"
18 - inet "github.com/jbenet/go-ipfs/net"
18 peer "github.com/jbenet/go-ipfs/peer"
19 u "github.com/jbenet/go-ipfs/util"
20 )
21
22 var log = u.Logger("bitswap")
23
25 -// NetMessageSession initializes a BitSwap session that communicates over the
26 -// provided NetMessage service.
24 +// New initializes a BitSwap instance that communicates over the
25 +// provided BitSwapNetwork. This function registers the returned instance as
26 +// the network delegate.
27 // Runs until context is cancelled
28 -func NetMessageSession(ctx context.Context, p peer.Peer,
29 - net inet.Network, srv inet.Service, routing bsnet.Routing,
28 +func New(ctx context.Context, p peer.Peer,
29 + network bsnet.BitSwapNetwork, routing bsnet.Routing,
30 d ds.ThreadSafeDatastore, nice bool) exchange.Interface {
31
32 notif := notifications.New()
@@ -37,8 +37,6 @@ func NetMessageSession(ctx context.Context, p peer.Peer,
37 }
38 }()
39
40 - network := bsnet.NewFromIpfsNetwork(srv, net)
41 -
40 bs := &bitswap{
41 blockstore: blockstore.NewBlockstore(d),
42 notifications: notif,