]> git.meshlink.io Git - meshlink/blob - src/meshlink_internal.h
rename of avahi to catta
[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 "meshlink.h"
28 #include "meshlink_queue.h"
29 #include "sockaddr.h"
30 #include "sptps.h"
31
32 #include <pthread.h>
33
34 #define MAXSOCKETS 8    /* Probably overkill... */
35
36 struct CattaServer;
37 struct CattaSServiceBrowser;
38 struct CattaSimplePoll;
39 struct CattaSEntryGroup;
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 /// A handle for an instance of MeshLink.
58 struct meshlink_handle {
59         char *name;
60         void *priv;
61
62         char *appname;
63         dev_class_t devclass;
64
65         char *confbase;
66
67         meshlink_receive_cb_t receive_cb;
68         meshlink_node_status_cb_t node_status_cb;
69         meshlink_log_cb_t log_cb;
70         meshlink_log_level_t log_level;
71
72         meshlink_channel_accept_cb_t channel_accept_cb;
73
74         pthread_t thread;
75         bool threadstarted;
76         pthread_mutex_t outpacketqueue_mutex;
77         pthread_mutex_t mesh_mutex;
78         event_loop_t loop;
79         listen_socket_t listen_socket[MAXSOCKETS];
80         int listen_sockets;
81         signal_t datafromapp;
82
83         struct node_t *self;
84
85         struct splay_tree_t *config;
86         struct splay_tree_t *edges;
87         struct splay_tree_t *nodes;
88
89         struct list_t *connections;
90         struct list_t *outgoings;
91
92         meshlink_queue_t outpacketqueue;
93
94         struct splay_tree_t *past_request_tree;
95         timeout_t past_request_timeout;
96
97         int contradicting_add_edge;
98         int contradicting_del_edge;
99         int sleeptime;
100         time_t last_config_check;
101         timeout_t pingtimer;
102         timeout_t periodictimer;
103
104         char *myport;
105
106         char *proxyhost;
107         char *proxyport;
108         char *proxyuser;
109         char *proxypass;
110         proxytype_t proxytype;
111
112         bool localdiscovery;
113         sockaddr_t localdiscovery_address;
114
115         bool default_blacklist;
116
117         hash_t *node_udp_cache;
118         struct connection_t *everyone;
119         struct ecdsa *invitation_key;
120
121         int pinginterval;       /* seconds between pings */
122         int pingtimeout;        /* seconds to wait for response */
123         int maxtimeout;
124
125         int sock;
126         sptps_t sptps;
127         char cookie[18], hash[18];
128         char *data;
129         size_t thedatalen;
130         bool success;
131         char line[4096];
132         char buffer[4096];
133         size_t blen;
134
135         pthread_t discovery_thread;
136         bool discovery_threadstarted;
137         struct CattaServer *catta_server;
138         struct CattaSServiceBrowser *catta_browser;
139         struct CattaSimplePoll *catta_poll;
140         struct CattaSEntryGroup *catta_group;
141         char* catta_servicetype;
142 };
143
144 /// A handle for a MeshLink node.
145 struct meshlink_node {
146         const char *name;
147         void *priv;
148 };
149
150 /// A channel.
151 struct meshlink_channel {
152         struct node_t *node;
153         void *priv;
154
155         struct utcp_connection *c;
156         meshlink_channel_receive_cb_t receive_cb;
157         meshlink_channel_poll_cb_t poll_cb;
158 };
159
160 /// Header for data packets routed between nodes
161 typedef struct meshlink_packethdr {
162         uint8_t destination[16];
163         uint8_t source[16];
164 } __attribute__ ((__packed__)) meshlink_packethdr_t;
165
166 extern void meshlink_send_from_queue(event_loop_t* el,meshlink_handle_t *mesh);
167 extern void update_node_status(meshlink_handle_t *mesh, struct node_t *n);
168 extern meshlink_log_level_t global_log_level;
169 extern meshlink_log_cb_t global_log_cb;
170
171 /// Device class traits
172 typedef struct {
173         unsigned int min_connects;
174         unsigned int max_connects;
175         int edge_weight;
176 } dev_class_traits_t;
177
178 extern dev_class_traits_t dev_class_traits[];
179
180 #endif // MESHLINK_INTERNAL_H