C++ Distributed Hash Table
Public Types | Public Member Functions | Static Public Member Functions | List of all members
dht::SecureDht Class Referencefinal
Inheritance diagram for dht::SecureDht:
Inheritance graph
[legend]
Collaboration diagram for dht::SecureDht:
Collaboration graph
[legend]

Public Types

typedef std::function< void(bool)> SignatureCheckCallback
 
using Config = SecureDhtConfig
 
- Public Types inherited from dht::DhtInterface
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::CertificateregisterCertificate (const InfoHash &node, const Blob &cert)
 
void registerCertificate (Sp< crypto::Certificate > &cert)
 
const Sp< crypto::CertificategetCertificate (const InfoHash &node) const
 
const Sp< const crypto::PublicKeygetPublicKey (const InfoHash &node) const
 
void setLocalCertificateStore (CertificateStoreQuery &&query_method)
 
void shutdown (ShutdownCallback cb) override
 
void dumpTables () const override
 
const InfoHashgetNodeId () 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< NodeExportexportNodes () 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< SockAddrgetPublicAddress (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 ValueTypegetType (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< ValuegetLocalById (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< ValuegetPut (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 > &notification) 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::ConfiggetConfig (SecureDht::Config &conf)
 

Additional Inherited Members

- Protected Attributes inherited from dht::DhtInterface
bool logFilerEnable_ {}
 
InfoHash logFiler_ {}
 
Logger DHT_LOG
 

Detailed Description

Definition at line 33 of file securedht.h.

Constructor & Destructor Documentation

◆ SecureDht()

dht::SecureDht::SecureDht ( std::unique_ptr< DhtInterface dht,
Config  config 
)

s, s6: bound socket descriptors for IPv4 and IPv6, respectively. For the Dht to be initialised, at least one of them must be >= 0. id: the identity to use for the crypto layer and to compute our own hash on the Dht.

Member Function Documentation

◆ cancelPut()

bool dht::SecureDht::cancelPut ( const InfoHash ,
const Value::Id &   
)
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.

◆ connectivityChanged()

void dht::SecureDht::connectivityChanged ( sa_family_t  )
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.

◆ exportNodes()

std::vector<NodeExport> dht::SecureDht::exportNodes ( )
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.

◆ get()

void dht::SecureDht::get ( const InfoHash id,
GetCallback  cb,
DoneCallback  donecb = {},
Value::Filter &&  = {},
Where &&  w = {} 
)
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.

◆ getLocal()

std::vector<Sp<Value> > dht::SecureDht::getLocal ( const InfoHash key,
Value::Filter  f = Value::AllFilter() 
) const
inlineoverridevirtual

Get locally stored data for the given hash.

Implements dht::DhtInterface.

Definition at line 234 of file securedht.h.

◆ getLocalById()

Sp<Value> dht::SecureDht::getLocalById ( const InfoHash key,
Value::Id  vid 
) const
inlineoverridevirtual

Get locally stored data for the given key and value id.

Implements dht::DhtInterface.

Definition at line 237 of file securedht.h.

◆ getNodeId()

const InfoHash& dht::SecureDht::getNodeId ( ) const
inlineoverridevirtual

Get the ID of the DHT node.

Implements dht::DhtInterface.

Definition at line 157 of file securedht.h.

◆ getPut() [1/2]

std::vector<Sp<Value> > dht::SecureDht::getPut ( const InfoHash )
inlineoverridevirtual

Get data currently being put at the given hash.

Implements dht::DhtInterface.

Definition at line 273 of file securedht.h.

◆ getPut() [2/2]

Sp<Value> dht::SecureDht::getPut ( const InfoHash ,
const Value::Id &   
)
inlineoverridevirtual

Get data currently being put at the given hash with the given id.

Implements dht::DhtInterface.

Definition at line 276 of file securedht.h.

◆ getStatus()

NodeStatus dht::SecureDht::getStatus ( sa_family_t  af) const
inlineoverridevirtual

Get the current status of the node for the given family.

Implements dht::DhtInterface.

Definition at line 204 of file securedht.h.

◆ getStoreSize()

std::pair<size_t, size_t> dht::SecureDht::getStoreSize ( ) const
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.

◆ insertNode()

void dht::SecureDht::insertNode ( const InfoHash id,
const SockAddr  
)
inlineoverridevirtual

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.

◆ isRunning()

bool dht::SecureDht::isRunning ( sa_family_t  af = 0) const
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.

◆ listen()

size_t dht::SecureDht::listen ( const InfoHash ,
GetCallback  ,
Value::Filter  = {},
Where  w = {} 
)
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.

Returns
a token to cancel the listener later.

Implements dht::DhtInterface.

◆ pushNotificationReceived()

void dht::SecureDht::pushNotificationReceived ( const std::map< std::string, std::string > &  notification)
inlineoverridevirtual

Call linked callback with push_notification

Parameters
notificationto process

Implements dht::DhtInterface.

Definition at line 310 of file securedht.h.

◆ put()

void dht::SecureDht::put ( const InfoHash key,
Sp< Value ,
DoneCallback  cb = nullptr,
time_point  created = time_point::max(),
bool  permanent = false 
)
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.

◆ putEncrypted()

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

◆ putSigned()

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.

◆ query()

void dht::SecureDht::query ( const InfoHash key,
QueryCallback  cb,
DoneCallback  done_cb = {},
Query &&  q = {} 
)
inlineoverridevirtual

Similar to Dht::get, but sends a Query to filter data remotely.

Parameters
keythe key for which to query data for.
cba function called when new values are found on the network. It should return false to stop the operation.
done_cba function called when the operation is complete. cb and done_cb won't be called again afterward.
qa query used to filter values on the remotes before they send a response.

Implements dht::DhtInterface.

Definition at line 228 of file securedht.h.

◆ setLocalCertificateStore()

void dht::SecureDht::setLocalCertificateStore ( CertificateStoreQuery &&  query_method)
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.

◆ setLogFilter()

void dht::SecureDht::setLogFilter ( const InfoHash f)
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.

◆ setLoggers()

void dht::SecureDht::setLoggers ( LogMethod  error = NOLOG,
LogMethod  warn = NOLOG,
LogMethod  debug = NOLOG 
)
inlineoverridevirtual

Enable or disable logging of DHT internal messages

Reimplemented from dht::DhtInterface.

Definition at line 314 of file securedht.h.

◆ setStorageLimit()

void dht::SecureDht::setStorageLimit ( size_t  limit = DEFAULT_STORAGE_LIMIT)
inlineoverridevirtual

Set the in-memory storage limit in bytes

Implements dht::DhtInterface.

Definition at line 168 of file securedht.h.

◆ shutdown()

void dht::SecureDht::shutdown ( ShutdownCallback  cb)
inlineoverridevirtual

SecureDht to Dht proxy

Implements dht::DhtInterface.

Definition at line 151 of file securedht.h.

◆ sign()

void dht::SecureDht::sign ( Value v) const

Take ownership of the value and sign it using our private key.


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