Version: v0.20.0 Latest Latest

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

Go to latest
Published: Dec 11, 2022 License: MIT Imports: 15 Imported by: 60



Package dual provides an implementaiton of a split or "dual" dht, where two parallel instances are maintained for the global internet and the local LAN respectively.



View Source
const LanExtension protocol.ID = "/lan"

LanExtension is used to differentiate local protocol requests from those on the WAN DHT.


This section is empty.


This section is empty.


type DHT

type DHT struct {
	WAN *dht.IpfsDHT
	LAN *dht.IpfsDHT

DHT implements the routing interface to provide two concrete DHT implementationts for use in IPFS that are used to support both global network users and disjoint LAN usecases.

func New

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

New creates a new DualDHT instance. Options provided are forwarded on to the two concrete IpfsDHT internal constructions, modulo additional options used by the Dual DHT to enforce the LAN-vs-WAN distinction. Note: query or routing table functional options provided as arguments to this function will be overriden by this constructor.

func (*DHT) Bootstrap

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

Bootstrap allows callers to hint to the routing system to get into a Boostrapped state and remain there.

func (*DHT) Close

func (dht *DHT) Close() error

Close closes the DHT context.

func (*DHT) FindPeer

func (dht *DHT) FindPeer(ctx context.Context, pid peer.ID) (peer.AddrInfo, error)

FindPeer searches for a peer with given ID Note: with signed peer records, we can change this to short circuit once either DHT returns.

func (*DHT) FindProvidersAsync

func (dht *DHT) FindProvidersAsync(ctx context.Context, key cid.Cid, count int) <-chan peer.AddrInfo

FindProvidersAsync searches for peers who are able to provide a given key

func (*DHT) GetPublicKey

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

GetPublicKey returns the public key for the given peer.

func (*DHT) GetRoutingTableDiversityStats added in v0.9.0

func (dht *DHT) GetRoutingTableDiversityStats() []peerdiversity.CplDiversityStats

GetRoutingTableDiversityStats fetches the Routing Table Diversity Stats.

func (*DHT) GetValue

func (d *DHT) GetValue(ctx context.Context, key string, opts ...routing.Option) ([]byte, error)

GetValue searches for the value corresponding to given Key.

func (*DHT) Provide

func (dht *DHT) Provide(ctx context.Context, key cid.Cid, announce bool) error

Provide adds the given cid to the content routing system.

func (*DHT) PutValue

func (dht *DHT) PutValue(ctx context.Context, key string, val []byte, opts ...routing.Option) error

PutValue adds value corresponding to given Key.

func (*DHT) SearchValue

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

SearchValue searches for better values from this value

func (*DHT) WANActive added in v0.7.2

func (dht *DHT) WANActive() bool

WANActive returns true when the WAN DHT is active (has peers).

type Option added in v0.9.0

type Option func(*config) error

Option is an option used to configure the Dual DHT.

func DHTOption added in v0.9.0

func DHTOption(opts ...dht.Option) Option

DHTOption applies the given DHT options to both the WAN and the LAN DHTs.

func LanDHTOption added in v0.9.0

func LanDHTOption(opts ...dht.Option) Option

LanDHTOption applies the given DHT options to the LAN DHT.

func WanDHTOption added in v0.9.0

func WanDHTOption(opts ...dht.Option) Option

WanDHTOption applies the given DHT options to the WAN DHT.

Source Files

Jump to

Keyboard shortcuts

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