]> git.meshlink.io Git - meshlink/blob - src/connection.h
Merge branch 'channels'
[meshlink] / src / connection.h
1 /*
2     connection.h -- header for connection.c
3     Copyright (C) 2000-2013 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_CONNECTION_H__
21 #define __MESHLINK_CONNECTION_H__
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                 unsigned int pinged:1;                  /* sent ping */
35                 unsigned int active:1;                  /* 1 if active.. */
36                 unsigned int connecting:1;              /* 1 if we are waiting for a non-blocking connect() to finish */
37                 unsigned int unused_termreq:1;          /* the termination of this connection was requested */
38                 unsigned int remove_unused:1;           /* Set to 1 if you want this connection removed */
39                 unsigned int timeout_unused:1;          /* 1 if gotten timeout */
40                 unsigned int unused_encryptout:1;       /* 1 if we can encrypt outgoing traffic */
41                 unsigned int unused_decryptin:1;        /* 1 if we have to decrypt incoming traffic */
42                 unsigned int mst:1;                     /* 1 if this connection is part of a minimum spanning tree */
43                 unsigned int control:1;                 /* 1 if this is a control connection */
44                 unsigned int pcap:1;                    /* 1 if this is a control connection requesting packet capture */
45                 unsigned int log:1;                     /* 1 if this is a control connection requesting log dump */
46                 unsigned int invitation:1;              /* 1 if this is an invitation */
47                 unsigned int invitation_used:1;         /* 1 if the invitation has been consumed */
48                 unsigned int unused:19;
49 } connection_status_t;
50
51 #include "ecdsa.h"
52 #include "edge.h"
53 #include "net.h"
54 #include "node.h"
55
56 typedef struct connection_t {
57         char *name;                     /* name he claims to have */
58
59         union sockaddr_t address;       /* his real (internet) ip */
60         char *hostname;                 /* the hostname of its real ip */
61         int protocol_major;             /* used protocol */
62         int protocol_minor;             /* used protocol */
63
64         int socket;                     /* socket used for this connection */
65         uint32_t options;               /* options for this connection */
66         connection_status_t status;     /* status info */
67         struct outgoing_t *outgoing;    /* used to keep track of outgoing connections */
68
69         struct meshlink_handle *mesh;   /* the mesh this connection belongs to */
70         struct node_t *node;            /* node associated with the other end */
71         struct edge_t *edge;            /* edge associated with this connection */
72
73         ecdsa_t *ecdsa;                 /* his public ECDSA key */
74         sptps_t sptps;
75
76         int incompression;
77         int outcompression;
78
79         struct buffer_t inbuf;
80         struct buffer_t outbuf;
81         io_t io;                        /* input/output event on this metadata connection */
82         int tcplen;                     /* length of incoming TCPpacket */
83         int allow_request;              /* defined if there's only one request possible */
84
85         time_t last_ping_time;          /* last time we saw some activity from the other end or pinged them */
86
87         splay_tree_t *config_tree;      /* Pointer to configuration tree belonging to him */
88 } connection_t;
89
90 extern void init_connections(struct meshlink_handle *mesh);
91 extern void exit_connections(struct meshlink_handle *mesh);
92 extern connection_t *new_connection(void) __attribute__ ((__malloc__));
93 extern void free_connection(connection_t *);
94 extern void connection_add(struct meshlink_handle *mesh, connection_t *);
95 extern void connection_del(struct meshlink_handle *mesh, connection_t *);
96
97 #endif /* __MESHLINK_CONNECTION_H__ */