My Project: dht Namespace Reference

My Project 3.7.7 C++ Distributed Hash Table

Loading...
Searching...
No Matches
Namespaces | Classes | Typedefs | Enumerations | Functions | Variables
dht Namespace Reference

## Namespaces
namespace | crypto
namespace | log

## Classes
struct | NodeStats
struct | NodeInfo
struct | Config
struct | SecureDhtConfig
class | DhtMessage
class | SignedValue
class | EncryptedValue
class | ImMessage
class | TrustRequest
class | IceCandidates
class | IpServiceAnnouncement
class | Dht
class | DhtInterface
class | DhtProxyClient
struct | ProxyServerConfig
class | DhtProxyServer
class | DhtRunner
class | Hash
struct | HexMap
struct | Socket
struct | Node
struct | NodeCache
struct | NodeExport
class | PeerDiscovery
class | RateLimiter
struct | Bucket
class | RoutingTable
class | Scheduler
| Job scheduler. More...
class | SecureDht
class | SockAddr
class | ThreadPool
class | Executor
class | ExecutionContext
class | DhtException
class | SocketException
class | uniform_duration_distribution
struct | ValueType
class | TypeStore
struct | Value
class | FieldValue
| Describes a value filter. More...
class | Select
| Serializable Value field selection. More...
class | Where
| Serializable dht::Value filter. More...
class | Query
| Describes a query destined to another peer. More...
class | FieldValueIndex
| An index for field values. More...

## Typedefs
using | ValuesExport = std::pair<InfoHash, Blob>
using | QueryCallback = std::function<bool(const std::vector<std::shared_ptr<FieldValueIndex>>& fields)>
using | GetCallback = std::function<bool(const std::vector<std::shared_ptr<Value>>& values)>
using | ValueCallback = std::function<bool(const std::vector<std::shared_ptr<Value>>& values, bool expired)>
using | GetCallbackSimple = std::function<bool(std::shared_ptr<Value> value)>
using | ShutdownCallback = std::function<void()>
using | IdentityAnnouncedCb = std::function<void(bool)>
using | PublicAddressChangedCb = std::function<void(std::vector<SockAddr>)>
using | CertificateStoreQueryLegacy = std::function<std::vector<std::shared_ptr<crypto::Certificate>>(const InfoHash& pk_id)>
using | CertificateStoreQuery = std::function<std::vector<std::shared_ptr<crypto::Certificate>>(const PkId& pk_id)>
using | DoneCallback = std::function<void(bool success, const std::vector<std::shared_ptr<Node>>& nodes)>
using | DoneCallbackSimple = std::function<void(bool success)>
typedef bool(* | GetCallbackRaw) (std::shared_ptr< Value >, void *user_data)
typedef bool(* | ValueCallbackRaw) (std::shared_ptr< Value >, bool expired, void *user_data)
typedef void(* | DoneCallbackRaw) (bool, std::vector< std::shared_ptr< Node > > *, void *user_data)
typedef void(* | ShutdownCallbackRaw) (void *user_data)
typedef void(* | DoneCallbackSimpleRaw) (bool, void *user_data)
typedef bool(* | FilterRaw) (const Value &, void *user_data)
using | RestRouter = restinio::router::express_router_t<>
using | RequestStatus = restinio::request_handling_status_t
using | byte = uint8_t
using | InfoHash = Hash<HASH_LEN>
using | h256 = Hash<32>
using | PkId = h256
using | Logger = log::Logger
using | Tid = uint32_t
using | SocketCb = std::function<void(const Sp<Node>&, net::RequestAnswer&&)>
using | NetId = uint32_t
using | want_t = int_fast8_t
template<class T>
using | Sp = std::shared_ptr<T>
using | clock = std::chrono::steady_clock
using | system_clock = std::chrono::system_clock
using | time_point = clock::time_point
using | duration = clock::duration
using | Blob = std::vector<uint8_t>
using | StorePolicy = std::function<bool(InfoHash key, std::shared_ptr<Value>& value, const InfoHash& from, const SockAddr& addr)>
using | EditPolicy

