interface.go 1.57 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
		destination *peer.Peer, outgoing bsmsg.BitSwapMessage, err error)
37
}
38 39

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

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

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