ams::mitm::ldn::LdnProxyBuffer
ams::mitm::ldn::LdnProxyBuffer
Section titled “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)
Members
Section titled “Members”MaxPacketDataSize
Section titled “MaxPacketDataSize”Type: constexpr size_t
Maximum size of a single proxy data packet (data only, not header)
BufferSize
Section titled “BufferSize”Type: constexpr size_t
Total buffer size (fits ~4 max-size packets)
MaxQueuedPackets
Section titled “MaxQueuedPackets”Type: constexpr size_t
Maximum number of packets that can be queued.
Members
Section titled “Members”m_mutex
Section titled “m_mutex”Type: os::SdkMutex
Thread safety.
m_packets
Section titled “m_packets”Type: PacketEntry
Packet metadata queue.
m_packet_read_idx
Section titled “m_packet_read_idx”Type: size_t
Read position.
m_packet_write_idx
Section titled “m_packet_write_idx”Type: size_t
Write position.
m_packet_count
Section titled “m_packet_count”Type: size_t
Number of packets.
m_data_buffer
Section titled “m_data_buffer”Type: u8
Payload data storage.
m_data_read_pos
Section titled “m_data_read_pos”Type: size_t
Data read position.
m_data_write_pos
Section titled “m_data_write_pos”Type: size_t
Data write position.
Methods
Section titled “Methods”LdnProxyBuffer
Section titled “LdnProxyBuffer”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
GetPendingCount
Section titled “GetPendingCount”size_t GetPendingCount()Get number of packets in queue.
Number of pending packetsreturnNumber of packets waiting to be readreturn
Returns: size_t
IsEmpty
Section titled “IsEmpty”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:
GetUsedBytes
Section titled “GetUsedBytes”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