diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2014-02-04 16:33:44 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2014-02-04 16:33:44 +0000 |
commit | 991d4eaa448df2e774e80e1a61bd308f95cd991e (patch) | |
tree | 8d0a99dd7607d186a0f52d2972530eb65fb63414 /src/ats-tool | |
parent | f9e731f8dc6350db2567165537fe2fee8c28fbad (diff) | |
download | gnunet-991d4eaa448df2e774e80e1a61bd308f95cd991e.tar.gz gnunet-991d4eaa448df2e774e80e1a61bd308f95cd991e.zip |
filter ats information in non-verbose mode
Diffstat (limited to 'src/ats-tool')
-rw-r--r-- | src/ats-tool/gnunet-ats.c | 87 |
1 files changed, 86 insertions, 1 deletions
diff --git a/src/ats-tool/gnunet-ats.c b/src/ats-tool/gnunet-ats.c index 05e76a43f..cf55b8438 100644 --- a/src/ats-tool/gnunet-ats.c +++ b/src/ats-tool/gnunet-ats.c | |||
@@ -87,6 +87,9 @@ static struct GNUNET_CONFIGURATION_Handle *cfg; | |||
87 | 87 | ||
88 | static GNUNET_SCHEDULER_TaskIdentifier end_task; | 88 | static GNUNET_SCHEDULER_TaskIdentifier end_task; |
89 | 89 | ||
90 | static struct GNUNET_CONTAINER_MultiPeerMap *addresses; | ||
91 | |||
92 | |||
90 | struct PendingResolutions | 93 | struct PendingResolutions |
91 | { | 94 | { |
92 | struct PendingResolutions *next; | 95 | struct PendingResolutions *next; |
@@ -102,10 +105,31 @@ struct PendingResolutions | |||
102 | struct GNUNET_TRANSPORT_AddressToStringContext * tats_ctx; | 105 | struct GNUNET_TRANSPORT_AddressToStringContext * tats_ctx; |
103 | }; | 106 | }; |
104 | 107 | ||
108 | struct ATSAddress | ||
109 | { | ||
110 | struct GNUNET_HELLO_Address *address; | ||
111 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out; | ||
112 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in; | ||
113 | }; | ||
114 | |||
115 | |||
116 | |||
105 | static struct PendingResolutions *head; | 117 | static struct PendingResolutions *head; |
106 | 118 | ||
107 | static struct PendingResolutions *tail; | 119 | static struct PendingResolutions *tail; |
108 | 120 | ||
121 | static int | ||
122 | free_addr_it (void *cls, | ||
123 | const struct GNUNET_PeerIdentity *key, | ||
124 | void *value) | ||
125 | { | ||
126 | struct ATSAddress *a = value; | ||
127 | GNUNET_CONTAINER_multipeermap_remove (addresses, key, a); | ||
128 | GNUNET_HELLO_address_free (a->address); | ||
129 | GNUNET_free (a); | ||
130 | return GNUNET_OK; | ||
131 | } | ||
132 | |||
109 | static void | 133 | static void |
110 | end(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 134 | end(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
111 | { | 135 | { |
@@ -136,6 +160,10 @@ end(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
136 | GNUNET_free(pr); | 160 | GNUNET_free(pr); |
137 | pending++; | 161 | pending++; |
138 | } | 162 | } |
163 | |||
164 | GNUNET_CONTAINER_multipeermap_iterate(addresses, &free_addr_it, NULL); | ||
165 | GNUNET_CONTAINER_multipeermap_destroy(addresses); | ||
166 | |||
139 | if (0 < pending) | 167 | if (0 < pending) |
140 | fprintf (stderr, _("%u address resolutions had a timeout\n"), pending); | 168 | fprintf (stderr, _("%u address resolutions had a timeout\n"), pending); |
141 | if (op_list_used || op_list_all) | 169 | if (op_list_used || op_list_all) |
@@ -169,7 +197,8 @@ transport_addr_to_str_cb(void *cls, const char *address) | |||
169 | 197 | ||
170 | if (ats_type > GNUNET_ATS_PropertyCount) | 198 | if (ats_type > GNUNET_ATS_PropertyCount) |
171 | { | 199 | { |
172 | GNUNET_break(0); | 200 | fprintf (stderr, "Invalid ATS property type %u %u for address %s\n", ats_type, pr->ats[c].type, |
201 | address); | ||
173 | continue; | 202 | continue; |
174 | } | 203 | } |
175 | 204 | ||
@@ -224,6 +253,30 @@ transport_addr_to_str_cb(void *cls, const char *address) | |||
224 | } | 253 | } |
225 | } | 254 | } |
226 | 255 | ||
256 | |||
257 | struct AddressFindCtx | ||
258 | { | ||
259 | const struct GNUNET_HELLO_Address *src; | ||
260 | struct ATSAddress *res; | ||
261 | }; | ||
262 | |||
263 | static int | ||
264 | find_address_it (void *cls, | ||
265 | const struct GNUNET_PeerIdentity *key, | ||
266 | void *value) | ||
267 | { | ||
268 | struct AddressFindCtx *actx = cls; | ||
269 | struct ATSAddress *exist = value; | ||
270 | |||
271 | if (0 == GNUNET_HELLO_address_cmp (actx->src, exist->address)) | ||
272 | { | ||
273 | actx->res = exist; | ||
274 | return GNUNET_NO; | ||
275 | } | ||
276 | |||
277 | return GNUNET_YES; | ||
278 | } | ||
279 | |||
227 | static void | 280 | static void |
228 | ats_perf_cb(void *cls, const struct GNUNET_HELLO_Address *address, int active, | 281 | ats_perf_cb(void *cls, const struct GNUNET_HELLO_Address *address, int active, |
229 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 282 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
@@ -232,6 +285,36 @@ ats_perf_cb(void *cls, const struct GNUNET_HELLO_Address *address, int active, | |||
232 | { | 285 | { |
233 | struct PendingResolutions * pr; | 286 | struct PendingResolutions * pr; |
234 | 287 | ||
288 | if ((GNUNET_YES == op_monitor) && (GNUNET_NO == verbose)) | ||
289 | { | ||
290 | struct AddressFindCtx actx; | ||
291 | |||
292 | actx.src = address; | ||
293 | actx.res = NULL; | ||
294 | |||
295 | GNUNET_CONTAINER_multipeermap_iterate (addresses, find_address_it, &actx); | ||
296 | if ((actx.res != NULL)) | ||
297 | { | ||
298 | if ((bandwidth_in.value__ == actx.res->bandwidth_in.value__) && | ||
299 | (bandwidth_out.value__ == actx.res->bandwidth_out.value__) ) | ||
300 | { | ||
301 | return; /* Nothing to do here */ | ||
302 | } | ||
303 | else | ||
304 | { | ||
305 | actx.res->bandwidth_in = bandwidth_in; | ||
306 | actx.res->bandwidth_out = bandwidth_out; | ||
307 | } | ||
308 | } | ||
309 | |||
310 | struct ATSAddress *a = GNUNET_new (struct ATSAddress); | ||
311 | a->address = GNUNET_HELLO_address_copy(address); | ||
312 | a->bandwidth_in = bandwidth_in; | ||
313 | a->bandwidth_out = bandwidth_out; | ||
314 | GNUNET_CONTAINER_multipeermap_put (addresses, &address->peer, a, | ||
315 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
316 | } | ||
317 | |||
235 | if (NULL != address) | 318 | if (NULL != address) |
236 | { | 319 | { |
237 | pr = GNUNET_malloc (sizeof (struct PendingResolutions) + | 320 | pr = GNUNET_malloc (sizeof (struct PendingResolutions) + |
@@ -342,6 +425,8 @@ testservice_ats(void *cls, int result) | |||
342 | unsigned int c; | 425 | unsigned int c; |
343 | unsigned int type; | 426 | unsigned int type; |
344 | 427 | ||
428 | addresses = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_YES); | ||
429 | |||
345 | if (GNUNET_YES != result) | 430 | if (GNUNET_YES != result) |
346 | { | 431 | { |
347 | FPRINTF (stderr, _("Service `%s' is not running\n"), "ats"); | 432 | FPRINTF (stderr, _("Service `%s' is not running\n"), "ats"); |