Skip to content

File baton_node.c

FileList > src > baton_node.c

Go to the source code of this file

  • #include <stddef.h>
  • #include <string.h>
  • #include "baton_node.h"

Classes

Type Name
struct msg_desc
Identifier and maximum length of one message.

Public Static Attributes

Type Name
const struct msg_desc state_desc = /* multi line expression */

Public Static Functions

Type Name
void chan_abandon (struct baton_channel * channel)
The content of the outstanding frame was abandoned: the next content uses a new seq.
void chan_commit (struct baton_node * node, uint8_t peer)
Acknowledged: release all messages of the outstanding frame for this peer.
void chan_drop_ref (struct baton_node * node, uint8_t peer, uint16_t ref)
Remove an expired event from the outstanding frame of peer (its inflight bit is set).
void chan_remove_at (struct baton_channel * channel, uint8_t i)
bool config_valid (const struct baton_node_config * config)
void deliver (struct baton_node * node, uint8_t src_index, const uint8_t * payload, uint16_t length)
uint16_t emit (uint8_t * out, uint16_t n, uint8_t id, const uint8_t * data, uint8_t length)
void expire_events (struct baton_node * node, uint32_t now_ms)
void expire_record (struct baton_node * node, uint8_t qi, uint16_t offset, const struct baton_record * record)
bool find_desc (const struct msg_desc * table, uint8_t count, uint8_t id, uint8_t * index)
uint32_t frame_ms (const struct baton_node * node, uint32_t bytes)
void handle_frame (struct baton_node * node, const struct baton_frame * frame, uint32_t now_ms)
void housekeeping (struct baton_node * node, uint32_t now_ms)
void link_service (struct baton_node * node, uint32_t now_ms)
void lock (const struct baton_node * node)
void master_on_resp (struct baton_node * node, uint8_t src_index, const struct baton_frame * frame)
void master_poll_done (struct baton_node * node, bool responded, uint32_t nack_nodes)
void master_send_poll (struct baton_node * node)
void master_service (struct baton_node * node, uint32_t now_ms)
uint32_t min_slot_ms (const struct baton_node * node)
Shortest slot in which a slave can still send one maximum-size message.
int msg_max_length (uint8_t id)
Maximum length of a known message (state or event), -1 for an unknown id.
uint32_t node_bit (uint8_t index)
uint8_t node_index (const struct baton_node * node, uint8_t address)
void on_tx_done (struct baton_node * node, uint32_t now_ms)
int pack (struct baton_node * node, uint8_t peer, uint8_t * out, uint16_t max_length)
Build the message part of a frame for peer: the outstanding content again, or HIGH events, NORMAL events and dirty states.
int pack_again (struct baton_node * node, uint8_t peer, uint8_t * out, uint16_t max_length)
Rebuild the content of the unacknowledged frame (same seq) so the receiver can filter duplicates.
uint16_t pack_events (struct baton_node * node, uint8_t peer, uint8_t * out, uint16_t n, uint16_t max_length)
Take queued events for peer , HIGH first, FIFO within a queue (never skip ahead).
uint16_t pack_states (struct baton_node * node, uint8_t peer, uint8_t * out, uint16_t n, uint16_t max_length)
Take the dirty states for peer .
void queue_reclaim (struct baton_node * node, uint8_t qi)
uint8_t ref_kind (uint16_t ref)
uint16_t ref_make (uint8_t kind, uint16_t value)
uint16_t ref_value (uint16_t ref)
void rx_content (struct baton_node * node, uint8_t src_index, uint8_t ctrl, const uint8_t * payload, uint16_t length)
Deliver the content of a frame unless it is a retransmission that was already delivered.
void slave_ack_timeout (struct baton_node * node, uint32_t now_ms)
int32_t slave_budget (const struct baton_node * node, uint32_t now_ms)
Payload bytes a DATA frame may still carry in this slot (time for the RESP is reserved).
void slave_on_ack (struct baton_node * node, uint8_t src_index, uint8_t ctrl, uint32_t now_ms)
void slave_on_data (struct baton_node * node, uint8_t src_index, const struct baton_frame * frame)
void slave_on_poll (struct baton_node * node, const struct baton_frame * frame, uint32_t now_ms)
void slave_send_resp (struct baton_node * node)
void slave_slot_step (struct baton_node * node, uint32_t now_ms)
Continue the slot: DATA to the next peer that has something, else RESP.
int slave_tx_data (struct baton_node * node, uint8_t peer, uint32_t now_ms)
uint16_t state_offset (uint8_t s)
Offset of state s in the mailbox storage.
bool timing_valid (const struct baton_node * node)
Timing must allow an ACK and at least one maximum-size exchange per slot.
bool topology_valid (struct baton_node * node)
Build the node table (0 = master, 1..n = slaves) and find this node in it.
bool try_emit_state (struct baton_node * node, uint8_t * out, uint16_t * n, uint16_t limit, uint8_t s, uint32_t clear_bit)
Copy the current value of state s if it fits below limit ; clear its dirty bits.
void tx_request (struct baton_node * node, uint8_t * buffer, size_t capacity, uint8_t dst, uint8_t ctrl, uint8_t payload_length)
Seal the frame in buffer (payload already at BATON_HEADER_SIZE) and request it.
void unlock (const struct baton_node * node)

