X-Git-Url: http://git.meshlink.io/?p=meshlink;a=blobdiff_plain;f=src%2Fmeshlink_internal.h;h=f32e87e65b18a20959b26dcd1404fc4a46473437;hp=a856180686de947c494e164ab47252a58aafb4cd;hb=ea20fcfcded669ce8fbbda3a1f93f354ed254603;hpb=ac63b6adaf29c4143f9e106039011b9ebeb96b93 diff --git a/src/meshlink_internal.h b/src/meshlink_internal.h index a8561806..f32e87e6 100644 --- a/src/meshlink_internal.h +++ b/src/meshlink_internal.h @@ -32,6 +32,7 @@ #include "meshlink_queue.h" #include "sockaddr.h" #include "sptps.h" +#include "xoshiro.h" #include @@ -130,6 +131,7 @@ struct meshlink_handle { timeout_t periodictimer; struct connection_t *everyone; + uint64_t prng_state[4]; int next_pit; int pits[10]; @@ -255,4 +257,12 @@ extern meshlink_log_cb_t global_log_cb; extern void handle_duplicate_node(meshlink_handle_t *mesh, struct node_t *n); extern void handle_network_change(meshlink_handle_t *mesh, bool online); +/// Per-instance PRNG +static inline int prng(meshlink_handle_t *mesh, uint64_t max) { + return xoshiro(mesh->prng_state) % max; +} + +/// Fudge value of ~0.1 seconds, in microseconds. +static const unsigned int TIMER_FUDGE = 0x20000; + #endif