dht::Dht Class Referencefinal

`#include <dht.h>`

Inheritance diagram for dht::Dht:
[legend]
Collaboration diagram for dht::Dht:
[legend]

## 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)
Public Member Functions inherited from dht::DhtInterface
virtual NodeStatus | getStatus (sa_family_t af) const =0
virtual NodeStatus | getStatus () const =0
virtual const InfoHash & | getNodeId () const =0
virtual void | shutdown (ShutdownCallback cb)=0
virtual bool | isRunning (sa_family_t af=0) const =0
virtual void | registerType (const ValueType &type)=0
virtual const ValueType & | getType (ValueType::Id type_id) const =0
virtual void | insertNode (const InfoHash &id, const SockAddr &)=0
virtual void | insertNode (const InfoHash &id, const sockaddr *sa, socklen_t salen)=0
virtual void | insertNode (const NodeExport &n)=0
virtual void | pingNode (const sockaddr *, socklen_t, DoneCallbackSimple &&cb={})=0
virtual time_point | periodic (const uint8_t *buf, size_t buflen, const SockAddr &)=0
virtual time_point | periodic (const uint8_t *buf, size_t buflen, const sockaddr *from, socklen_t fromlen)=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, Value::Filter f=Value::AllFilter()) const =0
virtual Sp< Value > | getLocalById (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 &)=0
virtual Sp< Value > | getPut (const InfoHash &, const Value::Id &)=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< NodeExport > | exportNodes ()=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 std::pair< size_t, size_t > | getStoreSize () const =0
virtual std::vector< SockAddr > | getPublicAddress (sa_family_t family=0)=0
virtual void | setLoggers (LogMethod error=NOLOG, LogMethod warn=NOLOG, LogMethod debug=NOLOG)
virtual void | setLogFilter (const InfoHash &f)
virtual void | setPushNotificationToken (const std::string &)
virtual void | pushNotificationReceived (const std::map< std::string, std::string > &data)=0

## Additional Inherited Members

Public Types inherited from dht::DhtInterface
using | Status = NodeStatus
using | NodeExport = dht::NodeExport
Protected Attributes inherited from dht::DhtInterface
bool | logFilerEnable_ {}
InfoHash | logFiler_ {}
Logger | DHT_LOG

## Detailed Description

Main Dht class. Provides a Distributed Hash Table node.

Must be given open UDP sockets and ::periodic must be called regularly.

Definition at line 62 of file dht.h.

## Constructor & Destructor Documentation

## Dht()

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.

## Member Function Documentation

## cancelListen()

virtual bool dht::Dht::cancelListen | ( | const InfoHash & | ,
|  | size_t | token
| ) |  |

virtual

Implements dht::DhtInterface.

## cancelPut()

bool dht::Dht::cancelPut | ( | const InfoHash & | ,
|  | const Value::Id & |
| ) |  |

virtual

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

Implements dht::DhtInterface.

## connectivityChanged() [1/2]

void dht::Dht::connectivityChanged | ( |  | ) |

inline virtual

Implements dht::DhtInterface.

Definition at line 254 of file dht.h.

## connectivityChanged() [2/2]

void dht::Dht::connectivityChanged | ( | sa_family_t |  | ) |

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.

## dumpTables()

void dht::Dht::dumpTables | ( |  | ) | const

virtual

Implements dht::DhtInterface.

## exportNodes()

std::vector< NodeExport > dht::Dht::exportNodes | ( |  | ) |

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.

## exportValues()

std::vector< ValuesExport > dht::Dht::exportValues | ( |  | ) | const

virtual

Implements dht::DhtInterface.

## get() [1/4]

virtual void dht::Dht::get | ( | const InfoHash & | key,
|  | GetCallback | cb,
|  | DoneCallback | donecb = `{}`,
|  | Value::Filter && | f = `{}`,
|  | Where && | w = `{}`
| ) |  |

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

  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.

## get() [2/4]

virtual void dht::Dht::get | ( | const InfoHash & | key,
|  | GetCallback | cb,
|  | DoneCallbackSimple | donecb = `{}`,
|  | Value::Filter && | f = `{}`,
|  | Where && | w = `{}`
| ) |  |

inline virtual

Implements dht::DhtInterface.

Definition at line 139 of file dht.h.

## get() [3/4]

virtual void dht::Dht::get | ( | const InfoHash & | key,
|  | GetCallbackSimple | cb,
|  | DoneCallback | donecb = `{}`,
|  | Value::Filter && | f = `{}`,
|  | Where && | w = `{}`
| ) |  |

inline virtual

Implements dht::DhtInterface.

