Back to Site
Loading...
Searching...
No Matches
librats::DhtDiscovery Class Referencefinal

#include <dht_discovery.h>

Inheritance diagram for librats::DhtDiscovery:
[legend]
Collaboration diagram for librats::DhtDiscovery:
[legend]

Classes

struct  Config
class  Redials
 Which addresses found to dial, and how: a policy of times alone. More...
struct  Key

Public Types

enum class  Use : uint8_t { Announce = 1 , Search = 2 , Both = 3 }
 What is done with a key: announced, so that the node is found under it; searched, so that it finds who is (and dials them); or both. More...

Public Member Functions

 DhtDiscovery (Config config)
 ~DhtDiscovery () override
void attach (NodeContext &ctx) override
void start () override
void stop () override
bool is_running () const
DhtClient * dht_client () override
 DhtService: hand out the live Kademlia node so siblings (e.g.
uint16_t dht_port () const
 IPv4 DHT UDP port (0 if not running).
uint16_t dht_port_v6 () const
 IPv6 DHT UDP port (0 if not running).
InfoHash discovery_hash () const
 The first key's hash (the only one, unless keys were given).
std::vector< InfoHash > discovery_hashes () const
void set_keys (const std::vector< Key > &keys)
 The keys announced and searched from now on, in place of those before (a key twice: what both say): one new is announced or searched at once, one gone no longer.
void set_keys (const std::vector< std::string > &keys)
std::string external_address () const
 Our external (public) IP currently used to derive the DHT node id, learned via STUN at startup or in-DHT "ip" voting.
bool is_own (const Address &address) const
 Whether address is this node's own, as a key it announces and searches hands it back: an IP of this host's (its interfaces, loopback) at the listen port, or where STUN sees it or the router's that forwards a port to it at a port the outside sees (the one announced, the router's, or STUN's — not the listen port: another device behind the same NAT may hold that one there).
Public Member Functions inherited from librats::Subsystem
virtual ~Subsystem ()=default
Public Member Functions inherited from librats::DhtService
virtual ~DhtService ()=default

Static Public Member Functions

static InfoHash hash_for_key (const std::string &key)
 Map an application key to a stable 20-byte discovery hash (SHA-1).

Detailed Description

Definition at line 80 of file dht_discovery.h.

Member Enumeration Documentation

◆ Use

enum class librats::DhtDiscovery::Use : uint8_t
strong

What is done with a key: announced, so that the node is found under it; searched, so that it finds who is (and dials them); or both.

A node that only announces a key never dials who it meets there, so one that finds it there gets through only if it can be dialed (a public address, a port the router forwards: PortMapped) — or meets it some other way. Behind NATs both must dial at once: Both, at both ends.

Enumerator
Announce 
Search 
Both 

Definition at line 199 of file dht_discovery.h.

Constructor & Destructor Documentation

◆ DhtDiscovery()

librats::DhtDiscovery::DhtDiscovery ( Config config)
explicit

◆ ~DhtDiscovery()

librats::DhtDiscovery::~DhtDiscovery ( )
override

Member Function Documentation

◆ attach()

void librats::DhtDiscovery::attach ( NodeContext & ctx)
overridevirtual

Implements librats::Subsystem.

◆ dht_client()

DhtClient * librats::DhtDiscovery::dht_client ( )
inlineoverridevirtual

DhtService: hand out the live Kademlia node so siblings (e.g.

Bittorrent) can share this swarm. IPv4 preferred, IPv6 fallback; nullptr before start() / after stop(). Borrow it during start() and drop it in stop() (see DhtService).

Implements librats::DhtService.

Definition at line 185 of file dht_discovery.h.

◆ dht_port()

uint16_t librats::DhtDiscovery::dht_port ( ) const

IPv4 DHT UDP port (0 if not running).

◆ dht_port_v6()

uint16_t librats::DhtDiscovery::dht_port_v6 ( ) const

IPv6 DHT UDP port (0 if not running).

◆ discovery_hash()

InfoHash librats::DhtDiscovery::discovery_hash ( ) const

The first key's hash (the only one, unless keys were given).

◆ discovery_hashes()

std::vector< InfoHash > librats::DhtDiscovery::discovery_hashes ( ) const

◆ external_address()

std::string librats::DhtDiscovery::external_address ( ) const

Our external (public) IP currently used to derive the DHT node id, learned via STUN at startup or in-DHT "ip" voting.

"" if not yet known / random.

◆ hash_for_key()

InfoHash librats::DhtDiscovery::hash_for_key ( const std::string & key)
static

Map an application key to a stable 20-byte discovery hash (SHA-1).

◆ is_own()

bool librats::DhtDiscovery::is_own ( const Address & address) const

Whether address is this node's own, as a key it announces and searches hands it back: an IP of this host's (its interfaces, loopback) at the listen port, or where STUN sees it or the router's that forwards a port to it at a port the outside sees (the one announced, the router's, or STUN's — not the listen port: another device behind the same NAT may hold that one there).

Such an address is never dialed (it would be handshaken with, and punched for two minutes). Another node on this host listens at another port.

◆ is_running()

bool librats::DhtDiscovery::is_running ( ) const

◆ set_keys() [1/2]

void librats::DhtDiscovery::set_keys ( const std::vector< Key > & keys)

The keys announced and searched from now on, in place of those before (a key twice: what both say): one new is announced or searched at once, one gone no longer.

None: the node finds and is found by none until some are set. Any thread; before start() too.

◆ set_keys() [2/2]

void librats::DhtDiscovery::set_keys ( const std::vector< std::string > & keys)

◆ start()

void librats::DhtDiscovery::start ( )
overridevirtual

Implements librats::Subsystem.

◆ stop()

void librats::DhtDiscovery::stop ( )
overridevirtual

Implements librats::Subsystem.


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