rippled
|
Peer to peer network simulator. More...
Classes | |
struct | link_type |
Public Member Functions | |
BasicNetwork (BasicNetwork const &)=delete | |
BasicNetwork & | operator= (BasicNetwork const &)=delete |
BasicNetwork (Scheduler &s) | |
bool | connect (Peer const &from, Peer const &to, duration const &delay=std::chrono::seconds{0}) |
Connect two peers. More... | |
bool | disconnect (Peer const &peer1, Peer const &peer2) |
Break a link. More... | |
template<class Function > | |
void | send (Peer const &from, Peer const &to, Function &&f) |
Send a message to a peer. More... | |
auto | links (Peer const &from) |
Return the range of active links. More... | |
Digraph< Peer, link_type > const & | graph () const |
Return the underlying digraph. More... | |
Private Types | |
using | peer_type = Peer |
using | clock_type = Scheduler::clock_type |
using | duration = typename clock_type::duration |
using | time_point = typename clock_type::time_point |
Private Attributes | |
Scheduler & | scheduler |
Digraph< Peer, link_type > | links_ |
Peer to peer network simulator.
The network is formed from a set of Peer objects representing vertices and configurable connections representing edges. The caller is responsible for creating the Peer objects ahead of time.
Peer objects cannot be destroyed once the BasicNetwork is constructed. To handle peers going online and offline, callers can simply disconnect all links and reconnect them later. Connections are directed, one end is the inbound Peer and the other is the outbound Peer.
Peers may send messages along their connections. To simulate the effects of latency, these messages can be delayed by a configurable duration set when the link is established. Messages always arrive in the order they were sent on a particular connection.
A message is modeled using a lambda function. The caller provides the code to execute upon delivery of the message. If a Peer is disconnected, all messages pending delivery at either end of the connection will not be delivered.
When creating the Peer set, the caller needs to provide a Scheduler object for managing the the timing and delivery of messages. After constructing the network, and establishing connections, the caller uses the scheduler's step_* functions to drive messages through the network.
The graph of peers and connections is internally represented using Digraph<Peer,BasicNetwork::link_type>. Clients have const access to that graph to perform additional operations not directly provided by BasicNetwork.
Peer Requirements:
Peer should be a lightweight type, cheap to copy and/or move. A good candidate is a simple pointer to the underlying user defined type in the simulation. Expression Type Requirements ---------- ---- ------------ P Peer u, v Values of type P P u(v) CopyConstructible u.~P() Destructible u == v bool EqualityComparable u < v bool LessThanComparable std::hash<P> class std::hash is defined for P ! u bool true if u is not-a-peer
Definition at line 83 of file BasicNetwork.h.
|
private |
Definition at line 85 of file BasicNetwork.h.
|
private |
Definition at line 87 of file BasicNetwork.h.
|
private |
Definition at line 89 of file BasicNetwork.h.
|
private |
Definition at line 91 of file BasicNetwork.h.
|
delete |
ripple::test::csf::BasicNetwork< Peer >::BasicNetwork | ( | Scheduler & | s | ) |
Definition at line 200 of file BasicNetwork.h.
|
delete |
bool ripple::test::csf::BasicNetwork< Peer >::connect | ( | Peer const & | from, |
Peer const & | to, | ||
duration const & | delay = std::chrono::seconds{0} |
||
) |
Connect two peers.
The link is directed, with from
establishing the outbound connection and to
receiving the incoming connection.
Preconditions:
from != to (self connect disallowed). A link between from and to does not already exist (duplicates disallowed).
Effects:
Creates a link between from and to.
<tt>from</tt> | The source of the outgoing connection |
<tt>to</tt> | The recipient of the incoming connection |
<tt>delay</tt> | The time delay of all delivered messages |
true
if a new connection was established Definition at line 206 of file BasicNetwork.h.
bool ripple::test::csf::BasicNetwork< Peer >::disconnect | ( | Peer const & | peer1, |
Peer const & | peer2 | ||
) |
Break a link.
Effects:
If a connection is present, both ends are disconnected. Any pending messages on the connection are discarded.
true
if a connection was broken. Definition at line 224 of file BasicNetwork.h.
void ripple::test::csf::BasicNetwork< Peer >::send | ( | Peer const & | from, |
Peer const & | to, | ||
Function && | f | ||
) |
Send a message to a peer.
Preconditions:
A link exists between from and to.
Effects:
If the link is not broken when the link's `delay` time has elapsed, the function will be invoked with no arguments.
from
's receipt of a message from to
. Definition at line 237 of file BasicNetwork.h.
auto ripple::test::csf::BasicNetwork< Peer >::links | ( | Peer const & | from | ) |
Return the range of active links.
Definition at line 185 of file BasicNetwork.h.
Digraph<Peer, link_type> const& ripple::test::csf::BasicNetwork< Peer >::graph | ( | ) | const |
Return the underlying digraph.
Definition at line 193 of file BasicNetwork.h.
|
private |
Definition at line 105 of file BasicNetwork.h.
|
private |
Definition at line 106 of file BasicNetwork.h.