My Project 1.7.4
C++ Distributed Hash Table
Namespaces | Classes | Typedefs | Enumerations | Functions | Variables
dht Namespace Reference

Namespaces

namespace  crypto
 
namespace  log
 

Classes

struct  Bucket
 
struct  Config
 
class  Dht
 
class  DhtException
 
class  DhtInterface
 
class  DhtMessage
 
class  DhtRunner
 
class  EncryptedValue
 
class  FieldValue
 Describes a value filter. More...
 
class  FieldValueIndex
 An index for field values. More...
 
class  Hash
 
struct  HexMap
 
class  IceCandidates
 
class  ImMessage
 
class  IpServiceAnnouncement
 
struct  Logger
 
struct  LogMethod
 
struct  Node
 
struct  NodeCache
 
struct  NodeExport
 
struct  NodeInfo
 
struct  NodeStats
 
class  Query
 Describes a query destined to another peer. More...
 
class  RateLimiter
 
class  RoutingTable
 
class  Scheduler
 Job scheduler. More...
 
class  SecureDht
 
struct  SecureDhtConfig
 
class  Select
 Serializable Value field selection. More...
 
class  SignedValue
 
class  SockAddr
 
struct  Socket
 
class  SocketException
 
class  TrustRequest
 
class  TypeStore
 
class  uniform_duration_distribution
 
struct  Value
 
struct  ValueType
 
class  Where
 Serializable dht::Value filter. 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 CertificateStoreQuery = std::function< std::vector< std::shared_ptr< crypto::Certificate > >(const InfoHash &pk_id)>
 
typedef bool(* GetCallbackRaw) (std::shared_ptr< Value >, void *user_data)
 
using DoneCallback = std::function< void(bool success, const std::vector< std::shared_ptr< Node > > &nodes)>
 
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 DoneCallbackSimple = std::function< void(bool success)>
 
using byte = uint8_t
 
using InfoHash = Hash< HASH_LEN >
 
using h256 = Hash< 32 >
 
using PkId = h256
 
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 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 = std::function< bool(InfoHash key, const std::shared_ptr< Value > &old_val, std::shared_ptr< Value > &new_val, const InfoHash &from, const SockAddr &addr)>
 

Enumerations

enum class  NodeStatus { Disconnected , Connecting , Connected }
 
enum class  ImStatus : uint8_t { NONE = 0 , TYPING , RECEIVED , READ }
 

Functions

OPENDHT_PUBLIC GetCallbackSimple bindGetCb (GetCallbackRaw raw_cb, void *user_data)
 
OPENDHT_PUBLIC GetCallback bindGetCb (GetCallbackSimple cb)
 
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)
 
void NOLOG (char const *, va_list)
 
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 bool operator== (const SockAddr &a, const SockAddr &b)
 
template<typename Key , typename Item , typename Condition >
void erase_if (std::map< Key, Item > &map, const Condition &condition)
 
OPENDHT_PUBLIC std::pair< std::string, std::string > splitPort (const std::string &s)
 
time_point from_time_t (std::time_t t)
 
std::time_t to_time_t (time_point t)
 
template<class DT >
static double print_dt (DT d)
 
OPENDHT_PUBLIC Blob unpackBlob (msgpack::object &o)
 
template<typename Type >
Blob packMsg (const Type &t)
 
template<typename Type >
Type unpackMsg (Blob b)
 
msgpack::unpacked unpackMsg (Blob b)
 
msgpack::object * findMapValue (msgpack::object &map, const std::string &key)
 
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

static constexpr size_t DEFAULT_STORAGE_LIMIT {1024 * 1024 * 64}
 
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
 
OPENDHT_PUBLIC const HexMap hex_map
 
const InfoHash zeroes {}
 
static constexpr unsigned TARGET_NODES {8}
 
const ValueType CERTIFICATE_TYPE
 
static constexpr const size_t MAX_VALUE_SIZE {1024 * 64}
 

Detailed Description

OpenDHT C++ namespace

Typedef Documentation

◆ Blob

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

Arbitrary binary data.

Definition at line 114 of file utils.h.

◆ byte

using dht::byte = typedef uint8_t

Definition at line 50 of file infohash.h.

◆ CertificateStoreQuery

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

Definition at line 126 of file callbacks.h.

◆ clock

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

Definition at line 77 of file utils.h.

◆ DoneCallback

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

Definition at line 133 of file callbacks.h.

◆ DoneCallbackRaw

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

Definition at line 134 of file callbacks.h.

◆ DoneCallbackSimple

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

Definition at line 139 of file callbacks.h.

◆ DoneCallbackSimpleRaw

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

Definition at line 136 of file callbacks.h.

◆ duration

using dht::duration = typedef clock::duration

