My Project 3.2.0
C++ Distributed Hash Table
|
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 |
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:
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 126 of file network_engine.h.
using dht::net::NetworkEngine::RequestCb = std::function<void(const Request&, RequestAnswer&&)> |
Definition at line 214 of file network_engine.h.
using dht::net::NetworkEngine::RequestErrorCb = std::function<bool(const Request&, DhtProtocolException&&)> |
Definition at line 215 of file network_engine.h.
using dht::net::NetworkEngine::RequestExpiredCb = std::function<void(const Request&, bool)> |
Definition at line 216 of file network_engine.h.
|
inline |
Definition at line 460 of file network_engine.h.
|
inline |
Definition at line 464 of file network_engine.h.
|
inline |
Definition at line 467 of file network_engine.h.
|
inline |
Definition at line 451 of file network_engine.h.
|
inline |
Definition at line 475 of file network_engine.h.
|
inline |
Definition at line 471 of file network_engine.h.
|
inline |
Definition at line 237 of file network_engine.h.
|
inline |
Definition at line 445 of file network_engine.h.
void dht::net::NetworkEngine::processMessage | ( | const uint8_t * | buf, |
size_t | buflen, | ||
SockAddr | addr ) |
Parses a message and calls appropriate callbacks.
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. |
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.
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. |
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.
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. |
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.
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. |
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.
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 purpose, sendListen has to handle creation of the socket. Therefor, you cannot use openSocket yourself. TODO: Once we don't support the old "listen" negociation, 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. |
Sp< Request > dht::net::NetworkEngine::sendPing | ( | const Sp< Node > & | n, |
RequestCb && | on_done, | ||
RequestExpiredCb && | on_expired ) |
Send a "ping" request to a given node.
n | The node. |
on_done | Request callback when the request is completed. |
on_expired | Request callback when the request expires. |
|
inline |
Send a "ping" request to a given node.
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. |
Definition at line 295 of file network_engine.h.
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.
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. |
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
n | The node. |
hash | The target hash. |
values | The values. |
created | Time id. |
token | A security token. |
sid | The socket id. |
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.
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 |
|
inline |
Definition at line 264 of file network_engine.h.