diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-10-25 14:14:37 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-10-25 14:14:37 +0000 |
commit | 18d7de54a90ef3b2f7c562573bc95513119d3466 (patch) | |
tree | a2db35a1c6450c6beb1bbabcdf16a5b1e8fe132f | |
parent | d02ab50a92b6af0ed638febb147d9a2fab447dd5 (diff) | |
download | gnunet-18d7de54a90ef3b2f7c562573bc95513119d3466.tar.gz gnunet-18d7de54a90ef3b2f7c562573bc95513119d3466.zip |
move ats-tool due to transport dependency
-rw-r--r-- | src/ats-tool/Makefile.am | 21 | ||||
-rw-r--r-- | src/ats-tool/gnunet-ats.c | 209 |
2 files changed, 230 insertions, 0 deletions
diff --git a/src/ats-tool/Makefile.am b/src/ats-tool/Makefile.am new file mode 100644 index 000000000..d39bef3e7 --- /dev/null +++ b/src/ats-tool/Makefile.am | |||
@@ -0,0 +1,21 @@ | |||
1 | INCLUDES = -I$(top_srcdir)/src/include | ||
2 | |||
3 | if MINGW | ||
4 | WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols | ||
5 | endif | ||
6 | |||
7 | if USE_COVERAGE | ||
8 | AM_CFLAGS = -fprofile-arcs -ftest-coverage | ||
9 | endif | ||
10 | |||
11 | bin_PROGRAMS = \ | ||
12 | gnunet-ats | ||
13 | |||
14 | gnunet_ats_SOURCES = \ | ||
15 | gnunet-ats.c gnunet-service-ats.h | ||
16 | gnunet_ats_LDADD = \ | ||
17 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
18 | $(top_builddir)/src/ats/libgnunetats.la \ | ||
19 | $(top_builddir)/src/transport/libgnunettransport.la \ | ||
20 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
21 | $(GN_LIBINTL) \ No newline at end of file | ||
diff --git a/src/ats-tool/gnunet-ats.c b/src/ats-tool/gnunet-ats.c new file mode 100644 index 000000000..a443778a4 --- /dev/null +++ b/src/ats-tool/gnunet-ats.c | |||
@@ -0,0 +1,209 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009 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/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 | /** | ||
34 | * Final status code. | ||
35 | */ | ||
36 | static int ret; | ||
37 | static int results; | ||
38 | static int resolve_addresses_numeric; | ||
39 | |||
40 | static struct GNUNET_ATS_PerformanceHandle *ph; | ||
41 | |||
42 | static struct GNUNET_CONFIGURATION_Handle *cfg; | ||
43 | |||
44 | GNUNET_SCHEDULER_TaskIdentifier end_task; | ||
45 | |||
46 | struct PendingResolutions | ||
47 | { | ||
48 | struct PendingResolutions *next; | ||
49 | struct PendingResolutions *prev; | ||
50 | |||
51 | struct GNUNET_HELLO_Address *address; | ||
52 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out; | ||
53 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in; | ||
54 | |||
55 | struct GNUNET_TRANSPORT_AddressToStringContext * tats_ctx; | ||
56 | }; | ||
57 | |||
58 | struct PendingResolutions *head; | ||
59 | struct PendingResolutions *tail; | ||
60 | |||
61 | void transport_addr_to_str_cb (void *cls, const char *address) | ||
62 | { | ||
63 | struct PendingResolutions * pr = cls; | ||
64 | if (NULL != address) | ||
65 | { | ||
66 | fprintf (stderr, _("Peer `%s' plugin `%s', address `%s', bandwidth out: %u Bytes/s, bandwidth in %u Bytes/s\n"), | ||
67 | GNUNET_i2s (&pr->address->peer), pr->address->transport_name, address, | ||
68 | ntohl (pr->bandwidth_out.value__), ntohl (pr->bandwidth_in.value__)); | ||
69 | } | ||
70 | else if (NULL != pr) | ||
71 | { | ||
72 | /* We're done */ | ||
73 | GNUNET_CONTAINER_DLL_remove (head, tail, pr); | ||
74 | GNUNET_free (pr->address); | ||
75 | GNUNET_free (pr); | ||
76 | } | ||
77 | |||
78 | } | ||
79 | |||
80 | void ats_perf_cb (void *cls, | ||
81 | const struct | ||
82 | GNUNET_HELLO_Address * | ||
83 | address, | ||
84 | struct | ||
85 | GNUNET_BANDWIDTH_Value32NBO | ||
86 | bandwidth_out, | ||
87 | struct | ||
88 | GNUNET_BANDWIDTH_Value32NBO | ||
89 | bandwidth_in, | ||
90 | const struct | ||
91 | GNUNET_ATS_Information * | ||
92 | ats, uint32_t ats_count) | ||
93 | { | ||
94 | struct PendingResolutions * pr; | ||
95 | |||
96 | pr = GNUNET_malloc (sizeof (struct PendingResolutions)); | ||
97 | pr->address = GNUNET_HELLO_address_copy (address); | ||
98 | pr->bandwidth_in = bandwidth_in; | ||
99 | pr->bandwidth_out = bandwidth_out; | ||
100 | pr->tats_ctx = GNUNET_TRANSPORT_address_to_string(cfg, address, | ||
101 | resolve_addresses_numeric, GNUNET_TIME_UNIT_FOREVER_REL, transport_addr_to_str_cb, pr); | ||
102 | GNUNET_CONTAINER_DLL_insert (head, tail, pr); | ||
103 | results++; | ||
104 | } | ||
105 | |||
106 | void end (void *cls, | ||
107 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
108 | { | ||
109 | struct PendingResolutions * pr; | ||
110 | struct PendingResolutions * next; | ||
111 | unsigned int pending; | ||
112 | |||
113 | GNUNET_ATS_performance_done (ph); | ||
114 | ph = NULL; | ||
115 | |||
116 | pending = 0; | ||
117 | next = head; | ||
118 | while (NULL != (pr = next)) | ||
119 | { | ||
120 | next = pr->next; | ||
121 | GNUNET_CONTAINER_DLL_remove (head, tail, pr); | ||
122 | GNUNET_TRANSPORT_address_to_string_cancel (pr->tats_ctx); | ||
123 | GNUNET_free (pr->address); | ||
124 | GNUNET_free (pr); | ||
125 | pending ++; | ||
126 | } | ||
127 | if (0 < pending) | ||
128 | fprintf (stderr, _("%u address resolutions had a timeout\n"), pending); | ||
129 | |||
130 | fprintf (stderr, _("ATS returned results for %u addresses\n"), results); | ||
131 | ret = 0; | ||
132 | } | ||
133 | |||
134 | void testservice_ats (void *cls, | ||
135 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
136 | { | ||
137 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; | ||
138 | |||
139 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) | ||
140 | { | ||
141 | FPRINTF (stderr, _("Service `%s' is not running\n"), "ats"); | ||
142 | return; | ||
143 | } | ||
144 | |||
145 | results = 0; | ||
146 | ph = GNUNET_ATS_performance_init (cfg, ats_perf_cb, NULL); | ||
147 | if (NULL == ph) | ||
148 | fprintf (stderr, _("Cannot connect to ATS service, exiting...\n")); | ||
149 | |||
150 | end_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end, NULL); | ||
151 | ret = 1; | ||
152 | } | ||
153 | |||
154 | /** | ||
155 | * Main function that will be run by the scheduler. | ||
156 | * | ||
157 | * @param cls closure | ||
158 | * @param args remaining command-line arguments | ||
159 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
160 | * @param cfg configuration | ||
161 | */ | ||
162 | static void | ||
163 | run (void *cls, char *const *args, const char *cfgfile, | ||
164 | const struct GNUNET_CONFIGURATION_Handle *my_cfg) | ||
165 | { | ||
166 | cfg = (struct GNUNET_CONFIGURATION_Handle *) my_cfg; | ||
167 | GNUNET_CLIENT_service_test ("ats", cfg, | ||
168 | GNUNET_TIME_UNIT_MINUTES, | ||
169 | &testservice_ats, | ||
170 | (void *) cfg); | ||
171 | } | ||
172 | |||
173 | |||
174 | /** | ||
175 | * The main function. | ||
176 | * | ||
177 | * @param argc number of arguments from the command line | ||
178 | * @param argv command line arguments | ||
179 | * @return 0 ok, 1 on error | ||
180 | */ | ||
181 | int | ||
182 | main (int argc, char *const *argv) | ||
183 | { | ||
184 | int res; | ||
185 | resolve_addresses_numeric = GNUNET_NO; | ||
186 | |||
187 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
188 | {'n', "numeric", NULL, | ||
189 | gettext_noop ("do not resolve hostnames"), | ||
190 | 0, &GNUNET_GETOPT_set_one, &resolve_addresses_numeric}, | ||
191 | GNUNET_GETOPT_OPTION_END | ||
192 | }; | ||
193 | |||
194 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | ||
195 | return 2; | ||
196 | |||
197 | res = GNUNET_PROGRAM_run (argc, argv, "gnunet-ats", | ||
198 | gettext_noop ("Print information about ATS state"), options, &run, | ||
199 | NULL); | ||
200 | GNUNET_free ((void *) argv); | ||
201 | |||
202 | if (GNUNET_OK == res) | ||
203 | return ret; | ||
204 | else | ||
205 | return 1; | ||
206 | |||
207 | } | ||
208 | |||
209 | /* end of gnunet-ats.c */ | ||