connection.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. connection.h -- header for connection.c
  3. Copyright (C) 2000-2002 Guus Sliepen <guus@sliepen.warande.net>,
  4. 2000-2002 Ivo Timmermans <itimmermans@bigfoot.com>
  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. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. $Id: connection.h,v 1.1.2.24 2002/02/10 21:57:53 guus Exp $
  17. */
  18. #ifndef __TINC_CONNECTION_H__
  19. #define __TINC_CONNECTION_H__
  20. #include <sys/time.h>
  21. #include <avl_tree.h>
  22. #include <list.h>
  23. #ifdef HAVE_OPENSSL_EVP_H
  24. # include <openssl/evp.h>
  25. #else
  26. # include <evp.h>
  27. #endif
  28. #ifdef HAVE_OPENSSL_RSA_H
  29. # include <openssl/rsa.h>
  30. #else
  31. # include <rsa.h>
  32. #endif
  33. #include "net.h"
  34. #include "conf.h"
  35. #include "node.h"
  36. #include "edge.h"
  37. #define OPTION_INDIRECT 0x0001
  38. #define OPTION_TCPONLY 0x0002
  39. typedef struct connection_status_t {
  40. int pinged:1; /* sent ping */
  41. int active:1; /* 1 if active.. */
  42. int termreq:1; /* the termination of this connection was requested */
  43. int remove:1; /* Set to 1 if you want this connection removed */
  44. int timeout:1; /* 1 if gotten timeout */
  45. int encryptout:1; /* 1 if we can encrypt outgoing traffic */
  46. int decryptin:1; /* 1 if we have to decrypt incoming traffic */
  47. int mst:1; /* 1 if this connection is part of a minimum spanning tree */
  48. int unused:18;
  49. } connection_status_t;
  50. typedef struct connection_t {
  51. char *name; /* name he claims to have */
  52. ipv4_t address; /* his real (internet) ip */
  53. port_t port; /* port number of meta connection */
  54. char *hostname; /* the hostname of its real ip */
  55. int protocol_version; /* used protocol */
  56. int socket; /* socket used for this connection */
  57. long int options; /* options for this connection */
  58. struct connection_status_t status; /* status info */
  59. int estimated_weight; /* estimation for the weight of the edge for this connection */
  60. struct timeval start; /* time this connection was started, used for above estimation */
  61. struct outgoing_t *outgoing; /* used to keep track of outgoing connections */
  62. struct node_t *node; /* node associated with the other end */
  63. struct edge_t *edge; /* edge associated with this connection */
  64. RSA *rsa_key; /* his public/private key */
  65. EVP_CIPHER *incipher; /* Cipher he will use to send data to us */
  66. EVP_CIPHER *outcipher; /* Cipher we will use to send data to him */
  67. EVP_CIPHER_CTX *inctx; /* Context of encrypted meta data that will come from him to us */
  68. EVP_CIPHER_CTX *outctx; /* Context of encrypted meta data that will be sent from us to him */
  69. char *inkey; /* His symmetric meta key + iv */
  70. char *outkey; /* Our symmetric meta key + iv */
  71. int inkeylength; /* Length of his key + iv */
  72. int outkeylength; /* Length of our key + iv */
  73. char *mychallenge; /* challenge we received from him */
  74. char *hischallenge; /* challenge we sent to him */
  75. char buffer[MAXBUFSIZE]; /* metadata input buffer */
  76. int buflen; /* bytes read into buffer */
  77. int tcplen; /* length of incoming TCPpacket */
  78. int allow_request; /* defined if there's only one request possible */
  79. time_t last_ping_time; /* last time we saw some activity from the other end */
  80. avl_tree_t *config_tree; /* Pointer to configuration tree belonging to him */
  81. } connection_t;
  82. extern avl_tree_t *connection_tree;
  83. extern void init_connections(void);
  84. extern void exit_connections(void);
  85. extern connection_t *new_connection(void);
  86. extern void free_connection(connection_t *);
  87. extern void connection_add(connection_t *);
  88. extern void connection_del(connection_t *);
  89. extern connection_t *lookup_connection(ipv4_t, short unsigned int);
  90. extern void dump_connections(void);
  91. extern int read_connection_config(connection_t *);
  92. #endif /* __TINC_CONNECTION_H__ */