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