Skip to content

File syn_heartbeat.h

FileList > net > syn_heartbeat.h

Go to the source code of this file

Heartbeat / keep-alive monitor. More...

  • #include "../common/syn_defs.h"
  • #include "../system/syn_errlog.h"
  • #include "syn_router.h"
  • #include <stdbool.h>
  • #include <stdint.h>

Classes

Type Name
struct SYN_HB_Peer
Tracked peer entry.
struct SYN_Heartbeat
Heartbeat monitor — send keepalives, track peer liveness.

Public Types

Type Name
typedef void(* SYN_HB_Callback
Heartbeat event callback.

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.

Macros

Type Name
define SYN_HB_ERR_PEER_FOUND 0x0501
define SYN_HB_ERR_PEER_LOST 0x0500

Detailed Description

Sends periodic keepalive messages and tracks peer liveness. Integrates with the packet router for transport and can log peer-lost events to errlog.

Usage:

static SYN_HB_Peer peers[4];
static SYN_Heartbeat hb;

syn_heartbeat_init(&hb, &router, peers, 4, 1000, 3000);
syn_heartbeat_add_peer(&hb, 0x02);
syn_heartbeat_add_peer(&hb, 0x03);
syn_heartbeat_on_peer_lost(&hb, my_lost_cb, NULL);

// In main loop:
syn_heartbeat_update(&hb);

Public Types Documentation

typedef SYN_HB_Callback

Heartbeat event callback.

typedef void(* SYN_HB_Callback) (uint8_t node_id, void *ctx);

Parameters:

  • node_id Node that triggered the event.
  • ctx User context.

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.

Macro Definition Documentation

define SYN_HB_ERR_PEER_FOUND

#define SYN_HB_ERR_PEER_FOUND `0x0501`

Peer reappeared.


define SYN_HB_ERR_PEER_LOST

#define SYN_HB_ERR_PEER_LOST `0x0500`

Peer heartbeat timeout.



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