aboutsummaryrefslogtreecommitdiff
path: root/src/ats-tool
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-11-19 15:54:08 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-11-19 15:54:08 +0000
commit6c937680c28892c73b6fd380d4ee75e5251274fb (patch)
treebb5ba75a6ddd029752e601621c79cb5e8baa9396 /src/ats-tool
parent1d65d71fb25ec9281f69ea4df5c907d79878d840 (diff)
downloadgnunet-6c937680c28892c73b6fd380d4ee75e5251274fb.tar.gz
gnunet-6c937680c28892c73b6fd380d4ee75e5251274fb.zip
- changes
Diffstat (limited to 'src/ats-tool')
-rw-r--r--src/ats-tool/gnunet-ats.c175
1 files changed, 120 insertions, 55 deletions
diff --git a/src/ats-tool/gnunet-ats.c b/src/ats-tool/gnunet-ats.c
index 902dc4a20..0ca28724a 100644
--- a/src/ats-tool/gnunet-ats.c
+++ b/src/ats-tool/gnunet-ats.c
@@ -36,8 +36,6 @@
36static int ret; 36static int ret;
37static int results; 37static int results;
38static int resolve_addresses_numeric; 38static int resolve_addresses_numeric;
39static int monitor;
40
41/** 39/**
42 * For which peer should we change preference values? 40 * For which peer should we change preference values?
43 */ 41 */
@@ -54,16 +52,29 @@ static int verbose;
54/** 52/**
55 * List only addresses currently used (active) 53 * List only addresses currently used (active)
56 */ 54 */
57static int list_used; 55static int op_list_used;
58 56
59/** 57/**
60 * List all addresses 58 * List all addresses
61 */ 59 */
62static int list_all; 60static int op_list_all;
61
62/**
63 * List all addresses
64 */
65static int op_set_pref;
66
67/**
68 * Monitor addresses used
69 */
70static int op_monitor;
71
63 72
64 73
65static struct GNUNET_ATS_PerformanceHandle *ph; 74static struct GNUNET_ATS_PerformanceHandle *ph;
66 75
76struct GNUNET_ATS_AddressListHandle *alh;
77
67static struct GNUNET_CONFIGURATION_Handle *cfg; 78static struct GNUNET_CONFIGURATION_Handle *cfg;
68 79
69GNUNET_SCHEDULER_TaskIdentifier end_task; 80GNUNET_SCHEDULER_TaskIdentifier end_task;
@@ -183,6 +194,15 @@ void ats_perf_cb (void *cls,
183 results++; 194 results++;
184} 195}
185 196
197void la_cb (void *cls,
198 const struct GNUNET_HELLO_Address * address,
199 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
200 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
201 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
202{
203
204}
205
186void end (void *cls, 206void end (void *cls,
187 const struct GNUNET_SCHEDULER_TaskContext *tc) 207 const struct GNUNET_SCHEDULER_TaskContext *tc)
188{ 208{
@@ -190,6 +210,12 @@ void end (void *cls,
190 struct PendingResolutions * next; 210 struct PendingResolutions * next;
191 unsigned int pending; 211 unsigned int pending;
192 212
213 if (NULL != alh)
214 {
215 GNUNET_ATS_performance_list_addresses_cancel (alh);
216 alh = NULL;
217 }
218
193 GNUNET_ATS_performance_done (ph); 219 GNUNET_ATS_performance_done (ph);
194 ph = NULL; 220 ph = NULL;
195 221
@@ -225,23 +251,8 @@ void testservice_ats (void *cls,
225 return; 251 return;
226 } 252 }
227 253
228 if ((GNUNET_YES == list_all) && (GNUNET_YES ==list_used))
229 {
230 FPRINTF (stderr, _("Please select one operation : %s or %s \n"),"--used", "--all");
231 return;
232 }
233
234 if ((GNUNET_NO == list_all) && (GNUNET_NO == list_used))
235 list_used = GNUNET_YES; /* set default */
236
237
238 if (GNUNET_YES == list_all)
239 {
240 FPRINTF (stderr, _("NOT YET IMPLEMENTED\n"));
241 return;
242 }
243
244 results = 0; 254 results = 0;
255
245 if (NULL != pid_str) 256 if (NULL != pid_str)
246 { 257 {
247 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (pid_str, &pid.hashPubKey)) 258 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (pid_str, &pid.hashPubKey))
@@ -254,44 +265,95 @@ void testservice_ats (void *cls,
254 FPRINTF (stderr, "%s", _("Type required\n")); 265 FPRINTF (stderr, "%s", _("Type required\n"));
255 return; 266 return;
256 } 267 }
268 }
257 269
258 for (c = 0; c<strlen(type_str); c++) 270 c = op_list_all + op_list_used + op_monitor + op_set_pref;
259 if (isupper (type_str[c])) 271 if ((1 < c))
260 type_str[c] = tolower (type_str[c]); 272 {
273 FPRINTF (stderr, _("Please select one operation : %s or %s or %s or %s\n"),
274 "--used", "--all", "--monitor", "--preference");
275 return;
276 }
277 if ((0 == c))
278 op_list_used = GNUNET_YES; /* set default */
261 279
262 280
263 if (0 == strcasecmp("latency", type_str)) 281 if (op_list_all)
264 type = GNUNET_ATS_PREFERENCE_LATENCY; 282 {
265 else if (0 == strcasecmp("bandwidth", type_str)) 283 ph = GNUNET_ATS_performance_init (cfg, NULL, NULL);
266 type = GNUNET_ATS_PREFERENCE_BANDWIDTH; 284 if (NULL == ph)
267 else 285 {
268 { 286 fprintf (stderr, _("Cannot connect to ATS service, exiting...\n"));
269 FPRINTF (stderr, "%s", _("Type required\n")); 287 return;
270 return; 288 }
271 }
272 289
273 /* set */ 290 alh = GNUNET_ATS_performance_list_addresses (ph,
274 ph = GNUNET_ATS_performance_init (cfg, NULL, NULL); 291 (NULL == pid_str) ? NULL : &pid,
275 if (NULL == ph) 292 GNUNET_YES, la_cb, NULL);
276 fprintf (stderr, _("Cannot connect to ATS service, exiting...\n")); 293 if (NULL == alh)
294 {
295 fprintf (stderr, _("Cannot issue request to ATS service, exiting...\n"));
296 end_task = GNUNET_SCHEDULER_add_now (&end, NULL);
297 return;
298 }
277 299
278 GNUNET_ATS_change_preference (ph, &pid, type, (double) value, GNUNET_ATS_PREFERENCE_END); 300 end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &end, NULL);
301
302 }
303 else if (op_list_used)
304 {
305 ph = GNUNET_ATS_performance_init (cfg, NULL, NULL);
306 if (NULL == ph)
307 fprintf (stderr, _("Cannot connect to ATS service, exiting...\n"));
308
309 alh = GNUNET_ATS_performance_list_addresses (ph,
310 (NULL == pid_str) ? NULL : &pid,
311 GNUNET_NO, la_cb, NULL);
312 if (NULL == alh)
313 {
314 fprintf (stderr, _("Cannot issue request to ATS service, exiting...\n"));
315 end_task = GNUNET_SCHEDULER_add_now (&end, NULL);
316 return;
317 }
279 318
280 end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &end, NULL);
281 }
282 else
283 {
284 ph = GNUNET_ATS_performance_init (cfg, ats_perf_cb, NULL);
285 if (NULL == ph)
286 fprintf (stderr, _("Cannot connect to ATS service, exiting...\n"));
287 319
288 if (GNUNET_NO == monitor)
289 end_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end, NULL);
290 else
291 end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &end, NULL); 320 end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &end, NULL);
292 } 321 }
322 else if (op_monitor)
323 {
324 ph = GNUNET_ATS_performance_init (cfg, ats_perf_cb, NULL);
325 if (NULL == ph)
326 fprintf (stderr, _("Cannot connect to ATS service, exiting...\n"));
327 end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &end, NULL);
328
329 }
330 else if (op_set_pref)
331 {
332 for (c = 0; c<strlen(type_str); c++)
333 {
334 if (isupper (type_str[c]))
335 type_str[c] = tolower (type_str[c]);
336 }
337
338 if (0 == strcasecmp("latency", type_str))
339 type = GNUNET_ATS_PREFERENCE_LATENCY;
340 else if (0 == strcasecmp("bandwidth", type_str))
341 type = GNUNET_ATS_PREFERENCE_BANDWIDTH;
342 else
343 {
344 FPRINTF (stderr, "%s", _("Type required\n"));
345 return;
346 }
347
348 /* set */
349 ph = GNUNET_ATS_performance_init (cfg, NULL, NULL);
350 if (NULL == ph)
351 fprintf (stderr, _("Cannot connect to ATS service, exiting...\n"));
293 352
353 GNUNET_ATS_change_preference (ph, &pid, type, (double) value, GNUNET_ATS_PREFERENCE_END);
294 354
355 end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &end, NULL);
356 }
295 ret = 1; 357 ret = 1;
296} 358}
297 359
@@ -327,25 +389,28 @@ main (int argc, char *const *argv)
327{ 389{
328 int res; 390 int res;
329 resolve_addresses_numeric = GNUNET_NO; 391 resolve_addresses_numeric = GNUNET_NO;
330 monitor = GNUNET_NO; 392 op_monitor = GNUNET_NO;
331 list_all = GNUNET_NO; 393 op_list_all = GNUNET_NO;
332 list_used = GNUNET_NO; 394 op_list_used = GNUNET_NO;
333 395
334 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 396 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
335 {'u', "used", NULL, 397 {'u', "used", NULL,
336 gettext_noop ("get list of active addresses currently used"), 398 gettext_noop ("get list of active addresses currently used"),
337 0, &GNUNET_GETOPT_set_one, &list_used}, 399 0, &GNUNET_GETOPT_set_one, &op_list_used},
338 {'a', "all", NULL, 400 {'a', "all", NULL,
339 gettext_noop ("get list of all active addresses"), 401 gettext_noop ("get list of all active addresses"),
340 0, &GNUNET_GETOPT_set_one, &list_all}, 402 0, &GNUNET_GETOPT_set_one, &op_list_all},
341 {'n', "numeric", NULL, 403 {'n', "numeric", NULL,
342 gettext_noop ("do not resolve IP addresses to hostnames"), 404 gettext_noop ("do not resolve IP addresses to hostnames"),
343 0, &GNUNET_GETOPT_set_one, &resolve_addresses_numeric}, 405 0, &GNUNET_GETOPT_set_one, &resolve_addresses_numeric},
344 {'m', "monitor", NULL, 406 {'m', "monitor", NULL,
345 gettext_noop ("monitor mode"), 407 gettext_noop ("monitor mode"),
346 0, &GNUNET_GETOPT_set_one, &monitor}, 408 0, &GNUNET_GETOPT_set_one, &op_monitor},
347 {'p', "preference", "PEER", 409 {'p', "preference", NULL,
348 gettext_noop ("set preference for the given peer"), 410 gettext_noop ("set preference for the given peer"),
411 0, &GNUNET_GETOPT_set_one, &op_set_pref},
412 {'i', "id", "TYPE",
413 gettext_noop ("peer id"),
349 1, &GNUNET_GETOPT_set_string, &pid_str}, 414 1, &GNUNET_GETOPT_set_string, &pid_str},
350 {'t', "type", "TYPE", 415 {'t', "type", "TYPE",
351 gettext_noop ("preference type to set: latency | bandwidth"), 416 gettext_noop ("preference type to set: latency | bandwidth"),