interface.go 1.37 KB
Newer Older
1 2 3 4 5 6 7
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"
	peer "github.com/jbenet/go-ipfs/peer"
8
	u "github.com/jbenet/go-ipfs/util"
9 10
)

11 12
// BitSwapNetwork provides network connectivity for BitSwap sessions
type BitSwapNetwork interface {
13

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
14
	// DialPeer ensures there is a connection to peer.
15
	DialPeer(context.Context, peer.ID) error
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
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
}