ascii-chat
Binary v0.16.50-198-g78f51665f
Library lib/v0.3.2-2240-g78f51665f
Video chat in your terminal
Loading...
Searching...
No Matches
coordinator.c File Reference

Ring consensus coordinator implementation. More...

Go to the source code of this file.

Data Structures

struct  consensus_coordinator
 Coordinates consensus work for a session: it tracks the participant topology, election state, callbacks, and messages waiting to be processed. The session owns the coordinator and tears down its queues and synchronization objects with it. More...

Macros

#define NETWORK_CONSENSUS_COORDINATOR_COORDINATOR_NAME_BUFFER_SIZE   64
#define CONSENSUS_ROUND_INTERVAL_NS   (5ULL * 60 * NS_PER_SEC_INT) /* 5 minutes */
#define CONSENSUS_COLLECTION_DEADLINE_NS   (30ULL * NS_PER_SEC_INT) /* 30 seconds */

Typedefs

typedef struct consensus_coordinator consensus_coordinator_t
 Coordinates consensus work for a session: it tracks the participant topology, election state, callbacks, and messages waiting to be processed. The session owns the coordinator and tears down its queues and synchronization objects with it.

Functions

asciichat_error_t consensus_coordinator_create (const uint8_t my_id[SESSION_ID_SIZE], const consensus_topology_t *topology, consensus_election_func_t election_func, void *election_context, consensus_coordinator_t **out_coordinator)
 Initialize coordinator with given parameters.
void consensus_coordinator_destroy (consensus_coordinator_t *coordinator)
 Clean up coordinator resources.
asciichat_error_t consensus_coordinator_process (consensus_coordinator_t *coordinator, uint32_t timeout_ms)
 Main orchestration loop.
asciichat_error_t consensus_coordinator_on_ring_members (consensus_coordinator_t *coordinator, const consensus_topology_t *new_topology)
 Update ring topology when participants change.
asciichat_error_t consensus_coordinator_on_collection_start (consensus_coordinator_t *coordinator, uint32_t round_id, uint64_t deadline_ns)
 Handle STATS_COLLECTION_START packet.
asciichat_error_t consensus_coordinator_on_stats_update (consensus_coordinator_t *coordinator, const uint8_t sender_id[SESSION_ID_SIZE], const participant_metrics_t *metrics, uint8_t num_metrics)
 Handle STATS_UPDATE packet.
asciichat_error_t consensus_coordinator_on_election_result (consensus_coordinator_t *coordinator, const uint8_t host_id[SESSION_ID_SIZE], const uint8_t backup_id[SESSION_ID_SIZE])
 Handle ELECTION_RESULT packet.
asciichat_error_t consensus_coordinator_get_current_host (const consensus_coordinator_t *coordinator, uint8_t out_host_id[SESSION_ID_SIZE], uint8_t out_backup_id[SESSION_ID_SIZE])
 Get currently elected host.
consensus_state_machine_t consensus_coordinator_get_state (const consensus_coordinator_t *coordinator)
 Get current coordinator state.
uint64_t consensus_coordinator_time_until_next_round (const consensus_coordinator_t *coordinator)
 Get time until next round.
int consensus_coordinator_get_metrics_count (const consensus_coordinator_t *coordinator)
 Get count of metrics in current round.
void consensus_coordinator_set_metrics_provider (consensus_coordinator_t *coordinator, consensus_metrics_provider_fn provider, void *context)

Detailed Description

Ring consensus coordinator implementation.

Definition in file coordinator.c.

Macro Definition Documentation

◆ CONSENSUS_COLLECTION_DEADLINE_NS

#define CONSENSUS_COLLECTION_DEADLINE_NS   (30ULL * NS_PER_SEC_INT) /* 30 seconds */

Definition at line 23 of file coordinator.c.

◆ CONSENSUS_ROUND_INTERVAL_NS

#define CONSENSUS_ROUND_INTERVAL_NS   (5ULL * 60 * NS_PER_SEC_INT) /* 5 minutes */

Definition at line 22 of file coordinator.c.

Referenced by consensus_coordinator_time_until_next_round().

◆ NETWORK_CONSENSUS_COORDINATOR_COORDINATOR_NAME_BUFFER_SIZE

#define NETWORK_CONSENSUS_COORDINATOR_COORDINATOR_NAME_BUFFER_SIZE   64

Definition at line 7 of file coordinator.c.

