14#include "librats/util/rats_export.h"
20#include "librats/core/types.h"
65 virtual const std::string&
protocol()
const = 0;
75 SendOptions options = {}) = 0;
80 virtual std::vector<PeerInfo>
peers()
const = 0;
86 on(type, [handler = std::move(handler)](
const Peer& peer,
ByteView payload) {
87 handler(peer, payload, Deadline{});
141 if (
const std::optional<PathStats> path =
path_stats(
id))
142 return path->answers(std::chrono::steady_clock::now());
145 if (peer ==
id)
return true;
A dialable transport endpoint: a numeric IP + port.
Lightweight byte container aliases and a non-owning byte view.
Non-owning view over a contiguous run of bytes.
std::function< void(const Peer &, ByteView, Deadline)> DeadlineMessageHandler
A message handler that is also told each message's deadline: for a live one (SendOptions::lifetime),...
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 anoth...
virtual void on(MessageType type, MessageHandler handler)=0
std::function< void(const Address &)> DialFailedHandler
virtual const std::string & protocol() const =0
app protocol id (e.g. "librats/1.0"); namespaces discovery
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 t...
virtual const PeerId & local_id() const =0
virtual void connect(const Address &address)=0
dial a discovered peer
virtual bool broadcast(MessageType type, ByteView payload, SendOptions options={})=0
Send to every connected peer.
virtual uint8_t transports() const
Which transports that port actually accepts, as a PeerTransports bitmask — the same value identify re...
std::function< void(const PeerId &, CloseReason)> PeerDisconnectHandler
A peer went away, and why.
virtual void on_with_deadline(MessageType type, DeadlineMessageHandler handler)
on(), with each message's deadline.
std::function< void(const Peer &, ByteView)> MessageHandler
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,...
std::function< void(const Peer &, const PathStats &)> PeerPathHandler
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 c...
bool answers(const PeerId &id) const
Whether id is reached over a link that answers (PathStats::answers) — connected, and not over a link ...
virtual void on_peer_disconnected(PeerDisconnectHandler handler)=0
std::function< void(const Peer &, uint64_t tag, bool delivered)> LiveOutcomeHandler
What became of a live message sent with a tag: delivered, or given up on (see LiveOutcome).
virtual ~PeerNetwork()=default
virtual void on_peer_rerouted(PeerEventHandler)
A connected peer's traffic moved to another connection: a cross-connect or a reconnect settled on a l...
virtual void on_peer_connected(PeerEventHandler handler)=0
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_dial_failed(DialFailedHandler handler)=0
virtual std::vector< PeerInfo > peers() const =0
snapshot incl. dialable addresses
virtual void on_peer_path(PeerPathHandler)
A periodic sample of each connected peer's path (see PathStats) — what a sender that sizes its own ou...
virtual uint16_t listen_port() const =0
our advertised listen port (shared by both transports)
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.
std::function< void(const Peer &)> PeerEventHandler
virtual bool send(const PeerId &to, MessageType type, ByteView payload, SendOptions options={})=0
Send to one peer.
virtual std::vector< PeerId > connected_peers() const =0
A pluggable network subsystem.
virtual ~Subsystem()=default
virtual void attach(NodeContext &ctx)=0
Two-level wire framing: outer length-prefixed blocks, inner messages.
MessageType
Inner-message kind. Application traffic uses App, addressed by channel.
Self-certifying peer identity.
Addressing/metadata for a peer — the shareable, persistable identity.