## Enumerations
enum class | NodeStatus { Disconnected , Connecting , Connected }
enum class | ImStatus : uint8_t { NONE = 0 , TYPING , RECEIVED , READ }
enum class | PushType { None = 0 , Android , iOS , UnifiedPush }

## Functions
constexpr std::string_view | statusToStr (NodeStatus status)
OPENDHT_PUBLIC GetCallbackSimple | bindGetCb (GetCallbackRaw raw_cb, void *user_data)
OPENDHT_PUBLIC GetCallback | bindGetCb (GetCallbackSimple cb)
OPENDHT_PUBLIC ValueCallback | bindValueCb (ValueCallbackRaw raw_cb, void *user_data)
OPENDHT_PUBLIC ShutdownCallback | bindShutdownCb (ShutdownCallbackRaw shutdown_cb_raw, void *user_data)
OPENDHT_PUBLIC DoneCallback | bindDoneCb (DoneCallbackSimple donecb)
OPENDHT_PUBLIC DoneCallback | bindDoneCb (DoneCallbackRaw raw_cb, void *user_data)
OPENDHT_PUBLIC DoneCallbackSimple | bindDoneCbSimple (DoneCallbackSimpleRaw raw_cb, void *user_data)
OPENDHT_PUBLIC Value::Filter | bindFilterRaw (FilterRaw raw_filter, void *user_data)
template<size_t N>
std::ostream & | operator<< (std::ostream &s, const Hash< N > &h)
template<size_t N>
std::istream & | operator>> (std::istream &s, Hash< N > &h)
std::string | toHex (const uint8_t *data, size_t size)
std::string | toHex (const std::vector< uint8_t > &data)
template<size_t N>
constexpr std::array< char, N *2 > | toHexArray (const Hash< N > &h)
OPENDHT_PUBLIC void | print_addr (std::ostream &os, const sockaddr *sa, socklen_t slen)
OPENDHT_PUBLIC std::string | print_addr (const sockaddr *sa, socklen_t slen)
OPENDHT_PUBLIC std::string | print_addr (const sockaddr_storage &ss, socklen_t sslen)
OPENDHT_PUBLIC const char * | version ()
template<typename Key, typename Item, typename Condition>
void | erase_if (std::map< Key, Item > &map, const Condition &condition)
template<typename... Args>
std::string | concat (Args &&... args)
OPENDHT_PUBLIC std::pair< std::string_view, std::string_view > | splitPort (std::string_view s)
OPENDHT_PUBLIC time_point | from_time_t (std::time_t t)
OPENDHT_PUBLIC std::time_t | to_time_t (time_point t)
template<class DT>
static std::string | print_duration (DT d)
template<class TimePoint>
static std::string | print_time_relative (TimePoint now, TimePoint d)
OPENDHT_PUBLIC std::string | printByteCount (size_t bytes)
OPENDHT_PUBLIC Blob | unpackBlob (const msgpack::object &o)
template<typename Type>
Blob | packMsg (const Type &t)
template<typename Type>
Type | unpackMsg (const Blob &b)
msgpack::unpacked | unpackMsg (const Blob &b)
OPENDHT_PUBLIC msgpack::object * | findMapValue (const msgpack::object &map, const char *key, size_t length)
msgpack::object * | findMapValue (const msgpack::object &map, const char *key)
msgpack::object * | findMapValue (const msgpack::object &map, std::string_view key)
static constexpr auto | VALUE_KEY_ID ("id")
static const std::string | VALUE_KEY_DAT ("dat")
static const std::string | VALUE_KEY_PRIO ("p")
static const std::string | VALUE_KEY_SIGNATURE ("sig")
static const std::string | VALUE_KEY_SEQ ("seq")
static const std::string | VALUE_KEY_DATA ("data")
static const std::string | VALUE_KEY_OWNER ("owner")
static const std::string | VALUE_KEY_TYPE ("type")
static const std::string | VALUE_KEY_TO ("to")
static const std::string | VALUE_KEY_BODY ("body")
static const std::string | VALUE_KEY_USERTYPE ("utype")
template<typename T, typename std::enable_if< std::is_base_of< Value::SerializableBase, T >::value, T >::type * = nullptr>
Value::Filter | getFilterSet (Value::Filter f)
template<typename T, typename std::enable_if< std::is_base_of< Value::SerializableBase, T >::value, T >::type * = nullptr>
Value::Filter | getFilterSet ()
template<class T>
std::vector< T > | unpackVector (const std::vector< std::shared_ptr< Value > > &vals)

