Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewErrPeerGroupNotFound ¶ added in v0.3.0
func NewErrPeerGroupNotFound(groupID protocol.PeerGroupID) error
func NewErrPeerNotFound ¶
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.PeerGroupID, 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 // AddPeerGroup creates a new PeerGroup in the dht with given name and PeerIDs. AddPeerGroup(protocol.PeerGroupID, protocol.PeerIDs) error // PeerGroupIDs returns the PeerIDs of the given PeerGroupID PeerGroupIDs(protocol.PeerGroupID) (protocol.PeerIDs, error) // PeerGroupAddresses returns the PeerAddresses of the given PeerGroupID. It // will not return Peers which we don't have the PeerAddresses. PeerGroupAddresses(protocol.PeerGroupID) (protocol.PeerAddresses, error) // Remove a PeerGroup with given name from the DHT. RemovePeerGroup(protocol.PeerGroupID) }
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 ErrPeerGroupNotFound ¶ added in v0.3.0
type ErrPeerGroupNotFound struct { protocol.PeerGroupID // contains filtered or unexported fields }
type ErrPeerNotFound ¶
Click to show internal directories.
Click to hide internal directories.