kubo/exchange/bitswap/network/interface.go
Brian Tiger Chow fd086b9c48 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)
2014-09-22 04:06:13 -07:00

44 lines
1.3 KiB
Go

package network
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/exchange/bitswap/message"
netmsg "github.com/jbenet/go-ipfs/net/message"
peer "github.com/jbenet/go-ipfs/peer"
)
// NetworkAdapter mediates the exchange's communication with the network.
type NetworkAdapter interface {
// SendMessage sends a BitSwap message to a peer.
SendMessage(
context.Context,
*peer.Peer,
bsmsg.BitSwapMessage) error
// SendRequest sends a BitSwap message to a peer and waits for a response.
SendRequest(
context.Context,
*peer.Peer,
bsmsg.BitSwapMessage) (incoming bsmsg.BitSwapMessage, err error)
// SetDelegate registers the Reciver to handle messages received from the
// network.
SetDelegate(Receiver)
}
type Receiver interface {
ReceiveMessage(
ctx context.Context, sender *peer.Peer, incoming bsmsg.BitSwapMessage) (
destination *peer.Peer, outgoing bsmsg.BitSwapMessage, err error)
}
// TODO(brian): move this to go-ipfs/net package
type NetworkService interface {
SendRequest(ctx context.Context, m netmsg.NetMessage) (netmsg.NetMessage, error)
SendMessage(ctx context.Context, m netmsg.NetMessage) error
SetHandler(netservice.Handler)
}