kubo/exchange/bitswap/network/interface.go
Ho-Sheng Hsiao bf22aeec0a Reorged imports from jbenet/go-ipfs to ipfs/go-ipfs
- Modified Godeps/Godeps.json by hand
- [TEST] Updated welcome docs hash to sharness
- [TEST] Updated contact doc
- [TEST] disabled breaking test (t0080-repo refs local)
2015-03-31 12:52:25 -07:00

55 lines
1.5 KiB
Go

package network
import (
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
bsmsg "github.com/ipfs/go-ipfs/exchange/bitswap/message"
peer "github.com/ipfs/go-ipfs/p2p/peer"
protocol "github.com/ipfs/go-ipfs/p2p/protocol"
u "github.com/ipfs/go-ipfs/util"
)
var ProtocolBitswap protocol.ID = "/ipfs/bitswap"
// BitSwapNetwork provides network connectivity for BitSwap sessions
type BitSwapNetwork interface {
// SendMessage sends a BitSwap message to a peer.
SendMessage(
context.Context,
peer.ID,
bsmsg.BitSwapMessage) error
// SendRequest sends a BitSwap message to a peer and waits for a response.
SendRequest(
context.Context,
peer.ID,
bsmsg.BitSwapMessage) (incoming bsmsg.BitSwapMessage, err error)
// SetDelegate registers the Reciver to handle messages received from the
// network.
SetDelegate(Receiver)
Routing
}
// Implement Receiver to receive messages from the BitSwapNetwork
type Receiver interface {
ReceiveMessage(
ctx context.Context, sender peer.ID, incoming bsmsg.BitSwapMessage) (
destination peer.ID, outgoing bsmsg.BitSwapMessage)
ReceiveError(error)
// Connected/Disconnected warns bitswap about peer connections
PeerConnected(peer.ID)
PeerDisconnected(peer.ID)
}
type Routing interface {
// FindProvidersAsync returns a channel of providers for the given key
FindProvidersAsync(context.Context, u.Key, int) <-chan peer.ID
// Provide provides the key to the network
Provide(context.Context, u.Key) error
}