routing.go 1.09 KB
Newer Older
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
1 2
package routing

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
3
import (
4 5
	context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
6 7
	peer "github.com/jbenet/go-ipfs/peer"
	u "github.com/jbenet/go-ipfs/util"
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
8
)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
9

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
10 11 12
// IpfsRouting is the routing module interface
// It is implemented by things like DHTs, etc.
type IpfsRouting interface {
13
	FindProvidersAsync(context.Context, u.Key, int) <-chan *peer.Peer
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
14

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
15
	// Basic Put/Get
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
16

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
17
	// PutValue adds value corresponding to given Key.
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
18
	PutValue(context.Context, u.Key, []byte) error
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
19

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
20
	// GetValue searches for the value corresponding to given Key.
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
21
	GetValue(context.Context, u.Key) ([]byte, error)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
22

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
23 24
	// Value provider layer of indirection.
	// This is what DSHTs (Coral and MainlineDHT) do to store large values in a DHT.
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
25

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
26
	// Announce that this node can provide value for given key
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
27
	Provide(context.Context, u.Key) error
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
28

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
29
	// FindProviders searches for peers who can provide the value for given key.
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
30
	FindProviders(context.Context, u.Key) ([]*peer.Peer, error)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
31

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
32
	// Find specific Peer
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
33

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
34
	// FindPeer searches for a peer with given ID.
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
35
	FindPeer(context.Context, peer.ID) (*peer.Peer, error)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
36
}