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.
Index ¶
- Constants
- Variables
- func Quorum(n int) routing.Option
- type IpfsDHT
- func (dht *IpfsDHT) Bootstrap(_ context.Context) error
- func (dht *IpfsDHT) Close() error
- func (dht *IpfsDHT) Context() context.Context
- func (dht *IpfsDHT) FindLocal(id peer.ID) peer.AddrInfo
- func (dht *IpfsDHT) FindPeer(ctx context.Context, id peer.ID) (_ peer.AddrInfo, err error)
- func (dht *IpfsDHT) FindPeersConnectedToPeer(ctx context.Context, id peer.ID) (<-chan *peer.AddrInfo, error)
- func (dht *IpfsDHT) FindProviders(ctx context.Context, c cid.Cid) ([]peer.AddrInfo, error)
- func (dht *IpfsDHT) FindProvidersAsync(ctx context.Context, key cid.Cid, count int) <-chan peer.AddrInfo
- 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 ...routing.Option) (_ []byte, err error)
- func (dht *IpfsDHT) GetValues(ctx context.Context, key string, nvals int) (_ []RecvdVal, err error)
- func (dht *IpfsDHT) Host() host.Host
- func (dht *IpfsDHT) PeerID() peer.ID
- func (dht *IpfsDHT) PeerKey() []byte
- func (dht *IpfsDHT) Ping(ctx context.Context, p peer.ID) 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 ...routing.Option) (err error)
- func (dht *IpfsDHT) RefreshRoutingTable()
- func (dht *IpfsDHT) RoutingTable() *kb.RoutingTable
- func (dht *IpfsDHT) SearchValue(ctx context.Context, key string, opts ...routing.Option) (<-chan []byte, error)
- func (dht *IpfsDHT) Update(ctx context.Context, p peer.ID)
- type RecvdVal
Constants ¶
const ( // DefaultDialQueueMinParallelism is the default value for the minimum number of worker dial goroutines that will // be alive at any time. DefaultDialQueueMinParallelism = 6 // DefaultDialQueueMaxParallelism is the default value for the maximum number of worker dial goroutines that can // be alive at any time. DefaultDialQueueMaxParallelism = 20 // DefaultDialQueueMaxIdle is the default value for the period that a worker dial goroutine waits before signalling // a worker pool downscaling. DefaultDialQueueMaxIdle = 5 * time.Second // DefaultDialQueueScalingMutePeriod is the default value for the amount of time to ignore further worker pool // scaling events, after one is processed. Its role is to reduce jitter. DefaultDialQueueScalingMutePeriod = 1 * time.Second // DefaultDialQueueScalingFactor is the default factor by which the current number of workers will be multiplied // or divided when upscaling and downscaling events occur, respectively. DefaultDialQueueScalingFactor = 1.5 )
Variables ¶
var AlphaValue = 3
Alpha is the concurrency factor for asynchronous requests.
var DefaultBootstrapPeers []multiaddr.Multiaddr
var ErrNoPeersQueried = errors.New("failed to query any peers")
ErrNoPeersQueried is returned when we failed to connect to any peers.
var ErrReadTimeout = fmt.Errorf("timed out reading response")
var KValue = 20
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 IpfsDHT ¶
type IpfsDHT struct { Validator record.Validator // contains filtered or unexported fields }
IpfsDHT is an implementation of Kademlia with S/Kademlia modifications. It is used to implement the base Routing 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 tells the DHT to get into a bootstrapped state satisfying the IpfsRouter interface.
This just calls `RefreshRoutingTable`.
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 *peer.AddrInfo, 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 peer.AddrInfo
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 ...routing.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 ...routing.Option) (err error)
PutValue adds value corresponding to given Key. This is the top level "Store" operation of the DHT
func (*IpfsDHT) RefreshRoutingTable ¶ added in v0.3.0
func (dht *IpfsDHT) RefreshRoutingTable()
RefreshRoutingTable tells the DHT to refresh it's routing tables.
func (*IpfsDHT) RoutingTable ¶
func (dht *IpfsDHT) RoutingTable() *kb.RoutingTable
RoutingTable return dht's routingTable