]> git.meshlink.io Git - meshlink/blob - src/meshlink_internal.h
A first attempt at merging UTCP into 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 #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 typedef struct outpacketqueue {
53         meshlink_node_t *destination;
54         const void *data;
55         unsigned int len;
56 } outpacketqueue_t;
57
58 /// A handle for an instance of MeshLink.
59 struct meshlink_handle {
60         char *confbase;
61         char *name;
62
63         meshlink_receive_cb_t receive_cb;
64         meshlink_node_status_cb_t node_status_cb;
65         meshlink_log_cb_t log_cb;
66         meshlink_log_level_t log_level;
67
68         meshlink_channel_accept_cb_t channel_accept_cb;
69
70         pthread_t thread;
71         bool threadstarted;
72         pthread_mutex_t outpacketqueue_mutex;
73         pthread_mutex_t nodes_mutex;
74         event_loop_t loop;
75         listen_socket_t listen_socket[MAXSOCKETS];
76         int listen_sockets;
77         signal_t datafromapp;
78
79         struct node_t *self;
80
81         struct splay_tree_t *config;
82         struct splay_tree_t *edges;
83         struct splay_tree_t *nodes;
84
85         struct list_t *connections;
86         struct list_t *outgoings;
87
88         struct list_t *outpacketqueue;
89
90         struct splay_tree_t *past_request_tree;
91         timeout_t past_request_timeout;
92
93         int contradicting_add_edge;
94         int contradicting_del_edge;
95         int sleeptime;
96         time_t last_config_check;
97         timeout_t pingtimer;
98         timeout_t periodictimer;
99
100         char *myport;
101
102         char *proxyhost;
103         char *proxyport;
104         char *proxyuser;
105         char *proxypass;
106         proxytype_t proxytype;
107
108         bool localdiscovery;
109         sockaddr_t localdiscovery_address;
110
111         hash_t *node_udp_cache;
112         struct connection_t *everyone;
113         struct ecdsa *invitation_key;
114
115         debug_t debug_level;
116         int pinginterval;       /* seconds between pings */
117         int pingtimeout;        /* seconds to wait for response */
118         int maxtimeout;
119
120         int sock;
121         sptps_t sptps;
122         char cookie[18], hash[18];
123         char *data;
124         size_t thedatalen;
125         bool success;
126         char line[4096];
127         char buffer[4096];
128         size_t blen;
129 };
130
131 /// A handle for a MeshLink node.
132 struct meshlink_node {
133         const char *name;
134         void *priv;
135 };
136
137 /// A channel.
138 struct meshlink_channel {
139         struct utcp_connection *c;
140         struct node_t *node;
141         meshlink_channel_receive_cb_t receive_cb;
142 };
143
144 /// Header for data packets routed between nodes
145 typedef struct meshlink_packethdr {
146         uint8_t destination[16];
147         uint8_t source[16];
148 } __attribute__ ((__packed__)) meshlink_packethdr_t;
149
150 extern void meshlink_send_from_queue(event_loop_t* el,meshlink_handle_t *mesh);
151
152
153 #endif // MESHLINK_INTERNAL_H