]> git.scottworley.com Git - tattlekey/commitdiff
client: New epoch if seq wraps
authorScott Worley <scottworley@scottworley.com>
Tue, 10 Oct 2023 21:48:33 +0000 (14:48 -0700)
committerScott Worley <scottworley@scottworley.com>
Wed, 11 Oct 2023 01:50:37 +0000 (18:50 -0700)
client/net.c
client/net.h
client/tattlekey.c

index fa5d07b257d9f96117d299c169380f7538c549ee..3d4be8cea998f707472740155a601ea912f46001 100644 (file)
@@ -34,7 +34,7 @@ static void net_local_init() {
   if (the_pcb)
     return;
 
   if (the_pcb)
     return;
 
-  epoch = get_rand_32();
+  new_epoch();
 
   the_pcb = udp_new();
   if (!the_pcb)
 
   the_pcb = udp_new();
   if (!the_pcb)
@@ -48,6 +48,8 @@ static void net_local_init() {
     signal_error_by_blinking();
 }
 
     signal_error_by_blinking();
 }
 
+void new_epoch() { epoch = get_rand_32(); }
+
 struct tattle_message_wire_format {
   u32_t epoch;
   u16_t sender;
 struct tattle_message_wire_format {
   u32_t epoch;
   u16_t sender;
index 9b8fc1f7e0043d8a8fff61c35495ee7e859847cd..31e5cc492238be93f60a4e0cfe49fe8067f93ea2 100644 (file)
@@ -22,4 +22,6 @@
 
 void send_report_packet(u16_t seq, u32_t ago);
 
 
 void send_report_packet(u16_t seq, u32_t ago);
 
+void new_epoch();
+
 #endif
 #endif
index f9b74c1c14ebb98bf8f44a0daa8d41d9354a05cb..5e829d1654e608f307923efc6ec10a0ba1ce120d 100644 (file)
@@ -119,6 +119,8 @@ void service_queue() {
     switch (e.type) {
     case NEW_BUTTON_PRESS: {
       add_press(pp, &(press_t){e.buttonpress.timestamp, seq++, 0});
     switch (e.type) {
     case NEW_BUTTON_PRESS: {
       add_press(pp, &(press_t){e.buttonpress.timestamp, seq++, 0});
+      if (seq == 0)
+        new_epoch();
     } break;
     case RESEND_TIME: {
       /* OK, we're awake. Cool. Thanks! (We actually do the sends in the
     } break;
     case RESEND_TIME: {
       /* OK, we're awake. Cool. Thanks! (We actually do the sends in the