Referenced by consensus_coordinator_create().

Typedef Documentation

◆ consensus_coordinator_t

Coordinates consensus work for a session: it tracks the participant topology, election state, callbacks, and messages waiting to be processed. The session owns the coordinator and tears down its queues and synchronization objects with it.

Opaque consensus coordinator handle.

Coordinates consensus work for a session: it tracks the participant topology, election state, callbacks, and messages waiting to be processed. The session owns the coordinator and tears down its queues and synchronization objects with it.

Function Documentation

◆ consensus_coordinator_create()

asciichat_error_t consensus_coordinator_create ( const uint8_t my_id[SESSION_ID_SIZE],
const consensus_topology_t * topology,
consensus_election_func_t election_func,
void * election_context,
consensus_coordinator_t ** out_coordinator )

Initialize coordinator with given parameters.

Initialize ring consensus coordinator.

Definition at line 56 of file coordinator.c.

57 {
58 if (!my_id || !topology || !election_func || !out_coordinator) {
59 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid parameter: my_id=%p, topology=%p, election_func=%p, out_coordinator=%p", (const void *)my_id, (const void *)topology, (const void *)election_func,
60 (const void *)out_coordinator);
61 }
62
64 if (!coordinator) {
65 return SET_ERRNO(ERROR_MEMORY, "Failed to allocate coordinator");
66 }
67
68 defer_named(release_coordinator, SAFE_FREE(coordinator));
69 memset(coordinator, 0, sizeof(*coordinator));
70 memcpy(coordinator->my_id, my_id, SESSION_ID_SIZE);
71 coordinator->topology = topology;
72 coordinator->election_func = election_func;
73 coordinator->election_context = election_context;
74
75 /* Initialize state machine */
76 asciichat_error_t err = consensus_state_create(my_id, topology, &coordinator->state);
77 if (err != ASCIICHAT_OK) {
78 return err;
79 }
80
81 /* Initialize round scheduling */
82 coordinator->last_round_start_ns = time_get_ns();
83 coordinator->next_round_id = 1;
84 coordinator->has_stored_result = false;
85
86 /* Register coordinator with named registry */
88 snprintf(coordinator_name, sizeof(coordinator_name), "consensus_coordinator:node_%u", my_id[0]);
89 NAMED_REGISTER(coordinator, coordinator_name, "consensus_coordinator_t", "0x%tx", NULL);
90
91 /* Register child state with coordinator as parent */
92 NAMED_REGISTER(coordinator->state, "state", "consensus_state_t", "0x%tx", (uintptr_t)(const void *)(coordinator));
93
94 log_debug("Coordinator created for node %u, first round in 5 minutes", my_id[0]);
95
96 *out_coordinator = coordinator;
97 defer_cancel(release_coordinator);
98 return ASCIICHAT_OK;
99}
#define SET_ERRNO(code,...)
struct consensus_coordinator consensus_coordinator_t
Coordinates consensus work for a session: it tracks the participant topology, election state,...
#define NETWORK_CONSENSUS_COORDINATOR_COORDINATOR_NAME_BUFFER_SIZE
Definition coordinator.c:7
#define SAFE_FREE(ptr)
#define SAFE_MALLOC(size, cast)
#define NAMED_REGISTER(ptr, name, type, fmt, parent_ptr)
Register any pointer with base name, type, format spec, and location (auto-suffix).
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:48
@ ERROR_MEMORY
Definition error_codes.h:55
@ ASCIICHAT_OK
Definition error_codes.h:50
@ ERROR_INVALID_PARAM
#define SESSION_ID_SIZE
#define log_debug(...)
Log a DEBUG message.
Definition log/log.h:589
asciichat_error_t consensus_state_create(const uint8_t my_id[SESSION_ID_SIZE], const consensus_topology_t *topology, consensus_state_t **out_state)
Initialize state machine with topology.
Definition state.c:43
uint64_t last_round_start_ns
Definition coordinator.c:43
const consensus_topology_t * topology
Definition coordinator.c:35
uint8_t my_id[SESSION_ID_SIZE]
Definition coordinator.c:34
consensus_election_func_t election_func
Definition coordinator.c:37
consensus_state_t * state
Definition coordinator.c:36

