My Project: dht::net::NetworkEngine Class Reference

My Project 3.7.7 C++ Distributed Hash Table

Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
dht::net::NetworkEngine Class Referencefinal

An abstraction of communication protocol on the network. More...

`#include <network_engine.h>`

## Public Types
using | RequestCb = std::function<void(const Request&, RequestAnswer&&)>
using | RequestErrorCb = std::function<bool(const Request&, DhtProtocolException&&)>
using | RequestExpiredCb = std::function<void(const Request&, bool)>

## Public Member Functions
| NetworkEngine (InfoHash &myid, NetworkConfig config, std::unique_ptr< DatagramSocket > &&sock, const Sp< Logger > &log, std::mt19937_64 &rd, Scheduler &scheduler, decltype(NetworkEngine::onError)&&onError, decltype(NetworkEngine::onNewNode)&&onNewNode, decltype(NetworkEngine::onReportedAddr)&&onReportedAddr, decltype(NetworkEngine::onPing)&&onPing, decltype(NetworkEngine::onFindNode)&&onFindNode, decltype(NetworkEngine::onGetValues)&&onGetValues, decltype(NetworkEngine::onListen)&&onListen, decltype(NetworkEngine::onAnnounce)&&onAnnounce, decltype(NetworkEngine::onRefresh)&&onRefresh)
net::DatagramSocket * | getSocket () const
void | clear ()
void | tellListener (const Sp< Node > &n, Tid socket_id, const InfoHash &hash, want_t want, const Blob &ntoken, std::vector< Sp< Node > > &&nodes, std::vector< Sp< Node > > &&nodes6, std::vector< Sp< Value > > &&values, const Query &q, int version)
void | tellListenerRefreshed (const Sp< Node > &n, Tid socket_id, const InfoHash &hash, const Blob &ntoken, const std::vector< Value::Id > &values, int version)
void | tellListenerExpired (const Sp< Node > &n, Tid socket_id, const InfoHash &hash, const Blob &ntoken, const std::vector< Value::Id > &values, int version)
bool | isRunning (sa_family_t af) const
want_t | want () const
void | connectivityChanged (sa_family_t)
Sp< Request > | sendPing (const Sp< Node > &n, RequestCb &&on_done, RequestExpiredCb &&on_expired)
Sp< Request > | sendPing (SockAddr &&sa, RequestCb &&on_done, RequestExpiredCb &&on_expired)
Sp< Request > | sendFindNode (const Sp< Node > &n, const InfoHash &hash, want_t want=-1, RequestCb &&on_done={}, RequestExpiredCb &&on_expired={})
Sp< Request > | sendGetValues (const Sp< Node > &n, const InfoHash &hash, const Query &query, want_t want, RequestCb &&on_done, RequestExpiredCb &&on_expired)
Sp< Request > | sendListen (const Sp< Node > &n, const InfoHash &hash, const Query &query, const Blob &token, Tid socketId, RequestCb &&on_done, RequestExpiredCb &&on_expired)
Sp< Request > | sendAnnounceValue (const Sp< Node > &n, const InfoHash &hash, const Sp< Value > &v, time_point created, const Blob &token, RequestCb &&on_done, RequestExpiredCb &&on_expired)
Sp< Request > | sendRefreshValue (const Sp< Node > &n, const InfoHash &hash, const Value::Id &vid, const Blob &token, RequestCb &&on_done, RequestErrorCb &&on_error, RequestExpiredCb &&on_expired)
void | sendUpdateValues (const Sp< Node > &n, const InfoHash &infohash, std::vector< Sp< Value > > &&values, time_point created, const Blob &token, size_t sid)
Sp< Request > | sendUpdateValues (const Sp< Node > &n, const InfoHash &infohash, std::vector< Sp< Value > >::iterator begin, std::vector< Sp< Value > >::iterator end, time_point created, const Blob &token, size_t sid)
void | processMessage (const uint8_t *buf, size_t buflen, SockAddr addr)
Sp< Node > | insertNode (const InfoHash &id, const SockAddr &addr)
std::vector< unsigned > | getNodeMessageStats (bool in)
void | blacklistNode (const Sp< Node > &n)
std::vector< Sp< Node > > | getCachedNodes (const InfoHash &id, sa_family_t sa_f, size_t count)
size_t | getNodeCacheSize () const
size_t | getNodeCacheSize (sa_family_t af) const
size_t | getRateLimiterSize () const
size_t | getPartialCount () const

## Detailed Description

An abstraction of communication protocol on the network.

The NetworkEngine processes all requests to nodes by offering a public interface for handling sending and receiving packets. The following parameters specify callbacks for DHT work:

