C++ Distributed Hash Table
Classes | Public Types | Public Member Functions | List of all members
dht::DhtRunner Class Reference

#include <dhtrunner.h>

Classes

struct  Config
 
struct  Context
 

Public Types

using StatusCallback = std::function< void(NodeStatus, NodeStatus)>
 

Public Member Functions

void get (InfoHash id, GetCallbackSimple cb, DoneCallback donecb={}, Value::Filter f={}, Where w={})
 
void get (InfoHash id, GetCallbackSimple cb, DoneCallbackSimple donecb={}, Value::Filter f={}, Where w={})
 
void get (InfoHash hash, GetCallback vcb, DoneCallback dcb, Value::Filter f={}, Where w={})
 
void get (InfoHash id, GetCallback cb, DoneCallbackSimple donecb={}, Value::Filter f={}, Where w={})
 
void get (const std::string &key, GetCallback vcb, DoneCallbackSimple dcb={}, Value::Filter f={}, Where w={})
 
template<class T >
void get (InfoHash hash, std::function< bool(std::vector< T > &&)> cb, DoneCallbackSimple dcb={})
 
template<class T >
void get (InfoHash hash, std::function< bool(T &&)> cb, DoneCallbackSimple dcb={})
 
std::future< std::vector< std::shared_ptr< dht::Value > > > get (InfoHash key, Value::Filter f={}, Where w={})
 
template<class T >
std::future< std::vector< T > > get (InfoHash key)
 
void query (const InfoHash &hash, QueryCallback cb, DoneCallback done_cb={}, Query q={})
 
void query (const InfoHash &hash, QueryCallback cb, DoneCallbackSimple done_cb={}, Query q={})
 
std::future< size_t > listen (InfoHash key, ValueCallback vcb, Value::Filter f={}, Where w={})
 
std::future< size_t > listen (InfoHash key, GetCallback cb, Value::Filter f={}, Where w={})
 
std::future< size_t > listen (const std::string &key, GetCallback vcb, Value::Filter f={}, Where w={})
 
std::future< size_t > listen (InfoHash key, GetCallbackSimple cb, Value::Filter f={}, Where w={})
 
template<class T >
std::future< size_t > listen (InfoHash hash, std::function< bool(std::vector< T > &&)> cb)
 
template<class T >
std::future< size_t > listen (InfoHash hash, std::function< bool(std::vector< T > &&, bool)> cb)
 
template<typename T >
std::future< size_t > listen (InfoHash hash, std::function< bool(T &&)> cb, Value::Filter f={}, Where w={})
 
template<typename T >
std::future< size_t > listen (InfoHash hash, std::function< bool(T &&, bool)> cb, Value::Filter f={}, Where w={})
 
void cancelListen (InfoHash h, size_t token)
 
void cancelListen (InfoHash h, std::shared_future< size_t > token)
 
void put (InfoHash hash, std::shared_ptr< Value > value, DoneCallback cb={}, time_point created=time_point::max(), bool permanent=false)
 
void put (InfoHash hash, std::shared_ptr< Value > value, DoneCallbackSimple cb, time_point created=time_point::max(), bool permanent=false)
 
void put (InfoHash hash, Value &&value, DoneCallback cb={}, time_point created=time_point::max(), bool permanent=false)
 
void put (InfoHash hash, Value &&value, DoneCallbackSimple cb, time_point created=time_point::max(), bool permanent=false)
 
void put (const std::string &key, Value &&value, DoneCallbackSimple cb={}, time_point created=time_point::max(), bool permanent=false)
 
void cancelPut (const InfoHash &h, Value::Id id)
 
void cancelPut (const InfoHash &h, const std::shared_ptr< Value > &value)
 
void putSigned (InfoHash hash, std::shared_ptr< Value > value, DoneCallback cb={}, bool permanent=false)
 
void putSigned (InfoHash hash, std::shared_ptr< Value > value, DoneCallbackSimple cb, bool permanent=false)
 
void putSigned (InfoHash hash, Value &&value, DoneCallback cb={}, bool permanent=false)
 
void putSigned (InfoHash hash, Value &&value, DoneCallbackSimple cb, bool permanent=false)
 
void putSigned (const std::string &key, Value &&value, DoneCallbackSimple cb={}, bool permanent=false)
 
void putEncrypted (InfoHash hash, InfoHash to, std::shared_ptr< Value > value, DoneCallback cb={}, bool permanent=false)
 
void putEncrypted (InfoHash hash, InfoHash to, std::shared_ptr< Value > value, DoneCallbackSimple cb, bool permanent=false)
 
void putEncrypted (InfoHash hash, InfoHash to, Value &&value, DoneCallback cb={}, bool permanent=false)
 