References ASCIICHAT_OK, consensus_state_create(), consensus_coordinator::election_context, consensus_coordinator::election_func, ERROR_INVALID_PARAM, ERROR_MEMORY, consensus_coordinator::has_stored_result, consensus_coordinator::last_round_start_ns, log_debug, consensus_coordinator::my_id, NAMED_REGISTER, NETWORK_CONSENSUS_COORDINATOR_COORDINATOR_NAME_BUFFER_SIZE, consensus_coordinator::next_round_id, SAFE_FREE, SAFE_MALLOC, SESSION_ID_SIZE, SET_ERRNO, consensus_coordinator::state, and consensus_coordinator::topology.

Referenced by session_consensus_create().

◆ consensus_coordinator_destroy()

void consensus_coordinator_destroy ( consensus_coordinator_t * coordinator)

Clean up coordinator resources.

Destroy coordinator and free resources.

Definition at line 104 of file coordinator.c.

104 {
105 if (!coordinator) {
106 return;
107 }
108 consensus_state_destroy(coordinator->state);
109 SAFE_FREE(coordinator);
110}
void consensus_state_destroy(consensus_state_t *state)
Destroy state machine and free resources.
Definition state.c:66

References consensus_state_destroy(), SAFE_FREE, and consensus_coordinator::state.

Referenced by session_consensus_destroy().

◆ consensus_coordinator_get_current_host()

asciichat_error_t consensus_coordinator_get_current_host ( const consensus_coordinator_t * coordinator,
uint8_t out_host_id[SESSION_ID_SIZE],
uint8_t out_backup_id[SESSION_ID_SIZE] )

Get currently elected host.

Retrieves the host and backup elected in the most recent successful round. If no round has completed yet, returns stored previous result if available, or an error if no result exists.

Parameters
coordinatorCoordinator handle
out_host_idOutput 16-byte host UUID (caller provides buffer)
out_backup_idOutput 16-byte backup UUID (caller provides buffer)
Returns
ASCIICHAT_OK on success, error code otherwise

Definition at line 382 of file coordinator.c.

382 {
383 if (!coordinator || !out_host_id || !out_backup_id) {
384 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid parameter");
385 }
386
387 /* Try to get from current state first */
389 if (current_state == CONSENSUS_STATE_ELECTION_COMPLETE) {
390 asciichat_error_t err = consensus_state_get_elected_host(coordinator->state, out_host_id);
391 if (err == ASCIICHAT_OK) {
392 err = consensus_state_get_elected_backup(coordinator->state, out_backup_id);
393 }
394 if (err == ASCIICHAT_OK) {
395 return ASCIICHAT_OK;
396 }
397 }
398
399 /* Fall back to stored result */
400 if (coordinator->has_stored_result) {
401 memcpy(out_host_id, coordinator->stored_host_id, SESSION_ID_SIZE);
402 memcpy(out_backup_id, coordinator->stored_backup_id, SESSION_ID_SIZE);
403 return ASCIICHAT_OK;
404 }
405
406 return SET_ERRNO(ERROR_INVALID_STATE, "No election result available");
407}
@ ERROR_INVALID_STATE
asciichat_error_t consensus_state_get_elected_backup(const consensus_state_t *state, uint8_t out_backup_id[SESSION_ID_SIZE])
Get elected backup host ID from last election.
Definition state.c:197
asciichat_error_t consensus_state_get_elected_host(const consensus_state_t *state, uint8_t out_host_id[SESSION_ID_SIZE])
Get elected host ID from last election.
Definition state.c:184
consensus_state_machine_t consensus_state_get_current_state(const consensus_state_t *state)
Get current state machine state.
Definition state.c:177
consensus_state_machine_t
State machine lifecycle states.
Definition state.h:23
@ CONSENSUS_STATE_ELECTION_COMPLETE
Definition state.h:30
uint8_t stored_backup_id[SESSION_ID_SIZE]
Definition coordinator.c:49
uint8_t stored_host_id[SESSION_ID_SIZE]
Definition coordinator.c:48

References ASCIICHAT_OK, CONSENSUS_STATE_ELECTION_COMPLETE, consensus_state_get_current_state(), consensus_state_get_elected_backup(), consensus_state_get_elected_host(), ERROR_INVALID_PARAM, ERROR_INVALID_STATE, consensus_coordinator::has_stored_result, SESSION_ID_SIZE, SET_ERRNO, consensus_coordinator::state, consensus_coordinator::stored_backup_id, and consensus_coordinator::stored_host_id.

Referenced by session_consensus_get_elected_host(), and session_consensus_is_ready().

