aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/transport/Makefile.am10
-rw-r--r--src/transport/gnunet-transport-list-connections.c123
-rw-r--r--src/transport/gnunet-transport.c53
3 files changed, 47 insertions, 139 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index 142d4de25..aa387ff2c 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -91,7 +91,6 @@ bin_PROGRAMS = \
91 gnunet-transport \ 91 gnunet-transport \
92 $(WLAN_BIN) \ 92 $(WLAN_BIN) \
93 gnunet-service-transport \ 93 gnunet-service-transport \
94 gnunet-transport-list-connections \
95 gnunet-transport-certificate-creation 94 gnunet-transport-certificate-creation
96 95
97#bin_SCRIPTS = \ 96#bin_SCRIPTS = \
@@ -121,15 +120,6 @@ gnunet_transport_wlan_helper_dummy_SOURCES = \
121gnunet_transport_wlan_helper_dummy_LDADD = \ 120gnunet_transport_wlan_helper_dummy_LDADD = \
122 $(top_builddir)/src/util/libgnunetutil.la 121 $(top_builddir)/src/util/libgnunetutil.la
123 122
124gnunet_transport_list_connections_SOURCES = \
125 gnunet-transport-list-connections.c
126gnunet_transport_list_connections_LDADD = \
127 $(top_builddir)/src/transport/libgnunettransport.la \
128 $(top_builddir)/src/util/libgnunetutil.la \
129 $(GN_LIBINTL)
130gnunet_transport_list_connections_DEPENDENCIES = \
131 libgnunettransport.la
132
133gnunet_transport_SOURCES = \ 123gnunet_transport_SOURCES = \
134 gnunet-transport.c 124 gnunet-transport.c
135gnunet_transport_LDADD = \ 125gnunet_transport_LDADD = \
diff --git a/src/transport/gnunet-transport-list-connections.c b/src/transport/gnunet-transport-list-connections.c
deleted file mode 100644
index 64b67dcd4..000000000
--- a/src/transport/gnunet-transport-list-connections.c
+++ /dev/null
@@ -1,123 +0,0 @@
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 transport/gnunet-transport-list-connections.c
23 *
24 * @brief Print all known address information about other peers.
25 *
26 * Lists all peers and connections that the transport service is
27 * aware of. Pretty prints addresses, peer id's, and whether
28 * or not the _address_ is connected. Note that these are not
29 * core level connections, only transport level connections.
30 *
31 * @author Nathan Evans
32 */
33#include "platform.h"
34#include "gnunet_crypto_lib.h"
35#include "gnunet_configuration_lib.h"
36#include "gnunet_getopt_lib.h"
37#include "gnunet_transport_service.h"
38#include "gnunet_program_lib.h"
39
40#define VERBOSE 0
41static int no_resolve;
42
43#if VERBOSE
44static unsigned int connection_count;
45#endif
46
47static const struct GNUNET_CONFIGURATION_Handle *cfg;
48
49/**
50 * Function to call with a human-readable format of an address
51 *
52 * @param cls closure
53 * @param address NULL on error, otherwise 0-terminated printable UTF-8 string
54 */
55static void
56process_address (void *cls, const struct GNUNET_PeerIdentity *peer,
57 const char *transport, const void *addr, size_t addrlen)
58{
59#if VERBOSE
60 connection_count++;
61#endif
62 if ((peer != NULL) || (transport != NULL) ||
63 ((addr != NULL) && (addrlen > 0)))
64 fprintf (stdout, "Peer `%s' plugin: `%s' address `%s'\n",
65 (peer != NULL) ? GNUNET_i2s (peer) : "<unknown>",
66 (transport != NULL) ? transport : "<unknown>", ((addr != NULL) &&
67 (addrlen > 0) &&
68 (transport !=
69 NULL)) ?
70 "how do i resolve the name without transport service?" :
71 "<unknown>");
72}
73
74
75/**
76 * Main function that will be run by the scheduler.
77 *
78 * @param cls closure
79 * @param args remaining command-line arguments
80 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
81 * @param c configuration
82 */
83static void
84run (void *cls, char *const *args, const char *cfgfile,
85 const struct GNUNET_CONFIGURATION_Handle *c)
86{
87
88 cfg = c;
89 if (args[0] != NULL)
90 {
91 fprintf (stderr, _("Invalid command line argument `%s'\n"), args[0]);
92 return;
93 }
94
95 GNUNET_TRANSPORT_address_iterate (cfg, GNUNET_TIME_UNIT_MINUTES,
96 &process_address, NULL);
97}
98
99
100/**
101 * The main function to obtain peer information.
102 *
103 * @param argc number of arguments from the command line
104 * @param argv command line arguments
105 * @return 0 ok, 1 on error
106 */
107int
108main (int argc, char *const *argv)
109{
110 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
111 {'n', "numeric", NULL,
112 gettext_noop ("don't resolve host names"),
113 0, &GNUNET_GETOPT_set_one, &no_resolve},
114 GNUNET_GETOPT_OPTION_END
115 };
116 return (GNUNET_OK ==
117 GNUNET_PROGRAM_run (argc, argv, "gnunet-list-connections",
118 gettext_noop
119 ("Print information about connected peers."),
120 options, &run, NULL)) ? 0 : 1;
121}
122
123/* end of gnunet-transport-list-connections.c */
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;
53static int benchmark_receive; 54static int benchmark_receive;
54 55
55/** 56/**
57 * Option -l.
58 */
59static int benchmark_receive;
60
61/**
62 * Option -i.
63 */
64static int iterate_connections;
65
66/**
56 * Global return value (0 success). 67 * Global return value (0 success).
57 */ 68 */
58static int ret; 69static 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 */
298static void
299process_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},