diff options
Diffstat (limited to 'src/transport/gnunet-transport.c')
-rw-r--r-- | src/transport/gnunet-transport.c | 53 |
1 files changed, 47 insertions, 6 deletions
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c index bc78e3d04..68f508f5b 100644 --- a/src/transport/gnunet-transport.c +++ b/src/transport/gnunet-transport.c | |||
@@ -22,6 +22,7 @@ | |||
22 | * @file src/transport/gnunet-transport.c | 22 | * @file src/transport/gnunet-transport.c |
23 | * @brief Tool to help configure, measure and control the transport subsystem. | 23 | * @brief Tool to help configure, measure and control the transport subsystem. |
24 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
25 | * @author Nathan Evans | ||
25 | * | 26 | * |
26 | * This utility can be used to test if a transport mechanism for | 27 | * This utility can be used to test if a transport mechanism for |
27 | * GNUnet is properly configured. | 28 | * GNUnet is properly configured. |
@@ -53,6 +54,16 @@ static int benchmark_send; | |||
53 | static int benchmark_receive; | 54 | static int benchmark_receive; |
54 | 55 | ||
55 | /** | 56 | /** |
57 | * Option -l. | ||
58 | */ | ||
59 | static int benchmark_receive; | ||
60 | |||
61 | /** | ||
62 | * Option -i. | ||
63 | */ | ||
64 | static int iterate_connections; | ||
65 | |||
66 | /** | ||
56 | * Global return value (0 success). | 67 | * Global return value (0 success). |
57 | */ | 68 | */ |
58 | static int ret; | 69 | static int ret; |
@@ -113,7 +124,7 @@ do_disconnect (void *cls, | |||
113 | if (benchmark_receive) | 124 | if (benchmark_receive) |
114 | { | 125 | { |
115 | duration = GNUNET_TIME_absolute_get_duration (start_time); | 126 | duration = GNUNET_TIME_absolute_get_duration (start_time); |
116 | fprintf (stderr, | 127 | fprintf (stdout, |
117 | _("Received %llu bytes/s (%llu bytes in %llu ms)\n"), | 128 | _("Received %llu bytes/s (%llu bytes in %llu ms)\n"), |
118 | 1000 * traffic_received / (1+duration.rel_value), | 129 | 1000 * traffic_received / (1+duration.rel_value), |
119 | traffic_received, | 130 | traffic_received, |
@@ -122,7 +133,7 @@ do_disconnect (void *cls, | |||
122 | if (benchmark_send) | 133 | if (benchmark_send) |
123 | { | 134 | { |
124 | duration = GNUNET_TIME_absolute_get_duration (start_time); | 135 | duration = GNUNET_TIME_absolute_get_duration (start_time); |
125 | fprintf (stderr, | 136 | fprintf (stdout, |
126 | _("Transmitted %llu bytes/s (%llu bytes in %llu ms)\n"), | 137 | _("Transmitted %llu bytes/s (%llu bytes in %llu ms)\n"), |
127 | 1000 * traffic_sent / (1+duration.rel_value), | 138 | 1000 * traffic_sent / (1+duration.rel_value), |
128 | traffic_sent, | 139 | traffic_sent, |
@@ -161,7 +172,7 @@ transmit_data (void *cls, size_t size, | |||
161 | GNUNET_TIME_UNIT_FOREVER_REL, | 172 | GNUNET_TIME_UNIT_FOREVER_REL, |
162 | &transmit_data, NULL); | 173 | &transmit_data, NULL); |
163 | if (verbosity > 0) | 174 | if (verbosity > 0) |
164 | fprintf (stderr, | 175 | fprintf (stdout, |
165 | _("Transmitting %u bytes to %s\n"), | 176 | _("Transmitting %u bytes to %s\n"), |
166 | (unsigned int) size, | 177 | (unsigned int) size, |
167 | GNUNET_i2s (&pid)); | 178 | GNUNET_i2s (&pid)); |
@@ -187,7 +198,7 @@ notify_connect (void *cls, | |||
187 | * ats, uint32_t ats_count) | 198 | * ats, uint32_t ats_count) |
188 | { | 199 | { |
189 | if (verbosity > 0) | 200 | if (verbosity > 0) |
190 | fprintf (stderr, | 201 | fprintf (stdout, |
191 | _("Connected to %s\n"), | 202 | _("Connected to %s\n"), |
192 | GNUNET_i2s (peer)); | 203 | GNUNET_i2s (peer)); |
193 | if (0 != memcmp (&pid, | 204 | if (0 != memcmp (&pid, |
@@ -228,7 +239,7 @@ notify_disconnect (void *cls, | |||
228 | GNUNET_PeerIdentity * peer) | 239 | GNUNET_PeerIdentity * peer) |
229 | { | 240 | { |
230 | if (verbosity > 0) | 241 | if (verbosity > 0) |
231 | fprintf (stderr, | 242 | fprintf (stdout, |
232 | _("Disconnected from %s\n"), | 243 | _("Disconnected from %s\n"), |
233 | GNUNET_i2s (peer)); | 244 | GNUNET_i2s (peer)); |
234 | if ( (0 == memcmp (&pid, | 245 | if ( (0 == memcmp (&pid, |
@@ -268,7 +279,7 @@ notify_receive (void *cls, | |||
268 | if (! benchmark_receive) | 279 | if (! benchmark_receive) |
269 | return; | 280 | return; |
270 | if (verbosity > 0) | 281 | if (verbosity > 0) |
271 | fprintf (stderr, | 282 | fprintf (stdout, |
272 | _("Received %u bytes from %s\n"), | 283 | _("Received %u bytes from %s\n"), |
273 | (unsigned int) ntohs (message->size), | 284 | (unsigned int) ntohs (message->size), |
274 | GNUNET_i2s (peer)); | 285 | GNUNET_i2s (peer)); |
@@ -279,6 +290,28 @@ notify_receive (void *cls, | |||
279 | 290 | ||
280 | 291 | ||
281 | /** | 292 | /** |
293 | * Function to call with a human-readable format of an address | ||
294 | * | ||
295 | * @param cls closure | ||
296 | * @param address NULL on error, otherwise 0-terminated printable UTF-8 string | ||
297 | */ | ||
298 | static void | ||
299 | process_address (void *cls, const struct GNUNET_PeerIdentity *peer, | ||
300 | const char *transport, const void *addr, size_t addrlen) | ||
301 | { | ||
302 | if ((peer != NULL) || (transport != NULL) || | ||
303 | ((addr != NULL) && (addrlen > 0))) | ||
304 | fprintf (stdout, | ||
305 | _("Peer `%s' plugin: `%s' address `%s'\n"), | ||
306 | (peer != NULL) ? GNUNET_i2s (peer) : "<unknown>", | ||
307 | (transport != NULL) ? transport : "<unknown>", | ||
308 | ((addr != NULL) && (addrlen > 0) && (transport != NULL)) ? | ||
309 | "how do i resolve the name without transport service?" : | ||
310 | "<unknown>"); | ||
311 | } | ||
312 | |||
313 | |||
314 | /** | ||
282 | * Main function that will be run by the scheduler. | 315 | * Main function that will be run by the scheduler. |
283 | * | 316 | * |
284 | * @param cls closure | 317 | * @param cls closure |
@@ -328,6 +361,11 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
328 | &do_disconnect, | 361 | &do_disconnect, |
329 | NULL); | 362 | NULL); |
330 | } | 363 | } |
364 | if (iterate_connections) | ||
365 | { | ||
366 | GNUNET_TRANSPORT_address_iterate (cfg, GNUNET_TIME_UNIT_MINUTES, | ||
367 | &process_address, NULL); | ||
368 | } | ||
331 | } | 369 | } |
332 | 370 | ||
333 | 371 | ||
@@ -341,6 +379,9 @@ main (int argc, char *const *argv) | |||
341 | {'C', "connect", "PEER", | 379 | {'C', "connect", "PEER", |
342 | gettext_noop ("try to connect to the given peer"), | 380 | gettext_noop ("try to connect to the given peer"), |
343 | 1, &GNUNET_GETOPT_set_string, &cpid}, | 381 | 1, &GNUNET_GETOPT_set_string, &cpid}, |
382 | {'i', "information", NULL, | ||
383 | gettext_noop ("provide information about all current connections (once)"), | ||
384 | 0, &GNUNET_GETOPT_set_one, &iterate_connections}, | ||
344 | {'s', "send", NULL, | 385 | {'s', "send", NULL, |
345 | gettext_noop ("send data for benchmarking to the other peer (until CTRL-C)"), | 386 | gettext_noop ("send data for benchmarking to the other peer (until CTRL-C)"), |
346 | 0, &GNUNET_GETOPT_set_one, &benchmark_send}, | 387 | 0, &GNUNET_GETOPT_set_one, &benchmark_send}, |