void putEncrypted (InfoHash hash, InfoHash to, Value &&value, DoneCallbackSimple cb, bool permanent=false)
 
void putEncrypted (const std::string &key, InfoHash to, Value &&value, DoneCallback cb={}, bool permanent=false)
 
void putEncrypted (InfoHash hash, const std::shared_ptr< crypto::PublicKey > &to, std::shared_ptr< Value > value, DoneCallback cb={}, bool permanent=false)
 
void putEncrypted (InfoHash hash, const std::shared_ptr< crypto::PublicKey > &to, std::shared_ptr< Value > value, DoneCallbackSimple cb, bool permanent=false)
 
void putEncrypted (InfoHash hash, const std::shared_ptr< crypto::PublicKey > &to, Value &&value, DoneCallback cb={}, bool permanent=false)
 
void putEncrypted (InfoHash hash, const std::shared_ptr< crypto::PublicKey > &to, Value &&value, DoneCallbackSimple cb, bool permanent=false)
 
void bootstrap (std::vector< SockAddr > nodes, DoneCallbackSimple cb={})
 
void bootstrap (SockAddr addr, DoneCallbackSimple cb={})
 
void bootstrap (std::vector< NodeExport > nodes)
 
void bootstrap (const std::string &host, const std::string &service)
 
void bootstrap (const std::string &hostService)
 
void bootstrap (const InfoHash &id, const SockAddr &address)
 
void clearBootstrap ()
 
void connectivityChanged ()
 
void dumpTables () const
 
InfoHash getId () const
 
std::shared_ptr< crypto::PublicKeygetPublicKey () const
 
InfoHash getNodeId () const
 
SockAddr getBound (sa_family_t f=AF_INET) const
 
in_port_t getBoundPort (sa_family_t f=AF_INET) const
 
std::pair< size_t, size_t > getStoreSize () const
 
void getStorageLimit () const
 
void setStorageLimit (size_t limit=DEFAULT_STORAGE_LIMIT)
 
std::vector< NodeExportexportNodes () const
 
std::vector< ValuesExport > exportValues () const
 
void setLogger (const Sp< Logger > &logger={})
 
void setLogger (const Logger &logger)
 
void setLoggers (LogMethod err={}, LogMethod warn={}, LogMethod debug={})
 
void setLogFilter (const InfoHash &f={})
 
void registerType (const ValueType &type)
 
void importValues (const std::vector< ValuesExport > &values)
 
bool isRunning () const
 
NodeStats getNodesStats (sa_family_t af) const
 
unsigned getNodesStats (sa_family_t af, unsigned *good_return, unsigned *dubious_return, unsigned *cached_return, unsigned *incoming_return) const
 
NodeInfo getNodeInfo () const
 
void getNodeInfo (std::function< void(std::shared_ptr< NodeInfo >)>)
 
std::vector< unsigned > getNodeMessageStats (bool in=false) const
 
std::string getStorageLog () const
 
std::string getStorageLog (const InfoHash &) const
 
std::string getRoutingTablesLog (sa_family_t af) const
 
std::string getSearchesLog (sa_family_t af=AF_UNSPEC) const
 
std::string getSearchLog (const InfoHash &, sa_family_t af=AF_UNSPEC) const
 
std::vector< SockAddrgetPublicAddress (sa_family_t af=AF_UNSPEC)
 
std::vector< std::string > getPublicAddressStr (sa_family_t af=AF_UNSPEC)
 
void getPublicAddress (std::function< void(std::vector< SockAddr > &&)>, sa_family_t af=AF_UNSPEC)
 
void findCertificate (InfoHash hash, std::function< void(const std::shared_ptr< crypto::Certificate > &)>)
 
void registerCertificate (std::shared_ptr< crypto::Certificate > cert)
 
void setLocalCertificateStore (CertificateStoreQuery &&query_method)
 
void run (in_port_t port=dht::net::DHT_DEFAULT_PORT, const crypto::Identity &identity={}, bool threaded=true, NetId network=0)
 
void run (in_port_t port, Config &config, Context &&context={})
 
void run (const char *ip4, const char *ip6, const char *service, Config &config, Context &&context={})
 
void run (const Config &config, Context &&context)
 
void setOnStatusChanged (StatusCallback &&cb)
 
time_point loop ()
 
void shutdown (ShutdownCallback cb={}, bool stop=false)
 
void join ()
 
std::shared_ptr< PeerDiscoverygetPeerDiscovery () const
 
void setProxyServer (const std::string &proxy, const std::string &pushNodeId="")
 
void enableProxy (bool proxify)
 
void setPushNotificationToken (const std::string &token)
 
void pushNotificationReceived (const std::map< std::string, std::string > &data)
 