Macros

Type Name
define HOUSEKEEP_PERIOD_MS 10U
Period of the TTL scan.
define L_IDLE 0U
Link (master/slave) states.
define M_POLL_TX 5U
define M_WAIT_RESP 6U
define NO_NODE 0xFFU
Returned by node_index() for an unknown address.
define Q_HIGH 0U
Queue indexes; also the kind of a message reference.
define Q_NORMAL 1U
define REF_STATE 2U
define RESP_TIMEOUT_MARGIN_MS 10U
Margin added to the slot time before the master gives up waiting for a RESP.
define STREAK_MAX 255U
Saturation limit of the failure streak counters.
define S_ACK_TX 4U
define S_DATA_TX 1U
define S_RESP_TX 3U
define S_WAIT_ACK 2U

Public Static Attributes Documentation

variable state_desc

const struct msg_desc state_desc[BATON_STATE_COUNT+1U];

Public Static Functions Documentation

function chan_abandon

The content of the outstanding frame was abandoned: the next content uses a new seq.

static void chan_abandon (
    struct baton_channel * channel
) 


function chan_commit

Acknowledged: release all messages of the outstanding frame for this peer.

static void chan_commit (
    struct baton_node * node,
    uint8_t peer
) 


function chan_drop_ref

Remove an expired event from the outstanding frame of peer (its inflight bit is set).

static void chan_drop_ref (
    struct baton_node * node,
    uint8_t peer,
    uint16_t ref
) 


function chan_remove_at

static void chan_remove_at (
    struct baton_channel * channel,
    uint8_t i
) 

function config_valid

static bool config_valid (
    const struct baton_node_config * config
) 

function deliver

static void deliver (
    struct baton_node * node,
    uint8_t src_index,
    const uint8_t * payload,
    uint16_t length
) 

function emit

static uint16_t emit (
    uint8_t * out,
    uint16_t n,
    uint8_t id,
    const uint8_t * data,
    uint8_t length
) 

function expire_events

static void expire_events (
    struct baton_node * node,
    uint32_t now_ms
) 

function expire_record

static void expire_record (
    struct baton_node * node,
    uint8_t qi,
    uint16_t offset,
    const struct baton_record * record
) 

function find_desc

static bool find_desc (
    const struct msg_desc * table,
    uint8_t count,
    uint8_t id,
    uint8_t * index
) 

function frame_ms

static uint32_t frame_ms (
    const struct baton_node * node,
    uint32_t bytes
) 

function handle_frame

static void handle_frame (
    struct baton_node * node,
    const struct baton_frame * frame,
    uint32_t now_ms
) 

function housekeeping

static void housekeeping (
    struct baton_node * node,
    uint32_t now_ms
) 

static void link_service (
    struct baton_node * node,
    uint32_t now_ms
) 

function lock

static void lock (
    const struct baton_node * node
) 

function master_on_resp

static void master_on_resp (
    struct baton_node * node,
    uint8_t src_index,
    const struct baton_frame * frame
) 

function master_poll_done

static void master_poll_done (
    struct baton_node * node,
    bool responded,
    uint32_t nack_nodes
) 

function master_send_poll

static void master_send_poll (
    struct baton_node * node
) 

function master_service

static void master_service (
    struct baton_node * node,
    uint32_t now_ms
) 

function min_slot_ms

Shortest slot in which a slave can still send one maximum-size message.

static uint32_t min_slot_ms (
    const struct baton_node * node
) 


function msg_max_length

Maximum length of a known message (state or event), -1 for an unknown id.

static int msg_max_length (
    uint8_t id
) 


function node_bit

static uint32_t node_bit (
    uint8_t index
) 

function node_index

static uint8_t node_index (
    const struct baton_node * node,
    uint8_t address
) 

function on_tx_done

static void on_tx_done (
    struct baton_node * node,
    uint32_t now_ms
) 

function pack

Build the message part of a frame for peer: the outstanding content again, or HIGH events, NORMAL events and dirty states.

static int pack (
    struct baton_node * node,
    uint8_t peer,
    uint8_t * out,
    uint16_t max_length
) 

Returns:

bytes written, 0 when there is nothing to send, -1 when the retransmission does not fit into max_length.


function pack_again

Rebuild the content of the unacknowledged frame (same seq) so the receiver can filter duplicates.

static int pack_again (
    struct baton_node * node,
    uint8_t peer,
    uint8_t * out,
    uint16_t max_length
) 

A state that grew and no longer fits is sent in a later frame.

Returns:

bytes written, 0 when nothing is left (the frame was abandoned), -1 when the events do not fit into max_length.


