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.
Parameters:
node_idNode that triggered the event.ctxUser context.
Public Functions Documentation¶
function syn_heartbeat_add_peer¶
Add a peer to monitor.
Parameters:
hbHeartbeat instance.node_idPeer 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:
hbHeartbeat instance.routerPacket router.peersCaller-owned peer array.peer_capArray capacity.interval_msHow often to send our heartbeat.timeout_msHow long before a peer is "dead".
function syn_heartbeat_on_peer_found¶
Register peer-found callback.
Parameters:
hbHeartbeat instance.cbCallback function.ctxUser context.
function syn_heartbeat_on_peer_lost¶
Register peer-lost callback.
Parameters:
hbHeartbeat instance.cbCallback function.ctxUser context.
function syn_heartbeat_peer_alive¶
Check if a specific peer is alive.
Parameters:
hbHeartbeat instance.node_idPeer node ID.
Returns:
true if the peer is alive.
function syn_heartbeat_set_errlog¶
Attach error log for peer-lost/found events.
Parameters:
hbHeartbeat instance.errlogError log instance.
function syn_heartbeat_update¶
Update — send heartbeat + check peers.
Call from your main loop.
Parameters:
hbHeartbeat instance.
Macro Definition Documentation¶
define SYN_HB_ERR_PEER_FOUND¶
Peer reappeared.
define SYN_HB_ERR_PEER_LOST¶
Peer heartbeat timeout.
The documentation for this class was generated from the following file src/syntropic/net/syn_heartbeat.h