]> git.meshlink.io Git - meshlink/blob - src/meshlink_internal.h
Merge branch 'mesh_topology_output' into roles
[meshlink] / src / meshlink_internal.h
1 /*
2     meshlink_internal.h -- Internal parts of the public API.
3     Copyright (C) 2014 Guus Sliepen <guus@meshlink.io>
4
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.
9
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.
14
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.
18 */
19
20 #ifndef MESHLINK_INTERNAL_H
21 #define MESHLINK_INTERNAL_H
22
23 #include "system.h"
24
25 #include "event.h"
26 #include "hash.h"
27 #include "meshlink.h"
28 #include "meshlink_queue.h"
29 #include "sockaddr.h"
30 #include "sptps.h"
31
32 #include <pthread.h>
33
34 #define MAXSOCKETS 8    /* Probably overkill... */
35
36 struct AvahiServer;
37 struct AvahiSServiceBrowser;
38 struct AvahiSimplePoll;
39 struct AvahiSEntryGroup;
40
41 typedef struct listen_socket_t {
42         struct io_t tcp;
43         struct io_t udp;
44         sockaddr_t sa;
45         bool bindto;
46 } listen_socket_t;
47
48 typedef enum proxytype_t {
49         PROXY_NONE = 0,
50         PROXY_SOCKS4,
51         PROXY_SOCKS4A,
52         PROXY_SOCKS5,
53         PROXY_HTTP,
54         PROXY_EXEC,
55 } proxytype_t;
56
57 typedef struct outpacketqueue {
58         meshlink_node_t *destination;
59         const void *data;
60         unsigned int len;
61 } outpacketqueue_t;
62
63 /// A handle for an instance of MeshLink.
64 struct meshlink_handle {
65         char *name;
66         char *appname;
67         dev_class_t devclass;
68         void *priv;
69
70         char *confbase;
71
72         meshlink_receive_cb_t receive_cb;
73         meshlink_node_status_cb_t node_status_cb;
74         meshlink_log_cb_t log_cb;
75         meshlink_log_level_t log_level;
76
77         pthread_t thread;
78         bool threadstarted;
79         pthread_mutex_t outpacketqueue_mutex;
80         pthread_mutex_t mesh_mutex;
81         event_loop_t loop;
82         listen_socket_t listen_socket[MAXSOCKETS];
83         int listen_sockets;
84         signal_t datafromapp;
85
86         struct node_t *self;
87
88         struct splay_tree_t *config;
89         struct splay_tree_t *edges;
90         struct splay_tree_t *nodes;
91
92         struct list_t *connections;
93         struct list_t *outgoings;
94
95         meshlink_queue_t outpacketqueue;
96
97         struct splay_tree_t *past_request_tree;
98         timeout_t past_request_timeout;
99
100         int contradicting_add_edge;
101         int contradicting_del_edge;
102         int sleeptime;
103         time_t last_config_check;
104         timeout_t pingtimer;
105         timeout_t periodictimer;
106
107         char *myport;
108
109         char *proxyhost;
110         char *proxyport;
111         char *proxyuser;
112         char *proxypass;
113         proxytype_t proxytype;
114
115         bool localdiscovery;
116         sockaddr_t localdiscovery_address;
117
118         hash_t *node_udp_cache;
119         struct connection_t *everyone;
120         struct ecdsa *invitation_key;
121
122         int pinginterval;       /* seconds between pings */
123         int pingtimeout;        /* seconds to wait for response */
124         int maxtimeout;
125
126         int sock;
127         sptps_t sptps;
128         char cookie[18], hash[18];
129         char *data;
130         size_t thedatalen;
131         bool success;
132         char line[4096];
133         char buffer[4096];
134         size_t blen;
135
136         pthread_t discovery_thread;
137         bool discovery_threadstarted;
138         struct AvahiServer *avahi_server;
139         struct AvahiSServiceBrowser *avahi_browser;
140         struct AvahiSimplePoll *avahi_poll;
141         struct AvahiSEntryGroup *avahi_group;
142         char* avahi_servicetype;
143 };
144
145 /// A handle for a MeshLink node.
146 struct meshlink_node {
147         const char *name;
148         void *priv;
149 };
150
151 /// Header for data packets routed between nodes
152 typedef struct meshlink_packethdr {
153         uint8_t destination[16];
154         uint8_t source[16];
155 } __attribute__ ((__packed__)) meshlink_packethdr_t;
156
157 extern void meshlink_send_from_queue(event_loop_t* el,meshlink_handle_t *mesh);
158 extern meshlink_log_level_t global_log_level;
159 extern meshlink_log_cb_t global_log_cb;
160
161 /// Device class traits
162 typedef struct {
163         unsigned int min_connects;
164         unsigned int max_connects;
165         int edge_weight;
166 } dev_class_traits_t;
167
168 extern dev_class_traits_t dev_class_traits[];
169
170 #endif // MESHLINK_INTERNAL_H