diff options
Diffstat (limited to 'src/ats-tool/gnunet-ats.c')
-rw-r--r-- | src/ats-tool/gnunet-ats.c | 478 |
1 files changed, 232 insertions, 246 deletions
diff --git a/src/ats-tool/gnunet-ats.c b/src/ats-tool/gnunet-ats.c index 553e9db7d..05e76a43f 100644 --- a/src/ats-tool/gnunet-ats.c +++ b/src/ats-tool/gnunet-ats.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2009--2013 Christian Grothoff (and other contributing authors) | 3 | (C) 2009--2013 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 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 | 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 | 7 | by the Free Software Foundation; either version 3, or (at your |
8 | option) any later version. | 8 | option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 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 | 16 | along with GNUnet; see the file COPYING. If not, write to the |
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file ats-tool/gnunet-ats.c | 22 | * @file ats-tool/gnunet-ats.c |
@@ -79,7 +79,6 @@ static int op_print_quotas; | |||
79 | */ | 79 | */ |
80 | static int op_monitor; | 80 | static int op_monitor; |
81 | 81 | ||
82 | |||
83 | static struct GNUNET_ATS_PerformanceHandle *ph; | 82 | static struct GNUNET_ATS_PerformanceHandle *ph; |
84 | 83 | ||
85 | static struct GNUNET_ATS_AddressListHandle *alh; | 84 | static struct GNUNET_ATS_AddressListHandle *alh; |
@@ -88,7 +87,6 @@ static struct GNUNET_CONFIGURATION_Handle *cfg; | |||
88 | 87 | ||
89 | static GNUNET_SCHEDULER_TaskIdentifier end_task; | 88 | static GNUNET_SCHEDULER_TaskIdentifier end_task; |
90 | 89 | ||
91 | |||
92 | struct PendingResolutions | 90 | struct PendingResolutions |
93 | { | 91 | { |
94 | struct PendingResolutions *next; | 92 | struct PendingResolutions *next; |
@@ -104,15 +102,12 @@ struct PendingResolutions | |||
104 | struct GNUNET_TRANSPORT_AddressToStringContext * tats_ctx; | 102 | struct GNUNET_TRANSPORT_AddressToStringContext * tats_ctx; |
105 | }; | 103 | }; |
106 | 104 | ||
107 | |||
108 | static struct PendingResolutions *head; | 105 | static struct PendingResolutions *head; |
109 | 106 | ||
110 | static struct PendingResolutions *tail; | 107 | static struct PendingResolutions *tail; |
111 | 108 | ||
112 | |||
113 | static void | 109 | static void |
114 | end (void *cls, | 110 | end(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
115 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
116 | { | 111 | { |
117 | struct PendingResolutions * pr; | 112 | struct PendingResolutions * pr; |
118 | struct PendingResolutions * next; | 113 | struct PendingResolutions * next; |
@@ -120,8 +115,8 @@ end (void *cls, | |||
120 | 115 | ||
121 | if (NULL != alh) | 116 | if (NULL != alh) |
122 | { | 117 | { |
123 | GNUNET_ATS_performance_list_addresses_cancel (alh); | 118 | GNUNET_ATS_performance_list_addresses_cancel (alh); |
124 | alh = NULL; | 119 | alh = NULL; |
125 | } | 120 | } |
126 | 121 | ||
127 | if (NULL != ph) | 122 | if (NULL != ph) |
@@ -134,23 +129,22 @@ end (void *cls, | |||
134 | next = head; | 129 | next = head; |
135 | while (NULL != (pr = next)) | 130 | while (NULL != (pr = next)) |
136 | { | 131 | { |
137 | next = pr->next; | 132 | next = pr->next; |
138 | GNUNET_CONTAINER_DLL_remove (head, tail, pr); | 133 | GNUNET_CONTAINER_DLL_remove(head, tail, pr); |
139 | GNUNET_TRANSPORT_address_to_string_cancel (pr->tats_ctx); | 134 | GNUNET_TRANSPORT_address_to_string_cancel (pr->tats_ctx); |
140 | GNUNET_free (pr->address); | 135 | GNUNET_free(pr->address); |
141 | GNUNET_free (pr); | 136 | GNUNET_free(pr); |
142 | pending ++; | 137 | pending++; |
143 | } | 138 | } |
144 | if (0 < pending) | 139 | if (0 < pending) |
145 | fprintf (stderr, _("%u address resolutions had a timeout\n"), pending); | 140 | fprintf (stderr, _("%u address resolutions had a timeout\n"), pending); |
146 | if (op_list_used || op_list_all) | 141 | if (op_list_used || op_list_all) |
147 | fprintf (stderr, _("ATS returned results for %u addresses\n"), results); | 142 | fprintf (stderr, _("ATS returned results for %u addresses\n"), results); |
148 | ret = 0; | 143 | ret = 0; |
149 | } | 144 | } |
150 | 145 | ||
151 | |||
152 | static void | 146 | static void |
153 | transport_addr_to_str_cb (void *cls, const char *address) | 147 | transport_addr_to_str_cb(void *cls, const char *address) |
154 | { | 148 | { |
155 | struct PendingResolutions * pr = cls; | 149 | struct PendingResolutions * pr = cls; |
156 | char *ats_str; | 150 | char *ats_str; |
@@ -168,97 +162,93 @@ transport_addr_to_str_cb (void *cls, const char *address) | |||
168 | network = GNUNET_ATS_NET_UNSPECIFIED; | 162 | network = GNUNET_ATS_NET_UNSPECIFIED; |
169 | for (c = 0; c < pr->ats_count; c++) | 163 | for (c = 0; c < pr->ats_count; c++) |
170 | { | 164 | { |
171 | ats_tmp = ats_str; | 165 | ats_tmp = ats_str; |
172 | 166 | ||
173 | ats_type = ntohl(pr->ats[c].type); | 167 | ats_type = ntohl (pr->ats[c].type); |
174 | ats_value = ntohl(pr->ats[c].value); | 168 | ats_value = ntohl (pr->ats[c].value); |
175 | 169 | ||
176 | if (ats_type > GNUNET_ATS_PropertyCount) | 170 | if (ats_type > GNUNET_ATS_PropertyCount) |
177 | { | 171 | { |
178 | GNUNET_break (0); | 172 | GNUNET_break(0); |
179 | continue; | 173 | continue; |
180 | } | 174 | } |
181 | 175 | ||
182 | switch (ats_type) { | 176 | switch (ats_type) |
183 | case GNUNET_ATS_NETWORK_TYPE: | 177 | { |
184 | if (ats_value > GNUNET_ATS_NetworkTypeCount) | 178 | case GNUNET_ATS_NETWORK_TYPE: |
185 | { | 179 | if (ats_value > GNUNET_ATS_NetworkTypeCount) |
186 | GNUNET_break (0); | ||
187 | continue; | ||
188 | } | ||
189 | network = ats_value; | ||
190 | GNUNET_asprintf (&ats_prop_value, "%s", GNUNET_ATS_print_network_type(ats_value)); | ||
191 | break; | ||
192 | default: | ||
193 | GNUNET_asprintf (&ats_prop_value, "%u", ats_value); | ||
194 | break; | ||
195 | } | ||
196 | if ((verbose) && (ats_type < GNUNET_ATS_PropertyCount)) | ||
197 | { | 180 | { |
198 | GNUNET_asprintf (&ats_str, "%s%s=%s, ", ats_tmp, ats_prop_arr[ats_type] , ats_prop_value); | 181 | GNUNET_break(0); |
199 | GNUNET_free (ats_tmp); | 182 | continue; |
200 | } | 183 | } |
201 | GNUNET_free (ats_prop_value); | 184 | network = ats_value; |
185 | GNUNET_asprintf (&ats_prop_value, "%s", | ||
186 | GNUNET_ATS_print_network_type (ats_value)); | ||
187 | break; | ||
188 | default: | ||
189 | GNUNET_asprintf (&ats_prop_value, "%u", ats_value); | ||
190 | break; | ||
191 | } | ||
192 | if ((verbose) && (ats_type < GNUNET_ATS_PropertyCount)) | ||
193 | { | ||
194 | GNUNET_asprintf (&ats_str, "%s%s=%s, ", ats_tmp, ats_prop_arr[ats_type], | ||
195 | ats_prop_value); | ||
196 | GNUNET_free(ats_tmp); | ||
197 | } | ||
198 | GNUNET_free(ats_prop_value); | ||
202 | } | 199 | } |
203 | 200 | ||
204 | fprintf (stderr, | 201 | fprintf (stderr, |
205 | _("Peer `%s' plugin `%s', address `%s', `%s' bw out: %u Bytes/s, bw in %u Bytes/s, %s\n"), | 202 | _("Peer `%s' plugin `%s', address `%s', `%s' bw out: %u Bytes/s, bw in %u Bytes/s, %s\n"), |
206 | GNUNET_i2s (&pr->address->peer), | 203 | GNUNET_i2s (&pr->address->peer), pr->address->transport_name, address, |
207 | pr->address->transport_name, | 204 | GNUNET_ATS_print_network_type (network), |
208 | address, | 205 | ntohl (pr->bandwidth_out.value__), ntohl (pr->bandwidth_in.value__), |
209 | GNUNET_ATS_print_network_type(network), | 206 | ats_str); |
210 | ntohl (pr->bandwidth_out.value__), | 207 | GNUNET_free(ats_str); |
211 | ntohl (pr->bandwidth_in.value__), | ||
212 | ats_str); | ||
213 | GNUNET_free (ats_str); | ||
214 | } | 208 | } |
215 | else | 209 | else |
216 | { | 210 | { |
217 | /* We're done */ | 211 | /* We're done */ |
218 | GNUNET_CONTAINER_DLL_remove (head, tail, pr); | 212 | GNUNET_CONTAINER_DLL_remove(head, tail, pr); |
219 | GNUNET_free (pr->address); | 213 | GNUNET_free(pr->address); |
220 | GNUNET_free (pr); | 214 | GNUNET_free(pr); |
221 | pending--; | 215 | pending--; |
222 | 216 | ||
223 | if ((GNUNET_YES == receive_done) && (0 == pending)) | 217 | if ((GNUNET_YES == receive_done) && (0 == pending)) |
224 | { | 218 | { |
225 | /* All messages received and no resolutions pending*/ | 219 | /* All messages received and no resolutions pending*/ |
226 | if (end_task != GNUNET_SCHEDULER_NO_TASK) | 220 | if (end_task != GNUNET_SCHEDULER_NO_TASK ) |
227 | GNUNET_SCHEDULER_cancel (end_task); | 221 | GNUNET_SCHEDULER_cancel (end_task); |
228 | end_task = GNUNET_SCHEDULER_add_now (end, NULL); | 222 | end_task = GNUNET_SCHEDULER_add_now (end, NULL ); |
229 | } | 223 | } |
230 | } | 224 | } |
231 | } | 225 | } |
232 | 226 | ||
233 | |||
234 | static void | 227 | static void |
235 | ats_perf_cb (void *cls, | 228 | ats_perf_cb(void *cls, const struct GNUNET_HELLO_Address *address, int active, |
236 | const struct GNUNET_HELLO_Address *address, | 229 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
237 | int active, | 230 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, |
238 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 231 | const struct GNUNET_ATS_Information *ats, uint32_t ats_count) |
239 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | ||
240 | const struct GNUNET_ATS_Information *ats, | ||
241 | uint32_t ats_count) | ||
242 | { | 232 | { |
243 | struct PendingResolutions * pr; | 233 | struct PendingResolutions * pr; |
244 | 234 | ||
245 | if (NULL != address) | 235 | if (NULL != address) |
246 | { | 236 | { |
247 | pr = GNUNET_malloc (sizeof (struct PendingResolutions) + | 237 | pr = GNUNET_malloc (sizeof (struct PendingResolutions) + |
248 | ats_count * sizeof (struct GNUNET_ATS_Information)); | 238 | ats_count * sizeof (struct GNUNET_ATS_Information)); |
249 | 239 | ||
250 | pr->ats_count = ats_count; | 240 | pr->ats_count = ats_count; |
251 | pr->ats = (struct GNUNET_ATS_Information *) &pr[1]; | 241 | pr->ats = (struct GNUNET_ATS_Information *) &pr[1]; |
252 | if (ats_count > 0) | 242 | if (ats_count > 0) |
253 | memcpy (pr->ats, ats, ats_count * sizeof (struct GNUNET_ATS_Information)); | 243 | memcpy (pr->ats, ats, ats_count * sizeof(struct GNUNET_ATS_Information)); |
254 | pr->address = GNUNET_HELLO_address_copy (address); | 244 | pr->address = GNUNET_HELLO_address_copy (address); |
255 | pr->bandwidth_in = bandwidth_in; | 245 | pr->bandwidth_in = bandwidth_in; |
256 | pr->bandwidth_out = bandwidth_out; | 246 | pr->bandwidth_out = bandwidth_out; |
257 | pr->tats_ctx = GNUNET_TRANSPORT_address_to_string(cfg, address, | 247 | pr->tats_ctx = GNUNET_TRANSPORT_address_to_string (cfg, address, |
258 | resolve_addresses_numeric, | 248 | resolve_addresses_numeric, |
259 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), | 249 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), |
260 | transport_addr_to_str_cb, pr); | 250 | transport_addr_to_str_cb, pr); |
261 | GNUNET_CONTAINER_DLL_insert (head, tail, pr); | 251 | GNUNET_CONTAINER_DLL_insert(head, tail, pr); |
262 | results++; | 252 | results++; |
263 | pending++; | 253 | pending++; |
264 | } | 254 | } |
@@ -270,15 +260,15 @@ ats_perf_cb (void *cls, | |||
270 | if (0 == pending) | 260 | if (0 == pending) |
271 | { | 261 | { |
272 | /* All messages received and no resolutions pending*/ | 262 | /* All messages received and no resolutions pending*/ |
273 | if (end_task != GNUNET_SCHEDULER_NO_TASK) | 263 | if (end_task != GNUNET_SCHEDULER_NO_TASK ) |
274 | GNUNET_SCHEDULER_cancel (end_task); | 264 | GNUNET_SCHEDULER_cancel (end_task); |
275 | end_task = GNUNET_SCHEDULER_add_now (end, NULL); | 265 | end_task = GNUNET_SCHEDULER_add_now (end, NULL ); |
276 | } | 266 | } |
277 | } | 267 | } |
278 | } | 268 | } |
279 | 269 | ||
280 | static unsigned int | 270 | static unsigned int |
281 | print_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg) | 271 | print_quotas(const struct GNUNET_CONFIGURATION_Handle *cfg) |
282 | { | 272 | { |
283 | char *network_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString; | 273 | char *network_str[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString; |
284 | char * entry_in = NULL; | 274 | char * entry_in = NULL; |
@@ -296,51 +286,56 @@ print_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
296 | GNUNET_asprintf (&entry_in, "%s_QUOTA_IN", network_str[c]); | 286 | GNUNET_asprintf (&entry_in, "%s_QUOTA_IN", network_str[c]); |
297 | 287 | ||
298 | /* quota out */ | 288 | /* quota out */ |
299 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, "a_out_str)) | 289 | if (GNUNET_OK |
290 | == GNUNET_CONFIGURATION_get_value_string (cfg, "ats", entry_out, | ||
291 | "a_out_str)) | ||
300 | { | 292 | { |
301 | if (0 == strcmp(quota_out_str, BIG_M_STRING) || | 293 | if (0 == strcmp (quota_out_str, BIG_M_STRING) |
302 | (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, "a_out))) | 294 | || (GNUNET_SYSERR |
295 | == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, "a_out))) | ||
303 | quota_out = UINT32_MAX; | 296 | quota_out = UINT32_MAX; |
304 | 297 | ||
305 | GNUNET_free (quota_out_str); | 298 | GNUNET_free(quota_out_str); |
306 | GNUNET_asprintf ("a_out_str, "%llu", quota_out); | 299 | GNUNET_asprintf ("a_out_str, "%llu", quota_out); |
307 | } | 300 | } |
308 | else | 301 | else |
309 | { | 302 | { |
310 | fprintf (stderr, "Outbound quota for network `%11s' not configured!\n", | 303 | fprintf (stderr, "Outbound quota for network `%11s' not configured!\n", |
311 | network_str[c]); | 304 | network_str[c]); |
312 | GNUNET_asprintf ("a_out_str, "-"); | 305 | GNUNET_asprintf ("a_out_str, "-"); |
313 | } | 306 | } |
314 | GNUNET_free (entry_out); | 307 | GNUNET_free(entry_out); |
315 | 308 | ||
316 | /* quota in */ | 309 | /* quota in */ |
317 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_in, "a_in_str)) | 310 | if (GNUNET_OK |
311 | == GNUNET_CONFIGURATION_get_value_string (cfg, "ats", entry_in, | ||
312 | "a_in_str)) | ||
318 | { | 313 | { |
319 | if (0 == strcmp(quota_in_str, BIG_M_STRING) || | 314 | if (0 == strcmp (quota_in_str, BIG_M_STRING) |
320 | (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, "a_in))) | 315 | || (GNUNET_SYSERR |
321 | quota_in = UINT32_MAX; | 316 | == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, "a_in))) |
322 | GNUNET_free (quota_in_str); | 317 | quota_in = UINT32_MAX; |
318 | GNUNET_free(quota_in_str); | ||
323 | GNUNET_asprintf ("a_in_str, "%llu", quota_in); | 319 | GNUNET_asprintf ("a_in_str, "%llu", quota_in); |
324 | } | 320 | } |
325 | else | 321 | else |
326 | { | 322 | { |
327 | fprintf (stderr, "Inbound quota for network `%11s' not configured!\n", | 323 | fprintf (stderr, "Inbound quota for network `%11s' not configured!\n", |
328 | network_str[c]); | 324 | network_str[c]); |
329 | GNUNET_asprintf ("a_in_str, "-"); | 325 | GNUNET_asprintf ("a_in_str, "-"); |
330 | } | 326 | } |
331 | GNUNET_free (entry_in); | 327 | GNUNET_free(entry_in); |
332 | 328 | ||
333 | fprintf (stderr, _("Quota for network `%11s' (in/out): %10s / %10s\n"), network_str[c], quota_in_str, quota_out_str ); | 329 | fprintf (stderr, _("Quota for network `%11s' (in/out): %10s / %10s\n"), |
334 | GNUNET_free (quota_out_str); | 330 | network_str[c], quota_in_str, quota_out_str); |
335 | GNUNET_free (quota_in_str); | 331 | GNUNET_free(quota_out_str); |
332 | GNUNET_free(quota_in_str); | ||
336 | } | 333 | } |
337 | return GNUNET_ATS_NetworkTypeCount; | 334 | return GNUNET_ATS_NetworkTypeCount; |
338 | } | 335 | } |
339 | 336 | ||
340 | |||
341 | static void | 337 | static void |
342 | testservice_ats (void *cls, | 338 | testservice_ats(void *cls, int result) |
343 | int result) | ||
344 | { | 339 | { |
345 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 340 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
346 | struct GNUNET_PeerIdentity pid; | 341 | struct GNUNET_PeerIdentity pid; |
@@ -357,9 +352,9 @@ testservice_ats (void *cls, | |||
357 | 352 | ||
358 | if (NULL != pid_str) | 353 | if (NULL != pid_str) |
359 | { | 354 | { |
360 | if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (pid_str, | 355 | if (GNUNET_OK |
361 | strlen (pid_str), | 356 | != GNUNET_CRYPTO_eddsa_public_key_from_string (pid_str, |
362 | &pid.public_key)) | 357 | strlen (pid_str), &pid.public_key)) |
363 | { | 358 | { |
364 | FPRINTF (stderr, _("Failed to parse peer identity `%s'\n"), pid_str); | 359 | FPRINTF (stderr, _("Failed to parse peer identity `%s'\n"), pid_str); |
365 | return; | 360 | return; |
@@ -369,102 +364,104 @@ testservice_ats (void *cls, | |||
369 | c = op_list_all + op_list_used + op_monitor + op_set_pref; | 364 | c = op_list_all + op_list_used + op_monitor + op_set_pref; |
370 | if ((1 < c)) | 365 | if ((1 < c)) |
371 | { | 366 | { |
372 | FPRINTF (stderr, _("Please select one operation : %s or %s or %s or %s or %s\n"), | 367 | FPRINTF (stderr, |
373 | "--used", "--all", "--monitor", "--preference", "--quotas"); | 368 | _("Please select one operation : %s or %s or %s or %s or %s\n"), |
374 | return; | 369 | "--used", "--all", "--monitor", "--preference", "--quotas"); |
370 | return; | ||
375 | } | 371 | } |
376 | if ((0 == c)) | 372 | if ((0 == c)) |
377 | op_list_used = GNUNET_YES; /* set default */ | 373 | op_list_used = GNUNET_YES; /* set default */ |
378 | if (op_print_quotas) | 374 | if (op_print_quotas) |
375 | { | ||
376 | ret = print_quotas (cfg); | ||
377 | return; | ||
378 | } | ||
379 | if (op_list_all) | ||
380 | { | ||
381 | ph = GNUNET_ATS_performance_init (cfg, NULL, NULL ); | ||
382 | if (NULL == ph) | ||
379 | { | 383 | { |
380 | ret = print_quotas (cfg); | 384 | fprintf (stderr, _("Cannot connect to ATS service, exiting...\n") ); |
381 | return; | 385 | return; |
382 | } | 386 | } |
383 | if (op_list_all) | ||
384 | { | ||
385 | ph = GNUNET_ATS_performance_init (cfg, NULL, NULL); | ||
386 | if (NULL == ph) | ||
387 | { | ||
388 | fprintf (stderr, _("Cannot connect to ATS service, exiting...\n")); | ||
389 | return; | ||
390 | } | ||
391 | 387 | ||
392 | alh = GNUNET_ATS_performance_list_addresses (ph, | 388 | alh = GNUNET_ATS_performance_list_addresses (ph, |
393 | (NULL == pid_str) ? NULL : &pid, | 389 | (NULL == pid_str) ? NULL : &pid, GNUNET_YES, ats_perf_cb, NULL ); |
394 | GNUNET_YES, ats_perf_cb, NULL); | 390 | if (NULL == alh) |
395 | if (NULL == alh) | ||
396 | { | ||
397 | fprintf (stderr, _("Cannot issue request to ATS service, exiting...\n")); | ||
398 | end_task = GNUNET_SCHEDULER_add_now (&end, NULL); | ||
399 | return; | ||
400 | } | ||
401 | end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &end, NULL); | ||
402 | } | ||
403 | else if (op_list_used) | ||
404 | { | 391 | { |
405 | ph = GNUNET_ATS_performance_init (cfg, NULL, NULL); | 392 | fprintf (stderr, _("Cannot issue request to ATS service, exiting...\n") ); |
406 | if (NULL == ph) | 393 | end_task = GNUNET_SCHEDULER_add_now (&end, NULL ); |
407 | fprintf (stderr, _("Cannot connect to ATS service, exiting...\n")); | 394 | return; |
408 | |||
409 | alh = GNUNET_ATS_performance_list_addresses (ph, | ||
410 | (NULL == pid_str) ? NULL : &pid, | ||
411 | GNUNET_NO, ats_perf_cb, NULL); | ||
412 | if (NULL == alh) | ||
413 | { | ||
414 | fprintf (stderr, _("Cannot issue request to ATS service, exiting...\n")); | ||
415 | end_task = GNUNET_SCHEDULER_add_now (&end, NULL); | ||
416 | return; | ||
417 | } | ||
418 | end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &end, NULL); | ||
419 | } | 395 | } |
420 | else if (op_monitor) | 396 | end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &end, |
397 | NULL ); | ||
398 | } | ||
399 | else if (op_list_used) | ||
400 | { | ||
401 | ph = GNUNET_ATS_performance_init (cfg, NULL, NULL ); | ||
402 | if (NULL == ph) | ||
403 | fprintf (stderr, _("Cannot connect to ATS service, exiting...\n") ); | ||
404 | |||
405 | alh = GNUNET_ATS_performance_list_addresses (ph, | ||
406 | (NULL == pid_str) ? NULL : &pid, GNUNET_NO, ats_perf_cb, NULL ); | ||
407 | if (NULL == alh) | ||
421 | { | 408 | { |
422 | ph = GNUNET_ATS_performance_init (cfg, &ats_perf_cb, NULL); | 409 | fprintf (stderr, _("Cannot issue request to ATS service, exiting...\n") ); |
423 | if (NULL == ph) | 410 | end_task = GNUNET_SCHEDULER_add_now (&end, NULL ); |
424 | fprintf (stderr, _("Cannot connect to ATS service, exiting...\n")); | 411 | return; |
425 | end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &end, NULL); | 412 | } |
413 | end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &end, | ||
414 | NULL ); | ||
415 | } | ||
416 | else if (op_monitor) | ||
417 | { | ||
418 | ph = GNUNET_ATS_performance_init (cfg, &ats_perf_cb, NULL ); | ||
419 | if (NULL == ph) | ||
420 | fprintf (stderr, _("Cannot connect to ATS service, exiting...\n") ); | ||
421 | end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &end, | ||
422 | NULL ); | ||
426 | 423 | ||
424 | } | ||
425 | else if (op_set_pref) | ||
426 | { | ||
427 | if (NULL == type_str) | ||
428 | { | ||
429 | fprintf (stderr, _("No preference type given!\n") ); | ||
430 | return; | ||
427 | } | 431 | } |
428 | else if (op_set_pref) | 432 | if (NULL == pid_str) |
429 | { | 433 | { |
430 | if (NULL == type_str) | 434 | fprintf (stderr, _("No peer given!\n") ); |
431 | { | 435 | return; |
432 | fprintf (stderr, _("No preference type given!\n")); | 436 | } |
433 | return; | ||
434 | } | ||
435 | if (NULL == pid_str) | ||
436 | { | ||
437 | fprintf (stderr, _("No peer given!\n")); | ||
438 | return; | ||
439 | } | ||
440 | |||
441 | |||
442 | 437 | ||
443 | for (c = 0; c<strlen(type_str); c++) | 438 | for (c = 0; c < strlen (type_str); c++) |
444 | { | 439 | { |
445 | if (isupper (type_str[c])) | 440 | if (isupper (type_str[c])) |
446 | type_str[c] = tolower (type_str[c]); | 441 | type_str[c] = tolower (type_str[c]); |
447 | } | 442 | } |
448 | 443 | ||
449 | if (0 == strcasecmp("latency", type_str)) | 444 | if (0 == strcasecmp ("latency", type_str)) |
450 | type = GNUNET_ATS_PREFERENCE_LATENCY; | 445 | type = GNUNET_ATS_PREFERENCE_LATENCY; |
451 | else if (0 == strcasecmp("bandwidth", type_str)) | 446 | else if (0 == strcasecmp ("bandwidth", type_str)) |
452 | type = GNUNET_ATS_PREFERENCE_BANDWIDTH; | 447 | type = GNUNET_ATS_PREFERENCE_BANDWIDTH; |
453 | else | 448 | else |
454 | { | 449 | { |
455 | FPRINTF (stderr, "%s", _("Valid type required\n")); | 450 | FPRINTF (stderr, "%s", _("Valid type required\n") ); |
456 | return; | 451 | return; |
457 | } | 452 | } |
458 | 453 | ||
459 | /* set */ | 454 | /* set */ |
460 | ph = GNUNET_ATS_performance_init (cfg, NULL, NULL); | 455 | ph = GNUNET_ATS_performance_init (cfg, NULL, NULL ); |
461 | if (NULL == ph) | 456 | if (NULL == ph) |
462 | fprintf (stderr, _("Cannot connect to ATS service, exiting...\n")); | 457 | fprintf (stderr, _("Cannot connect to ATS service, exiting...\n") ); |
463 | 458 | ||
464 | GNUNET_ATS_performance_change_preference (ph, &pid, type, (double) value, GNUNET_ATS_PREFERENCE_END); | 459 | GNUNET_ATS_performance_change_preference (ph, &pid, type, (double) value, |
460 | GNUNET_ATS_PREFERENCE_END); | ||
465 | 461 | ||
466 | end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &end, NULL); | 462 | end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &end, |
467 | } | 463 | NULL ); |
464 | } | ||
468 | ret = 1; | 465 | ret = 1; |
469 | } | 466 | } |
470 | 467 | ||
@@ -477,17 +474,14 @@ testservice_ats (void *cls, | |||
477 | * @param my_cfg configuration | 474 | * @param my_cfg configuration |
478 | */ | 475 | */ |
479 | static void | 476 | static void |
480 | run (void *cls, char *const *args, const char *cfgfile, | 477 | run(void *cls, char * const *args, const char *cfgfile, |
481 | const struct GNUNET_CONFIGURATION_Handle *my_cfg) | 478 | const struct GNUNET_CONFIGURATION_Handle *my_cfg) |
482 | { | 479 | { |
483 | cfg = (struct GNUNET_CONFIGURATION_Handle *) my_cfg; | 480 | cfg = (struct GNUNET_CONFIGURATION_Handle *) my_cfg; |
484 | GNUNET_CLIENT_service_test ("ats", cfg, | 481 | GNUNET_CLIENT_service_test ("ats", cfg, TIMEOUT, &testservice_ats, |
485 | TIMEOUT, | 482 | (void *) cfg); |
486 | &testservice_ats, | ||
487 | (void *) cfg); | ||
488 | } | 483 | } |
489 | 484 | ||
490 | |||
491 | /** | 485 | /** |
492 | * The main function. | 486 | * The main function. |
493 | * | 487 | * |
@@ -496,7 +490,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
496 | * @return 0 ok, 1 on error | 490 | * @return 0 ok, 1 on error |
497 | */ | 491 | */ |
498 | int | 492 | int |
499 | main (int argc, char *const *argv) | 493 | main(int argc, char * const *argv) |
500 | { | 494 | { |
501 | int res; | 495 | int res; |
502 | resolve_addresses_numeric = GNUNET_NO; | 496 | resolve_addresses_numeric = GNUNET_NO; |
@@ -508,49 +502,41 @@ main (int argc, char *const *argv) | |||
508 | receive_done = GNUNET_NO; | 502 | receive_done = GNUNET_NO; |
509 | type_str = NULL; | 503 | type_str = NULL; |
510 | 504 | ||
511 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 505 | static const struct GNUNET_GETOPT_CommandLineOption options[] = |
512 | {'u', "used", NULL, | 506 | { |
513 | gettext_noop ("get list of active addresses currently used"), | 507 | { 'u', "used", NULL, |
514 | 0, &GNUNET_GETOPT_set_one, &op_list_used}, | 508 | gettext_noop ("get list of active addresses currently used"), 0, |
515 | {'a', "all", NULL, | 509 | &GNUNET_GETOPT_set_one, &op_list_used }, |
516 | gettext_noop ("get list of all active addresses"), | 510 | { 'a', "all", NULL, gettext_noop ("get list of all active addresses"), 0, |
517 | 0, &GNUNET_GETOPT_set_one, &op_list_all}, | 511 | &GNUNET_GETOPT_set_one, &op_list_all }, |
518 | {'n', "numeric", NULL, | 512 | { 'n', "numeric", NULL, |
519 | gettext_noop ("do not resolve IP addresses to hostnames"), | 513 | gettext_noop ("do not resolve IP addresses to hostnames"), 0, |
520 | 0, &GNUNET_GETOPT_set_one, &resolve_addresses_numeric}, | 514 | &GNUNET_GETOPT_set_one, &resolve_addresses_numeric }, |
521 | {'m', "monitor", NULL, | 515 | { 'm', "monitor", NULL, gettext_noop ("monitor mode"), 0, |
522 | gettext_noop ("monitor mode"), | 516 | &GNUNET_GETOPT_set_one, &op_monitor }, |
523 | 0, &GNUNET_GETOPT_set_one, &op_monitor}, | 517 | { 'p', "preference", NULL, gettext_noop ("set preference for the given peer"), |
524 | {'p', "preference", NULL, | 518 | 0, &GNUNET_GETOPT_set_one, &op_set_pref }, |
525 | gettext_noop ("set preference for the given peer"), | 519 | { 'q', "quotas", NULL, gettext_noop ("print all configured quotas"), 0, |
526 | 0, &GNUNET_GETOPT_set_one, &op_set_pref}, | 520 | &GNUNET_GETOPT_set_one, &op_print_quotas }, |
527 | {'q', "quotas", NULL, | 521 | { 'i', "id", "TYPE", gettext_noop ("peer id"), 1, &GNUNET_GETOPT_set_string, |
528 | gettext_noop ("print all configured quotas"), | 522 | &pid_str }, |
529 | 0, &GNUNET_GETOPT_set_one, &op_print_quotas}, | 523 | { 't', "type", "TYPE", |
530 | {'i', "id", "TYPE", | 524 | gettext_noop ("preference type to set: latency | bandwidth"), 1, |
531 | gettext_noop ("peer id"), | 525 | &GNUNET_GETOPT_set_string, &type_str }, |
532 | 1, &GNUNET_GETOPT_set_string, &pid_str}, | 526 | { 'k', "value", "VALUE", gettext_noop ("preference value"), 1, |
533 | {'t', "type", "TYPE", | 527 | &GNUNET_GETOPT_set_uint, &value }, |
534 | gettext_noop ("preference type to set: latency | bandwidth"), | 528 | { 'V', "verbose", NULL, |
535 | 1, &GNUNET_GETOPT_set_string, &type_str}, | 529 | gettext_noop ("verbose output (include ATS address properties)"), 0, |
536 | {'k', "value", "VALUE", | 530 | &GNUNET_GETOPT_set_one, &verbose }, GNUNET_GETOPT_OPTION_END }; |
537 | gettext_noop ("preference value"), | ||
538 | 1, &GNUNET_GETOPT_set_uint, &value}, | ||
539 | {'V', "verbose", NULL, | ||
540 | gettext_noop ("verbose output (include ATS address properties)"), | ||
541 | 0, &GNUNET_GETOPT_set_one, &verbose}, | ||
542 | GNUNET_GETOPT_OPTION_END | ||
543 | }; | ||
544 | 531 | ||
545 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 532 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
546 | return 2; | 533 | return 2; |
547 | 534 | ||
548 | res = GNUNET_PROGRAM_run (argc, argv, "gnunet-ats", | 535 | res = GNUNET_PROGRAM_run (argc, argv, "gnunet-ats", |
549 | gettext_noop ("Print information about ATS state"), options, &run, | 536 | gettext_noop ("Print information about ATS state"), options, &run, NULL ); |
550 | NULL); | 537 | GNUNET_free_non_null(pid_str); |
551 | GNUNET_free_non_null (pid_str); | 538 | GNUNET_free_non_null(type_str); |
552 | GNUNET_free_non_null (type_str); | 539 | GNUNET_free((void * ) argv); |
553 | GNUNET_free ((void *) argv); | ||
554 | 540 | ||
555 | if (GNUNET_OK == res) | 541 | if (GNUNET_OK == res) |
556 | return ret; | 542 | return ret; |