◆ consensus_coordinator_get_metrics_count()

int consensus_coordinator_get_metrics_count ( const consensus_coordinator_t * coordinator)

Get count of metrics in current round.

Get count of metrics collected in current round.

Definition at line 440 of file coordinator.c.

440 {
441 if (!coordinator || !coordinator->state) {
442 return -1;
443 }
444 return consensus_state_get_metrics_count(coordinator->state);
445}
int consensus_state_get_metrics_count(const consensus_state_t *state)
Get count of metrics collected in current round.
Definition state.c:217

References consensus_state_get_metrics_count(), and consensus_coordinator::state.

Referenced by session_consensus_get_metrics_count().

◆ consensus_coordinator_get_state()

consensus_state_machine_t consensus_coordinator_get_state ( const consensus_coordinator_t * coordinator)

Get current coordinator state.

Parameters
coordinatorCoordinator handle
Returns
Current state from internal state machine

Definition at line 412 of file coordinator.c.

412 {
413 if (!coordinator || !coordinator->state) {
415 }
416 return consensus_state_get_current_state(coordinator->state);
417}
@ CONSENSUS_STATE_FAILED
Definition state.h:31

References CONSENSUS_STATE_FAILED, consensus_state_get_current_state(), and consensus_coordinator::state.

Referenced by session_consensus_get_state().

◆ consensus_coordinator_on_collection_start()

asciichat_error_t consensus_coordinator_on_collection_start ( consensus_coordinator_t * coordinator,
uint32_t round_id,
uint64_t deadline_ns )

Handle STATS_COLLECTION_START packet.

Called when receiving a collection start message from the previous ring member. Prepares to collect metrics and transitions state machine.

Parameters
coordinatorCoordinator handle
round_idCollection round ID
deadline_nsUnix nanosecond deadline for this round
Returns
ASCIICHAT_OK on success, error code otherwise

Definition at line 295 of file coordinator.c.

295 {
296 if (!coordinator) {
297 return SET_ERRNO(ERROR_INVALID_PARAM, "Coordinator is NULL");
298 }
299
301 if (current_state != CONSENSUS_STATE_IDLE) {
302 return SET_ERRNO(ERROR_INVALID_STATE, "Cannot start collection, state is %d", current_state);
303 }
304
305 /* Start collection */
307 if (err != ASCIICHAT_OK) {
308 return err;
309 }
310
311 coordinator->next_round_id = round_id;
312 coordinator->collection_deadline_ns = deadline_ns;
313
314 /* Measure and add our metrics */
315 err = measure_and_add_metrics(coordinator);
316 if (err != ASCIICHAT_OK) {
317 log_warn("Failed to measure metrics: %d", err);
318 }
319
320 uint64_t now_ns = time_get_ns();
321 log_dev("Collection started: round_id=%u, deadline in %u seconds", round_id, (unsigned int)((deadline_ns > now_ns ? deadline_ns - now_ns : 0) / NS_PER_SEC_INT));
322
323 return ASCIICHAT_OK;
324}
unsigned long long uint64_t
#define log_warn(...)
Log a WARN message.
Definition log/log.h:615
#define log_dev(...)
Log a DEV message (most verbose, development only).
Definition log/log.h:575
#define NS_PER_SEC_INT
Definition time.h:173
asciichat_error_t consensus_state_start_collection(consensus_state_t *state)
Transition to COLLECTION_START state.
Definition state.c:75
@ CONSENSUS_STATE_IDLE
Definition state.h:24
uint64_t collection_deadline_ns
Definition coordinator.c:45

References ASCIICHAT_OK, consensus_coordinator::collection_deadline_ns, consensus_state_get_current_state(), CONSENSUS_STATE_IDLE, consensus_state_start_collection(), ERROR_INVALID_PARAM, ERROR_INVALID_STATE, log_dev, log_warn, consensus_coordinator::next_round_id, NS_PER_SEC_INT, SET_ERRNO, and consensus_coordinator::state.

Referenced by session_consensus_on_collection_start().

◆ consensus_coordinator_on_election_result()

asciichat_error_t consensus_coordinator_on_election_result ( consensus_coordinator_t * coordinator,
const uint8_t host_id[SESSION_ID_SIZE],
const uint8_t backup_id[SESSION_ID_SIZE] )

Handle ELECTION_RESULT packet.

Called when election result is received from leader. Verifies the election, stores the elected host/backup, and stores for fallback.