## Variables
enum OPENDHT_PUBLIC | PushNotificationResult
enum OPENDHT_PUBLIC | ListenRefresh
enum OPENDHT_PUBLIC | Values
enum OPENDHT_PUBLIC | ValuesExpired
enum OPENDHT_PUBLIC | IgnoredWrongSession = 0x80
enum OPENDHT_PUBLIC | IgnoredNoOp
enum OPENDHT_PUBLIC | IgnoredStopped
enum OPENDHT_PUBLIC | IgnoredDisabled
enum OPENDHT_PUBLIC | Error
static constexpr size_t | STORAGE_LIMIT_DEFAULT {1024 * 1024 * 64}
static constexpr size_t | STORAGE_LIMIT_UNLIMITED {(size_t) -1}
OPENDHT_PUBLIC const std::array< std::reference_wrapper< const ValueType >, 5 > | DEFAULT_TYPES
OPENDHT_PUBLIC const std::array< std::reference_wrapper< const ValueType >, 1 > | DEFAULT_INSECURE_TYPES
constexpr HexMap | hex_map {}
static constexpr unsigned | TARGET_NODES {8}
const ValueType | CERTIFICATE_TYPE
static constexpr const size_t | MAX_VALUE_SIZE {1024 * 64}
static constexpr const duration | DEFAULT_VALUE_EXPIRATION {std::chrono::minutes(10)}

## Detailed Description

OpenDHT C++ namespace

## Typedef Documentation

## ◆ Blob

using dht::Blob = std::vector<uint8_t>

Arbitrary binary data.

Definition at line 158 of file utils.h.

## ◆ byte

using dht::byte = uint8_t

Definition at line 38 of file infohash.h.

## ◆ CertificateStoreQuery

using dht::CertificateStoreQuery = std::function<std::vector<std::shared_ptr<crypto::Certificate>>(const PkId& pk_id)>

Definition at line 191 of file callbacks.h.

## ◆ CertificateStoreQueryLegacy

using dht::CertificateStoreQueryLegacy = std::function<std::vector<std::shared_ptr<crypto::Certificate>>(const InfoHash& pk_id)>

Definition at line 190 of file callbacks.h.

## ◆ clock

using dht::clock = std::chrono::steady_clock

Definition at line 83 of file utils.h.

## ◆ DoneCallback

using dht::DoneCallback = std::function<void(bool success, const std::vector<std::shared_ptr<Node>>& nodes)>

Definition at line 193 of file callbacks.h.

## ◆ DoneCallbackRaw

typedef void(* dht::DoneCallbackRaw) (bool, std::vector< std::shared_ptr< Node > > *, void *user_data)

Definition at line 198 of file callbacks.h.

## ◆ DoneCallbackSimple

using dht::DoneCallbackSimple = std::function<void(bool success)>

Definition at line 194 of file callbacks.h.

## ◆ DoneCallbackSimpleRaw

typedef void(* dht::DoneCallbackSimpleRaw) (bool, void *user_data)

Definition at line 200 of file callbacks.h.

## ◆ duration

using dht::duration = clock::duration

Definition at line 86 of file utils.h.

## ◆ EditPolicy

using dht::EditPolicy

Initial value:
std::function<bool(InfoHash key,
const std::shared_ptr<Value>& old_val,
std::shared_ptr<Value>& new_val,
const InfoHash& from,
const SockAddr& addr)>
dht::SockAddr
Definition sockaddr.h:47

An edition policy is applied once to every incoming value storage requests, if a value already exists for this key and value id. If the policy returns false, the edition request is ignored. The default behavior is to deny edition (see {ValueType::DEFAULT_EDIT_POLICY}). Some {ValueType}s may override this behavior (e.g. SignedValue).

