More updates to new node/vertex/connection combo.
[tinc] / src / connection.h
1 /*
2     connection.h -- header for connection.c
3     Copyright (C) 2000,2001 Guus Sliepen <guus@sliepen.warande.net>,
4                   2000,2001 Ivo Timmermans <itimmermans@bigfoot.com>
5
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20     $Id: connection.h,v 1.1.2.16 2001/10/10 20:35:10 guus Exp $
21 */
22
23 #ifndef __TINC_CONNECTION_H__
24 #define __TINC_CONNECTION_H__
25
26 #include <avl_tree.h>
27 #include <list.h>
28
29 #include "config.h"
30
31 #ifdef HAVE_OPENSSL_EVP_H
32 # include <openssl/evp.h>
33 #else
34 # include <evp.h>
35 #endif
36
37 #ifdef HAVE_OPENSSL_RSA_H
38 # include <openssl/rsa.h>
39 #else
40 # include <rsa.h>
41 #endif
42
43 #include "net.h"
44 #include "conf.h"
45
46 #include "node.h"
47 #include "vertex.h"
48
49 typedef struct status_bits_t {
50   int pinged:1;                    /* sent ping */
51   int meta:1;                      /* meta connection exists */
52   int active:1;                    /* 1 if active.. */
53   int outgoing:1;                  /* I myself asked for this conn */
54   int termreq:1;                   /* the termination of this connection was requested */
55   int remove:1;                    /* Set to 1 if you want this connection removed */
56   int timeout:1;                   /* 1 if gotten timeout */
57   int validkey:1;                  /* 1 if we currently have a valid key for him */
58   int waitingforkey:1;             /* 1 if we already sent out a request */
59   int dataopen:1;                  /* 1 if we have a valid UDP connection open */
60   int encryptout:1;                /* 1 if we can encrypt outgoing traffic */
61   int decryptin:1;                 /* 1 if we have to decrypt incoming traffic */
62   int unused:18;
63 } status_bits_t;
64
65 #define OPTION_INDIRECT         0x0001
66 #define OPTION_TCPONLY          0x0002
67
68 typedef struct connection_t {
69   ipv4_t address;                  /* his real (internet) ip */
70   short unsigned int port;         /* port number of meta connection */
71   char *hostname;                  /* the hostname of its real ip */
72   int protocol_version;            /* used protocol */
73
74   int socket;                      /* socket used for this connection */
75   long int options;                /* options for this connection */
76   status_bits_t status;            /* status info */
77
78   struct node_t *node;             /* node associated with the other end */
79   struct vertex_t *vertex;         /* vertex associated with this connection */
80
81   RSA *rsa_key;                    /* his public/private key */
82   EVP_CIPHER *incipher;            /* Cipher he will use to send data to us */
83   EVP_CIPHER *outcipher;           /* Cipher we will use to send data to him */
84   EVP_CIPHER_CTX *inctx;           /* Context of encrypted meta data that will come from him to us */
85   EVP_CIPHER_CTX *outctx;          /* Context of encrypted meta data that will be sent from us to him */
86   char *inkey;                     /* His symmetric meta key + iv */
87   char *outkey;                    /* Our symmetric meta key + iv */
88   int inkeylength;                 /* Length of his key + iv */
89   int outkeylength;                /* Length of our key + iv */
90   char *mychallenge;               /* challenge we received from him */
91   char *hischallenge;              /* challenge we sent to him */
92
93   char buffer[MAXBUFSIZE];         /* metadata input buffer */
94   int buflen;                      /* bytes read into buffer */
95   int tcplen;                      /* length of incoming TCPpacket */
96   int allow_request;               /* defined if there's only one request possible */
97
98   time_t last_ping_time;           /* last time we saw some activity from the other end */
99 } connection_t;
100
101 extern avl_tree_t *connection_tree;
102
103 #endif /* __TINC_CONNECTION_H__ */