Definition at line 142 of file dht.h.

## get() [4/4]

virtual void dht::Dht::get | ( | const InfoHash & | key,
|  | GetCallbackSimple | cb,
|  | DoneCallbackSimple | donecb,
|  | Value::Filter && | f = `{}`,
|  | Where && | w = `{}`
| ) |  |

inline virtual

Implements dht::DhtInterface.

Definition at line 145 of file dht.h.

## getLocal()

std::vector< Sp< Value > > dht::Dht::getLocal | ( | const InfoHash & | key,
|  | Value::Filter | f = `Value::AllFilter()`
| ) |  | const

virtual

Get locally stored data for the given hash.

Implements dht::DhtInterface.

## getLocalById()

Sp< Value > dht::Dht::getLocalById | ( | const InfoHash & | key,
|  | Value::Id | vid
| ) |  | const

virtual

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

Implements dht::DhtInterface.

## getNodeId()

const InfoHash & dht::Dht::getNodeId | ( |  | ) | const

inline virtual

Get the ID of the node.

Implements dht::DhtInterface.

Definition at line 77 of file dht.h.

## getNodeMessageStats()

std::vector< unsigned > dht::Dht::getNodeMessageStats | ( | bool | in = `false` | ) |

inline virtual

Implements dht::DhtInterface.

Definition at line 279 of file dht.h.

## getNodesStats()

NodeStats dht::Dht::getNodesStats | ( | sa_family_t | af | ) | const

virtual

Implements dht::DhtInterface.

## getPublicAddress()

std::vector< SockAddr > dht::Dht::getPublicAddress | ( | sa_family_t | family = `0` | ) |

virtual

Implements dht::DhtInterface.

## getPut() [1/2]

std::vector< Sp< Value > > dht::Dht::getPut | ( | const InfoHash & |  | ) |

virtual

Get data currently being put at the given hash.

Implements dht::DhtInterface.

## getPut() [2/2]

Sp< Value > dht::Dht::getPut | ( | const InfoHash & | ,
|  | const Value::Id & |
| ) |  |

virtual

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

Implements dht::DhtInterface.

## getRoutingTablesLog()

std::string dht::Dht::getRoutingTablesLog | ( | sa_family_t |  | ) | const

virtual

Implements dht::DhtInterface.

## getSearchesLog()

std::string dht::Dht::getSearchesLog | ( | sa_family_t |  | ) | const

virtual

Implements dht::DhtInterface.

## getSearchLog()

std::string dht::Dht::getSearchLog | ( | const InfoHash & | ,
|  | sa_family_t | af = `AF_UNSPEC`
| ) |  | const

virtual

Implements dht::DhtInterface.

## getStatus() [1/2]

NodeStatus dht::Dht::getStatus | ( |  | ) | const

inline virtual

Implements dht::DhtInterface.

Definition at line 84 of file dht.h.

## getStatus() [2/2]

NodeStatus dht::Dht::getStatus | ( | sa_family_t | af | ) | const

virtual

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

Implements dht::DhtInterface.

## getStorageLog() [1/2]

std::string dht::Dht::getStorageLog | ( |  | ) | const

virtual

Implements dht::DhtInterface.

## getStorageLog() [2/2]

std::string dht::Dht::getStorageLog | ( | const InfoHash & |  | ) | const

virtual

Implements dht::DhtInterface.

## getStoreSize()

std::pair< size_t, size_t > dht::Dht::getStoreSize | ( |  | ) | const

inline virtual

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

Implements dht::DhtInterface.

Definition at line 294 of file dht.h.

## getType()

const ValueType & dht::Dht::getType | ( | ValueType::Id | type_id | ) | const

inline virtual

Implements dht::DhtInterface.

Definition at line 104 of file dht.h.

## importValues()

void dht::Dht::importValues | ( | const std::vector< ValuesExport > & |  | ) |

virtual

Implements dht::DhtInterface.

## insertNode() [1/3]

void dht::Dht::insertNode | ( | const InfoHash & | id,
|  | const SockAddr & |
| ) |  |

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.

Implements dht::DhtInterface.

## insertNode() [2/3]

void dht::Dht::insertNode | ( | const InfoHash & | id,
|  | const sockaddr * | sa,
|  | socklen_t | salen
| ) |  |

inline virtual

Implements dht::DhtInterface.

Definition at line 114 of file dht.h.

## insertNode() [3/3]

void dht::Dht::insertNode | ( | const NodeExport & | n | ) |

inline virtual

Implements dht::DhtInterface.

Definition at line 117 of file dht.h.

## isRunning()

bool dht::Dht::isRunning | ( | sa_family_t | af = `0` | ) | const

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.

