]> git.meshlink.io Git - meshlink/blob - src/protocol.h
Send our canonical address to nodes we want to communicate with.
[meshlink] / src / protocol.h
1 #ifndef MESHLINK_PROTOCOL_H
2 #define MESHLINK_PROTOCOL_H
3
4 /*
5     protocol.h -- header for protocol.c
6     Copyright (C) 2014, 2017 Guus Sliepen <guus@meshlink.io>
7
8     This program is free software; you can redistribute it and/or modify
9     it under the terms of the GNU General Public License as published by
10     the Free Software Foundation; either version 2 of the License, or
11     (at your option) any later version.
12
13     This program is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17
18     You should have received a copy of the GNU General Public License along
19     with this program; if not, write to the Free Software Foundation, Inc.,
20     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23 #include "ecdsa.h"
24
25 /* Protocol version. Different major versions are incompatible. */
26
27 #define PROT_MAJOR 17
28 #define PROT_MINOR 3 /* Should not exceed 255! */
29
30 /* Silly Windows */
31
32 #ifdef ERROR
33 #undef ERROR
34 #endif
35
36 /* Request numbers */
37
38 typedef enum request_t {
39         ALL = -1, /* Guardian for allow_request */
40         ID = 0, METAKEY, CHALLENGE, CHAL_REPLY, ACK,
41         STATUS, ERROR, TERMREQ,
42         PING, PONG,
43         ADD_SUBNET, DEL_SUBNET,
44         ADD_EDGE, DEL_EDGE,
45         KEY_CHANGED, REQ_KEY, ANS_KEY,
46         PACKET,
47         /* Extended requests */
48         CONTROL,
49         REQ_PUBKEY, ANS_PUBKEY,
50         REQ_SPTPS,
51         REQ_CANONICAL,
52         NUM_REQUESTS
53 } request_t;
54
55 typedef enum request_error_t {
56         NONE = 0,
57         BLACKLISTED = 1,
58 } request_error_t;
59
60 typedef struct past_request_t {
61         const char *request;
62         time_t firstseen;
63 } past_request_t;
64
65 /* Maximum size of strings in a request.
66  * scanf terminates %2048s with a NUL character,
67  * but the NUL character can be written after the 2048th non-NUL character.
68  */
69
70 #define MAX_STRING_SIZE 2049
71 #define MAX_STRING "%2048s"
72
73 #include "edge.h"
74 #include "net.h"
75 #include "node.h"
76
77 /* Basic functions */
78
79 bool send_request(struct meshlink_handle *mesh, struct connection_t *, const struct submesh_t *s, const char *, ...) __attribute__((__format__(printf, 4, 5)));
80 void forward_request(struct meshlink_handle *mesh, struct connection_t *, const struct submesh_t *, const char *);
81 bool receive_request(struct meshlink_handle *mesh, struct connection_t *, const char *);
82 bool check_id(const char *);
83
84 void init_requests(struct meshlink_handle *mesh);
85 void exit_requests(struct meshlink_handle *mesh);
86 bool seen_request(struct meshlink_handle *mesh, const char *);
87
88 /* Requests */
89
90 bool send_id(struct meshlink_handle *mesh, struct connection_t *);
91 bool send_ack(struct meshlink_handle *mesh, struct connection_t *);
92 bool send_error(struct meshlink_handle *mesh, struct connection_t *, request_error_t, const char *);
93 bool send_ping(struct meshlink_handle *mesh, struct connection_t *);
94 bool send_pong(struct meshlink_handle *mesh, struct connection_t *);
95 bool send_add_edge(struct meshlink_handle *mesh, struct connection_t *, const struct edge_t *, int contradictions);
96 bool send_del_edge(struct meshlink_handle *mesh, struct connection_t *, const struct edge_t *, int contradictions);
97 bool send_req_key(struct meshlink_handle *mesh, struct node_t *);
98 bool send_canonical_address(struct meshlink_handle *mesh, struct node_t *);
99
100 /* Request handlers  */
101
102 bool id_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
103 bool ack_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
104 bool status_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
105 bool error_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
106 bool termreq_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
107 bool ping_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
108 bool pong_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
109 bool add_edge_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
110 bool del_edge_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
111 bool key_changed_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
112 bool req_key_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
113 bool ans_key_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
114 bool tcppacket_h(struct meshlink_handle *mesh, struct connection_t *, const char *);
115
116 #endif