]> git.meshlink.io Git - meshlink/blob - src/meshlink_internal.h
Remove global variables from the event loop code.
[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 "sockaddr.h"
30
31 #define MAXSOCKETS 8    /* Probably overkill... */
32
33 typedef struct listen_socket_t {
34         struct io_t tcp;
35         struct io_t udp;
36         sockaddr_t sa;
37         bool bindto;
38 } listen_socket_t;
39
40 typedef enum proxytype_t {
41         PROXY_NONE = 0,
42         PROXY_SOCKS4,
43         PROXY_SOCKS4A,
44         PROXY_SOCKS5,
45         PROXY_HTTP,
46         PROXY_EXEC,
47 } proxytype_t;
48
49 /// A handle for an instance of MeshLink.
50 struct meshlink_handle {
51         char *confbase;
52         char *name;
53
54         meshlink_receive_cb_t receive_cb;
55         meshlink_node_status_cb_t node_status_cb;
56         meshlink_log_cb_t log_cb;
57         meshlink_log_level_t log_level;
58
59         pthread_t thread;
60         event_loop_t loop;
61         listen_socket_t listen_socket[MAXSOCKETS];
62         int listen_sockets;
63
64         struct node_t *self;
65
66         struct splay_tree_t *config;
67         struct splay_tree_t *edges;
68         struct splay_tree_t *nodes;
69
70         struct list_t *connections;
71         struct list_t *outgoings;
72
73         int contradicting_add_edge;
74         int contradicting_del_edge;
75         int sleeptime;
76         time_t last_config_check;
77         timeout_t pingtimer;
78         timeout_t periodictimer;
79
80         char *myport;
81
82         char *proxyhost;
83         char *proxyport;
84         char *proxyuser;
85         char *proxypass;
86         proxytype_t proxytype;
87
88         bool localdiscovery;
89         sockaddr_t localdiscovery_address;
90
91         hash_t *node_udp_cache;
92         struct connection_t *everyone;
93         struct ecdsa *invitation_key;
94
95         debug_t debug_level;
96         int pinginterval;       /* seconds between pings */
97         int pingtimeout;        /* seconds to wait for response */
98         int maxtimeout;
99 };
100
101 /// A handle for a MeshLink node.
102 struct meshlink_node {
103         const char *name;
104         void *priv;
105 };
106
107 // This is a *temporary* global variable which will keep the compiler happy
108 // while refactoring the code to get rid of global variables.
109 // TODO: remove this when no other global variables remain.
110
111 extern meshlink_handle_t *mesh;
112
113 /// Header for data packets routed between nodes
114 typedef struct meshlink_packethdr {
115         uint8_t destination[16];
116         uint8_t source[16];
117 } __attribute__ ((__packed__)) meshlink_packethdr_t;
118
119 #endif // MESHLINK_INTERNAL_H