diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-04-11 13:31:42 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-04-11 13:31:42 +0000 |
commit | c570ddd55c8822fba50a460d398c2296f80d74df (patch) | |
tree | 3319fd6a2e467b95cba73cec6349989cf437ed9a /src/integration-tests | |
parent | 6d01103efa1bcd9ef68a79261b34218599ed1eec (diff) | |
download | gnunet-c570ddd55c8822fba50a460d398c2296f80d74df.tar.gz gnunet-c570ddd55c8822fba50a460d398c2296f80d74df.zip |
- added plugin functionality
Diffstat (limited to 'src/integration-tests')
-rw-r--r-- | src/integration-tests/connection_watchdog.c | 236 |
1 files changed, 187 insertions, 49 deletions
diff --git a/src/integration-tests/connection_watchdog.c b/src/integration-tests/connection_watchdog.c index f70755076..c3c19ce5e 100644 --- a/src/integration-tests/connection_watchdog.c +++ b/src/integration-tests/connection_watchdog.c | |||
@@ -45,6 +45,12 @@ | |||
45 | */ | 45 | */ |
46 | static int ret; | 46 | static int ret; |
47 | 47 | ||
48 | static int have_tcp; | ||
49 | static int have_udp; | ||
50 | static int have_http; | ||
51 | static int have_https; | ||
52 | static int have_unix; | ||
53 | |||
48 | static struct GNUNET_TRANSPORT_Handle *th; | 54 | static struct GNUNET_TRANSPORT_Handle *th; |
49 | static struct GNUNET_CORE_Handle *ch; | 55 | static struct GNUNET_CORE_Handle *ch; |
50 | static struct GNUNET_PeerIdentity my_peer_id; | 56 | static struct GNUNET_PeerIdentity my_peer_id; |
@@ -75,6 +81,38 @@ struct PeerContainer | |||
75 | }; | 81 | }; |
76 | 82 | ||
77 | 83 | ||
84 | enum protocol | ||
85 | { | ||
86 | tcp, | ||
87 | udp, | ||
88 | unixdomain | ||
89 | }; | ||
90 | |||
91 | struct TransportPlugin | ||
92 | { | ||
93 | /** | ||
94 | * This is a doubly-linked list. | ||
95 | */ | ||
96 | struct TransportPlugin *next; | ||
97 | |||
98 | /** | ||
99 | * This is a doubly-linked list. | ||
100 | */ | ||
101 | struct TransportPlugin *prev; | ||
102 | |||
103 | /** | ||
104 | * Short name for the plugin (i.e. "tcp"). | ||
105 | */ | ||
106 | char *short_name; | ||
107 | |||
108 | int port; | ||
109 | |||
110 | int protocol; | ||
111 | }; | ||
112 | |||
113 | struct TransportPlugin *phead; | ||
114 | struct TransportPlugin *ptail; | ||
115 | |||
78 | int map_check_it (void *cls, | 116 | int map_check_it (void *cls, |
79 | const GNUNET_HashCode * key, | 117 | const GNUNET_HashCode * key, |
80 | void *value) | 118 | void *value) |
@@ -136,13 +174,6 @@ map_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
136 | static void | 174 | static void |
137 | stats_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 175 | stats_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
138 | 176 | ||
139 | enum protocol | ||
140 | { | ||
141 | tcp, | ||
142 | udp, | ||
143 | unixdomain | ||
144 | }; | ||
145 | |||
146 | static int | 177 | static int |
147 | check_lowlevel_connections (int port, int protocol) | 178 | check_lowlevel_connections (int port, int protocol) |
148 | { | 179 | { |
@@ -205,6 +236,20 @@ check_lowlevel_connections (int port, int protocol) | |||
205 | #endif | 236 | #endif |
206 | } | 237 | } |
207 | 238 | ||
239 | |||
240 | static struct TransportPlugin * | ||
241 | find_plugin (char * name) | ||
242 | { | ||
243 | struct TransportPlugin *cur = NULL; | ||
244 | |||
245 | for (cur = phead; cur != NULL; cur = phead) | ||
246 | { | ||
247 | if (0 == strcmp(name, cur->short_name)) | ||
248 | return cur; | ||
249 | } | ||
250 | return cur; | ||
251 | } | ||
252 | |||
208 | int stats_check_cb (void *cls, const char *subsystem, | 253 | int stats_check_cb (void *cls, const char *subsystem, |
209 | const char *name, uint64_t value, | 254 | const char *name, uint64_t value, |
210 | int is_persistent) | 255 | int is_persistent) |
@@ -217,16 +262,18 @@ int stats_check_cb (void *cls, const char *subsystem, | |||
217 | (*val) = value; | 262 | (*val) = value; |
218 | 263 | ||
219 | counter ++; | 264 | counter ++; |
220 | if (STATS_VALUES == counter) | 265 | if ((STATS_VALUES == counter) || ((GNUNET_NO == have_tcp) && (STATS_VALUES - 1 == counter))) |
221 | { | 266 | { |
222 | int fail = GNUNET_NO; | 267 | int fail = GNUNET_NO; |
223 | int low_level_connections_tcp = check_lowlevel_connections (2086, tcp); | 268 | |
269 | |||
270 | |||
224 | int low_level_connections_udp = check_lowlevel_connections (2086, udp); | 271 | int low_level_connections_udp = check_lowlevel_connections (2086, udp); |
225 | 272 | ||
226 | if (transport_connections != core_connections) | 273 | if (transport_connections != core_connections) |
227 | { | 274 | { |
228 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 275 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
229 | "Transport connections are inconsistent:\n %u transport notifications <-> %u core notifications\n", | 276 | "%u transport notifications <-> %u core notifications\n", |
230 | transport_connections, core_connections); | 277 | transport_connections, core_connections); |
231 | fail = GNUNET_YES; | 278 | fail = GNUNET_YES; |
232 | } | 279 | } |
@@ -234,14 +281,15 @@ int stats_check_cb (void *cls, const char *subsystem, | |||
234 | if (transport_connections != statistics_transport_connections) | 281 | if (transport_connections != statistics_transport_connections) |
235 | { | 282 | { |
236 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 283 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
237 | "Transport connections are inconsistent:\n %u transport notifications <-> %u in statistics (peers connected)\n", | 284 | "%u transport notifications <-> %u in statistics (peers connected)\n", |
238 | transport_connections, statistics_transport_connections); | 285 | transport_connections, statistics_transport_connections); |
239 | fail = GNUNET_YES; | 286 | fail = GNUNET_YES; |
240 | } | 287 | } |
288 | |||
241 | if (core_connections != statistics_core_entries_session_map) | 289 | if (core_connections != statistics_core_entries_session_map) |
242 | { | 290 | { |
243 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 291 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
244 | "Transport connections are inconsistent:\n %u core notifications <-> %u in statistics (entries session map)\n", | 292 | "%u core notifications <-> %u in statistics (entries session map)\n", |
245 | core_connections, statistics_core_entries_session_map); | 293 | core_connections, statistics_core_entries_session_map); |
246 | fail = GNUNET_YES; | 294 | fail = GNUNET_YES; |
247 | } | 295 | } |
@@ -249,48 +297,50 @@ int stats_check_cb (void *cls, const char *subsystem, | |||
249 | if (core_connections != statistics_core_neighbour_entries) | 297 | if (core_connections != statistics_core_neighbour_entries) |
250 | { | 298 | { |
251 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 299 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
252 | "Transport connections are inconsistent:\n %u core notifications <-> %u in statistics (neighbour entries allocated)\n", | 300 | "%u core notifications <-> %u in statistics (neighbour entries allocated)\n", |
253 | core_connections, statistics_core_neighbour_entries); | 301 | core_connections, statistics_core_neighbour_entries); |
254 | fail = GNUNET_YES; | 302 | fail = GNUNET_YES; |
255 | } | 303 | } |
256 | 304 | ||
257 | if (GNUNET_NO == fail) | 305 | if (GNUNET_NO == fail) |
258 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 306 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
259 | "Statistics consistency check successful : (%u transport / %u core) connections established\n", transport_connections, core_connections); | 307 | "Check successful : (%u transport / %u core) connections established\n", transport_connections, core_connections); |
260 | 308 | ||
261 | /* This is only an issue when transport_connections > statistics_transport_tcp_connections */ | 309 | /* TCP plugin specific checks */ |
262 | if ((low_level_connections_tcp != -1) && (statistics_transport_tcp_connections > low_level_connections_tcp)) | 310 | if (GNUNET_YES == have_tcp) |
263 | { | ||
264 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
265 | "Lowlevel connections are inconsistent:\n %u transport tcp sessions <-> %i established tcp connections\n", | ||
266 | statistics_transport_tcp_connections, low_level_connections_tcp); | ||
267 | fail = GNUNET_YES; | ||
268 | } | ||
269 | else if (low_level_connections_tcp != -1) | ||
270 | { | 311 | { |
271 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 312 | struct TransportPlugin * p = find_plugin ("tcp"); |
272 | "%u TCP connections, %u UDP connections \n", | 313 | int low_level_connections_tcp = check_lowlevel_connections (p->port, tcp); |
273 | low_level_connections_tcp, low_level_connections_udp); | 314 | |
274 | } | 315 | if (low_level_connections_tcp != -1) |
275 | else | 316 | { |
276 | { | 317 | if (statistics_transport_tcp_connections > low_level_connections_tcp) |
277 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 318 | { |
278 | "Error obtaining TCP connections\n"); | 319 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
279 | } | 320 | "%u transport tcp sessions <-> %i established tcp connections\n", |
280 | 321 | statistics_transport_tcp_connections, low_level_connections_tcp); | |
281 | 322 | fail = GNUNET_YES; | |
282 | if (transport_connections > statistics_transport_tcp_connections) | 323 | } |
283 | { | 324 | else if (low_level_connections_tcp != -1) |
284 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 325 | { |
285 | "Transport connections are inconsistent: %u transport notifications <-> %u in statistics (statistics_transport_tcp_connections)\n", | 326 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
286 | transport_connections, statistics_transport_tcp_connections); | 327 | "%u TCP connections, %u UDP connections \n", |
287 | fail = GNUNET_YES; | 328 | low_level_connections_tcp, low_level_connections_udp); |
288 | } | 329 | } |
289 | else | 330 | } |
290 | { | 331 | if (transport_connections > statistics_transport_tcp_connections) |
291 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 332 | { |
292 | "Transport connections are inconsistent: %u transport notifications <-> %u in statistics (statistics_transport_tcp_connections)\n", | 333 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
293 | transport_connections, statistics_transport_tcp_connections); | 334 | "%u transport notifications <-> %u in statistics (statistics_transport_tcp_connections)\n", |
335 | transport_connections, statistics_transport_tcp_connections); | ||
336 | fail = GNUNET_YES; | ||
337 | } | ||
338 | else | ||
339 | { | ||
340 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
341 | " %u transport notifications <-> %u in statistics (statistics_transport_tcp_connections)\n", | ||
342 | transport_connections, statistics_transport_tcp_connections); | ||
343 | } | ||
294 | } | 344 | } |
295 | 345 | ||
296 | if (GNUNET_SCHEDULER_NO_TASK == statistics_task) | 346 | if (GNUNET_SCHEDULER_NO_TASK == statistics_task) |
@@ -321,9 +371,14 @@ stats_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
321 | statistics_core_neighbour_entries = 0; | 371 | statistics_core_neighbour_entries = 0; |
322 | 372 | ||
323 | GNUNET_STATISTICS_get (stats, "transport", "# peers connected", GNUNET_TIME_UNIT_MINUTES, NULL, &stats_check_cb, &statistics_transport_connections); | 373 | GNUNET_STATISTICS_get (stats, "transport", "# peers connected", GNUNET_TIME_UNIT_MINUTES, NULL, &stats_check_cb, &statistics_transport_connections); |
324 | GNUNET_STATISTICS_get (stats, "transport", "# TCP sessions active", GNUNET_TIME_UNIT_MINUTES, NULL, &stats_check_cb, &statistics_transport_tcp_connections); | ||
325 | GNUNET_STATISTICS_get (stats, "core", "# neighbour entries allocated", GNUNET_TIME_UNIT_MINUTES, NULL, &stats_check_cb, &statistics_core_neighbour_entries); | 374 | GNUNET_STATISTICS_get (stats, "core", "# neighbour entries allocated", GNUNET_TIME_UNIT_MINUTES, NULL, &stats_check_cb, &statistics_core_neighbour_entries); |
326 | GNUNET_STATISTICS_get (stats, "core", "# entries in session map", GNUNET_TIME_UNIT_MINUTES, NULL, &stats_check_cb, &statistics_core_entries_session_map); | 375 | GNUNET_STATISTICS_get (stats, "core", "# entries in session map", GNUNET_TIME_UNIT_MINUTES, NULL, &stats_check_cb, &statistics_core_entries_session_map); |
376 | |||
377 | /* TCP plugin specific checks */ | ||
378 | if (GNUNET_YES == have_tcp) | ||
379 | GNUNET_STATISTICS_get (stats, "transport", "# TCP sessions active", GNUNET_TIME_UNIT_MINUTES, NULL, &stats_check_cb, &statistics_transport_tcp_connections); | ||
380 | |||
381 | |||
327 | } | 382 | } |
328 | 383 | ||
329 | 384 | ||
@@ -461,6 +516,8 @@ map_disconnect (const struct GNUNET_PeerIdentity * peer, void * source) | |||
461 | static void | 516 | static void |
462 | cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 517 | cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
463 | { | 518 | { |
519 | struct TransportPlugin * cur = phead; | ||
520 | |||
464 | if (NULL != th) | 521 | if (NULL != th) |
465 | { | 522 | { |
466 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Disconnecting from transport service\n"); | 523 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Disconnecting from transport service\n"); |
@@ -485,6 +542,14 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
485 | GNUNET_SCHEDULER_cancel(check_task); | 542 | GNUNET_SCHEDULER_cancel(check_task); |
486 | check_task = GNUNET_SCHEDULER_NO_TASK; | 543 | check_task = GNUNET_SCHEDULER_NO_TASK; |
487 | } | 544 | } |
545 | |||
546 | for (cur = phead; cur != NULL; cur = phead) | ||
547 | { | ||
548 | GNUNET_CONTAINER_DLL_remove(phead, ptail, cur); | ||
549 | GNUNET_free (cur->short_name); | ||
550 | GNUNET_free (cur); | ||
551 | } | ||
552 | |||
488 | check_task = GNUNET_SCHEDULER_add_now (&map_check, &map_cleanup); | 553 | check_task = GNUNET_SCHEDULER_add_now (&map_check, &map_cleanup); |
489 | } | 554 | } |
490 | 555 | ||
@@ -568,7 +633,78 @@ core_init_cb (void *cls, struct GNUNET_CORE_Handle *server, | |||
568 | const struct GNUNET_PeerIdentity *my_identity) | 633 | const struct GNUNET_PeerIdentity *my_identity) |
569 | { | 634 | { |
570 | my_peer_id = *my_identity; | 635 | my_peer_id = *my_identity; |
571 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Connected to core service\n"); | 636 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connected to core service\n"); |
637 | } | ||
638 | |||
639 | |||
640 | static void | ||
641 | init () | ||
642 | { | ||
643 | struct TransportPlugin * cur; | ||
644 | char *plugs; | ||
645 | char *pos; | ||
646 | char *secname; | ||
647 | int counter; | ||
648 | long long unsigned int port; | ||
649 | |||
650 | have_tcp = GNUNET_NO; | ||
651 | have_udp = GNUNET_NO; | ||
652 | have_http = GNUNET_NO; | ||
653 | have_https = GNUNET_NO; | ||
654 | have_unix = GNUNET_NO; | ||
655 | |||
656 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (mycfg, "TRANSPORT", "PLUGINS", &plugs)) | ||
657 | return; | ||
658 | counter = 0; | ||
659 | for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " ")) | ||
660 | { | ||
661 | counter++; | ||
662 | |||
663 | GNUNET_asprintf(&secname, "transport-%s", pos); | ||
664 | |||
665 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (mycfg, secname, "PORT", &port)) | ||
666 | { | ||
667 | GNUNET_free (secname); | ||
668 | continue; | ||
669 | } | ||
670 | |||
671 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Transport plugin: `%s' port %llu\n"), pos, port); | ||
672 | cur = GNUNET_malloc(sizeof (struct TransportPlugin)); | ||
673 | cur->short_name = strdup (pos); | ||
674 | cur->port = port; | ||
675 | if (0 == strcmp("tcp", pos)) | ||
676 | { | ||
677 | have_tcp = GNUNET_YES; | ||
678 | cur->protocol = tcp; | ||
679 | } | ||
680 | if (0 == strcmp("udp", pos)) | ||
681 | { | ||
682 | have_udp = GNUNET_YES; | ||
683 | cur->protocol = udp; | ||
684 | } | ||
685 | if (0 == strcmp("http", pos)) | ||
686 | { | ||
687 | have_http = GNUNET_YES; | ||
688 | cur->protocol = tcp; | ||
689 | } | ||
690 | if (0 == strcmp("https", pos)) | ||
691 | { | ||
692 | have_https = GNUNET_YES; | ||
693 | cur->protocol = tcp; | ||
694 | } | ||
695 | if (0 == strcmp("unix", pos)) | ||
696 | { | ||
697 | have_unix = GNUNET_YES; | ||
698 | cur->protocol = unixdomain; | ||
699 | } | ||
700 | |||
701 | GNUNET_CONTAINER_DLL_insert(phead, ptail, cur); | ||
702 | GNUNET_free (secname); | ||
703 | } | ||
704 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Found %u transport plugins: `%s'\n"), | ||
705 | counter, plugs); | ||
706 | |||
707 | GNUNET_free (plugs); | ||
572 | } | 708 | } |
573 | 709 | ||
574 | /** | 710 | /** |
@@ -587,6 +723,8 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
587 | core_connections = 0; | 723 | core_connections = 0; |
588 | mycfg = cfg; | 724 | mycfg = cfg; |
589 | 725 | ||
726 | init(); | ||
727 | |||
590 | stats = GNUNET_STATISTICS_create ("watchdog", cfg); | 728 | stats = GNUNET_STATISTICS_create ("watchdog", cfg); |
591 | peers = GNUNET_CONTAINER_multihashmap_create (20); | 729 | peers = GNUNET_CONTAINER_multihashmap_create (20); |
592 | 730 | ||
@@ -594,7 +732,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
594 | &transport_notify_connect_cb, | 732 | &transport_notify_connect_cb, |
595 | &transport_notify_disconnect_cb); | 733 | &transport_notify_disconnect_cb); |
596 | GNUNET_assert (th != NULL); | 734 | GNUNET_assert (th != NULL); |
597 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Connected to transport service\n"); | 735 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connected to transport service\n"); |
598 | ch = GNUNET_CORE_connect (cfg, 1, NULL, | 736 | ch = GNUNET_CORE_connect (cfg, 1, NULL, |
599 | &core_init_cb, | 737 | &core_init_cb, |
600 | &core_connect_cb, | 738 | &core_connect_cb, |