libp2p-hs-0.1.0.0: Haskell implementation of the libp2p networking stack
Safe HaskellNone
LanguageGHC2021

LibP2P.DHT.API

Description

High-level DHT API for content publishing and retrieval.

Provides the user-facing operations that libp2p applications use: provide, putValue, getValue, findProviders, and findPeer. These compose the lower-level iterative lookups with direct RPC sending to the closest peers found.

Synopsis

Content provider operations

provide :: DHTNode -> [Multiaddr] -> ByteString -> IO () Source #

Announce that the local node provides a given content key.

Performs an iterative FIND_NODE lookup for the content key, then sends ADD_PROVIDER messages to the k closest peers found. The local peer's listen addresses are included so remote peers can dial back.

putValue :: DHTNode -> Validator -> ByteString -> ByteString -> IO (Either String ()) Source #

Store a value in the DHT under the given key.

Performs an iterative FIND_NODE lookup for the key, then sends PUT_VALUE messages to the k closest peers. Also stores the value locally. The value is validated using the node's configured validator; if validation fails, the function returns Left with an error message.

getValue :: DHTNode -> Validator -> ByteString -> IO (Either String DHTRecord) Source #

Retrieve a value from the DHT.

Convenience wrapper around iterativeGetValue.

findProviders :: DHTNode -> ByteString -> IO [ProviderEntry] Source #

Find providers for a content key.

Convenience wrapper around iterativeGetProviders.

findPeer :: DHTNode -> PeerId -> IO [BucketEntry] Source #

Find the closest known peers to a target peer ID.

Convenience wrapper around iterativeFindNode.