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

wip(bitswap) port service wrapper

parent fda94d9f
......@@ -11,6 +11,7 @@ import (
notifications "github.com/jbenet/go-ipfs/bitswap/notifications"
tx "github.com/jbenet/go-ipfs/bitswap/transmission"
blocks "github.com/jbenet/go-ipfs/blocks"
net "github.com/jbenet/go-ipfs/net"
peer "github.com/jbenet/go-ipfs/peer"
routing "github.com/jbenet/go-ipfs/routing"
u "github.com/jbenet/go-ipfs/util"
......@@ -61,14 +62,14 @@ type BitSwap struct {
}
// 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
// fall under bitswap's purview
ctx, _ := context.WithCancel(parent)
// ctx, _ := context.WithCancel(parent)
receiver := tx.Forwarder{}
sender := tx.NewServiceWrapper(ctx, &receiver)
sender := tx.NewSender(s)
bs := &BitSwap{
peer: p,
datastore: d,
......
......@@ -4,21 +4,20 @@ 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"
inet "github.com/jbenet/go-ipfs/net"
net "github.com/jbenet/go-ipfs/net"
netmsg "github.com/jbenet/go-ipfs/net/message"
netservice "github.com/jbenet/go-ipfs/net/service"
peer "github.com/jbenet/go-ipfs/peer"
)
// NewServiceWrapper handles protobuf marshalling
func NewServiceWrapper(ctx context.Context, r Receiver) Sender {
h := &handlerWrapper{r}
s := netservice.NewService(h)
s.Start(ctx)
// NewSender wraps the net.service.Sender to perform translation between
// BitSwapMessage and NetMessage formats. This allows the BitSwap session to
// ignore these details.
func NewSender(s net.Sender) Sender {
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.
type handlerWrapper struct {
bitswapDelegate Receiver
......@@ -51,7 +50,7 @@ func (wrapper *handlerWrapper) HandleMessage(
}
type senderWrapper struct {
serviceDelegate inet.Sender
serviceDelegate net.Sender
}
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