## listen() [1/3]

virtual size_t dht::Dht::listen | ( | const InfoHash & | ,
|  | ValueCallback | ,
|  | Value::Filter | = `{}`,
|  | Where | = `{}`
| ) |  |

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.

Implements dht::DhtInterface.

## listen() [2/3]

virtual size_t dht::Dht::listen | ( | const InfoHash & | ,
|  | GetCallback | ,
|  | Value::Filter | = `{}`,
|  | Where | w = `{}`
| ) |  |

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

Implements dht::DhtInterface.

Definition at line 235 of file dht.h.

## listen() [3/3]

virtual size_t dht::Dht::listen | ( | const InfoHash & | key,
|  | GetCallbackSimple | cb,
|  | Value::Filter | f = `{}`,
|  | Where | w = `{}`
| ) |  |

inline virtual

Implements dht::DhtInterface.

Definition at line 242 of file dht.h.

## periodic() [1/2]

time_point dht::Dht::periodic | ( | const uint8_t * | buf,
|  | size_t | buflen,
|  | const SockAddr & |
| ) |  |

virtual

Implements dht::DhtInterface.

## periodic() [2/2]

time_point dht::Dht::periodic | ( | const uint8_t * | buf,
|  | size_t | buflen,
|  | const sockaddr * | from,
|  | socklen_t | fromlen
| ) |  |

inline virtual

Implements dht::DhtInterface.

Definition at line 124 of file dht.h.

## pingNode()

void dht::Dht::pingNode | ( | const sockaddr * | ,
|  | socklen_t | ,
|  | DoneCallbackSimple && | cb = `{}`
| ) |  |

virtual

Implements dht::DhtInterface.

## pushNotificationReceived()

void dht::Dht::pushNotificationReceived | ( | const std::map< std::string, std::string > & | data | ) |

inline virtual

Call linked callback with a push notification

Parameters

  notification | to process

Implements dht::DhtInterface.

Definition at line 300 of file dht.h.

## put() [1/4]

void dht::Dht::put | ( | const InfoHash & | key,
|  | const Sp< Value > & | v,
|  | DoneCallbackSimple | cb,
|  | time_point | created = `time_point::max()`,
|  | bool | permanent = `false`
| ) |  |

inline virtual

Implements dht::DhtInterface.

Definition at line 184 of file dht.h.

## put() [2/4]

void dht::Dht::put | ( | const InfoHash & | key,
|  | Sp< Value > | ,
|  | DoneCallback | cb = `nullptr`,
|  | time_point | created = `time_point::max()`,
|  | bool | permanent = `false`
| ) |  |

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.

## put() [3/4]

void dht::Dht::put | ( | const InfoHash & | key,
|  | Value && | v,
|  | DoneCallback | cb = `nullptr`,
|  | time_point | created = `time_point::max()`,
|  | bool | permanent = `false`
| ) |  |

inline virtual

Implements dht::DhtInterface.

Definition at line 193 of file dht.h.

## put() [4/4]

void dht::Dht::put | ( | const InfoHash & | key,
|  | Value && | v,
|  | DoneCallbackSimple | cb,
|  | time_point | created = `time_point::max()`,
|  | bool | permanent = `false`
| ) |  |

inline virtual

Implements dht::DhtInterface.

Definition at line 201 of file dht.h.

## query() [1/2]

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

virtual

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

Parameters

  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.

## query() [2/2]

virtual void dht::Dht::query | ( | const InfoHash & | key,
|  | QueryCallback | cb,
|  | DoneCallbackSimple | done_cb = `{}`,
|  | Query && | q = `{}`
| ) |  |

inline virtual

Implements dht::DhtInterface.

Definition at line 159 of file dht.h.

## registerType()

virtual void dht::Dht::registerType | ( | const ValueType & | type | ) |

inline virtual

Implements dht::DhtInterface.

Definition at line 101 of file dht.h.

## resubscribe()

void dht::Dht::resubscribe | ( | unsigned |  | ) |

inline

Definition at line 301 of file dht.h.

## setStorageLimit()

void dht::Dht::setStorageLimit | ( | size_t | limit = `DEFAULT_STORAGE_LIMIT` | ) |

inline virtual

Set the in-memory storage limit in bytes

Implements dht::DhtInterface.

Definition at line 286 of file dht.h.

## shutdown()

void dht::Dht::shutdown | ( | ShutdownCallback | cb | ) |

virtual

Performs final operations before quitting.

Implements dht::DhtInterface.

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

- /tmp/slackbuilds_libs/opendht-1.7.4/include/opendht/dht.h