]> git.meshlink.io Git - meshlink/blob - src/meshlink_internal.h
Fix filename generation, remove need for meshlink_conf and meshlink_hosts in meshlink...
[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 #include "sptps.h"
31
32 #define MAXSOCKETS 8    /* Probably overkill... */
33
34 typedef struct listen_socket_t {
35         struct io_t tcp;
36         struct io_t udp;
37         sockaddr_t sa;
38         bool bindto;
39 } listen_socket_t;
40
41 typedef enum proxytype_t {
42         PROXY_NONE = 0,
43         PROXY_SOCKS4,
44         PROXY_SOCKS4A,
45         PROXY_SOCKS5,
46         PROXY_HTTP,
47         PROXY_EXEC,
48 } proxytype_t;
49
50 /// A handle for an instance of MeshLink.
51 struct meshlink_handle {
52         char *confbase;
53         char *name;
54
55         meshlink_receive_cb_t receive_cb;
56         meshlink_node_status_cb_t node_status_cb;
57         meshlink_log_cb_t log_cb;
58         meshlink_log_level_t log_level;
59
60         pthread_t thread;
61         event_loop_t loop;
62         listen_socket_t listen_socket[MAXSOCKETS];
63         int listen_sockets;
64
65         struct node_t *self;
66
67         struct splay_tree_t *config;
68         struct splay_tree_t *edges;
69         struct splay_tree_t *nodes;
70
71         struct list_t *connections;
72         struct list_t *outgoings;
73
74         int contradicting_add_edge;
75         int contradicting_del_edge;
76         int sleeptime;
77         time_t last_config_check;
78         timeout_t pingtimer;
79         timeout_t periodictimer;
80
81         char *myport;
82
83         char *proxyhost;
84         char *proxyport;
85         char *proxyuser;
86         char *proxypass;
87         proxytype_t proxytype;
88
89         bool localdiscovery;
90         sockaddr_t localdiscovery_address;
91
92         hash_t *node_udp_cache;
93         struct connection_t *everyone;
94         struct ecdsa *invitation_key;
95
96         debug_t debug_level;
97         int pinginterval;       /* seconds between pings */
98         int pingtimeout;        /* seconds to wait for response */
99         int maxtimeout;
100
101         int sock;
102         sptps_t sptps;
103         char cookie[18], hash[18];
104         char *data;
105         size_t thedatalen;
106         bool success;
107         char line[4096];
108         char buffer[4096];
109         size_t blen;
110 };
111
112 /// A handle for a MeshLink node.
113 struct meshlink_node {
114         const char *name;
115         void *priv;
116 };
117
118 /// Header for data packets routed between nodes
119 typedef struct meshlink_packethdr {
120         uint8_t destination[16];
121         uint8_t source[16];
122 } __attribute__ ((__packed__)) meshlink_packethdr_t;
123
124 #endif // MESHLINK_INTERNAL_H