Typed JSON message exchange over PeerNetwork. More...
#include "node/peer_network.h"#include "peer/peer.h"#include "peer/peer_id.h"#include "core/bytes.h"#include "util/json.h"#include <functional>#include <mutex>#include <string>#include <unordered_map>#include <vector>Go to the source code of this file.
Classes | |
| class | librats::MessageJson |
Namespaces | |
| namespace | librats |
Typed JSON message exchange over PeerNetwork.
A familiar on/once/off + send messaging API as a Subsystem: an application names a message type (a string) and exchanges librats::Json payloads with peers, without caring about framing or channels. Attach it like any subsystem; reach it later via node.json() (or subsystem<MessageJson>()):
node.add_subsystem(std::make_unique<MessageJson>()); node.json()->on("chat", [](const PeerId& from, const json& j){ ... }); node.start(); node.json()->send(peer_id, "chat", json{{"text","hi"}});
Two deliberate properties:
Wire format (MessageType::Typed payload): [type_len:u16][type bytes][json payload bytes] (json as compact text)
Handlers run on a reactor thread; do not block in them. Registration is thread-safe and may happen before or after start().
Definition in file message_json.h.