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 10UPeriod of the TTL scan. |
| define | L_IDLE 0ULink (master/slave) states. |
| define | M_POLL_TX 5U |
| define | M_WAIT_RESP 6U |
| define | NO_NODE 0xFFUReturned by node_index() for an unknown address. |
| define | Q_HIGH 0UQueue indexes; also the kind of a message reference. |
| define | Q_NORMAL 1U |
| define | REF_STATE 2U |
| define | RESP_TIMEOUT_MARGIN_MS 10UMargin added to the slot time before the master gives up waiting for a RESP. |
| define | STREAK_MAX 255USaturation 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¶
Public Static Functions Documentation¶
function chan_abandon¶
The content of the outstanding frame was abandoned: the next content uses a new seq.
function chan_commit¶
Acknowledged: release all messages of the outstanding frame for this peer.
function chan_drop_ref¶
Remove an expired event from the outstanding frame of peer (its inflight bit is set).
function chan_remove_at¶
function config_valid¶
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¶
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¶
function frame_ms¶
function handle_frame¶
static void handle_frame (
struct baton_node * node,
const struct baton_frame * frame,
uint32_t now_ms
)
function housekeeping¶
function link_service¶
function lock¶
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¶
function master_send_poll¶
function master_service¶
function min_slot_ms¶
Shortest slot in which a slave can still send one maximum-size message.
function msg_max_length¶
Maximum length of a known message (state or event), -1 for an unknown id.
function node_bit¶
function node_index¶
function on_tx_done¶
function pack¶
Build the message part of a frame for peer: the outstanding content again, or HIGH events, NORMAL events and dirty states.
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¶
function ref_kind¶
function ref_make¶
function ref_value¶
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¶
function slave_budget¶
Payload bytes a DATA frame may still carry in this slot (time for the RESP is reserved).
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¶
function slave_slot_step¶
Continue the slot: DATA to the next peer that has something, else RESP.
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¶
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.
function timing_valid¶
Timing must allow an ACK and at least one maximum-size exchange per slot.
function topology_valid¶
Build the node table (0 = master, 1..n = slaves) and find this node in it.
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¶
Macro Definition Documentation¶
define HOUSEKEEP_PERIOD_MS¶
Period of the TTL scan.
define L_IDLE¶
Link (master/slave) states.
define M_POLL_TX¶
define M_WAIT_RESP¶
define NO_NODE¶
Returned by node_index() for an unknown address.
define Q_HIGH¶
Queue indexes; also the kind of a message reference.
define Q_NORMAL¶
define REF_STATE¶
define RESP_TIMEOUT_MARGIN_MS¶
Margin added to the slot time before the master gives up waiting for a RESP.
define STREAK_MAX¶
Saturation limit of the failure streak counters.
define S_ACK_TX¶
define S_DATA_TX¶
define S_RESP_TX¶
define S_WAIT_ACK¶
The documentation for this class was generated from the following file src/baton_node.c