From: Scott Worley Date: Tue, 10 Oct 2023 09:40:57 +0000 (-0700) Subject: client: Change wire format!: Add epoch X-Git-Tag: v0.1.0~22 X-Git-Url: http://git.scottworley.com/tattlekey/commitdiff_plain/8eacf88f138305f7bb8802367d80fa787d8830c4?ds=sidebyside;hp=9266b741959871619b5431a2b4e4ebdad5567a3d client: Change wire format!: Add epoch This helps the server de-dupe: Records with the same sequence number but different epochs do not describe the same event. --- diff --git a/client/net.c b/client/net.c index 1e0790e..fa5d07b 100644 --- a/client/net.c +++ b/client/net.c @@ -20,6 +20,7 @@ #include "config.h" #include "pico/cyw43_arch.h" +#include "pico/rand.h" #include "lwip/pbuf.h" #include "lwip/udp.h" @@ -27,11 +28,14 @@ /* We only ever send to one address, and we only ever have one thread, so just * use one udp_pcb */ static struct udp_pcb *the_pcb = NULL; +static uint32_t epoch = 0; -static void initialize_the_pcb() { +static void net_local_init() { if (the_pcb) return; + epoch = get_rand_32(); + the_pcb = udp_new(); if (!the_pcb) signal_error_by_blinking(); @@ -45,6 +49,7 @@ static void initialize_the_pcb() { } struct tattle_message_wire_format { + u32_t epoch; u16_t sender; u16_t seq; u32_t ago; @@ -53,7 +58,7 @@ struct tattle_message_wire_format { void send_report_packet(u16_t seq, u32_t ago) { cyw43_arch_lwip_begin(); - initialize_the_pcb(); + net_local_init(); struct pbuf *p = pbuf_alloc( PBUF_TRANSPORT, sizeof(struct tattle_message_wire_format), PBUF_RAM); @@ -62,6 +67,7 @@ void send_report_packet(u16_t seq, u32_t ago) { struct tattle_message_wire_format *msg = (struct tattle_message_wire_format *)(p->payload); + msg->epoch = htonl(epoch); msg->sender = htons(config_this_tattler_identity); msg->seq = htons(seq); msg->ago = htonl(ago);