function pack_events

Take queued events for peer , HIGH first, FIFO within a queue (never skip ahead).

static uint16_t pack_events (
    struct baton_node * node,
    uint8_t peer,
    uint8_t * out,
    uint16_t n,
    uint16_t max_length
) 

Called only when the channel has no outstanding content, so no record has the inflight bit of peer set (a bit is set only together with a channel reference).


function pack_states

Take the dirty states for peer .

static uint16_t pack_states (
    struct baton_node * node,
    uint8_t peer,
    uint8_t * out,
    uint16_t n,
    uint16_t max_length
) 


function queue_reclaim

static void queue_reclaim (
    struct baton_node * node,
    uint8_t qi
) 

function ref_kind

static uint8_t ref_kind (
    uint16_t ref
) 

function ref_make

static uint16_t ref_make (
    uint8_t kind,
    uint16_t value
) 

function ref_value

static uint16_t ref_value (
    uint16_t ref
) 

function rx_content

Deliver the content of a frame unless it is a retransmission that was already delivered.

static void rx_content (
    struct baton_node * node,
    uint8_t src_index,
    uint8_t ctrl,
    const uint8_t * payload,
    uint16_t length
) 


function slave_ack_timeout

static void slave_ack_timeout (
    struct baton_node * node,
    uint32_t now_ms
) 

function slave_budget

Payload bytes a DATA frame may still carry in this slot (time for the RESP is reserved).

static int32_t slave_budget (
    const struct baton_node * node,
    uint32_t now_ms
) 


function slave_on_ack

static void slave_on_ack (
    struct baton_node * node,
    uint8_t src_index,
    uint8_t ctrl,
    uint32_t now_ms
) 

function slave_on_data

static void slave_on_data (
    struct baton_node * node,
    uint8_t src_index,
    const struct baton_frame * frame
) 

function slave_on_poll

static void slave_on_poll (
    struct baton_node * node,
    const struct baton_frame * frame,
    uint32_t now_ms
) 

function slave_send_resp

static void slave_send_resp (
    struct baton_node * node
) 

function slave_slot_step

Continue the slot: DATA to the next peer that has something, else RESP.

static void slave_slot_step (
    struct baton_node * node,
    uint32_t now_ms
) 

Pass 0 serves peers that answered recently, pass 1 the ones that failed before, so an unreachable node cannot eat the slot of the healthy ones.


function slave_tx_data

static int slave_tx_data (
    struct baton_node * node,
    uint8_t peer,
    uint32_t now_ms
) 

Returns:

1 frame requested, 0 nothing for this peer, -1 no time left or it does not fit.


function state_offset

Offset of state s in the mailbox storage.

static uint16_t state_offset (
    uint8_t s
) 


function timing_valid

Timing must allow an ACK and at least one maximum-size exchange per slot.

static bool timing_valid (
    const struct baton_node * node
) 


function topology_valid

Build the node table (0 = master, 1..n = slaves) and find this node in it.

static bool topology_valid (
    struct baton_node * node
) 


function try_emit_state

Copy the current value of state s if it fits below limit ; clear its dirty bits.

static bool try_emit_state (
    struct baton_node * node,
    uint8_t * out,
    uint16_t * n,
    uint16_t limit,
    uint8_t s,
    uint32_t clear_bit
) 


function tx_request

Seal the frame in buffer (payload already at BATON_HEADER_SIZE) and request it.

static void tx_request (
    struct baton_node * node,
    uint8_t * buffer,
    size_t capacity,
    uint8_t dst,
    uint8_t ctrl,
    uint8_t payload_length
) 


function unlock

static void unlock (
    const struct baton_node * node
) 

Macro Definition Documentation

define HOUSEKEEP_PERIOD_MS

Period of the TTL scan.

#define HOUSEKEEP_PERIOD_MS `10U`


define L_IDLE

Link (master/slave) states.

#define L_IDLE `0U`


define M_POLL_TX

#define M_POLL_TX `5U`

define M_WAIT_RESP

#define M_WAIT_RESP `6U`

define NO_NODE

Returned by node_index() for an unknown address.

#define NO_NODE `0xFFU`


define Q_HIGH

Queue indexes; also the kind of a message reference.

#define Q_HIGH `0U`


define Q_NORMAL

#define Q_NORMAL `1U`

define REF_STATE

#define REF_STATE `2U`

define RESP_TIMEOUT_MARGIN_MS

Margin added to the slot time before the master gives up waiting for a RESP.

#define RESP_TIMEOUT_MARGIN_MS `10U`


define STREAK_MAX

Saturation limit of the failure streak counters.

#define STREAK_MAX `255U`


define S_ACK_TX

#define S_ACK_TX `4U`

define S_DATA_TX

#define S_DATA_TX `1U`

define S_RESP_TX

#define S_RESP_TX `3U`

define S_WAIT_ACK

#define S_WAIT_ACK `2U`


The documentation for this class was generated from the following file src/baton_node.c