My Project 3.2.0
C++ Distributed Hash Table
Loading...
Searching...
No Matches
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::DatagramSocketgetSocket () 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< NodeinsertNode (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
onErrorcallback for handling error messages.
onNewNodecallback for handling new nodes.
onReportedAddrcallback for reporting an our address as seen from the other peer.
onPingcallback for ping request.
onFindNodecallback for "find node" request.
onGetValuescallback for "get values" request.
onListencallback for "listen" request.
onAnnouncecallback for "announce" request.
onRefreshcallback for "refresh" request.

Definition at line 126 of file network_engine.h.

Member Typedef Documentation

◆ RequestCb

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

Definition at line 214 of file network_engine.h.

◆ RequestErrorCb

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

Definition at line 215 of file network_engine.h.

◆ RequestExpiredCb

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

Definition at line 216 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 460 of file network_engine.h.

◆ getNodeCacheSize() [1/2]

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

Definition at line 464 of file network_engine.h.

◆ getNodeCacheSize() [2/2]

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

Definition at line 467 of file network_engine.h.

◆ getNodeMessageStats()

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

Definition at line 451 of file network_engine.h.

◆ getPartialCount()

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

Definition at line 475 of file network_engine.h.

◆ getRateLimiterSize()

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

Definition at line 471 of file network_engine.h.

◆ getSocket()

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

Definition at line 237 of file network_engine.h.

◆ insertNode()

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

Definition at line 445 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
bufThe buffer containing the binary message.
buflenThe length of the buffer.
fromThe address info of the sender.
fromlenThe length of the corresponding sockaddr structure.
nowThe 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
nThe node.
hashThe target hash.
createdThe time when the value was created (avoiding extended value lifetime)
tokenA security token.
on_doneRequest callback when the request is completed.
on_expiredRequest 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
nThe node.
targetThe target hash.
wantIndicating wether IPv4 or IPv6 are wanted in response. Use NetworkEngine::want()
on_doneRequest callback when the request is completed.
on_expiredRequest 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
nThe node.
hashThe target hash.
queryThe query describing filters.
tokenA security token.
wantIndicating wether IPv4 or IPv6 are wanted in response. Use NetworkEngine::want()
on_doneRequest callback when the request is completed.
on_expiredRequest 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
nThe node.
hashThe storage's hash.
queryThe query describing filters.
tokenA security token.
previousThe previous request "listen" sent to this node.
socketUNUSED 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_doneRequest callback when the request is completed.
on_expiredRequest callback when the request expires.
socket_cbCallback 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
nThe node.
on_doneRequest callback when the request is completed.
on_expiredRequest 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
saThe node's ip sockaddr info.
salenThe associated sockaddr struct length.
on_doneRequest callback when the request is completed.
on_expiredRequest callback when the request expires.
Returns
the request with information concerning its success.

Definition at line 295 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
nThe node.
hashThe target hash.
vidThe value id.
tokenA security token.
on_doneRequest callback when the request is completed.
on_expiredRequest 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
nThe node.
hashThe target hash.
valuesThe values.
createdTime id.
tokenA security token.
sidThe 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
saThe address of the listener.
sslenThe length of the sockaddr structure.
socket_idThe tid to use to write to the request socket.
hashThe hash key of the value.
wantWether to send ipv4 and/or ipv6 nodes.
ntokenListen security token.
nodesThe ipv4 closest nodes.
nodes6The ipv6 closest nodes.
valuesThe values to send.
versionIf version = 1, a request will be used to answer to the listener

◆ want()

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

Definition at line 264 of file network_engine.h.


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