routent.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * routent.h
  3. * Onion Router and related definitions.
  4. *
  5. * Matej Pfajfar <mp292@cam.ac.uk>
  6. */
  7. /*
  8. * Changes :
  9. * $Log$
  10. * Revision 1.1 2002/06/26 22:45:50 arma
  11. * Initial revision
  12. *
  13. * Revision 1.25 2002/04/02 14:27:11 badbytes
  14. * Final finishes.
  15. *
  16. * Revision 1.24 2002/03/29 09:54:19 badbytes
  17. * Fixed type of routentEX.min_interval to struct timeval.
  18. *
  19. * Revision 1.23 2002/03/21 07:20:59 badbytes
  20. * Added a dependency to <sys/time.h>.
  21. *
  22. * Revision 1.22 2002/03/12 23:37:14 mp292
  23. * Additional flag - destory_buf saying whether the buffer should be destroyed
  24. * when the destroy cell is sent.
  25. *
  26. * Revision 1.21 2002/03/03 00:06:45 mp292
  27. * Modifications to support re-transmission.
  28. *
  29. * Revision 1.20 2002/02/09 16:58:53 mp292
  30. * Postponed implementtion of POLICY_DROP_CONNECTIONS due to problems. Need to
  31. * discuss with Andrei first.
  32. *
  33. * Revision 1.19 2002/02/09 16:54:59 mp292
  34. * routentEX now contains a per anonymous connection packet count
  35. *
  36. * Revision 1.18 2002/01/29 00:59:16 mp292
  37. * Slight changes in the way timers are kept, c.f. changes in the network funnel.
  38. *
  39. * Revision 1.17 2002/01/28 21:37:36 mp292
  40. * Router's output buffer is now dynamic. Time of last output to the router
  41. * added to routentEX.
  42. *
  43. * Revision 1.16 2002/01/26 19:26:55 mp292
  44. * Reviewed according to Secure-Programs-HOWTO.
  45. *
  46. * Revision 1.15 2002/01/18 22:55:40 mp292
  47. * Added a cell buffer to struct routent so that a cell can be received in
  48. * several bursts of data. This prevents a DoS attack on the network funnel.
  49. *
  50. * Revision 1.14 2002/01/14 13:05:37 badbytes
  51. * System testing in progress.
  52. *
  53. * Revision 1.13 2002/01/11 15:47:17 badbytes
  54. * *** empty log message ***
  55. *
  56. * Revision 1.12 2002/01/10 08:28:33 badbytes
  57. * routent and routentEX related routines
  58. *
  59. * Revision 1.11 2002/01/08 15:13:30 badbytes
  60. * Added cipher context to routentEX
  61. *
  62. * Revision 1.10 2002/01/08 13:18:48 badbytes
  63. * Added a connection buffer to routentEX
  64. *
  65. * Revision 1.9 2002/01/08 13:02:16 badbytes
  66. * routentEX now contains f_key and b_key, 56-bit DES keys for link encryption
  67. *
  68. * Revision 1.8 2002/01/03 11:17:01 badbytes
  69. * routentEX.max and routentEX.min values changed to 32bit not 64bit.
  70. *
  71. * Revision 1.7 2002/01/03 11:04:16 badbytes
  72. * *** empty log message ***
  73. *
  74. * Revision 1.6 2002/01/03 11:03:14 badbytes
  75. * Added an extended version of routent which includes link utilisation info.
  76. *
  77. * Revision 1.5 2001/12/18 15:26:34 badbytes
  78. * Added #inclusion of <stdint.h>
  79. *
  80. * Revision 1.4 2001/12/18 15:19:41 badbytes
  81. * In struct routent, changed long and short types to uint32_t and uint16_t
  82. *
  83. * Revision 1.3 2001/12/18 10:37:47 badbytes
  84. * Header files now only apply if they were not previously included from somewhere else.
  85. *
  86. * Revision 1.2 2001/12/17 13:35:17 badbytes
  87. * Still writing handle_connection()
  88. *
  89. * Revision 1.1 2001/12/14 13:14:03 badbytes
  90. * Split types.h into routent.h and ss.h. Keeping them all in one file created unnecesary dependencies.
  91. *
  92. */
  93. #ifndef __ROUTENT_H
  94. #include <openssl/rsa.h>
  95. #include <openssl/evp.h>
  96. #include <stdint.h>
  97. #include <sys/time.h>
  98. #include <time.h>
  99. #include <sys/timeb.h>
  100. #include "cell.h"
  101. /* per-anonymous-connection cell buffer */
  102. typedef struct
  103. {
  104. uint16_t aci;
  105. int policy;
  106. unsigned int cells;
  107. unsigned char *buf;
  108. unsigned int buflen;
  109. unsigned int offset; /* offset to the position of the first cell in the buffer */
  110. cell_t dc; /* static buffer for the destroy cell - so we are always able to destroy a connection */
  111. unsigned char dc_set; /* flag that signifies presence of a destroy cell */
  112. unsigned char destroy_buf; /* flag that signifies that the buffer shuld be destroyed when the destroy cell is sent */
  113. /* POLICY_DROP_CELLS only */
  114. unsigned int win_size; /* window size for the connection (number of cells)*/
  115. unsigned int win_avail; /* available window size */
  116. uint32_t seq_out; /* next sequence number to use for outgoing cells */
  117. uint32_t seq_in; /* next expected sequence number */
  118. uint32_t ack; /* next expected ack/nack */
  119. struct timeval last_ack; /* time of last ACK/NACK */
  120. void *prev;
  121. void *next;
  122. } conn_buf_t;
  123. /* onion router as seen by the onion proxy */
  124. typedef struct
  125. {
  126. char *address;
  127. uint32_t addr; /* address in network byte order */
  128. uint16_t port; /* network port in network byte order */
  129. uint16_t entry_port; /* entry port in network byte order */
  130. RSA *pkey;
  131. void *next;
  132. } routent_t;
  133. /* onion router as seen by other routers */
  134. typedef struct
  135. {
  136. char *address;
  137. uint32_t addr;
  138. uint16_t port;
  139. RSA *pkey; /* public RSA key */
  140. /* 64-bit DES keys for link encryption */
  141. char f_key[8];
  142. char b_key[8];
  143. char f_iv[8];
  144. char b_iv[8];
  145. EVP_CIPHER_CTX f_ctx;
  146. EVP_CIPHER_CTX b_ctx;
  147. /* link info */
  148. uint32_t min;
  149. uint32_t max;
  150. struct timeval min_interval;
  151. /* time when last data was sent to that router */
  152. struct timeval lastsend;
  153. /* socket */
  154. int s;
  155. /* connection buffers */
  156. conn_buf_t *conn_bufs; /* linked list of connection buffers */
  157. conn_buf_t *last_conn_buf; /* last item in the list */
  158. unsigned int next_to_service; /* offset to the connection buffer that is next in turn to be serviced */
  159. /* cell buffer */
  160. unsigned char cellbuf[128];
  161. unsigned int celllen;
  162. void *next;
  163. } routentEX_t;
  164. routentEX_t *id_router(routentEX_t **routerarray, size_t rarray_len, uint32_t addr, uint16_t port);
  165. routentEX_t *id_routerbys(routentEX_t **routerarray, size_t rarray_len, int s);
  166. conn_buf_t *new_conn_buf(uint16_t aci, int policy, conn_buf_t **conn_bufs, conn_buf_t **last_conn_buf);
  167. int remove_conn_buf(conn_buf_t *conn_buf, conn_buf_t **conn_bufs, conn_buf_t **last_conn_buf);
  168. conn_buf_t *id_conn_buf(conn_buf_t *conn_bufs, uint16_t aci);
  169. #define __ROUTENT_H
  170. #endif