dht::Value Struct Reference

`#include <value.h>`

Collaboration diagram for dht::Value:
[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 >
T | unpack ()
bool | isEncrypted () const
bool | isSigned () const
void | sign (const crypto::PrivateKey &key)
bool | checkSignature () const
std::shared_ptr< const crypto::PublicKey > | getOwner () 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::PublicKey > | owner {}
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

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

## Member Typedef Documentation

## Id

typedef uint64_t dht::Value::Id

Definition at line 147 of file value.h.

## Member Enumeration Documentation

## Field

enum class dht::Value::Field : int

strong

Definition at line 136 of file value.h.

## Constructor & Destructor Documentation

## Value() [1/13]

dht::Value::Value | ( |  | ) |

inline

Definition at line 363 of file value.h.

## Value() [2/13]

dht::Value::Value | ( | Id | id | ) |

inline

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

## Value() [4/13]

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

inline

Definition at line 370 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 372 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 384 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 388 of file value.h.

## Value() [8/13]

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

inline

Custom user data constructor

Definition at line 392 of file value.h.

## Value() [9/13]

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

inline

Definition at line 393 of file value.h.

## Value() [10/13]

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

inline

Definition at line 394 of file value.h.

## Value() [11/13]

dht::Value::Value | ( | Value && | o | ) |

inline noexcept

Definition at line 396 of file value.h.

## Value() [12/13]

template<typename Type >

dht::Value::Value | ( | const Type & | vs | ) |

inline

Definition at line 401 of file value.h.

## Value() [13/13]

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

inline

Unpack a serialized value

Definition at line 407 of file value.h.

## Member Function Documentation

## AllFilter()

static const Filter dht::Value::AllFilter | ( |  | ) |

inline static

Definition at line 203 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 342 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 353 of file value.h.

## getOwner()

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

inline

Definition at line 346 of file value.h.

## getPacked()

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

inline

Definition at line 543 of file value.h.

## getToEncrypt()

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

inline

Pack part of the data to be encrypted

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

## IdFilter()

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

inline static

Definition at line 219 of file value.h.

## isEncrypted()

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

inline

Definition at line 319 of file value.h.

## isSigned()

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

inline

Definition at line 322 of file value.h.

## msgpack_pack()

template<typename Packer >

void dht::Value::msgpack_pack | ( | Packer & | pk | ) | const

inline

Definition at line 506 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 514 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 490 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 470 of file value.h.

## operator==()

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

inline

Definition at line 411 of file value.h.

## OwnerFilter() [1/2]

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

inline static

Definition at line 231 of file value.h.

## OwnerFilter() [2/2]

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

inline static

Definition at line 235 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 | ) |

inline static

Definition at line 285 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 | ) |

inline static

Definition at line 292 of file value.h.

## RecipientFilter()

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

inline static

Definition at line 225 of file value.h.

## SeqNumFilter()

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

inline static

Definition at line 241 of file value.h.

## setCypher()

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

inline

Definition at line 421 of file value.h.

## setRecipient()

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

inline

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

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

## TypeFilter() [1/2]

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

inline static

Definition at line 207 of file value.h.

## TypeFilter() [2/2]

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

inline static

Definition at line 213 of file value.h.

## unpack() [1/3]

template<typename T >

T dht::Value::unpack | ( |  | ) |

inline

Definition at line 314 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 | ) |

inline static

Definition at line 299 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 | ) |

inline static

Definition at line 308 of file value.h.

## UserTypeFilter()

static Filter dht::Value::UserTypeFilter | ( | const std::string & | ut | ) |

inline static

Definition at line 247 of file value.h.

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

## data

Blob dht::Value::data {}

Definition at line 570 of file value.h.

## id

Id dht::Value::id {INVALID_ID}

Definition at line 552 of file value.h.

## INVALID_ID

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

static constexpr

Definition at line 148 of file value.h.

## owner

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

Public key of the signer.

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

## seq

uint16_t dht::Value::seq {0}

Sequence number to avoid replay attacks

Definition at line 580 of file value.h.

## signature

Blob dht::Value::signature {}

Optional signature.

Definition at line 585 of file value.h.

## type

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

Type of data.

Definition at line 569 of file value.h.

## user_type

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

Custom user-defined type

Definition at line 575 of file value.h.

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

- /tmp/slackbuilds_libs/opendht-1.7.4/include/opendht/value.h