Definition at line 79 of file utils.h.

◆ EditPolicy

using dht::EditPolicy = typedef std::function<bool(InfoHash key, const std::shared_ptr<Value>& old_val, std::shared_ptr<Value>& new_val, const InfoHash& from, const SockAddr& addr)>

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
keythe key where the value is stored.
old_valthe previously stored value.
new_valthe new value to be stored. The value can be edited by the edit policy.
fromid of the requesting node.
form_addrnetwork address of the incoming request.
from_lennetwork address lendth of the incoming request.

Definition at line 75 of file value.h.

◆ FilterRaw

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

Definition at line 137 of file callbacks.h.

◆ GetCallback

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

Definition at line 121 of file callbacks.h.

◆ GetCallbackRaw

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

Definition at line 128 of file callbacks.h.

◆ GetCallbackSimple

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

Definition at line 123 of file callbacks.h.

◆ h256

using dht::h256 = typedef Hash<32>

Definition at line 269 of file infohash.h.

◆ InfoHash

using dht::InfoHash = typedef Hash<HASH_LEN>

Definition at line 268 of file infohash.h.

◆ NetId

using dht::NetId = typedef uint32_t

Definition at line 40 of file utils.h.

◆ PkId

using dht::PkId = typedef h256

Definition at line 270 of file infohash.h.

◆ QueryCallback

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

Definition at line 120 of file callbacks.h.

◆ ShutdownCallback

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

Definition at line 124 of file callbacks.h.

◆ ShutdownCallbackRaw

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

Definition at line 135 of file callbacks.h.

◆ SocketCb

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

Definition at line 39 of file node.h.

◆ Sp

template<class T >
using dht::Sp = typedef std::shared_ptr<T>

Definition at line 45 of file utils.h.

◆ StorePolicy

using dht::StorePolicy = typedef 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
keythe key where the storage is requested.
valuethe value to be stored. The value can be edited by the storage policy.
fromid of the requesting node.
form_addrnetwork address of the incoming request.
from_lennetwork address lendth of the incoming request.

Definition at line 59 of file value.h.

◆ Tid

using dht::Tid = typedef uint32_t

Definition at line 38 of file node.h.

◆ time_point

using dht::time_point = typedef clock::time_point

Definition at line 78 of file utils.h.

◆ ValueCallback

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

Definition at line 122 of file callbacks.h.

◆ ValuesExport

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

Definition at line 118 of file callbacks.h.

◆ want_t

using dht::want_t = typedef int_fast8_t

Definition at line 41 of file utils.h.

Enumeration Type Documentation

◆ ImStatus

enum class dht::ImStatus : uint8_t
strong

Definition at line 25 of file default_types.h.

◆ NodeStatus

enum class dht::NodeStatus
strong

Current status of a DHT node.

Definition at line 41 of file callbacks.h.

Function Documentation

◆ erase_if()

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

Definition at line 48 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 970 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 950 of file value.h.

◆ NOLOG()

void dht::NOLOG ( char const *  ,
va_list   
)
inline

Dummy function used to disable logging

Definition at line 38 of file log_enable.h.

◆ operator<<()

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

Definition at line 273 of file infohash.h.

◆ operator>>()

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

Definition at line 280 of file infohash.h.

◆ packMsg()

template<typename Type >
Blob dht::packMsg ( const Type &  t)

Definition at line 123 of file utils.h.

◆ print_dt()

template<class DT >
static double dht::print_dt ( DT  d)
static

Converts std::chrono::duration to floating-point seconds.

Definition at line 89 of file utils.h.

◆ splitPort()

OPENDHT_PUBLIC std::pair< std::string, std::string > dht::splitPort ( const std::string &  s)

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

◆ unpackBlob()

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

Provides backward compatibility with msgpack 1.0

◆ unpackMsg()

template<typename Type >
Type dht::unpackMsg ( Blob  b)

Definition at line 132 of file utils.h.

◆ unpackVector()

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

Definition at line 988 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;
} 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().getId() == crypto::Certificate(n->data).getPublicKey().getId();
} catch (const std::exception& e) {}
return false;
}
}

Definition at line 352 of file securedht.h.

◆ DEFAULT_STORAGE_LIMIT

constexpr size_t dht::DEFAULT_STORAGE_LIMIT {1024 * 1024 * 64}
staticconstexpr

Definition at line 116 of file callbacks.h.

◆ MAX_VALUE_SIZE

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

Definition at line 77 of file value.h.

◆ TARGET_NODES

constexpr unsigned dht::TARGET_NODES {8}
staticconstexpr

Definition at line 26 of file routing_table.h.

◆ zeroes

const InfoHash dht::zeroes {}

Definition at line 361 of file infohash.h.