C++ Distributed Hash Table
|
Public Types | |
typedef std::function< void(bool)> | SignatureCheckCallback |
using | Config = SecureDhtConfig |
![]() | |
using | Status = NodeStatus |
using | NodeExport = dht::NodeExport |
Public Member Functions | |
SecureDht (std::unique_ptr< DhtInterface > dht, Config config) | |
InfoHash | getId () const |
PkId | getLongId () const |
ValueType | secureType (ValueType &&type) |
ValueType | secureType (const ValueType &type) |
void | registerType (const ValueType &type) override |
void | registerType (ValueType &&type) |
void | registerInsecureType (const ValueType &type) |
void | get (const InfoHash &id, GetCallback cb, DoneCallback donecb={}, Value::Filter &&={}, Where &&w={}) override |
void | get (const InfoHash &id, GetCallback cb, DoneCallbackSimple donecb={}, Value::Filter &&f={}, Where &&w={}) override |
void | get (const InfoHash &key, GetCallbackSimple cb, DoneCallback donecb={}, Value::Filter &&f={}, Where &&w={}) override |
void | get (const InfoHash &key, GetCallbackSimple cb, DoneCallbackSimple donecb, Value::Filter &&f={}, Where &&w={}) override |
void | putSigned (const InfoHash &hash, Sp< Value > val, DoneCallback callback, bool permanent=false) |
void | putSigned (const InfoHash &hash, Value &&v, DoneCallback callback, bool permanent=false) |
void | putEncrypted (const InfoHash &hash, const InfoHash &to, Sp< Value > val, DoneCallback callback, bool permanent=false) |
void | putEncrypted (const InfoHash &hash, const InfoHash &to, Value &&v, DoneCallback callback, bool permanent=false) |
void | sign (Value &v) const |
Value | encrypt (Value &v, const crypto::PublicKey &to) const |
Value | decrypt (const Value &v) |
void | findCertificate (const InfoHash &node, std::function< void(const Sp< crypto::Certificate >)> cb) |
void | findPublicKey (const InfoHash &node, std::function< void(const Sp< const crypto::PublicKey >)> cb) |
const Sp< crypto::Certificate > | registerCertificate (const InfoHash &node, const Blob &cert) |
void | registerCertificate (Sp< crypto::Certificate > &cert) |
const Sp< crypto::Certificate > | getCertificate (const InfoHash &node) const |
const Sp< const crypto::PublicKey > | getPublicKey (const InfoHash &node) const |
void | setLocalCertificateStore (CertificateStoreQuery &&query_method) |
void | shutdown (ShutdownCallback cb) override |
void | dumpTables () const override |
const InfoHash & | getNodeId () const override |
std::pair< size_t, size_t > | getStoreSize () const override |
std::string | getStorageLog () const override |
std::string | getStorageLog (const InfoHash &h) const override |
void | setStorageLimit (size_t limit=DEFAULT_STORAGE_LIMIT) override |
std::vector< NodeExport > | exportNodes () override |
std::vector< ValuesExport > | exportValues () const override |
void | importValues (const std::vector< ValuesExport > &v) override |
NodeStats | getNodesStats (sa_family_t af) const override |
std::vector< unsigned > | getNodeMessageStats (bool in=false) override |
std::string | getRoutingTablesLog (sa_family_t af) const override |
std::string | getSearchesLog (sa_family_t af) const override |
std::string | getSearchLog (const InfoHash &h, sa_family_t af=AF_UNSPEC) const override |
std::vector< SockAddr > | getPublicAddress (sa_family_t family=0) override |
time_point | periodic (const uint8_t *buf, size_t buflen, const SockAddr &sa) override |
time_point | periodic (const uint8_t *buf, size_t buflen, const sockaddr *from, socklen_t fromlen) override |
NodeStatus | getStatus (sa_family_t af) const override |
NodeStatus | getStatus () const override |
bool | isRunning (sa_family_t af=0) const override |
const ValueType & | getType (ValueType::Id type_id) const override |
void | insertNode (const InfoHash &id, const SockAddr &sa) override |
void | insertNode (const InfoHash &id, const sockaddr *sa, socklen_t salen) override |
void | insertNode (const NodeExport &n) override |
void | pingNode (const sockaddr *sa, socklen_t salen, DoneCallbackSimple &&cb={}) override |
void | query (const InfoHash &key, QueryCallback cb, DoneCallback done_cb={}, Query &&q={}) override |
void | query (const InfoHash &key, QueryCallback cb, DoneCallbackSimple done_cb={}, Query &&q={}) override |
std::vector< Sp< Value > > | getLocal (const InfoHash &key, Value::Filter f=Value::AllFilter()) const override |
Sp< Value > | getLocalById (const InfoHash &key, Value::Id vid) const override |
void | put (const InfoHash &key, Sp< Value > v, DoneCallback cb=nullptr, time_point created=time_point::max(), bool permanent=false) override |
void | put (const InfoHash &key, const Sp< Value > &v, DoneCallbackSimple cb, time_point created=time_point::max(), bool permanent=false) override |
void | put (const InfoHash &key, Value &&v, DoneCallback cb=nullptr, time_point created=time_point::max(), bool permanent=false) override |
void | put (const InfoHash &key, Value &&v, DoneCallbackSimple cb, time_point created=time_point::max(), bool permanent=false) override |
std::vector< Sp< Value > > | getPut (const InfoHash &h) override |
Sp< Value > | getPut (const InfoHash &h, const Value::Id &vid) override |
bool | cancelPut (const InfoHash &h, const Value::Id &vid) override |
size_t | listen (const InfoHash &key, ValueCallback, Value::Filter={}, Where={}) override |
size_t | listen (const InfoHash &key, GetCallback cb, Value::Filter={}, Where w={}) override |
size_t | listen (const InfoHash &key, GetCallbackSimple cb, Value::Filter f={}, Where w={}) override |
bool | cancelListen (const InfoHash &h, size_t token) override |
void | connectivityChanged (sa_family_t af) override |
void | connectivityChanged () override |
void | forwardAllMessages (bool forward) |
void | setPushNotificationToken (const std::string &token="") override |
void | pushNotificationReceived (const std::map< std::string, std::string > ¬ification) override |
void | setLoggers (LogMethod error=NOLOG, LogMethod warn=NOLOG, LogMethod debug=NOLOG) override |
void | setLogFilter (const InfoHash &f) override |
Static Public Member Functions | |
static dht::Config & | getConfig (SecureDht::Config &conf) |
Additional Inherited Members | |
![]() | |
bool | logFilerEnable_ {} |
InfoHash | logFiler_ {} |
Logger | DHT_LOG |
Definition at line 33 of file securedht.h.
dht::SecureDht::SecureDht | ( | std::unique_ptr< DhtInterface > | dht, |
Config | config | ||
) |
|
inlineoverridevirtual |
Stop any put/announce operation at the given location, for the value with the given id.
Implements dht::DhtInterface.
Definition at line 279 of file securedht.h.
|
inlineoverridevirtual |
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.
Definition at line 291 of file securedht.h.
|
inlineoverridevirtual |
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.
Definition at line 171 of file securedht.h.
|
overridevirtual |
"Secure" get(), that will check the signature of signed data, and decrypt encrypted data. If the signature can't be checked, or if the data can't be decrypted, it is not returned. Public, non-signed & non-encrypted data is retransmitted as-is.
Implements dht::DhtInterface.
|
inlineoverridevirtual |
Get locally stored data for the given hash.
Implements dht::DhtInterface.
Definition at line 234 of file securedht.h.
|
inlineoverridevirtual |
Get locally stored data for the given key and value id.
Implements dht::DhtInterface.
Definition at line 237 of file securedht.h.
|
inlineoverridevirtual |
Get the ID of the DHT node.
Implements dht::DhtInterface.
Definition at line 157 of file securedht.h.
Get data currently being put at the given hash.
Implements dht::DhtInterface.
Definition at line 273 of file securedht.h.
Get data currently being put at the given hash with the given id.
Implements dht::DhtInterface.
Definition at line 276 of file securedht.h.
|
inlineoverridevirtual |
Get the current status of the node for the given family.
Implements dht::DhtInterface.
Definition at line 204 of file securedht.h.
|
inlineoverridevirtual |
Returns the total memory usage of stored values and the number of stored values.
Implements dht::DhtInterface.
Definition at line 159 of file securedht.h.
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.
Definition at line 216 of file securedht.h.
|
inlineoverridevirtual |
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.
Definition at line 210 of file securedht.h.
|
overridevirtual |
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.
|
inlineoverridevirtual |
Call linked callback with push_notification
notification | to process |
Implements dht::DhtInterface.
Definition at line 310 of file securedht.h.
|
inlineoverridevirtual |
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.
Definition at line 240 of file securedht.h.
void dht::SecureDht::putEncrypted | ( | const InfoHash & | hash, |
const InfoHash & | to, | ||
Sp< Value > | val, | ||
DoneCallback | callback, | ||
bool | permanent = false |
||
) |
Will sign the data using our private key, encrypt it using the recipient' public key, and put it in the DHT. The operation will be immediate if the recipient' public key is known (otherwise it will be retrived first).
void dht::SecureDht::putSigned | ( | const InfoHash & | hash, |
Sp< Value > | val, | ||
DoneCallback | callback, | ||
bool | permanent = false |
||
) |
Will take ownership of the value, sign it using our private key and put it in the DHT.
|
inlineoverridevirtual |
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.
Definition at line 228 of file securedht.h.
|
inline |
Allows to set a custom callback called by the library to find a locally-stored certificate. The search key used is the public key ID, so there may be multiple certificates retured, signed with the same private key.
Definition at line 144 of file securedht.h.
|
inlineoverridevirtual |
Only print logs related to the given InfoHash (if given), or disable filter (if zeroes).
Reimplemented from dht::DhtInterface.
Definition at line 323 of file securedht.h.
|
inlineoverridevirtual |
Enable or disable logging of DHT internal messages
Reimplemented from dht::DhtInterface.
Definition at line 314 of file securedht.h.
|
inlineoverridevirtual |
Set the in-memory storage limit in bytes
Implements dht::DhtInterface.
Definition at line 168 of file securedht.h.
|
inlineoverridevirtual |
void dht::SecureDht::sign | ( | Value & | v | ) | const |
Take ownership of the value and sign it using our private key.