#include <peer_network.h>
Public Types | |
| using | MessageHandler = std::function< void(const Peer &, ByteView)> |
| 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 &)> |
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)=0 |
| Send to one peer. | |
| virtual bool | broadcast (MessageType type, ByteView payload)=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_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. | |
Definition at line 31 of file peer_network.h.
| using librats::PeerNetwork::DialFailedHandler = std::function<void(const Address&)> |
Definition at line 43 of file peer_network.h.
| using librats::PeerNetwork::MessageHandler = std::function<void(const Peer&, ByteView)> |
Definition at line 34 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 42 of file peer_network.h.
| using librats::PeerNetwork::PeerEventHandler = std::function<void(const Peer&)> |
Definition at line 36 of file peer_network.h.
|
virtualdefault |
|
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.
|
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.
|
pure virtual |
Implemented in librats::Node.
|
pure virtual |
Implemented in librats::Node.
|
pure virtual |
Implemented in librats::Node.
|
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 82 of file peer_network.h.
|
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 91 of file peer_network.h.
|
pure virtual |
snapshot incl. dialable addresses
Implemented in librats::Node.
|
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 |
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 52 of file peer_network.h.
References librats::PeerTransportTcp.