dht

package
v0.0.0-...-2963f48 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2015 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

Package dht implements a distributed hash table that satisfies the ipfs routing interface. This DHT is modeled after kademlia with Coral and S/Kademlia modifications.

Index

Constants

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 = 4

The number of closer peers to send on requests.

View Source
var ErrBadRecord = errors.New("bad dht record")

ErrBadRecord is returned any time a dht record is found to be incorrectly formatted or signed.

View Source
var ErrInvalidRecordType = errors.New("invalid record keytype")

ErrInvalidRecordType is returned if a DHTRecord keys prefix is not found in the Validator map of the DHT.

View Source
var KValue = 10

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

View Source
var ProtocolDHT protocol.ID = "/ipfs/dht"

Functions

func KeyForPublicKey

func KeyForPublicKey(id peer.ID) u.Key

KeyForPublicKey returns the key used to retrieve public keys from the dht.

func RecordBlobForSig

func RecordBlobForSig(r *pb.Record) []byte

RecordBlobForSig returns the blob protected by the record signature

func ValidatePublicKeyRecord

func ValidatePublicKeyRecord(k u.Key, val []byte) error

ValidatePublicKeyRecord implements ValidatorFunc and verifies that the passed in record value is the PublicKey that matches the passed in key.

Types

type IpfsDHT

type IpfsDHT struct {

	// record validator funcs
	Validators map[string]ValidatorFunc

	ctxgroup.ContextGroup
	// contains filtered or unexported fields
}

IpfsDHT is an implementation of Kademlia with Coral and S/Kademlia modifications. It is used to implement the base IpfsRouting module.

func NewDHT

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

NewDHT creates a new DHT object with the given peer as the 'local' host

func (*IpfsDHT) Bootstrap

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

Bootstrap builds up list of peers by requesting random peer IDs

func (*IpfsDHT) Connect

func (dht *IpfsDHT) Connect(ctx context.Context, npeer peer.ID) error

Connect to a new peer at the given address, ping and add to the routing table

func (*IpfsDHT) FindLocal

func (dht *IpfsDHT) FindLocal(id peer.ID) peer.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) (peer.PeerInfo, error)

FindPeer searches for a peer with given ID.

func (*IpfsDHT) FindPeersConnectedToPeer

func (dht *IpfsDHT) FindPeersConnectedToPeer(ctx context.Context, id peer.ID) (<-chan peer.PeerInfo, error)

FindPeersConnectedToPeer searches for peers directly connected to a given peer.

func (*IpfsDHT) FindProviders

func (dht *IpfsDHT) FindProviders(ctx context.Context, key u.Key) ([]peer.PeerInfo, error)

FindProviders searches until the context expires.

func (*IpfsDHT) FindProvidersAsync

func (dht *IpfsDHT) FindProvidersAsync(ctx context.Context, key u.Key, count int) <-chan peer.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) GetValue

func (dht *IpfsDHT) GetValue(ctx context.Context, key u.Key) ([]byte, error)

GetValue searches for the value corresponding to given Key. If the search does not succeed, a multiaddr string of a closer peer is returned along with util.ErrSearchIncomplete

func (*IpfsDHT) LocalPeer

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

LocalPeer returns the peer.Peer of the dht.

func (*IpfsDHT) Ping

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

Ping a peer, log the time it took

func (*IpfsDHT) PingRoutine

func (dht *IpfsDHT) PingRoutine(t time.Duration)

PingRoutine periodically pings nearest neighbors.

func (*IpfsDHT) Provide

func (dht *IpfsDHT) Provide(ctx context.Context, key u.Key) 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 u.Key, value []byte) error

PutValue adds value corresponding to given Key. This is the top level "Store" operation of the DHT

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 ProviderManager

type ProviderManager struct {
	ctxgroup.ContextGroup
	// contains filtered or unexported fields
}

func NewProviderManager

func NewProviderManager(ctx context.Context, local peer.ID) *ProviderManager

func (*ProviderManager) AddProvider

func (pm *ProviderManager) AddProvider(k u.Key, val peer.ID)

func (*ProviderManager) GetLocal

func (pm *ProviderManager) GetLocal() []u.Key

func (*ProviderManager) GetProviders

func (pm *ProviderManager) GetProviders(ctx context.Context, k u.Key) []peer.ID

type ValidatorFunc

type ValidatorFunc func(u.Key, []byte) error

ValidatorFunc is a function that is called to validate a given type of DHTRecord.

Directories

Path Synopsis
Package dht_pb is a generated protocol buffer package.
Package dht_pb is a generated protocol buffer package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