Parameters

  key | the key where the value is stored.
  old_val | the previously stored value.
  new_val | the new value to be stored. The value can be edited by the edit policy.
  from | id of the requesting node.
  form_addr | network address of the incoming request.
  from_len | network address lendth of the incoming request.

Definition at line 73 of file value.h.

## ◆ FilterRaw

typedef bool(* dht::FilterRaw) (const Value &, void *user_data)

Definition at line 201 of file callbacks.h.

## ◆ GetCallback

using dht::GetCallback = std::function<bool(const std::vector<std::shared_ptr<Value>>& values)>

Definition at line 183 of file callbacks.h.

## ◆ GetCallbackRaw

typedef bool(* dht::GetCallbackRaw) (std::shared_ptr< Value >, void *user_data)

Definition at line 196 of file callbacks.h.

## ◆ GetCallbackSimple

using dht::GetCallbackSimple = std::function<bool(std::shared_ptr<Value> value)>

Definition at line 185 of file callbacks.h.

## ◆ h256

using dht::h256 = Hash<32>

Definition at line 279 of file infohash.h.

## ◆ IdentityAnnouncedCb

using dht::IdentityAnnouncedCb = std::function<void(bool)>

Definition at line 187 of file callbacks.h.

## ◆ InfoHash

using dht::InfoHash = Hash<HASH_LEN>

Definition at line 278 of file infohash.h.

## ◆ Logger

using dht::Logger = log::Logger

Definition at line 205 of file logger.h.

## ◆ NetId

using dht::NetId = uint32_t

Definition at line 27 of file utils.h.

## ◆ PkId

using dht::PkId = h256

Definition at line 280 of file infohash.h.

## ◆ PublicAddressChangedCb

using dht::PublicAddressChangedCb = std::function<void(std::vector<SockAddr>)>

Definition at line 188 of file callbacks.h.

## ◆ QueryCallback

using dht::QueryCallback = std::function<bool(const std::vector<std::shared_ptr<FieldValueIndex>>& fields)>

Definition at line 182 of file callbacks.h.

## ◆ RequestStatus

using dht::RequestStatus = restinio::request_handling_status_t

Definition at line 40 of file dht_proxy_server.h.

## ◆ RestRouter

using dht::RestRouter = restinio::router::express_router_t<>

Definition at line 39 of file dht_proxy_server.h.

## ◆ ShutdownCallback

using dht::ShutdownCallback = std::function<void()>

Definition at line 186 of file callbacks.h.

## ◆ ShutdownCallbackRaw

typedef void(* dht::ShutdownCallbackRaw) (void *user_data)

Definition at line 199 of file callbacks.h.

## ◆ SocketCb

using dht::SocketCb = std::function<void(const Sp<Node>&, net::RequestAnswer&&)>

Definition at line 23 of file node.h.

## ◆ Sp

template<class T>

using dht::Sp = std::shared_ptr<T>

Definition at line 34 of file utils.h.

## ◆ StorePolicy

using dht::StorePolicy = std::function<bool(InfoHash key, std::shared_ptr<Value>& value, const InfoHash& from, const SockAddr& addr)>

A storage policy is applied once to every incoming value storage requests. If the policy returns false, the value is dropped.

Parameters

  key | the key where the storage is requested.
  value | the value to be stored. The value can be edited by the storage policy.
  from | id of the requesting node.
  form_addr | network address of the incoming request.
  from_len | network address lendth of the incoming request.

Definition at line 57 of file value.h.

## ◆ system_clock

using dht::system_clock = std::chrono::system_clock

Definition at line 84 of file utils.h.

## ◆ Tid

using dht::Tid = uint32_t

Definition at line 22 of file node.h.

## ◆ time_point

using dht::time_point = clock::time_point

Definition at line 85 of file utils.h.

## ◆ ValueCallback

using dht::ValueCallback = std::function<bool(const std::vector<std::shared_ptr<Value>>& values, bool expired)>

Definition at line 184 of file callbacks.h.

## ◆ ValueCallbackRaw

typedef bool(* dht::ValueCallbackRaw) (std::shared_ptr< Value >, bool expired, void *user_data)

