#include <peer_network.h>
Public Types | |
| using | MessageHandler = std::function<void(const Peer&, ByteView)> |
| using | DeadlineMessageHandler = std::function<void(const Peer&, ByteView, Deadline)> |
| A message handler that is also told each message's deadline: for a live one (SendOptions::lifetime), the moment it was due to arrive here by the time its sender gave it, on this node's clock (Frame::deadline) — what a node passing it on gives the next hop, so that a message relayed does not get its lifetime afresh at each. | |
| using | PeerEventHandler = std::function<void(const Peer&)> |
| using | PeerDisconnectHandler = std::function<void(const PeerId&, CloseReason)> |
| A peer went away, and why. | |
| using | DialFailedHandler = std::function<void(const Address&)> |
| using | PeerPathHandler = std::function<void(const Peer&, const PathStats&)> |
| using | LiveOutcomeHandler = std::function<void(const Peer&, uint64_t tag, bool delivered)> |
| What became of a live message sent with a tag: delivered, or given up on (see LiveOutcome). | |
Public Member Functions | |
| virtual | ~PeerNetwork ()=default |
| virtual const PeerId & | local_id () const =0 |
| virtual uint16_t | listen_port () const =0 |
| our advertised listen port (shared by both transports) | |
| virtual uint8_t | transports () const |
| Which transports that port actually accepts, as a PeerTransports bitmask — the same value identify reports to peers. | |
| virtual const std::string & | protocol () const =0 |
| app protocol id (e.g. "librats/1.0"); namespaces discovery | |
| virtual void | connect (const Address &address)=0 |
| dial a discovered peer | |
| virtual bool | send (const PeerId &to, MessageType type, ByteView payload, SendOptions options={})=0 |
| Send to one peer. | |
| virtual bool | broadcast (MessageType type, ByteView payload, SendOptions options={})=0 |
| Send to every connected peer. | |
| virtual std::vector< PeerId > | connected_peers () const =0 |
| virtual std::vector< PeerInfo > | peers () const =0 |
| snapshot incl. dialable addresses | |
| virtual void | on (MessageType type, MessageHandler handler)=0 |
| virtual void | on_with_deadline (MessageType type, DeadlineMessageHandler handler) |
| on(), with each message's deadline. | |
| virtual void | on_peer_connected (PeerEventHandler handler)=0 |
| virtual void | on_peer_disconnected (PeerDisconnectHandler handler)=0 |
| virtual void | on_dial_failed (DialFailedHandler handler)=0 |
| virtual void | on_peer_writable (PeerEventHandler) |
| A peer whose send queue had filled up has drained back under its mark, so sending to it may resume. | |
| virtual bool | peer_writable (const PeerId &) const |
| The same question send() answers — "has this peer room for more?" — asked without sending anything. | |
| virtual void | on_peer_rerouted (PeerEventHandler) |
| A connected peer's traffic moved to another connection: a cross-connect or a reconnect settled on a link other than the one "connected" fired for, and that one is closed. | |
| virtual void | on_peer_moved (PeerEventHandler) |
| The path to a connected peer changed under its connection: one end's address did (a NAT gave it another port, its network changed) and the connection followed it there. | |
| virtual void | on_peer_path (PeerPathHandler) |
| A periodic sample of each connected peer's path (see PathStats) — what a sender that sizes its own output to the path, a live encoder above all, steers by. | |
| virtual std::optional< PathStats > | path_stats (const PeerId &) const |
| The latest path sample for a peer, from any thread; nullopt if the peer is not connected, sampling is off, or no sample has been taken yet. | |
| bool | answers (const PeerId &id) const |
| Whether id is reached over a link that answers (PathStats::answers) — connected, and not over a link gone dead, which a peer that moved leaves behind until it times out. | |
| virtual void | set_send_ceiling (const PeerId &, uint64_t) |
| Send to id no faster than bits_per_second, whatever its congestion controller paces at; 0 lifts the ceiling. | |
| virtual void | on_live_outcome (MessageType, LiveOutcomeHandler) |
| What becomes of each live message of type sent with a tag (SendOptions::tag), once per peer it went to: the moment it is delivered or given up on, as far as the sender can tell — sooner than a receiver could say, and for a message given up on before a byte of it left, the only word there is. | |
Definition at line 32 of file peer_network.h.
| using librats::PeerNetwork::DeadlineMessageHandler = std::function<void(const Peer&, ByteView, Deadline)> |
A message handler that is also told each message's deadline: for a live one (SendOptions::lifetime), the moment it was due to arrive here by the time its sender gave it, on this node's clock (Frame::deadline) — what a node passing it on gives the next hop, so that a message relayed does not get its lifetime afresh at each.
The epoch for a reliable message, and for a live one that came over TCP or a byte-stream relay, which do not say.
Definition at line 42 of file peer_network.h.
| using librats::PeerNetwork::DialFailedHandler = std::function<void(const Address&)> |
Definition at line 51 of file peer_network.h.
| using librats::PeerNetwork::LiveOutcomeHandler = std::function<void(const Peer&, uint64_t tag, bool delivered)> |
What became of a live message sent with a tag: delivered, or given up on (see LiveOutcome).
Definition at line 55 of file peer_network.h.
| using librats::PeerNetwork::MessageHandler = std::function<void(const Peer&, ByteView)> |
Definition at line 35 of file peer_network.h.
| using librats::PeerNetwork::PeerDisconnectHandler = std::function<void(const PeerId&, CloseReason)> |
A peer went away, and why.
The reason matters as much as the event: an application dropped as a slow consumer (CloseReason::SlowConsumer) has to slow down, while one whose peer simply left should reconnect — and without the reason those look identical, so the usual answer to both is to redial and repeat whatever caused it.
Definition at line 50 of file peer_network.h.
| using librats::PeerNetwork::PeerEventHandler = std::function<void(const Peer&)> |
Definition at line 44 of file peer_network.h.
| using librats::PeerNetwork::PeerPathHandler = std::function<void(const Peer&, const PathStats&)> |
Definition at line 52 of file peer_network.h.
|
virtualdefault |
|
inline |
Whether id is reached over a link that answers (PathStats::answers) — connected, and not over a link gone dead, which a peer that moved leaves behind until it times out.
Where there are no path samples, connected.
Definition at line 140 of file peer_network.h.
References connected_peers(), path_stats(), and peers().
|
pure virtual |
Send to every connected peer.
Implemented in librats::Node.
|
pure virtual |
dial a discovered peer
Implemented in librats::Node.
|
pure virtual |
Implemented in librats::Node.
Referenced by answers().
|
pure virtual |
our advertised listen port (shared by both transports)
Implemented in librats::Node.
|
pure virtual |
Implemented in librats::Node.
|
pure virtual |
Implemented in librats::Node.
Referenced by on_with_deadline().
|
pure virtual |
Implemented in librats::Node.
|
inlinevirtual |
What becomes of each live message of type sent with a tag (SendOptions::tag), once per peer it went to: the moment it is delivered or given up on, as far as the sender can tell — sooner than a receiver could say, and for a message given up on before a byte of it left, the only word there is.
Nothing for a message to a peer that disconnects first. Runs on a reactor thread; register before start(). Default: not offered (nothing is reported).
Reimplemented in librats::Node.
Definition at line 164 of file peer_network.h.
|
pure virtual |
Implemented in librats::Node.
|
pure virtual |
Implemented in librats::Node.
|
inlinevirtual |
The path to a connected peer changed under its connection: one end's address did (a NAT gave it another port, its network changed) and the connection followed it there.
PeerInfo::endpoint is where the peer is seen now. Its other peers, which knew it at the old address, may not hear it from the new one until told (Rendezvous tells them). Runs on a reactor thread. Default: not offered (a mock's peers never move).
Reimplemented in librats::Node.
Definition at line 128 of file peer_network.h.
|
inlinevirtual |
A periodic sample of each connected peer's path (see PathStats) — what a sender that sizes its own output to the path, a live encoder above all, steers by.
Registering one turns sampling on. Runs on a reactor thread. Default: not offered (nothing subscribes).
Reimplemented in librats::Node.
Definition at line 133 of file peer_network.h.
|
inlinevirtual |
A connected peer's traffic moved to another connection: a cross-connect or a reconnect settled on a link other than the one "connected" fired for, and that one is closed.
What was sent on it and not yet delivered is lost, with no disconnect to say so — a subsystem that tells a peer something once, on connect (what it offers, what it asks for, a request), tells it again here. What did arrive may so arrive twice. Runs on a reactor thread. Default: not offered (a mock's peers never move).
Reimplemented in librats::Node.
Definition at line 121 of file peer_network.h.
|
inlinevirtual |
A peer whose send queue had filled up has drained back under its mark, so sending to it may resume.
The counterpart of send() returning false; a subsystem that never checks that return never needs this either. Runs on a reactor thread. Default: not offered (nothing subscribes).
Reimplemented in librats::Node.
Definition at line 104 of file peer_network.h.
|
inlinevirtual |
on(), with each message's deadline.
One handler per type, of either kind. Default: every deadline the epoch, all a mock that merely moves messages can say.
Reimplemented in librats::Node.
Definition at line 85 of file peer_network.h.
References on().
|
inlinevirtual |
The latest path sample for a peer, from any thread; nullopt if the peer is not connected, sampling is off, or no sample has been taken yet.
Reimplemented in librats::Node.
Definition at line 136 of file peer_network.h.
Referenced by answers().
|
inlinevirtual |
The same question send() answers — "has this peer room for more?" — asked without sending anything.
For a subsystem that paces a long fan-out from a thread of its own (StorageManager streaming a snapshot): the event alone cannot serve it, because a queue filled only with bytes handed to send() that the reactor has not taken up yet never crossed anything on the connection, so nothing raises on_peer_writable when they drain. Safe to poll — it weighs those in-flight bytes too. False for an unknown peer. Default: always writable, all a mock that merely moves messages can claim.
Reimplemented in librats::Node.
Definition at line 113 of file peer_network.h.
|
pure virtual |
|
pure virtual |
app protocol id (e.g. "librats/1.0"); namespaces discovery
Implemented in librats::Node.
|
pure virtual |
Send to one peer.
Implemented in librats::Node.
|
inlinevirtual |
Send to id no faster than bits_per_second, whatever its congestion controller paces at; 0 lifts the ceiling.
For a sender that knows several connections share one uplink narrower than each path beyond it — copies of a stream to several peers — and keeps their bursts from filling its queue together, which no one connection's controller sees. Kept for the peer across a change of link; forgotten when it disconnects. Paced on UDP connections (TCP leaves pacing to the kernel). Any thread. Default: not offered (a mock's sends are not paced).
Reimplemented in librats::Node.
Definition at line 156 of file peer_network.h.
|
inlinevirtual |
Which transports that port actually accepts, as a PeerTransports bitmask — the same value identify reports to peers.
A subsystem that has to make the port reachable from outside (PortMappingService) needs to know which protocols to ask the router for. Default: TCP only, which is all a mock that merely moves messages has to claim.
Reimplemented in librats::Node.
Definition at line 64 of file peer_network.h.
References librats::PeerTransportTcp.