Add randomness to the periodicity of broadcasts
This commit is contained in:
parent
87d0b33b3b
commit
3beda7742f
1 changed files with 8 additions and 4 deletions
12
ethermess.c
12
ethermess.c
|
@ -30,6 +30,8 @@
|
||||||
#define EMT_STATUS 2
|
#define EMT_STATUS 2
|
||||||
#define EMT_MSGID_REQUEST 3
|
#define EMT_MSGID_REQUEST 3
|
||||||
#define EMT_MSGID 4
|
#define EMT_MSGID 4
|
||||||
|
#define EMT_MESSAGE 5
|
||||||
|
#define EMT_ACK 6
|
||||||
|
|
||||||
#define EMS_AVAILABLE 0
|
#define EMS_AVAILABLE 0
|
||||||
#define EMS_UNAVAILABLE 1
|
#define EMS_UNAVAILABLE 1
|
||||||
|
@ -52,6 +54,8 @@ bool own_message_queued = false;
|
||||||
unsigned char own_message_destination_mac[6];
|
unsigned char own_message_destination_mac[6];
|
||||||
unsigned char own_message[1500 - 2 - 2 - 2];
|
unsigned char own_message[1500 - 2 - 2 - 2];
|
||||||
size_t own_message_length = 0;
|
size_t own_message_length = 0;
|
||||||
|
bool own_message_msgid_known = false;
|
||||||
|
uint16_t own_message_msgid = 0;
|
||||||
|
|
||||||
struct msgid_cache_entry {
|
struct msgid_cache_entry {
|
||||||
unsigned char other_mac[6];
|
unsigned char other_mac[6];
|
||||||
|
@ -474,8 +478,8 @@ void eventloop(void) {
|
||||||
if (next_status_broadcast <= now) {
|
if (next_status_broadcast <= now) {
|
||||||
// The time has come to send the status broadcast
|
// The time has come to send the status broadcast
|
||||||
send_status(broadcast_mac);
|
send_status(broadcast_mac);
|
||||||
// Do next one in 5 minutes
|
// Do next one in about 5 minutes
|
||||||
next_status_broadcast = now + 5 * 60;
|
next_status_broadcast = now + 5 * 60 + random_byte() / 64;
|
||||||
} else {
|
} else {
|
||||||
if (INT_MAX / 1000 >= next_status_broadcast - now) {
|
if (INT_MAX / 1000 >= next_status_broadcast - now) {
|
||||||
// Wail until next status broadcast is due
|
// 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
|
// Broadcast our status to the network to let them know we're here
|
||||||
send_status(broadcast_mac);
|
send_status(broadcast_mac);
|
||||||
|
|
||||||
// Schedule next broadcast of our status 5 min in the future
|
// Schedule next broadcast of our status about 5 min in the future
|
||||||
next_status_broadcast = monotonic_time() + 5 * 60;
|
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
|
// Request status from everyone, so that we can get an idea of who is on the network
|
||||||
send_status_request(broadcast_mac);
|
send_status_request(broadcast_mac);
|
||||||
|
|
Loading…
Reference in a new issue