Definition at line 197 of file callbacks.h.

## ◆ ValuesExport

typedef std::pair< InfoHash, Blob > dht::ValuesExport = std::pair<InfoHash, Blob>

Definition at line 180 of file callbacks.h.

## ◆ want_t

using dht::want_t = int_fast8_t

Definition at line 28 of file utils.h.

## Enumeration Type Documentation

## ◆ ImStatus

enum class dht::ImStatus : uint8_t
| strong

Definition at line 9 of file default_types.h.

## ◆ NodeStatus

enum class dht::NodeStatus
| strong

Current status of a DHT node.

Definition at line 24 of file callbacks.h.

## ◆ PushType

enum class dht::PushType
| strong

Definition at line 22 of file dht_proxy_server.h.

## Function Documentation

## ◆ concat()

template<typename... Args>

std::string dht::concat | ( | Args &&... | args | ) |

Definition at line 51 of file utils.h.

## ◆ erase_if()

template<typename Key, typename Item, typename Condition>

void dht::erase_if | ( | std::map< Key, Item > & | map,
|  | const Condition & | condition )

Definition at line 38 of file utils.h.

## ◆ findMapValue() [1/2]

msgpack::object * dht::findMapValue | ( | const msgpack::object & | map,
|  | const char * | key )
| inline

Definition at line 192 of file utils.h.

## ◆ findMapValue() [2/2]

msgpack::object * dht::findMapValue | ( | const msgpack::object & | map,
|  | std::string_view | key )
| inline

Definition at line 197 of file utils.h.

## ◆ getFilterSet() [1/2]

template<typename T, typename std::enable_if< std::is_base_of< Value::SerializableBase, T >::value, T >::type * = nullptr>

Value::Filter dht::getFilterSet | ( |  | ) |

Definition at line 1095 of file value.h.

## ◆ getFilterSet() [2/2]

template<typename T, typename std::enable_if< std::is_base_of< Value::SerializableBase, T >::value, T >::type * = nullptr>

Value::Filter dht::getFilterSet | ( | Value::Filter | f | ) |

Definition at line 1081 of file value.h.

## ◆ operator<<()

template<size_t N>

std::ostream & dht::operator<< | ( | std::ostream & | s,
|  | const Hash< N > & | h )

Definition at line 283 of file infohash.h.

## ◆ operator>>()

template<size_t N>

std::istream & dht::operator>> | ( | std::istream & | s,
|  | Hash< N > & | h )

Definition at line 292 of file infohash.h.

## ◆ packMsg()

template<typename Type>

Blob dht::packMsg | ( | const Type & | t | ) |

Definition at line 167 of file utils.h.

## ◆ print_duration()

template<class DT>

std::string dht::print_duration | ( | DT | d | ) |
| static

Definition at line 93 of file utils.h.

## ◆ print_time_relative()

template<class TimePoint>

std::string dht::print_time_relative | ( | TimePoint | now,
|  | TimePoint | d )
| static

Definition at line 119 of file utils.h.

## ◆ splitPort()

OPENDHT_PUBLIC std::pair< std::string_view, std::string_view > dht::splitPort | ( | std::string_view | s | ) |

Split "[host]:port" or "host:port" to pair<"host", "port">.

## ◆ statusToStr()

std::string_view dht::statusToStr | ( | NodeStatus | status | ) |
| inlineconstexpr

Definition at line 31 of file callbacks.h.

## ◆ toHex() [1/2]

std::string dht::toHex | ( | const std::vector< uint8_t > & | data | ) |
| inline

Definition at line 401 of file infohash.h.

## ◆ toHex() [2/2]

std::string dht::toHex | ( | const uint8_t * | data,
|  | size_t | size )
| inline

Definition at line 389 of file infohash.h.

## ◆ toHexArray()

template<size_t N>

std::array< char, N *2 > dht::toHexArray | ( | const Hash< N > & | h | ) |
| constexpr

Definition at line 408 of file infohash.h.

## ◆ unpackBlob()

OPENDHT_PUBLIC Blob dht::unpackBlob | ( | const msgpack::object & | o | ) |

