dht

package
v0.3.10 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewErrGroupNotFound added in v0.3.3

func NewErrGroupNotFound(groupID protocol.GroupID) error

func NewErrPeerNotFound

func NewErrPeerNotFound(peerID protocol.PeerID) error

Types

type DHT

type DHT interface {

	// Me returns self PeerAddress
	Me() protocol.PeerAddress

	// NumPeers returns total number of PeerAddresses stored in the DHT.
	NumPeers() (int, error)

	// PeerAddress returns the resolved protocol.PeerAddress of the given
	// PeerID. It returns an ErrPeerNotFound if the PeerID cannot be found.
	PeerAddress(protocol.PeerID) (protocol.PeerAddress, error)

	// PeerAddresses returns all the PeerAddresses stored in the DHT.
	PeerAddresses() (protocol.PeerAddresses, error)

	// RandomPeerAddresses returns (at max) n random PeerAddresses in the given
	// peer group.
	RandomPeerAddresses(id protocol.GroupID, n int) (protocol.PeerAddresses, error)

	// AddPeerAddress adds a PeerAddress into the DHT.
	AddPeerAddress(protocol.PeerAddress) error

	// UpdatePeerAddress tries to update the PeerAddress in the DHT. It returns
	// true if the given peerAddr is newer than the one we stored.
	UpdatePeerAddress(protocol.PeerAddress) (bool, error)

	// RemovePeerAddress removes the PeerAddress of given PeerID from the DHT.
	// It wouldn't return any error if the PeerAddress doesn't exist.
	RemovePeerAddress(protocol.PeerID) error

	// AddGroup creates a new group in the DHT with given ID and PeerIDs.
	AddGroup(protocol.GroupID, protocol.PeerIDs) error

	// GroupIDs returns the PeerIDs in the group with the given ID.
	GroupIDs(protocol.GroupID) (protocol.PeerIDs, error)

	// GroupAddresses returns the PeerAddresses in the group with the given ID.
	// It will not return peers for which we do not have the PeerAddresses.
	GroupAddresses(protocol.GroupID) (protocol.PeerAddresses, error)

	// Remove a group from the DHT with the given ID.
	RemoveGroup(protocol.GroupID)
}

A DHT is a distributed hash table. It is used for storing peer addresses. A DHT is not required to be persistent and will often purge stale peer addresses.

func New

func New(me protocol.PeerAddress, codec protocol.PeerAddressCodec, store kv.Table, bootstrapAddrs ...protocol.PeerAddress) (DHT, error)

New DHT that stores peer addresses in the given store. It will cache all peer addresses in memory for fast access. It is safe for concurrent use, regardless of the underlying store.

type ErrGroupNotFound added in v0.3.3

type ErrGroupNotFound struct {
	protocol.GroupID
	// contains filtered or unexported fields
}

type ErrPeerNotFound

type ErrPeerNotFound struct {
	protocol.PeerID
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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