diff options
-rw-r--r-- | src/ats-tool/gnunet-ats.c | 187 | ||||
-rw-r--r-- | src/ats/ats.h | 4 | ||||
-rw-r--r-- | src/ats/ats_api_performance.c | 111 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_performance.c | 125 |
4 files changed, 281 insertions, 146 deletions
diff --git a/src/ats-tool/gnunet-ats.c b/src/ats-tool/gnunet-ats.c index 27dfd4dca..2219363d5 100644 --- a/src/ats-tool/gnunet-ats.c +++ b/src/ats-tool/gnunet-ats.c | |||
@@ -36,6 +36,8 @@ | |||
36 | static int ret; | 36 | static int ret; |
37 | static int results; | 37 | static int results; |
38 | static int resolve_addresses_numeric; | 38 | static int resolve_addresses_numeric; |
39 | static int receive_done; | ||
40 | |||
39 | /** | 41 | /** |
40 | * For which peer should we change preference values? | 42 | * For which peer should we change preference values? |
41 | */ | 43 | */ |
@@ -43,6 +45,7 @@ static char *pid_str; | |||
43 | 45 | ||
44 | static char *type_str; | 46 | static char *type_str; |
45 | static unsigned int value; | 47 | static unsigned int value; |
48 | static int pending; | ||
46 | 49 | ||
47 | /** | 50 | /** |
48 | * Print verbose ATS information | 51 | * Print verbose ATS information |
@@ -97,6 +100,44 @@ struct PendingResolutions | |||
97 | struct PendingResolutions *head; | 100 | struct PendingResolutions *head; |
98 | struct PendingResolutions *tail; | 101 | struct PendingResolutions *tail; |
99 | 102 | ||
103 | void end (void *cls, | ||
104 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
105 | { | ||
106 | struct PendingResolutions * pr; | ||
107 | struct PendingResolutions * next; | ||
108 | unsigned int pending; | ||
109 | |||
110 | if (NULL != alh) | ||
111 | { | ||
112 | GNUNET_ATS_performance_list_addresses_cancel (alh); | ||
113 | alh = NULL; | ||
114 | } | ||
115 | |||
116 | if (NULL != ph) | ||
117 | { | ||
118 | GNUNET_ATS_performance_done (ph); | ||
119 | ph = NULL; | ||
120 | } | ||
121 | |||
122 | pending = 0; | ||
123 | next = head; | ||
124 | while (NULL != (pr = next)) | ||
125 | { | ||
126 | next = pr->next; | ||
127 | GNUNET_CONTAINER_DLL_remove (head, tail, pr); | ||
128 | GNUNET_TRANSPORT_address_to_string_cancel (pr->tats_ctx); | ||
129 | GNUNET_free (pr->address); | ||
130 | GNUNET_free (pr); | ||
131 | pending ++; | ||
132 | } | ||
133 | if (0 < pending) | ||
134 | fprintf (stderr, _("%u address resolutions had a timeout\n"), pending); | ||
135 | |||
136 | fprintf (stderr, _("ATS returned results for %u addresses\n"), results); | ||
137 | ret = 0; | ||
138 | } | ||
139 | |||
140 | |||
100 | void transport_addr_to_str_cb (void *cls, const char *address) | 141 | void transport_addr_to_str_cb (void *cls, const char *address) |
101 | { | 142 | { |
102 | struct PendingResolutions * pr = cls; | 143 | struct PendingResolutions * pr = cls; |
@@ -108,58 +149,65 @@ void transport_addr_to_str_cb (void *cls, const char *address) | |||
108 | unsigned int c; | 149 | unsigned int c; |
109 | uint32_t ats_type; | 150 | uint32_t ats_type; |
110 | uint32_t ats_value; | 151 | uint32_t ats_value; |
111 | |||
112 | if (NULL != address) | 152 | if (NULL != address) |
113 | { | 153 | { |
114 | ats_str = GNUNET_strdup(""); | 154 | ats_str = GNUNET_strdup(""); |
115 | if (verbose) | 155 | if (verbose) |
116 | { | 156 | { |
117 | for (c = 0; c < pr->ats_count; c++) | 157 | for (c = 0; c < pr->ats_count; c++) |
118 | { | 158 | { |
119 | ats_tmp = ats_str; | 159 | ats_tmp = ats_str; |
120 | 160 | ||
121 | ats_type = ntohl(pr->ats[c].type); | 161 | ats_type = ntohl(pr->ats[c].type); |
122 | ats_value = ntohl(pr->ats[c].value); | 162 | ats_value = ntohl(pr->ats[c].value); |
123 | 163 | ||
124 | if (ats_type > GNUNET_ATS_PropertyCount) | 164 | if (ats_type > GNUNET_ATS_PropertyCount) |
125 | { | 165 | { |
126 | GNUNET_break (0); | 166 | GNUNET_break (0); |
127 | continue; | 167 | continue; |
128 | } | 168 | } |
129 | 169 | ||
130 | switch (ats_type) { | 170 | switch (ats_type) { |
131 | case GNUNET_ATS_NETWORK_TYPE: | 171 | case GNUNET_ATS_NETWORK_TYPE: |
132 | if (ats_value > GNUNET_ATS_NetworkTypeCount) | 172 | if (ats_value > GNUNET_ATS_NetworkTypeCount) |
133 | { | 173 | { |
134 | GNUNET_break (0); | 174 | GNUNET_break (0); |
135 | continue; | 175 | continue; |
136 | } | 176 | } |
137 | GNUNET_asprintf (&ats_prop_value, "%s", ats_net_arr[ats_value]); | 177 | GNUNET_asprintf (&ats_prop_value, "%s", ats_net_arr[ats_value]); |
138 | break; | 178 | break; |
139 | default: | 179 | default: |
140 | GNUNET_asprintf (&ats_prop_value, "%u", ats_value); | 180 | GNUNET_asprintf (&ats_prop_value, "%u", ats_value); |
141 | break; | 181 | break; |
142 | } | ||
143 | |||
144 | GNUNET_asprintf (&ats_str, "%s%s=%s, ", ats_tmp, ats_prop_arr[ats_type] , ats_prop_value); | ||
145 | GNUNET_free (ats_tmp); | ||
146 | GNUNET_free (ats_prop_value); | ||
147 | } | 182 | } |
183 | |||
184 | GNUNET_asprintf (&ats_str, "%s%s=%s, ", ats_tmp, ats_prop_arr[ats_type] , ats_prop_value); | ||
185 | GNUNET_free (ats_tmp); | ||
186 | GNUNET_free (ats_prop_value); | ||
148 | } | 187 | } |
188 | } | ||
149 | 189 | ||
150 | fprintf (stderr, _("Peer `%s' plugin `%s', address `%s', bw out: %u Bytes/s, bw in %u Bytes/s, %s\n"), | 190 | fprintf (stderr, _("Peer `%s' plugin `%s', address `%s', bw out: %u Bytes/s, bw in %u Bytes/s, %s\n"), |
151 | GNUNET_i2s (&pr->address->peer), pr->address->transport_name, address, | 191 | GNUNET_i2s (&pr->address->peer), pr->address->transport_name, address, |
152 | ntohl (pr->bandwidth_out.value__), ntohl (pr->bandwidth_in.value__),ats_str); | 192 | ntohl (pr->bandwidth_out.value__), ntohl (pr->bandwidth_in.value__),ats_str); |
153 | GNUNET_free (ats_str); | 193 | GNUNET_free (ats_str); |
154 | } | 194 | } |
155 | else if (NULL != pr) | 195 | else |
156 | { | 196 | { |
157 | /* We're done */ | 197 | /* We're done */ |
158 | GNUNET_CONTAINER_DLL_remove (head, tail, pr); | 198 | GNUNET_CONTAINER_DLL_remove (head, tail, pr); |
159 | GNUNET_free (pr->address); | 199 | GNUNET_free (pr->address); |
160 | GNUNET_free (pr); | 200 | GNUNET_free (pr); |
161 | } | 201 | pending--; |
162 | 202 | ||
203 | if ((GNUNET_YES == receive_done) && (0 == pending)) | ||
204 | { | ||
205 | /* All messages received and no resolutions pending*/ | ||
206 | if (end_task != GNUNET_SCHEDULER_NO_TASK) | ||
207 | GNUNET_SCHEDULER_cancel (end_task); | ||
208 | end_task = GNUNET_SCHEDULER_add_now (end, NULL); | ||
209 | } | ||
210 | } | ||
163 | } | 211 | } |
164 | 212 | ||
165 | void ats_perf_cb (void *cls, | 213 | void ats_perf_cb (void *cls, |
@@ -195,44 +243,23 @@ void ats_perf_cb (void *cls, | |||
195 | resolve_addresses_numeric, GNUNET_TIME_UNIT_FOREVER_REL, transport_addr_to_str_cb, pr); | 243 | resolve_addresses_numeric, GNUNET_TIME_UNIT_FOREVER_REL, transport_addr_to_str_cb, pr); |
196 | GNUNET_CONTAINER_DLL_insert (head, tail, pr); | 244 | GNUNET_CONTAINER_DLL_insert (head, tail, pr); |
197 | results++; | 245 | results++; |
246 | pending++; | ||
198 | } | 247 | } |
199 | } | 248 | else |
200 | |||
201 | |||
202 | void end (void *cls, | ||
203 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
204 | { | ||
205 | struct PendingResolutions * pr; | ||
206 | struct PendingResolutions * next; | ||
207 | unsigned int pending; | ||
208 | |||
209 | if (NULL != alh) | ||
210 | { | ||
211 | GNUNET_ATS_performance_list_addresses_cancel (alh); | ||
212 | alh = NULL; | ||
213 | } | ||
214 | |||
215 | GNUNET_ATS_performance_done (ph); | ||
216 | ph = NULL; | ||
217 | |||
218 | pending = 0; | ||
219 | next = head; | ||
220 | while (NULL != (pr = next)) | ||
221 | { | 249 | { |
222 | next = pr->next; | 250 | /* All messages received */ |
223 | GNUNET_CONTAINER_DLL_remove (head, tail, pr); | 251 | receive_done = GNUNET_YES; |
224 | GNUNET_TRANSPORT_address_to_string_cancel (pr->tats_ctx); | 252 | if (0 == pending) |
225 | GNUNET_free (pr->address); | 253 | { |
226 | GNUNET_free (pr); | 254 | /* All messages received and no resolutions pending*/ |
227 | pending ++; | 255 | if (end_task != GNUNET_SCHEDULER_NO_TASK) |
256 | GNUNET_SCHEDULER_cancel (end_task); | ||
257 | end_task = GNUNET_SCHEDULER_add_now (end, NULL); | ||
258 | } | ||
228 | } | 259 | } |
229 | if (0 < pending) | ||
230 | fprintf (stderr, _("%u address resolutions had a timeout\n"), pending); | ||
231 | |||
232 | fprintf (stderr, _("ATS returned results for %u addresses\n"), results); | ||
233 | ret = 0; | ||
234 | } | 260 | } |
235 | 261 | ||
262 | |||
236 | void testservice_ats (void *cls, | 263 | void testservice_ats (void *cls, |
237 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 264 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
238 | { | 265 | { |
@@ -292,9 +319,7 @@ void testservice_ats (void *cls, | |||
292 | end_task = GNUNET_SCHEDULER_add_now (&end, NULL); | 319 | end_task = GNUNET_SCHEDULER_add_now (&end, NULL); |
293 | return; | 320 | return; |
294 | } | 321 | } |
295 | |||
296 | end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &end, NULL); | 322 | end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &end, NULL); |
297 | |||
298 | } | 323 | } |
299 | else if (op_list_used) | 324 | else if (op_list_used) |
300 | { | 325 | { |
@@ -311,8 +336,6 @@ void testservice_ats (void *cls, | |||
311 | end_task = GNUNET_SCHEDULER_add_now (&end, NULL); | 336 | end_task = GNUNET_SCHEDULER_add_now (&end, NULL); |
312 | return; | 337 | return; |
313 | } | 338 | } |
314 | |||
315 | |||
316 | end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &end, NULL); | 339 | end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &end, NULL); |
317 | } | 340 | } |
318 | else if (op_monitor) | 341 | else if (op_monitor) |
@@ -388,6 +411,8 @@ main (int argc, char *const *argv) | |||
388 | op_monitor = GNUNET_NO; | 411 | op_monitor = GNUNET_NO; |
389 | op_list_all = GNUNET_NO; | 412 | op_list_all = GNUNET_NO; |
390 | op_list_used = GNUNET_NO; | 413 | op_list_used = GNUNET_NO; |
414 | pending = 0; | ||
415 | receive_done = GNUNET_NO; | ||
391 | 416 | ||
392 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 417 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
393 | {'u', "used", NULL, | 418 | {'u', "used", NULL, |
diff --git a/src/ats/ats.h b/src/ats/ats.h index 009a1609d..70b88263d 100644 --- a/src/ats/ats.h +++ b/src/ats/ats.h | |||
@@ -172,6 +172,8 @@ struct PeerInformationMessage | |||
172 | 172 | ||
173 | uint32_t address_active GNUNET_PACKED; | 173 | uint32_t address_active GNUNET_PACKED; |
174 | 174 | ||
175 | uint32_t id GNUNET_PACKED; | ||
176 | |||
175 | struct GNUNET_PeerIdentity peer; | 177 | struct GNUNET_PeerIdentity peer; |
176 | 178 | ||
177 | uint16_t address_length GNUNET_PACKED; | 179 | uint16_t address_length GNUNET_PACKED; |
@@ -194,6 +196,8 @@ struct AddressListRequestMessage | |||
194 | { | 196 | { |
195 | struct GNUNET_MessageHeader header; | 197 | struct GNUNET_MessageHeader header; |
196 | 198 | ||
199 | uint32_t id GNUNET_PACKED; | ||
200 | |||
197 | int32_t all GNUNET_PACKED; | 201 | int32_t all GNUNET_PACKED; |
198 | 202 | ||
199 | struct GNUNET_PeerIdentity peer; | 203 | struct GNUNET_PeerIdentity peer; |
diff --git a/src/ats/ats_api_performance.c b/src/ats/ats_api_performance.c index c4254cf90..855e983b5 100644 --- a/src/ats/ats_api_performance.c +++ b/src/ats/ats_api_performance.c | |||
@@ -150,6 +150,11 @@ struct GNUNET_ATS_AddressListHandle | |||
150 | * Return all or used address only | 150 | * Return all or used address only |
151 | */ | 151 | */ |
152 | int all_addresses; | 152 | int all_addresses; |
153 | |||
154 | /** | ||
155 | * Request multiplexing | ||
156 | */ | ||
157 | uint32_t id; | ||
153 | }; | 158 | }; |
154 | 159 | ||
155 | /** | 160 | /** |
@@ -218,6 +223,10 @@ struct GNUNET_ATS_PerformanceHandle | |||
218 | */ | 223 | */ |
219 | GNUNET_SCHEDULER_TaskIdentifier task; | 224 | GNUNET_SCHEDULER_TaskIdentifier task; |
220 | 225 | ||
226 | /** | ||
227 | * Request multiplexing | ||
228 | */ | ||
229 | uint32_t id; | ||
221 | }; | 230 | }; |
222 | 231 | ||
223 | 232 | ||
@@ -338,6 +347,7 @@ process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
338 | GNUNET_break (0); | 347 | GNUNET_break (0); |
339 | return GNUNET_SYSERR; | 348 | return GNUNET_SYSERR; |
340 | } | 349 | } |
350 | |||
341 | pi = (const struct PeerInformationMessage *) msg; | 351 | pi = (const struct PeerInformationMessage *) msg; |
342 | ats_count = ntohl (pi->ats_count); | 352 | ats_count = ntohl (pi->ats_count); |
343 | plugin_address_length = ntohs (pi->address_length); | 353 | plugin_address_length = ntohs (pi->address_length); |
@@ -359,6 +369,7 @@ process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
359 | { | 369 | { |
360 | return GNUNET_OK; | 370 | return GNUNET_OK; |
361 | } | 371 | } |
372 | |||
362 | address.peer = pi->peer; | 373 | address.peer = pi->peer; |
363 | address.address = plugin_address; | 374 | address.address = plugin_address; |
364 | address.address_length = plugin_address_length; | 375 | address.address_length = plugin_address_length; |
@@ -430,45 +441,89 @@ static int | |||
430 | process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph, | 441 | process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph, |
431 | const struct GNUNET_MessageHeader *msg) | 442 | const struct GNUNET_MessageHeader *msg) |
432 | { | 443 | { |
433 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "TO BE IMPLEMENTED\n"); | 444 | const struct PeerInformationMessage *pi; |
434 | # if 0 | 445 | struct GNUNET_ATS_AddressListHandle *alh; |
435 | TBD! | 446 | struct GNUNET_ATS_AddressListHandle *next; |
436 | const struct ReservationResultMessage *rr; | 447 | const struct GNUNET_ATS_Information *atsi; |
437 | struct GNUNET_ATS_ReservationContext *rc; | 448 | const char *plugin_address; |
438 | int32_t amount; | 449 | const char *plugin_name; |
450 | struct GNUNET_HELLO_Address address; | ||
451 | struct GNUNET_PeerIdentity allzeros; | ||
452 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_zero; | ||
453 | uint16_t plugin_address_length; | ||
454 | uint16_t plugin_name_length; | ||
455 | uint32_t ats_count; | ||
456 | uint32_t active; | ||
457 | uint32_t id; | ||
439 | 458 | ||
440 | if (ntohs (msg->size) < sizeof (struct ReservationResultMessage)) | 459 | if (ntohs (msg->size) < sizeof (struct PeerInformationMessage)) |
441 | { | 460 | { |
442 | GNUNET_break (0); | 461 | GNUNET_break (0); |
443 | return GNUNET_SYSERR; | 462 | return GNUNET_SYSERR; |
444 | } | 463 | } |
445 | rr = (const struct ReservationResultMessage *) msg; | 464 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
446 | amount = ntohl (rr->amount); | 465 | _("Received %s message\n"), "ATS_ADDRESSLIST_RESPONSE"); |
447 | rc = ph->reservation_head; | 466 | |
448 | if (0 != memcmp (&rr->peer, &rc->peer, sizeof (struct GNUNET_PeerIdentity))) | 467 | pi = (const struct PeerInformationMessage *) msg; |
468 | id = ntohl (pi->id); | ||
469 | ats_count = ntohl (pi->ats_count); | ||
470 | active = ntohl (pi->address_active); | ||
471 | plugin_address_length = ntohs (pi->address_length); | ||
472 | plugin_name_length = ntohs (pi->plugin_name_length); | ||
473 | atsi = (const struct GNUNET_ATS_Information *) &pi[1]; | ||
474 | plugin_address = (const char *) &atsi[ats_count]; | ||
475 | plugin_name = &plugin_address[plugin_address_length]; | ||
476 | if ((plugin_address_length + plugin_name_length + | ||
477 | ats_count * sizeof (struct GNUNET_ATS_Information) + | ||
478 | sizeof (struct PeerInformationMessage) != ntohs (msg->size)) || | ||
479 | (ats_count > | ||
480 | GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) | ||
481 | || (plugin_name[plugin_name_length - 1] != '\0')) | ||
449 | { | 482 | { |
450 | GNUNET_break (0); | 483 | GNUNET_break (0); |
451 | return GNUNET_SYSERR; | 484 | return GNUNET_SYSERR; |
452 | } | 485 | } |
453 | GNUNET_CONTAINER_DLL_remove (ph->reservation_head, ph->reservation_tail, rc); | 486 | |
454 | if ((amount == 0) || (rc->rcb != NULL)) | 487 | next = ph->addresslist_head; |
488 | while (NULL != (alh = next)) | ||
455 | { | 489 | { |
456 | /* tell client if not cancelled */ | 490 | next = alh->next; |
457 | if (rc->rcb != NULL) | 491 | if (alh->id == id) |
458 | rc->rcb (rc->rcb_cls, &rr->peer, amount, | 492 | break; |
459 | GNUNET_TIME_relative_ntoh (rr->res_delay)); | ||
460 | GNUNET_free (rc); | ||
461 | return GNUNET_OK; | ||
462 | } | 493 | } |
463 | /* amount non-zero, but client cancelled, consider undo! */ | 494 | if (NULL == alh) |
464 | if (GNUNET_YES != rc->undo) | ||
465 | { | 495 | { |
466 | GNUNET_free (rc); | 496 | GNUNET_break (0); |
467 | return GNUNET_OK; /* do not try to undo failed undos or negative amounts */ | 497 | return GNUNET_SYSERR; |
498 | } | ||
499 | |||
500 | memset (&allzeros, '\0', sizeof (allzeros)); | ||
501 | if ((0 == memcmp (&allzeros, &pi->peer, sizeof (allzeros))) && | ||
502 | (0 == plugin_name_length) && | ||
503 | (0 == plugin_address_length) && | ||
504 | (0 == ats_count)) | ||
505 | { | ||
506 | /* Done */ | ||
507 | bandwidth_zero.value__ = htonl (0); | ||
508 | alh->cb (ph->infocb_cls, | ||
509 | NULL, | ||
510 | bandwidth_zero, bandwidth_zero, | ||
511 | NULL, 0); | ||
512 | return GNUNET_OK; | ||
513 | } | ||
514 | |||
515 | address.peer = pi->peer; | ||
516 | address.address = plugin_address; | ||
517 | address.address_length = plugin_address_length; | ||
518 | address.transport_name = plugin_name; | ||
519 | |||
520 | if ((GNUNET_YES == alh->all_peers) || (GNUNET_YES == active)) | ||
521 | { | ||
522 | alh->cb (ph->infocb_cls, | ||
523 | &address, | ||
524 | pi->bandwidth_out, pi->bandwidth_in, | ||
525 | atsi, ats_count); | ||
468 | } | 526 | } |
469 | GNUNET_free (rc); | ||
470 | (void) GNUNET_ATS_reserve_bandwidth (ph, &rr->peer, -amount, NULL, NULL); | ||
471 | #endif | ||
472 | return GNUNET_OK; | 527 | return GNUNET_OK; |
473 | } | 528 | } |
474 | 529 | ||
@@ -577,6 +632,7 @@ GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
577 | ph->cfg = cfg; | 632 | ph->cfg = cfg; |
578 | ph->infocb = infocb; | 633 | ph->infocb = infocb; |
579 | ph->infocb_cls = infocb_cls; | 634 | ph->infocb_cls = infocb_cls; |
635 | ph->id = 0; | ||
580 | reconnect (ph); | 636 | reconnect (ph); |
581 | return ph; | 637 | return ph; |
582 | } | 638 | } |
@@ -712,6 +768,8 @@ GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *hand | |||
712 | GNUNET_assert (NULL != handle); | 768 | GNUNET_assert (NULL != handle); |
713 | 769 | ||
714 | alh = GNUNET_malloc (sizeof (struct GNUNET_ATS_AddressListHandle)); | 770 | alh = GNUNET_malloc (sizeof (struct GNUNET_ATS_AddressListHandle)); |
771 | alh->id = handle->id; | ||
772 | handle->id ++; | ||
715 | alh->cb = infocb; | 773 | alh->cb = infocb; |
716 | alh->cb_cls = infocb_cls; | 774 | alh->cb_cls = infocb_cls; |
717 | alh->ph = handle; | 775 | alh->ph = handle; |
@@ -733,6 +791,7 @@ GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *hand | |||
733 | m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_REQUEST); | 791 | m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_REQUEST); |
734 | m->header.size = htons (sizeof (struct AddressListRequestMessage)); | 792 | m->header.size = htons (sizeof (struct AddressListRequestMessage)); |
735 | m->all = htonl (all); | 793 | m->all = htonl (all); |
794 | m->id = htonl (alh->id); | ||
736 | if (NULL != peer) | 795 | if (NULL != peer) |
737 | m->peer = *peer; | 796 | m->peer = *peer; |
738 | else | 797 | else |
diff --git a/src/ats/gnunet-service-ats_performance.c b/src/ats/gnunet-service-ats_performance.c index 124654b25..446024b32 100644 --- a/src/ats/gnunet-service-ats_performance.c +++ b/src/ats/gnunet-service-ats_performance.c | |||
@@ -72,6 +72,8 @@ struct AddressIteration | |||
72 | 72 | ||
73 | int all; | 73 | int all; |
74 | 74 | ||
75 | uint32_t id; | ||
76 | |||
75 | unsigned int msg_type; | 77 | unsigned int msg_type; |
76 | }; | 78 | }; |
77 | 79 | ||
@@ -311,7 +313,62 @@ GAS_performance_add_client (struct GNUNET_SERVER_Client *client, | |||
311 | GAS_addresses_iterate_peers (&peer_it, pc); | 313 | GAS_addresses_iterate_peers (&peer_it, pc); |
312 | } | 314 | } |
313 | 315 | ||
316 | static void transmit_req_addr (struct AddressIteration *ai, | ||
317 | const struct GNUNET_PeerIdentity *id, | ||
318 | const char *plugin_name, | ||
319 | const void *plugin_addr, size_t plugin_addr_len, | ||
320 | const int active, | ||
321 | const struct GNUNET_ATS_Information *atsi, | ||
322 | uint32_t atsi_count, | ||
323 | struct GNUNET_BANDWIDTH_Value32NBO | ||
324 | bandwidth_out, | ||
325 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | ||
326 | |||
327 | { | ||
314 | 328 | ||
329 | struct GNUNET_ATS_Information *atsp; | ||
330 | struct PeerInformationMessage *msg; | ||
331 | char *addrp; | ||
332 | size_t plugin_name_length; | ||
333 | size_t msize; | ||
334 | |||
335 | if (NULL != plugin_name) | ||
336 | plugin_name_length = strlen (plugin_name) + 1; | ||
337 | else | ||
338 | plugin_name_length = 0; | ||
339 | msize = sizeof (struct PeerInformationMessage) + | ||
340 | atsi_count * sizeof (struct GNUNET_ATS_Information) + | ||
341 | plugin_addr_len + plugin_name_length; | ||
342 | char buf[msize] GNUNET_ALIGN; | ||
343 | |||
344 | GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE); | ||
345 | GNUNET_assert (atsi_count < | ||
346 | GNUNET_SERVER_MAX_MESSAGE_SIZE / | ||
347 | sizeof (struct GNUNET_ATS_Information)); | ||
348 | msg = (struct PeerInformationMessage *) buf; | ||
349 | msg->header.size = htons (msize); | ||
350 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE); | ||
351 | msg->ats_count = htonl (atsi_count); | ||
352 | msg->id = htonl (ai->id); | ||
353 | if (NULL != id) | ||
354 | msg->peer = *id; | ||
355 | else | ||
356 | memset (&msg->peer, '\0', sizeof (struct GNUNET_PeerIdentity)); | ||
357 | msg->address_length = htons (plugin_addr_len); | ||
358 | msg->address_active = ntohl (active); | ||
359 | msg->plugin_name_length = htons (plugin_name_length); | ||
360 | msg->bandwidth_out = bandwidth_out; | ||
361 | msg->bandwidth_in = bandwidth_in; | ||
362 | atsp = (struct GNUNET_ATS_Information *) &msg[1]; | ||
363 | memcpy (atsp, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count); | ||
364 | addrp = (char *) &atsp[atsi_count]; | ||
365 | if (NULL != plugin_addr) | ||
366 | memcpy (addrp, plugin_addr, plugin_addr_len); | ||
367 | if (NULL != plugin_name) | ||
368 | strcpy (&addrp[plugin_addr_len], plugin_name); | ||
369 | GNUNET_SERVER_notification_context_unicast (nc, ai->pc->client, &msg->header, | ||
370 | GNUNET_YES); | ||
371 | } | ||
315 | 372 | ||
316 | static void | 373 | static void |
317 | req_addr_peerinfo_it (void *cls, | 374 | req_addr_peerinfo_it (void *cls, |
@@ -326,12 +383,6 @@ req_addr_peerinfo_it (void *cls, | |||
326 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | 383 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) |
327 | { | 384 | { |
328 | struct AddressIteration *ai = cls; | 385 | struct AddressIteration *ai = cls; |
329 | struct PeerInformationMessage *msg; | ||
330 | size_t plugin_name_length; | ||
331 | size_t msize; | ||
332 | struct GNUNET_ATS_Information *atsp; | ||
333 | char *addrp; | ||
334 | |||
335 | 386 | ||
336 | GNUNET_assert (NULL != ai); | 387 | GNUNET_assert (NULL != ai); |
337 | GNUNET_assert (NULL != ai->pc); | 388 | GNUNET_assert (NULL != ai->pc); |
@@ -340,46 +391,37 @@ req_addr_peerinfo_it (void *cls, | |||
340 | 391 | ||
341 | if ((NULL == id) && (NULL == id) && (NULL == id)) | 392 | if ((NULL == id) && (NULL == id) && (NULL == id)) |
342 | { | 393 | { |
343 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 394 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
344 | "Address iteration done\n"); | 395 | "Address iteration done\n"); |
345 | return; | 396 | return; |
346 | } | 397 | } |
347 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 398 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
348 | "Callback for peer `%s' plugin `%s' BW out %llu, BW in %llu \n", | 399 | "Callback for %s peer `%s' plugin `%s' BW out %llu, BW in %llu \n", |
400 | (active == GNUNET_YES) ? "ACTIVE" : "INACTIVE", | ||
349 | GNUNET_i2s (id), | 401 | GNUNET_i2s (id), |
350 | plugin_name, | 402 | plugin_name, |
351 | ntohl (bandwidth_out.value__), | 403 | ntohl (bandwidth_out.value__), |
352 | ntohl (bandwidth_in.value__)); | 404 | ntohl (bandwidth_in.value__)); |
353 | 405 | ||
354 | /* Transmit result */ | 406 | /* Transmit result */ |
355 | 407 | if ((GNUNET_YES == ai->all) || (GNUNET_YES == active)) | |
356 | plugin_name_length = strlen (plugin_name) + 1; | 408 | { |
357 | msize = sizeof (struct PeerInformationMessage) + | 409 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
358 | atsi_count * sizeof (struct GNUNET_ATS_Information) + | 410 | "Sending result for %s peer `%s' plugin `%s' BW out %llu, BW in %llu \n", |
359 | plugin_addr_len + plugin_name_length; | 411 | (active == GNUNET_YES) ? "ACTIVE" : "INACTIVE", |
360 | char buf[msize] GNUNET_ALIGN; | 412 | GNUNET_i2s (id), |
361 | 413 | plugin_name, | |
362 | GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE); | 414 | ntohl (bandwidth_out.value__), |
363 | GNUNET_assert (atsi_count < | 415 | ntohl (bandwidth_in.value__)); |
364 | GNUNET_SERVER_MAX_MESSAGE_SIZE / | 416 | transmit_req_addr (cls, |
365 | sizeof (struct GNUNET_ATS_Information)); | 417 | id, |
366 | msg = (struct PeerInformationMessage *) buf; | 418 | plugin_name, |
367 | msg->header.size = htons (msize); | 419 | plugin_addr, plugin_addr_len, |
368 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE); | 420 | active, |
369 | msg->ats_count = htonl (atsi_count); | 421 | atsi, |
370 | msg->peer = *id; | 422 | atsi_count, |
371 | msg->address_length = htons (plugin_addr_len); | 423 | bandwidth_out, bandwidth_in); |
372 | msg->address_active = ntohl (active); | 424 | } |
373 | msg->plugin_name_length = htons (plugin_name_length); | ||
374 | msg->bandwidth_out = bandwidth_out; | ||
375 | msg->bandwidth_in = bandwidth_in; | ||
376 | atsp = (struct GNUNET_ATS_Information *) &msg[1]; | ||
377 | memcpy (atsp, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count); | ||
378 | addrp = (char *) &atsp[atsi_count]; | ||
379 | memcpy (addrp, plugin_addr, plugin_addr_len); | ||
380 | strcpy (&addrp[plugin_addr_len], plugin_name); | ||
381 | GNUNET_SERVER_notification_context_unicast (nc, ai->pc->client, &msg->header, | ||
382 | GNUNET_YES); | ||
383 | } | 425 | } |
384 | 426 | ||
385 | 427 | ||
@@ -396,12 +438,12 @@ req_addr_peer_it (void *cls, | |||
396 | struct AddressIteration *ai = cls; | 438 | struct AddressIteration *ai = cls; |
397 | if (NULL != id) | 439 | if (NULL != id) |
398 | { | 440 | { |
399 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Callback for peer `%s'\n", GNUNET_i2s (id)); | 441 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for peer `%s'\n", GNUNET_i2s (id)); |
400 | GAS_addresses_get_peer_info (id, &req_addr_peerinfo_it, ai); | 442 | GAS_addresses_get_peer_info (id, &req_addr_peerinfo_it, ai); |
401 | } | 443 | } |
402 | else | 444 | else |
403 | { | 445 | { |
404 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peer iteration done\n"); | 446 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer iteration done\n"); |
405 | } | 447 | } |
406 | } | 448 | } |
407 | 449 | ||
@@ -420,6 +462,7 @@ GAS_handle_request_address_list (void *cls, struct GNUNET_SERVER_Client *client, | |||
420 | struct AddressIteration ai; | 462 | struct AddressIteration ai; |
421 | struct AddressListRequestMessage * alrm = (struct AddressListRequestMessage *) message; | 463 | struct AddressListRequestMessage * alrm = (struct AddressListRequestMessage *) message; |
422 | struct GNUNET_PeerIdentity allzeros; | 464 | struct GNUNET_PeerIdentity allzeros; |
465 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_zero; | ||
423 | 466 | ||
424 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", | 467 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", |
425 | "ADDRESSLIST_REQUEST"); | 468 | "ADDRESSLIST_REQUEST"); |
@@ -431,18 +474,22 @@ GAS_handle_request_address_list (void *cls, struct GNUNET_SERVER_Client *client, | |||
431 | } | 474 | } |
432 | 475 | ||
433 | ai.all = ntohl (alrm->all); | 476 | ai.all = ntohl (alrm->all); |
477 | ai.id = ntohl (alrm->id); | ||
434 | ai.pc = pc; | 478 | ai.pc = pc; |
435 | 479 | ||
436 | memset (&allzeros, '\0', sizeof (struct GNUNET_PeerIdentity)); | 480 | memset (&allzeros, '\0', sizeof (struct GNUNET_PeerIdentity)); |
481 | bandwidth_zero.value__ = htonl (0); | ||
437 | if (0 == memcmp (&alrm->peer, &allzeros, sizeof (struct GNUNET_PeerIdentity))) | 482 | if (0 == memcmp (&alrm->peer, &allzeros, sizeof (struct GNUNET_PeerIdentity))) |
438 | { | 483 | { |
439 | /* Return addresses for all peers */ | 484 | /* Return addresses for all peers */ |
440 | GAS_addresses_iterate_peers (&req_addr_peer_it, &ai); | 485 | GAS_addresses_iterate_peers (&req_addr_peer_it, &ai); |
486 | transmit_req_addr (&ai, NULL, NULL, NULL, 0, GNUNET_NO, NULL, 0, bandwidth_zero, bandwidth_zero); | ||
441 | } | 487 | } |
442 | else | 488 | else |
443 | { | 489 | { |
444 | /* Return addresses for a specific peer */ | 490 | /* Return addresses for a specific peer */ |
445 | GAS_addresses_get_peer_info (&alrm->peer, &req_addr_peerinfo_it, &ai); | 491 | GAS_addresses_get_peer_info (&alrm->peer, &req_addr_peerinfo_it, &ai); |
492 | transmit_req_addr (&ai, NULL, NULL, NULL, 0, GNUNET_NO, NULL, 0, bandwidth_zero, bandwidth_zero); | ||
446 | } | 493 | } |
447 | } | 494 | } |
448 | 495 | ||