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