void forwardAllMessages (bool forward)
 

Detailed Description

Provides a thread-safe interface to run the (secure) DHT. The class will open sockets on the provided port and will either wait for (expectedly frequent) calls to ::loop() or start an internal thread that will update the DHT when appropriate.

Definition at line 53 of file dhtrunner.h.

Member Function Documentation

◆ bootstrap() [1/4]

void dht::DhtRunner::bootstrap ( std::vector< SockAddr nodes,
DoneCallbackSimple  cb = {} 
)

Insert known nodes to the routing table, without necessarly ping them. Usefull to restart a node and get things running fast without putting load on the network.

◆ bootstrap() [2/4]

void dht::DhtRunner::bootstrap ( std::vector< NodeExport nodes)

Insert known nodes to the routing table, without necessarly ping them. Usefull to restart a node and get things running fast without putting load on the network.

◆ bootstrap() [3/4]

void dht::DhtRunner::bootstrap ( const std::string &  host,
const std::string &  service 
)

Add host:service to bootstrap nodes, and ping this node. DNS resolution is performed asynchronously. When disconnected, all bootstrap nodes added with this method will be tried regularly until connection to the DHT network is established.

◆ bootstrap() [4/4]

void dht::DhtRunner::bootstrap ( const InfoHash id,
const SockAddr address 
)

Insert known nodes to the routing table, without necessarly ping them. Usefull to restart a node and get things running fast without putting load on the network.

◆ clearBootstrap()

void dht::DhtRunner::clearBootstrap ( )

Clear the list of bootstrap added using bootstrap(const std::string&, const std::string&).

◆ connectivityChanged()

void dht::DhtRunner::connectivityChanged ( )

Inform the DHT of lower-layer connectivity changes. This will cause the DHT to assume an IP address change. The DHT will recontact neighbor nodes, re-register for listen ops etc.

◆ enableProxy()

void dht::DhtRunner::enableProxy ( bool  proxify)

Start or stop the proxy

Parameters
proxifyif we want to use the proxy
deviceKeynon empty to enable push notifications

◆ getBound()

SockAddr dht::DhtRunner::getBound ( sa_family_t  f = AF_INET) const

Returns the currently bound address.

Parameters
faddress family of the bound address to retreive.

◆ getBoundPort()

in_port_t dht::DhtRunner::getBoundPort ( sa_family_t  f = AF_INET) const

Returns the currently bound port, in host byte order.

Parameters
faddress family of the bound port to retreive.

◆ getId()

InfoHash dht::DhtRunner::getId ( ) const

Get the public key fingerprint if an identity is used with this node, 0 otherwise.

◆ getNodeId()

InfoHash dht::DhtRunner::getNodeId ( ) const

Get the ID of the DHT node.

◆ join()

void dht::DhtRunner::join ( )

Quit and wait for all threads to terminate. No callbacks will be called after this method returns. All internal state will be lost. The DHT can then be run again with ().

◆ loop()

time_point dht::DhtRunner::loop ( )
inline

In non-threaded mode, the user should call this method regularly and everytime a new packet is received.

Returns
the next op

Definition at line 416 of file dhtrunner.h.

◆ pushNotificationReceived()

void dht::DhtRunner::pushNotificationReceived ( const std::map< std::string, std::string > &  data)

Insert a push notification to process for OpenDHT

◆ run() [1/2]

void dht::DhtRunner::run ( in_port_t  port = dht::net::DHT_DEFAULT_PORT,
const crypto::Identity &  identity = {},
bool  threaded = true,
NetId  network = 0 
)
inline
Parameters
portLocal port to bind. Both IPv4 and IPv6 will be tried (ANY).
identityRSA key pair to use for cryptographic operations.
threadedIf false, ::loop() must be called periodically. Otherwise a thread is launched.
cbOptional callback to receive general state information.

Definition at line 391 of file dhtrunner.h.

◆ run() [2/2]

void dht::DhtRunner::run ( const char *  ip4,
const char *  ip6,
const char *  service,
Config config,
Context &&  context = {} 
)

Same as (sockaddr_in, sockaddr_in6, Identity, bool, StatusCallback), but with string IP addresses and service (port).

◆ setLogFilter()

void dht::DhtRunner::setLogFilter ( const InfoHash f = {})

Only print logs related to the given InfoHash (if given), or disable filter (if zeroes).

◆ setPushNotificationToken()

void dht::DhtRunner::setPushNotificationToken ( const std::string &  token)

Updates the push notification device token

◆ shutdown()

void dht::DhtRunner::shutdown ( ShutdownCallback  cb = {},
bool  stop = false 
)

Gracefuly disconnect from network.


The documentation for this class was generated from the following file: