My Project 3.2.0
C++ Distributed Hash Table
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Attributes | List of all members
dht::DhtInterface Class Referenceabstract
Inheritance diagram for dht::DhtInterface:
Inheritance graph
[legend]
Collaboration diagram for dht::DhtInterface:
Collaboration graph
[legend]

Public Types

using Status = NodeStatus
 
using NodeExport = dht::NodeExport
 

Public Member Functions

 DhtInterface (const Logger &l)
 
 DhtInterface (const std::shared_ptr< Logger > &l)
 
virtual NodeStatus updateStatus (sa_family_t af)
 
virtual NodeStatus getStatus (sa_family_t af) const =0
 
virtual NodeStatus getStatus () const =0
 
void addOnConnectedCallback (std::function< void()> cb)
 
virtual void setOnPublicAddressChanged (PublicAddressChangedCb)
 
virtual net::DatagramSocketgetSocket () const
 
virtual const InfoHashgetNodeId () const =0
 
virtual void shutdown (ShutdownCallback cb, bool stop=false)=0
 
virtual bool isRunning (sa_family_t af=0) const =0
 
virtual void registerType (const ValueType &type)=0
 
virtual const ValueTypegetType (ValueType::Id type_id) const =0
 
virtual void addBootstrap (const std::string &, const std::string &)
 
virtual void clearBootstrap ()
 
virtual void insertNode (const InfoHash &id, const SockAddr &)=0
 
virtual void insertNode (const NodeExport &n)=0
 
virtual void pingNode (SockAddr, DoneCallbackSimple &&cb={})=0
 
virtual time_point periodic (const uint8_t *buf, size_t buflen, SockAddr, const time_point &now)=0
 
virtual time_point periodic (const uint8_t *buf, size_t buflen, const sockaddr *from, socklen_t fromlen, const time_point &now)=0
 
virtual void get (const InfoHash &key, GetCallback cb, DoneCallback donecb={}, Value::Filter &&f={}, Where &&w={})=0
 
virtual void get (const InfoHash &key, GetCallback cb, DoneCallbackSimple donecb={}, Value::Filter &&f={}, Where &&w={})=0
 
virtual void get (const InfoHash &key, GetCallbackSimple cb, DoneCallback donecb={}, Value::Filter &&f={}, Where &&w={})=0
 
virtual void get (const InfoHash &key, GetCallbackSimple cb, DoneCallbackSimple donecb, Value::Filter &&f={}, Where &&w={})=0
 
virtual void query (const InfoHash &key, QueryCallback cb, DoneCallback done_cb={}, Query &&q={})=0
 
virtual void query (const InfoHash &key, QueryCallback cb, DoneCallbackSimple done_cb={}, Query &&q={})=0
 
virtual std::vector< Sp< Value > > getLocal (const InfoHash &key, const Value::Filter &f={}) const =0
 
virtual Sp< ValuegetLocalById (const InfoHash &key, Value::Id vid) const =0
 
virtual void put (const InfoHash &key, Sp< Value >, DoneCallback cb=nullptr, time_point created=time_point::max(), bool permanent=false)=0
 
virtual void put (const InfoHash &key, const Sp< Value > &v, DoneCallbackSimple cb, time_point created=time_point::max(), bool permanent=false)=0
 
virtual void put (const InfoHash &key, Value &&v, DoneCallback cb=nullptr, time_point created=time_point::max(), bool permanent=false)=0
 
virtual void put (const InfoHash &key, Value &&v, DoneCallbackSimple cb, time_point created=time_point::max(), bool permanent=false)=0
 
virtual std::vector< Sp< Value > > getPut (const InfoHash &) const =0
 
virtual Sp< ValuegetPut (const InfoHash &, const Value::Id &) const =0
 
virtual bool cancelPut (const InfoHash &, const Value::Id &)=0
 
virtual size_t listen (const InfoHash &, GetCallback, Value::Filter={}, Where w={})=0
 
virtual size_t listen (const InfoHash &key, GetCallbackSimple cb, Value::Filter f={}, Where w={})=0
 
virtual size_t listen (const InfoHash &, ValueCallback, Value::Filter={}, Where w={})=0
 
virtual bool cancelListen (const InfoHash &, size_t token)=0
 
virtual void connectivityChanged (sa_family_t)=0
 
virtual void connectivityChanged ()=0
 
virtual std::vector< NodeExportexportNodes () const =0
 
virtual std::vector< ValuesExport > exportValues () const =0
 
virtual void importValues (const std::vector< ValuesExport > &)=0
 
virtual NodeStats getNodesStats (sa_family_t af) const =0
 
virtual std::string getStorageLog () const =0
 
virtual std::string getStorageLog (const InfoHash &) const =0
 
virtual std::string getRoutingTablesLog (sa_family_t) const =0
 
