diff options
author | Bart Polot <bart@net.in.tum.de> | 2012-07-12 17:01:29 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2012-07-12 17:01:29 +0000 |
commit | 4d1707340ffd21eafab733607b03ef3f433b80ef (patch) | |
tree | 0321973e947274e6ee49ffc4d650657f7f81307a /src | |
parent | f7031640f16ac459d6be5c8c055d37fb7d9a6a9d (diff) | |
download | gnunet-4d1707340ffd21eafab733607b03ef3f433b80ef.tar.gz gnunet-4d1707340ffd21eafab733607b03ef3f433b80ef.zip |
-extend regex testcase, add debug info to service
Diffstat (limited to 'src')
-rw-r--r-- | src/mesh/gnunet-service-mesh_new.c | 9 | ||||
-rw-r--r-- | src/mesh/test_mesh_regex.c | 151 |
2 files changed, 116 insertions, 44 deletions
diff --git a/src/mesh/gnunet-service-mesh_new.c b/src/mesh/gnunet-service-mesh_new.c index b66a7dd6e..d5e28d6e4 100644 --- a/src/mesh/gnunet-service-mesh_new.c +++ b/src/mesh/gnunet-service-mesh_new.c | |||
@@ -4029,11 +4029,13 @@ handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
4029 | if (NULL == t) | 4029 | if (NULL == t) |
4030 | { | 4030 | { |
4031 | /* TODO notify that we don't know the tunnel */ | 4031 | /* TODO notify that we don't know the tunnel */ |
4032 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " don't know the tunnel %s [%X]!\n", | ||
4033 | GNUNET_i2s (&msg->oid), ntohl(msg->tid)); | ||
4032 | return GNUNET_OK; | 4034 | return GNUNET_OK; |
4033 | } | 4035 | } |
4034 | 4036 | ||
4035 | peer_info = peer_info_get (&msg->peer_id); | 4037 | peer_info = peer_info_get (&msg->peer_id); |
4036 | 4038 | ||
4037 | if (NULL != t->regex_ctx && t->regex_ctx->info->peer == peer_info->id) | 4039 | if (NULL != t->regex_ctx && t->regex_ctx->info->peer == peer_info->id) |
4038 | { | 4040 | { |
4039 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4041 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -5310,6 +5312,11 @@ handle_local_connect_by_string (void *cls, struct GNUNET_SERVER_Client *client, | |||
5310 | return; | 5312 | return; |
5311 | } | 5313 | } |
5312 | 5314 | ||
5315 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
5316 | " on tunnel %s [%u]\n", | ||
5317 | GNUNET_i2s(&my_full_id), | ||
5318 | t->id.tid); | ||
5319 | |||
5313 | /* Only one connect_by_string allowed at the same time! */ | 5320 | /* Only one connect_by_string allowed at the same time! */ |
5314 | /* FIXME: allow more, return handle at api level to cancel, document */ | 5321 | /* FIXME: allow more, return handle at api level to cancel, document */ |
5315 | if (NULL != t->regex_ctx) | 5322 | if (NULL != t->regex_ctx) |
diff --git a/src/mesh/test_mesh_regex.c b/src/mesh/test_mesh_regex.c index c6452171f..499eac5bf 100644 --- a/src/mesh/test_mesh_regex.c +++ b/src/mesh/test_mesh_regex.c | |||
@@ -29,11 +29,12 @@ | |||
29 | 29 | ||
30 | #define VERBOSE GNUNET_YES | 30 | #define VERBOSE GNUNET_YES |
31 | #define REMOVE_DIR GNUNET_YES | 31 | #define REMOVE_DIR GNUNET_YES |
32 | #define MESH_REGEX_PEERS 2 | ||
32 | 33 | ||
33 | /** | 34 | /** |
34 | * How long until we give up on connecting the peers? | 35 | * How long until we give up on connecting the peers? |
35 | */ | 36 | */ |
36 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1500) | 37 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) |
37 | 38 | ||
38 | /** | 39 | /** |
39 | * Time to wait for stuff that should be rather fast | 40 | * Time to wait for stuff that should be rather fast |
@@ -42,9 +43,14 @@ | |||
42 | 43 | ||
43 | 44 | ||
44 | /** | 45 | /** |
45 | * How many events have happened | 46 | * Which strings have been found & connected. |
46 | */ | 47 | */ |
47 | static int ok; | 48 | static int ok[MESH_REGEX_PEERS]; |
49 | |||
50 | /** | ||
51 | * How many connects have happened. | ||
52 | */ | ||
53 | static int connected_peers; | ||
48 | 54 | ||
49 | /** | 55 | /** |
50 | * Be verbose | 56 | * Be verbose |
@@ -91,18 +97,47 @@ static GNUNET_SCHEDULER_TaskIdentifier disconnect_task; | |||
91 | */ | 97 | */ |
92 | static GNUNET_SCHEDULER_TaskIdentifier shutdown_handle; | 98 | static GNUNET_SCHEDULER_TaskIdentifier shutdown_handle; |
93 | 99 | ||
100 | /** | ||
101 | * Mesh handle for connecting peer. | ||
102 | */ | ||
103 | static struct GNUNET_MESH_Handle *h1; | ||
94 | 104 | ||
95 | static struct GNUNET_TESTING_Daemon *d1; | 105 | /** |
106 | * Mesh handle for announcing peers. | ||
107 | */ | ||
108 | static struct GNUNET_MESH_Handle *h2[MESH_REGEX_PEERS]; | ||
96 | 109 | ||
97 | static struct GNUNET_TESTING_Daemon *d2; | 110 | /** |
111 | * Tunnel handles for announcing peer. | ||
112 | */ | ||
113 | static struct GNUNET_MESH_Tunnel *t[MESH_REGEX_PEERS]; | ||
98 | 114 | ||
99 | static struct GNUNET_MESH_Handle *h1; | 115 | /** |
116 | * Incoming tunnels for announcing peers. | ||
117 | */ | ||
118 | static struct GNUNET_MESH_Tunnel *incoming_t[MESH_REGEX_PEERS]; | ||
119 | |||
120 | /** | ||
121 | * Regular expressions for the announces. | ||
122 | */ | ||
123 | static char *regexes[MESH_REGEX_PEERS] = {"(0|1)" | ||
124 | "(0|1)" | ||
125 | "23456789A*BC", | ||
100 | 126 | ||
101 | static struct GNUNET_MESH_Handle *h2; | 127 | "0123456789ABC"/*, |
102 | 128 | ||
103 | static struct GNUNET_MESH_Tunnel *t; | 129 | "0*123456789ABC*"*/}; |
130 | // "(0|1|2|3|4|5|6|7|8|9)" | ||
104 | 131 | ||
105 | static struct GNUNET_MESH_Tunnel *incoming_t; | 132 | |
133 | /** | ||
134 | * Service strings to look for. | ||
135 | */ | ||
136 | static char *strings[MESH_REGEX_PEERS] = {"0123456789ABC", | ||
137 | |||
138 | "0123456789ABC"/*, | ||
139 | |||
140 | "000123456789ABCCCC"*/}; | ||
106 | 141 | ||
107 | /** | 142 | /** |
108 | * Check whether peers successfully shut down. | 143 | * Check whether peers successfully shut down. |
@@ -113,11 +148,14 @@ static struct GNUNET_MESH_Tunnel *incoming_t; | |||
113 | static void | 148 | static void |
114 | shutdown_callback (void *cls, const char *emsg) | 149 | shutdown_callback (void *cls, const char *emsg) |
115 | { | 150 | { |
151 | unsigned int i; | ||
152 | |||
116 | if (emsg != NULL) | 153 | if (emsg != NULL) |
117 | { | 154 | { |
118 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 155 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
119 | "test: Shutdown of peers failed! (%s)\n", emsg); | 156 | "test: Shutdown of peers failed! (%s)\n", emsg); |
120 | ok = GNUNET_NO; | 157 | for (i = 0; i < MESH_REGEX_PEERS; i++) |
158 | ok[i] = GNUNET_NO; | ||
121 | } | 159 | } |
122 | #if VERBOSE | 160 | #if VERBOSE |
123 | else | 161 | else |
@@ -156,11 +194,16 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
156 | static void | 194 | static void |
157 | disconnect_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 195 | disconnect_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
158 | { | 196 | { |
159 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: disconnecting peers\n"); | 197 | unsigned int i; |
160 | 198 | ||
161 | GNUNET_MESH_tunnel_destroy (t); | 199 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: disconnecting peers\n"); |
200 | |||
201 | for (i = 0; i < MESH_REGEX_PEERS; i++) | ||
202 | { | ||
203 | GNUNET_MESH_tunnel_destroy (t[i]); | ||
204 | GNUNET_MESH_disconnect (h2[i]); | ||
205 | } | ||
162 | GNUNET_MESH_disconnect (h1); | 206 | GNUNET_MESH_disconnect (h1); |
163 | GNUNET_MESH_disconnect (h2); | ||
164 | if (GNUNET_SCHEDULER_NO_TASK != shutdown_handle) | 207 | if (GNUNET_SCHEDULER_NO_TASK != shutdown_handle) |
165 | { | 208 | { |
166 | GNUNET_SCHEDULER_cancel (shutdown_handle); | 209 | GNUNET_SCHEDULER_cancel (shutdown_handle); |
@@ -222,11 +265,9 @@ ch (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
222 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 265 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
223 | "Peer connected: %s\n", | 266 | "Peer connected: %s\n", |
224 | GNUNET_i2s (peer)); | 267 | GNUNET_i2s (peer)); |
268 | connected_peers++; | ||
269 | GNUNET_assert (i = 1L); | ||
225 | 270 | ||
226 | if (i != 1L || peer == NULL) | ||
227 | ok = GNUNET_NO; | ||
228 | else | ||
229 | ok = GNUNET_OK; | ||
230 | if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) | 271 | if (GNUNET_SCHEDULER_NO_TASK != disconnect_task) |
231 | { | 272 | { |
232 | GNUNET_SCHEDULER_cancel (disconnect_task); | 273 | GNUNET_SCHEDULER_cancel (disconnect_task); |
@@ -251,13 +292,16 @@ incoming_tunnel (void *cls, struct GNUNET_MESH_Tunnel *tunnel, | |||
251 | const struct GNUNET_PeerIdentity *initiator, | 292 | const struct GNUNET_PeerIdentity *initiator, |
252 | const struct GNUNET_ATS_Information *atsi) | 293 | const struct GNUNET_ATS_Information *atsi) |
253 | { | 294 | { |
295 | long i = (long) cls; | ||
254 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 296 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
255 | "Incoming tunnel from %s to peer %d\n", | 297 | "Incoming tunnel from %s to peer %d\n", |
256 | GNUNET_i2s (initiator), (long) cls); | 298 | GNUNET_i2s (initiator), (long) cls); |
257 | // ok++; | ||
258 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok); | 299 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok); |
259 | if ((long) cls == 2L) | 300 | if (i > 1L && i <= 1L + MESH_REGEX_PEERS) |
260 | incoming_t = tunnel; | 301 | { |
302 | incoming_t[i - 1] = tunnel; | ||
303 | ok[i - 1] = GNUNET_OK; | ||
304 | } | ||
261 | else | 305 | else |
262 | { | 306 | { |
263 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 307 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
@@ -290,7 +334,6 @@ data_callback (void *cls, struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx, | |||
290 | const struct GNUNET_MessageHeader *message, | 334 | const struct GNUNET_MessageHeader *message, |
291 | const struct GNUNET_ATS_Information *atsi) | 335 | const struct GNUNET_ATS_Information *atsi) |
292 | { | 336 | { |
293 | |||
294 | return GNUNET_OK; | 337 | return GNUNET_OK; |
295 | } | 338 | } |
296 | 339 | ||
@@ -312,6 +355,8 @@ static void | |||
312 | peergroup_ready (void *cls, const char *emsg) | 355 | peergroup_ready (void *cls, const char *emsg) |
313 | { | 356 | { |
314 | GNUNET_MESH_ApplicationType app; | 357 | GNUNET_MESH_ApplicationType app; |
358 | struct GNUNET_TESTING_Daemon *d; | ||
359 | unsigned int i; | ||
315 | 360 | ||
316 | if (emsg != NULL) | 361 | if (emsg != NULL) |
317 | { | 362 | { |
@@ -319,7 +364,6 @@ peergroup_ready (void *cls, const char *emsg) | |||
319 | "test: Peergroup callback called with error, aborting test!\n"); | 364 | "test: Peergroup callback called with error, aborting test!\n"); |
320 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "test: Error from testing: `%s'\n", | 365 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "test: Error from testing: `%s'\n", |
321 | emsg); | 366 | emsg); |
322 | ok = GNUNET_NO; | ||
323 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | 367 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); |
324 | return; | 368 | return; |
325 | } | 369 | } |
@@ -333,7 +377,6 @@ peergroup_ready (void *cls, const char *emsg) | |||
333 | peers_running = GNUNET_TESTING_daemons_running (pg); | 377 | peers_running = GNUNET_TESTING_daemons_running (pg); |
334 | if (0 < failed_connections) | 378 | if (0 < failed_connections) |
335 | { | 379 | { |
336 | ok = GNUNET_NO; | ||
337 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "test: %u connections have FAILED!\n", | 380 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "test: %u connections have FAILED!\n", |
338 | failed_connections); | 381 | failed_connections); |
339 | disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_peers, NULL); | 382 | disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_peers, NULL); |
@@ -341,32 +384,40 @@ peergroup_ready (void *cls, const char *emsg) | |||
341 | } | 384 | } |
342 | disconnect_task = | 385 | disconnect_task = |
343 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &disconnect_peers, NULL); | 386 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &disconnect_peers, NULL); |
344 | d1 = GNUNET_TESTING_daemon_get (pg, 1); | 387 | d = GNUNET_TESTING_daemon_get (pg, 1); |
345 | d2 = GNUNET_TESTING_daemon_get (pg, 10); | 388 | |
346 | app = (GNUNET_MESH_ApplicationType) 0; | 389 | app = (GNUNET_MESH_ApplicationType) 0; |
347 | 390 | ||
348 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 391 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
349 | "Connect to mesh\n"); | 392 | "Connect to mesh\n"); |
350 | h1 = GNUNET_MESH_connect (d1->cfg, 5, (void *) 1L, | 393 | h1 = GNUNET_MESH_connect (d->cfg, 5, (void *) 1L, |
351 | NULL, | 394 | NULL, |
352 | NULL, | 395 | NULL, |
353 | handlers, | 396 | handlers, |
354 | &app); | 397 | &app); |
355 | h2 = GNUNET_MESH_connect (d2->cfg, 5, (void *) 2L, | 398 | for (i = 0; i < MESH_REGEX_PEERS; i++) |
356 | &incoming_tunnel, | 399 | { |
357 | &tunnel_cleaner, | 400 | ok[i] = GNUNET_NO; |
358 | handlers, | 401 | d = GNUNET_TESTING_daemon_get (pg, 10 + i); |
359 | &app); | 402 | h2[i] = GNUNET_MESH_connect (d->cfg, 5, (void *) (long) (i + 1), |
360 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 403 | &incoming_tunnel, |
361 | "Announce REGEX\n"); | 404 | &tunnel_cleaner, |
362 | GNUNET_MESH_announce_regex (h2, "0123456789A*BC"); | 405 | handlers, |
406 | &app); | ||
407 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
408 | "Announce REGEX %u: %s\n", i, regexes[i]); | ||
409 | GNUNET_MESH_announce_regex (h2[i], regexes[i]); | ||
410 | } | ||
363 | 411 | ||
364 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 412 | for (i = 0; i < MESH_REGEX_PEERS; i++) |
365 | "Create tunnel\n"); | 413 | { |
366 | t = GNUNET_MESH_tunnel_create (h1, NULL, &ch, &dh, (void *) 1L); | 414 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
367 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 415 | "Create tunnel\n"); |
368 | "Connect by string\n"); | 416 | t[i] = GNUNET_MESH_tunnel_create (h1, NULL, &ch, &dh, (void *) 1L); |
369 | GNUNET_MESH_peer_request_connect_by_string (t, "0123456789ABC"); | 417 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
418 | "Connect by string %s\n", strings[i]); | ||
419 | GNUNET_MESH_peer_request_connect_by_string (t[i], strings[i]); | ||
420 | } | ||
370 | /* connect handler = success, timeout = error */ | 421 | /* connect handler = success, timeout = error */ |
371 | 422 | ||
372 | } | 423 | } |
@@ -422,7 +473,6 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
422 | { | 473 | { |
423 | struct GNUNET_TESTING_Host *hosts; | 474 | struct GNUNET_TESTING_Host *hosts; |
424 | 475 | ||
425 | ok = GNUNET_NO; | ||
426 | total_connections = 0; | 476 | total_connections = 0; |
427 | failed_connections = 0; | 477 | failed_connections = 0; |
428 | testing_cfg = GNUNET_CONFIGURATION_dup (cfg); | 478 | testing_cfg = GNUNET_CONFIGURATION_dup (cfg); |
@@ -489,6 +539,8 @@ main (int argc, char *argv[]) | |||
489 | #endif | 539 | #endif |
490 | NULL | 540 | NULL |
491 | }; | 541 | }; |
542 | int result; | ||
543 | unsigned int i; | ||
492 | 544 | ||
493 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Start\n"); | 545 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Start\n"); |
494 | 546 | ||
@@ -500,9 +552,22 @@ main (int argc, char *argv[]) | |||
500 | #if REMOVE_DIR | 552 | #if REMOVE_DIR |
501 | GNUNET_DISK_directory_remove ("/tmp/test_mesh_2dtorus"); | 553 | GNUNET_DISK_directory_remove ("/tmp/test_mesh_2dtorus"); |
502 | #endif | 554 | #endif |
503 | if (GNUNET_OK != ok) | 555 | result = GNUNET_OK; |
556 | for (i = 0; i < MESH_REGEX_PEERS; i++) | ||
504 | { | 557 | { |
505 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "test: FAILED! (ok = %d)\n", ok); | 558 | if (GNUNET_OK != ok[i]) |
559 | { | ||
560 | result = GNUNET_SYSERR; | ||
561 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
562 | "COULD NOT CONNECT TO %u: %s!\n", | ||
563 | i, strings[i]); | ||
564 | } | ||
565 | } | ||
566 | if (GNUNET_OK != result || connected_peers != MESH_REGEX_PEERS) | ||
567 | { | ||
568 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
569 | "test: FAILED! %u connected peers\n", | ||
570 | connected_peers); | ||
506 | return 1; | 571 | return 1; |
507 | } | 572 | } |
508 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: success\n"); | 573 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: success\n"); |