52#define SEQ_UNSEEN ((time_t)0)
53#define SEQ_EXPIRED ((time_t)1)
64 const struct packet_id_net *pin,
const char *message, uint64_t value)
74#if defined(__GNUC__) || defined(__clang__)
75#pragma GCC diagnostic push
76#pragma GCC diagnostic ignored "-Wsign-conversion"
81 const char *name,
int unit)
99 dmsg(
D_PID_DEBUG,
"PID packet_id_init seq_backtrack=%d time_backtrack=%d", seq_backtrack,
139 const time_t local_now =
now;
160 while (p->
id < pin->
id
161#ifdef PID_SIMULATE_BACKTRACK
170 diff = p->
id - pin->
id;
183#if defined(__GNUC__) || defined(__clang__)
184#pragma GCC diagnostic pop
195 const time_t local_now =
now;
252 const uint64_t diff = p->
id - pin->
id;
300 return !p->
id || pin->
id == p->
id + 1;
327 if (!
buf_read(buf, &net_id,
sizeof(net_id)))
334 if (!
buf_read(buf, &net_time,
sizeof(net_time)))
355 if (!long_form || now <= p->time)
407 if (!
buf_write(buf, &net_id,
sizeof(net_id)))
413 if (!
buf_write(buf, &net_time,
sizeof(net_time)))
448 const time_t prev_now =
now;
449 const struct seq_list *sl = p->
seq_list;
453 gettimeofday(&tv, NULL);
457 for (i = 0; sl != NULL && i < sl->x_size; ++i)
473 const int diff = (int)(prev_now - v);
480 c = (char)(
'0' + diff);
495 buf_printf(&out,
" t=%" PRIi64
"[%d]", (int64_t)prev_now, (
int)(prev_now - tv.tv_sec));
501 buf_printf(&out,
" sl=[%d,%d,%d,%zu]", sl->x_head, sl->x_size, sl->x_cap, sl->x_sizeof);
505 msg(msglevel,
"%s",
BSTR(&out));
523 uint16_t epoch = (uint16_t)(
id >> 48);
540 uint64_t net_id = ((uint64_t)epoch) << 48 | p->
id;
546 return buf_write(buf, &net_id,
sizeof(net_id));
bool buf_printf(struct buffer *buf, const char *format,...)
printf-style append to a buffer with overflow check.
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
Allocate a buffer of the given size under garbage collection.
#define BSTR(buf)
Return the buffer content pointer cast to char *.
static bool buf_write_prepend(struct buffer *dest, const void *src, int size)
Prepend data to a buffer.
static bool buf_read(struct buffer *src, void *dest, int size)
Read bytes from the front of a buffer into a caller-supplied destination.
static bool buf_write(struct buffer *dest, const void *src, size_t size)
Append data to a buffer.
static void gc_free(struct gc_arena *a)
Free all allocations in a garbage collection arena.
static struct gc_arena gc_new(void)
Allocate and return a new, empty garbage collection arena.
#define CIRC_LIST_ALLOC(dest, list_type, size)
#define CIRC_LIST_PUSH(obj, item)
#define CIRC_LIST_ITEM(obj, index)
#define CIRC_LIST_RESET(obj)
#define CIRC_LIST_SIZE(obj)
int64_t get_random(void)
an analogue to the random() function, but use prng_bytes and also int64_t instead of long to avoid LL...
#define D_PID_DEBUG_MEDIUM
static bool check_debug_level(msglvl_t level)
const char * time_string(time_t t, tv_usec_t usec, bool show_usec, struct gc_arena *gc)
static void packet_id_init_recv(struct packet_id_rec *rec, int seq_backtrack, int time_backtrack, const char *name, int unit)
uint16_t packet_id_read_epoch(struct packet_id_net *pin, struct buffer *buf)
Reads the packet ID containing both the epoch and the per-epoch counter from the buf.
void packet_id_init(struct packet_id *p, int seq_backtrack, int time_backtrack, const char *name, int unit)
static void packet_id_debug(msglvl_t msglevel, const struct packet_id_rec *p, const struct packet_id_net *pin, const char *message, uint64_t value)
bool packet_id_write_epoch(struct packet_id_send *p, uint16_t epoch, struct buffer *buf)
Writes the packet ID containing both the epoch and the packet id to the buffer specified by buf.
void packet_id_free(struct packet_id *p)
static bool packet_id_send_update_epoch(struct packet_id_send *p)
bool packet_id_test(struct packet_id_rec *p, const struct packet_id_net *pin)
bool packet_id_read(struct packet_id_net *pin, struct buffer *buf, bool long_form)
static bool packet_id_send_update(struct packet_id_send *p, bool long_form)
void packet_id_move_recv(struct packet_id_rec *dest, struct packet_id_rec *src)
Move the packet id recv structure from src to dest.
void packet_id_reap(struct packet_id_rec *p)
const char * packet_id_net_print(const struct packet_id_net *pin, bool print_timestamp, struct gc_arena *gc)
void packet_id_add(struct packet_id_rec *p, const struct packet_id_net *pin)
static void packet_id_debug_print(msglvl_t msglevel, const struct packet_id_rec *p, const struct packet_id_net *pin, const char *message, packet_id_print_type value)
bool packet_id_write(struct packet_id_send *p, struct buffer *buf, bool long_form, bool prepend)
Write a packet ID to buf, and update the packet ID state.
uint64_t packet_id_print_type
#define MAX_SEQ_BACKTRACK
#define MIN_SEQ_BACKTRACK
#define MAX_TIME_BACKTRACK
#define MIN_TIME_BACKTRACK
#define PACKET_ID_EPOCH_MAX
#define PACKET_ID_MASK
Mask of the bits that contain the 48-bit of the per-epoch packet counter in the packet id.
Wrapper structure for dynamically allocated memory.
int len
Length in bytes of the actual content within the allocated memory.
Garbage collection arena used to keep track of dynamically allocated memory.
Data structure for describing the packet id that is received/send to the network.
uint64_t max_backtrack_stat
struct seq_list * seq_list