Parameters
coordinatorCoordinator handle
host_idElected host UUID
backup_idElected backup UUID
Returns
ASCIICHAT_OK on success, error code otherwise

Definition at line 355 of file coordinator.c.

355 {
356 if (!coordinator || !host_id || !backup_id) {
357 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid parameter");
358 }
359
360 /* Store the elected host and backup */
361 memcpy(coordinator->stored_host_id, host_id, SESSION_ID_SIZE);
362 memcpy(coordinator->stored_backup_id, backup_id, SESSION_ID_SIZE);
363 coordinator->has_stored_result = true;
364
365 log_info("Election result received: host=%u, backup=%u", host_id[0], backup_id[0]);
366
367 /* Transition state back to IDLE */
369 if (current_state == CONSENSUS_STATE_ELECTION_COMPLETE) {
371 if (err != ASCIICHAT_OK) {
372 log_warn("Failed to reset state to IDLE: %d", err);
373 }
374 }
375
376 return ASCIICHAT_OK;
377}
#define log_info(...)
Log an INFO message.
Definition log/log.h:602
asciichat_error_t consensus_state_reset_to_idle(consensus_state_t *state)
Transition back to IDLE from ELECTION_COMPLETE.
Definition state.c:164

References ASCIICHAT_OK, CONSENSUS_STATE_ELECTION_COMPLETE, consensus_state_get_current_state(), consensus_state_reset_to_idle(), ERROR_INVALID_PARAM, consensus_coordinator::has_stored_result, log_info, log_warn, SESSION_ID_SIZE, SET_ERRNO, consensus_coordinator::state, consensus_coordinator::stored_backup_id, and consensus_coordinator::stored_host_id.

Referenced by session_consensus_on_election_result().

◆ consensus_coordinator_on_ring_members()

asciichat_error_t consensus_coordinator_on_ring_members ( consensus_coordinator_t * coordinator,
const consensus_topology_t * new_topology )

Update ring topology when participants change.

Called when the ring topology changes (participants join/leave). Updates internal topology reference and resets any in-progress round.

Parameters
coordinatorCoordinator handle
new_topologyNew topology handle (not owned, must remain valid)
Returns
ASCIICHAT_OK on success, error code otherwise

Definition at line 270 of file coordinator.c.

270 {
271 if (!coordinator || !new_topology) {
272 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid parameter");
273 }
274
275 /* State also borrows the topology while idle. Build a complete replacement
276 * before publishing either pointer so a rejected update leaves both valid. */
277 consensus_state_t *replacement = NULL;
278 asciichat_error_t err = consensus_state_create(coordinator->my_id, new_topology, &replacement);
279 if (err != ASCIICHAT_OK)
280 return err;
282 if (current_state != CONSENSUS_STATE_IDLE)
283 log_warn("Ring topology changed during round, resetting state");
284 consensus_state_destroy(coordinator->state);
285 coordinator->state = replacement;
286 coordinator->topology = new_topology;
287
288 log_info("Ring topology updated");
289 return ASCIICHAT_OK;
290}
struct consensus_state consensus_state_t
State machine instance.

References ASCIICHAT_OK, consensus_state_create(), consensus_state_destroy(), consensus_state_get_current_state(), CONSENSUS_STATE_IDLE, ERROR_INVALID_PARAM, log_info, log_warn, consensus_coordinator::my_id, SET_ERRNO, consensus_coordinator::state, and consensus_coordinator::topology.

Referenced by session_consensus_set_topology().

◆ consensus_coordinator_on_stats_update()

asciichat_error_t consensus_coordinator_on_stats_update ( consensus_coordinator_t * coordinator,
const uint8_t sender_id[SESSION_ID_SIZE],
const participant_metrics_t * metrics,
uint8_t num_metrics )

Handle STATS_UPDATE packet.

Handle STATS_UPDATE packet (metrics relayed from another participant).

Definition at line 329 of file coordinator.c.

