summaryrefslogtreecommitdiff
path: root/src/common/routent.h
blob: 6a905a9bb7b6f0f12a0d1195160ac97956333f4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*
 * routent.h
 * Onion Router and related definitions.
 * 
 * Matej Pfajfar <mp292@cam.ac.uk>
 */

/*
 * Changes :
 * $Log$
 * Revision 1.1  2002/06/26 22:45:50  arma
 * Initial revision
 *
 * Revision 1.25  2002/04/02 14:27:11  badbytes
 * Final finishes.
 *
 * Revision 1.24  2002/03/29 09:54:19  badbytes
 * Fixed type of routentEX.min_interval to struct timeval.
 *
 * Revision 1.23  2002/03/21 07:20:59  badbytes
 * Added a dependency to <sys/time.h>.
 *
 * Revision 1.22  2002/03/12 23:37:14  mp292
 * Additional flag - destory_buf saying whether the buffer should be destroyed
 * when the destroy cell is sent.
 *
 * Revision 1.21  2002/03/03 00:06:45  mp292
 * Modifications to support re-transmission.
 *
 * Revision 1.20  2002/02/09 16:58:53  mp292
 * Postponed implementtion of POLICY_DROP_CONNECTIONS due to problems. Need to
 * discuss with Andrei first.
 *
 * Revision 1.19  2002/02/09 16:54:59  mp292
 * routentEX now contains a per anonymous connection packet count
 *
 * Revision 1.18  2002/01/29 00:59:16  mp292
 * Slight changes in the way timers are kept, c.f. changes in the network funnel.
 *
 * Revision 1.17  2002/01/28 21:37:36  mp292
 * Router's output buffer is now dynamic. Time of last output to the router
 * added to routentEX.
 *
 * Revision 1.16  2002/01/26 19:26:55  mp292
 * Reviewed according to Secure-Programs-HOWTO.
 *
 * Revision 1.15  2002/01/18 22:55:40  mp292
 * Added a cell buffer to struct routent so that a cell can be received in
 * several bursts of data. This prevents a DoS attack on the network funnel.
 *
 * Revision 1.14  2002/01/14 13:05:37  badbytes
 * System testing in progress.
 *
 * Revision 1.13  2002/01/11 15:47:17  badbytes
 * *** empty log message ***
 *
 * Revision 1.12  2002/01/10 08:28:33  badbytes
 * routent and routentEX related routines
 *
 * Revision 1.11  2002/01/08 15:13:30  badbytes
 * Added cipher context to routentEX
 *
 * Revision 1.10  2002/01/08 13:18:48  badbytes
 * Added a connection buffer to routentEX
 *
 * Revision 1.9  2002/01/08 13:02:16  badbytes
 * routentEX now contains f_key and b_key, 56-bit DES keys for link encryption
 *
 * Revision 1.8  2002/01/03 11:17:01  badbytes
 * routentEX.max and routentEX.min values changed to 32bit not 64bit.
 *
 * Revision 1.7  2002/01/03 11:04:16  badbytes
 * *** empty log message ***
 *
 * Revision 1.6  2002/01/03 11:03:14  badbytes
 * Added an extended version of routent which includes link utilisation info.
 *
 * Revision 1.5  2001/12/18 15:26:34  badbytes
 * Added #inclusion of <stdint.h>
 *
 * Revision 1.4  2001/12/18 15:19:41  badbytes
 * In struct routent, changed long and short types to uint32_t and uint16_t
 *
 * Revision 1.3  2001/12/18 10:37:47  badbytes
 * Header files now only apply if they were not previously included from somewhere else.
 *
 * Revision 1.2  2001/12/17 13:35:17  badbytes
 * Still writing handle_connection()
 *
 * Revision 1.1  2001/12/14 13:14:03  badbytes
 * Split types.h into routent.h and ss.h. Keeping them all in one file created unnecesary dependencies.
 *
 */

#ifndef __ROUTENT_H
#include <openssl/rsa.h>
#include <openssl/evp.h>
#include <stdint.h>
#include <sys/time.h>
#include <time.h>
#include <sys/timeb.h>

#include "cell.h"

/* per-anonymous-connection cell buffer */
typedef struct
{
  uint16_t aci;
  int policy;
  unsigned int cells;
  unsigned char *buf;
  unsigned int buflen;
  unsigned int offset; /* offset to the position of the first cell in the buffer */
  cell_t dc; /* static buffer for the destroy cell - so we are always able to destroy a connection */
  unsigned char dc_set; /* flag that signifies presence of a destroy cell */
  unsigned char destroy_buf; /* flag that signifies that the buffer shuld be destroyed when the destroy cell is sent */

  /* POLICY_DROP_CELLS only */
  unsigned int win_size; /* window size for the connection (number of cells)*/
  unsigned int win_avail; /* available window size */
  uint32_t seq_out; /* next sequence number to use for outgoing cells */
  uint32_t seq_in; /* next expected sequence number */
  uint32_t ack; /* next expected ack/nack */
  struct timeval last_ack; /* time of last ACK/NACK  */

  void *prev;
  void *next;
} conn_buf_t;

/* onion router as seen by the onion proxy */
typedef struct 
{
  char *address;
  uint32_t addr; /* address in network byte order */
  uint16_t port; /* network port in network byte order */
  uint16_t entry_port; /* entry port in network byte order */
  RSA *pkey;
  void *next;
} routent_t;

/* onion router as seen by other routers */
typedef struct
{
  char *address;
  
  uint32_t addr;
  uint16_t port;
  
  RSA *pkey; /* public RSA key */
  /* 64-bit DES keys for link encryption */
  char f_key[8];
  char b_key[8];
  char f_iv[8];
  char b_iv[8];
  EVP_CIPHER_CTX f_ctx;
  EVP_CIPHER_CTX b_ctx;
  
  /* link info */
  uint32_t min;
  uint32_t max;
  struct timeval  min_interval;
  
  /* time when last data was sent to that router */
  struct timeval lastsend;
  
  /* socket */
  int s;

  /* connection buffers */
  conn_buf_t *conn_bufs; /* linked list of connection buffers */
  conn_buf_t *last_conn_buf; /* last item in the list */
  unsigned int next_to_service; /* offset to the connection buffer that is next in turn to be serviced */
  
  /* cell buffer */
  unsigned char cellbuf[128];
  unsigned int celllen;
  
  void *next;
} routentEX_t;

routentEX_t *id_router(routentEX_t **routerarray, size_t rarray_len, uint32_t addr, uint16_t port);
routentEX_t *id_routerbys(routentEX_t **routerarray, size_t rarray_len, int s);

conn_buf_t *new_conn_buf(uint16_t aci, int policy, conn_buf_t **conn_bufs, conn_buf_t **last_conn_buf);
int remove_conn_buf(conn_buf_t *conn_buf, conn_buf_t **conn_bufs, conn_buf_t **last_conn_buf);
conn_buf_t *id_conn_buf(conn_buf_t *conn_bufs, uint16_t aci);

#define __ROUTENT_H
#endif