30#include "librats/util/rats_export.h"
40#include <unordered_map>
48 using SendCallback = std::function<void(
bool ok,
const std::string& error)>;
58 void off(
const std::string& type);
83 PeerNetwork* network_ =
nullptr;
84 mutable std::mutex mutex_;
85 std::unordered_map<std::string, std::vector<Entry>> handlers_;
Lightweight byte container aliases and a non-owning byte view.
Non-owning view over a contiguous run of bytes.
void attach(NodeContext &ctx) override
void on(const std::string &type, Handler handler)
Register a handler for type.
void once(const std::string &type, Handler handler)
Like on(), but the handler is removed right after it fires once.
void send(const PeerId &to, const std::string &type, const librats::Json &data, SendCallback cb=nullptr)
Send data of type to one peer.
std::function< void(bool ok, const std::string &error)> SendCallback
void send(const std::string &type, const librats::Json &data, SendCallback cb=nullptr)
Broadcast data of type to all connected peers.
std::function< void(const PeerId &from, const librats::Json &data)> Handler
void off(const std::string &type)
Remove every handler registered for type.
A pluggable network subsystem.
A small, self-contained JSON value type for librats.
std::vector< uint8_t > Bytes
A lightweight handle to a connected peer.
Self-certifying peer identity.
The narrow contract a subsystem needs from the node — and nothing more.