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

#include <dhtrunner.h>

Classes

struct  Config
 

Public Types

typedef std::function< void(NodeStatus, NodeStatus)> StatusCallback
 

Public Member Functions

void get (InfoHash id, GetCallbackSimple cb, DoneCallback donecb={}, Value::Filter f=Value::AllFilter(), Where w={})
 
void get (InfoHash id, GetCallbackSimple cb, DoneCallbackSimple donecb={}, Value::Filter f=Value::AllFilter(), 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=Value::AllFilter(), Where w={})
 
void get (const std::string &key, GetCallback vcb, DoneCallbackSimple dcb={}, Value::Filter f=Value::AllFilter(), 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=Value::AllFilter(), 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=Value::AllFilter(), 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=Value::AllFilter(), Where w={})
 
std::future< size_t > listen (InfoHash key, GetCallbackSimple cb, Value::Filter f=Value::AllFilter(), Where w={})
 
template<class T >
std::future< size_t > listen (InfoHash hash, std::function< bool(std::vector< T > &&)> cb)
 
template<typename T >
std::future< size_t > listen (InfoHash hash, std::function< bool(T &&)> cb, Value::Filter f=Value::AllFilter(), 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, const Value::Id &id)
 
void putSigned (InfoHash hash, std::shared_ptr< Value > value, DoneCallback cb={})
 
void putSigned (InfoHash hash, std::shared_ptr< Value > value, DoneCallbackSimple cb)
 
void putSigned (InfoHash hash, Value &&value, DoneCallback cb={})
 
void putSigned (InfoHash hash, Value &&value, DoneCallbackSimple cb)
 
void putSigned (const std::string &key, Value &&value, DoneCallbackSimple cb={})
 
void putEncrypted (InfoHash hash, InfoHash to, std::shared_ptr< Value > value, DoneCallback cb={})
 
void putEncrypted (InfoHash hash, InfoHash to, std::shared_ptr< Value > value, DoneCallbackSimple cb)
 
void putEncrypted (InfoHash hash, InfoHash to, Value &&value, DoneCallback cb={})
 
void putEncrypted (InfoHash hash, InfoHash to, Value &&value, DoneCallbackSimple cb)
 
void putEncrypted (const std::string &key, InfoHash to, Value &&value, DoneCallback cb={})
 
void bootstrap (const std::vector< SockAddr > &nodes, DoneCallbackSimple &&cb={})
 
void bootstrap (const SockAddr &addr, DoneCallbackSimple &&cb={})
 
void bootstrap (const std::vector< NodeExport > &nodes)
 
void bootstrap (const std::string &host, const std::string &service)
 
void clearBootstrap ()
 
void connectivityChanged ()
 
void dumpTables () const
 
InfoHash getId () const
 
InfoHash getNodeId () const
 
const SockAddrgetBound (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 setStorageLimit (size_t limit=DEFAULT_STORAGE_LIMIT)
 
std::vector< NodeExportexportNodes () const
 
std::vector< ValuesExport > exportValues () const
 
void setLoggers (LogMethod err=NOLOG, LogMethod warn=NOLOG, LogMethod debug=NOLOG)
 
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
 
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 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=4222, const crypto::Identity identity={}, bool threaded=false, NetId network=0)
 
void run (in_port_t port, Config config)
 
void run (const SockAddr &local4, const SockAddr &local6, Config config)
 
void run (const char *ip4, const char *ip6, const char *service, Config config)
 
void setOnStatusChanged (StatusCallback &&cb)
 
time_point loop ()
 
void shutdown (ShutdownCallback cb)
 
void join ()
 
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 51 of file dhtrunner.h.

Member Typedef Documentation

◆ StatusCallback

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

Definition at line 54 of file dhtrunner.h.

Member Function Documentation

◆ bootstrap() [1/3]

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() [2/3]

void dht::DhtRunner::bootstrap ( const 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/3]

void dht::DhtRunner::bootstrap ( const 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
deviceKeynon empty to enable push notifications

◆ 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 82 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 91 of file dhtrunner.h.

◆ get() [3/7]

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

Definition at line 76 of file dhtrunner.h.

◆ get() [4/7]

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

Definition at line 66 of file dhtrunner.h.

◆ get() [5/7]

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

Definition at line 70 of file dhtrunner.h.

◆ get() [6/7]

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

Definition at line 122 of file dhtrunner.h.

◆ get() [7/7]

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

Definition at line 108 of file dhtrunner.h.

◆ getBound()

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

Returns the currently bound address.

Parameters
faddress family of the bound address to retreive.

Definition at line 259 of file dhtrunner.h.

◆ getBoundPort()

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

Returns the currently bound port, in host byte order.

Parameters
faddress family of the bound port to retreive.

Definition at line 267 of file dhtrunner.h.

◆ isRunning()

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

Definition at line 290 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/4]

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

Definition at line 154 of file dhtrunner.h.

◆ listen() [2/4]

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

Definition at line 162 of file dhtrunner.h.

◆ listen() [3/4]

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

Definition at line 141 of file dhtrunner.h.

◆ listen() [4/4]

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

Definition at line 149 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 361 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 182 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 187 of file dhtrunner.h.

◆ putEncrypted() [1/2]

void dht::DhtRunner::putEncrypted ( InfoHash  hash,
InfoHash  to,
std::shared_ptr< Value value,
DoneCallbackSimple  cb 
)
inline

Definition at line 206 of file dhtrunner.h.

◆ putEncrypted() [2/2]

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

Definition at line 211 of file dhtrunner.h.

◆ putSigned() [1/2]

void dht::DhtRunner::putSigned ( InfoHash  hash,
std::shared_ptr< Value value,
DoneCallbackSimple  cb 
)
inline

Definition at line 195 of file dhtrunner.h.

◆ putSigned() [2/2]

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

Definition at line 200 of file dhtrunner.h.

◆ query()

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

Definition at line 135 of file dhtrunner.h.

◆ run() [1/3]

void dht::DhtRunner::run ( const char *  ip4,
const char *  ip6,
const char *  service,
Config  config 
)

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

◆ run() [2/3]

void dht::DhtRunner::run ( const SockAddr local4,
const SockAddr local6,
Config  config 
)
Parameters
local4Local IPv4 address and port to bind. Can be null.
local6Local IPv6 address and port to bind. Can be null. You should allways bind to a global IPv6 address.
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.

◆ run() [3/3]

void dht::DhtRunner::run ( in_port_t  port = 4222,
const crypto::Identity  identity = {},
bool  threaded = false,
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 319 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).

◆ setOnStatusChanged()

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

Definition at line 352 of file dhtrunner.h.

◆ setPushNotificationToken()

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

Updates the push notification device token

◆ shutdown()

void dht::DhtRunner::shutdown ( ShutdownCallback  cb)

Gracefuly disconnect from network.


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