routing.go 1.11 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
	"time"

6 7
	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
8 9
	peer "github.com/jbenet/go-ipfs/peer"
	u "github.com/jbenet/go-ipfs/util"
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
10
)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
11

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

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
17
	// Basic Put/Get
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
18

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
19 20
	// PutValue adds value corresponding to given Key.
	PutValue(key u.Key, value []byte) error
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
21

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
22 23
	// GetValue searches for the value corresponding to given Key.
	GetValue(key u.Key, timeout time.Duration) ([]byte, error)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
24

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
25 26
	// 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
27

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
28 29
	// Announce that this node can provide value for given key
	Provide(key u.Key) error
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
30

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
31
	// FindProviders searches for peers who can provide the value for given key.
32
	FindProviders(key u.Key, timeout time.Duration) ([]*peer.Peer, error)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
33

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
34
	// Find specific Peer
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
35

Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
36 37
	// FindPeer searches for a peer with given ID.
	FindPeer(id peer.ID, timeout time.Duration) (*peer.Peer, error)
Juan Batiz-Benet's avatar
Juan Batiz-Benet committed
38
}