interface.go 1.38 KB
Newer Older
1 2 3 4 5 6
package network

import (
	context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"

	bsmsg "github.com/jbenet/go-ipfs/exchange/bitswap/message"
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
7
	peer "github.com/jbenet/go-ipfs/p2p/peer"
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
8
	protocol "github.com/jbenet/go-ipfs/p2p/protocol"
9
	u "github.com/jbenet/go-ipfs/util"
10 11
)

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

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

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

	// SendRequest sends a BitSwap message to a peer and waits for a response.
	SendRequest(
		context.Context,
26
		peer.ID,
27 28 29 30 31
		bsmsg.BitSwapMessage) (incoming bsmsg.BitSwapMessage, err error)

	// SetDelegate registers the Reciver to handle messages received from the
	// network.
	SetDelegate(Receiver)
32 33

	Routing
34 35
}

36
// Implement Receiver to receive messages from the BitSwapNetwork
37 38
type Receiver interface {
	ReceiveMessage(
39 40
		ctx context.Context, sender peer.ID, incoming bsmsg.BitSwapMessage) (
		destination peer.ID, outgoing bsmsg.BitSwapMessage)
41 42

	ReceiveError(error)
43 44
}

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

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