Documentation ¶
Overview ¶
Package dht implements a distributed hash table that satisfies the ipfs routing interface. This DHT is modeled after kademlia with S/Kademlia modifications.
Package dht implements a distributed hash table that satisfies the ipfs routing interface. This DHT is modeled after Kademlia with S/Kademlia modifications.
package query implement a query manager to drive concurrent workers to query the DHT. A query is setup with a target key, a queryFunc tasked to communicate with a peer, and a set of initial peers. As the query progress, queryFunc can return closer peers that will be used to navigate closer to the target key in the DHT until an answer is reached.
Index ¶
- Constants
- Variables
- func Quorum(n int) ropts.Option
- type BootstrapConfig
- type IpfsDHT
- func (dht *IpfsDHT) Bootstrap(ctx context.Context) error
- func (dht *IpfsDHT) BootstrapOnSignal(cfg BootstrapConfig, signal <-chan time.Time) (goprocess.Process, error)
- func (dht *IpfsDHT) BootstrapWithConfig(cfg BootstrapConfig) (goprocess.Process, error)
- func (dht *IpfsDHT) Close() error
- func (dht *IpfsDHT) Context() context.Context
- func (dht *IpfsDHT) FindLocal(id peer.ID) pstore.PeerInfo
- func (dht *IpfsDHT) FindPeer(ctx context.Context, id peer.ID) (_ pstore.PeerInfo, err error)
- func (dht *IpfsDHT) FindPeersConnectedToPeer(ctx context.Context, id peer.ID) (<-chan *pstore.PeerInfo, error)
- func (dht *IpfsDHT) FindProviders(ctx context.Context, c cid.Cid) ([]pstore.PeerInfo, error)
- func (dht *IpfsDHT) FindProvidersAsync(ctx context.Context, key cid.Cid, count int) <-chan pstore.PeerInfo
- func (dht *IpfsDHT) GetClosestPeers(ctx context.Context, key string) (<-chan peer.ID, error)
- func (dht *IpfsDHT) GetPublicKey(ctx context.Context, p peer.ID) (ci.PubKey, error)
- func (dht *IpfsDHT) GetValue(ctx context.Context, key string, opts ...ropts.Option) (_ []byte, err error)
- func (dht *IpfsDHT) GetValues(ctx context.Context, key string, nvals int) (_ []RecvdVal, err error)
- func (dht *IpfsDHT) Process() goprocess.Process
- func (dht *IpfsDHT) Provide(ctx context.Context, key cid.Cid, brdcst bool) (err error)
- func (dht *IpfsDHT) PutValue(ctx context.Context, key string, value []byte, opts ...ropts.Option) (err error)
- func (dht *IpfsDHT) RoutingTable() *kb.RoutingTable
- func (dht *IpfsDHT) SearchValue(ctx context.Context, key string, opts ...ropts.Option) (<-chan []byte, error)
- func (dht *IpfsDHT) Update(ctx context.Context, p peer.ID)
- type RecvdVal
Constants ¶
const MaxRecordAge = time.Hour * 36
MaxRecordAge specifies the maximum time that any node will hold onto a record from the time its received. This does not apply to any other forms of validity that the record may contain. For example, a record may contain an ipns entry with an EOL saying its valid until the year 2020 (a great time in the future). For that record to stick around it must be rebroadcasted more frequently than once every 'MaxRecordAge'
const NumBootstrapQueries = 5
NumBootstrapQueries defines the number of random dht queries to do to collect members of the routing table.
Variables ¶
var AlphaValue = 3
Alpha is the concurrency factor for asynchronous requests.
var CloserPeerCount = KValue
The number of closer peers to send on requests.
var DefaultBootstrapConfig = BootstrapConfig{ Queries: 1, Period: time.Duration(2 * time.Minute), Timeout: time.Duration(10 * time.Second), }
var ErrReadTimeout = fmt.Errorf("timed out reading response")
var KValue = 16
K is the maximum number of requests to perform before returning failure.
var PoolSize = 6
Pool size is the number of nodes used for group find/set RPC calls
Functions ¶
Types ¶
type BootstrapConfig ¶
type BootstrapConfig struct { Queries int // how many queries to run per period Period time.Duration // how often to run periodic bootstrap. Timeout time.Duration // how long to wait for a bootstrap query to run }
BootstrapConfig specifies parameters used bootstrapping the DHT.
Note there is a tradeoff between the bootstrap period and the number of queries. We could support a higher period with less queries.
type IpfsDHT ¶
IpfsDHT is an implementation of Kademlia with S/Kademlia modifications. It is used to implement the base IpfsRouting module.
func NewDHT ¶
NewDHT creates a new DHT object with the given peer as the 'local' host. IpfsDHT's initialized with this function will respond to DHT requests, whereas IpfsDHT's initialized with NewDHTClient will not.
func NewDHTClient ¶
NewDHTClient creates a new DHT object with the given peer as the 'local' host. IpfsDHT clients initialized with this function will not respond to DHT requests. If you need a peer to respond to DHT requests, use NewDHT instead. NewDHTClient creates a new DHT object with the given peer as the 'local' host
func (*IpfsDHT) Bootstrap ¶
Bootstrap ensures the dht routing table remains healthy as peers come and go. it builds up a list of peers by requesting random peer IDs. The Bootstrap process will run a number of queries each time, and run every time signal fires. These parameters are configurable.
As opposed to BootstrapWithConfig, Bootstrap satisfies the routing interface
func (*IpfsDHT) BootstrapOnSignal ¶
func (dht *IpfsDHT) BootstrapOnSignal(cfg BootstrapConfig, signal <-chan time.Time) (goprocess.Process, error)
SignalBootstrap ensures the dht routing table remains healthy as peers come and go. it builds up a list of peers by requesting random peer IDs. The Bootstrap process will run a number of queries each time, and run every time signal fires. These parameters are configurable.
SignalBootstrap returns a process, so the user can stop it.
func (*IpfsDHT) BootstrapWithConfig ¶
func (dht *IpfsDHT) BootstrapWithConfig(cfg BootstrapConfig) (goprocess.Process, error)
BootstrapWithConfig ensures the dht routing table remains healthy as peers come and go. it builds up a list of peers by requesting random peer IDs. The Bootstrap process will run a number of queries each time, and run every time signal fires. These parameters are configurable.
BootstrapWithConfig returns a process, so the user can stop it.
func (*IpfsDHT) FindLocal ¶
FindLocal looks for a peer with a given ID connected to this dht and returns the peer and the table it was found in.
func (*IpfsDHT) FindPeersConnectedToPeer ¶
func (dht *IpfsDHT) FindPeersConnectedToPeer(ctx context.Context, id peer.ID) (<-chan *pstore.PeerInfo, error)
FindPeersConnectedToPeer searches for peers directly connected to a given peer.
func (*IpfsDHT) FindProviders ¶
FindProviders searches until the context expires.
func (*IpfsDHT) FindProvidersAsync ¶
func (dht *IpfsDHT) FindProvidersAsync(ctx context.Context, key cid.Cid, count int) <-chan pstore.PeerInfo
FindProvidersAsync is the same thing as FindProviders, but returns a channel. Peers will be returned on the channel as soon as they are found, even before the search query completes.
func (*IpfsDHT) GetClosestPeers ¶
Kademlia 'node lookup' operation. Returns a channel of the K closest peers to the given key
func (*IpfsDHT) GetPublicKey ¶
func (*IpfsDHT) GetValue ¶
func (dht *IpfsDHT) GetValue(ctx context.Context, key string, opts ...ropts.Option) (_ []byte, err error)
GetValue searches for the value corresponding to given Key.
func (*IpfsDHT) Provide ¶
Provide makes this node announce that it can provide a value for the given key
func (*IpfsDHT) PutValue ¶
func (dht *IpfsDHT) PutValue(ctx context.Context, key string, value []byte, opts ...ropts.Option) (err error)
PutValue adds value corresponding to given Key. This is the top level "Store" operation of the DHT
func (*IpfsDHT) RoutingTable ¶
func (dht *IpfsDHT) RoutingTable() *kb.RoutingTable
RoutingTable return dht's routingTable