Provides backward compatibility with msgpack 1.0

## ◆ unpackMsg() [1/2]

msgpack::unpacked dht::unpackMsg | ( | const Blob & | b | ) |
| inline

Definition at line 184 of file utils.h.

## ◆ unpackMsg() [2/2]

template<typename Type>

Type dht::unpackMsg | ( | const Blob & | b | ) |

Definition at line 177 of file utils.h.

## ◆ unpackVector()

template<class T>

std::vector< T > dht::unpackVector | ( | const std::vector< std::shared_ptr< Value > > & | vals | ) |

Definition at line 1109 of file value.h.

## Variable Documentation

## ◆ CERTIFICATE_TYPE

const ValueType dht::CERTIFICATE_TYPE

Initial value:
= {8,
"Certificate",
std::chrono::hours(24 * 7),
[](InfoHash id, Sp<Value>& v, const InfoHash&, const SockAddr&) {
try {
crypto::Certificate crt(v->data);
return crt.getPublicKey().getId() == id
|| InfoHash::get(crt.getPublicKey().getLongId()) == id;
} catch (const std::exception& e) {
}
return false;
},
[](InfoHash, const Sp<Value>& o, Sp<Value>& n, const InfoHash&, const SockAddr&) {
try {
return crypto::Certificate(o->data).getPublicKey().getLongId()
== crypto::Certificate(n->data).getPublicKey().getLongId();
} catch (const std::exception& e) {
}
return false;
}}
dht::crypto::Certificate
Definition crypto.h:412
dht::crypto::PublicKey::getLongId
const PkId & getLongId() const

Definition at line 362 of file securedht.h.

## ◆ DEFAULT_VALUE_EXPIRATION

const duration dht::DEFAULT_VALUE_EXPIRATION {std::chrono::minutes(10)}
| staticconstexpr

Definition at line 80 of file value.h.

## ◆ Error

enum OPENDHT_PUBLIC dht::Error

Definition at line 174 of file callbacks.h.

## ◆ hex_map

HexMap dht::hex_map {}
| inlineconstexpr

Definition at line 386 of file infohash.h.

## ◆ IgnoredDisabled

enum OPENDHT_PUBLIC dht::IgnoredDisabled

Definition at line 173 of file callbacks.h.

## ◆ IgnoredNoOp

enum OPENDHT_PUBLIC dht::IgnoredNoOp

Definition at line 171 of file callbacks.h.

## ◆ IgnoredStopped

enum OPENDHT_PUBLIC dht::IgnoredStopped

Definition at line 172 of file callbacks.h.

## ◆ IgnoredWrongSession

enum OPENDHT_PUBLIC dht::IgnoredWrongSession = 0x80

Definition at line 170 of file callbacks.h.

## ◆ ListenRefresh

enum OPENDHT_PUBLIC dht::ListenRefresh

Definition at line 166 of file callbacks.h.

## ◆ MAX_VALUE_SIZE

const size_t dht::MAX_VALUE_SIZE {1024 * 64}
| staticconstexpr

Definition at line 79 of file value.h.

## ◆ PushNotificationResult

enum OPENDHT_PUBLIC dht::PushNotificationResult
| strong

Definition at line 163 of file callbacks.h.

## ◆ STORAGE_LIMIT_DEFAULT

size_t dht::STORAGE_LIMIT_DEFAULT {1024 * 1024 * 64}
| staticconstexpr

Definition at line 177 of file callbacks.h.

## ◆ STORAGE_LIMIT_UNLIMITED

size_t dht::STORAGE_LIMIT_UNLIMITED {(size_t) -1}
| staticconstexpr

Definition at line 178 of file callbacks.h.

## ◆ TARGET_NODES

unsigned dht::TARGET_NODES {8}
| staticconstexpr

Definition at line 9 of file routing_table.h.

## ◆ Values

enum OPENDHT_PUBLIC dht::Values

Definition at line 167 of file callbacks.h.

## ◆ ValuesExpired

enum OPENDHT_PUBLIC dht::ValuesExpired

Definition at line 168 of file callbacks.h.