From 3beda7742f4fc87c35a7a92e9cf338cbfbbafe9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Tue, 9 Jul 2019 19:16:23 +0300 Subject: [PATCH] Add randomness to the periodicity of broadcasts --- ethermess.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ethermess.c b/ethermess.c index f59e407..99a6ea8 100644 --- a/ethermess.c +++ b/ethermess.c @@ -30,6 +30,8 @@ #define EMT_STATUS 2 #define EMT_MSGID_REQUEST 3 #define EMT_MSGID 4 +#define EMT_MESSAGE 5 +#define EMT_ACK 6 #define EMS_AVAILABLE 0 #define EMS_UNAVAILABLE 1 @@ -52,6 +54,8 @@ bool own_message_queued = false; unsigned char own_message_destination_mac[6]; unsigned char own_message[1500 - 2 - 2 - 2]; size_t own_message_length = 0; +bool own_message_msgid_known = false; +uint16_t own_message_msgid = 0; struct msgid_cache_entry { unsigned char other_mac[6]; @@ -474,8 +478,8 @@ void eventloop(void) { if (next_status_broadcast <= now) { // The time has come to send the status broadcast send_status(broadcast_mac); - // Do next one in 5 minutes - next_status_broadcast = now + 5 * 60; + // Do next one in about 5 minutes + next_status_broadcast = now + 5 * 60 + random_byte() / 64; } else { if (INT_MAX / 1000 >= next_status_broadcast - now) { // Wail until next status broadcast is due @@ -583,8 +587,8 @@ int main(int argc, char **argv) { // Broadcast our status to the network to let them know we're here send_status(broadcast_mac); - // Schedule next broadcast of our status 5 min in the future - next_status_broadcast = monotonic_time() + 5 * 60; + // Schedule next broadcast of our status about 5 min in the future + next_status_broadcast = monotonic_time() + 5 * 60 + random_byte() / 64; // Request status from everyone, so that we can get an idea of who is on the network send_status_request(broadcast_mac);