Commit 06b5804d authored by Brian Tiger Chow's avatar Brian Tiger Chow

wip(bitswap) port service wrapper

parent fda94d9f
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
notifications "github.com/jbenet/go-ipfs/bitswap/notifications" notifications "github.com/jbenet/go-ipfs/bitswap/notifications"
tx "github.com/jbenet/go-ipfs/bitswap/transmission" tx "github.com/jbenet/go-ipfs/bitswap/transmission"
blocks "github.com/jbenet/go-ipfs/blocks" blocks "github.com/jbenet/go-ipfs/blocks"
net "github.com/jbenet/go-ipfs/net"
peer "github.com/jbenet/go-ipfs/peer" peer "github.com/jbenet/go-ipfs/peer"
routing "github.com/jbenet/go-ipfs/routing" routing "github.com/jbenet/go-ipfs/routing"
u "github.com/jbenet/go-ipfs/util" u "github.com/jbenet/go-ipfs/util"
...@@ -61,14 +62,14 @@ type BitSwap struct { ...@@ -61,14 +62,14 @@ type BitSwap struct {
} }
// NewSession initializes a bitswap session. // NewSession initializes a bitswap session.
func NewSession(parent context.Context, p *peer.Peer, d ds.Datastore, r routing.IpfsRouting) *BitSwap { func NewSession(parent context.Context, s net.Sender, p *peer.Peer, d ds.Datastore, r routing.IpfsRouting) *BitSwap {
// TODO(brian): define a contract for management of async operations that // TODO(brian): define a contract for management of async operations that
// fall under bitswap's purview // fall under bitswap's purview
ctx, _ := context.WithCancel(parent) // ctx, _ := context.WithCancel(parent)
receiver := tx.Forwarder{} receiver := tx.Forwarder{}
sender := tx.NewServiceWrapper(ctx, &receiver) sender := tx.NewSender(s)
bs := &BitSwap{ bs := &BitSwap{
peer: p, peer: p,
datastore: d, datastore: d,
......
...@@ -4,21 +4,20 @@ import ( ...@@ -4,21 +4,20 @@ import (
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context" 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/bitswap/message"
inet "github.com/jbenet/go-ipfs/net" net "github.com/jbenet/go-ipfs/net"
netmsg "github.com/jbenet/go-ipfs/net/message" netmsg "github.com/jbenet/go-ipfs/net/message"
netservice "github.com/jbenet/go-ipfs/net/service"
peer "github.com/jbenet/go-ipfs/peer" peer "github.com/jbenet/go-ipfs/peer"
) )
// NewServiceWrapper handles protobuf marshalling // NewSender wraps the net.service.Sender to perform translation between
func NewServiceWrapper(ctx context.Context, r Receiver) Sender { // BitSwapMessage and NetMessage formats. This allows the BitSwap session to
h := &handlerWrapper{r} // ignore these details.
s := netservice.NewService(h) func NewSender(s net.Sender) Sender {
s.Start(ctx)
return &senderWrapper{s} return &senderWrapper{s}
} }
// handlerWrapper is responsible for marshaling/unmarshaling NetMessages. It // handlerWrapper implements the net.service.Handler interface. It is
// responsible for converting between
// delegates calls to the BitSwap delegate. // delegates calls to the BitSwap delegate.
type handlerWrapper struct { type handlerWrapper struct {
bitswapDelegate Receiver bitswapDelegate Receiver
...@@ -51,7 +50,7 @@ func (wrapper *handlerWrapper) HandleMessage( ...@@ -51,7 +50,7 @@ func (wrapper *handlerWrapper) HandleMessage(
} }
type senderWrapper struct { type senderWrapper struct {
serviceDelegate inet.Sender serviceDelegate net.Sender
} }
func (wrapper *senderWrapper) SendMessage( func (wrapper *senderWrapper) SendMessage(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment