C++ Distributed Hash Table
|
#include <dht.h>
Public Member Functions | |
Dht (const int &s, const int &s6, Config config) | |
const InfoHash & | getNodeId () const |
NodeStatus | getStatus (sa_family_t af) const |
NodeStatus | getStatus () const |
void | shutdown (ShutdownCallback cb) |
bool | isRunning (sa_family_t af=0) const |
virtual void | registerType (const ValueType &type) |
const ValueType & | getType (ValueType::Id type_id) const |
void | insertNode (const InfoHash &id, const SockAddr &) |
void | insertNode (const InfoHash &id, const sockaddr *sa, socklen_t salen) |
void | insertNode (const NodeExport &n) |
void | pingNode (const sockaddr *, socklen_t, DoneCallbackSimple &&cb={}) |
time_point | periodic (const uint8_t *buf, size_t buflen, const SockAddr &) |
time_point | periodic (const uint8_t *buf, size_t buflen, const sockaddr *from, socklen_t fromlen) |
virtual void | get (const InfoHash &key, GetCallback cb, DoneCallback donecb={}, Value::Filter &&f={}, Where &&w={}) |
virtual void | get (const InfoHash &key, GetCallback cb, DoneCallbackSimple donecb={}, Value::Filter &&f={}, Where &&w={}) |
virtual void | get (const InfoHash &key, GetCallbackSimple cb, DoneCallback donecb={}, Value::Filter &&f={}, Where &&w={}) |
virtual void | get (const InfoHash &key, GetCallbackSimple cb, DoneCallbackSimple donecb, Value::Filter &&f={}, Where &&w={}) |
virtual void | query (const InfoHash &key, QueryCallback cb, DoneCallback done_cb={}, Query &&q={}) |
virtual void | query (const InfoHash &key, QueryCallback cb, DoneCallbackSimple done_cb={}, Query &&q={}) |
std::vector< Sp< Value > > | getLocal (const InfoHash &key, Value::Filter f=Value::AllFilter()) const |
Sp< Value > | getLocalById (const InfoHash &key, Value::Id vid) const |
void | put (const InfoHash &key, Sp< Value >, DoneCallback cb=nullptr, time_point created=time_point::max(), bool permanent=false) |
void | put (const InfoHash &key, const Sp< Value > &v, DoneCallbackSimple cb, time_point created=time_point::max(), bool permanent=false) |
void | put (const InfoHash &key, Value &&v, DoneCallback cb=nullptr, time_point created=time_point::max(), bool permanent=false) |
void | put (const InfoHash &key, Value &&v, DoneCallbackSimple cb, time_point created=time_point::max(), bool permanent=false) |
std::vector< Sp< Value > > | getPut (const InfoHash &) |
Sp< Value > | getPut (const InfoHash &, const Value::Id &) |
bool | cancelPut (const InfoHash &, const Value::Id &) |
virtual size_t | listen (const InfoHash &, ValueCallback, Value::Filter={}, Where={}) |
virtual size_t | listen (const InfoHash &key, GetCallback cb, Value::Filter f={}, Where w={}) |
virtual size_t | listen (const InfoHash &key, GetCallbackSimple cb, Value::Filter f={}, Where w={}) |
virtual bool | cancelListen (const InfoHash &, size_t token) |
void | connectivityChanged (sa_family_t) |
void | connectivityChanged () |
std::vector< NodeExport > | exportNodes () |
std::vector< ValuesExport > | exportValues () const |
void | importValues (const std::vector< ValuesExport > &) |
NodeStats | getNodesStats (sa_family_t af) const |
std::string | getStorageLog () const |
std::string | getStorageLog (const InfoHash &) const |
std::string | getRoutingTablesLog (sa_family_t) const |
std::string | getSearchesLog (sa_family_t) const |
std::string | getSearchLog (const InfoHash &, sa_family_t af=AF_UNSPEC) const |
void | dumpTables () const |
std::vector< unsigned > | getNodeMessageStats (bool in=false) |
void | setStorageLimit (size_t limit=DEFAULT_STORAGE_LIMIT) |
std::pair< size_t, size_t > | getStoreSize () const |
std::vector< SockAddr > | getPublicAddress (sa_family_t family=0) |
void | pushNotificationReceived (const std::map< std::string, std::string > &) |
void | resubscribe (unsigned) |
![]() | |
virtual void | setLoggers (LogMethod error=NOLOG, LogMethod warn=NOLOG, LogMethod debug=NOLOG) |
virtual void | setLogFilter (const InfoHash &f) |
virtual void | setPushNotificationToken (const std::string &) |
Additional Inherited Members | |
![]() | |
using | Status = NodeStatus |
using | NodeExport = dht::NodeExport |
![]() | |
bool | logFilerEnable_ {} |
InfoHash | logFiler_ {} |
Logger | DHT_LOG |
Main Dht class. Provides a Distributed Hash Table node.
Must be given open UDP sockets and ::periodic must be called regularly.
dht::Dht::Dht | ( | const int & | s, |
const int & | s6, | ||
Config | config | ||
) |
Initialise the Dht with two open sockets (for IPv4 and IP6) and an ID for the node.
|
virtual |
Stop any put/announce operation at the given location, for the value with the given id.
Implements dht::DhtInterface.
|
virtual |
Inform the DHT of lower-layer connectivity changes. This will cause the DHT to assume a public IP address change. The DHT will recontact neighbor nodes, re-register for listen ops etc.
Implements dht::DhtInterface.
|
virtual |
Get the list of good nodes for local storage saving purposes The list is ordered to minimize the back-to-work delay.
Implements dht::DhtInterface.
|
virtual |
Get a value by searching on all available protocols (IPv4, IPv6), and call the provided get callback when values are found at key. The operation will start as soon as the node is connected to the network.
cb | a function called when new values are found on the network. It should return false to stop the operation. |
donecb | a function called when the operation is complete. cb and donecb won't be called again afterward. |
f | a filter function used to prefilter values. |
Implements dht::DhtInterface.
|
virtual |
Get locally stored data for the given hash.
Implements dht::DhtInterface.
Get locally stored data for the given key and value id.
Implements dht::DhtInterface.
|
inlinevirtual |
Get data currently being put at the given hash.
Implements dht::DhtInterface.
Get data currently being put at the given hash with the given id.
Implements dht::DhtInterface.
|
virtual |
Get the current status of the node for the given family.
Implements dht::DhtInterface.
|
inlinevirtual |
Returns the total memory usage of stored values and the number of stored values.
Implements dht::DhtInterface.
Insert a node in the main routing table. The node is not pinged, so this should be used to bootstrap efficiently from previously known nodes.
Implements dht::DhtInterface.
|
virtual |
Returns true if the node is running (have access to an open socket).
af: address family. If non-zero, will return true if the node is running for the provided family.
Implements dht::DhtInterface.
|
virtual |
Listen on the network for any changes involving a specified hash. The node will register to receive updates from relevent nodes when new values are added or removed.
Implements dht::DhtInterface.
|
inlinevirtual |
Listen on the network for any changes involving a specified hash. The node will register to receive updates from relevent nodes when new values are added or removed.
Implements dht::DhtInterface.
|
inlinevirtual |
Call linked callback with a push notification
notification | to process |
Implements dht::DhtInterface.
|
virtual |
Announce a value on all available protocols (IPv4, IPv6).
The operation will start as soon as the node is connected to the network. The done callback will be called once, when the first announce succeeds, or fails.
Implements dht::DhtInterface.
|
virtual |
Similar to Dht::get, but sends a Query to filter data remotely.
key | the key for which to query data for. |
cb | a function called when new values are found on the network. It should return false to stop the operation. |
done_cb | a function called when the operation is complete. cb and done_cb won't be called again afterward. |
q | a query used to filter values on the remotes before they send a response. |
Implements dht::DhtInterface.
|
inlinevirtual |
Set the in-memory storage limit in bytes
Implements dht::DhtInterface.
|
virtual |
Performs final operations before quitting.
Implements dht::DhtInterface.