dht

package module
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2019 License: MIT Imports: 45 Imported by: 0

README

go-libp2p-kad-dht

standard-readme compliant GoDoc Build Status

A Kademlia DHT implementation on go-libp2p

Table of Contents

Install

go get github.com/libp2p/go-libp2p-kad-dht

Usage

Go to https://godoc.org/github.com/libp2p/go-libp2p-kad-dht.

Contribute

Contributions welcome. Please check out the issues.

Check out our contributing document for more information on how we work, and about contributing in general. Please be aware that all interactions related to libp2p are subject to the IPFS Code of Conduct.

Small note: If editing the README, please conform to the standard-readme specification.

License

MIT © Protocol Labs Inc.

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

View Source
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
)
View Source
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'

View Source
const NumBootstrapQueries = 5

NumBootstrapQueries defines the number of random dht queries to do to collect members of the routing table.

Variables

View Source
var AlphaValue = 3

Alpha is the concurrency factor for asynchronous requests.

View Source
var CloserPeerCount = KValue

The number of closer peers to send on requests.

View Source
var DefaultBootstrapConfig = BootstrapConfig{

	Queries: 1,

	Period: time.Duration(5 * time.Minute),

	Timeout: time.Duration(10 * time.Second),
}
View Source
var DefaultBootstrapPeers []multiaddr.Multiaddr
View Source
var ErrReadTimeout = fmt.Errorf("timed out reading response")
View Source
var KValue = 20

K is the maximum number of requests to perform before returning failure.

View Source
var PoolSize = 6

Pool size is the number of nodes used for group find/set RPC calls

Functions

func Quorum

func Quorum(n int) ropts.Option

Quorum is a DHT option that tells the DHT how many peers it needs to get values from before returning the best one.

Default: 16

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

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 IpfsRouting module.

func New

func New(ctx context.Context, h host.Host, options ...opts.Option) (*IpfsDHT, error)

New creates a new DHT with the specified host and options.

func NewDHT

func NewDHT(ctx context.Context, h host.Host, dstore ds.Batching) *IpfsDHT

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

func NewDHTClient(ctx context.Context, h host.Host, dstore ds.Batching) *IpfsDHT

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

func (dht *IpfsDHT) Bootstrap(ctx context.Context) error

A method in the IpfsRouting interface. It calls BootstrapWithConfig with the default bootstrap config.

func (*IpfsDHT) BootstrapOnce

func (dht *IpfsDHT) BootstrapOnce(ctx context.Context, cfg BootstrapConfig) error

This is a synchronous bootstrap. cfg.Queries queries will run each with a timeout of cfg.Timeout. cfg.Period is not used.

func (*IpfsDHT) BootstrapRandom added in v0.0.4

func (dht *IpfsDHT) BootstrapRandom(ctx context.Context) error

func (*IpfsDHT) BootstrapSelf added in v0.0.4

func (dht *IpfsDHT) BootstrapSelf(ctx context.Context) error

func (*IpfsDHT) BootstrapWithConfig

func (dht *IpfsDHT) BootstrapWithConfig(ctx context.Context, cfg BootstrapConfig) error

Runs cfg.Queries bootstrap queries every cfg.Period.

func (*IpfsDHT) Close

func (dht *IpfsDHT) Close() error

Close calls Process Close

func (*IpfsDHT) Context

func (dht *IpfsDHT) Context() context.Context

Context return dht's context

func (*IpfsDHT) FindLocal

func (dht *IpfsDHT) FindLocal(id peer.ID) pstore.PeerInfo

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) FindPeer

func (dht *IpfsDHT) FindPeer(ctx context.Context, id peer.ID) (_ pstore.PeerInfo, err error)

FindPeer searches for a peer with given ID.

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

func (dht *IpfsDHT) FindProviders(ctx context.Context, c cid.Cid) ([]pstore.PeerInfo, error)

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

func (dht *IpfsDHT) GetClosestPeers(ctx context.Context, key string) (<-chan peer.ID, error)

Kademlia 'node lookup' operation. Returns a channel of the K closest peers to the given key

func (*IpfsDHT) GetPublicKey

func (dht *IpfsDHT) GetPublicKey(ctx context.Context, p peer.ID) (ci.PubKey, error)

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) GetValues

func (dht *IpfsDHT) GetValues(ctx context.Context, key string, nvals int) (_ []RecvdVal, err error)

GetValues gets nvals values corresponding to the given key.

func (*IpfsDHT) Host added in v0.0.4

func (dht *IpfsDHT) Host() host.Host

func (*IpfsDHT) PeerID added in v0.0.4

func (dht *IpfsDHT) PeerID() peer.ID

func (*IpfsDHT) PeerKey added in v0.0.4

func (dht *IpfsDHT) PeerKey() []byte

func (*IpfsDHT) Ping added in v0.0.4

func (dht *IpfsDHT) Ping(ctx context.Context, p peer.ID) error

func (*IpfsDHT) Process

func (dht *IpfsDHT) Process() goprocess.Process

Process return dht's process

func (*IpfsDHT) Provide

func (dht *IpfsDHT) Provide(ctx context.Context, key cid.Cid, brdcst bool) (err error)

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

func (*IpfsDHT) SearchValue

func (dht *IpfsDHT) SearchValue(ctx context.Context, key string, opts ...ropts.Option) (<-chan []byte, error)

func (*IpfsDHT) Update

func (dht *IpfsDHT) Update(ctx context.Context, p peer.ID)

Update signals the routingTable to Update its last-seen status on the given peer.

type RecvdVal

type RecvdVal struct {
	Val  []byte
	From peer.ID
}

RecvdVal stores a value and the peer from which we got the value.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL