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