X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fmeshlink_internal.h;h=cbb98c6fd07048994f0bf7cae1df7ca52e951690;hb=46e373d99b4559245885c94930a6979d03a6f12b;hp=0e3581f5142fa9354350e1efa6451f88dc6e98a7;hpb=d5112a0a5e7036957f22c604e767e33c4b10b775;p=meshlink diff --git a/src/meshlink_internal.h b/src/meshlink_internal.h index 0e3581f5..cbb98c6f 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 @@ -53,6 +54,7 @@ typedef struct listen_socket_t { struct io_t tcp; struct io_t udp; sockaddr_t sa; + sockaddr_t broadcast_sa; bool bindto; } listen_socket_t; @@ -76,6 +78,15 @@ struct meshlink_open_params { size_t keylen; }; +/// Device class traits +typedef struct { + int pinginterval; + int pingtimeout; + unsigned int min_connects; + unsigned int max_connects; + int edge_weight; +} dev_class_traits_t; + /// A handle for an instance of MeshLink. struct meshlink_handle { // public members @@ -121,12 +132,14 @@ struct meshlink_handle { timeout_t periodictimer; struct connection_t *everyone; + uint64_t prng_state[4]; int next_pit; int pits[10]; // Infrequently used callbacks meshlink_node_status_cb_t node_status_cb; + meshlink_node_pmtu_cb_t node_pmtu_cb; meshlink_channel_accept_cb_t channel_accept_cb; meshlink_node_duplicate_cb_t node_duplicate_cb; meshlink_connection_try_cb_t connection_try_cb; @@ -138,14 +151,14 @@ struct meshlink_handle { struct ecdsa *private_key; struct ecdsa *invitation_key; - int32_t devclass; + dev_class_t devclass; int invitation_timeout; - int pinginterval; /* seconds between pings */ - int pingtimeout; /* seconds to wait for response */ int maxtimeout; int udp_choice; + dev_class_traits_t dev_class_traits[DEV_CLASS_COUNT]; + int netns; bool default_blacklist; @@ -208,9 +221,13 @@ struct meshlink_submesh { /// An AIO buffer. typedef struct meshlink_aio_buffer { const void *data; + int fd; size_t len; size_t done; - meshlink_aio_cb_t cb; + union { + meshlink_aio_cb_t buffer; + meshlink_aio_fd_cb_t fd; + } cb; void *priv; struct meshlink_aio_buffer *next; } meshlink_aio_buffer_t; @@ -221,7 +238,8 @@ struct meshlink_channel { void *priv; struct utcp_connection *c; - meshlink_aio_buffer_t *aio; + meshlink_aio_buffer_t *aio_send; + meshlink_aio_buffer_t *aio_receive; meshlink_channel_receive_cb_t receive_cb; meshlink_channel_poll_cb_t poll_cb; }; @@ -232,21 +250,20 @@ typedef struct meshlink_packethdr { uint8_t source[16]; } __attribute__((__packed__)) meshlink_packethdr_t; -extern void meshlink_send_from_queue(event_loop_t *el, meshlink_handle_t *mesh); +extern void meshlink_send_from_queue(event_loop_t *loop, void *mesh); extern void update_node_status(meshlink_handle_t *mesh, struct node_t *n); +extern void update_node_pmtu(meshlink_handle_t *mesh, struct node_t *n); extern meshlink_log_level_t global_log_level; extern meshlink_log_cb_t global_log_cb; -extern int check_port(meshlink_handle_t *mesh); extern void handle_duplicate_node(meshlink_handle_t *mesh, struct node_t *n); extern void handle_network_change(meshlink_handle_t *mesh, bool online); -/// Device class traits -typedef struct { - unsigned int min_connects; - unsigned int max_connects; - int edge_weight; -} dev_class_traits_t; +/// Per-instance PRNG +static inline int prng(meshlink_handle_t *mesh, uint64_t max) { + return xoshiro(mesh->prng_state) % max; +} -extern const dev_class_traits_t dev_class_traits[]; +/// Fudge value of ~0.1 seconds, in microseconds. +static const unsigned int TIMER_FUDGE = 0x20000; #endif