C++ Distributed Hash Table
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  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< const 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 operator== (const Value &o)
 
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 (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)
 

Static Public Member Functions

static const 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 (const 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< const 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 {}
 

Static Public Attributes

static const constexpr Id INVALID_ID {0}
 

Friends

class SecureDht
 
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 136 of file value.h.

Constructor & Destructor Documentation

◆ Value() [1/3]

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

Generic constructor

Definition at line 370 of file value.h.

◆ Value() [2/3]

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

Custom user data constructor

Definition at line 394 of file value.h.

◆ Value() [3/3]

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

Unpack a serialized value

Definition at line 409 of file value.h.

Member Function Documentation

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

◆ encrypt()

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

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

Definition at line 355 of file value.h.

◆ getToEncrypt()

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

Pack part of the data to be encrypted

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

◆ sign()

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

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

Definition at line 333 of file value.h.

◆ size()

size_t dht::Value::size ( ) const

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

Friends And Related Function 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 592 of file value.h.

◆ owner

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

Public key of the signer.

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

◆ seq

uint16_t dht::Value::seq {0}

Sequence number to avoid replay attacks

Definition at line 582 of file value.h.

◆ signature

Blob dht::Value::signature {}

Optional signature.

Definition at line 587 of file value.h.

◆ type

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

Type of data.

Definition at line 571 of file value.h.

◆ user_type

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

Custom user-defined type

Definition at line 577 of file value.h.


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