interface.go 1.24 KB
Newer Older
1 2 3
package network

import (
4 5 6 7 8
	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"
9 10
)

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
11 12
var ProtocolBitswap protocol.ID = "/ipfs/bitswap"

13 14
// BitSwapNetwork provides network connectivity for BitSwap sessions
type BitSwapNetwork interface {
15 16 17 18

	// SendMessage sends a BitSwap message to a peer.
	SendMessage(
		context.Context,
19
		peer.ID,
20 21 22 23 24
		bsmsg.BitSwapMessage) error

	// SetDelegate registers the Reciver to handle messages received from the
	// network.
	SetDelegate(Receiver)
25 26

	Routing
27 28
}

29
// Implement Receiver to receive messages from the BitSwapNetwork
30 31
type Receiver interface {
	ReceiveMessage(
Jeromy Johnson's avatar
Jeromy Johnson committed
32 33 34
		ctx context.Context,
		sender peer.ID,
		incoming bsmsg.BitSwapMessage) error
35 36

	ReceiveError(error)
37 38 39 40

	// Connected/Disconnected warns bitswap about peer connections
	PeerConnected(peer.ID)
	PeerDisconnected(peer.ID)
41 42
}

43 44
type Routing interface {
	// FindProvidersAsync returns a channel of providers for the given key
45
	FindProvidersAsync(context.Context, u.Key, int) <-chan peer.ID
46 47

	// Provide provides the key to the network
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
48
	Provide(context.Context, u.Key) error
49
}