Back to Site
Loading...
Searching...
No Matches
message_json.h File Reference

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>
Include dependency graph for message_json.h:

Go to the source code of this file.

Classes

class  librats::MessageJson
 

Namespaces

namespace  librats
 

Detailed Description

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:

  • the sender is the authenticated PeerId from the handshake, not a self-reported field in the payload (which could be spoofed);
  • no JSON envelope on the wire — just [type][payload], encrypted by the transport like everything else.

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.