329 {
330 if (!coordinator || !sender_id || !metrics) {
331 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid parameter");
332 }
333
335 if (current_state != CONSENSUS_STATE_COLLECTING) {
336 return SET_ERRNO(ERROR_INVALID_STATE, "Cannot accept metrics, state is %d", current_state);
337 }
338
339 /* Add all metrics to state */
340 for (int i = 0; i < num_metrics; i++) {
341 asciichat_error_t err = consensus_state_add_metrics(coordinator->state, &metrics[i]);
342 if (err != ASCIICHAT_OK) {
343 log_warn("Failed to add metric %d: %d", i, err);
344 }
345 }
346
347 log_debug("Received %d metrics from sender %u", num_metrics, sender_id[0]);
348
349 return ASCIICHAT_OK;
350}
asciichat_error_t consensus_state_add_metrics(consensus_state_t *state, const participant_metrics_t *metrics)
Add collected metrics from a participant.
Definition state.c:92
@ CONSENSUS_STATE_COLLECTING
Definition state.h:26

References ASCIICHAT_OK, consensus_state_add_metrics(), CONSENSUS_STATE_COLLECTING, consensus_state_get_current_state(), ERROR_INVALID_PARAM, ERROR_INVALID_STATE, log_debug, log_warn, SESSION_ID_SIZE, SET_ERRNO, and consensus_coordinator::state.

Referenced by session_consensus_on_stats_update().

◆ consensus_coordinator_process()

asciichat_error_t consensus_coordinator_process ( consensus_coordinator_t * coordinator,
uint32_t timeout_ms )

Main orchestration loop.

Main orchestration loop - call periodically.

Definition at line 232 of file coordinator.c.

232 {
233 (void)timeout_ms; /* Currently unused, but kept for future use */
234
235 if (!coordinator) {
236 return SET_ERRNO(ERROR_INVALID_PARAM, "Coordinator is NULL");
237 }
238
239 uint64_t now_ns = time_get_ns();
240
241 /* Check if we should start a new round */
242 if (should_start_new_round(coordinator, now_ns)) {
243 /* Only leader starts rounds */
244 if (consensus_topology_am_leader(coordinator->topology)) {
245 asciichat_error_t err = start_collection_round(coordinator, now_ns);
246 if (err != ASCIICHAT_OK) {
247 log_warn("Failed to start collection round: %d", err);
248 return err;
249 }
250 }
251 }
252
254
255 /* Check for collection timeout */
256 if (current_state == CONSENSUS_STATE_COLLECTING && has_collection_timed_out(coordinator, now_ns)) {
257 log_warn("Collection round timed out, completing early");
258 asciichat_error_t err = complete_collection(coordinator);
259 if (err != ASCIICHAT_OK) {
260 log_error("Failed to complete collection on timeout: %d", err);
261 }
262 }
263
264 return ASCIICHAT_OK;
265}
#define log_error(...)
Log an ERROR message.
Definition log/log.h:628
bool consensus_topology_am_leader(const consensus_topology_t *topology)
Check if I am the ring leader (last position).
Definition topology.c:82

References ASCIICHAT_OK, CONSENSUS_STATE_COLLECTING, consensus_state_get_current_state(), consensus_topology_am_leader(), ERROR_INVALID_PARAM, log_error, log_warn, SET_ERRNO, consensus_coordinator::state, and consensus_coordinator::topology.

Referenced by session_consensus_process().

◆ consensus_coordinator_set_metrics_provider()

void consensus_coordinator_set_metrics_provider ( consensus_coordinator_t * coordinator,
consensus_metrics_provider_fn provider,
void * context )

Definition at line 447 of file coordinator.c.

447 {
448 if (!coordinator)
449 return;
450 coordinator->metrics_provider = provider;
451 coordinator->metrics_context = context;
452}
consensus_metrics_provider_fn metrics_provider
Definition coordinator.c:39

References consensus_coordinator::metrics_context, and consensus_coordinator::metrics_provider.

Referenced by session_consensus_create().

◆ consensus_coordinator_time_until_next_round()

uint64_t consensus_coordinator_time_until_next_round ( const consensus_coordinator_t * coordinator)

Get time until next round.

Get time until next round is due.

Definition at line 422 of file coordinator.c.

422 {
423 if (!coordinator) {
424 return 0;
425 }
426
427 uint64_t now_ns = time_get_ns();
428 uint64_t next_round_ns = coordinator->last_round_start_ns + CONSENSUS_ROUND_INTERVAL_NS;
429
430 if (now_ns >= next_round_ns) {
431 return 0;
432 }
433
434 return next_round_ns - now_ns;
435}
#define CONSENSUS_ROUND_INTERVAL_NS
Definition coordinator.c:22

References CONSENSUS_ROUND_INTERVAL_NS, and consensus_coordinator::last_round_start_ns.

Referenced by session_consensus_time_until_next_round().