Skip to content

ams::mitm::ldn::LdnProxyBuffer

Ring buffer for proxy data packets.

Implements a lock-free single-producer single-consumer queue for proxy data. Uses a fixed-size ring buffer to avoid memory allocation during gameplay.Memory LayoutThe buffer stores packets as: [PacketSize:4][Header:8][Data:N] This allows reading packet boundaries without parsing headers. Safety: Called from network receive thread: Called from game threadUses os::SdkMutex for simplicity (games don’t call at high frequency)

Type: constexpr size_t

Maximum size of a single proxy data packet (data only, not header)

Type: constexpr size_t

Total buffer size (fits ~4 max-size packets)

Type: constexpr size_t

Maximum number of packets that can be queued.

Type: os::SdkMutex

Thread safety.

Type: PacketEntry

Packet metadata queue.

Type: size_t

Read position.

Type: size_t

Write position.

Type: size_t

Number of packets.

Type: u8

Payload data storage.

Type: size_t

Data read position.

Type: size_t

Data write position.

void LdnProxyBuffer()

Constructor - initializes empty buffer.

All indices start at 0, buffer is empty.

bool Write(const ryu_ldn::protocol::ProxyDataHeader & header, const u8 * data, size_t size)

Write a packet to the buffer.

Adds a proxy data packet to the queue. If the buffer is full, the oldest packet is dropped to make room.Copies the header and data into the ring buffer.AlgorithmCheck if packet queue is fullCheck if data buffer has enough spaceCopy data to ring buffer (handle wrap-around)Store packet metadataUpdate write indicesheaderProxy data header (8 bytes)dataPacket payloadsizePayload size (must be <= MaxPacketDataSize)paramtrue if packet was queued successfullyreturn

Parameters:

  • header (const ryu_ldn::protocol::ProxyDataHeader &)
  • data (const u8 *)
  • size (size_t)

Returns: bool

bool Read(ryu_ldn::protocol::ProxyDataHeader & header, u8 * data, size_t & size, size_t max_size)

Read a packet from the buffer.

Removes and returns the oldest packet from the queue.Copies the oldest packet’s header and data to the output buffers.AlgorithmCheck if queue is emptyGet packet metadata from read positionCopy header to outputCopy data to output (respecting max_size)Update read indicesheaderOutput: packet headerdataOutput: payload buffersizeOutput: actual payload size copiedmax_sizeMaximum bytes to copy to data bufferparamtrue if packet was read, false if queue emptyreturn

Parameters:

  • header (ryu_ldn::protocol::ProxyDataHeader &)
  • data (u8 *)
  • size (size_t &)
  • max_size (size_t)

Returns: bool

bool Peek(ryu_ldn::protocol::ProxyDataHeader & header, size_t & size)

Peek at next packet without removing it.

Allows inspection of the next packet’s metadata without consuming it from the queue.headerOutput: packet headersizeOutput: payload sizeparamtrue if packet availablereturn

Parameters:

  • header (ryu_ldn::protocol::ProxyDataHeader &)
  • size (size_t &)

Returns: bool

size_t GetPendingCount()

Get number of packets in queue.

Number of pending packetsreturnNumber of packets waiting to be readreturn

Returns: size_t

bool IsEmpty()

Check if buffer is empty.

true if no packets queuedreturntrue if no packets in queuereturn

Returns: bool

void Reset()

Clear all queued packets.

Discards all pending packets and resets buffer to empty state. Called when:

size_t GetUsedBytes()

Get total bytes used in buffer.

For debugging/monitoring buffer usage.Returns approximate bytes used in the data buffer. Useful for monitoring buffer fill level.Bytes used (may wrap, so approximate)return

Returns: size_t