diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-07-01 21:30:28 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-07-01 21:30:28 +0000 |
commit | e3f24011c0e95a67d673b43348202b7751574474 (patch) | |
tree | 89fff5172468c23f762c3db9c531b3e792da56dc /src/nat/nat_test.c | |
parent | 490cf7e092613f7c511b46332710187336eb3a6a (diff) | |
download | gnunet-e3f24011c0e95a67d673b43348202b7751574474.tar.gz gnunet-e3f24011c0e95a67d673b43348202b7751574474.zip |
testcase for nat test code
Diffstat (limited to 'src/nat/nat_test.c')
-rw-r--r-- | src/nat/nat_test.c | 72 |
1 files changed, 62 insertions, 10 deletions
diff --git a/src/nat/nat_test.c b/src/nat/nat_test.c index 74b2dddec..9b07b48f9 100644 --- a/src/nat/nat_test.c +++ b/src/nat/nat_test.c | |||
@@ -62,6 +62,29 @@ struct NatActivity | |||
62 | 62 | ||
63 | 63 | ||
64 | /** | 64 | /** |
65 | * Entry we keep for each connection to the gnunet-nat-service. | ||
66 | */ | ||
67 | struct ClientActivity | ||
68 | { | ||
69 | /** | ||
70 | * This is a doubly-linked list. | ||
71 | */ | ||
72 | struct ClientActivity *next; | ||
73 | |||
74 | /** | ||
75 | * This is a doubly-linked list. | ||
76 | */ | ||
77 | struct ClientActivity *prev; | ||
78 | |||
79 | /** | ||
80 | * Socket of the incoming connection. | ||
81 | */ | ||
82 | struct GNUNET_CLIENT_Connection *client; | ||
83 | |||
84 | }; | ||
85 | |||
86 | |||
87 | /** | ||
65 | * Handle to a NAT test. | 88 | * Handle to a NAT test. |
66 | */ | 89 | */ |
67 | struct GNUNET_NAT_Test | 90 | struct GNUNET_NAT_Test |
@@ -95,12 +118,22 @@ struct GNUNET_NAT_Test | |||
95 | /** | 118 | /** |
96 | * Head of list of nat activities. | 119 | * Head of list of nat activities. |
97 | */ | 120 | */ |
98 | struct NatActivity *head; | 121 | struct NatActivity *na_head; |
99 | 122 | ||
100 | /** | 123 | /** |
101 | * Tail of list of nat activities. | 124 | * Tail of list of nat activities. |
102 | */ | 125 | */ |
103 | struct NatActivity *tail; | 126 | struct NatActivity *na_tail; |
127 | |||
128 | /** | ||
129 | * Head of list of client activities. | ||
130 | */ | ||
131 | struct ClientActivity *ca_head; | ||
132 | |||
133 | /** | ||
134 | * Tail of list of client activities. | ||
135 | */ | ||
136 | struct ClientActivity *ca_tail; | ||
104 | 137 | ||
105 | /** | 138 | /** |
106 | * Identity of task for the listen socket (if any) | 139 | * Identity of task for the listen socket (if any) |
@@ -172,8 +205,8 @@ do_read (void *cls, | |||
172 | 205 | ||
173 | na->rtask = GNUNET_SCHEDULER_NO_TASK; | 206 | na->rtask = GNUNET_SCHEDULER_NO_TASK; |
174 | tst = na->h; | 207 | tst = na->h; |
175 | GNUNET_CONTAINER_DLL_remove (tst->head, | 208 | GNUNET_CONTAINER_DLL_remove (tst->na_head, |
176 | tst->tail, | 209 | tst->na_tail, |
177 | na); | 210 | na); |
178 | if ( (NULL != tc->write_ready) && | 211 | if ( (NULL != tc->write_ready) && |
179 | (GNUNET_NETWORK_fdset_isset (tc->read_ready, | 212 | (GNUNET_NETWORK_fdset_isset (tc->read_ready, |
@@ -234,8 +267,8 @@ do_accept (void *cls, | |||
234 | wl->sock, | 267 | wl->sock, |
235 | &do_read, | 268 | &do_read, |
236 | wl); | 269 | wl); |
237 | GNUNET_CONTAINER_DLL_insert (tst->head, | 270 | GNUNET_CONTAINER_DLL_insert (tst->na_head, |
238 | tst->tail, | 271 | tst->na_tail, |
239 | wl); | 272 | wl); |
240 | } | 273 | } |
241 | 274 | ||
@@ -256,6 +289,7 @@ addr_cb (void *cls, | |||
256 | socklen_t addrlen) | 289 | socklen_t addrlen) |
257 | { | 290 | { |
258 | struct GNUNET_NAT_Test *h = cls; | 291 | struct GNUNET_NAT_Test *h = cls; |
292 | struct ClientActivity *ca; | ||
259 | struct GNUNET_CLIENT_Connection *client; | 293 | struct GNUNET_CLIENT_Connection *client; |
260 | struct GNUNET_NAT_TestMessage msg; | 294 | struct GNUNET_NAT_TestMessage msg; |
261 | const struct sockaddr_in *sa; | 295 | const struct sockaddr_in *sa; |
@@ -264,6 +298,9 @@ addr_cb (void *cls, | |||
264 | return; | 298 | return; |
265 | if (addrlen != sizeof (struct sockaddr_in)) | 299 | if (addrlen != sizeof (struct sockaddr_in)) |
266 | return; /* ignore IPv6 here */ | 300 | return; /* ignore IPv6 here */ |
301 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
302 | "Asking gnunet-nat-server to connect to `%s'\n", | ||
303 | GNUNET_a2s (addr, addrlen)); | ||
267 | sa = (const struct sockaddr_in*) addr; | 304 | sa = (const struct sockaddr_in*) addr; |
268 | msg.header.size = htons (sizeof(struct GNUNET_NAT_TestMessage)); | 305 | msg.header.size = htons (sizeof(struct GNUNET_NAT_TestMessage)); |
269 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_NAT_TEST); | 306 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_NAT_TEST); |
@@ -274,13 +311,19 @@ addr_cb (void *cls, | |||
274 | 311 | ||
275 | client = GNUNET_CLIENT_connect ("gnunet-nat-server", | 312 | client = GNUNET_CLIENT_connect ("gnunet-nat-server", |
276 | h->cfg); | 313 | h->cfg); |
314 | if (NULL == client) | ||
315 | return; | ||
316 | ca = GNUNET_malloc (sizeof (struct ClientActivity)); | ||
317 | ca->client = client; | ||
318 | GNUNET_CONTAINER_DLL_insert (h->ca_head, | ||
319 | h->ca_tail, | ||
320 | ca); | ||
277 | GNUNET_break (GNUNET_OK == | 321 | GNUNET_break (GNUNET_OK == |
278 | GNUNET_CLIENT_transmit_and_get_response (client, | 322 | GNUNET_CLIENT_transmit_and_get_response (client, |
279 | &msg.header, | 323 | &msg.header, |
280 | GNUNET_TIME_UNIT_SECONDS, | 324 | GNUNET_TIME_UNIT_SECONDS, |
281 | GNUNET_YES, | 325 | GNUNET_YES, |
282 | NULL, NULL)); | 326 | NULL, NULL)); |
283 | GNUNET_CLIENT_disconnect (client, GNUNET_YES); | ||
284 | } | 327 | } |
285 | 328 | ||
286 | 329 | ||
@@ -369,11 +412,20 @@ void | |||
369 | GNUNET_NAT_test_stop (struct GNUNET_NAT_Test *tst) | 412 | GNUNET_NAT_test_stop (struct GNUNET_NAT_Test *tst) |
370 | { | 413 | { |
371 | struct NatActivity *pos; | 414 | struct NatActivity *pos; |
415 | struct ClientActivity *cpos; | ||
372 | 416 | ||
373 | while (NULL != (pos = tst->head)) | 417 | while (NULL != (cpos = tst->ca_head)) |
418 | { | ||
419 | GNUNET_CONTAINER_DLL_remove (tst->ca_head, | ||
420 | tst->ca_tail, | ||
421 | cpos); | ||
422 | GNUNET_CLIENT_disconnect (cpos->client, GNUNET_NO); | ||
423 | GNUNET_free (cpos); | ||
424 | } | ||
425 | while (NULL != (pos = tst->na_head)) | ||
374 | { | 426 | { |
375 | GNUNET_CONTAINER_DLL_remove (tst->head, | 427 | GNUNET_CONTAINER_DLL_remove (tst->na_head, |
376 | tst->tail, | 428 | tst->na_tail, |
377 | pos); | 429 | pos); |
378 | GNUNET_SCHEDULER_cancel (pos->rtask); | 430 | GNUNET_SCHEDULER_cancel (pos->rtask); |
379 | GNUNET_NETWORK_socket_close (pos->sock); | 431 | GNUNET_NETWORK_socket_close (pos->sock); |