Skip to content

File syn_heartbeat.c

FileList > net > syn_heartbeat.c

Go to the source code of this file

Heartbeat / keep-alive implementation.

  • #include "../util/syn_assert.h"
  • #include "syn_heartbeat.h"
  • #include <string.h>

Public Functions

Type Name
bool syn_heartbeat_add_peer (SYN_Heartbeat * hb, uint8_t node_id)
Add a peer to monitor.
void syn_heartbeat_init (SYN_Heartbeat * hb, SYN_Router * router, SYN_HB_Peer * peers, uint8_t peer_cap, uint32_t interval_ms, uint32_t timeout_ms)
Initialize heartbeat system.
void syn_heartbeat_on_peer_found (SYN_Heartbeat * hb, SYN_HB_Callback cb, void * ctx)
Register peer-found callback.
void syn_heartbeat_on_peer_lost (SYN_Heartbeat * hb, SYN_HB_Callback cb, void * ctx)
Register peer-lost callback.
bool syn_heartbeat_peer_alive (const SYN_Heartbeat * hb, uint8_t node_id)
Check if a specific peer is alive.
void syn_heartbeat_set_errlog (SYN_Heartbeat * hb, SYN_ErrLog * errlog)
Attach error log for peer-lost/found events.
void syn_heartbeat_update (SYN_Heartbeat * hb)
Update — send heartbeat + check peers.

Public Static Functions

Type Name
void hb_rx_handler (const SYN_Packet * pkt, void * ctx)
Router callback for incoming heartbeat packets.

Public Functions Documentation

function syn_heartbeat_add_peer

Add a peer to monitor.

bool syn_heartbeat_add_peer (
    SYN_Heartbeat * hb,
    uint8_t node_id
) 

Parameters:

  • hb Heartbeat instance.
  • node_id Peer node ID.

Returns:

true if added, false if peer table is full.


function syn_heartbeat_init

Initialize heartbeat system.

void syn_heartbeat_init (
    SYN_Heartbeat * hb,
    SYN_Router * router,
    SYN_HB_Peer * peers,
    uint8_t peer_cap,
    uint32_t interval_ms,
    uint32_t timeout_ms
) 

Automatically registers a handler for SYN_MSG_HEARTBEAT on the router.

Parameters:

  • hb Heartbeat instance.
  • router Packet router.
  • peers Caller-owned peer array.
  • peer_cap Array capacity.
  • interval_ms How often to send our heartbeat.
  • timeout_ms How long before a peer is "dead".

function syn_heartbeat_on_peer_found

Register peer-found callback.

void syn_heartbeat_on_peer_found (
    SYN_Heartbeat * hb,
    SYN_HB_Callback cb,
    void * ctx
) 

Parameters:

  • hb Heartbeat instance.
  • cb Callback function.
  • ctx User context.

function syn_heartbeat_on_peer_lost

Register peer-lost callback.

void syn_heartbeat_on_peer_lost (
    SYN_Heartbeat * hb,
    SYN_HB_Callback cb,
    void * ctx
) 

Parameters:

  • hb Heartbeat instance.
  • cb Callback function.
  • ctx User context.

function syn_heartbeat_peer_alive

Check if a specific peer is alive.

bool syn_heartbeat_peer_alive (
    const SYN_Heartbeat * hb,
    uint8_t node_id
) 

Parameters:

  • hb Heartbeat instance.
  • node_id Peer node ID.

Returns:

true if the peer is alive.


function syn_heartbeat_set_errlog

Attach error log for peer-lost/found events.

void syn_heartbeat_set_errlog (
    SYN_Heartbeat * hb,
    SYN_ErrLog * errlog
) 

Parameters:

  • hb Heartbeat instance.
  • errlog Error log instance.

function syn_heartbeat_update

Update — send heartbeat + check peers.

void syn_heartbeat_update (
    SYN_Heartbeat * hb
) 

Call from your main loop.

Parameters:

  • hb Heartbeat instance.

Public Static Functions Documentation

function hb_rx_handler

Router callback for incoming heartbeat packets.

static void hb_rx_handler (
    const SYN_Packet * pkt,
    void * ctx
) 

Parameters:



The documentation for this class was generated from the following file src/syntropic/net/syn_heartbeat.c