kubo/exchange/bitswap/network/interface.go
Jeromy f4d7369c4a bitswap: protocol extension to handle cids
This change adds the /ipfs/bitswap/1.1.0 protocol. The new protocol
adds a 'payload' field to the protobuf message and deprecates the
existing 'blocks' field. The 'payload' field is an array of pairs of cid
prefixes and block data. The cid prefixes are used to ensure the correct
codecs and hash functions are used to handle the block on the receiving
end.

License: MIT
Signed-off-by: Jeromy <why@ipfs.io>
2016-10-10 08:19:31 -07:00

66 lines
1.6 KiB
Go

package network
import (
"context"
bsmsg "github.com/ipfs/go-ipfs/exchange/bitswap/message"
cid "gx/ipfs/QmXUuRadqDq5BuFWzVU6VuKaSjTcNm1gNCtLvvP1TJCW4z/go-cid"
protocol "gx/ipfs/QmZNkThpqfVXs9GNbexPrfBbXSLNYeKrE7jwFM2oqHbyqN/go-libp2p-protocol"
peer "gx/ipfs/QmfMmLGoKzCHDN7cGgk64PJr4iipzidDRME8HABSJqvmhC/go-libp2p-peer"
)
var (
// These two are equivalent, legacy
ProtocolBitswapOne protocol.ID = "/ipfs/bitswap/1.0.0"
ProtocolBitswapNoVers protocol.ID = "/ipfs/bitswap"
ProtocolBitswap protocol.ID = "/ipfs/bitswap/1.1.0"
)
// 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
// SetDelegate registers the Reciver to handle messages received from the
// network.
SetDelegate(Receiver)
ConnectTo(context.Context, peer.ID) error
NewMessageSender(context.Context, peer.ID) (MessageSender, error)
Routing
}
type MessageSender interface {
SendMsg(bsmsg.BitSwapMessage) error
Close() error
}
// Implement Receiver to receive messages from the BitSwapNetwork
type Receiver interface {
ReceiveMessage(
ctx context.Context,
sender peer.ID,
incoming 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, *cid.Cid, int) <-chan peer.ID
// Provide provides the key to the network
Provide(context.Context, *cid.Cid) error
}