diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-06-05 21:33:58 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-06-05 21:33:58 +0000 |
commit | a998e0abbd220035bdb333388da229852980e2cc (patch) | |
tree | addf062abb3cc68ab1103a415fbdec315dd54a63 | |
parent | 4ce2d673d41ad8a8b9e5389b5b97ecb5e77f190d (diff) | |
download | gnunet-a998e0abbd220035bdb333388da229852980e2cc.tar.gz gnunet-a998e0abbd220035bdb333388da229852980e2cc.zip |
-cleaning up client api to test for service availability
-rw-r--r-- | src/arm/arm_api.c | 14 | ||||
-rw-r--r-- | src/ats-tool/gnunet-ats.c | 67 | ||||
-rw-r--r-- | src/include/gnunet_client_lib.h | 46 | ||||
-rw-r--r-- | src/include/gnunet_crypto_lib.h | 2 | ||||
-rw-r--r-- | src/include/gnunet_service_lib.h | 4 | ||||
-rw-r--r-- | src/namestore/gnunet-namestore.c | 40 | ||||
-rw-r--r-- | src/regex/gnunet-regex-simulation-profiler.c | 2 | ||||
-rw-r--r-- | src/regex/regex.c | 1 | ||||
-rw-r--r-- | src/statistics/gnunet-statistics.c | 107 | ||||
-rw-r--r-- | src/transport/gnunet-transport.c | 30 | ||||
-rw-r--r-- | src/util/client.c | 225 | ||||
-rw-r--r-- | src/util/test_service.c | 25 |
12 files changed, 363 insertions, 200 deletions
diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c index 4ef6b3c27..34f7a6704 100644 --- a/src/arm/arm_api.c +++ b/src/arm/arm_api.c | |||
@@ -743,10 +743,11 @@ control_message_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *t | |||
743 | * it is not, start the ARM process. | 743 | * it is not, start the ARM process. |
744 | * | 744 | * |
745 | * @param cls the context for the request that we will report on (struct ARMControlMessage *) | 745 | * @param cls the context for the request that we will report on (struct ARMControlMessage *) |
746 | * @param tc why were we called (reason says if ARM is running) | 746 | * @param result GNUNET_YES if ARM is running |
747 | */ | 747 | */ |
748 | static void | 748 | static void |
749 | arm_service_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 749 | arm_service_report (void *cls, |
750 | int result) | ||
750 | { | 751 | { |
751 | struct ARMControlMessage *cm = cls; | 752 | struct ARMControlMessage *cm = cls; |
752 | struct GNUNET_ARM_Handle *h; | 753 | struct GNUNET_ARM_Handle *h; |
@@ -759,12 +760,11 @@ arm_service_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
759 | char *lopostfix; | 760 | char *lopostfix; |
760 | 761 | ||
761 | test_is_active = cm->h->service_test_is_active; | 762 | test_is_active = cm->h->service_test_is_active; |
762 | |||
763 | /* FIXME: shouldn't we check for GNUNET_SCHEDULER_REASON_SHUTDOWN ? */ | ||
764 | if ((GNUNET_YES == test_is_active) && | 763 | if ((GNUNET_YES == test_is_active) && |
765 | (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))) | 764 | (GNUNET_YES == result)) |
766 | { | 765 | { |
767 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Looks like `%s' is already running.\n", | 766 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
767 | "Looks like `%s' is already running.\n", | ||
768 | "gnunet-service-arm"); | 768 | "gnunet-service-arm"); |
769 | /* arm is running! */ | 769 | /* arm is running! */ |
770 | if (cm->result_cont) | 770 | if (cm->result_cont) |
@@ -780,7 +780,7 @@ arm_service_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
780 | GNUNET_CONFIGURATION_destroy (cm->h->cfg); | 780 | GNUNET_CONFIGURATION_destroy (cm->h->cfg); |
781 | GNUNET_free (cm->h); | 781 | GNUNET_free (cm->h); |
782 | } | 782 | } |
783 | if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)) || | 783 | if ((GNUNET_YES == result) || |
784 | (GNUNET_NO == test_is_active)) | 784 | (GNUNET_NO == test_is_active)) |
785 | { | 785 | { |
786 | GNUNET_free (cm); | 786 | GNUNET_free (cm); |
diff --git a/src/ats-tool/gnunet-ats.c b/src/ats-tool/gnunet-ats.c index 2e61247bb..f8ecd3aad 100644 --- a/src/ats-tool/gnunet-ats.c +++ b/src/ats-tool/gnunet-ats.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors) | 3 | (C) 2009--2013 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -80,14 +80,14 @@ static int op_print_quotas; | |||
80 | static int op_monitor; | 80 | static int op_monitor; |
81 | 81 | ||
82 | 82 | ||
83 | |||
84 | static struct GNUNET_ATS_PerformanceHandle *ph; | 83 | static struct GNUNET_ATS_PerformanceHandle *ph; |
85 | 84 | ||
86 | struct GNUNET_ATS_AddressListHandle *alh; | 85 | static struct GNUNET_ATS_AddressListHandle *alh; |
87 | 86 | ||
88 | static struct GNUNET_CONFIGURATION_Handle *cfg; | 87 | static struct GNUNET_CONFIGURATION_Handle *cfg; |
89 | 88 | ||
90 | GNUNET_SCHEDULER_TaskIdentifier end_task; | 89 | static GNUNET_SCHEDULER_TaskIdentifier end_task; |
90 | |||
91 | 91 | ||
92 | struct PendingResolutions | 92 | struct PendingResolutions |
93 | { | 93 | { |
@@ -104,11 +104,15 @@ struct PendingResolutions | |||
104 | struct GNUNET_TRANSPORT_AddressToStringContext * tats_ctx; | 104 | struct GNUNET_TRANSPORT_AddressToStringContext * tats_ctx; |
105 | }; | 105 | }; |
106 | 106 | ||
107 | struct PendingResolutions *head; | ||
108 | struct PendingResolutions *tail; | ||
109 | 107 | ||
110 | void end (void *cls, | 108 | static struct PendingResolutions *head; |
111 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 109 | |
110 | static struct PendingResolutions *tail; | ||
111 | |||
112 | |||
113 | static void | ||
114 | end (void *cls, | ||
115 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
112 | { | 116 | { |
113 | struct PendingResolutions * pr; | 117 | struct PendingResolutions * pr; |
114 | struct PendingResolutions * next; | 118 | struct PendingResolutions * next; |
@@ -145,7 +149,8 @@ void end (void *cls, | |||
145 | } | 149 | } |
146 | 150 | ||
147 | 151 | ||
148 | void transport_addr_to_str_cb (void *cls, const char *address) | 152 | static void |
153 | transport_addr_to_str_cb (void *cls, const char *address) | ||
149 | { | 154 | { |
150 | struct PendingResolutions * pr = cls; | 155 | struct PendingResolutions * pr = cls; |
151 | char *ats_str; | 156 | char *ats_str; |
@@ -156,11 +161,10 @@ void transport_addr_to_str_cb (void *cls, const char *address) | |||
156 | uint32_t ats_type; | 161 | uint32_t ats_type; |
157 | uint32_t ats_value; | 162 | uint32_t ats_value; |
158 | uint32_t network; | 163 | uint32_t network; |
164 | |||
159 | if (NULL != address) | 165 | if (NULL != address) |
160 | { | 166 | { |
161 | ats_str = GNUNET_strdup(""); | 167 | ats_str = GNUNET_strdup(""); |
162 | |||
163 | |||
164 | for (c = 0; c < pr->ats_count; c++) | 168 | for (c = 0; c < pr->ats_count; c++) |
165 | { | 169 | { |
166 | ats_tmp = ats_str; | 170 | ats_tmp = ats_str; |
@@ -220,17 +224,18 @@ void transport_addr_to_str_cb (void *cls, const char *address) | |||
220 | } | 224 | } |
221 | } | 225 | } |
222 | 226 | ||
223 | void ats_perf_cb (void *cls, | 227 | |
224 | const struct GNUNET_HELLO_Address *address, | 228 | static void |
225 | int active, | 229 | ats_perf_cb (void *cls, |
226 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 230 | const struct GNUNET_HELLO_Address *address, |
227 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | 231 | int active, |
228 | const struct GNUNET_ATS_Information *ats, | 232 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
229 | uint32_t ats_count) | 233 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, |
234 | const struct GNUNET_ATS_Information *ats, | ||
235 | uint32_t ats_count) | ||
230 | { | 236 | { |
231 | struct PendingResolutions * pr; | 237 | struct PendingResolutions * pr; |
232 | 238 | ||
233 | |||
234 | if (NULL != address) | 239 | if (NULL != address) |
235 | { | 240 | { |
236 | pr = GNUNET_malloc (sizeof (struct PendingResolutions) + | 241 | pr = GNUNET_malloc (sizeof (struct PendingResolutions) + |
@@ -325,30 +330,30 @@ print_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
325 | } | 330 | } |
326 | 331 | ||
327 | 332 | ||
328 | 333 | static void | |
329 | void testservice_ats (void *cls, | 334 | testservice_ats (void *cls, |
330 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 335 | int result) |
331 | { | 336 | { |
332 | struct GNUNET_PeerIdentity pid; | ||
333 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 337 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
338 | struct GNUNET_PeerIdentity pid; | ||
334 | unsigned int c; | 339 | unsigned int c; |
335 | unsigned int type; | 340 | unsigned int type; |
336 | 341 | ||
337 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) | 342 | if (GNUNET_YES != result) |
338 | { | 343 | { |
339 | FPRINTF (stderr, _("Service `%s' is not running\n"), "ats"); | 344 | FPRINTF (stderr, _("Service `%s' is not running\n"), "ats"); |
340 | return; | 345 | return; |
341 | } | 346 | } |
342 | 347 | ||
343 | results = 0; | 348 | results = 0; |
344 | 349 | ||
345 | if (NULL != pid_str) | 350 | if (NULL != pid_str) |
346 | { | 351 | { |
347 | if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (pid_str, &pid.hashPubKey)) | 352 | if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (pid_str, &pid.hashPubKey)) |
348 | { | 353 | { |
349 | FPRINTF (stderr, _("Failed to parse peer identity `%s'\n"), pid_str); | 354 | FPRINTF (stderr, _("Failed to parse peer identity `%s'\n"), pid_str); |
350 | return; | 355 | return; |
351 | } | 356 | } |
352 | } | 357 | } |
353 | 358 | ||
354 | c = op_list_all + op_list_used + op_monitor + op_set_pref; | 359 | c = op_list_all + op_list_used + op_monitor + op_set_pref; |
diff --git a/src/include/gnunet_client_lib.h b/src/include/gnunet_client_lib.h index 8642dd941..e402b4295 100644 --- a/src/include/gnunet_client_lib.h +++ b/src/include/gnunet_client_lib.h | |||
@@ -1,10 +1,10 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors) | 3 | (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2013 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
7 | by the Free Software Foundation; either version 2, or (at your | 7 | by the Free Software Foundation; either version 3, or (at your |
8 | option) any later version. | 8 | option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
@@ -190,21 +190,49 @@ GNUNET_CLIENT_transmit_and_get_response (struct GNUNET_CLIENT_Connection *client | |||
190 | 190 | ||
191 | 191 | ||
192 | /** | 192 | /** |
193 | * Wait until the service is running. | 193 | * Handle for a test to check if a service is running. |
194 | */ | ||
195 | struct GNUNET_CLIENT_TestHandle; | ||
196 | |||
197 | /** | ||
198 | * Function called with the result on the service test. | ||
199 | * | ||
200 | * @param cls closure | ||
201 | * @param result GNUNET_YES if the service is running, | ||
202 | * GNUNET_NO if the service is not running | ||
203 | * GNUNET_SYSERR if the configuration is invalid | ||
204 | */ | ||
205 | typedef void (*GNUNET_CLIENT_TestResultCallback)(void *cls, | ||
206 | int result); | ||
207 | |||
208 | |||
209 | /** | ||
210 | * Test if the service is running. If we are given a UNIXPATH or a | ||
211 | * local address, we do this NOT by trying to connect to the service, | ||
212 | * but by trying to BIND to the same port. If the BIND fails, we know | ||
213 | * the service is running. | ||
194 | * | 214 | * |
195 | * @param service name of the service to wait for | 215 | * @param service name of the service to wait for |
196 | * @param cfg configuration to use | 216 | * @param cfg configuration to use |
197 | * @param timeout how long to wait at most in ms | 217 | * @param timeout how long to wait at most in ms |
198 | * @param task task to run if service is running | 218 | * @param cb function to call with the result |
199 | * (reason will be "PREREQ_DONE" (service running) | 219 | * @param cb_cls closure for 'cb' |
200 | * or "TIMEOUT" (service not known to be running)) | 220 | * @return handle to cancel the test |
201 | * @param task_cls closure for task | ||
202 | */ | 221 | */ |
203 | void | 222 | struct GNUNET_CLIENT_TestHandle * |
204 | GNUNET_CLIENT_service_test (const char *service, | 223 | GNUNET_CLIENT_service_test (const char *service, |
205 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 224 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
206 | struct GNUNET_TIME_Relative timeout, | 225 | struct GNUNET_TIME_Relative timeout, |
207 | GNUNET_SCHEDULER_Task task, void *task_cls); | 226 | GNUNET_CLIENT_TestResultCallback cb, void *cb_cls); |
227 | |||
228 | |||
229 | /** | ||
230 | * Abort testing for service. | ||
231 | * | ||
232 | * @param th test handle | ||
233 | */ | ||
234 | void | ||
235 | GNUNET_CLIENT_service_test_cancel (struct GNUNET_CLIENT_TestHandle *th); | ||
208 | 236 | ||
209 | 237 | ||
210 | #if 0 /* keep Emacsens' auto-indent happy */ | 238 | #if 0 /* keep Emacsens' auto-indent happy */ |
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index eb16e0120..693cfcf12 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h | |||
@@ -1106,7 +1106,7 @@ GNUNET_CRYPTO_rsa_key_get_public (const struct GNUNET_CRYPTO_RsaPrivateKey | |||
1106 | */ | 1106 | */ |
1107 | void | 1107 | void |
1108 | GNUNET_CRYPTO_rsa_get_public_key_hash (struct GNUNET_CRYPTO_RsaPrivateKey *key, | 1108 | GNUNET_CRYPTO_rsa_get_public_key_hash (struct GNUNET_CRYPTO_RsaPrivateKey *key, |
1109 | struct GNUNET_HashCode *id); | 1109 | struct GNUNET_HashCode *id); |
1110 | 1110 | ||
1111 | 1111 | ||
1112 | /** | 1112 | /** |
diff --git a/src/include/gnunet_service_lib.h b/src/include/gnunet_service_lib.h index 39e6a8050..cc224ff16 100644 --- a/src/include/gnunet_service_lib.h +++ b/src/include/gnunet_service_lib.h | |||
@@ -119,8 +119,8 @@ enum GNUNET_SERVICE_Options | |||
119 | */ | 119 | */ |
120 | int | 120 | int |
121 | GNUNET_SERVICE_run (int argc, char *const *argv, const char *service_name, | 121 | GNUNET_SERVICE_run (int argc, char *const *argv, const char *service_name, |
122 | enum GNUNET_SERVICE_Options options, GNUNET_SERVICE_Main task, | 122 | enum GNUNET_SERVICE_Options options, |
123 | void *task_cls); | 123 | GNUNET_SERVICE_Main task, void *task_cls); |
124 | 124 | ||
125 | 125 | ||
126 | /** | 126 | /** |
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c index 699df0670..20452eb8c 100644 --- a/src/namestore/gnunet-namestore.c +++ b/src/namestore/gnunet-namestore.c | |||
@@ -326,12 +326,20 @@ display_record (void *cls, | |||
326 | GNUNET_NAMESTORE_zone_iterator_next (list_it); | 326 | GNUNET_NAMESTORE_zone_iterator_next (list_it); |
327 | } | 327 | } |
328 | 328 | ||
329 | |||
330 | /** | ||
331 | * Function called with the result of the ECC key generation. | ||
332 | * | ||
333 | * @param cls our configuration | ||
334 | * @param pk our private key, NULL on failure | ||
335 | * @param emsg NULL on success, otherwise error message | ||
336 | */ | ||
329 | static void | 337 | static void |
330 | key_generation_cb (void *cls, | 338 | key_generation_cb (void *cls, |
331 | struct GNUNET_CRYPTO_EccPrivateKey *pk, | 339 | struct GNUNET_CRYPTO_EccPrivateKey *pk, |
332 | const char *emsg) | 340 | const char *emsg) |
333 | { | 341 | { |
334 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 342 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
335 | struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pub; | 343 | struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pub; |
336 | uint32_t type; | 344 | uint32_t type; |
337 | void *data = NULL; | 345 | void *data = NULL; |
@@ -599,19 +607,26 @@ key_generation_cb (void *cls, | |||
599 | } | 607 | } |
600 | 608 | ||
601 | 609 | ||
610 | /** | ||
611 | * Function called with the result from the check if the namestore | ||
612 | * service is actually running. If it is, we start the actual | ||
613 | * operation. | ||
614 | * | ||
615 | * @param cls closure with our configuration | ||
616 | * @param result GNUNET_YES if the namestore service is running | ||
617 | */ | ||
602 | static void | 618 | static void |
603 | testservice_task (void *cls, | 619 | testservice_task (void *cls, |
604 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 620 | int result) |
605 | { | 621 | { |
606 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 622 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
607 | 623 | ||
608 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) | 624 | if (GNUNET_YES != result) |
609 | { | 625 | { |
610 | FPRINTF (stderr, _("Service `%s' is not running\n"), "namestore"); | 626 | FPRINTF (stderr, _("Service `%s' is not running\n"), |
611 | return; | 627 | "namestore"); |
628 | return; | ||
612 | } | 629 | } |
613 | |||
614 | |||
615 | if (NULL == keyfile) | 630 | if (NULL == keyfile) |
616 | { | 631 | { |
617 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", | 632 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", |
@@ -625,7 +640,8 @@ testservice_task (void *cls, | |||
625 | _("Using default zone file `%s'\n"), | 640 | _("Using default zone file `%s'\n"), |
626 | keyfile); | 641 | keyfile); |
627 | } | 642 | } |
628 | keygen = GNUNET_CRYPTO_ecc_key_create_start (keyfile, key_generation_cb, cfg); | 643 | keygen = GNUNET_CRYPTO_ecc_key_create_start (keyfile, |
644 | &key_generation_cb, (void *) cfg); | ||
629 | GNUNET_free (keyfile); | 645 | GNUNET_free (keyfile); |
630 | keyfile = NULL; | 646 | keyfile = NULL; |
631 | if (NULL == keygen) | 647 | if (NULL == keygen) |
@@ -653,9 +669,9 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
653 | uri = GNUNET_strdup (args[0]); | 669 | uri = GNUNET_strdup (args[0]); |
654 | 670 | ||
655 | GNUNET_CLIENT_service_test ("namestore", cfg, | 671 | GNUNET_CLIENT_service_test ("namestore", cfg, |
656 | GNUNET_TIME_UNIT_SECONDS, | 672 | GNUNET_TIME_UNIT_SECONDS, |
657 | &testservice_task, | 673 | &testservice_task, |
658 | (void *) cfg); | 674 | (void *) cfg); |
659 | } | 675 | } |
660 | 676 | ||
661 | 677 | ||
diff --git a/src/regex/gnunet-regex-simulation-profiler.c b/src/regex/gnunet-regex-simulation-profiler.c index 32b09eaee..604d25612 100644 --- a/src/regex/gnunet-regex-simulation-profiler.c +++ b/src/regex/gnunet-regex-simulation-profiler.c | |||
@@ -489,7 +489,7 @@ announce_regex (const char *regex) | |||
489 | * @return GNUNET_OK to continue to iterate, | 489 | * @return GNUNET_OK to continue to iterate, |
490 | * GNUNET_SYSERR to abort iteration with error! | 490 | * GNUNET_SYSERR to abort iteration with error! |
491 | */ | 491 | */ |
492 | int | 492 | static int |
493 | policy_filename_cb (void *cls, const char *filename) | 493 | policy_filename_cb (void *cls, const char *filename) |
494 | { | 494 | { |
495 | char *regex; | 495 | char *regex; |
diff --git a/src/regex/regex.c b/src/regex/regex.c index ad8e56b97..711e5458b 100644 --- a/src/regex/regex.c +++ b/src/regex/regex.c | |||
@@ -3478,6 +3478,7 @@ GNUNET_REGEX_iterate_all_edges (struct GNUNET_REGEX_Automaton *a, | |||
3478 | NULL, a->start, iterator, iterator_cls); | 3478 | NULL, a->start, iterator, iterator_cls); |
3479 | } | 3479 | } |
3480 | 3480 | ||
3481 | |||
3481 | /** | 3482 | /** |
3482 | * Create a string with binary IP notation for the given 'addr' in 'str'. | 3483 | * Create a string with binary IP notation for the given 'addr' in 'str'. |
3483 | * | 3484 | * |
diff --git a/src/statistics/gnunet-statistics.c b/src/statistics/gnunet-statistics.c index 2747f7adc..2b2b1c745 100644 --- a/src/statistics/gnunet-statistics.c +++ b/src/statistics/gnunet-statistics.c | |||
@@ -167,42 +167,18 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
167 | } | 167 | } |
168 | 168 | ||
169 | 169 | ||
170 | 170 | /** | |
171 | * Main task that does the actual work. | ||
172 | * | ||
173 | * @param cls closure with our configuration | ||
174 | * @param tc schedueler context | ||
175 | */ | ||
171 | static void | 176 | static void |
172 | resolver_test_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 177 | main_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
173 | { | 178 | { |
174 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 179 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
175 | struct GNUNET_STATISTICS_Handle *h; | 180 | struct GNUNET_STATISTICS_Handle *h; |
176 | 181 | ||
177 | if (NULL != remote_host) | ||
178 | { | ||
179 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) | ||
180 | { | ||
181 | FPRINTF (stderr, _("Trying to connect to remote host, but service `%s' is not running\n"), "resolver"); | ||
182 | return; | ||
183 | } | ||
184 | |||
185 | /* connect to a remote host */ | ||
186 | if (0 == remote_port) | ||
187 | { | ||
188 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, "statistics", "PORT", &remote_port)) | ||
189 | { | ||
190 | FPRINTF (stderr, _("A port is required to connect to host `%s'\n"), remote_host); | ||
191 | return; | ||
192 | } | ||
193 | } | ||
194 | else if (65535 <= remote_port) | ||
195 | { | ||
196 | FPRINTF (stderr, _("A port has to be between 1 and 65535 to connect to host `%s'\n"), remote_host); | ||
197 | return; | ||
198 | } | ||
199 | |||
200 | /* Manipulate configuration */ | ||
201 | GNUNET_CONFIGURATION_set_value_string ((struct GNUNET_CONFIGURATION_Handle *) cfg, "statistics", "UNIXPATH", ""); | ||
202 | GNUNET_CONFIGURATION_set_value_string ((struct GNUNET_CONFIGURATION_Handle *) cfg, "statistics", "HOSTNAME", remote_host); | ||
203 | GNUNET_CONFIGURATION_set_value_number ((struct GNUNET_CONFIGURATION_Handle *) cfg, "statistics", "PORT", remote_port); | ||
204 | } | ||
205 | |||
206 | if (set_value) | 182 | if (set_value) |
207 | { | 183 | { |
208 | if (subsystem == NULL) | 184 | if (subsystem == NULL) |
@@ -264,6 +240,52 @@ resolver_test_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
264 | 240 | ||
265 | 241 | ||
266 | /** | 242 | /** |
243 | * Function called with th test result to see if the resolver is | ||
244 | * running. | ||
245 | * | ||
246 | * @param cls closure with our configuration | ||
247 | * @param result GNUNET_YES if the resolver is running | ||
248 | */ | ||
249 | static void | ||
250 | resolver_test_task (void *cls, | ||
251 | int result) | ||
252 | { | ||
253 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; | ||
254 | |||
255 | if (GNUNET_YES != result) | ||
256 | { | ||
257 | FPRINTF (stderr, | ||
258 | _("Trying to connect to remote host, but service `%s' is not running\n"), "resolver"); | ||
259 | return; | ||
260 | } | ||
261 | /* connect to a remote host */ | ||
262 | if (0 == remote_port) | ||
263 | { | ||
264 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, "statistics", "PORT", &remote_port)) | ||
265 | { | ||
266 | FPRINTF (stderr, _("A port is required to connect to host `%s'\n"), remote_host); | ||
267 | return; | ||
268 | } | ||
269 | } | ||
270 | else if (65535 <= remote_port) | ||
271 | { | ||
272 | FPRINTF (stderr, | ||
273 | _("A port has to be between 1 and 65535 to connect to host `%s'\n"), remote_host); | ||
274 | return; | ||
275 | } | ||
276 | |||
277 | /* Manipulate configuration */ | ||
278 | GNUNET_CONFIGURATION_set_value_string (cfg, | ||
279 | "statistics", "UNIXPATH", ""); | ||
280 | GNUNET_CONFIGURATION_set_value_string (cfg, | ||
281 | "statistics", "HOSTNAME", remote_host); | ||
282 | GNUNET_CONFIGURATION_set_value_number (cfg, | ||
283 | "statistics", "PORT", remote_port); | ||
284 | GNUNET_SCHEDULER_add_now (&main_task, cfg); | ||
285 | } | ||
286 | |||
287 | |||
288 | /** | ||
267 | * Main function that will be run by the scheduler. | 289 | * Main function that will be run by the scheduler. |
268 | * | 290 | * |
269 | * @param cls closure | 291 | * @param cls closure |
@@ -278,20 +300,19 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
278 | set_value = GNUNET_NO; | 300 | set_value = GNUNET_NO; |
279 | if (NULL != args[0]) | 301 | if (NULL != args[0]) |
280 | { | 302 | { |
281 | if (1 != SSCANF (args[0], "%llu", &set_val)) | 303 | if (1 != SSCANF (args[0], "%llu", &set_val)) |
282 | { | 304 | { |
283 | FPRINTF (stderr, _("Invalid argument `%s'\n"), args[0]); | 305 | FPRINTF (stderr, _("Invalid argument `%s'\n"), args[0]); |
284 | ret = 1; | 306 | ret = 1; |
285 | return; | 307 | return; |
286 | } | 308 | } |
287 | set_value = GNUNET_YES; | 309 | set_value = GNUNET_YES; |
288 | } | 310 | } |
289 | |||
290 | if (NULL != remote_host) | 311 | if (NULL != remote_host) |
291 | GNUNET_CLIENT_service_test ("resolver", cfg, GNUNET_TIME_UNIT_SECONDS, &resolver_test_task, (void *) cfg); | 312 | GNUNET_CLIENT_service_test ("resolver", cfg, GNUNET_TIME_UNIT_SECONDS, |
313 | &resolver_test_task, (void *) cfg); | ||
292 | else | 314 | else |
293 | GNUNET_SCHEDULER_add_now (&resolver_test_task, (void *) cfg); | 315 | GNUNET_SCHEDULER_add_now (&main_task, (void *) cfg); |
294 | |||
295 | } | 316 | } |
296 | 317 | ||
297 | 318 | ||
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c index 1c3b5e59c..c03d6a388 100644 --- a/src/transport/gnunet-transport.c +++ b/src/transport/gnunet-transport.c | |||
@@ -792,23 +792,32 @@ void try_connect_cb (void *cls, | |||
792 | } | 792 | } |
793 | 793 | ||
794 | 794 | ||
795 | /** | ||
796 | * Function called with the result of the check if the 'transport' | ||
797 | * service is running. | ||
798 | * | ||
799 | * @param cls closure with our configuration | ||
800 | * @param result GNUNET_YES if transport is running | ||
801 | */ | ||
795 | static void | 802 | static void |
796 | testservice_task (void *cls, | 803 | testservice_task (void *cls, |
797 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 804 | int result) |
798 | { | 805 | { |
799 | int counter = 0; | 806 | int counter = 0; |
800 | ret = 1; | 807 | ret = 1; |
801 | 808 | ||
802 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) | 809 | if (GNUNET_YES != result) |
803 | { | 810 | { |
804 | FPRINTF (stderr, _("Service `%s' is not running\n"), "transport"); | 811 | FPRINTF (stderr, |
805 | return; | 812 | _("Service `%s' is not running\n"), "transport"); |
813 | return; | ||
806 | } | 814 | } |
807 | 815 | ||
808 | if ((NULL != cpid) && (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (cpid, &pid.hashPubKey))) | 816 | if ( (NULL != cpid) && |
817 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (cpid, &pid.hashPubKey))) | ||
809 | { | 818 | { |
810 | FPRINTF (stderr, _("Failed to parse peer identity `%s'\n"), cpid); | 819 | FPRINTF (stderr, _("Failed to parse peer identity `%s'\n"), cpid); |
811 | return; | 820 | return; |
812 | } | 821 | } |
813 | 822 | ||
814 | counter = benchmark_send + benchmark_receive + iterate_connections + | 823 | counter = benchmark_send + benchmark_receive + iterate_connections + |
@@ -970,11 +979,10 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
970 | do_test_configuration (cfg); | 979 | do_test_configuration (cfg); |
971 | return; | 980 | return; |
972 | } | 981 | } |
973 | |||
974 | GNUNET_CLIENT_service_test ("transport", cfg, | 982 | GNUNET_CLIENT_service_test ("transport", cfg, |
975 | GNUNET_TIME_UNIT_SECONDS, | 983 | GNUNET_TIME_UNIT_SECONDS, |
976 | &testservice_task, | 984 | &testservice_task, |
977 | (void *) cfg); | 985 | (void *) cfg); |
978 | } | 986 | } |
979 | 987 | ||
980 | 988 | ||
diff --git a/src/util/client.c b/src/util/client.c index 8b4776201..73b912cc6 100644 --- a/src/util/client.c +++ b/src/util/client.c | |||
@@ -179,27 +179,12 @@ struct GNUNET_CLIENT_Connection | |||
179 | struct GNUNET_CLIENT_TransmitHandle *th; | 179 | struct GNUNET_CLIENT_TransmitHandle *th; |
180 | 180 | ||
181 | /** | 181 | /** |
182 | * Handler for service test completion (NULL unless in service_test) | ||
183 | */ | ||
184 | GNUNET_SCHEDULER_Task test_cb; | ||
185 | |||
186 | /** | ||
187 | * Deadline for calling 'test_cb'. | ||
188 | */ | ||
189 | struct GNUNET_TIME_Absolute test_deadline; | ||
190 | |||
191 | /** | ||
192 | * If we are re-trying and are delaying to do so, | 182 | * If we are re-trying and are delaying to do so, |
193 | * handle to the scheduled task managing the delay. | 183 | * handle to the scheduled task managing the delay. |
194 | */ | 184 | */ |
195 | GNUNET_SCHEDULER_TaskIdentifier receive_task; | 185 | GNUNET_SCHEDULER_TaskIdentifier receive_task; |
196 | 186 | ||
197 | /** | 187 | /** |
198 | * Closure for test_cb (NULL unless in service_test) | ||
199 | */ | ||
200 | void *test_cb_cls; | ||
201 | |||
202 | /** | ||
203 | * Buffer for received message. | 188 | * Buffer for received message. |
204 | */ | 189 | */ |
205 | char *received_buf; | 190 | char *received_buf; |
@@ -639,26 +624,119 @@ GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *client, | |||
639 | 624 | ||
640 | 625 | ||
641 | /** | 626 | /** |
642 | * Report service unavailable. | 627 | * Handle for a test to check if a service is running. |
628 | */ | ||
629 | struct GNUNET_CLIENT_TestHandle | ||
630 | { | ||
631 | /** | ||
632 | * Function to call with the result of the test. | ||
633 | */ | ||
634 | GNUNET_CLIENT_TestResultCallback cb; | ||
635 | |||
636 | /** | ||
637 | * Closure for 'cb'. | ||
638 | */ | ||
639 | void *cb_cls; | ||
640 | |||
641 | /** | ||
642 | * Client connection we are using for the test, if any. | ||
643 | */ | ||
644 | struct GNUNET_CLIENT_Connection *client; | ||
645 | |||
646 | /** | ||
647 | * Handle for the transmission request, if any. | ||
648 | */ | ||
649 | struct GNUNET_CLIENT_TransmitHandle *th; | ||
650 | |||
651 | /** | ||
652 | * Deadline for calling 'cb'. | ||
653 | */ | ||
654 | struct GNUNET_TIME_Absolute test_deadline; | ||
655 | |||
656 | /** | ||
657 | * ID of task used for asynchronous operations. | ||
658 | */ | ||
659 | GNUNET_SCHEDULER_TaskIdentifier task; | ||
660 | |||
661 | /** | ||
662 | * Final result to report back (once known). | ||
663 | */ | ||
664 | int result; | ||
665 | }; | ||
666 | |||
667 | |||
668 | /** | ||
669 | * Abort testing for service. | ||
670 | * | ||
671 | * @param th test handle | ||
672 | */ | ||
673 | void | ||
674 | GNUNET_CLIENT_service_test_cancel (struct GNUNET_CLIENT_TestHandle *th) | ||
675 | { | ||
676 | if (NULL != th->th) | ||
677 | { | ||
678 | GNUNET_CLIENT_notify_transmit_ready_cancel (th->th); | ||
679 | th->th = NULL; | ||
680 | } | ||
681 | if (NULL != th->client) | ||
682 | { | ||
683 | GNUNET_CLIENT_disconnect (th->client); | ||
684 | th->client = NULL; | ||
685 | } | ||
686 | if (GNUNET_SCHEDULER_NO_TASK != th->task) | ||
687 | { | ||
688 | GNUNET_SCHEDULER_cancel (th->task); | ||
689 | th->task = GNUNET_SCHEDULER_NO_TASK; | ||
690 | } | ||
691 | GNUNET_free (th); | ||
692 | } | ||
693 | |||
694 | |||
695 | /** | ||
696 | * Task that reports back the result by calling the callback | ||
697 | * and then cleans up. | ||
698 | * | ||
699 | * @param cls the 'struct GNUNET_CLIENT_TestHandle' | ||
700 | * @param tc scheduler context | ||
701 | */ | ||
702 | static void | ||
703 | report_result (void *cls, | ||
704 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
705 | { | ||
706 | struct GNUNET_CLIENT_TestHandle *th = cls; | ||
707 | |||
708 | th->task = GNUNET_SCHEDULER_NO_TASK; | ||
709 | th->cb (th->cb_cls, th->result); | ||
710 | GNUNET_CLIENT_service_test_cancel (th); | ||
711 | } | ||
712 | |||
713 | |||
714 | /** | ||
715 | * Report service test result asynchronously back to callback. | ||
716 | * | ||
717 | * @param th test handle with the result and the callback | ||
718 | * @param result result to report | ||
643 | */ | 719 | */ |
644 | static void | 720 | static void |
645 | service_test_error (GNUNET_SCHEDULER_Task task, void *task_cls) | 721 | service_test_report (struct GNUNET_CLIENT_TestHandle *th, |
722 | int result) | ||
646 | { | 723 | { |
647 | GNUNET_SCHEDULER_add_continuation (task, task_cls, | 724 | th->result = result; |
648 | GNUNET_SCHEDULER_REASON_TIMEOUT); | 725 | th->task = GNUNET_SCHEDULER_add_now (&report_result, |
726 | th); | ||
649 | } | 727 | } |
650 | 728 | ||
651 | 729 | ||
652 | /** | 730 | /** |
653 | * Receive confirmation from test, service is up. | 731 | * Receive confirmation from test, service is up. |
654 | * | 732 | * |
655 | * @param cls closure | 733 | * @param cls closure with the 'struct GNUNET_CLIENT_TestHandle' |
656 | * @param msg message received, NULL on timeout or fatal error | 734 | * @param msg message received, NULL on timeout or fatal error |
657 | */ | 735 | */ |
658 | static void | 736 | static void |
659 | confirm_handler (void *cls, const struct GNUNET_MessageHeader *msg) | 737 | confirm_handler (void *cls, const struct GNUNET_MessageHeader *msg) |
660 | { | 738 | { |
661 | struct GNUNET_CLIENT_Connection *client = cls; | 739 | struct GNUNET_CLIENT_TestHandle *th = cls; |
662 | 740 | ||
663 | /* We may want to consider looking at the reply in more | 741 | /* We may want to consider looking at the reply in more |
664 | * detail in the future, for example, is this the | 742 | * detail in the future, for example, is this the |
@@ -667,14 +745,12 @@ confirm_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
667 | { | 745 | { |
668 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 746 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
669 | "Received confirmation that service is running.\n"); | 747 | "Received confirmation that service is running.\n"); |
670 | GNUNET_SCHEDULER_add_continuation (client->test_cb, client->test_cb_cls, | 748 | service_test_report (th, GNUNET_YES); |
671 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
672 | } | 749 | } |
673 | else | 750 | else |
674 | { | 751 | { |
675 | service_test_error (client->test_cb, client->test_cb_cls); | 752 | service_test_report (th, GNUNET_NO); |
676 | } | 753 | } |
677 | GNUNET_CLIENT_disconnect (client); | ||
678 | } | 754 | } |
679 | 755 | ||
680 | 756 | ||
@@ -682,7 +758,7 @@ confirm_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
682 | * Send the 'TEST' message to the service. If successful, prepare to | 758 | * Send the 'TEST' message to the service. If successful, prepare to |
683 | * receive the reply. | 759 | * receive the reply. |
684 | * | 760 | * |
685 | * @param cls the 'struct GNUNET_CLIENT_Connection' of the connection to test | 761 | * @param cls the 'struct GNUNET_CLIENT_TestHandle' of the test |
686 | * @param size number of bytes available in buf | 762 | * @param size number of bytes available in buf |
687 | * @param buf where to write the message | 763 | * @param buf where to write the message |
688 | * @return number of bytes written to buf | 764 | * @return number of bytes written to buf |
@@ -690,52 +766,61 @@ confirm_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
690 | static size_t | 766 | static size_t |
691 | write_test (void *cls, size_t size, void *buf) | 767 | write_test (void *cls, size_t size, void *buf) |
692 | { | 768 | { |
693 | struct GNUNET_CLIENT_Connection *client = cls; | 769 | struct GNUNET_CLIENT_TestHandle *th = cls; |
694 | struct GNUNET_MessageHeader *msg; | 770 | struct GNUNET_MessageHeader *msg; |
695 | 771 | ||
772 | th->th = NULL; | ||
696 | if (size < sizeof (struct GNUNET_MessageHeader)) | 773 | if (size < sizeof (struct GNUNET_MessageHeader)) |
697 | { | 774 | { |
698 | LOG (GNUNET_ERROR_TYPE_DEBUG, _("Failure to transmit TEST request.\n")); | 775 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
699 | service_test_error (client->test_cb, client->test_cb_cls); | 776 | "Failed to transmit TEST request.\n"); |
700 | GNUNET_CLIENT_disconnect (client); | 777 | service_test_report (th, GNUNET_NO); |
701 | return 0; /* client disconnected */ | 778 | return 0; /* client disconnected */ |
702 | } | 779 | } |
703 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmitting `%s' request.\n", "TEST"); | 780 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
781 | "Transmitting `%s' request.\n", | ||
782 | "TEST"); | ||
704 | msg = (struct GNUNET_MessageHeader *) buf; | 783 | msg = (struct GNUNET_MessageHeader *) buf; |
705 | msg->type = htons (GNUNET_MESSAGE_TYPE_TEST); | 784 | msg->type = htons (GNUNET_MESSAGE_TYPE_TEST); |
706 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); | 785 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); |
707 | GNUNET_CLIENT_receive (client, &confirm_handler, client, | 786 | GNUNET_CLIENT_receive (th->client, |
787 | &confirm_handler, th, | ||
708 | GNUNET_TIME_absolute_get_remaining | 788 | GNUNET_TIME_absolute_get_remaining |
709 | (client->test_deadline)); | 789 | (th->test_deadline)); |
710 | return sizeof (struct GNUNET_MessageHeader); | 790 | return sizeof (struct GNUNET_MessageHeader); |
711 | } | 791 | } |
712 | 792 | ||
713 | 793 | ||
714 | /** | 794 | /** |
715 | * Test if the service is running. If we are given a UNIXPATH or a local address, | 795 | * Test if the service is running. If we are given a UNIXPATH or a |
716 | * we do this NOT by trying to connect to the service, but by trying to BIND to | 796 | * local address, we do this NOT by trying to connect to the service, |
717 | * the same port. If the BIND fails, we know the service is running. | 797 | * but by trying to BIND to the same port. If the BIND fails, we know |
798 | * the service is running. | ||
718 | * | 799 | * |
719 | * @param service name of the service to wait for | 800 | * @param service name of the service to wait for |
720 | * @param cfg configuration to use | 801 | * @param cfg configuration to use |
721 | * @param timeout how long to wait at most | 802 | * @param timeout how long to wait at most |
722 | * @param task task to run if service is running | 803 | * @param cb function to call with the result |
723 | * (reason will be "PREREQ_DONE" (service running) | 804 | * @param cb_cls closure for 'cb' |
724 | * or "TIMEOUT" (service not known to be running)) | 805 | * @return handle to cancel the test |
725 | * @param task_cls closure for task | ||
726 | */ | 806 | */ |
727 | void | 807 | struct GNUNET_CLIENT_TestHandle * |
728 | GNUNET_CLIENT_service_test (const char *service, | 808 | GNUNET_CLIENT_service_test (const char *service, |
729 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 809 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
730 | struct GNUNET_TIME_Relative timeout, | 810 | struct GNUNET_TIME_Relative timeout, |
731 | GNUNET_SCHEDULER_Task task, void *task_cls) | 811 | GNUNET_CLIENT_TestResultCallback cb, void *cb_cls) |
732 | { | 812 | { |
813 | struct GNUNET_CLIENT_TestHandle *th; | ||
733 | char *hostname; | 814 | char *hostname; |
734 | unsigned long long port; | 815 | unsigned long long port; |
735 | struct GNUNET_NETWORK_Handle *sock; | 816 | struct GNUNET_NETWORK_Handle *sock; |
736 | struct GNUNET_CLIENT_Connection *client; | ||
737 | 817 | ||
738 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Testing if service `%s' is running.\n", | 818 | th = GNUNET_new (struct GNUNET_CLIENT_TestHandle); |
819 | th->cb = cb; | ||
820 | th->cb_cls = cb_cls; | ||
821 | th->test_deadline = GNUNET_TIME_relative_to_absolute (timeout); | ||
822 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
823 | "Testing if service `%s' is running.\n", | ||
739 | service); | 824 | service); |
740 | #ifdef AF_UNIX | 825 | #ifdef AF_UNIX |
741 | { | 826 | { |
@@ -783,9 +868,8 @@ GNUNET_CLIENT_service_test (const char *service, | |||
783 | /* failed to bind => service must be running */ | 868 | /* failed to bind => service must be running */ |
784 | GNUNET_free (unixpath); | 869 | GNUNET_free (unixpath); |
785 | (void) GNUNET_NETWORK_socket_close (sock); | 870 | (void) GNUNET_NETWORK_socket_close (sock); |
786 | GNUNET_SCHEDULER_add_continuation (task, task_cls, | 871 | service_test_report (th, GNUNET_YES); |
787 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 872 | return th; |
788 | return; | ||
789 | } | 873 | } |
790 | (void) GNUNET_NETWORK_socket_close (sock); | 874 | (void) GNUNET_NETWORK_socket_close (sock); |
791 | /* let's try IP */ | 875 | /* let's try IP */ |
@@ -804,8 +888,8 @@ GNUNET_CLIENT_service_test (const char *service, | |||
804 | &hostname))) | 888 | &hostname))) |
805 | { | 889 | { |
806 | /* UNIXPATH failed (if possible) AND IP failed => error */ | 890 | /* UNIXPATH failed (if possible) AND IP failed => error */ |
807 | service_test_error (task, task_cls); | 891 | service_test_report (th, GNUNET_SYSERR); |
808 | return; | 892 | return th; |
809 | } | 893 | } |
810 | 894 | ||
811 | if (0 == strcmp ("localhost", hostname) | 895 | if (0 == strcmp ("localhost", hostname) |
@@ -834,9 +918,8 @@ GNUNET_CLIENT_service_test (const char *service, | |||
834 | /* failed to bind => service must be running */ | 918 | /* failed to bind => service must be running */ |
835 | GNUNET_free (hostname); | 919 | GNUNET_free (hostname); |
836 | (void) GNUNET_NETWORK_socket_close (sock); | 920 | (void) GNUNET_NETWORK_socket_close (sock); |
837 | GNUNET_SCHEDULER_add_continuation (task, task_cls, | 921 | service_test_report (th, GNUNET_YES); |
838 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 922 | return th; |
839 | return; | ||
840 | } | 923 | } |
841 | (void) GNUNET_NETWORK_socket_close (sock); | 924 | (void) GNUNET_NETWORK_socket_close (sock); |
842 | } | 925 | } |
@@ -868,9 +951,8 @@ GNUNET_CLIENT_service_test (const char *service, | |||
868 | /* failed to bind => service must be running */ | 951 | /* failed to bind => service must be running */ |
869 | GNUNET_free (hostname); | 952 | GNUNET_free (hostname); |
870 | (void) GNUNET_NETWORK_socket_close (sock); | 953 | (void) GNUNET_NETWORK_socket_close (sock); |
871 | GNUNET_SCHEDULER_add_continuation (task, task_cls, | 954 | service_test_report (th, GNUNET_YES); |
872 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | 955 | return th; |
873 | return; | ||
874 | } | 956 | } |
875 | (void) GNUNET_NETWORK_socket_close (sock); | 957 | (void) GNUNET_NETWORK_socket_close (sock); |
876 | } | 958 | } |
@@ -885,35 +967,33 @@ GNUNET_CLIENT_service_test (const char *service, | |||
885 | { | 967 | { |
886 | /* all binds succeeded => claim service not running right now */ | 968 | /* all binds succeeded => claim service not running right now */ |
887 | GNUNET_free_non_null (hostname); | 969 | GNUNET_free_non_null (hostname); |
888 | service_test_error (task, task_cls); | 970 | service_test_report (th, GNUNET_NO); |
889 | return; | 971 | return th; |
890 | } | 972 | } |
891 | GNUNET_free_non_null (hostname); | 973 | GNUNET_free_non_null (hostname); |
892 | 974 | ||
893 | /* non-localhost, try 'connect' method */ | 975 | /* non-localhost, try 'connect' method */ |
894 | client = GNUNET_CLIENT_connect (service, cfg); | 976 | th->client = GNUNET_CLIENT_connect (service, cfg); |
895 | if (NULL == client) | 977 | if (NULL == th->client) |
896 | { | 978 | { |
897 | LOG (GNUNET_ERROR_TYPE_INFO, | 979 | LOG (GNUNET_ERROR_TYPE_INFO, |
898 | _("Could not connect to service `%s', must not be running.\n"), | 980 | _("Could not connect to service `%s', configuration broken.\n"), |
899 | service); | 981 | service); |
900 | service_test_error (task, task_cls); | 982 | service_test_report (th, GNUNET_SYSERR); |
901 | return; | 983 | return th; |
902 | } | 984 | } |
903 | client->test_cb = task; | 985 | th->th = GNUNET_CLIENT_notify_transmit_ready (th->client, |
904 | client->test_cb_cls = task_cls; | 986 | sizeof (struct GNUNET_MessageHeader), |
905 | client->test_deadline = GNUNET_TIME_relative_to_absolute (timeout); | 987 | timeout, GNUNET_YES, |
906 | if (NULL == GNUNET_CLIENT_notify_transmit_ready (client, | 988 | &write_test, th); |
907 | sizeof (struct GNUNET_MessageHeader), | 989 | if (NULL == th->th) |
908 | timeout, GNUNET_YES, &write_test, | ||
909 | client)) | ||
910 | { | 990 | { |
911 | LOG (GNUNET_ERROR_TYPE_WARNING, | 991 | LOG (GNUNET_ERROR_TYPE_WARNING, |
912 | _("Failure to transmit request to service `%s'\n"), service); | 992 | _("Failure to transmit request to service `%s'\n"), service); |
913 | service_test_error (task, task_cls); | 993 | service_test_report (th, GNUNET_SYSERR); |
914 | GNUNET_CLIENT_disconnect (client); | 994 | return th; |
915 | return; | ||
916 | } | 995 | } |
996 | return th; | ||
917 | } | 997 | } |
918 | 998 | ||
919 | 999 | ||
@@ -1246,5 +1326,4 @@ GNUNET_CLIENT_transmit_and_get_response (struct GNUNET_CLIENT_Connection *client | |||
1246 | } | 1326 | } |
1247 | 1327 | ||
1248 | 1328 | ||
1249 | |||
1250 | /* end of client.c */ | 1329 | /* end of client.c */ |
diff --git a/src/util/test_service.c b/src/util/test_service.c index be49d1877..bdd3d8521 100644 --- a/src/util/test_service.c +++ b/src/util/test_service.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2009 Christian Grothoff (and other contributing authors) | 3 | (C) 2009, 2013 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -20,6 +20,7 @@ | |||
20 | /** | 20 | /** |
21 | * @file util/test_service.c | 21 | * @file util/test_service.c |
22 | * @brief tests for service.c | 22 | * @brief tests for service.c |
23 | * @author Christian Grothoff | ||
23 | */ | 24 | */ |
24 | #include "platform.h" | 25 | #include "platform.h" |
25 | #include "gnunet_common.h" | 26 | #include "gnunet_common.h" |
@@ -33,6 +34,9 @@ | |||
33 | 34 | ||
34 | #define PORT 12435 | 35 | #define PORT 12435 |
35 | 36 | ||
37 | /** | ||
38 | * Message type we use for testing. | ||
39 | */ | ||
36 | #define MY_TYPE 256 | 40 | #define MY_TYPE 256 |
37 | 41 | ||
38 | static struct GNUNET_SERVICE_Context *sctx; | 42 | static struct GNUNET_SERVICE_Context *sctx; |
@@ -42,8 +46,6 @@ static int ok = 1; | |||
42 | static struct GNUNET_CLIENT_Connection *client; | 46 | static struct GNUNET_CLIENT_Connection *client; |
43 | 47 | ||
44 | 48 | ||
45 | |||
46 | |||
47 | static void | 49 | static void |
48 | do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 50 | do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
49 | { | 51 | { |
@@ -87,11 +89,12 @@ build_msg (void *cls, size_t size, void *buf) | |||
87 | 89 | ||
88 | 90 | ||
89 | static void | 91 | static void |
90 | ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 92 | ready (void *cls, |
93 | int result) | ||
91 | { | 94 | { |
92 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 95 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
93 | 96 | ||
94 | GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)); | 97 | GNUNET_assert (GNUNET_YES == result); |
95 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service confirmed running\n"); | 98 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service confirmed running\n"); |
96 | client = GNUNET_CLIENT_connect ("test_service", cfg); | 99 | client = GNUNET_CLIENT_connect ("test_service", cfg); |
97 | GNUNET_assert (client != NULL); | 100 | GNUNET_assert (client != NULL); |
@@ -108,8 +111,7 @@ static void | |||
108 | recv_cb (void *cls, struct GNUNET_SERVER_Client *sc, | 111 | recv_cb (void *cls, struct GNUNET_SERVER_Client *sc, |
109 | const struct GNUNET_MessageHeader *message) | 112 | const struct GNUNET_MessageHeader *message) |
110 | { | 113 | { |
111 | if (NULL == message) | 114 | GNUNET_assert (NULL != message); |
112 | return; | ||
113 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving client message...\n"); | 115 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving client message...\n"); |
114 | GNUNET_SERVER_receive_done (sc, GNUNET_OK); | 116 | GNUNET_SERVER_receive_done (sc, GNUNET_OK); |
115 | GNUNET_SCHEDULER_add_now (&do_stop, NULL); | 117 | GNUNET_SCHEDULER_add_now (&do_stop, NULL); |
@@ -156,13 +158,15 @@ check () | |||
156 | return ok; | 158 | return ok; |
157 | } | 159 | } |
158 | 160 | ||
161 | |||
159 | static void | 162 | static void |
160 | ready6 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 163 | ready6 (void *cls, |
164 | int result) | ||
161 | { | 165 | { |
162 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 166 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
163 | 167 | ||
164 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "V6 ready\n"); | 168 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "V6 ready\n"); |
165 | GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)); | 169 | GNUNET_assert (GNUNET_YES == result); |
166 | client = GNUNET_CLIENT_connect ("test_service6", cfg); | 170 | client = GNUNET_CLIENT_connect ("test_service6", cfg); |
167 | GNUNET_assert (client != NULL); | 171 | GNUNET_assert (client != NULL); |
168 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "V6 client connected\n"); | 172 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "V6 client connected\n"); |
@@ -172,6 +176,7 @@ ready6 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
172 | &build_msg, NULL); | 176 | &build_msg, NULL); |
173 | } | 177 | } |
174 | 178 | ||
179 | |||
175 | static void | 180 | static void |
176 | runner6 (void *cls, struct GNUNET_SERVER_Handle *server, | 181 | runner6 (void *cls, struct GNUNET_SERVER_Handle *server, |
177 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 182 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
@@ -182,6 +187,7 @@ runner6 (void *cls, struct GNUNET_SERVER_Handle *server, | |||
182 | &ready6, (void *) cfg); | 187 | &ready6, (void *) cfg); |
183 | } | 188 | } |
184 | 189 | ||
190 | |||
185 | /** | 191 | /** |
186 | * Main method, starts scheduler with task1, | 192 | * Main method, starts scheduler with task1, |
187 | * checks that "ok" is correct at the end. | 193 | * checks that "ok" is correct at the end. |
@@ -205,7 +211,6 @@ check6 () | |||
205 | } | 211 | } |
206 | 212 | ||
207 | 213 | ||
208 | |||
209 | static void | 214 | static void |
210 | start_stop_main (void *cls, char *const *args, const char *cfgfile, | 215 | start_stop_main (void *cls, char *const *args, const char *cfgfile, |
211 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 216 | const struct GNUNET_CONFIGURATION_Handle *cfg) |