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

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

7
	bsmsg "github.com/jbenet/go-ipfs/exchange/bitswap/message"
8
	netmsg "github.com/jbenet/go-ipfs/net/message"
9
	peer "github.com/jbenet/go-ipfs/peer"
10
	u "github.com/jbenet/go-ipfs/util"
11 12
)

13 14
// Adapter provides network connectivity for BitSwap sessions
type Adapter interface {
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

	// SendMessage sends a BitSwap message to a peer.
	SendMessage(
		context.Context,
		*peer.Peer,
		bsmsg.BitSwapMessage) error

	// SendRequest sends a BitSwap message to a peer and waits for a response.
	SendRequest(
		context.Context,
		*peer.Peer,
		bsmsg.BitSwapMessage) (incoming bsmsg.BitSwapMessage, err error)

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

type Receiver interface {
34 35
	ReceiveMessage(
		ctx context.Context, sender *peer.Peer, incoming bsmsg.BitSwapMessage) (
36 37 38
		destination *peer.Peer, outgoing bsmsg.BitSwapMessage)

	ReceiveError(error)
39
}
40 41

// TODO(brian): move this to go-ipfs/net package
42
type NetMessageService interface {
43 44 45 46
	SendRequest(ctx context.Context, m netmsg.NetMessage) (netmsg.NetMessage, error)
	SendMessage(ctx context.Context, m netmsg.NetMessage) error
	SetHandler(netservice.Handler)
}
47 48 49 50

// TODO rename -> Router?
type Routing interface {
	// FindProvidersAsync returns a channel of providers for the given key
51
	FindProvidersAsync(context.Context, u.Key, int) <-chan *peer.Peer
52 53

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