-ignore
[oweals/gnunet.git] / src / ats-tool / gnunet-ats.c
1 /*
2  This file is part of GNUnet.
3  (C) 2009--2013 Christian Grothoff (and other contributing authors)
4
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
7  by the Free Software Foundation; either version 3, or (at your
8  option) any later version.
9
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  General Public License for more details.
14
15  You should have received a copy of the GNU General Public License
16  along with GNUnet; see the file COPYING.  If not, write to the
17  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  Boston, MA 02111-1307, USA.
19  */
20
21 /**
22  * @file ats-tool/gnunet-ats.c
23  * @brief ATS command line tool
24  * @author Matthias Wachs
25  */
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
28 #include "gnunet_ats_service.h"
29 #include "gnunet_transport_service.h"
30
31 #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5)
32
33 #define BIG_M_STRING "unlimited"
34
35 /**
36  * Final status code.
37  */
38 static int ret;
39 static int results;
40 static int resolve_addresses_numeric;
41 static int receive_done;
42
43 /**
44  * For which peer should we change preference values?
45  */
46 static char *pid_str;
47
48 static char *type_str;
49 static unsigned int value;
50 static int pending;
51
52 /**
53  * Print verbose ATS information
54  */
55 static int verbose;
56
57 /**
58  * List only addresses currently used (active)
59  */
60 static int op_list_used;
61
62 /**
63  * List all addresses
64  */
65 static int op_list_all;
66
67 /**
68  * List all addresses
69  */
70 static int op_set_pref;
71
72 /**
73  * Print quotas configured
74  */
75 static int op_print_quotas;
76
77 /**
78  * Monitor addresses used
79  */
80 static int op_monitor;
81
82 static struct GNUNET_ATS_PerformanceHandle *ph;
83
84 static struct GNUNET_ATS_AddressListHandle *alh;
85
86 static struct GNUNET_CONFIGURATION_Handle *cfg;
87
88 static GNUNET_SCHEDULER_TaskIdentifier end_task;
89
90 static struct GNUNET_CONTAINER_MultiPeerMap *addresses;
91
92
93 struct PendingResolutions
94 {
95   struct PendingResolutions *next;
96   struct PendingResolutions *prev;
97
98   struct GNUNET_HELLO_Address *address;
99   struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out;
100   struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in;
101
102   struct GNUNET_ATS_Information *ats;
103   uint32_t ats_count;
104
105   struct GNUNET_TRANSPORT_AddressToStringContext * tats_ctx;
106 };
107
108 struct ATSAddress
109 {
110   struct GNUNET_HELLO_Address *address;
111   struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out;
112   struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in;
113 };
114
115
116
117 static struct PendingResolutions *head;
118
119 static struct PendingResolutions *tail;
120
121 static int
122 free_addr_it (void *cls,
123     const struct GNUNET_PeerIdentity *key,
124     void *value)
125 {
126   struct ATSAddress *a = value;
127   GNUNET_break (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (addresses,
128       key, a));
129   GNUNET_HELLO_address_free (a->address);
130   GNUNET_free (a);
131   return GNUNET_OK;
132 }
133
134 static void
135 end(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
136 {
137   struct PendingResolutions * pr;
138   struct PendingResolutions * next;
139   unsigned int pending;
140
141   if (NULL != alh)
142   {
143     GNUNET_ATS_performance_list_addresses_cancel (alh);
144     alh = NULL;
145   }
146
147   if (NULL != ph)
148   {
149     GNUNET_ATS_performance_done (ph);
150     ph = NULL;
151   }
152
153   pending = 0;
154   next = head;
155   while (NULL != (pr = next))
156   {
157     next = pr->next;
158     GNUNET_CONTAINER_DLL_remove(head, tail, pr);
159     GNUNET_TRANSPORT_address_to_string_cancel (pr->tats_ctx);
160     GNUNET_free(pr->address);
161     GNUNET_free(pr);
162     pending++;
163   }
164
165   GNUNET_CONTAINER_multipeermap_iterate(addresses, &free_addr_it, NULL);
166   GNUNET_CONTAINER_multipeermap_destroy(addresses);
167
168   if (0 < pending)
169     fprintf (stderr, _("%u address resolutions had a timeout\n"), pending);
170   if (op_list_used || op_list_all)
171     fprintf (stderr, _("ATS returned results for %u addresses\n"), results);
172   ret = 0;
173 }
174
175 static void
176 transport_addr_to_str_cb(void *cls, const char *address, int res)
177 {
178   struct PendingResolutions * pr = cls;
179   char *ats_str;
180   char *ats_tmp;
181   char *ats_prop_arr[GNUNET_ATS_PropertyCount] = GNUNET_ATS_PropertyStrings;
182   char *ats_prop_value;
183   unsigned int c;
184   uint32_t ats_type;
185   uint32_t ats_value;
186   uint32_t network;
187
188   if (res == GNUNET_SYSERR)
189   {
190     fprintf (stderr, "Failed to convert address for peer `%s' plugin `%s' length %lu to string \n",
191         GNUNET_i2s (&pr->address->peer),
192         pr->address->transport_name,
193         pr->address->address_length );
194     return;
195   }
196
197   if (NULL == address)
198   {
199     /* We're done */
200     GNUNET_CONTAINER_DLL_remove(head, tail, pr);
201     GNUNET_free(pr->address);
202     GNUNET_free(pr);
203     pending--;
204
205     if ((GNUNET_YES == receive_done) && (0 == pending))
206     {
207       /* All messages received and no resolutions pending*/
208       if (end_task != GNUNET_SCHEDULER_NO_TASK )
209         GNUNET_SCHEDULER_cancel (end_task);
210       end_task = GNUNET_SCHEDULER_add_now (end, NULL );
211     }
212
213     return;
214   }
215
216   ats_str = GNUNET_strdup("");
217   network = GNUNET_ATS_NET_UNSPECIFIED;
218   for (c = 0; c < pr->ats_count; c++)
219   {
220     ats_tmp = ats_str;
221
222     ats_type = ntohl (pr->ats[c].type);
223     ats_value = ntohl (pr->ats[c].value);
224
225     if (ats_type > GNUNET_ATS_PropertyCount)
226     {
227       fprintf (stderr, "Invalid ATS property type %u %u for address %s\n", ats_type, pr->ats[c].type,
228           address);
229       continue;
230     }
231
232     switch (ats_type)
233     {
234     case GNUNET_ATS_NETWORK_TYPE:
235       if (ats_value > GNUNET_ATS_NetworkTypeCount)
236       {
237         GNUNET_break(0);
238         continue;
239       }
240       network = ats_value;
241       GNUNET_asprintf (&ats_prop_value, "%s",
242           GNUNET_ATS_print_network_type (ats_value));
243       break;
244     default:
245       GNUNET_asprintf (&ats_prop_value, "%u", ats_value);
246       break;
247     }
248     if ((verbose) && (ats_type < GNUNET_ATS_PropertyCount))
249     {
250       GNUNET_asprintf (&ats_str, "%s%s=%s, ", ats_tmp, ats_prop_arr[ats_type],
251           ats_prop_value);
252       GNUNET_free(ats_tmp);
253     }
254     GNUNET_free(ats_prop_value);
255   }
256
257   fprintf (stderr,
258       _("Peer `%s' plugin `%s', address `%s', `%s' bw out: %u Bytes/s, bw in %u Bytes/s, %s\n"),
259       GNUNET_i2s (&pr->address->peer), pr->address->transport_name, address,
260       GNUNET_ATS_print_network_type (network),
261       ntohl (pr->bandwidth_out.value__), ntohl (pr->bandwidth_in.value__),
262       ats_str);
263   GNUNET_free(ats_str);
264 }
265
266
267 struct AddressFindCtx
268 {
269   const struct GNUNET_HELLO_Address *src;
270   struct ATSAddress *res;
271 };
272
273 static int
274 find_address_it (void *cls,
275     const struct GNUNET_PeerIdentity *key,
276     void *value)
277 {
278   struct AddressFindCtx *actx = cls;
279   struct ATSAddress *exist = value;
280
281   if (0 == GNUNET_HELLO_address_cmp (actx->src, exist->address))
282   {
283     actx->res = exist;
284     return GNUNET_NO;
285   }
286
287   return GNUNET_YES;
288 }
289
290 static void
291 ats_perf_mon_cb(void *cls, const struct GNUNET_HELLO_Address *address, int active,
292     struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
293     struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
294     const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
295 {
296   struct PendingResolutions *pr;
297   struct PendingResolutions *cur;
298   struct PendingResolutions *next;
299
300   if (NULL == address)
301   {
302     /* ATS service temporarily disconnected, remove current state */
303     next = head;
304     for (cur = next; NULL != cur; cur = next)
305     {
306       next = cur->next;
307       GNUNET_CONTAINER_DLL_remove (head, tail, cur);
308       GNUNET_TRANSPORT_address_to_string_cancel (cur->tats_ctx);
309       GNUNET_HELLO_address_free (cur->address);
310       GNUNET_free (cur);
311     }
312
313     GNUNET_CONTAINER_multipeermap_iterate(addresses, &free_addr_it, NULL);
314     return;
315   }
316
317   if (GNUNET_NO == verbose)
318   {
319     struct AddressFindCtx actx;
320
321     actx.src = address;
322     actx.res = NULL;
323
324     GNUNET_CONTAINER_multipeermap_iterate (addresses, find_address_it, &actx);
325     if ((actx.res != NULL))
326     {
327       if ((bandwidth_in.value__ == actx.res->bandwidth_in.value__) &&
328           (bandwidth_out.value__ == actx.res->bandwidth_out.value__) )
329       {
330         return; /* Nothing to do here */
331       }
332       else
333       {
334         actx.res->bandwidth_in = bandwidth_in;
335         actx.res->bandwidth_out = bandwidth_out;
336       }
337     }
338     struct ATSAddress *a = GNUNET_new (struct ATSAddress);
339     a->address = GNUNET_HELLO_address_copy(address);
340     a->bandwidth_in = bandwidth_in;
341     a->bandwidth_out = bandwidth_out;
342     GNUNET_CONTAINER_multipeermap_put (addresses, &address->peer, a,
343         GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
344   }
345
346   pr = GNUNET_malloc (sizeof (struct PendingResolutions) +
347       ats_count * sizeof (struct GNUNET_ATS_Information));
348
349   pr->ats_count = ats_count;
350   pr->ats = (struct GNUNET_ATS_Information *) &pr[1];
351   if (ats_count > 0)
352     memcpy (pr->ats, ats, ats_count * sizeof(struct GNUNET_ATS_Information));
353   pr->address = GNUNET_HELLO_address_copy (address);
354   pr->bandwidth_in = bandwidth_in;
355   pr->bandwidth_out = bandwidth_out;
356   pr->tats_ctx = GNUNET_TRANSPORT_address_to_string (cfg, address,
357       resolve_addresses_numeric,
358       GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
359       transport_addr_to_str_cb, pr);
360   GNUNET_CONTAINER_DLL_insert (head, tail, pr);
361   results++;
362   pending++;
363 }
364
365
366 static void
367 ats_perf_cb(void *cls, const struct GNUNET_HELLO_Address *address, int active,
368     struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
369     struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
370     const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
371 {
372   struct PendingResolutions * pr;
373
374   if (NULL == address)
375   {
376     /* All messages received */
377     receive_done = GNUNET_YES;
378     alh = NULL;
379     if (0 == pending)
380     {
381       /* All messages received and no resolutions pending*/
382       if (end_task != GNUNET_SCHEDULER_NO_TASK )
383         GNUNET_SCHEDULER_cancel (end_task);
384       end_task = GNUNET_SCHEDULER_add_now (end, NULL );
385     }
386     return;
387   }
388
389   pr = GNUNET_malloc (sizeof (struct PendingResolutions) +
390       ats_count * sizeof (struct GNUNET_ATS_Information));
391
392   pr->ats_count = ats_count;
393   pr->ats = (struct GNUNET_ATS_Information *) &pr[1];
394   if (ats_count > 0)
395     memcpy (pr->ats, ats, ats_count * sizeof(struct GNUNET_ATS_Information));
396   pr->address = GNUNET_HELLO_address_copy (address);
397   pr->bandwidth_in = bandwidth_in;
398   pr->bandwidth_out = bandwidth_out;
399   pr->tats_ctx = GNUNET_TRANSPORT_address_to_string (cfg, address,
400       resolve_addresses_numeric,
401       GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
402       transport_addr_to_str_cb, pr);
403   GNUNET_CONTAINER_DLL_insert(head, tail, pr);
404   results++;
405   pending++;
406 }
407
408 static unsigned int
409 print_quotas(const struct GNUNET_CONFIGURATION_Handle *cfg)
410 {
411   char *network_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString;
412   char * entry_in = NULL;
413   char * entry_out = NULL;
414   char * quota_out_str;
415   char * quota_in_str;
416   unsigned long long int quota_out;
417   unsigned long long int quota_in;
418   int c;
419
420   for (c = 0; (c < GNUNET_ATS_NetworkTypeCount); c++)
421   {
422
423     GNUNET_asprintf (&entry_out, "%s_QUOTA_OUT", network_str[c]);
424     GNUNET_asprintf (&entry_in, "%s_QUOTA_IN", network_str[c]);
425
426     /* quota out */
427     if (GNUNET_OK
428         == GNUNET_CONFIGURATION_get_value_string (cfg, "ats", entry_out,
429             &quota_out_str))
430     {
431       if (0 == strcmp (quota_out_str, BIG_M_STRING)
432           || (GNUNET_SYSERR
433               == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &quota_out)))
434         quota_out = UINT32_MAX;
435
436       GNUNET_free(quota_out_str);
437       GNUNET_asprintf (&quota_out_str, "%llu", quota_out);
438     }
439     else
440     {
441       fprintf (stderr, "Outbound quota for network `%11s' not configured!\n",
442           network_str[c]);
443       GNUNET_asprintf (&quota_out_str, "-");
444     }
445     GNUNET_free(entry_out);
446
447     /* quota in */
448     if (GNUNET_OK
449         == GNUNET_CONFIGURATION_get_value_string (cfg, "ats", entry_in,
450             &quota_in_str))
451     {
452       if (0 == strcmp (quota_in_str, BIG_M_STRING)
453           || (GNUNET_SYSERR
454               == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &quota_in)))
455         quota_in = UINT32_MAX;
456       GNUNET_free(quota_in_str);
457       GNUNET_asprintf (&quota_in_str, "%llu", quota_in);
458     }
459     else
460     {
461       fprintf (stderr, "Inbound quota for network `%11s' not configured!\n",
462           network_str[c]);
463       GNUNET_asprintf (&quota_in_str, "-");
464     }
465     GNUNET_free(entry_in);
466
467     fprintf (stderr, _("Quota for network `%11s' (in/out): %10s / %10s\n"),
468         network_str[c], quota_in_str, quota_out_str);
469     GNUNET_free(quota_out_str);
470     GNUNET_free(quota_in_str);
471   }
472   return GNUNET_ATS_NetworkTypeCount;
473 }
474
475 static void
476 testservice_ats(void *cls, int result)
477 {
478   struct GNUNET_CONFIGURATION_Handle *cfg = cls;
479   struct GNUNET_PeerIdentity pid;
480   unsigned int c;
481   unsigned int type;
482
483   addresses = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_YES);
484
485   if (GNUNET_YES != result)
486   {
487     FPRINTF (stderr, _("Service `%s' is not running\n"), "ats");
488     return;
489   }
490
491   results = 0;
492
493   if (NULL != pid_str)
494   {
495     if (GNUNET_OK
496         != GNUNET_CRYPTO_eddsa_public_key_from_string (pid_str,
497             strlen (pid_str), &pid.public_key))
498     {
499       FPRINTF (stderr, _("Failed to parse peer identity `%s'\n"), pid_str);
500       return;
501     }
502   }
503
504   c = op_list_all + op_list_used + op_monitor + op_set_pref;
505   if ((1 < c))
506   {
507     FPRINTF (stderr,
508         _("Please select one operation : %s or %s or %s or %s or %s\n"),
509         "--used", "--all", "--monitor", "--preference", "--quotas");
510     return;
511   }
512   if ((0 == c))
513     op_list_used = GNUNET_YES; /* set default */
514   if (op_print_quotas)
515   {
516     ret = print_quotas (cfg);
517     return;
518   }
519   if (op_list_all)
520   {
521     ph = GNUNET_ATS_performance_init (cfg, NULL, NULL );
522     if (NULL == ph)
523     {
524       fprintf (stderr, _("Cannot connect to ATS service, exiting...\n") );
525       return;
526     }
527
528     alh = GNUNET_ATS_performance_list_addresses (ph,
529         (NULL == pid_str) ? NULL : &pid, GNUNET_YES, ats_perf_cb, NULL );
530     if (NULL == alh)
531     {
532       fprintf (stderr, _("Cannot issue request to ATS service, exiting...\n") );
533       end_task = GNUNET_SCHEDULER_add_now (&end, NULL );
534       return;
535     }
536     end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &end,
537         NULL );
538   }
539   else if (op_list_used)
540   {
541     ph = GNUNET_ATS_performance_init (cfg, NULL, NULL );
542     if (NULL == ph)
543       fprintf (stderr, _("Cannot connect to ATS service, exiting...\n") );
544
545     alh = GNUNET_ATS_performance_list_addresses (ph,
546         (NULL == pid_str) ? NULL : &pid, GNUNET_NO, ats_perf_cb, NULL );
547     if (NULL == alh)
548     {
549       fprintf (stderr, _("Cannot issue request to ATS service, exiting...\n") );
550       end_task = GNUNET_SCHEDULER_add_now (&end, NULL );
551       return;
552     }
553     end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &end,
554         NULL );
555   }
556   else if (op_monitor)
557   {
558     ph = GNUNET_ATS_performance_init (cfg, &ats_perf_mon_cb, NULL );
559     if (NULL == ph)
560       fprintf (stderr, _("Cannot connect to ATS service, exiting...\n") );
561     end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &end,
562         NULL );
563
564   }
565   else if (op_set_pref)
566   {
567     if (NULL == type_str)
568     {
569       fprintf (stderr, _("No preference type given!\n") );
570       return;
571     }
572     if (NULL == pid_str)
573     {
574       fprintf (stderr, _("No peer given!\n") );
575       return;
576     }
577
578     for (c = 0; c < strlen (type_str); c++)
579     {
580       if (isupper (type_str[c]))
581         type_str[c] = tolower (type_str[c]);
582     }
583
584     if (0 == strcasecmp ("latency", type_str))
585       type = GNUNET_ATS_PREFERENCE_LATENCY;
586     else if (0 == strcasecmp ("bandwidth", type_str))
587       type = GNUNET_ATS_PREFERENCE_BANDWIDTH;
588     else
589     {
590       FPRINTF (stderr, "%s", _("Valid type required\n") );
591       return;
592     }
593
594     /* set */
595     ph = GNUNET_ATS_performance_init (cfg, NULL, NULL );
596     if (NULL == ph)
597       fprintf (stderr, _("Cannot connect to ATS service, exiting...\n") );
598
599     GNUNET_ATS_performance_change_preference (ph, &pid, type, (double) value,
600         GNUNET_ATS_PREFERENCE_END);
601
602     end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &end,
603         NULL );
604   }
605   ret = 1;
606 }
607
608 /**
609  * Main function that will be run by the scheduler.
610  *
611  * @param cls closure
612  * @param args remaining command-line arguments
613  * @param cfgfile name of the configuration file used (for saving, can be NULL!)
614  * @param my_cfg configuration
615  */
616 static void
617 run(void *cls, char * const *args, const char *cfgfile,
618     const struct GNUNET_CONFIGURATION_Handle *my_cfg)
619 {
620   cfg = (struct GNUNET_CONFIGURATION_Handle *) my_cfg;
621   GNUNET_CLIENT_service_test ("ats", cfg, TIMEOUT, &testservice_ats,
622       (void *) cfg);
623 }
624
625 /**
626  * The main function.
627  *
628  * @param argc number of arguments from the command line
629  * @param argv command line arguments
630  * @return 0 ok, 1 on error
631  */
632 int
633 main(int argc, char * const *argv)
634 {
635   int res;
636   resolve_addresses_numeric = GNUNET_NO;
637   op_monitor = GNUNET_NO;
638   op_list_all = GNUNET_NO;
639   op_list_used = GNUNET_NO;
640   op_set_pref = GNUNET_NO;
641   pending = 0;
642   receive_done = GNUNET_NO;
643   type_str = NULL;
644
645   static const struct GNUNET_GETOPT_CommandLineOption options[] =
646   {
647   { 'u', "used", NULL,
648       gettext_noop ("get list of active addresses currently used"), 0,
649       &GNUNET_GETOPT_set_one, &op_list_used },
650   { 'a', "all", NULL, gettext_noop ("get list of all active addresses"), 0,
651       &GNUNET_GETOPT_set_one, &op_list_all },
652   { 'n', "numeric", NULL,
653       gettext_noop ("do not resolve IP addresses to hostnames"), 0,
654       &GNUNET_GETOPT_set_one, &resolve_addresses_numeric },
655   { 'm', "monitor", NULL, gettext_noop ("monitor mode"), 0,
656       &GNUNET_GETOPT_set_one, &op_monitor },
657   { 'p', "preference", NULL, gettext_noop ("set preference for the given peer"),
658       0, &GNUNET_GETOPT_set_one, &op_set_pref },
659   { 'q', "quotas", NULL, gettext_noop ("print all configured quotas"), 0,
660       &GNUNET_GETOPT_set_one, &op_print_quotas },
661   { 'i', "id", "TYPE", gettext_noop ("peer id"), 1, &GNUNET_GETOPT_set_string,
662       &pid_str },
663   { 't', "type", "TYPE",
664       gettext_noop ("preference type to set: latency | bandwidth"), 1,
665       &GNUNET_GETOPT_set_string, &type_str },
666   { 'k', "value", "VALUE", gettext_noop ("preference value"), 1,
667       &GNUNET_GETOPT_set_uint, &value },
668   { 'V', "verbose", NULL,
669       gettext_noop ("verbose output (include ATS address properties)"), 0,
670       &GNUNET_GETOPT_set_one, &verbose }, GNUNET_GETOPT_OPTION_END };
671
672   if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
673     return 2;
674
675   res = GNUNET_PROGRAM_run (argc, argv, "gnunet-ats",
676       gettext_noop ("Print information about ATS state"), options, &run, NULL );
677   GNUNET_free_non_null(pid_str);
678   GNUNET_free_non_null(type_str);
679   GNUNET_free((void * ) argv);
680
681   if (GNUNET_OK == res)
682     return ret;
683   else
684     return 1;
685
686 }
687
688 /* end of gnunet-ats.c */