]> git.meshlink.io Git - meshlink/blob - src/libmeshlink.h
471a90db0b5185afc10f393ad6b9348918379daa
[meshlink] / src / libmeshlink.h
1 /*
2     libmeshlink.h -- Tincd Library
3     Copyright (C) 2014 Guus Sliepen <guus@meshlink.io> Saverio Proto <zioproto@gmail.com>
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 #include "system.h"
21 #include "node.h"
22 //#include "tincctl.h"
23 #include "xalloc.h"
24 #include "logger.h"
25 #include "route.h"
26
27 typedef void (*recvdata_cb_t)(void *data);
28 void recvdata_register_cb(recvdata_cb_t cb);
29
30 extern recvdata_cb_t recv_callback;
31
32 extern char *hosts_dir;
33 extern FILE *fopenmask(const char *filename, const char *mode, mode_t perms);
34
35 extern int check_port(const char *name);
36
37 void *tinc_main_thread(void * in);
38
39 /* OLD: tinc_configuration_t provides all information required to setup "/etc/tinc"
40 I think tinc_setup() should basically do what cmd_init() from src/tincctl.c does, except it doesn't have to generate a tinc-up script.
41 */
42 bool tinc_setup(const char* confbase, const char* name);
43
44 bool tinc_start(const char* path);
45
46 bool tinc_stop();
47
48 typedef struct tincpackethdr {
49   u_int8_t destination[16];
50   u_int8_t source[16];
51 } __attribute__ ((__packed__)) tincpackethdr;
52
53 // can be called from any thread
54 bool tinc_send_packet(node_t *receiver, const char* buf, unsigned int len);
55
56 // handler runs in tinc thread and should return immediately
57 bool tinc_set_packet_receive_handler(void (*handler)(const char* sender, const char* buf, unsigned int len));
58
59
60 //It might also be a good idea to add the option of looking up hosts by public
61 //key (fingerprints) instead of names.
62
63 node_t *tinc_get_host(const char *name);
64
65 bool tinc_get_hosts(node_t** hosts);
66 //This tinc_host_t is redundant because node_t should be ok
67 /*
68 struct tinc_host_t
69 {
70     char* name;
71     sockaddr_t address;
72     char *hostname;
73     char *fingerprint;
74     unsigned int maxpacketsize;
75     //TODO: anything else?
76 }
77 */
78 bool tinc_sign(const char* payload, unsigned int len, const char** signature);
79
80 int tinc_verify(const char* sender, const char* payload, unsigned int plen, const char* signature, unsigned int slen);
81
82 /*
83 TODO: It would be good to add a void pointer here that will be passed on to the
84 handler function whenever it is called, or have a void pointer in node_t
85 that can be filled in by the application. That way, you can easily link an
86 application-specific data structure to a node_t.
87 */
88 void channel_set_packet_send_handler(int (*handler)(const char* receiver, const char* buf, unsigned int len));
89 void channel_packet_receive_handler(const char* sender, const char* buf, unsigned int len);
90
91 bool channel_open(const char* partner, void(*read)(int id, const char* buf, unsigned int len), void(*result)(int result, int id));
92 void channel_close(int id);
93 bool channel_write(int id, const char* buf, unsigned int len, void(*result)(int result, int id, unsigned int written));
94
95
96 //We do need some more functions. First of all, we need to be able to add nodes
97 //to a VPN. To do that, either an invitation protocol should be used:
98
99 bool tinc_join_network(const char *invitation);
100 const char *tinc_generate_invitation(const char *name);
101
102 /*
103 Or two nodes should exchange some information (their name, address, public
104 key). If the application provides a way to exchange some data with another
105 node, then:
106 */
107
108 bool tinc_export(char *buf, size_t *len);
109 node_t *tinc_import(const char *buf, size_t len);
110 /*
111 Last but not least, some way to get rid of unwanted nodes. Simplest is a
112 function that just blacklists a node.
113 Which should immediately cause the local tincd to ignore any data from that
114 host from that point on. Of course, a somewhat centrally managed,
115 automatically distributed blacklist or whitelist would be the next step.
116 */
117 bool tinc_blacklist(node_t *host);
118
119
120
121