Parameters

  onError | callback for handling error messages.
  onNewNode | callback for handling new nodes.
  onReportedAddr | callback for reporting an our address as seen from the other peer.
  onPing | callback for ping request.
  onFindNode | callback for "find node" request.
  onGetValues | callback for "get values" request.
  onListen | callback for "listen" request.
  onAnnounce | callback for "announce" request.
  onRefresh | callback for "refresh" request.

Definition at line 116 of file network_engine.h.

## Member Typedef Documentation

## ◆ RequestCb

using dht::net::NetworkEngine::RequestCb = std::function<void(const Request&, RequestAnswer&&)>

Definition at line 193 of file network_engine.h.

## ◆ RequestErrorCb

using dht::net::NetworkEngine::RequestErrorCb = std::function<bool(const Request&, DhtProtocolException&&)>

Definition at line 194 of file network_engine.h.

## ◆ RequestExpiredCb

using dht::net::NetworkEngine::RequestExpiredCb = std::function<void(const Request&, bool)>

Definition at line 195 of file network_engine.h.

## Member Function Documentation

## ◆ getCachedNodes()

std::vector< Sp< Node > > dht::net::NetworkEngine::getCachedNodes | ( | const InfoHash & | id,
|  | sa_family_t | sa_f,
|  | size_t | count )
| inline

Definition at line 456 of file network_engine.h.

## ◆ getNodeCacheSize() [1/2]

size_t dht::net::NetworkEngine::getNodeCacheSize | ( |  | ) | const
| inline

Definition at line 461 of file network_engine.h.

## ◆ getNodeCacheSize() [2/2]

size_t dht::net::NetworkEngine::getNodeCacheSize | ( | sa_family_t | af | ) | const
| inline

Definition at line 462 of file network_engine.h.

## ◆ getNodeMessageStats()

std::vector< unsigned > dht::net::NetworkEngine::getNodeMessageStats | ( | bool | in | ) |
| inline

Definition at line 446 of file network_engine.h.

## ◆ getPartialCount()

size_t dht::net::NetworkEngine::getPartialCount | ( |  | ) | const
| inline

Definition at line 466 of file network_engine.h.

## ◆ getRateLimiterSize()

size_t dht::net::NetworkEngine::getRateLimiterSize | ( |  | ) | const
| inline

Definition at line 464 of file network_engine.h.

## ◆ getSocket()

net::DatagramSocket * dht::net::NetworkEngine::getSocket | ( |  | ) | const
| inline

Definition at line 215 of file network_engine.h.

## ◆ insertNode()

Sp< Node > dht::net::NetworkEngine::insertNode | ( | const InfoHash & | id,
|  | const SockAddr & | addr )
| inline

Definition at line 439 of file network_engine.h.

## ◆ processMessage()

void dht::net::NetworkEngine::processMessage | ( | const uint8_t * | buf,
|  | size_t | buflen,
|  | SockAddr | addr )

Parses a message and calls appropriate callbacks.

Parameters

  buf | The buffer containing the binary message.
  buflen | The length of the buffer.
  from | The address info of the sender.
  fromlen | The length of the corresponding sockaddr structure.
  now | The time to adjust the clock in the network engine.

## ◆ sendAnnounceValue()

Sp< Request > dht::net::NetworkEngine::sendAnnounceValue | ( | const Sp< Node > & | n,
|  | const InfoHash & | hash,
|  | const Sp< Value > & | v,
|  | time_point | created,
|  | const Blob & | token,
|  | RequestCb && | on_done,
|  | RequestExpiredCb && | on_expired )

Send a "announce" request to a given node.

Parameters

  n | The node.
  hash | The target hash.
  created | The time when the value was created (avoiding extended value lifetime)
  token | A security token.
  on_done | Request callback when the request is completed.
  on_expired | Request callback when the request expires.

Returns
  the request with information concerning its success.

## ◆ sendFindNode()

Sp< Request > dht::net::NetworkEngine::sendFindNode | ( | const Sp< Node > & | n,
|  | const InfoHash & | hash,
|  | want_t | want = -1,
|  | RequestCb && | on_done = {},
|  | RequestExpiredCb && | on_expired = {} )

Send a "find node" request to a given node.

Parameters

  n | The node.
  target | The target hash.
  want | Indicating wether IPv4 or IPv6 are wanted in response. Use NetworkEngine::want()
  on_done | Request callback when the request is completed.
  on_expired | Request callback when the request expires.

Returns
  the request with information concerning its success.

## ◆ sendGetValues()

Sp< Request > dht::net::NetworkEngine::sendGetValues | ( | const Sp< Node > & | n,
|  | const InfoHash & | hash,
|  | const Query & | query,
|  | want_t | want,
|  | RequestCb && | on_done,
|  | RequestExpiredCb && | on_expired )

Send a "get" request to a given node.

