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

Two-level wire framing: outer length-prefixed blocks, inner messages. More...

#include "librats/util/rats_export.h"
#include "librats/core/bytes.h"
#include "librats/core/types.h"
#include <cstdint>
Include dependency graph for frame.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  librats::FrameHeader
 Fixed header of an inner message. More...
struct  librats::Frame
 A decoded inner message. payload is a non-owning view into the source bytes. More...
struct  librats::LiveOutcome
 What became of a live message sent with a tag (SendOptions::tag), as far as its sender can tell. More...
struct  librats::framer::Block
struct  librats::framer::Message

Namespaces

namespace  librats
namespace  librats::framer

Enumerations

enum class  librats::MessageType : uint8_t {
  librats::App = 1 , librats::Control = 2 , librats::Gossip = 3 , librats::FileChunk = 4 ,
  librats::Ping = 5 , librats::Storage = 6 , librats::Typed = 7 , librats::Pex = 8 ,
  librats::Punch = 9 , librats::Relay = 10 , librats::Media = 11 , librats::Rendezvous = 12 ,
  librats::Remote = 13
}
 Inner-message kind. Application traffic uses App, addressed by channel. More...

Functions

void librats::framer::encode_block (Bytes &out, ByteView body)
 Append [u32 len][body] to out.
void librats::framer::encode_block_header (uint8_t *out, size_t body_size)
 Write just the [u32 len] prefix into out (exactly kLengthPrefixSize bytes).
Block librats::framer::try_take_block (const uint8_t *data, size_t size)
 Try to take one block from the front of [data, data+size) without copying.
void librats::framer::encode_header (uint8_t *out, FrameHeader header)
 Write the kHeaderSize-byte [type][flags][channel] header at out.
void librats::framer::encode_message (Bytes &out, FrameHeader header, ByteView payload)
 Append [type][flags][channel][payload] to out (no length prefix).
Message librats::framer::parse_message (ByteView inner)
 Parse an inner message from inner (header + payload). ok false if short.

Variables

constexpr size_t librats::framer::kLengthPrefixSize = 4
constexpr size_t librats::framer::kHeaderSize = 4
 type+flags+channel
constexpr uint32_t librats::framer::kMaxBlockSize = 64u * 1024 * 1024
 body cap

Detailed Description

Two-level wire framing: outer length-prefixed blocks, inner messages.

The wire is a stream of length-prefixed blocks:

┌──────────────┬───────────────────────────┐ │ length (u32) │ body │ │ 4 bytes │ length bytes │ └──────────────┴───────────────────────────┘

A block's body is opaque at this layer. StreamTransport uses it for two things:

  • during the handshake, the body is a raw handshake message (Noise / id);
  • once established, the body is one inner message, sealed by the Session, which has its own fixed 4-byte header:

    ┌──────┬───────┬─────────┬───────────────┐ │ type │ flags │ channel │ payload … │ │ u8 │ u8 │ u16 │ │ └──────┴───────┴─────────┴───────────────┘

Splitting "outer block" from "inner message" keeps encryption clean: the cipher wraps the whole inner message (type included), and the block layer never needs to understand it. Decoding is zero-copy — views point into the caller's buffer and are valid only until it is consumed.

Definition in file frame.h.