virtual std::string getSearchesLog (sa_family_t) const =0
 
virtual std::string getSearchLog (const InfoHash &, sa_family_t af=AF_UNSPEC) const =0
 
virtual void dumpTables () const =0
 
virtual std::vector< unsigned > getNodeMessageStats (bool in=false)=0
 
virtual void setStorageLimit (size_t limit=DEFAULT_STORAGE_LIMIT)=0
 
virtual size_t getStorageLimit () const =0
 
virtual std::pair< size_t, size_t > getStoreSize () const =0
 
virtual std::vector< SockAddrgetPublicAddress (sa_family_t family=0)=0
 
virtual void setLogger (const Logger &l)
 
virtual void setLogger (const std::shared_ptr< Logger > &l)
 
virtual void setLogFilter (const InfoHash &f)
 
virtual void setPushNotificationToken (const std::string &)
 
virtual void setPushNotificationTopic (const std::string &)
 
virtual void setPushNotificationPlatform (const std::string &)
 
virtual void pushNotificationReceived (const std::map< std::string, std::string > &data)=0
 

Protected Attributes

std::shared_ptr< Loggerlogger_ {}
 
std::queue< std::function< void()> > onConnectCallbacks_ {}
 

Detailed Description

Definition at line 33 of file dht_interface.h.

Member Typedef Documentation

◆ NodeExport

Definition at line 43 of file dht_interface.h.

◆ Status

Definition at line 41 of file dht_interface.h.

Constructor & Destructor Documentation

◆ DhtInterface() [1/2]

dht::DhtInterface::DhtInterface ( const Logger & l)
inline

Definition at line 36 of file dht_interface.h.

◆ DhtInterface() [2/2]

dht::DhtInterface::DhtInterface ( const std::shared_ptr< Logger > & l)
inline

Definition at line 37 of file dht_interface.h.

Member Function Documentation

◆ addBootstrap()

virtual void dht::DhtInterface::addBootstrap ( const std::string & ,
const std::string &  )
inlinevirtual

Definition at line 83 of file dht_interface.h.

◆ addOnConnectedCallback()

void dht::DhtInterface::addOnConnectedCallback ( std::function< void()> cb)
inline

Definition at line 52 of file dht_interface.h.

◆ cancelPut()

virtual bool dht::DhtInterface::cancelPut ( const InfoHash & ,
const Value::Id &  )
pure virtual

Stop any put/announce operation at the given location, for the value with the given id.

Implemented in dht::Dht, dht::DhtProxyClient, and dht::SecureDht.

◆ clearBootstrap()

virtual void dht::DhtInterface::clearBootstrap ( )
inlinevirtual

Definition at line 84 of file dht_interface.h.

◆ connectivityChanged()

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

Implemented in dht::SecureDht, dht::Dht, and dht::DhtProxyClient.

◆ exportNodes()

virtual std::vector< NodeExport > dht::DhtInterface::exportNodes ( ) const
pure virtual

Get the list of good nodes for local storage saving purposes The list is ordered to minimize the back-to-work delay.

Implemented in dht::Dht, dht::DhtProxyClient, and dht::SecureDht.

◆ get()

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

Parameters
cba function called when new values are found on the network. It should return false to stop the operation.
donecba function called when the operation is complete. cb and donecb won't be called again afterward.
fa filter function used to prefilter values.

Implemented in dht::SecureDht, dht::Dht, and dht::DhtProxyClient.

◆ getLocal()

virtual std::vector< Sp< Value > > dht::DhtInterface::getLocal ( const InfoHash & key,
const Value::Filter & f = {} ) const
pure virtual

Get locally stored data for the given hash.

Implemented in dht::DhtProxyClient, dht::Dht, and dht::SecureDht.

◆ getLocalById()

virtual Sp< Value > dht::DhtInterface::getLocalById ( const InfoHash & key,
Value::Id vid ) const
pure virtual

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

Implemented in dht::DhtProxyClient, dht::Dht, and dht::SecureDht.

◆ getNodeId()

virtual const InfoHash & dht::DhtInterface::getNodeId ( ) const
pure virtual

Get the ID of the DHT node.

Implemented in dht::Dht, dht::DhtProxyClient, and dht::SecureDht.

◆ getNodesStats()

virtual NodeStats dht::DhtInterface::getNodesStats ( sa_family_t af) const
pure virtual

Implemented in dht::DhtProxyClient.

◆ getPublicAddress()

virtual std::vector< SockAddr > dht::DhtInterface::getPublicAddress ( sa_family_t family = 0)
pure virtual

Implemented in dht::DhtProxyClient.

◆ getPut() [1/2]

virtual std::vector< Sp< Value > > dht::DhtInterface::getPut ( const InfoHash & ) const
pure virtual

Get data currently being put at the given hash.

Implemented in dht::Dht, dht::DhtProxyClient, and dht::SecureDht.

