My Project 3.5.5
C++ Distributed Hash Table
Loading...
Searching...
No Matches
dht::Value Struct Reference

#include <value.h>

Collaboration diagram for dht::Value:

Classes

class  Filter
class  Serializable
class  SerializableBase

Public Types

enum class  Field : int {
  None = 0 , Id , ValueType , OwnerPk ,
  SeqNum , UserType , COUNT
}
typedef uint64_t Id

Public Member Functions

template<typename T>
unpack ()
bool isEncrypted () const
bool isSigned () const
void sign (const crypto::PrivateKey &key)
bool checkSignature () const
std::shared_ptr< crypto::PublicKeygetOwner () const
Value encrypt (const crypto::PrivateKey &from, const crypto::PublicKey &to)
 Value (Id id)
 Value (ValueType::Id t, const Blob &data, Id id=INVALID_ID)
 Value (ValueType::Id t, Blob &&data, Id id=INVALID_ID)
 Value (ValueType::Id t, const uint8_t *dat_ptr, size_t dat_len, Id id=INVALID_ID)
template<typename Type>
 Value (ValueType::Id t, const Type &d, Id id=INVALID_ID)
template<typename Type>
 Value (const ValueType &t, const Type &d, Id id=INVALID_ID)
 Value (const Blob &userdata)
 Value (Blob &&userdata)
 Value (const uint8_t *dat_ptr, size_t dat_len)
 Value (Value &&o) noexcept
template<typename Type>
 Value (const Type &vs)
 Value (const msgpack::object &o)
bool contentEquals (const Value &o) const
bool operator== (const Value &o) const
bool operator!= (const Value &o) const
void setRecipient (const InfoHash &r)
void setCypher (Blob &&c)
Blob getToSign () const
Blob getToEncrypt () const
std::string toString () const
size_t size () const
template<typename Packer>
void msgpack_pack_to_sign (Packer &pk) const
template<typename Packer>
void msgpack_pack_to_encrypt (Packer &pk) const
template<typename Packer>
void msgpack_pack (Packer &pk) const
template<typename Packer>
void msgpack_pack_fields (const std::set< Value::Field > &fields, Packer &pk) const
void msgpack_unpack (const msgpack::object &o)
void msgpack_unpack_body (const msgpack::object &o)
Blob getPacked () const
void msgpack_unpack_fields (const std::set< Value::Field > &fields, const msgpack::object &o, unsigned offset)
bool isSignatureChecked () const
bool isDecrypted () const
bool checkSignature ()
Sp< Valuedecrypt (const crypto::PrivateKey &key)

Static Public Member Functions

static Filter AllFilter ()
static Filter TypeFilter (const ValueType &t)
static Filter TypeFilter (const ValueType::Id &tid)
static Filter IdFilter (const Id id)
static Filter RecipientFilter (const InfoHash &r)
static Filter OwnerFilter (const crypto::PublicKey &pk)
static Filter OwnerFilter (const InfoHash &pkh)
static Filter SeqNumFilter (uint16_t seq_no)
static Filter UserTypeFilter (std::string ut)
template<typename T, typename std::enable_if< std::is_base_of< SerializableBase, T >::value, T >::type * = nullptr>
static Value pack (const T &obj)
template<typename T, typename std::enable_if<!std::is_base_of< SerializableBase, T >::value, T >::type * = nullptr>
static Value pack (const T &obj)
template<typename T, typename std::enable_if< std::is_base_of< SerializableBase, T >::value, T >::type * = nullptr>
static T unpack (const Value &v)
template<typename T, typename std::enable_if<!std::is_base_of< SerializableBase, T >::value, T >::type * = nullptr>
static T unpack (const Value &v)

Public Attributes

Id id {INVALID_ID}
std::shared_ptr< crypto::PublicKeyowner {}
InfoHash recipient {}
ValueType::Id type {ValueType::USER_DATA.id}
Blob data {}
std::string user_type {}
uint16_t seq {0}
Blob signature {}
Blob cypher {}
unsigned priority {0}

Static Public Attributes

static const constexpr Id INVALID_ID {0}

Friends

OPENDHT_PUBLIC friend std::ostream & operator<< (std::ostream &s, const Value &v)

Detailed Description

A "value" is data potentially stored on the Dht, with some metadata.

It can be an IP:port announced for a service, a public key, or any kind of light user-defined data (recommended: less than 512 bytes).

Values are stored at a given InfoHash in the Dht, but also have a unique ID to distinguish between values stored at the same location.

Definition at line 150 of file value.h.

Member Typedef Documentation

◆ Id

typedef uint64_t dht::Value::Id

Definition at line 163 of file value.h.

Member Enumeration Documentation

◆ Field

enum class dht::Value::Field : int
strong

Definition at line 152 of file value.h.

Constructor & Destructor Documentation

◆ Value() [1/13]

dht::Value::Value ( )
inline

Definition at line 376 of file value.h.

◆ Value() [2/13]

dht::Value::Value ( Id id)
inline

Definition at line 378 of file value.h.

◆ Value() [3/13]

dht::Value::Value ( ValueType::Id t,
const Blob & data,
Id id = INVALID_ID )
inline

Generic constructor

Definition at line 381 of file value.h.

◆ Value() [4/13]

dht::Value::Value ( ValueType::Id t,
Blob && data,
Id id = INVALID_ID )
inline

Definition at line 383 of file value.h.

◆ Value() [5/13]

dht::Value::Value ( ValueType::Id t,
const uint8_t * dat_ptr,
size_t dat_len,
Id id = INVALID_ID )
inline

Definition at line 385 of file value.h.

◆ Value() [6/13]

template<typename Type>
dht::Value::Value ( ValueType::Id t,
const Type & d,
Id id = INVALID_ID )
inline

Definition at line 397 of file value.h.

◆ Value() [7/13]

template<typename Type>
dht::Value::Value ( const ValueType & t,
const Type & d,
Id id = INVALID_ID )
inline

Definition at line 401 of file value.h.

◆ Value() [8/13]

dht::Value::Value ( const Blob & userdata)
inline

Custom user data constructor

Definition at line 405 of file value.h.

◆ Value() [9/13]

dht::Value::Value ( Blob && userdata)
inline

Definition at line 406 of file value.h.

◆ Value() [10/13]

dht::Value::Value ( const uint8_t * dat_ptr,
size_t dat_len )
inline

Definition at line 407 of file value.h.

◆ Value() [11/13]

dht::Value::Value ( Value && o)
inlinenoexcept

Definition at line 409 of file value.h.

◆ Value() [12/13]

template<typename Type>
dht::Value::Value ( const Type & vs)
inline

Definition at line 416 of file value.h.

◆ Value() [13/13]

dht::Value::Value ( const msgpack::object & o)
inline

Unpack a serialized value

Definition at line 422 of file value.h.

Member Function Documentation

◆ AllFilter()

Filter dht::Value::AllFilter ( )
inlinestatic

Definition at line 230 of file value.h.

◆ checkSignature()

bool dht::Value::checkSignature ( ) const
inline

Check that the value is signed and that the signature matches. If true, the owner field will contain the signer public key.

Definition at line 363 of file value.h.

◆ contentEquals()

bool dht::Value::contentEquals ( const Value & o) const
inline

Returns true if value contents are equals (not considering the value ID)

Definition at line 429 of file value.h.

◆ encrypt()

Value dht::Value::encrypt ( const crypto::PrivateKey & from,
const crypto::PublicKey & to )

Sign the value with from and returns the encrypted version for to.

◆ getOwner()

std::shared_ptr< crypto::PublicKey > dht::Value::getOwner ( ) const
inline

Definition at line 367 of file value.h.

◆ getPacked()

Blob dht::Value::getPacked ( ) const
inline

Definition at line 574 of file value.h.

◆ getToEncrypt()

Blob dht::Value::getToEncrypt ( ) const
inline

Pack part of the data to be encrypted

Definition at line 466 of file value.h.

◆ getToSign()

Blob dht::Value::getToSign ( ) const
inline

Pack part of the data to be signed (must always be done the same way)

Definition at line 456 of file value.h.

◆ IdFilter()

Filter dht::Value::IdFilter ( const Id id)
inlinestatic

Definition at line 245 of file value.h.

◆ isDecrypted()

bool dht::Value::isDecrypted ( ) const
inline

Definition at line 633 of file value.h.

◆ isEncrypted()

bool dht::Value::isEncrypted ( ) const
inline

Definition at line 345 of file value.h.

◆ isSignatureChecked()

bool dht::Value::isSignatureChecked ( ) const
inline

Definition at line 630 of file value.h.

◆ isSigned()

bool dht::Value::isSigned ( ) const
inline

Definition at line 348 of file value.h.

◆ msgpack_pack()

template<typename Packer>
void dht::Value::msgpack_pack ( Packer & pk) const
inline

Definition at line 534 of file value.h.

◆ msgpack_pack_fields()

template<typename Packer>
void dht::Value::msgpack_pack_fields ( const std::set< Value::Field > & fields,
Packer & pk ) const
inline

Definition at line 545 of file value.h.

◆ msgpack_pack_to_encrypt()

template<typename Packer>
void dht::Value::msgpack_pack_to_encrypt ( Packer & pk) const
inline

Definition at line 518 of file value.h.

◆ msgpack_pack_to_sign()

template<typename Packer>
void dht::Value::msgpack_pack_to_sign ( Packer & pk) const
inline

Definition at line 498 of file value.h.

◆ operator!=()

bool dht::Value::operator!= ( const Value & o) const
inline

Definition at line 441 of file value.h.

◆ operator==()

bool dht::Value::operator== ( const Value & o) const
inline

Definition at line 438 of file value.h.

◆ OwnerFilter() [1/2]

Filter dht::Value::OwnerFilter ( const crypto::PublicKey & pk)
inlinestatic

Definition at line 257 of file value.h.

◆ OwnerFilter() [2/2]

Filter dht::Value::OwnerFilter ( const InfoHash & pkh)
inlinestatic

Definition at line 261 of file value.h.

◆ pack() [1/2]

template<typename T, typename std::enable_if< std::is_base_of< SerializableBase, T >::value, T >::type * = nullptr>
Value dht::Value::pack ( const T & obj)
inlinestatic

Definition at line 311 of file value.h.

◆ pack() [2/2]

template<typename T, typename std::enable_if<!std::is_base_of< SerializableBase, T >::value, T >::type * = nullptr>
Value dht::Value::pack ( const T & obj)
inlinestatic

Definition at line 318 of file value.h.

◆ RecipientFilter()

Filter dht::Value::RecipientFilter ( const InfoHash & r)
inlinestatic

Definition at line 251 of file value.h.

◆ SeqNumFilter()

Filter dht::Value::SeqNumFilter ( uint16_t seq_no)
inlinestatic

Definition at line 267 of file value.h.

◆ setCypher()

void dht::Value::setCypher ( Blob && c)
inline

Definition at line 449 of file value.h.

◆ setRecipient()

void dht::Value::setRecipient ( const InfoHash & r)
inline

Definition at line 445 of file value.h.

◆ sign()

void dht::Value::sign ( const crypto::PrivateKey & key)

Sign the value using the provided private key. Afterward, checkSignature() will return true and owner will be set to the corresponding public key.

◆ size()

size_t dht::Value::size ( ) const

Return the size in bytes used by this value in memory (minimum).

◆ toString()

std::string dht::Value::toString ( ) const
inline

Definition at line 476 of file value.h.

◆ TypeFilter() [1/2]

Filter dht::Value::TypeFilter ( const ValueType & t)
inlinestatic

Definition at line 234 of file value.h.

◆ TypeFilter() [2/2]

Filter dht::Value::TypeFilter ( const ValueType::Id & tid)
inlinestatic

Definition at line 239 of file value.h.

◆ unpack() [1/3]

template<typename T>
T dht::Value::unpack ( )
inline

Definition at line 340 of file value.h.

◆ unpack() [2/3]

template<typename T, typename std::enable_if< std::is_base_of< SerializableBase, T >::value, T >::type * = nullptr>
T dht::Value::unpack ( const Value & v)
inlinestatic

Definition at line 325 of file value.h.

◆ unpack() [3/3]

template<typename T, typename std::enable_if<!std::is_base_of< SerializableBase, T >::value, T >::type * = nullptr>
T dht::Value::unpack ( const Value & v)
inlinestatic

Definition at line 334 of file value.h.

◆ UserTypeFilter()

Filter dht::Value::UserTypeFilter ( std::string ut)
inlinestatic

Definition at line 273 of file value.h.

◆ operator<<

OPENDHT_PUBLIC friend std::ostream & operator<< ( std::ostream & s,
const Value & v )
friend

print value for debugging

Member Data Documentation

◆ cypher

Blob dht::Value::cypher {}

Hold encrypted version of the data.

Definition at line 621 of file value.h.

◆ data

Blob dht::Value::data {}

Definition at line 601 of file value.h.

◆ id

Id dht::Value::id {INVALID_ID}

Definition at line 583 of file value.h.

◆ INVALID_ID

const constexpr Id dht::Value::INVALID_ID {0}
staticconstexpr

Definition at line 164 of file value.h.

◆ owner

std::shared_ptr<crypto::PublicKey> dht::Value::owner {}

Public key of the signer.

Definition at line 588 of file value.h.

◆ priority

unsigned dht::Value::priority {0}

Priority of this value (used for push notifications) 0 = high priority 1 = normal priority

Definition at line 628 of file value.h.

◆ recipient

InfoHash dht::Value::recipient {}

Hash of the recipient (optional). Should only be present for encrypted values. Can optionally be present for signed values.

Definition at line 595 of file value.h.

◆ seq

uint16_t dht::Value::seq {0}

Sequence number to avoid replay attacks

Definition at line 611 of file value.h.

◆ signature

Blob dht::Value::signature {}

Optional signature.

Definition at line 616 of file value.h.

◆ type

ValueType::Id dht::Value::type {ValueType::USER_DATA.id}

Type of data.

Definition at line 600 of file value.h.

◆ user_type

std::string dht::Value::user_type {}

Custom user-defined type

Definition at line 606 of file value.h.


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