Commit 89304239 authored by Brian Tiger Chow's avatar Brian Tiger Chow

style(exch:bitswap) rename adapter, session, etc.

style(exch:bitswap) rename NetMessage adapter impl
parent 619a9470
......@@ -24,10 +24,11 @@ type Routing interface {
Provide(key u.Key) error
}
// NewSession initializes a bitswap session.
func NewSession(parent context.Context, s bsnet.NetworkService, p *peer.Peer, d ds.Datastore, directory Routing) exchange.Interface {
// NetMessageSession initializes a BitSwap session that communicates over the
// provided NetMessage service
func NetMessageSession(parent context.Context, s bsnet.NetMessageService, p *peer.Peer, d ds.Datastore, directory Routing) exchange.Interface {
networkAdapter := bsnet.NewNetworkAdapter(s, nil)
networkAdapter := bsnet.NetMessageAdapter(s, nil)
bs := &bitswap{
blockstore: blockstore.NewBlockstore(d),
notifications: notifications.New(),
......@@ -44,7 +45,7 @@ func NewSession(parent context.Context, s bsnet.NetworkService, p *peer.Peer, d
type bitswap struct {
// sender delivers messages on behalf of the session
sender bsnet.NetworkAdapter
sender bsnet.Adapter
// blockstore is the local database
// NB: ensure threadsafety
......
......@@ -9,8 +9,8 @@ import (
peer "github.com/jbenet/go-ipfs/peer"
)
// NetworkAdapter mediates the exchange's communication with the network.
type NetworkAdapter interface {
// Adapter provides network connectivity for BitSwap sessions
type Adapter interface {
// SendMessage sends a BitSwap message to a peer.
SendMessage(
......@@ -36,7 +36,7 @@ type Receiver interface {
}
// TODO(brian): move this to go-ipfs/net package
type NetworkService interface {
type NetMessageService interface {
SendRequest(ctx context.Context, m netmsg.NetMessage) (netmsg.NetMessage, error)
SendMessage(ctx context.Context, m netmsg.NetMessage) error
SetHandler(netservice.Handler)
......
......@@ -10,27 +10,27 @@ import (
peer "github.com/jbenet/go-ipfs/peer"
)
// NewSender wraps a network Service to perform translation between
// BitSwapMessage and NetMessage formats. This allows the BitSwap session to
// ignore these details.
func NewNetworkAdapter(s NetworkService, r Receiver) NetworkAdapter {
adapter := networkAdapter{
networkService: s,
// NetMessageAdapter wraps a NetMessage network service
func NetMessageAdapter(s NetMessageService, r Receiver) Adapter {
adapter := impl{
nms: s,
receiver: r,
}
s.SetHandler(&adapter)
return &adapter
}
// networkAdapter implements NetworkAdapter
type networkAdapter struct {
networkService NetworkService
// implements an Adapter that integrates with a NetMessage network service
type impl struct {
nms NetMessageService
// inbound messages from the network are forwarded to the receiver
receiver Receiver
}
// HandleMessage marshals and unmarshals net messages, forwarding them to the
// BitSwapMessage receiver
func (adapter *networkAdapter) HandleMessage(
func (adapter *impl) HandleMessage(
ctx context.Context, incoming netmsg.NetMessage) (netmsg.NetMessage, error) {
if adapter.receiver == nil {
......@@ -60,7 +60,7 @@ func (adapter *networkAdapter) HandleMessage(
return outgoing, nil
}
func (adapter *networkAdapter) SendMessage(
func (adapter *impl) SendMessage(
ctx context.Context,
p *peer.Peer,
outgoing bsmsg.BitSwapMessage) error {
......@@ -69,10 +69,10 @@ func (adapter *networkAdapter) SendMessage(
if err != nil {
return err
}
return adapter.networkService.SendMessage(ctx, nmsg)
return adapter.nms.SendMessage(ctx, nmsg)
}
func (adapter *networkAdapter) SendRequest(
func (adapter *impl) SendRequest(
ctx context.Context,
p *peer.Peer,
outgoing bsmsg.BitSwapMessage) (bsmsg.BitSwapMessage, error) {
......@@ -81,13 +81,13 @@ func (adapter *networkAdapter) SendRequest(
if err != nil {
return nil, err
}
incomingMsg, err := adapter.networkService.SendRequest(ctx, outgoingMsg)
incomingMsg, err := adapter.nms.SendRequest(ctx, outgoingMsg)
if err != nil {
return nil, err
}
return bsmsg.FromNet(incomingMsg)
}
func (adapter *networkAdapter) SetDelegate(r Receiver) {
func (adapter *impl) SetDelegate(r Receiver) {
adapter.receiver = r
}
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