Parameters

  n | The node.
  hash | The target hash.
  query | The query describing filters.
  token | A security token.
  want | Indicating wether IPv4 or IPv6 are wanted in response. Use NetworkEngine::want()
  on_done | Request callback when the request is completed.
  on_expired | Request callback when the request expires.

Returns
  the request with information concerning its success.

## ◆ sendListen()

Sp< Request > dht::net::NetworkEngine::sendListen | ( | const Sp< Node > & | n,
|  | const InfoHash & | hash,
|  | const Query & | query,
|  | const Blob & | token,
|  | Tid | socketId,
|  | RequestCb && | on_done,
|  | RequestExpiredCb && | on_expired )

Send a "listen" request to a given node.

Parameters

  n | The node.
  hash | The storage's hash.
  query | The query describing filters.
  token | A security token.
  previous | The previous request "listen" sent to this node.
  socket | UNUSED The socket for further response.
                     For backward compatibility purposes, sendListen has to
                     handle creation of the socket. Therefore, you are unable to
                     use openSocket yourself.
                     TODO: Once we don't support the old "listen" negotiation,
                     sendListen shall not create the socket itself.
  on_done | Request callback when the request is completed.
  on_expired | Request callback when the request expires.
  socket_cb | Callback to execute each time new updates arrive on the socket.

Returns
  the request with information concerning its success.

## ◆ sendPing() [1/2]

Sp< Request > dht::net::NetworkEngine::sendPing | ( | const Sp< Node > & | n,
|  | RequestCb && | on_done,
|  | RequestExpiredCb && | on_expired )

Send a "ping" request to a given node.

Parameters

  n | The node.
  on_done | Request callback when the request is completed.
  on_expired | Request callback when the request expires.

Returns
  the request with information concerning its success.

## ◆ sendPing() [2/2]

Sp< Request > dht::net::NetworkEngine::sendPing | ( | SockAddr && | sa,
|  | RequestCb && | on_done,
|  | RequestExpiredCb && | on_expired )
| inline

Send a "ping" request to a given node.

Parameters

  sa | The node's ip sockaddr info.
  salen | The associated sockaddr struct length.
  on_done | Request callback when the request is completed.
  on_expired | Request callback when the request expires.

Returns
  the request with information concerning its success.

Definition at line 288 of file network_engine.h.

## ◆ sendRefreshValue()

Sp< Request > dht::net::NetworkEngine::sendRefreshValue | ( | const Sp< Node > & | n,
|  | const InfoHash & | hash,
|  | const Value::Id & | vid,
|  | const Blob & | token,
|  | RequestCb && | on_done,
|  | RequestErrorCb && | on_error,
|  | RequestExpiredCb && | on_expired )

Send a "refresh" request to a given node. Asks a node to keep the associated value Value.type.expiration more minutes in its storage.

Parameters

  n | The node.
  hash | The target hash.
  vid | The value id.
  token | A security token.
  on_done | Request callback when the request is completed.
  on_expired | Request callback when the request expires.

Returns
  the request with information concerning its success.

## ◆ sendUpdateValues()

void dht::net::NetworkEngine::sendUpdateValues | ( | const Sp< Node > & | n,
|  | const InfoHash & | infohash,
|  | std::vector< Sp< Value > > && | values,
|  | time_point | created,
|  | const Blob & | token,
|  | size_t | sid )

Send a "update" request to a given node. Used for Listen operations

Parameters

  n | The node.
  hash | The target hash.
  values | The values.
  created | Time id.
  token | A security token.
  sid | The socket id.

Returns
  the request with information concerning its success.

## ◆ tellListener()

void dht::net::NetworkEngine::tellListener | ( | const Sp< Node > & | n,
|  | Tid | socket_id,
|  | const InfoHash & | hash,
|  | want_t | want,
|  | const Blob & | ntoken,
|  | std::vector< Sp< Node > > && | nodes,
|  | std::vector< Sp< Node > > && | nodes6,
|  | std::vector< Sp< Value > > && | values,
|  | const Query & | q,
|  | int | version )

Sends values (with closest nodes) to a listener.

Deprecated

Parameters

  sa | The address of the listener.
  sslen | The length of the sockaddr structure.
  socket_id | The tid to use to write to the request socket.
  hash | The hash key of the value.
  want | Wether to send ipv4 and/or ipv6 nodes.
  ntoken | Listen security token.
  nodes | The ipv4 closest nodes.
  nodes6 | The ipv6 closest nodes.
  values | The values to send.
  version | If version = 1, a request will be used to answer to the listener

## ◆ want()

want_t dht::net::NetworkEngine::want | ( |  | ) | const
| inline

Definition at line 259 of file network_engine.h.

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

- /home/noptrix/ba/blackarch/packages/opendht-c/src/opendht/include/opendht/network_engine.h