session end function must include address to notify address
[oweals/gnunet.git] / src / transport / gnunet-transport.c
1 /*
2  This file is part of GNUnet.
3  (C) 2011 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 src/transport/gnunet-transport.c
23  * @brief Tool to help configure, measure and control the transport subsystem.
24  * @author Christian Grothoff
25  * @author Nathan Evans
26  *
27  * This utility can be used to test if a transport mechanism for
28  * GNUnet is properly configured.
29  */
30
31 #include "platform.h"
32 #include "gnunet_util_lib.h"
33 #include "gnunet_resolver_service.h"
34 #include "gnunet_protocols.h"
35 #include "gnunet_transport_service.h"
36 #include "gnunet_nat_lib.h"
37
38 /**
39  * How long do we wait for the NAT test to report success?
40  * Should match NAT_SERVER_TIMEOUT in 'nat_test.c'.
41  */
42 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
43 #define RESOLUTION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
44 #define OP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
45
46 /**
47  * Benchmarking block size in KB
48  */
49 #define BLOCKSIZE 4
50
51 /**
52  * Which peer should we connect to?
53  */
54 static char *cpid;
55
56 /**
57  * Handle to transport service.
58  */
59 static struct GNUNET_TRANSPORT_Handle *handle;
60
61 /**
62  * Configuration handle
63  */
64 static struct GNUNET_CONFIGURATION_Handle *cfg;
65
66 /**
67  * Try_connect handle
68  */
69 struct GNUNET_TRANSPORT_TryConnectHandle * tc_handle;
70
71 /**
72  * Option -s.
73  */
74 static int benchmark_send;
75
76 /**
77  * Option -b.
78  */
79 static int benchmark_receive;
80
81 /**
82  * Option -l.
83  */
84 static int benchmark_receive;
85
86 /**
87  * Option -i.
88  */
89 static int iterate_connections;
90
91 /**
92  * Option -d.
93  */
94 static int iterate_validation;
95
96 /**
97  * Option -a.
98  */
99 static int iterate_all;
100
101 /**
102  * Option -t.
103  */
104 static int test_configuration;
105
106 /**
107  * Option -c.
108  */
109 static int monitor_connects;
110
111 /**
112  * Option -m.
113  */
114 static int monitor_connections;
115
116 /**
117  * Option -f.
118  */
119 static int monitor_validation;
120
121 /**
122  * Option -C.
123  */
124 static int try_connect;
125
126 /**
127  * Option -n.
128  */
129 static int numeric;
130
131 /**
132  * Global return value (0 success).
133  */
134 static int ret;
135
136 /**
137  * Current number of connections in monitor mode
138  */
139 static int monitor_connect_counter;
140
141 /**
142  * Number of bytes of traffic we received so far.
143  */
144 static unsigned long long traffic_received;
145
146 /**
147  * Number of bytes of traffic we sent so far.
148  */
149 static unsigned long long traffic_sent;
150
151 /**
152  * Starting time of transmitting/receiving data.
153  */
154 static struct GNUNET_TIME_Absolute start_time;
155
156 /**
157  * Handle for current transmission request.
158  */
159 static struct GNUNET_TRANSPORT_TransmitHandle *th;
160
161 /**
162  * Map storing information about monitored peers
163  */
164 static struct GNUNET_CONTAINER_MultiPeerMap *monitored_peers;
165
166 /**
167  *
168  */
169 static struct GNUNET_TRANSPORT_PeerMonitoringContext *pic;
170
171 static struct GNUNET_TRANSPORT_ValidationMonitoringContext *vic;
172
173 /**
174  * Identity of the peer we transmit to / connect to.
175  * (equivalent to 'cpid' string).
176  */
177 static struct GNUNET_PeerIdentity pid;
178
179 /**
180  * Task scheduled for cleanup / termination of the process.
181  */
182 static GNUNET_SCHEDULER_TaskIdentifier end;
183
184 /**
185  * Task for operation timeout
186  */
187 static GNUNET_SCHEDULER_TaskIdentifier op_timeout;
188
189 /**
190  * Selected level of verbosity.
191  */
192 static int verbosity;
193
194 /**
195  * Resolver process handle.
196  */
197 struct GNUNET_OS_Process *resolver;
198
199 /**
200  * Number of address resolutions pending
201  */
202 static unsigned int address_resolutions;
203
204 /**
205  * Address resolutions pending in progress
206  */
207 static unsigned int address_resolution_in_progress;
208
209 /**
210  * DLL for NAT Test Contexts: head
211  */
212 struct TestContext *head;
213
214 /**
215  * DLL for NAT Test Contexts: tail
216  */
217 struct TestContext *tail;
218
219 /**
220  * Context for a plugin test.
221  */
222 struct TestContext
223 {
224   /**
225    * Previous in DLL
226    */
227   struct TestContext *prev;
228
229   /**
230    * Next in DLL
231    */
232   struct TestContext *next;
233
234   /**
235    * Handle to the active NAT test.
236    */
237   struct GNUNET_NAT_Test *tst;
238
239   /**
240    * Task identifier for the timeout.
241    */
242   GNUNET_SCHEDULER_TaskIdentifier tsk;
243
244   /**
245    * Name of plugin under test.
246    */
247   char *name;
248
249   /**
250    * Bound port
251    */
252   unsigned long long bnd_port;
253
254   /**
255    * Advertised ports
256    */
257   unsigned long long adv_port;
258
259 };
260
261 struct MonitoredPeer
262 {
263   enum GNUNET_TRANSPORT_PeerState state;
264   struct GNUNET_TIME_Absolute state_timeout;
265   struct GNUNET_HELLO_Address *address;
266 };
267
268
269  int destroy_it (void *cls,
270     const struct GNUNET_PeerIdentity *key,
271     void *value)
272 {
273    struct MonitoredPeer *m = value;
274    GNUNET_CONTAINER_multipeermap_remove (monitored_peers, key, value);
275    GNUNET_free_non_null (m->address);
276    GNUNET_free (value);
277    return GNUNET_OK;
278 }
279
280 /**
281  * Task run in monitor mode when the user presses CTRL-C to abort.
282  * Stops monitoring activity.
283  *
284  * @param cls the 'struct GNUNET_TRANSPORT_PeerIterateContext *'
285  * @param tc scheduler context
286  */
287 static void
288 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
289 {
290   struct GNUNET_TIME_Relative duration;
291   end = GNUNET_SCHEDULER_NO_TASK;
292   if (GNUNET_SCHEDULER_NO_TASK != op_timeout)
293   {
294     GNUNET_SCHEDULER_cancel (op_timeout);
295     op_timeout = GNUNET_SCHEDULER_NO_TASK;
296   }
297   if (NULL != tc_handle)
298   {
299     GNUNET_TRANSPORT_try_connect_cancel (tc_handle);
300     tc_handle = NULL;
301   }
302   if (NULL != pic)
303   {
304     GNUNET_TRANSPORT_monitor_peers_cancel (pic);
305     pic = NULL;
306   }
307   if (NULL != vic)
308   {
309     GNUNET_TRANSPORT_monitor_validation_entries_cancel (vic);
310     vic = NULL;
311   }
312   if (NULL != th)
313   {
314     GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
315     th = NULL;
316   }
317   if (NULL != handle)
318   {
319     GNUNET_TRANSPORT_disconnect (handle);
320     handle = NULL;
321   }
322   if (benchmark_send)
323   {
324     duration = GNUNET_TIME_absolute_get_duration (start_time);
325     FPRINTF (stdout, _("Transmitted %llu bytes/s (%llu bytes in %s)\n"),
326         1000LL * 1000LL * traffic_sent / (1 + duration.rel_value_us),
327         traffic_sent,
328         GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
329   }
330   if (benchmark_receive)
331   {
332     duration = GNUNET_TIME_absolute_get_duration (start_time);
333     FPRINTF (stdout, _("Received %llu bytes/s (%llu bytes in %s)\n"),
334         1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us),
335         traffic_received,
336         GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
337   }
338
339   if (NULL != monitored_peers)
340   {
341     GNUNET_CONTAINER_multipeermap_iterate (monitored_peers, &destroy_it, NULL);
342     GNUNET_CONTAINER_multipeermap_destroy (monitored_peers);
343     monitored_peers = NULL;
344   }
345 }
346
347 static struct PeerResolutionContext *rc_head;
348 static struct PeerResolutionContext *rc_tail;
349
350 struct PeerResolutionContext
351 {
352   struct PeerResolutionContext *next;
353   struct PeerResolutionContext *prev;
354   struct GNUNET_PeerIdentity id;
355   struct GNUNET_HELLO_Address *addrcp;
356   struct GNUNET_TRANSPORT_AddressToStringContext *asc;
357   enum GNUNET_TRANSPORT_PeerState state;
358   struct GNUNET_TIME_Absolute state_timeout;
359   char *transport;
360   int printed;
361 };
362
363 static struct ValidationResolutionContext *vc_head;
364 static struct ValidationResolutionContext *vc_tail;
365
366 struct ValidationResolutionContext
367 {
368   struct ValidationResolutionContext *next;
369   struct ValidationResolutionContext *prev;
370
371   struct GNUNET_PeerIdentity id;
372   struct GNUNET_HELLO_Address *addrcp;
373   struct GNUNET_TIME_Absolute last_validation;
374   struct GNUNET_TIME_Absolute valid_until;
375   struct GNUNET_TIME_Absolute next_validation;
376   enum GNUNET_TRANSPORT_ValidationState state;
377
378   struct GNUNET_TRANSPORT_AddressToStringContext *asc;
379
380   char *transport;
381   int printed;
382 };
383
384 static void
385 operation_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
386 {
387   struct PeerResolutionContext *cur;
388   struct PeerResolutionContext *next;
389   op_timeout = GNUNET_SCHEDULER_NO_TASK;
390   if ((try_connect) || (benchmark_send) || (benchmark_receive))
391   {
392     FPRINTF (stdout, _("Failed to connect to `%s'\n"), GNUNET_i2s_full (&pid));
393     if (GNUNET_SCHEDULER_NO_TASK != end)
394       GNUNET_SCHEDULER_cancel (end);
395     end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL );
396     ret = 1;
397     return;
398   }
399   if (iterate_connections)
400   {
401     next = rc_head;
402     while (NULL != (cur = next))
403     {
404       next = cur->next;
405       FPRINTF (stdout, _("Failed to resolve address for peer `%s'\n"),
406           GNUNET_i2s (&cur->addrcp->peer));
407
408       GNUNET_CONTAINER_DLL_remove(rc_head, rc_tail, cur);
409       GNUNET_TRANSPORT_address_to_string_cancel (cur->asc);
410       GNUNET_free(cur->transport);
411       GNUNET_free(cur->addrcp);
412       GNUNET_free(cur);
413
414     }
415     FPRINTF (stdout, "%s", _("Failed to list connections, timeout occured\n") );
416     if (GNUNET_SCHEDULER_NO_TASK != end)
417       GNUNET_SCHEDULER_cancel (end);
418     end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL );
419     ret = 1;
420     return;
421   }
422
423 }
424
425 static void
426 run_nat_test ();
427
428 /**
429  * Display the result of the test.
430  *
431  * @param tc test context
432  * @param result #GNUNET_YES on success
433  */
434 static void
435 display_test_result (struct TestContext *tc, int result)
436 {
437   if (GNUNET_YES != result)
438   {
439     FPRINTF (stderr, "Configuration for plugin `%s' did not work!\n", tc->name);
440   }
441   else
442   {
443     FPRINTF (stderr, "Configuration for plugin `%s' is working!\n", tc->name);
444   }
445   if (GNUNET_SCHEDULER_NO_TASK != tc->tsk)
446   {
447     GNUNET_SCHEDULER_cancel (tc->tsk);
448     tc->tsk = GNUNET_SCHEDULER_NO_TASK;
449   }
450   if (NULL != tc->tst)
451   {
452     GNUNET_NAT_test_stop (tc->tst);
453     tc->tst = NULL;
454   }
455
456   GNUNET_CONTAINER_DLL_remove (head, tail, tc);
457   GNUNET_free (tc->name);
458   GNUNET_free (tc);
459
460   if ((NULL == head) && (NULL != resolver))
461   {
462     GNUNET_break(0 == GNUNET_OS_process_kill (resolver, GNUNET_TERM_SIG));
463     GNUNET_OS_process_destroy (resolver);
464     resolver = NULL;
465   }
466   if (NULL != head)
467     run_nat_test ();
468 }
469
470 /**
471  * Function called by NAT on success.
472  * Clean up and update GUI (with success).
473  *
474  * @param cls test context
475  * @param success currently always #GNUNET_OK
476  * @param emsg error message, NULL on success
477  */
478 static void
479 result_callback (void *cls, int success, const char *emsg)
480 {
481   struct TestContext *tc = cls;
482   display_test_result (tc, success);
483 }
484
485 /**
486  * Function called if NAT failed to confirm success.
487  * Clean up and update GUI (with failure).
488  *
489  * @param cls test context
490  * @param tc scheduler callback
491  */
492 static void
493 fail_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
494 {
495   struct TestContext *tstc = cls;
496
497   tstc->tsk = GNUNET_SCHEDULER_NO_TASK;
498   display_test_result (tstc, GNUNET_NO);
499 }
500
501
502 static void
503 resolve_validation_address (const struct GNUNET_PeerIdentity *id,
504     const struct GNUNET_HELLO_Address *address, int numeric,
505     struct GNUNET_TIME_Absolute last_validation,
506     struct GNUNET_TIME_Absolute valid_until,
507     struct GNUNET_TIME_Absolute next_validation,
508     enum GNUNET_TRANSPORT_ValidationState state);
509
510 static void
511 process_validation_string (void *cls, const char *address)
512 {
513   struct ValidationResolutionContext *vc = cls;
514   char *s_valid;
515   char *s_last;
516   char *s_next;
517
518   if (address != NULL )
519   {
520     if (GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us == vc->valid_until.abs_value_us)
521       s_valid = GNUNET_strdup("never");
522     else
523       s_valid = GNUNET_strdup(GNUNET_STRINGS_absolute_time_to_string (vc->valid_until));
524
525     if (GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us == vc->last_validation.abs_value_us)
526       s_last = GNUNET_strdup("never");
527     else
528       s_last = GNUNET_strdup(GNUNET_STRINGS_absolute_time_to_string (vc->last_validation));
529
530     if (GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us == vc->next_validation.abs_value_us)
531       s_next = GNUNET_strdup("never");
532     else
533       s_next = GNUNET_strdup(GNUNET_STRINGS_absolute_time_to_string (vc->next_validation));
534
535     FPRINTF (stdout,
536         _("Peer `%s' %s %s\n\t%s%s\n\t%s%s\n\t%s%s\n"),
537         GNUNET_i2s (&vc->id), address,
538         (monitor_validation) ? GNUNET_TRANSPORT_vs2s (vc->state) : "",
539         "Valid until    : ", s_valid,
540         "Last validation: ",s_last,
541         "Next validation: ", s_next);
542     GNUNET_free (s_valid);
543     GNUNET_free (s_last);
544     GNUNET_free (s_next);
545     vc->printed = GNUNET_YES;
546   }
547   else
548   {
549     /* done */
550     GNUNET_assert(address_resolutions > 0);
551     address_resolutions--;
552     if (GNUNET_NO == vc->printed)
553     {
554       if (numeric == GNUNET_NO)
555       {
556         /* Failed to resolve address, try numeric lookup */
557         resolve_validation_address (&vc->id, vc->addrcp, GNUNET_NO,
558            vc->last_validation, vc->valid_until, vc->next_validation,
559            vc->state);
560       }
561       else
562       {
563         FPRINTF (stdout, _("Peer `%s' %s `%s' \n"),
564             GNUNET_i2s (&vc->id), "<unable to resolve address>",
565             GNUNET_TRANSPORT_vs2s (vc->state));
566       }
567     }
568     GNUNET_free (vc->transport);
569     GNUNET_free (vc->addrcp);
570     GNUNET_CONTAINER_DLL_remove(vc_head, vc_tail, vc);
571     GNUNET_free(vc);
572     if ((0 == address_resolutions) && (iterate_validation))
573     {
574       if (GNUNET_SCHEDULER_NO_TASK != end)
575       {
576         GNUNET_SCHEDULER_cancel (end);
577         end = GNUNET_SCHEDULER_NO_TASK;
578       }
579       if (GNUNET_SCHEDULER_NO_TASK != op_timeout)
580       {
581         GNUNET_SCHEDULER_cancel (op_timeout);
582         op_timeout = GNUNET_SCHEDULER_NO_TASK;
583       }
584       ret = 0;
585       end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL );
586     }
587   }
588 }
589
590
591
592 static void
593 resolve_validation_address (const struct GNUNET_PeerIdentity *id,
594     const struct GNUNET_HELLO_Address *address, int numeric,
595     struct GNUNET_TIME_Absolute last_validation,
596     struct GNUNET_TIME_Absolute valid_until,
597     struct GNUNET_TIME_Absolute next_validation,
598     enum GNUNET_TRANSPORT_ValidationState state)
599 {
600   struct ValidationResolutionContext *vc;
601
602   vc = GNUNET_new (struct ValidationResolutionContext);
603   GNUNET_assert(NULL != vc);
604   GNUNET_CONTAINER_DLL_insert(vc_head, vc_tail, vc);
605   address_resolutions++;
606
607   vc->id = (*id);
608   vc->transport = GNUNET_strdup(address->transport_name);
609   vc->addrcp = GNUNET_HELLO_address_copy (address);
610   vc->printed = GNUNET_NO;
611   vc->state = state;
612   vc->last_validation = last_validation;
613   vc->valid_until = valid_until;
614   vc->next_validation = next_validation;
615
616   /* Resolve address to string */
617   vc->asc = GNUNET_TRANSPORT_address_to_string (cfg, address, numeric,
618       RESOLUTION_TIMEOUT, &process_validation_string, vc);
619 }
620
621
622 void process_validation_cb (void *cls,
623     const struct GNUNET_PeerIdentity *peer,
624     const struct GNUNET_HELLO_Address *address,
625     struct GNUNET_TIME_Absolute last_validation,
626     struct GNUNET_TIME_Absolute valid_until,
627     struct GNUNET_TIME_Absolute next_validation,
628     enum GNUNET_TRANSPORT_ValidationState state)
629 {
630   if ((NULL == peer) && (NULL == address))
631   {
632     /* done */
633     vic = NULL;
634     if (GNUNET_SCHEDULER_NO_TASK != end)
635       GNUNET_SCHEDULER_cancel (end);
636     end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL );
637     return;
638   }
639   if ((NULL == peer) || (NULL == address))
640   {
641     /* invalid response */
642     vic = NULL;
643     if (GNUNET_SCHEDULER_NO_TASK != end)
644       GNUNET_SCHEDULER_cancel (end);
645     end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL );
646     return;
647   }
648   resolve_validation_address (peer, address,
649      numeric, last_validation,
650      valid_until, next_validation, state);
651 }
652
653 static void
654 run_nat_test ()
655 {
656   head->tst = GNUNET_NAT_test_start (cfg,
657       (0 == strcasecmp (head->name, "udp")) ? GNUNET_NO : GNUNET_YES,
658       (uint16_t) head->bnd_port,
659       (uint16_t) head->adv_port,
660       &result_callback, head);
661   if (NULL == head->tst)
662   {
663     display_test_result (head, GNUNET_SYSERR);
664     return;
665   }
666   head->tsk = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &fail_timeout, head);
667 }
668
669 /**
670  * Test our plugin's configuration (NAT traversal, etc.).
671  *
672  * @param cfg configuration to test
673  */
674 static void
675 do_test_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg)
676 {
677   char *plugins;
678   char *tok;
679   unsigned long long bnd_port;
680   unsigned long long adv_port;
681   struct TestContext *tc;
682   char *binary;
683
684   if (GNUNET_OK
685       != GNUNET_CONFIGURATION_get_value_string (cfg, "transport", "plugins",
686           &plugins))
687   {
688     FPRINTF (stderr, "%s", _
689     ("No transport plugins configured, peer will never communicate\n") );
690     ret = 4;
691     return;
692   }
693
694   for (tok = strtok (plugins, " "); tok != NULL ; tok = strtok (NULL, " "))
695   {
696     char section[12 + strlen (tok)];
697     GNUNET_snprintf (section, sizeof(section), "transport-%s", tok);
698     if (GNUNET_OK
699         != GNUNET_CONFIGURATION_get_value_number (cfg, section, "PORT",
700             &bnd_port))
701     {
702       FPRINTF (stderr,
703           _("No port configured for plugin `%s', cannot test it\n"), tok);
704       continue;
705     }
706     if (GNUNET_OK
707         != GNUNET_CONFIGURATION_get_value_number (cfg, section,
708             "ADVERTISED_PORT", &adv_port))
709       adv_port = bnd_port;
710
711     tc = GNUNET_new (struct TestContext);
712     tc->name = GNUNET_strdup (tok);
713     tc->adv_port = adv_port;
714     tc->bnd_port = bnd_port;
715     GNUNET_CONTAINER_DLL_insert_tail (head, tail, tc);
716   }
717   GNUNET_free(plugins);
718
719   if ((NULL != head) && (NULL == resolver))
720   {
721     binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-resolver");
722     resolver = GNUNET_OS_start_process (GNUNET_YES,
723                                         GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
724                                         NULL, NULL, NULL,
725                                         binary,
726                                         "gnunet-service-resolver", NULL );
727     GNUNET_free(binary);
728     GNUNET_RESOLVER_connect (cfg);
729     run_nat_test ();
730   }
731 }
732
733 /**
734  * Function called to notify a client about the socket
735  * begin ready to queue more data.  @a buf will be
736  * NULL and @a size zero if the socket was closed for
737  * writing in the meantime.
738  *
739  * @param cls closure
740  * @param size number of bytes available in @a buf
741  * @param buf where the callee should write the message
742  * @return number of bytes written to @a buf
743  */
744 static size_t
745 transmit_data (void *cls, size_t size, void *buf)
746 {
747   struct GNUNET_MessageHeader *m = buf;
748
749   if ((NULL == buf) || (0 == size))
750   {
751     th = NULL;
752     return 0;
753   }
754
755   GNUNET_assert(size >= sizeof(struct GNUNET_MessageHeader));
756   GNUNET_assert(size < GNUNET_SERVER_MAX_MESSAGE_SIZE);
757   m->size = ntohs (size);
758   m->type = ntohs (GNUNET_MESSAGE_TYPE_DUMMY);
759   memset (&m[1], 52, size - sizeof(struct GNUNET_MessageHeader));
760   traffic_sent += size;
761   th = GNUNET_TRANSPORT_notify_transmit_ready (handle, &pid,
762                                                BLOCKSIZE * 1024,
763                                                GNUNET_TIME_UNIT_FOREVER_REL,
764                                                &transmit_data, NULL );
765   if (verbosity > 0)
766     FPRINTF (stdout, _("Transmitting %u bytes to %s\n"), (unsigned int) size,
767         GNUNET_i2s (&pid));
768   return size;
769 }
770
771 /**
772  * Function called to notify transport users that another
773  * peer connected to us.
774  *
775  * @param cls closure
776  * @param peer the peer that connected
777  */
778 static void
779 notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
780 {
781   if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity)))
782     return;
783   ret = 0;
784   if (try_connect)
785   {
786     /* all done, terminate instantly */
787     FPRINTF (stdout, _("Successfully connected to `%s'\n"),
788         GNUNET_i2s_full (peer));
789     ret = 0;
790
791     if (GNUNET_SCHEDULER_NO_TASK != op_timeout)
792     {
793       GNUNET_SCHEDULER_cancel (op_timeout);
794       op_timeout = GNUNET_SCHEDULER_NO_TASK;
795     }
796
797     if (GNUNET_SCHEDULER_NO_TASK != end)
798       GNUNET_SCHEDULER_cancel (end);
799     end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL );
800     return;
801   }
802   if (benchmark_send)
803   {
804     if (GNUNET_SCHEDULER_NO_TASK != op_timeout)
805     {
806       GNUNET_SCHEDULER_cancel (op_timeout);
807       op_timeout = GNUNET_SCHEDULER_NO_TASK;
808     }
809     if (verbosity > 0)
810       FPRINTF (stdout,
811           _("Successfully connected to `%s', starting to send benchmark data in %u Kb blocks\n"),
812           GNUNET_i2s (&pid), BLOCKSIZE);
813     start_time = GNUNET_TIME_absolute_get ();
814     if (NULL == th)
815       th = GNUNET_TRANSPORT_notify_transmit_ready (handle, peer,
816                                                    BLOCKSIZE * 1024,
817                                                    GNUNET_TIME_UNIT_FOREVER_REL,
818                                                    &transmit_data,
819                                                    NULL);
820     else
821       GNUNET_break(0);
822     return;
823   }
824 }
825
826 /**
827  * Function called to notify transport users that another
828  * peer disconnected from us.
829  *
830  * @param cls closure
831  * @param peer the peer that disconnected
832  */
833 static void
834 notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
835 {
836   if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity)))
837     return;
838
839   if (NULL != th)
840   {
841     GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
842     th = NULL;
843   }
844   if (benchmark_send)
845   {
846     FPRINTF (stdout, _("Disconnected from peer `%s' while benchmarking\n"),
847         GNUNET_i2s (&pid));
848     if (GNUNET_SCHEDULER_NO_TASK != end)
849       GNUNET_SCHEDULER_cancel (end);
850     return;
851   }
852 }
853
854 /**
855  * Function called to notify transport users that another
856  * peer connected to us.
857  *
858  * @param cls closure
859  * @param peer the peer that connected
860  */
861 static void
862 monitor_notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
863 {
864   monitor_connect_counter++;
865   struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
866   const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
867
868   FPRINTF (stdout, _("%24s: %-17s %4s   (%u connections in total)\n"), now_str,
869       _("Connected to"), GNUNET_i2s (peer), monitor_connect_counter);
870 }
871
872 /**
873  * Function called to notify transport users that another
874  * peer disconnected from us.
875  *
876  * @param cls closure
877  * @param peer the peer that disconnected
878  */
879 static void
880 monitor_notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
881 {
882   struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
883   const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
884
885   GNUNET_assert(monitor_connect_counter > 0);
886   monitor_connect_counter--;
887
888   FPRINTF (stdout, _("%24s: %-17s %4s   (%u connections in total)\n"), now_str,
889       _("Disconnected from"), GNUNET_i2s (peer), monitor_connect_counter);
890 }
891
892 /**
893  * Function called by the transport for each received message.
894  *
895  * @param cls closure
896  * @param peer (claimed) identity of the other peer
897  * @param message the message
898  */
899 static void
900 notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
901     const struct GNUNET_MessageHeader *message)
902 {
903   if (benchmark_receive)
904   {
905     if (GNUNET_MESSAGE_TYPE_DUMMY != ntohs (message->type))
906       return;
907     if (verbosity > 0)
908       FPRINTF (stdout, _("Received %u bytes from %s\n"),
909           (unsigned int) ntohs (message->size), GNUNET_i2s (peer));
910
911     if (traffic_received == 0)
912       start_time = GNUNET_TIME_absolute_get ();
913     traffic_received += ntohs (message->size);
914     return;
915   }
916 }
917
918 static void
919 resolve_peer_address (const struct GNUNET_PeerIdentity *id,
920     const struct GNUNET_HELLO_Address *address, int numeric,
921     enum GNUNET_TRANSPORT_PeerState state,
922     struct GNUNET_TIME_Absolute state_timeout);
923
924 static void
925 print_info (const struct GNUNET_PeerIdentity *id, const char *transport,
926     const char *addr, enum GNUNET_TRANSPORT_PeerState state,
927     struct GNUNET_TIME_Absolute state_timeout)
928 {
929   if ((GNUNET_YES == iterate_all) || (GNUNET_YES == monitor_connections) )
930   {
931     FPRINTF (stdout, _("Peer `%s': %s %s in state `%s' until %s\n"),
932         GNUNET_i2s (id),
933         (NULL == transport) ? "<none>" : transport,
934         (NULL == transport) ? "<none>" : addr,
935         GNUNET_TRANSPORT_ps2s (state),
936         GNUNET_STRINGS_absolute_time_to_string (state_timeout));
937   }
938   else
939   {
940     /* Only connected peers, skip state */
941     FPRINTF (stdout, _("Peer `%s': %s %s\n"), GNUNET_i2s (id), transport, addr);
942   }
943
944 }
945
946 static void
947 process_peer_string (void *cls, const char *address)
948 {
949   struct PeerResolutionContext *rc = cls;
950
951   if (address != NULL )
952   {
953     print_info (&rc->id, rc->transport, address, rc->state, rc->state_timeout);
954     rc->printed = GNUNET_YES;
955   }
956   else
957   {
958     /* done */
959     GNUNET_assert(address_resolutions > 0);
960     address_resolutions--;
961     if (GNUNET_NO == rc->printed)
962     {
963       if (numeric == GNUNET_NO)
964       {
965         /* Failed to resolve address, try numeric lookup */
966         resolve_peer_address (&rc->id, rc->addrcp, GNUNET_YES,
967             rc->state, rc->state_timeout);
968       }
969       else
970       {
971         print_info (&rc->id, rc->transport, "<unable to resolve address>",
972             rc->state, rc->state_timeout);
973       }
974     }
975     GNUNET_free (rc->transport);
976     GNUNET_free (rc->addrcp);
977     GNUNET_CONTAINER_DLL_remove(rc_head, rc_tail, rc);
978     GNUNET_free(rc);
979     if ((0 == address_resolutions) && (iterate_connections))
980     {
981       if (GNUNET_SCHEDULER_NO_TASK != end)
982       {
983         GNUNET_SCHEDULER_cancel (end);
984         end = GNUNET_SCHEDULER_NO_TASK;
985       }
986       if (GNUNET_SCHEDULER_NO_TASK != op_timeout)
987       {
988         GNUNET_SCHEDULER_cancel (op_timeout);
989         op_timeout = GNUNET_SCHEDULER_NO_TASK;
990       }
991       ret = 0;
992       end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL );
993     }
994   }
995 }
996
997 static void
998 resolve_peer_address (const struct GNUNET_PeerIdentity *id,
999     const struct GNUNET_HELLO_Address *address, int numeric,
1000     enum GNUNET_TRANSPORT_PeerState state,
1001     struct GNUNET_TIME_Absolute state_timeout)
1002 {
1003   struct PeerResolutionContext *rc;
1004
1005   rc = GNUNET_new (struct PeerResolutionContext);
1006   GNUNET_assert(NULL != rc);
1007   GNUNET_CONTAINER_DLL_insert(rc_head, rc_tail, rc);
1008   address_resolutions++;
1009
1010   rc->id = (*id);
1011   rc->transport = GNUNET_strdup(address->transport_name);
1012   rc->addrcp = GNUNET_HELLO_address_copy (address);
1013   rc->printed = GNUNET_NO;
1014   rc->state = state;
1015   rc->state_timeout = state_timeout;
1016   /* Resolve address to string */
1017   rc->asc = GNUNET_TRANSPORT_address_to_string (cfg, address, numeric,
1018       RESOLUTION_TIMEOUT, &process_peer_string, rc);
1019 }
1020
1021 /**
1022  * Function called with information about a peers during a one shot iteration
1023  *
1024  * @param cls closure
1025  * @param peer identity of the peer, NULL for final callback when operation done
1026  * @param address binary address used to communicate with this peer,
1027  *  NULL on disconnect or when done
1028  * @param state current state this peer is in
1029  * @param state_timeout time out for the current state
1030  *
1031  */
1032 static void
1033 process_peer_iteration_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
1034     const struct GNUNET_HELLO_Address *address,
1035     enum GNUNET_TRANSPORT_PeerState state,
1036     struct GNUNET_TIME_Absolute state_timeout)
1037 {
1038   if (peer == NULL )
1039   {
1040     /* done */
1041     address_resolution_in_progress = GNUNET_NO;
1042     pic = NULL;
1043     if (GNUNET_SCHEDULER_NO_TASK != end)
1044       GNUNET_SCHEDULER_cancel (end);
1045     end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL );
1046     return;
1047   }
1048
1049   if ((GNUNET_NO == iterate_all) && (GNUNET_NO == GNUNET_TRANSPORT_is_connected(state)) )
1050       return; /* Display only connected peers */
1051
1052   if (GNUNET_SCHEDULER_NO_TASK != op_timeout)
1053     GNUNET_SCHEDULER_cancel (op_timeout);
1054   op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout,
1055       NULL );
1056
1057   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received address for peer `%s': %s\n",
1058       GNUNET_i2s (peer), address->transport_name);
1059
1060   if (NULL != address)
1061     resolve_peer_address (peer, address, numeric, state, state_timeout);
1062   else
1063     print_info (peer, NULL, NULL, state, state_timeout);
1064 }
1065
1066
1067 /**
1068  * Function called with information about a peers
1069  *
1070  * @param cls closure
1071  * @param peer identity of the peer, NULL for final callback when operation done
1072  * @param address binary address used to communicate with this peer,
1073  *  NULL on disconnect or when done
1074  * @param state current state this peer is in
1075  * @param state_timeout time out for the current state
1076  *
1077  */
1078 static void
1079 process_peer_monitoring_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
1080     const struct GNUNET_HELLO_Address *address,
1081     enum GNUNET_TRANSPORT_PeerState state,
1082     struct GNUNET_TIME_Absolute state_timeout)
1083 {
1084   struct MonitoredPeer *m;
1085
1086   if (peer == NULL )
1087   {
1088     /* done */
1089     address_resolution_in_progress = GNUNET_NO;
1090     pic = NULL;
1091     if (GNUNET_SCHEDULER_NO_TASK != end)
1092       GNUNET_SCHEDULER_cancel (end);
1093     end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL );
1094     return;
1095   }
1096
1097   if (GNUNET_SCHEDULER_NO_TASK != op_timeout)
1098     GNUNET_SCHEDULER_cancel (op_timeout);
1099   op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout,
1100       NULL );
1101
1102   if (NULL == (m = GNUNET_CONTAINER_multipeermap_get (monitored_peers, peer)))
1103   {
1104     m = GNUNET_new (struct MonitoredPeer);
1105     GNUNET_CONTAINER_multipeermap_put (monitored_peers, peer,
1106         m, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
1107   }
1108   else
1109   {
1110     if ( (m->state == state) &&
1111       (m->state_timeout.abs_value_us == state_timeout.abs_value_us) &&
1112       ((NULL == address) && (NULL == m->address)) )
1113     {
1114       return; /* No real change */
1115     }
1116     if ( (m->state == state) && ((NULL != address) && (NULL != m->address)) &&
1117         (0 == GNUNET_HELLO_address_cmp(m->address, address)) )
1118       return; /* No real change */
1119   }
1120
1121   if (NULL != m->address)
1122   {
1123     GNUNET_free (m->address);
1124     m->address = NULL;
1125   }
1126   if (NULL != address)
1127     m->address = GNUNET_HELLO_address_copy (address);
1128   m->state = state;
1129   m->state_timeout = state_timeout;
1130
1131   if (NULL != address)
1132     resolve_peer_address (peer, m->address, numeric, m->state, m->state_timeout);
1133   else
1134     print_info (peer, NULL, NULL, m->state, m->state_timeout);
1135 }
1136
1137 static void
1138 try_connect_cb (void *cls, const int result)
1139 {
1140   static int retries = 0;
1141   if (GNUNET_OK == result)
1142   {
1143     tc_handle = NULL;
1144     return;
1145   }
1146   retries++;
1147   if (retries < 10)
1148     tc_handle = GNUNET_TRANSPORT_try_connect (handle, &pid, try_connect_cb,
1149         NULL );
1150   else
1151   {
1152     FPRINTF (stderr, "%s",
1153         _("Failed to send connect request to transport service\n") );
1154     if (GNUNET_SCHEDULER_NO_TASK != end)
1155       GNUNET_SCHEDULER_cancel (end);
1156     ret = 1;
1157     end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL );
1158     return;
1159   }
1160 }
1161
1162 /**
1163  * Function called with the result of the check if the 'transport'
1164  * service is running.
1165  *
1166  * @param cls closure with our configuration
1167  * @param result #GNUNET_YES if transport is running
1168  */
1169 static void
1170 testservice_task (void *cls, int result)
1171 {
1172   int counter = 0;
1173   ret = 1;
1174
1175   if (GNUNET_YES != result)
1176   {
1177     FPRINTF (stderr, _("Service `%s' is not running\n"), "transport");
1178     return;
1179   }
1180
1181   if ((NULL != cpid)
1182       && (GNUNET_OK
1183           != GNUNET_CRYPTO_eddsa_public_key_from_string (cpid, strlen (cpid),
1184               &pid.public_key)))
1185   {
1186     FPRINTF (stderr, _("Failed to parse peer identity `%s'\n"), cpid);
1187     return;
1188   }
1189
1190   counter = benchmark_send + benchmark_receive + iterate_connections
1191       + monitor_connections + monitor_connects + try_connect
1192       + iterate_validation + monitor_validation;
1193
1194   if (1 < counter)
1195   {
1196     FPRINTF (stderr,
1197         _("Multiple operations given. Please choose only one operation: %s, %s, %s, %s, %s, %s\n"),
1198         "connect", "benchmark send", "benchmark receive", "information",
1199         "monitor", "events");
1200     return;
1201   }
1202   if (0 == counter)
1203   {
1204     FPRINTF (stderr,
1205         _("No operation given. Please choose one operation: %s, %s, %s, %s, %s, %s\n"),
1206         "connect", "benchmark send", "benchmark receive", "information",
1207         "monitor", "events");
1208     return;
1209   }
1210
1211   if (try_connect) /* -C: Connect to peer */
1212   {
1213     if (NULL == cpid)
1214     {
1215       FPRINTF (stderr, _("Option `%s' makes no sense without option `%s'.\n"),
1216           "-C", "-p");
1217       ret = 1;
1218       return;
1219     }
1220     handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, &notify_receive,
1221         &notify_connect, &notify_disconnect);
1222     if (NULL == handle)
1223     {
1224       FPRINTF (stderr, "%s", _("Failed to connect to transport service\n") );
1225       ret = 1;
1226       return;
1227     }
1228     tc_handle = GNUNET_TRANSPORT_try_connect (handle, &pid, try_connect_cb,
1229         NULL );
1230     if (NULL == tc_handle)
1231     {
1232       FPRINTF (stderr, "%s",
1233           _("Failed to send request to transport service\n") );
1234       ret = 1;
1235       return;
1236     }
1237     op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout,
1238         NULL );
1239
1240   }
1241   else if (benchmark_send) /* -s: Benchmark sending */
1242   {
1243     if (NULL == cpid)
1244     {
1245       FPRINTF (stderr, _("Option `%s' makes no sense without option `%s'.\n"),
1246           "-s", "-p");
1247       ret = 1;
1248       return;
1249     }
1250     handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, &notify_receive,
1251         &notify_connect, &notify_disconnect);
1252     if (NULL == handle)
1253     {
1254       FPRINTF (stderr, "%s", _("Failed to connect to transport service\n") );
1255       ret = 1;
1256       return;
1257     }
1258     tc_handle = GNUNET_TRANSPORT_try_connect (handle, &pid, try_connect_cb,
1259         NULL );
1260     if (NULL == tc_handle)
1261     {
1262       FPRINTF (stderr, "%s",
1263           _("Failed to send request to transport service\n") );
1264       ret = 1;
1265       return;
1266     }
1267     start_time = GNUNET_TIME_absolute_get ();
1268     op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout,
1269         NULL );
1270   }
1271   else if (benchmark_receive) /* -b: Benchmark receiving */
1272   {
1273     handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, &notify_receive, NULL,
1274         NULL );
1275     if (NULL == handle)
1276     {
1277       FPRINTF (stderr, "%s", _("Failed to connect to transport service\n") );
1278       ret = 1;
1279       return;
1280     }
1281     if (verbosity > 0)
1282       FPRINTF (stdout, "%s", _("Starting to receive benchmark data\n") );
1283     start_time = GNUNET_TIME_absolute_get ();
1284
1285   }
1286   else if (iterate_connections) /* -i: List information about peers once */
1287   {
1288     address_resolution_in_progress = GNUNET_YES;
1289     pic = GNUNET_TRANSPORT_monitor_peers (cfg, (NULL == cpid) ? NULL : &pid,
1290         GNUNET_YES, TIMEOUT, &process_peer_iteration_cb, (void *) cfg);
1291     op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout,
1292         NULL );
1293   }
1294   else if (monitor_connections) /* -m: List information about peers continuously */
1295   {
1296     monitored_peers = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
1297     address_resolution_in_progress = GNUNET_YES;
1298     pic = GNUNET_TRANSPORT_monitor_peers (cfg, (NULL == cpid) ? NULL : &pid,
1299         GNUNET_NO, TIMEOUT, &process_peer_monitoring_cb, (void *) cfg);
1300   }
1301   else if (iterate_validation) /* -d: Print information about validations */
1302   {
1303     vic = GNUNET_TRANSPORT_monitor_validation_entries (cfg,
1304         (NULL == cpid) ? NULL : &pid,
1305         GNUNET_YES, TIMEOUT, &process_validation_cb, (void *) cfg);
1306   }
1307   else if (monitor_validation) /* -f: Print information about validations continuously */
1308   {
1309     vic = GNUNET_TRANSPORT_monitor_validation_entries (cfg,
1310         (NULL == cpid) ? NULL : &pid,
1311         GNUNET_NO, TIMEOUT, &process_validation_cb, (void *) cfg);
1312   }
1313   else if (monitor_connects) /* -e : Monitor (dis)connect events continuously */
1314   {
1315     monitor_connect_counter = 0;
1316     handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, NULL,
1317         &monitor_notify_connect, &monitor_notify_disconnect);
1318     if (NULL == handle)
1319     {
1320       FPRINTF (stderr, "%s", _("Failed to connect to transport service\n") );
1321       ret = 1;
1322       return;
1323     }
1324     ret = 0;
1325   }
1326   else
1327   {
1328     GNUNET_break(0);
1329     return;
1330   }
1331
1332   end = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
1333       &shutdown_task, NULL );
1334
1335 }
1336
1337 /**
1338  * Main function that will be run by the scheduler.
1339  *
1340  * @param cls closure
1341  * @param args remaining command-line arguments
1342  * @param cfgfile name of the configuration file used (for saving, can be NULL!)
1343  * @param mycfg configuration
1344  */
1345 static void
1346 run (void *cls, char * const *args, const char *cfgfile,
1347     const struct GNUNET_CONFIGURATION_Handle *mycfg)
1348 {
1349   cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg;
1350   if (test_configuration)
1351   {
1352     do_test_configuration (cfg);
1353     return;
1354   }
1355   GNUNET_CLIENT_service_test ("transport", cfg, GNUNET_TIME_UNIT_SECONDS,
1356       &testservice_task, (void *) cfg);
1357 }
1358
1359 int
1360 main (int argc, char * const *argv)
1361 {
1362   int res;
1363   static const struct GNUNET_GETOPT_CommandLineOption options[] =
1364       {
1365           { 'a', "all", NULL,
1366               gettext_noop ("print information for all peers (instead of only connected peers )"),
1367               0, &GNUNET_GETOPT_set_one, &iterate_all },
1368           { 'b', "benchmark", NULL,
1369               gettext_noop ("measure how fast we are receiving data from all peers (until CTRL-C)"),
1370               0, &GNUNET_GETOPT_set_one, &benchmark_receive }, { 'C', "connect",
1371               NULL, gettext_noop ("connect to a peer"), 0,
1372               &GNUNET_GETOPT_set_one, &try_connect },
1373           { 'd', "validation", NULL,
1374               gettext_noop ("print information for all pending validations "),
1375               0, &GNUNET_GETOPT_set_one, &iterate_validation },
1376           { 'f', "monitorvalidation", NULL,
1377               gettext_noop ("print information for all pending validations continously"),
1378               0, &GNUNET_GETOPT_set_one, &monitor_validation },
1379           { 'i', "information", NULL,
1380               gettext_noop ("provide information about all current connections (once)"),
1381               0, &GNUNET_GETOPT_set_one, &iterate_connections },
1382           { 'm', "monitor", NULL,
1383               gettext_noop ("provide information about all current connections (continuously)"),
1384               0, &GNUNET_GETOPT_set_one, &monitor_connections },
1385           { 'e', "events", NULL,
1386               gettext_noop ("provide information about all connects and disconnect events (continuously)"),
1387               0, &GNUNET_GETOPT_set_one, &monitor_connects }, { 'n', "numeric",
1388               NULL, gettext_noop ("do not resolve hostnames"), 0,
1389               &GNUNET_GETOPT_set_one, &numeric }, { 'p', "peer", "PEER",
1390               gettext_noop ("peer identity"), 1, &GNUNET_GETOPT_set_string,
1391               &cpid }, { 's', "send", NULL, gettext_noop
1392           ("send data for benchmarking to the other peer (until CTRL-C)"), 0,
1393               &GNUNET_GETOPT_set_one, &benchmark_send },
1394           { 't', "test", NULL,
1395               gettext_noop ("test transport configuration (involves external server)"),
1396               0, &GNUNET_GETOPT_set_one, &test_configuration },
1397               GNUNET_GETOPT_OPTION_VERBOSE (&verbosity),
1398               GNUNET_GETOPT_OPTION_END };
1399
1400   if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1401     return 2;
1402
1403   res = GNUNET_PROGRAM_run (argc, argv, "gnunet-transport", gettext_noop
1404   ("Direct access to transport service."), options, &run, NULL );
1405   GNUNET_free((void * ) argv);
1406   if (GNUNET_OK == res)
1407     return ret;
1408   return 1;
1409 }
1410
1411 /* end of gnunet-transport.c */