aboutsummaryrefslogtreecommitdiff
path: root/src/statistics
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-06-05 21:33:58 +0000
committerChristian Grothoff <christian@grothoff.org>2013-06-05 21:33:58 +0000
commita998e0abbd220035bdb333388da229852980e2cc (patch)
treeaddf062abb3cc68ab1103a415fbdec315dd54a63 /src/statistics
parent4ce2d673d41ad8a8b9e5389b5b97ecb5e77f190d (diff)
downloadgnunet-a998e0abbd220035bdb333388da229852980e2cc.tar.gz
gnunet-a998e0abbd220035bdb333388da229852980e2cc.zip
-cleaning up client api to test for service availability
Diffstat (limited to 'src/statistics')
-rw-r--r--src/statistics/gnunet-statistics.c107
1 files changed, 64 insertions, 43 deletions
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 */
171static void 176static void
172resolver_test_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 177main_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 */
249static void
250resolver_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