File syn_router.c¶
FileList > net > syn_router.c
Go to the source code of this file
Packet router implementation.
#include "syn_router.h"#include "syntropic/util/syn_assert.h"#include "syntropic/util/syn_pack.h"#include <string.h>
Public Functions¶
| Type | Name |
|---|---|
| void | syn_router_enable_ack (SYN_Router * r, SYN_PendingAck * pending, uint8_t cap, uint16_t timeout_ms, uint8_t max_retries) Enable reliable delivery (ACK/retry). |
| void | syn_router_init (SYN_Router * r, uint8_t node_id, SYN_Transport * transport, SYN_RouterHandler * handlers, uint8_t handler_cap) Initialize packet router. |
| void | syn_router_poll (SYN_Router * r) Poll for incoming packets and dispatch handlers. |
| bool | syn_router_register (SYN_Router * r, uint8_t type, SYN_RouterHandlerFn handler, void * ctx) Register a handler for a message type. |
| bool | syn_router_send (SYN_Router * r, uint8_t dst, uint8_t type, const uint8_t * data, uint8_t len, bool reliable) Send a message. |
Public Static Functions¶
| Type | Name |
|---|---|
| void | check_retries (SYN_Router * r) Retry pending packets that have timed out. |
| bool | deserialize_packet (const uint8_t * buf, size_t len, SYN_Packet * pkt) Deserialize a wire-format buffer into a packet. |
| void | handle_ack (SYN_Router * r, uint8_t src, uint8_t seq) Handle an incoming ACK by clearing the pending entry. |
| bool | queue_pending (SYN_Router * r, uint8_t dst, uint8_t type, uint8_t seq, const uint8_t * data, uint8_t len) Queue a pending ACK entry for reliable delivery. |
| void | send_ack (SYN_Router * r, uint8_t dst, uint8_t seq) Send an ACK packet to the source. |
| size_t | serialize_packet (const SYN_Packet * pkt, uint8_t * buf) Serialize a packet into a wire-format buffer. |
Public Functions Documentation¶
function syn_router_enable_ack¶
Enable reliable delivery (ACK/retry).
void syn_router_enable_ack (
SYN_Router * r,
SYN_PendingAck * pending,
uint8_t cap,
uint16_t timeout_ms,
uint8_t max_retries
)
Parameters:
rRouter.pendingCaller-owned pending ACK array.capArray capacity.timeout_msACK timeout per attempt.max_retriesMax retransmissions before giving up.
function syn_router_init¶
Initialize packet router.
void syn_router_init (
SYN_Router * r,
uint8_t node_id,
SYN_Transport * transport,
SYN_RouterHandler * handlers,
uint8_t handler_cap
)
Parameters:
rRouter instance.node_idThis node's ID (0-254).transportTransport to send/receive over.handlersCaller-owned handler array.handler_capArray capacity.
function syn_router_poll¶
Poll for incoming packets and dispatch handlers.
Also checks for ACK timeouts and retransmits if needed. Call from your main loop.
Parameters:
rRouter.
function syn_router_register¶
Register a handler for a message type.
Parameters:
rRouter.typeMessage type to handle.handlerHandler function.ctxUser context.
Returns:
true if registered, false if handler table is full.
function syn_router_send¶
Send a message.
bool syn_router_send (
SYN_Router * r,
uint8_t dst,
uint8_t type,
const uint8_t * data,
uint8_t len,
bool reliable
)
Parameters:
rRouter.dstDestination node ID (0xFF = broadcast).typeMessage type.dataPayload.lenPayload length.reliableIf true and ACK is enabled, wait for ACK with retry.
Returns:
true if sent (or queued for retry).
Public Static Functions Documentation¶
function check_retries¶
Retry pending packets that have timed out.
Parameters:
rRouter instance.
function deserialize_packet¶
Deserialize a wire-format buffer into a packet.
Parameters:
bufInput buffer.lenBuffer length.pkt[out] Parsed packet.
Returns:
true on success.
function handle_ack¶
Handle an incoming ACK by clearing the pending entry.
Parameters:
rRouter instance.srcSource node ID.seqSequence number.
function queue_pending¶
Queue a pending ACK entry for reliable delivery.
static bool queue_pending (
SYN_Router * r,
uint8_t dst,
uint8_t type,
uint8_t seq,
const uint8_t * data,
uint8_t len
)
Parameters:
rRouter instance.dstDestination node ID.typeMessage type.seqSequence number.dataPayload data.lenPayload length.
Returns:
true if queued successfully.
function send_ack¶
Send an ACK packet to the source.
Parameters:
rRouter instance.dstDestination node to acknowledge.seqSequence number being acknowledged.
function serialize_packet¶
Serialize a packet into a wire-format buffer.
Parameters:
pktPacket to serialize.buf[out] Output buffer (header + payload).
Returns:
Total bytes written.
The documentation for this class was generated from the following file src/syntropic/net/syn_router.c