◆ getPut() [2/2]

virtual Sp< Value > dht::DhtInterface::getPut ( const InfoHash & ,
const Value::Id &  ) const
pure virtual

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

Implemented in dht::Dht, dht::DhtProxyClient, and dht::SecureDht.

◆ getSocket()

virtual net::DatagramSocket * dht::DhtInterface::getSocket ( ) const
inlinevirtual

Definition at line 57 of file dht_interface.h.

◆ getStatus()

virtual NodeStatus dht::DhtInterface::getStatus ( sa_family_t af) const
pure virtual

Implemented in dht::Dht, and dht::DhtProxyClient.

◆ getStoreSize()

virtual std::pair< size_t, size_t > dht::DhtInterface::getStoreSize ( ) const
pure virtual

Returns the total memory usage of stored values and the number of stored values.

Implemented in dht::Dht, dht::DhtProxyClient, and dht::SecureDht.

◆ insertNode()

virtual void dht::DhtInterface::insertNode ( const InfoHash & id,
const SockAddr &  )
pure virtual

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.

Implemented in dht::DhtProxyClient, dht::Dht, and dht::SecureDht.

◆ isRunning()

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

Implemented in dht::Dht, dht::DhtProxyClient, and dht::SecureDht.

◆ listen() [1/2]

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

Returns
a token to cancel the listener later.

Implemented in dht::Dht, dht::DhtProxyClient, and dht::SecureDht.

◆ listen() [2/2]

virtual size_t dht::DhtInterface::listen ( const InfoHash & ,
ValueCallback ,
Value::Filter = {},
Where w = {} )
pure virtual

Implemented in dht::Dht, and dht::DhtProxyClient.

◆ pushNotificationReceived()

virtual void dht::DhtInterface::pushNotificationReceived ( const std::map< std::string, std::string > & data)
pure virtual

Call linked callback with a push notification

Parameters
notificationto process

Implemented in dht::Dht, dht::DhtProxyClient, and dht::SecureDht.

◆ put()

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

Implemented in dht::SecureDht, dht::Dht, and dht::DhtProxyClient.

◆ query()

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

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.

Implemented in dht::DhtProxyClient, dht::Dht, and dht::SecureDht.

◆ setLogFilter()

virtual void dht::DhtInterface::setLogFilter ( const InfoHash & f)
inlinevirtual

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

Reimplemented in dht::SecureDht.

Definition at line 250 of file dht_interface.h.

◆ setLogger() [1/2]

virtual void dht::DhtInterface::setLogger ( const Logger & l)
inlinevirtual

Definition at line 236 of file dht_interface.h.

◆ setLogger() [2/2]

virtual void dht::DhtInterface::setLogger ( const std::shared_ptr< Logger > & l)
inlinevirtual

Definition at line 243 of file dht_interface.h.

◆ setOnPublicAddressChanged()

virtual void dht::DhtInterface::setOnPublicAddressChanged ( PublicAddressChangedCb )
inlinevirtual

Definition at line 55 of file dht_interface.h.

◆ setPushNotificationPlatform()

virtual void dht::DhtInterface::setPushNotificationPlatform ( const std::string & )
inlinevirtual

Definition at line 259 of file dht_interface.h.

◆ setPushNotificationToken()

virtual void dht::DhtInterface::setPushNotificationToken ( const std::string & )
inlinevirtual

Definition at line 256 of file dht_interface.h.

◆ setPushNotificationTopic()

virtual void dht::DhtInterface::setPushNotificationTopic ( const std::string & )
inlinevirtual

Definition at line 258 of file dht_interface.h.

◆ setStorageLimit()

virtual void dht::DhtInterface::setStorageLimit ( size_t limit = DEFAULT_STORAGE_LIMIT)
pure virtual

Set the in-memory storage limit in bytes

Implemented in dht::Dht, dht::SecureDht, and dht::DhtProxyClient.

◆ shutdown()

virtual void dht::DhtInterface::shutdown ( ShutdownCallback cb,
bool stop = false )
pure virtual

Performs final operations before quitting. stop: if true, cancel ongoing operations and call their 'done' callbacks synchronously.

Implemented in dht::Dht, dht::SecureDht, and dht::DhtProxyClient.

◆ updateStatus()

virtual NodeStatus dht::DhtInterface::updateStatus ( sa_family_t af)
inlinevirtual

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

Reimplemented in dht::Dht, and dht::SecureDht.

Definition at line 48 of file dht_interface.h.

Member Data Documentation

◆ logger_

std::shared_ptr<Logger> dht::DhtInterface::logger_ {}
protected

Definition at line 268 of file dht_interface.h.

◆ onConnectCallbacks_

std::queue<std::function<void()> > dht::DhtInterface::onConnectCallbacks_ {}
protected

Definition at line 269 of file dht_interface.h.


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