interface.go 1.36 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 32 33
		bsmsg.BitSwapMessage) (incoming bsmsg.BitSwapMessage, err error)

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

34
// Implement Receiver to receive messages from the BitSwapNetwork
35 36
type Receiver interface {
	ReceiveMessage(
37 38
		ctx context.Context, sender peer.ID, incoming bsmsg.BitSwapMessage) (
		destination peer.ID, 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.PeerInfo
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
}