My Project 3.2.0
C++ Distributed Hash Table
Loading...
Searching...
No Matches
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 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) const
 
std::vector< std::string > getPublicAddressStr (sa_family_t af=AF_UNSPEC) const
 
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 setPushNotificationTopic (const std::string &topic)
 
void setPushNotificationPlatform (const std::string &platform)
 
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 54 of file dhtrunner.h.

Member Typedef Documentation

◆ StatusCallback

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

Definition at line 57 of file dhtrunner.h.

Member Function Documentation

◆ bootstrap() [1/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.

◆ bootstrap() [2/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() [3/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() [4/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.

◆ 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

◆ get() [1/7]

template<class T >
void dht::DhtRunner::get ( InfoHash hash,
std::function< bool(std::vector< T > &&)> cb,
DoneCallbackSimple dcb = {} )
inline

Definition at line 105 of file dhtrunner.h.

◆ get() [2/7]

template<class T >
void dht::DhtRunner::get ( InfoHash hash,
std::function< bool(T &&)> cb,
DoneCallbackSimple dcb = {} )
inline

Definition at line 114 of file dhtrunner.h.

◆ get() [3/7]

void dht::DhtRunner::get ( InfoHash id,
GetCallback cb,
DoneCallbackSimple donecb = {},
Value::Filter f = {},
Where w = {} )
inline

Definition at line 99 of file dhtrunner.h.

◆ get() [4/7]

void dht::DhtRunner::get ( InfoHash id,
GetCallbackSimple cb,
DoneCallback donecb = {},
Value::Filter f = {},
Where w = {} )
inline

Definition at line 89 of file dhtrunner.h.

◆ get() [5/7]

void dht::DhtRunner::get ( InfoHash id,
GetCallbackSimple cb,
DoneCallbackSimple donecb = {},
Value::Filter f = {},
Where w = {} )
inline

Definition at line 93 of file dhtrunner.h.

◆ get() [6/7]

template<class T >
std::future< std::vector< T > > dht::DhtRunner::get ( InfoHash key)
inline

Definition at line 145 of file dhtrunner.h.

◆ get() [7/7]

std::future< std::vector< std::shared_ptr< dht::Value > > > dht::DhtRunner::get ( InfoHash key,
Value::Filter f = {},
Where w = {} )
inline

Definition at line 131 of file dhtrunner.h.

◆ 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.

◆ getPeerDiscovery()

std::shared_ptr< PeerDiscovery > dht::DhtRunner::getPeerDiscovery ( ) const
inline

Definition at line 438 of file dhtrunner.h.

◆ isRunning()

bool dht::DhtRunner::isRunning ( ) const
inline

Definition at line 364 of file dhtrunner.h.

◆ 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 @run().

◆ listen() [1/6]

template<class T >
std::future< size_t > dht::DhtRunner::listen ( InfoHash hash,
std::function< bool(std::vector< T > &&)> cb )
inline

Definition at line 177 of file dhtrunner.h.

◆ listen() [2/6]

template<class T >
std::future< size_t > dht::DhtRunner::listen ( InfoHash hash,
std::function< bool(std::vector< T > &&, bool)> cb )
inline

Definition at line 185 of file dhtrunner.h.

◆ listen() [3/6]

template<typename T >
std::future< size_t > dht::DhtRunner::listen ( InfoHash hash,
std::function< bool(T &&)> cb,
Value::Filter f = {},
Where w = {} )
inline

Definition at line 194 of file dhtrunner.h.

◆ listen() [4/6]

template<typename T >
std::future< size_t > dht::DhtRunner::listen ( InfoHash hash,
std::function< bool(T &&, bool)> cb,
Value::Filter f = {},
Where w = {} )
inline

Definition at line 210 of file dhtrunner.h.

◆ listen() [5/6]

std::future< size_t > dht::DhtRunner::listen ( InfoHash key,
GetCallback cb,
Value::Filter f = {},
Where w = {} )
inline

Definition at line 164 of file dhtrunner.h.

◆ listen() [6/6]

std::future< size_t > dht::DhtRunner::listen ( InfoHash key,
GetCallbackSimple cb,
Value::Filter f = {},
Where w = {} )
inline

Definition at line 172 of file dhtrunner.h.

◆ 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 421 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

◆ put() [1/2]

void dht::DhtRunner::put ( InfoHash hash,
std::shared_ptr< Value > value,
DoneCallbackSimple cb,
time_point created = time_point::max(),
bool permanent = false )
inline

Definition at line 230 of file dhtrunner.h.

◆ put() [2/2]

void dht::DhtRunner::put ( InfoHash hash,
Value && value,
DoneCallbackSimple cb,
time_point created = time_point::max(),
bool permanent = false )
inline

Definition at line 235 of file dhtrunner.h.

◆ putEncrypted() [1/4]

void dht::DhtRunner::putEncrypted ( InfoHash hash,
const std::shared_ptr< crypto::PublicKey > & to,
std::shared_ptr< Value > value,
DoneCallbackSimple cb,
bool permanent = false )
inline

Definition at line 266 of file dhtrunner.h.

◆ putEncrypted() [2/4]

void dht::DhtRunner::putEncrypted ( InfoHash hash,
const std::shared_ptr< crypto::PublicKey > & to,
Value && value,
DoneCallbackSimple cb,
bool permanent = false )
inline

Definition at line 271 of file dhtrunner.h.

◆ putEncrypted() [3/4]

void dht::DhtRunner::putEncrypted ( InfoHash hash,
InfoHash to,
std::shared_ptr< Value > value,
DoneCallbackSimple cb,
bool permanent = false )
inline

Definition at line 255 of file dhtrunner.h.

◆ putEncrypted() [4/4]

void dht::DhtRunner::putEncrypted ( InfoHash hash,
InfoHash to,
Value && value,
DoneCallbackSimple cb,
bool permanent = false )
inline

Definition at line 260 of file dhtrunner.h.

◆ putSigned() [1/2]

void dht::DhtRunner::putSigned ( InfoHash hash,
std::shared_ptr< Value > value,
DoneCallbackSimple cb,
bool permanent = false )
inline

Definition at line 244 of file dhtrunner.h.

◆ putSigned() [2/2]

void dht::DhtRunner::putSigned ( InfoHash hash,
Value && value,
DoneCallbackSimple cb,
bool permanent = false )
inline

Definition at line 249 of file dhtrunner.h.

◆ query()

void dht::DhtRunner::query ( const InfoHash & hash,
QueryCallback cb,
DoneCallbackSimple done_cb = {},
Query q = {} )
inline

Definition at line 158 of file dhtrunner.h.

◆ run() [1/2]

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

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

◆ run() [2/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 395 of file dhtrunner.h.

◆ setLogFilter()

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

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

◆ setLogger()

void dht::DhtRunner::setLogger ( const Logger & logger)
inline

Definition at line 351 of file dhtrunner.h.

◆ setOnStatusChanged()

void dht::DhtRunner::setOnStatusChanged ( StatusCallback && cb)
inline

Definition at line 411 of file dhtrunner.h.

◆ setPushNotificationPlatform()

void dht::DhtRunner::setPushNotificationPlatform ( const std::string & platform)

Sets the push notification platform

◆ setPushNotificationToken()

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

Updates the push notification device token

◆ setPushNotificationTopic()

void dht::DhtRunner::setPushNotificationTopic ( const std::string & topic)

Sets the push notification topic

◆ 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: