My Project 3.2.0
C++ Distributed Hash Table
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Friends | List of all members
dht::Value Struct Reference

#include <value.h>

Collaboration diagram for dht::Value:
Collaboration graph
[legend]

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 151 of file value.h.

Member Typedef Documentation

◆ Id

typedef uint64_t dht::Value::Id

Definition at line 164 of file value.h.

Member Enumeration Documentation

◆ Field

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

Definition at line 153 of file value.h.

Constructor & Destructor Documentation

◆ Value() [1/13]

dht::Value::Value ( )
inline

Definition at line 377 of file value.h.

◆ Value() [2/13]

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

Definition at line 379 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 382 of file value.h.

◆ Value() [4/13]

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

Definition at line 384 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 386 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 398 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 402 of file value.h.

◆ Value() [8/13]

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

Custom user data constructor

Definition at line 406 of file value.h.

◆ Value() [9/13]

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

Definition at line 407 of file value.h.

◆ Value() [10/13]

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

Definition at line 408 of file value.h.

◆ Value() [11/13]

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

Definition at line 410 of file value.h.

◆ Value() [12/13]

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

Definition at line 417 of file value.h.

◆ Value() [13/13]

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

Unpack a serialized value

Definition at line 423 of file value.h.

Member Function Documentation

◆ AllFilter()

static Filter dht::Value::AllFilter ( )
inlinestatic

Definition at line 231 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 364 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 430 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 368 of file value.h.

◆ getPacked()

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

Definition at line 575 of file value.h.

◆ getToEncrypt()

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

Pack part of the data to be encrypted

Definition at line 467 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 457 of file value.h.

◆ IdFilter()

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

Definition at line 246 of file value.h.

◆ isDecrypted()

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

Definition at line 634 of file value.h.

◆ isEncrypted()

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

Definition at line 346 of file value.h.

◆ isSignatureChecked()

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

Definition at line 631 of file value.h.

◆ isSigned()

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

Definition at line 349 of file value.h.

◆ msgpack_pack()

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

Definition at line 535 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 546 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 519 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 499 of file value.h.

◆ operator!=()

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

Definition at line 442 of file value.h.

◆ operator==()

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

Definition at line 439 of file value.h.

◆ OwnerFilter() [1/2]

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

Definition at line 258 of file value.h.

◆ OwnerFilter() [2/2]

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

Definition at line 262 of file value.h.

◆ pack() [1/2]

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

Definition at line 312 of file value.h.

◆ pack() [2/2]

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

Definition at line 319 of file value.h.

◆ RecipientFilter()

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

Definition at line 252 of file value.h.

◆ SeqNumFilter()

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

Definition at line 268 of file value.h.

◆ setCypher()

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

Definition at line 450 of file value.h.

◆ setRecipient()

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

Definition at line 446 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 477 of file value.h.

◆ TypeFilter() [1/2]

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

Definition at line 235 of file value.h.

◆ TypeFilter() [2/2]

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

Definition at line 240 of file value.h.

◆ unpack() [1/3]

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

Definition at line 341 of file value.h.

◆ unpack() [2/3]

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

Definition at line 326 of file value.h.

◆ unpack() [3/3]

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

Definition at line 335 of file value.h.

◆ UserTypeFilter()

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

Definition at line 274 of file value.h.

Friends And Related Symbol Documentation

◆ 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 622 of file value.h.

◆ data

Blob dht::Value::data {}

Definition at line 602 of file value.h.

◆ id

Id dht::Value::id {INVALID_ID}

Definition at line 584 of file value.h.

◆ INVALID_ID

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

Definition at line 165 of file value.h.

◆ owner

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

Public key of the signer.

Definition at line 589 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 629 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 596 of file value.h.

◆ seq

uint16_t dht::Value::seq {0}

Sequence number to avoid replay attacks

Definition at line 612 of file value.h.

◆ signature

Blob dht::Value::signature {}

Optional signature.

Definition at line 617 of file value.h.

◆ type

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

Type of data.

Definition at line 601 of file value.h.

◆ user_type

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

Custom user-defined type

Definition at line 607 of file value.h.


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