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

import (
4
	key "github.com/ipfs/go-ipfs/blocks/key"
5
	bsmsg "github.com/ipfs/go-ipfs/exchange/bitswap/message"
Jeromy's avatar
Jeromy committed
6
	peer "gx/ipfs/QmQGwpJy9P4yXZySmqkZEXCmbBpJUb8xntCv8Ca4taZwDC/go-libp2p-peer"
Jeromy's avatar
Jeromy committed
7
	protocol "gx/ipfs/QmXJBB9U6e6ennAJPzk8E2rSaVGuHVR2jCxE9H9gPDtRrq/go-libp2p/p2p/protocol"
Jeromy's avatar
Jeromy committed
8
	context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
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 27
	ConnectTo(context.Context, peer.ID) error

28
	Routing
29 30
}

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

	ReceiveError(error)
39 40 41 42

	// Connected/Disconnected warns bitswap about peer connections
	PeerConnected(peer.ID)
	PeerDisconnected(peer.ID)
43 44
}

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

	// Provide provides the key to the network
50
	Provide(context.Context, key.Key) error
51
}