Version: 0.0.1

home

[report issue]

dht_state

Declared in "libtorrent/kademlia/dht_state.hpp"

This structure helps to store and load the state of the dht_tracker. At this moment the library is only a dual stack implementation of the DHT. See BEP 32

struct dht_state
{
   void clear ();

   node_ids_t nids;
   std::vector<udp::endpoint> nodes;
   std::vector<udp::endpoint> nodes6;
};
[report issue]
nodes
the bootstrap nodes saved from the buckets node
[report issue]
nodes6
the bootstrap nodes saved from the IPv6 buckets node
[report issue]

dht_storage_counters

Declared in "libtorrent/kademlia/dht_storage.hpp"

This structure hold the relevant counters for the storage

struct dht_storage_counters
{
   void reset ();

   std::int32_t torrents  = 0;
   std::int32_t peers  = 0;
   std::int32_t immutable_data  = 0;
   std::int32_t mutable_data  = 0;
};
[report issue]

reset()

void reset ();

This member function set the counters to zero.

[report issue]

dht_storage_interface

Declared in "libtorrent/kademlia/dht_storage.hpp"

The DHT storage interface is a pure virtual class that can be implemented to customize how the data for the DHT is stored.

The default storage implementation uses three maps in RAM to save the peers, mutable and immutable items and it's designed to provide a fast and fully compliant behavior of the BEPs.

libtorrent comes with one built-in storage implementation: dht_default_storage (private non-accessible class). Its constructor function is called dht_default_storage_constructor(). You should know that if this storage becomes full of DHT items, the current implementation could degrade in performance.

struct dht_storage_interface
{
   virtual void update_node_ids (std::vector<node_id> const& ids) = 0;
   virtual bool get_immutable_item (sha256_hash const& target
      , entry& item) const = 0;
   virtual void put_immutable_item (sha256_hash const& target
      , span<char const> buf
      , address const& addr) = 0;
   virtual bool get_mutable_item_seq (sha256_hash const& target
      , sequence_number& seq) const = 0;
   virtual bool get_mutable_item (sha256_hash const& target
      , sequence_number seq, bool force_fill
      , entry& item) const = 0;
   virtual void put_mutable_item (sha256_hash const& target
      , span<char const> buf
      , signature const& sig
      , sequence_number seq
      , public_key const& pk
      , span<char const> salt
      , address const& addr) = 0;
   virtual void tick () = 0;
   virtual dht_storage_counters counters () const = 0;
};
[report issue]

update_node_ids()

virtual void update_node_ids (std::vector<node_id> const& ids) = 0;

This member function notifies the list of all node's ids of each DHT running inside libtorrent. It's advisable that the concrete implementation keeps a copy of this list for an eventual prioritization when deleting an element to make room for a new one.

[report issue]

get_immutable_item()

virtual bool get_immutable_item (sha256_hash const& target
      , entry& item) const = 0;

This function retrieves the immutable item given its target hash.

For future implementers: The value should be returned as an entry in the key item["v"].

returns true if the item is found and the data is returned inside the (entry) out parameter item.

[report issue]

put_immutable_item()

virtual void put_immutable_item (sha256_hash const& target
      , span<char const> buf
      , address const& addr) = 0;

Store the item's data. This layer is only for storage. The authentication of the item is performed by the upper layer.

For implementers: This data can be stored only if the target is not already present. The implementation should consider the value of settings_pack::dht_max_dht_items.

[report issue]

get_mutable_item_seq()

virtual bool get_mutable_item_seq (sha256_hash const& target
      , sequence_number& seq) const = 0;

This function retrieves the sequence number of a mutable item.

returns true if the item is found and the data is returned inside the out parameter seq.

[report issue]

get_mutable_item()

virtual bool get_mutable_item (sha256_hash const& target
      , sequence_number seq, bool force_fill
      , entry& item) const = 0;

This function retrieves the mutable stored in the DHT.

For implementers: The item sequence should be stored in the key item["seq"]. if force_fill is true or (0 <= seq and seq < item["seq"]) the following keys should be filled item["v"] - with the value no encoded. item["sig"] - with a string representation of the signature. item["k"] - with a string representation of the public key.

returns true if the item is found and the data is returned inside the (entry) out parameter item.

[report issue]

put_mutable_item()

virtual void put_mutable_item (sha256_hash const& target
      , span<char const> buf
      , signature const& sig
      , sequence_number seq
      , public_key const& pk
      , span<char const> salt
      , address const& addr) = 0;

Store the item's data. This layer is only for storage. The authentication of the item is performed by the upper layer.

For implementers: The sequence number should be checked if the item is already present. The implementation should consider the value of settings_pack::dht_max_dht_items.

[report issue]

tick()

virtual void tick () = 0;

This function is called periodically (non-constant frequency).

For implementers: Use this functions for expire peers or items or any other storage cleanup.

[report issue]

counters()

virtual dht_storage_counters counters () const = 0;

return stats counters for the store

[report issue]

node_entry

Declared in "libtorrent/kademlia/node_entry.hpp"

struct node_entry
{
   void update_rtt (int new_rtt);
   node_entry (node_id const& id_, udp::endpoint const& ep, int roundtriptime = 0xffff
      , bool pinged = false);
   node_entry () = default;
   explicit node_entry (udp::endpoint const& ep);
   address addr () const;
   void timed_out ();
   bool confirmed () const;
   udp::endpoint ep () const;
   void set_pinged ();
   int port () const;
   int fail_count () const;
   bool pinged () const;
   void reset_fail_count ();
   bool operator< (node_entry const& rhs) const;
   time_point last_queried = min_time ();

   time_point first_seen  = aux::time_now();
   node_id id {nullptr};
   aux::union_endpoint endpoint;
   std::uint16_t rtt  = 0xffff;
   std::uint8_t timeout_count  = 0xff;
   bool verified  = false;
};
[report issue]

operator<()

bool operator< (node_entry const& rhs) const;

compares which node_entry is "better". Smaller is better

[report issue]

min_time()

time_point last_queried = min_time ();

the time we last received a response for a request to this peer

[report issue]
rtt
the average RTT of this node
[report issue]
timeout_count
the number of times this node has failed to respond in a row 0xff is a special value to indicate we have not pinged this node yet
[report issue]

dht_default_storage_constructor()

Declared in "libtorrent/kademlia/dht_storage.hpp"

std::unique_ptr<dht_storage_interface> dht_default_storage_constructor (
   settings_interface const& settings);

constructor for the default DHT storage. The DHT storage is responsible for maintaining peers and mutable and immutable items announced and stored/put to the DHT node.

[report issue]

sign_mutable_item()

Declared in "libtorrent/kademlia/item.hpp"

signature sign_mutable_item (
   span<char const> v
   , span<char const> salt
   , sequence_number seq
   , public_key const& pk
   , secret_key const& sk);

given a byte range v and an optional byte range salt, a sequence number, public key pk (must be 32 bytes) and a secret key sk (must be 64 bytes), this function produces a signature which is written into a 64 byte buffer pointed to by sig. The caller is responsible for allocating the destination buffer that's passed in as the sig argument. Typically it would be allocated on the stack.

[report issue]

announce_flags_t

Declared in "libtorrent/kademlia/announce_flags.hpp"

seed
announce to DHT as a seed
implied_port
announce to DHT with the implied-port flag set. This tells the network to use your source UDP port as your listen port, rather than the one specified in the message. This may improve the chances of traversing NATs when using uTP.
ssl_torrent
Specify the port number for the SSL listen socket in the DHT announce.