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