6d14d51aa8c4fff1b6212345b6cdf2da1e1cd82a
[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, 30)
43 #define RESOLUTION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
44
45 /**
46  * Which peer should we connect to?
47  */
48 static char *cpid;
49
50 /**
51  * Handle to transport service.
52  */
53 static struct GNUNET_TRANSPORT_Handle *handle;
54
55 /**
56  * Option -s.
57  */
58 static int benchmark_send;
59
60 /**
61  * Option -b.
62  */
63 static int benchmark_receive;
64
65 /**
66  * Option -l.
67  */
68 static int benchmark_receive;
69
70 /**
71  * Option -i.
72  */
73 static int iterate_connections;
74
75 /**
76  * Option -t.
77  */
78 static int test_configuration;
79
80 /**
81  * Option -c.
82  */
83 static int monitor_connects;
84
85 /**
86  * Option -m.
87  */
88 static int monitor_connections;
89
90 /**
91  * Option -n.
92  */
93 static int numeric;
94
95 /**
96  * Global return value (0 success).
97  */
98 static int ret;
99
100 /**
101  * Current number of connections in monitor mode
102  */
103 static int monitor_connect_counter;
104
105 /**
106  * Number of bytes of traffic we received so far.
107  */
108 static unsigned long long traffic_received;
109
110 /**
111  * Number of bytes of traffic we sent so far.
112  */
113 static unsigned long long traffic_sent;
114
115 /**
116  * Starting time of transmitting/receiving data.
117  */
118 static struct GNUNET_TIME_Absolute start_time;
119
120 /**
121  * Handle for current transmission request.
122  */
123 static struct GNUNET_TRANSPORT_TransmitHandle *th;
124
125 /**
126  *
127  */
128 struct GNUNET_TRANSPORT_PeerIterateContext *pic;
129
130 /**
131  * Identity of the peer we transmit to / connect to.
132  * (equivalent to 'cpid' string).
133  */
134 static struct GNUNET_PeerIdentity pid;
135
136 /**
137  * Task scheduled for cleanup / termination of the process.
138  */
139 static GNUNET_SCHEDULER_TaskIdentifier end;
140
141 static struct GNUNET_CONTAINER_MultiHashMap *peers;
142
143 /**
144  * Selected level of verbosity.
145  */
146 static int verbosity;
147
148 /**
149  * Resolver process handle.
150  */
151 struct GNUNET_OS_Process *resolver;
152
153 /**
154  * Number of tasks running that still need the resolver.
155  */
156 static unsigned int resolver_users;
157
158 /**
159  * Number of address resolutions pending
160  */
161 static unsigned int address_resolutions;
162
163 /**
164  * Address resolutions pending in progress
165  */
166 static unsigned int address_resolution_in_progress;
167
168 /**
169  * Context for a plugin test.
170  */
171 struct TestContext
172 {
173
174   /**
175    * Handle to the active NAT test.
176    */
177   struct GNUNET_NAT_Test *tst;
178
179   /**
180    * Task identifier for the timeout.
181    */
182   GNUNET_SCHEDULER_TaskIdentifier tsk;
183
184   /**
185    * Name of plugin under test.
186    */
187   const char *name;
188
189 };
190
191
192 /**
193  * Task run in monitor mode when the user presses CTRL-C to abort.
194  * Stops monitoring activity.
195  *
196  * @param cls the 'struct GNUNET_TRANSPORT_PeerIterateContext *'
197  * @param tc scheduler context
198  */
199 static void
200 shutdown_task (void *cls,
201                const struct GNUNET_SCHEDULER_TaskContext *tc)
202 {
203   if (NULL != pic)
204   {
205       GNUNET_TRANSPORT_peer_get_active_addresses_cancel (pic);
206       pic = NULL;
207   }
208   if (NULL != th)
209   {
210     GNUNET_TRANSPORT_notify_transmit_ready_cancel(th);
211     th = NULL;
212   }
213   if (NULL != handle)
214   {
215     GNUNET_TRANSPORT_disconnect(handle);
216     handle = NULL;
217   }
218
219   if (NULL != peers)
220   {
221     GNUNET_CONTAINER_multihashmap_destroy (peers);
222     peers = NULL;
223   }
224 }
225
226 /**
227  * Display the result of the test.
228  *
229  * @param tc test context
230  * @param result GNUNET_YES on success
231  */
232 static void
233 display_test_result (struct TestContext *tc, int result)
234 {
235   if (GNUNET_YES != result)
236   {
237     FPRINTF (stderr, "Configuration for plugin `%s' did not work!\n", tc->name);
238   }
239   else
240   {
241     FPRINTF (stderr, "Configuration for plugin `%s' is working!\n", tc->name);
242   }
243   if (GNUNET_SCHEDULER_NO_TASK != tc->tsk)
244   {
245     GNUNET_SCHEDULER_cancel (tc->tsk);
246     tc->tsk = GNUNET_SCHEDULER_NO_TASK;
247   }
248   if (NULL != tc->tst)
249   {
250     GNUNET_NAT_test_stop (tc->tst);
251     tc->tst = NULL;
252   }
253   GNUNET_free (tc);
254   resolver_users--;
255   if ((0 == resolver_users) && (NULL != resolver))
256   {
257     GNUNET_break (0 == GNUNET_OS_process_kill (resolver, SIGTERM));
258     GNUNET_OS_process_destroy (resolver);
259     resolver = NULL;
260   }
261 }
262
263
264 /**
265  * Function called by NAT on success.
266  * Clean up and update GUI (with success).
267  *
268  * @param cls test context
269  * @param success currently always GNUNET_OK
270  */
271 static void
272 result_callback (void *cls, int success)
273 {
274   struct TestContext *tc = cls;
275
276   display_test_result (tc, success);
277 }
278
279
280 /**
281  * Function called if NAT failed to confirm success.
282  * Clean up and update GUI (with failure).
283  *
284  * @param cls test context
285  * @param tc scheduler callback
286  */
287 static void
288 fail_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
289 {
290   struct TestContext *tstc = cls;
291
292   tstc->tsk = GNUNET_SCHEDULER_NO_TASK;
293   display_test_result (tstc, GNUNET_NO);
294 }
295
296
297 /**
298  * Test our plugin's configuration (NAT traversal, etc.).
299  *
300  * @param cfg configuration to test
301  */
302 static void
303 do_test_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg)
304 {
305   char *plugins;
306   char *tok;
307   unsigned long long bnd_port;
308   unsigned long long adv_port;
309   struct TestContext *tc;
310
311   if (GNUNET_OK !=
312       GNUNET_CONFIGURATION_get_value_string (cfg, "transport", "plugins",
313                                              &plugins))
314   {
315     FPRINTF (stderr,
316              "%s",
317              _
318              ("No transport plugins configured, peer will never communicate\n"));
319     ret = 4;
320     return;
321   }
322   for (tok = strtok (plugins, " "); tok != NULL; tok = strtok (NULL, " "))
323   {
324     char section[12 + strlen (tok)];
325
326     GNUNET_snprintf (section, sizeof (section), "transport-%s", tok);
327     if (GNUNET_OK !=
328         GNUNET_CONFIGURATION_get_value_number (cfg, section, "PORT", &bnd_port))
329     {
330       FPRINTF (stderr,
331                _("No port configured for plugin `%s', cannot test it\n"), tok);
332       continue;
333     }
334     if (GNUNET_OK !=
335         GNUNET_CONFIGURATION_get_value_number (cfg, section, "ADVERTISED_PORT",
336                                                &adv_port))
337       adv_port = bnd_port;
338     if (NULL == resolver)
339       resolver =
340           GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-service-resolver",
341                                    "gnunet-service-resolver", NULL);
342     resolver_users++;
343     GNUNET_RESOLVER_connect (cfg);
344     tc = GNUNET_malloc (sizeof (struct TestContext));
345     tc->name = GNUNET_strdup (tok);
346     tc->tst =
347         GNUNET_NAT_test_start (cfg,
348                                (0 ==
349                                 strcasecmp (tok,
350                                             "udp")) ? GNUNET_NO : GNUNET_YES,
351                                (uint16_t) bnd_port, (uint16_t) adv_port,
352                                &result_callback, tc);
353     if (NULL == tc->tst)
354     {
355       display_test_result (tc, GNUNET_SYSERR);
356       continue;
357     }
358     tc->tsk = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &fail_timeout, tc);
359   }
360   GNUNET_free (plugins);
361 }
362
363
364 /**
365  * Shutdown, print statistics.
366  */
367 static void
368 do_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
369 {
370   struct GNUNET_TIME_Relative duration;
371
372   if (NULL != th)
373   {
374     GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
375     th = NULL;
376   }
377   GNUNET_TRANSPORT_disconnect (handle);
378   if (benchmark_receive)
379   {
380     duration = GNUNET_TIME_absolute_get_duration (start_time);
381     FPRINTF (stdout, _("Received %llu bytes/s (%llu bytes in %s)\n"),
382              1000 * traffic_received / (1 + duration.rel_value),
383              traffic_received,
384              GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
385   }
386   if (benchmark_send)
387   {
388     duration = GNUNET_TIME_absolute_get_duration (start_time);
389     FPRINTF (stdout, _("Transmitted %llu bytes/s (%llu bytes in %s)\n"),
390              1000 * traffic_sent / (1 + duration.rel_value), traffic_sent,
391              GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
392   }
393 }
394
395
396 /**
397  * Function called to notify a client about the socket
398  * begin ready to queue more data.  "buf" will be
399  * NULL and "size" zero if the socket was closed for
400  * writing in the meantime.
401  *
402  * @param cls closure
403  * @param size number of bytes available in buf
404  * @param buf where the callee should write the message
405  * @return number of bytes written to buf
406  */
407 static size_t
408 transmit_data (void *cls, size_t size, void *buf)
409 {
410   struct GNUNET_MessageHeader *m = buf;
411
412   if ((NULL == buf) && (0 == size))
413   {
414     th = NULL;
415     return 0;
416   }
417
418   GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
419   GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE);
420   m->size = ntohs (size);
421   m->type = ntohs (GNUNET_MESSAGE_TYPE_DUMMY);
422   memset (&m[1], 52, size - sizeof (struct GNUNET_MessageHeader));
423   traffic_sent += size;
424   th = GNUNET_TRANSPORT_notify_transmit_ready (handle, &pid, 32 * 1024, 0,
425                                                GNUNET_TIME_UNIT_FOREVER_REL,
426                                                &transmit_data, NULL);
427   if (verbosity > 0)
428     FPRINTF (stdout, _("Transmitting %u bytes to %s\n"), (unsigned int) size,
429              GNUNET_i2s (&pid));
430   return size;
431 }
432
433
434 /**
435  * Function called to notify transport users that another
436  * peer connected to us.
437  *
438  * @param cls closure
439  * @param peer the peer that connected
440  * @param ats performance data
441  * @param ats_count number of entries in ats (excluding 0-termination)
442  */
443 static void
444 notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
445                 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
446 {
447   if (verbosity > 0)
448     FPRINTF (stdout, _("Connected to %s\n"), GNUNET_i2s (peer));
449   if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity)))
450     return;
451   ret = 0;
452   if (benchmark_send)
453   {
454     start_time = GNUNET_TIME_absolute_get ();
455     if (NULL == th)
456       th = GNUNET_TRANSPORT_notify_transmit_ready (handle, peer, 32 * 1024, 0,
457                                                  GNUNET_TIME_UNIT_FOREVER_REL,
458                                                  &transmit_data, NULL);
459   }
460   else
461   {
462     /* all done, terminate instantly */
463     GNUNET_SCHEDULER_cancel (end);
464     end = GNUNET_SCHEDULER_add_now (&do_disconnect, NULL);
465   }
466 }
467
468
469 /**
470  * Function called to notify transport users that another
471  * peer disconnected from us.
472  *
473  * @param cls closure
474  * @param peer the peer that disconnected
475  */
476 static void
477 notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
478 {
479   if (verbosity > 0)
480     FPRINTF (stdout, _("Disconnected from %s\n"), GNUNET_i2s (peer));
481   if (NULL != th)
482   {
483     GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
484     th = NULL;
485   }
486
487 }
488
489 /**
490  * Function called to notify transport users that another
491  * peer connected to us.
492  *
493  * @param cls closure
494  * @param peer the peer that connected
495  * @param ats performance data
496  * @param ats_count number of entries in ats (excluding 0-termination)
497  */
498 static void
499 monitor_notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
500                 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
501 {
502   monitor_connect_counter ++;
503   struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get();
504   const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
505
506   FPRINTF (stdout, _("%24s: %-17s %4s   (%u connections in total)\n"),
507            now_str,
508            _("Connected to"),
509            GNUNET_i2s (peer),
510            monitor_connect_counter);
511 }
512
513
514 /**
515  * Function called to notify transport users that another
516  * peer disconnected from us.
517  *
518  * @param cls closure
519  * @param peer the peer that disconnected
520  */
521 static void
522 monitor_notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
523 {
524   struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get();
525   const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
526
527   GNUNET_assert (monitor_connect_counter > 0);
528   monitor_connect_counter --;
529
530   FPRINTF (stdout, _("%24s: %-17s %4s   (%u connections in total)\n"),
531            now_str,
532            _("Disconnected from"),
533            GNUNET_i2s (peer),
534            monitor_connect_counter);
535 }
536
537
538
539 /**
540  * Function called by the transport for each received message.
541  *
542  * @param cls closure
543  * @param peer (claimed) identity of the other peer
544  * @param message the message
545  * @param ats performance data
546  * @param ats_count number of entries in ats
547  */
548 static void
549 notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
550                 const struct GNUNET_MessageHeader *message,
551                 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
552 {
553   if (!benchmark_receive)
554     return;
555   if (GNUNET_MESSAGE_TYPE_DUMMY != ntohs (message->type))
556     return;
557   if (verbosity > 0)
558     FPRINTF (stdout, _("Received %u bytes from %s\n"),
559              (unsigned int) ntohs (message->size), GNUNET_i2s (peer));
560   if (traffic_received == 0)
561     start_time = GNUNET_TIME_absolute_get ();
562   traffic_received += ntohs (message->size);
563 }
564
565 struct ResolutionContext
566 {
567   struct GNUNET_HELLO_Address *addrcp;
568
569   int printed;
570 };
571
572
573 static void
574 process_string (void *cls, const char *address)
575 {
576   struct ResolutionContext *rc = cls;
577   struct GNUNET_HELLO_Address *addrcp = rc->addrcp;
578
579   if (address != NULL)
580   {
581     FPRINTF (stdout, _("Peer `%s': %s %s\n"), GNUNET_i2s (&addrcp->peer), addrcp->transport_name, address);
582     rc->printed = GNUNET_YES;
583   }
584   else
585   {
586     /* done */
587     GNUNET_assert (address_resolutions > 0);
588     address_resolutions --;
589     if (GNUNET_NO == rc->printed)
590       FPRINTF (stdout, _("Peer `%s': %s <unable to resolve address>\n"), GNUNET_i2s (&addrcp->peer), addrcp->transport_name);
591     GNUNET_free (rc->addrcp);
592     GNUNET_free (rc);
593     FPRINTF (stdout, _("Peer --: %u\n"), address_resolutions);
594     if (0 == address_resolutions)
595     {
596         if (GNUNET_SCHEDULER_NO_TASK == end)
597           GNUNET_SCHEDULER_cancel (end);
598         GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
599         GNUNET_break (0);
600     }
601   }
602 }
603
604 /**
605  * Function to call with a binary address
606  *
607  * @param cls closure
608  * @param peer identity of the peer
609  * @param address binary address (NULL on disconnect)
610  */
611 static void
612 process_address (void *cls, const struct GNUNET_PeerIdentity *peer,
613                  const struct GNUNET_HELLO_Address *address)
614 {
615   const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
616   struct ResolutionContext *rc;
617
618   if (peer == NULL)
619   {
620     /* done */
621     address_resolution_in_progress = GNUNET_NO;
622     pic = NULL;
623     return;
624   }
625   if (address == NULL)
626   {
627     FPRINTF (stdout, _("Peer `%s' disconnected\n"), GNUNET_i2s (peer));
628     return;
629   }
630
631   rc = GNUNET_malloc(sizeof (struct ResolutionContext));
632   rc->addrcp = GNUNET_HELLO_address_copy(address);
633   rc->printed = GNUNET_NO;
634
635   GNUNET_assert (NULL != rc);
636   address_resolutions ++;
637   FPRINTF (stdout, _("Peer `%s' ++: %u\n"), GNUNET_i2s (peer), address_resolutions);
638   /* Resolve address to string */
639   GNUNET_TRANSPORT_address_to_string (cfg, address, numeric,
640                                       RESOLUTION_TIMEOUT, &process_string,
641                                       rc);
642 }
643
644
645 static void
646 testservice_task (void *cls,
647                   const struct GNUNET_SCHEDULER_TaskContext *tc)
648 {
649   struct GNUNET_CONFIGURATION_Handle *cfg = cls;
650   int counter = 0;
651
652   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
653   {
654       FPRINTF (stderr, _("Service `%s' is not running\n"), "transport");
655       return;
656   }
657
658   counter = benchmark_send + benchmark_receive + iterate_connections +
659             monitor_connections + monitor_connects;
660
661   if (1 < counter)
662   {
663     FPRINTF (stderr, _("Multiple operations given. Please choose only one operation: %s, %s, %s, %s, %s\n"),
664              "benchmark send", "benchmark receive", "information", "monitor", "events");
665     return;
666   }
667   if (0 == counter)
668   {
669     FPRINTF (stderr, _("No operation given. Please choose one operation: %s, %s, %s, %s, %s\n"),
670              "benchmark send", "benchmark receive", "information", "monitor", "events");
671     return;
672   }
673
674
675   if (benchmark_send) /* Benchmark sending */
676   {
677     if (NULL == cpid)
678     {
679       FPRINTF (stderr, _("Option `%s' makes no sense without option `%s'.\n"),
680                "-s", "-C");
681       return;
682     }
683     ret = 1;
684     if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (cpid, &pid.hashPubKey))
685     {
686       FPRINTF (stderr, _("Failed to parse peer identity `%s'\n"), cpid);
687       return;
688     }
689     handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL,
690                                        &notify_receive,
691                                        &notify_connect,
692                                        &notify_disconnect);
693     GNUNET_TRANSPORT_try_connect (handle, &pid);
694     end = GNUNET_SCHEDULER_add_delayed (benchmark_send ?
695                                         GNUNET_TIME_UNIT_FOREVER_REL :
696                                         GNUNET_TIME_UNIT_SECONDS,
697                                         &do_disconnect,
698                                         NULL);
699   }
700   else if (benchmark_receive) /* Benchmark receiving */
701   {
702     handle =
703         GNUNET_TRANSPORT_connect (cfg, NULL, NULL, &notify_receive,
704                                   &notify_connect, &notify_disconnect);
705     GNUNET_TRANSPORT_try_connect (handle, &pid);
706     start_time = GNUNET_TIME_absolute_get ();
707     end =
708         GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
709                                       &do_disconnect, NULL);
710   }
711   else if (iterate_connections) /* List all active addresses once */
712   {
713     peers = GNUNET_CONTAINER_multihashmap_create (20, GNUNET_NO);
714     address_resolution_in_progress = GNUNET_YES;
715     pic = GNUNET_TRANSPORT_peer_get_active_addresses (cfg, NULL,
716                                                 GNUNET_NO,
717                                                 TIMEOUT,
718                                                 &process_address, (void *) cfg);
719   }
720   else if (monitor_connections) /* List all active addresses continously */
721   {
722     peers = GNUNET_CONTAINER_multihashmap_create (20, GNUNET_NO);
723     address_resolution_in_progress = GNUNET_YES;
724     pic = GNUNET_TRANSPORT_peer_get_active_addresses (cfg, NULL,
725                                                 GNUNET_YES,
726                                                 TIMEOUT,
727                                                 &process_address, (void *) cfg);
728   }
729   else if (monitor_connects) /* Monitor (dis)connect events continously */
730   {
731     monitor_connect_counter = 0;
732     handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, NULL,
733                                        &monitor_notify_connect,
734                                        &monitor_notify_disconnect);
735     if (NULL == handle)
736     {
737       GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
738       return;
739     }
740   }
741   else
742   {
743     GNUNET_break (0)
744     return;
745   }
746
747   end = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
748                                            &shutdown_task,
749                                            NULL);
750 }
751
752
753 /**
754  * Main function that will be run by the scheduler.
755  *
756  * @param cls closure
757  * @param args remaining command-line arguments
758  * @param cfgfile name of the configuration file used (for saving, can be NULL!)
759  * @param cfg configuration
760  */
761 static void
762 run (void *cls, char *const *args, const char *cfgfile,
763      const struct GNUNET_CONFIGURATION_Handle *cfg)
764 {
765   if (test_configuration)
766   {
767     do_test_configuration (cfg);
768   }
769
770   GNUNET_CLIENT_service_test ("transport", cfg,
771       GNUNET_TIME_UNIT_SECONDS,
772       &testservice_task,
773       (void *) cfg);
774 }
775
776
777 int
778 main (int argc, char *const *argv)
779 {
780   int res;
781   static const struct GNUNET_GETOPT_CommandLineOption options[] = {
782     {'b', "benchmark", NULL,
783      gettext_noop ("measure how fast we are receiving data (until CTRL-C)"),
784      0, &GNUNET_GETOPT_set_one, &benchmark_receive},
785     {'C', "connect", "PEER",
786      gettext_noop ("try to connect to the given peer"),
787      1, &GNUNET_GETOPT_set_string, &cpid},
788     {'i', "information", NULL,
789      gettext_noop ("provide information about all current connections (once)"),
790      0, &GNUNET_GETOPT_set_one, &iterate_connections},
791     {'m', "monitor", NULL,
792      gettext_noop ("provide information about all current connections (continuously)"),
793      0, &GNUNET_GETOPT_set_one, &monitor_connections},
794     {'e', "events", NULL,
795      gettext_noop ("provide information about all connects and disconnect events (continuously)"),
796      0, &GNUNET_GETOPT_set_one, &monitor_connects},
797     {'n', "numeric", NULL,
798      gettext_noop ("do not resolve hostnames"),
799      0, &GNUNET_GETOPT_set_one, &numeric},
800     {'s', "send", NULL,
801      gettext_noop
802      ("send data for benchmarking to the other peer (until CTRL-C)"),
803      0, &GNUNET_GETOPT_set_one, &benchmark_send},
804     {'t', "test", NULL,
805      gettext_noop ("test transport configuration (involves external server)"),
806      0, &GNUNET_GETOPT_set_one, &test_configuration},
807     GNUNET_GETOPT_OPTION_VERBOSE (&verbosity),
808     GNUNET_GETOPT_OPTION_END
809   };
810
811   if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
812     return 2;
813
814   res = GNUNET_PROGRAM_run (argc, argv, "gnunet-transport",
815                               gettext_noop
816                               ("Direct access to transport service."), options,
817                               &run, NULL);
818   GNUNET_free ((void *) argv);
819   if (GNUNET_OK == res)
820     return ret;
821   return 1;
822 }
823
824
825 /* end of gnunet-transport.c */