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

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

6
	bsmsg "github.com/jbenet/go-ipfs/exchange/bitswap/message"
7
	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.Peer) 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.Peer,
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.Peer,
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
}

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

	ReceiveError(error)
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.Peer
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
}