diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-11-16 15:24:36 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-11-16 15:24:36 +0000 |
commit | 5f5b69feb3ca531788f2c3b102fbe17a02d5be38 (patch) | |
tree | ee0c5bdd0515d1ee8b22ce4ce4db506fc7d21b0c /src | |
parent | f9226cec1d04a4edd32f7b0967c67c7b559393be (diff) | |
download | gnunet-5f5b69feb3ca531788f2c3b102fbe17a02d5be38.tar.gz gnunet-5f5b69feb3ca531788f2c3b102fbe17a02d5be38.zip |
- checking for resolver when trying to connect to remote host
Diffstat (limited to 'src')
-rw-r--r-- | src/statistics/gnunet-statistics.c | 83 |
1 files changed, 64 insertions, 19 deletions
diff --git a/src/statistics/gnunet-statistics.c b/src/statistics/gnunet-statistics.c index 97d867272..0cd55342e 100644 --- a/src/statistics/gnunet-statistics.c +++ b/src/statistics/gnunet-statistics.c | |||
@@ -73,6 +73,15 @@ static char *remote_host; | |||
73 | */ | 73 | */ |
74 | static unsigned long long remote_port; | 74 | static unsigned long long remote_port; |
75 | 75 | ||
76 | /** | ||
77 | * Value to set | ||
78 | */ | ||
79 | static unsigned long long set_val; | ||
80 | |||
81 | /** | ||
82 | * Set operation | ||
83 | */ | ||
84 | static int set_value; | ||
76 | 85 | ||
77 | /** | 86 | /** |
78 | * Callback function to process statistic values. | 87 | * Callback function to process statistic values. |
@@ -158,23 +167,21 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
158 | } | 167 | } |
159 | 168 | ||
160 | 169 | ||
161 | /** | 170 | |
162 | * Main function that will be run by the scheduler. | ||
163 | * | ||
164 | * @param cls closure | ||
165 | * @param args remaining command-line arguments | ||
166 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
167 | * @param cfg configuration | ||
168 | */ | ||
169 | static void | 171 | static void |
170 | run (void *cls, char *const *args, const char *cfgfile, | 172 | resolver_test_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
171 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
172 | { | 173 | { |
174 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; | ||
173 | struct GNUNET_STATISTICS_Handle *h; | 175 | struct GNUNET_STATISTICS_Handle *h; |
174 | unsigned long long val; | ||
175 | 176 | ||
176 | if (NULL != remote_host) | 177 | if (NULL != remote_host) |
177 | { | 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 | |||
178 | /* connect to a remote host */ | 185 | /* connect to a remote host */ |
179 | if (0 == remote_port) | 186 | if (0 == remote_port) |
180 | { | 187 | { |
@@ -196,12 +203,17 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
196 | GNUNET_CONFIGURATION_set_value_number ((struct GNUNET_CONFIGURATION_Handle *) cfg, "statistics", "PORT", remote_port); | 203 | GNUNET_CONFIGURATION_set_value_number ((struct GNUNET_CONFIGURATION_Handle *) cfg, "statistics", "PORT", remote_port); |
197 | } | 204 | } |
198 | 205 | ||
199 | if (args[0] != NULL) | 206 | if (set_value) |
200 | { | 207 | { |
201 | if ((1 != SSCANF (args[0], "%llu", &val)) || (subsystem == NULL) || | 208 | if (subsystem == NULL) |
202 | (name == NULL)) | 209 | { |
210 | FPRINTF (stderr, _("Missing argument: subsystem \n")); | ||
211 | ret = 1; | ||
212 | return; | ||
213 | } | ||
214 | if (name == NULL) | ||
203 | { | 215 | { |
204 | FPRINTF (stderr, _("Invalid argument `%s'\n"), args[0]); | 216 | FPRINTF (stderr, _("Missing argument: name\n")); |
205 | ret = 1; | 217 | ret = 1; |
206 | return; | 218 | return; |
207 | } | 219 | } |
@@ -211,7 +223,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
211 | ret = 1; | 223 | ret = 1; |
212 | return; | 224 | return; |
213 | } | 225 | } |
214 | GNUNET_STATISTICS_set (h, name, (uint64_t) val, persistent); | 226 | GNUNET_STATISTICS_set (h, name, (uint64_t) set_val, persistent); |
215 | GNUNET_STATISTICS_destroy (h, GNUNET_YES); | 227 | GNUNET_STATISTICS_destroy (h, GNUNET_YES); |
216 | h = NULL; | 228 | h = NULL; |
217 | return; | 229 | return; |
@@ -234,7 +246,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
234 | { | 246 | { |
235 | printf (_("No subsystem or name given\n")); | 247 | printf (_("No subsystem or name given\n")); |
236 | GNUNET_STATISTICS_destroy (h, GNUNET_NO); | 248 | GNUNET_STATISTICS_destroy (h, GNUNET_NO); |
237 | h = NULL; | 249 | h = NULL; |
238 | ret = 1; | 250 | ret = 1; |
239 | return; | 251 | return; |
240 | } | 252 | } |
@@ -245,8 +257,41 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
245 | return; | 257 | return; |
246 | } | 258 | } |
247 | } | 259 | } |
248 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 260 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
249 | &shutdown_task, h); | 261 | &shutdown_task, h); |
262 | |||
263 | } | ||
264 | |||
265 | |||
266 | /** | ||
267 | * Main function that will be run by the scheduler. | ||
268 | * | ||
269 | * @param cls closure | ||
270 | * @param args remaining command-line arguments | ||
271 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
272 | * @param cfg configuration | ||
273 | */ | ||
274 | static void | ||
275 | run (void *cls, char *const *args, const char *cfgfile, | ||
276 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
277 | { | ||
278 | set_value = GNUNET_NO; | ||
279 | if (NULL != args[0]) | ||
280 | { | ||
281 | if (1 != SSCANF (args[0], "%llu", &set_val)) | ||
282 | { | ||
283 | FPRINTF (stderr, _("Invalid argument `%s'\n"), args[0]); | ||
284 | ret = 1; | ||
285 | return; | ||
286 | } | ||
287 | set_value = GNUNET_YES; | ||
288 | } | ||
289 | |||
290 | if (NULL != remote_host) | ||
291 | GNUNET_CLIENT_service_test ("resolver", cfg, GNUNET_TIME_UNIT_SECONDS, &resolver_test_task, (void *) cfg); | ||
292 | else | ||
293 | GNUNET_SCHEDULER_add_now (&resolver_test_task, (void *) cfg); | ||
294 | |||
250 | } | 295 | } |
251 | 296 | ||
252 | 297 | ||