35 #elif defined(_MSC_VER) 53 #define SEQ_UNSEEN ((time_t)0) 54 #define SEQ_EXPIRED ((time_t)1) 80 dmsg(
D_PID_DEBUG,
"PID packet_id_init seq_backtrack=%d time_backtrack=%d",
114 const time_t local_now =
now;
137 while (p->
id < pin->
id 138 #ifdef PID_SIMULATE_BACKTRACK
147 diff = p->
id - pin->
id;
169 const time_t local_now =
now;
230 diff = p->
id - pin->
id;
279 return !p->
id || pin->
id == p->
id + 1;
306 if (!
buf_read(buf, &net_id,
sizeof(net_id)))
313 if (!
buf_read(buf, &net_time,
sizeof(net_time)))
334 if (!long_form || now <= p->time)
372 if (!
buf_write(buf, &net_id,
sizeof(net_id)))
378 if (!
buf_write(buf, &net_time,
sizeof(net_time)))
393 if (print_timestamp && pin->
time)
442 "Cannot open --replay-persist file %s for read/write",
450 #if defined(HAVE_FLOCK) && defined(LOCK_EX) && defined(LOCK_NB) 451 if (flock(p->
fd, LOCK_EX | LOCK_NB))
453 msg(
M_ERR,
"Cannot obtain exclusive lock on --replay-persist file %s", filename);
458 n =
read(p->
fd, &image,
sizeof(image));
459 if (n ==
sizeof(image))
469 "Read error on --replay-persist file %s",
491 seek_ret = lseek(p->
fd, (off_t)0, SEEK_SET);
492 if (seek_ret == (off_t)0)
494 n =
write(p->
fd, &image,
sizeof(image));
495 if (n ==
sizeof(image))
505 "Cannot write to --replay-persist file %s",
512 "Cannot seek to beginning of --replay-persist file %s",
549 return (
char *)out.
data;
564 const time_t prev_now =
now;
565 const struct seq_list *sl = p->
seq_list;
569 gettimeofday(&tv, NULL);
573 for (i = 0; sl != NULL && i < sl->x_size; ++i)
590 diff = (int) prev_now - v;
614 (
int)(prev_now - tv.tv_sec));
632 msg(msglevel,
"%s",
BSTR(&out));
641 packet_id_interactive_test(
void)
649 const int seq_backtrack = 10;
650 const int time_backtrack = 10;
657 if (!fgets(buf,
sizeof(buf), stdin))
662 if (sscanf(buf,
"%lu,%u", &pin.
time, &pin.
id) == 2)
677 long_form = (count < 20);
678 packet_id_alloc_outgoing(&pid.
send, &pin, long_form);
void packet_id_persist_init(struct packet_id_persist *p)
void packet_id_persist_load_obj(const struct packet_id_persist *p, struct packet_id *pid)
static void gc_free(struct gc_arena *a)
#define CIRC_LIST_PUSH(obj, item)
void packet_id_persist_close(struct packet_id_persist *p)
#define D_PID_DEBUG_MEDIUM
bool buf_printf(struct buffer *buf, const char *format,...)
packet_id_type id_last_written
bool packet_id_read(struct packet_id_net *pin, struct buffer *buf, bool long_form)
const char * packet_id_persist_print(const struct packet_id_persist *p, struct gc_arena *gc)
#define MIN_TIME_BACKTRACK
static bool check_debug_level(unsigned int level)
void packet_id_free(struct packet_id *p)
static bool buf_read(struct buffer *src, void *dest, int size)
void packet_id_add(struct packet_id_rec *p, const struct packet_id_net *pin)
static bool buf_write(struct buffer *dest, const void *src, int size)
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.
const char * packet_id_net_print(const struct packet_id_net *pin, bool print_timestamp, struct gc_arena *gc)
void packet_id_init(struct packet_id *p, int seq_backtrack, int time_backtrack, const char *name, int unit)
static void packet_id_debug(int msglevel, const struct packet_id_rec *p, const struct packet_id_net *pin, const char *message, int value)
unsigned int packet_id_print_type
static void packet_id_reap_test(struct packet_id_rec *p)
#define CIRC_LIST_ALLOC(dest, list_type, size)
static struct gc_arena gc_new(void)
struct seq_list * seq_list
bool packet_id_test(struct packet_id_rec *p, const struct packet_id_net *pin)
const char * time_string(time_t t, int usec, bool show_usec, struct gc_arena *gc)
#define D_PID_PERSIST_DEBUG
static void packet_id_debug_print(int msglevel, const struct packet_id_rec *p, const struct packet_id_net *pin, const char *message, int value)
struct packet_id_send send
uint8_t * data
Pointer to the allocated memory.
#define MIN_SEQ_BACKTRACK
#define CIRC_LIST_ITEM(obj, index)
#define MAX_SEQ_BACKTRACK
Wrapper structure for dynamically allocated memory.
static bool buf_write_prepend(struct buffer *dest, const void *src, int size)
void packet_id_persist_load(struct packet_id_persist *p, const char *filename)
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
#define CIRC_LIST_RESET(obj)
Garbage collection arena used to keep track of dynamically allocated memory.
static bool packet_id_persist_enabled(const struct packet_id_persist *p)
static bool packet_id_send_update(struct packet_id_send *p, bool long_form)
long int get_random(void)
#define CIRC_LIST_SIZE(obj)
void packet_id_persist_save(struct packet_id_persist *p)
static void update_time(void)
void packet_id_reap(struct packet_id_rec *p)
#define MAX_TIME_BACKTRACK