2 meshlink_internal.h -- Internal parts of the public API.
3 Copyright (C) 2014 Guus Sliepen <guus@meshlink.io>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #ifndef MESHLINK_INTERNAL_H
21 #define MESHLINK_INTERNAL_H
28 #include "meshlink_queue.h"
34 #define MAXSOCKETS 8 /* Probably overkill... */
37 struct AvahiSServiceBrowser;
38 struct AvahiSimplePoll;
39 struct AvahiSEntryGroup;
41 typedef struct listen_socket_t {
48 typedef enum proxytype_t {
57 /// A handle for an instance of MeshLink.
58 struct meshlink_handle {
67 meshlink_receive_cb_t receive_cb;
68 meshlink_node_status_cb_t node_status_cb;
69 meshlink_log_cb_t log_cb;
70 meshlink_log_level_t log_level;
72 meshlink_channel_accept_cb_t channel_accept_cb;
76 pthread_mutex_t outpacketqueue_mutex;
77 pthread_mutex_t mesh_mutex;
79 listen_socket_t listen_socket[MAXSOCKETS];
85 struct splay_tree_t *config;
86 struct splay_tree_t *edges;
87 struct splay_tree_t *nodes;
89 struct list_t *connections;
90 struct list_t *outgoings;
92 meshlink_queue_t outpacketqueue;
94 struct splay_tree_t *past_request_tree;
95 timeout_t past_request_timeout;
97 int contradicting_add_edge;
98 int contradicting_del_edge;
100 time_t last_config_check;
102 timeout_t periodictimer;
110 proxytype_t proxytype;
113 sockaddr_t localdiscovery_address;
115 hash_t *node_udp_cache;
116 struct connection_t *everyone;
117 struct ecdsa *invitation_key;
119 int pinginterval; /* seconds between pings */
120 int pingtimeout; /* seconds to wait for response */
125 char cookie[18], hash[18];
133 pthread_t discovery_thread;
134 bool discovery_threadstarted;
135 struct AvahiServer *avahi_server;
136 struct AvahiSServiceBrowser *avahi_browser;
137 struct AvahiSimplePoll *avahi_poll;
138 struct AvahiSEntryGroup *avahi_group;
139 char* avahi_servicetype;
142 /// A handle for a MeshLink node.
143 struct meshlink_node {
149 struct meshlink_channel {
153 struct utcp_connection *c;
154 meshlink_channel_receive_cb_t receive_cb;
157 /// Header for data packets routed between nodes
158 typedef struct meshlink_packethdr {
159 uint8_t destination[16];
161 } __attribute__ ((__packed__)) meshlink_packethdr_t;
163 extern void meshlink_send_from_queue(event_loop_t* el,meshlink_handle_t *mesh);
164 extern void update_node_status(meshlink_handle_t *mesh, struct node_t *n);
165 extern meshlink_log_level_t global_log_level;
166 extern meshlink_log_cb_t global_log_cb;
168 /// Device class traits
170 unsigned int min_connects;
171 unsigned int max_connects;
173 } dev_class_traits_t;
175 extern dev_class_traits_t dev_class_traits[];
177 #endif // MESHLINK_INTERNAL_H