]> git.meshlink.io Git - meshlink/blob - src/connection.h
Never automatically try to bind to ports >= 32768.
[meshlink] / src / connection.h
1 #ifndef MESHLINK_CONNECTION_H
2 #define MESHLINK_CONNECTION_H
3
4 /*
5     connection.h -- header for connection.c
6     Copyright (C) 2000-2013, 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 "buffer.h"
24 #include "list.h"
25 #include "sptps.h"
26
27 #define OPTION_INDIRECT         0x0001
28 #define OPTION_TCPONLY          0x0002
29 #define OPTION_PMTU_DISCOVERY   0x0004
30 #define OPTION_CLAMP_MSS        0x0008
31 #define OPTION_VERSION(x) ((x) >> 24) /* Top 8 bits are for protocol minor version */
32
33 typedef struct connection_status_t {
34         uint16_t pinged: 1;                 /* sent ping */
35         uint16_t active: 1;                 /* 1 if active.. */
36         uint16_t connecting: 1;             /* 1 if we are waiting for a non-blocking connect() to finish */
37         uint16_t unused: 1;
38         uint16_t control: 1;                /* 1 if this is a control connection */
39         uint16_t pcap: 1;                   /* 1 if this is a control connection requesting packet capture */
40         uint16_t log: 1;                    /* 1 if this is a control connection requesting log dump */
41         uint16_t invitation: 1;             /* 1 if this is an invitation */
42         uint16_t invitation_used: 1;        /* 1 if the invitation has been consumed */
43         uint16_t initiator: 1;              /* 1 if we initiated this connection */
44         uint16_t raw_packet: 1;             /* 1 if we are expecting a raw packet next */
45 } connection_status_t;
46
47 #include "ecdsa.h"
48 #include "edge.h"
49 #include "net.h"
50 #include "node.h"
51 #include "submesh.h"
52
53 typedef struct connection_t {
54         char *name;                     /* name he claims to have */
55         struct node_t *node;            /* node associated with the other end */
56
57         connection_status_t status;     /* status info */
58         int socket;                     /* socket used for this connection */
59         union sockaddr_t address;       /* his real (internet) ip */
60
61         struct meshlink_handle *mesh;   /* the mesh this connection belongs to */
62
63         // I/O
64         sptps_t sptps;
65         struct buffer_t inbuf;
66         struct buffer_t outbuf;
67         io_t io;                        /* input/output event on this metadata connection */
68         int tcplen;                     /* length of incoming TCPpacket */
69         int allow_request;              /* defined if there's only one request possible */
70         time_t last_ping_time;          /* last time we saw some activity from the other end or pinged them */
71         time_t last_key_renewal;        /* last time we renewed the SPTPS key */
72
73         struct outgoing_t *outgoing;    /* used to keep track of outgoing connections */
74
75         struct edge_t *edge;            /* edge associated with this connection */
76         struct submesh_t *submesh;      /* his submesh handle if available in invitation file */
77
78         // Only used during authentication
79         ecdsa_t *ecdsa;                 /* his public ECDSA key */
80         int protocol_major;             /* used protocol */
81         int protocol_minor;             /* used protocol */
82         uint32_t flags;                 /* used protocol flags */
83 } connection_t;
84
85 void init_connections(struct meshlink_handle *mesh);
86 void exit_connections(struct meshlink_handle *mesh);
87 connection_t *new_connection(void) __attribute__((__malloc__));
88 void free_connection(connection_t *);
89 void connection_add(struct meshlink_handle *mesh, connection_t *);
90 void connection_del(struct meshlink_handle *mesh, connection_t *);
91
92 #endif