aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-12-15 18:09:16 +0000
committerChristian Grothoff <christian@grothoff.org>2014-12-15 18:09:16 +0000
commitd80d181ca46d0804af85bb33f16caa4c8eb00f9a (patch)
tree887188d35de602da8793241bae716a998f5702d6 /src
parent8978db474d26bef8fd7b023baeb5b8e3cb5224c6 (diff)
downloadgnunet-d80d181ca46d0804af85bb33f16caa4c8eb00f9a.tar.gz
gnunet-d80d181ca46d0804af85bb33f16caa4c8eb00f9a.zip
removing dead code, improving comments, simplifying iteration logic, making iteration over all addresses also faster
Diffstat (limited to 'src')
-rw-r--r--src/ats/ats.h19
-rw-r--r--src/ats/ats_api_performance.c175
-rw-r--r--src/ats/gnunet-service-ats.c3
-rw-r--r--src/ats/gnunet-service-ats_addresses.c207
-rw-r--r--src/ats/gnunet-service-ats_addresses.h24
-rw-r--r--src/ats/gnunet-service-ats_performance.c236
-rw-r--r--src/ats/gnunet-service-ats_performance.h16
7 files changed, 293 insertions, 387 deletions
diff --git a/src/ats/ats.h b/src/ats/ats.h
index 48c8a35d5..a758c3630 100644
--- a/src/ats/ats.h
+++ b/src/ats/ats.h
@@ -202,15 +202,32 @@ struct PeerInformationMessage
202}; 202};
203 203
204 204
205/**
206 * Client to service: please give us an overview of the addresses.
207 */
205struct AddressListRequestMessage 208struct AddressListRequestMessage
206{ 209{
210 /**
211 * Type is #GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_REQUEST
212 */
207 struct GNUNET_MessageHeader header; 213 struct GNUNET_MessageHeader header;
208 214
215 /**
216 * ID used to match replies to this request.
217 */
209 uint32_t id GNUNET_PACKED; 218 uint32_t id GNUNET_PACKED;
210 219
220 /**
221 * Which peer do we care about? All zeros for all.
222 */
223 struct GNUNET_PeerIdentity peer;
224
225 /**
226 * #GNUNET_YES to get information about all addresses,
227 * #GNUNET_NO to only return addresses that are in use.
228 */
211 int32_t all GNUNET_PACKED; 229 int32_t all GNUNET_PACKED;
212 230
213 struct GNUNET_PeerIdentity peer;
214}; 231};
215 232
216 233
diff --git a/src/ats/ats_api_performance.c b/src/ats/ats_api_performance.c
index 840e302b0..b1c48bdde 100644
--- a/src/ats/ats_api_performance.c
+++ b/src/ats/ats_api_performance.c
@@ -131,7 +131,7 @@ struct GNUNET_ATS_AddressListHandle
131 GNUNET_ATS_AddressInformationCallback cb; 131 GNUNET_ATS_AddressInformationCallback cb;
132 132
133 /** 133 /**
134 * Callback closure 134 * Callback closure for @e cb
135 */ 135 */
136 void *cb_cls; 136 void *cb_cls;
137 137
@@ -285,13 +285,15 @@ process_ats_message (void *cls,
285/** 285/**
286 * We can now transmit a message to ATS. Do it. 286 * We can now transmit a message to ATS. Do it.
287 * 287 *
288 * @param cls the 'struct GNUNET_ATS_SchedulingHandle' 288 * @param cls the `struct GNUNET_ATS_PerformanceHandle`
289 * @param size number of bytes we can transmit to ATS 289 * @param size number of bytes we can transmit to ATS
290 * @param buf where to copy the messages 290 * @param buf where to copy the messages
291 * @return number of bytes copied into buf 291 * @return number of bytes copied into @a buf
292 */ 292 */
293static size_t 293static size_t
294transmit_message_to_ats (void *cls, size_t size, void *buf) 294transmit_message_to_ats (void *cls,
295 size_t size,
296 void *buf)
295{ 297{
296 struct GNUNET_ATS_PerformanceHandle *ph = cls; 298 struct GNUNET_ATS_PerformanceHandle *ph = cls;
297 struct PendingMessage *p; 299 struct PendingMessage *p;
@@ -306,7 +308,9 @@ transmit_message_to_ats (void *cls, size_t size, void *buf)
306 memcpy (&cbuf[ret], &p[1], p->size); 308 memcpy (&cbuf[ret], &p[1], p->size);
307 ret += p->size; 309 ret += p->size;
308 size -= p->size; 310 size -= p->size;
309 GNUNET_CONTAINER_DLL_remove(ph->pending_head, ph->pending_tail, p); 311 GNUNET_CONTAINER_DLL_remove (ph->pending_head,
312 ph->pending_tail,
313 p);
310 GNUNET_free(p); 314 GNUNET_free(p);
311 } 315 }
312 do_transmit (ph); 316 do_transmit (ph);
@@ -331,8 +335,11 @@ do_transmit (struct GNUNET_ATS_PerformanceHandle *ph)
331 return; 335 return;
332 if (NULL == ph->client) 336 if (NULL == ph->client)
333 return; /* currently reconnecting */ 337 return; /* currently reconnecting */
334 ph->th = GNUNET_CLIENT_notify_transmit_ready (ph->client, p->size, 338 ph->th = GNUNET_CLIENT_notify_transmit_ready (ph->client,
335 GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &transmit_message_to_ats, ph); 339 p->size,
340 GNUNET_TIME_UNIT_FOREVER_REL,
341 GNUNET_YES,
342 &transmit_message_to_ats, ph);
336} 343}
337 344
338 345
@@ -428,13 +435,18 @@ process_rr_message (struct GNUNET_ATS_PerformanceHandle *ph,
428 GNUNET_break(0); 435 GNUNET_break(0);
429 return GNUNET_SYSERR; 436 return GNUNET_SYSERR;
430 } 437 }
431 GNUNET_CONTAINER_DLL_remove(ph->reservation_head, ph->reservation_tail, rc); 438 GNUNET_CONTAINER_DLL_remove (ph->reservation_head,
432 if ((amount == 0) || (rc->rcb != NULL )) 439 ph->reservation_tail,
440 rc);
441 if ( (0 == amount) ||
442 (NULL != rc->rcb) )
433 { 443 {
434 /* tell client if not cancelled */ 444 /* tell client if not cancelled */
435 if (rc->rcb != NULL ) 445 if (rc->rcb != NULL )
436 rc->rcb (rc->rcb_cls, &rr->peer, amount, 446 rc->rcb (rc->rcb_cls,
437 GNUNET_TIME_relative_ntoh (rr->res_delay)); 447 &rr->peer,
448 amount,
449 GNUNET_TIME_relative_ntoh (rr->res_delay));
438 GNUNET_free(rc); 450 GNUNET_free(rc);
439 return GNUNET_OK; 451 return GNUNET_OK;
440 } 452 }
@@ -445,7 +457,10 @@ process_rr_message (struct GNUNET_ATS_PerformanceHandle *ph,
445 return GNUNET_OK; /* do not try to undo failed undos or negative amounts */ 457 return GNUNET_OK; /* do not try to undo failed undos or negative amounts */
446 } 458 }
447 GNUNET_free(rc); 459 GNUNET_free(rc);
448 (void) GNUNET_ATS_reserve_bandwidth (ph, &rr->peer, -amount, NULL, NULL ); 460 (void) GNUNET_ATS_reserve_bandwidth (ph,
461 &rr->peer,
462 -amount,
463 NULL, NULL);
449 return GNUNET_OK; 464 return GNUNET_OK;
450} 465}
451 466
@@ -481,10 +496,6 @@ process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph,
481 GNUNET_break(0); 496 GNUNET_break(0);
482 return GNUNET_SYSERR; 497 return GNUNET_SYSERR;
483 } 498 }
484 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
485 _("Received %s message\n"),
486 "ATS_ADDRESSLIST_RESPONSE");
487
488 pi = (const struct PeerInformationMessage *) msg; 499 pi = (const struct PeerInformationMessage *) msg;
489 id = ntohl (pi->id); 500 id = ntohl (pi->id);
490 ats_count = ntohl (pi->ats_count); 501 ats_count = ntohl (pi->ats_count);
@@ -494,17 +505,21 @@ process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph,
494 atsi = (const struct GNUNET_ATS_Information *) &pi[1]; 505 atsi = (const struct GNUNET_ATS_Information *) &pi[1];
495 plugin_address = (const char *) &atsi[ats_count]; 506 plugin_address = (const char *) &atsi[ats_count];
496 plugin_name = &plugin_address[plugin_address_length]; 507 plugin_name = &plugin_address[plugin_address_length];
497 if ((plugin_address_length + plugin_name_length 508 if ( (plugin_address_length + plugin_name_length
498 + ats_count * sizeof(struct GNUNET_ATS_Information) 509 + ats_count * sizeof(struct GNUNET_ATS_Information)
499 + sizeof(struct PeerInformationMessage) != ntohs (msg->size)) 510 + sizeof (struct PeerInformationMessage) != ntohs (msg->size)) ||
500 || (ats_count 511 (ats_count > GNUNET_SERVER_MAX_MESSAGE_SIZE
501 > GNUNET_SERVER_MAX_MESSAGE_SIZE 512 / sizeof(struct GNUNET_ATS_Information)) ||
502 / sizeof(struct GNUNET_ATS_Information)) 513 (plugin_name[plugin_name_length - 1] != '\0') )
503 || (plugin_name[plugin_name_length - 1] != '\0'))
504 { 514 {
505 GNUNET_break(0); 515 GNUNET_break(0);
506 return GNUNET_SYSERR; 516 return GNUNET_SYSERR;
507 } 517 }
518 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
519 "Received %s message for peer %s and plugin %s\n",
520 "ATS_ADDRESSLIST_RESPONSE",
521 GNUNET_i2s (&pi->peer),
522 plugin_name);
508 523
509 next = ph->addresslist_head; 524 next = ph->addresslist_head;
510 while (NULL != (alh = next)) 525 while (NULL != (alh = next))
@@ -519,16 +534,16 @@ process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph,
519 return GNUNET_SYSERR; 534 return GNUNET_SYSERR;
520 } 535 }
521 536
522 memset (&allzeros, '\0', sizeof(allzeros)); 537 memset (&allzeros, '\0', sizeof (allzeros));
523 if ( (0 == memcmp (&allzeros, &pi->peer, sizeof(allzeros))) && 538 if ( (0 == memcmp (&allzeros, &pi->peer, sizeof(allzeros))) &&
524 (0 == plugin_name_length) && 539 (0 == plugin_name_length) &&
525 (0 == plugin_address_length) && 540 (0 == plugin_address_length) &&
526 (0 == ats_count) ) 541 (0 == ats_count) )
527 { 542 {
528 /* Done */ 543 /* Done */
529 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 544 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
530 _("Received last message for %s \n"), 545 "Received last message for %s\n",
531 "ATS_ADDRESSLIST_RESPONSE"); 546 "ATS_ADDRESSLIST_RESPONSE");
532 bandwidth_zero.value__ = htonl (0); 547 bandwidth_zero.value__ = htonl (0);
533 GNUNET_CONTAINER_DLL_remove (ph->addresslist_head, 548 GNUNET_CONTAINER_DLL_remove (ph->addresslist_head,
534 ph->addresslist_tail, 549 ph->addresslist_tail,
@@ -548,13 +563,15 @@ process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph,
548 address.address = plugin_address; 563 address.address = plugin_address;
549 address.address_length = plugin_address_length; 564 address.address_length = plugin_address_length;
550 address.transport_name = plugin_name; 565 address.transport_name = plugin_name;
551 566 if ( ( (GNUNET_YES == alh->all_addresses) ||
552 if ((GNUNET_YES == alh->all_addresses) || (GNUNET_YES == active)) 567 (GNUNET_YES == active) ) &&
553 { 568 (NULL != alh->cb) )
554 if (NULL != alh->cb) 569 alh->cb (ph->addr_info_cb_cls,
555 alh->cb (ph->addr_info_cb_cls, &address, active, pi->bandwidth_out, 570 &address,
556 pi->bandwidth_in, atsi, ats_count); 571 active,
557 } 572 pi->bandwidth_out,
573 pi->bandwidth_in,
574 atsi, ats_count);
558 return GNUNET_OK; 575 return GNUNET_OK;
559} 576}
560 577
@@ -592,11 +609,15 @@ process_ats_message (void *cls,
592 GNUNET_break(0); 609 GNUNET_break(0);
593 goto reconnect; 610 goto reconnect;
594 } 611 }
595 GNUNET_CLIENT_receive (ph->client, &process_ats_message, ph, 612 GNUNET_CLIENT_receive (ph->client,
596 GNUNET_TIME_UNIT_FOREVER_REL); 613 &process_ats_message,
614 ph,
615 GNUNET_TIME_UNIT_FOREVER_REL);
597 return; 616 return;
598 617
599 reconnect: 618 reconnect:
619 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
620 "Reconnecting!\n");
600 if (NULL != ph->th) 621 if (NULL != ph->th)
601 { 622 {
602 GNUNET_CLIENT_notify_transmit_ready_cancel (ph->th); 623 GNUNET_CLIENT_notify_transmit_ready_cancel (ph->th);
@@ -607,10 +628,12 @@ process_ats_message (void *cls,
607 if (NULL != ph->addr_info_cb) 628 if (NULL != ph->addr_info_cb)
608 { 629 {
609 /* Indicate reconnect */ 630 /* Indicate reconnect */
610 ph->addr_info_cb (ph->addr_info_cb_cls, NULL, GNUNET_NO, 631 ph->addr_info_cb (ph->addr_info_cb_cls,
611 GNUNET_BANDWIDTH_value_init (0), 632 NULL,
612 GNUNET_BANDWIDTH_value_init(0), 633 GNUNET_NO,
613 NULL, 0); 634 GNUNET_BANDWIDTH_value_init (0),
635 GNUNET_BANDWIDTH_value_init (0),
636 NULL, 0);
614 } 637 }
615 ph->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 638 ph->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
616 &reconnect_task, ph); 639 &reconnect_task, ph);
@@ -628,11 +651,14 @@ reconnect (struct GNUNET_ATS_PerformanceHandle *ph)
628 struct PendingMessage *p; 651 struct PendingMessage *p;
629 struct ClientStartMessage *init; 652 struct ClientStartMessage *init;
630 653
631 GNUNET_assert(NULL == ph->client); 654 GNUNET_assert (NULL == ph->client);
632 ph->client = GNUNET_CLIENT_connect ("ats", ph->cfg); 655 ph->client = GNUNET_CLIENT_connect ("ats",
633 GNUNET_assert(NULL != ph->client); 656 ph->cfg);
634 GNUNET_CLIENT_receive (ph->client, &process_ats_message, ph, 657 GNUNET_assert (NULL != ph->client);
635 GNUNET_TIME_UNIT_FOREVER_REL); 658 GNUNET_CLIENT_receive (ph->client,
659 &process_ats_message,
660 ph,
661 GNUNET_TIME_UNIT_FOREVER_REL);
636 if ((NULL == (p = ph->pending_head)) || (GNUNET_YES != p->is_init)) 662 if ((NULL == (p = ph->pending_head)) || (GNUNET_YES != p->is_init))
637 { 663 {
638 p = GNUNET_malloc (sizeof (struct PendingMessage) + 664 p = GNUNET_malloc (sizeof (struct PendingMessage) +
@@ -642,10 +668,12 @@ reconnect (struct GNUNET_ATS_PerformanceHandle *ph)
642 init = (struct ClientStartMessage *) &p[1]; 668 init = (struct ClientStartMessage *) &p[1];
643 init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START); 669 init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START);
644 init->header.size = htons (sizeof(struct ClientStartMessage)); 670 init->header.size = htons (sizeof(struct ClientStartMessage));
645 init->start_flag = htonl ( 671 init->start_flag = htonl ( (NULL == ph->addr_info_cb)
646 (NULL == ph->addr_info_cb) ? 672 ? START_FLAG_PERFORMANCE_NO_PIC
647 START_FLAG_PERFORMANCE_NO_PIC : START_FLAG_PERFORMANCE_WITH_PIC); 673 : START_FLAG_PERFORMANCE_WITH_PIC);
648 GNUNET_CONTAINER_DLL_insert(ph->pending_head, ph->pending_tail, p); 674 GNUNET_CONTAINER_DLL_insert (ph->pending_head,
675 ph->pending_tail,
676 p);
649 } 677 }
650 do_transmit (ph); 678 do_transmit (ph);
651} 679}
@@ -691,20 +719,25 @@ GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph)
691 719
692 while (NULL != (p = ph->pending_head)) 720 while (NULL != (p = ph->pending_head))
693 { 721 {
694 GNUNET_CONTAINER_DLL_remove(ph->pending_head, ph->pending_tail, p); 722 GNUNET_CONTAINER_DLL_remove (ph->pending_head,
695 GNUNET_free(p); 723 ph->pending_tail,
724 p);
725 GNUNET_free (p);
696 } 726 }
697 while (NULL != (alh = ph->addresslist_head)) 727 while (NULL != (alh = ph->addresslist_head))
698 { 728 {
699 GNUNET_CONTAINER_DLL_remove(ph->addresslist_head, ph->addresslist_tail, 729 GNUNET_CONTAINER_DLL_remove (ph->addresslist_head,
700 alh); 730 ph->addresslist_tail,
701 GNUNET_free(alh); 731 alh);
732 GNUNET_free (alh);
702 } 733 }
703 while (NULL != (rc = ph->reservation_head)) 734 while (NULL != (rc = ph->reservation_head))
704 { 735 {
705 GNUNET_CONTAINER_DLL_remove(ph->reservation_head, ph->reservation_tail, rc); 736 GNUNET_CONTAINER_DLL_remove (ph->reservation_head,
706 GNUNET_break(NULL == rc->rcb); 737 ph->reservation_tail,
707 GNUNET_free(rc); 738 rc);
739 GNUNET_break (NULL == rc->rcb);
740 GNUNET_free (rc);
708 } 741 }
709 742
710 if (GNUNET_SCHEDULER_NO_TASK != ph->task) 743 if (GNUNET_SCHEDULER_NO_TASK != ph->task)
@@ -717,7 +750,7 @@ GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph)
717 GNUNET_CLIENT_disconnect (ph->client); 750 GNUNET_CLIENT_disconnect (ph->client);
718 ph->client = NULL; 751 ph->client = NULL;
719 } 752 }
720 GNUNET_free(ph); 753 GNUNET_free (ph);
721} 754}
722 755
723 756
@@ -731,7 +764,7 @@ GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph)
731 * @param amount reserve N bytes for receiving, negative 764 * @param amount reserve N bytes for receiving, negative
732 * amounts can be used to undo a (recent) reservation; 765 * amounts can be used to undo a (recent) reservation;
733 * @param rcb function to call with the resulting reservation information 766 * @param rcb function to call with the resulting reservation information
734 * @param rcb_cls closure for info 767 * @param rcb_cls closure for @a rcb
735 * @return NULL on error 768 * @return NULL on error
736 * @deprecated will be replaced soon 769 * @deprecated will be replaced soon
737 */ 770 */
@@ -750,9 +783,12 @@ GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph,
750 rc->peer = *peer; 783 rc->peer = *peer;
751 rc->rcb = rcb; 784 rc->rcb = rcb;
752 rc->rcb_cls = rcb_cls; 785 rc->rcb_cls = rcb_cls;
753 if ((rcb != NULL )&& (amount > 0))rc->undo = GNUNET_YES; 786 if ( (NULL != rcb) &&
754 GNUNET_CONTAINER_DLL_insert_tail(ph->reservation_head, ph->reservation_tail, 787 (amount > 0) )
755 rc); 788 rc->undo = GNUNET_YES;
789 GNUNET_CONTAINER_DLL_insert_tail (ph->reservation_head,
790 ph->reservation_tail,
791 rc);
756 792
757 p = GNUNET_malloc (sizeof (struct PendingMessage) + 793 p = GNUNET_malloc (sizeof (struct PendingMessage) +
758 sizeof (struct ReservationRequestMessage)); 794 sizeof (struct ReservationRequestMessage));
@@ -763,7 +799,9 @@ GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph,
763 m->header.size = htons (sizeof(struct ReservationRequestMessage)); 799 m->header.size = htons (sizeof(struct ReservationRequestMessage));
764 m->amount = htonl (amount); 800 m->amount = htonl (amount);
765 m->peer = *peer; 801 m->peer = *peer;
766 GNUNET_CONTAINER_DLL_insert_tail(ph->pending_head, ph->pending_tail, p); 802 GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head,
803 ph->pending_tail,
804 p);
767 do_transmit (ph); 805 do_transmit (ph);
768 return rc; 806 return rc;
769} 807}
@@ -790,7 +828,7 @@ GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc)
790 * get only address currently used 828 * get only address currently used
791 * @param infocb callback to call with the addresses, 829 * @param infocb callback to call with the addresses,
792 * will callback with address == NULL when done 830 * will callback with address == NULL when done
793 * @param infocb_cls closure for infocb 831 * @param infocb_cls closure for @a infocb
794 * @return ats performance context 832 * @return ats performance context
795 */ 833 */
796struct GNUNET_ATS_AddressListHandle* 834struct GNUNET_ATS_AddressListHandle*
@@ -820,7 +858,7 @@ GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *hand
820 else 858 else
821 { 859 {
822 alh->all_peers = GNUNET_NO; 860 alh->all_peers = GNUNET_NO;
823 alh->peer = (*peer); 861 alh->peer = *peer;
824 } 862 }
825 GNUNET_CONTAINER_DLL_insert (handle->addresslist_head, 863 GNUNET_CONTAINER_DLL_insert (handle->addresslist_head,
826 handle->addresslist_tail, 864 handle->addresslist_tail,
@@ -836,9 +874,9 @@ GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *hand
836 m->id = htonl (alh->id); 874 m->id = htonl (alh->id);
837 if (NULL != peer) 875 if (NULL != peer)
838 m->peer = *peer; 876 m->peer = *peer;
839 GNUNET_CONTAINER_DLL_insert_tail(handle->pending_head, 877 GNUNET_CONTAINER_DLL_insert_tail (handle->pending_head,
840 handle->pending_tail, 878 handle->pending_tail,
841 p); 879 p);
842 do_transmit (handle); 880 do_transmit (handle);
843 881
844 return alh; 882 return alh;
@@ -853,7 +891,6 @@ GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *hand
853void 891void
854GNUNET_ATS_performance_list_addresses_cancel (struct GNUNET_ATS_AddressListHandle *handle) 892GNUNET_ATS_performance_list_addresses_cancel (struct GNUNET_ATS_AddressListHandle *handle)
855{ 893{
856 GNUNET_assert (NULL != handle);
857 GNUNET_CONTAINER_DLL_remove (handle->ph->addresslist_head, 894 GNUNET_CONTAINER_DLL_remove (handle->ph->addresslist_head,
858 handle->ph->addresslist_tail, 895 handle->ph->addresslist_tail,
859 handle); 896 handle);
diff --git a/src/ats/gnunet-service-ats.c b/src/ats/gnunet-service-ats.c
index 729f1952b..db6ce6663 100644
--- a/src/ats/gnunet-service-ats.c
+++ b/src/ats/gnunet-service-ats.c
@@ -144,7 +144,8 @@ cleanup_task (void *cls,
144 * @param cfg configuration to use 144 * @param cfg configuration to use
145 */ 145 */
146static void 146static void
147run (void *cls, struct GNUNET_SERVER_Handle *server, 147run (void *cls,
148 struct GNUNET_SERVER_Handle *server,
148 const struct GNUNET_CONFIGURATION_Handle *cfg) 149 const struct GNUNET_CONFIGURATION_Handle *cfg)
149{ 150{
150 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 151 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c
index 70224e67a..768b13076 100644
--- a/src/ats/gnunet-service-ats_addresses.c
+++ b/src/ats/gnunet-service-ats_addresses.c
@@ -1616,16 +1616,16 @@ find_preference_client (struct GAS_Addresses_Handle *handle, void *client)
1616 return NULL; 1616 return NULL;
1617} 1617}
1618 1618
1619
1619/** 1620/**
1620 * A performance client disconnected 1621 * A performance client disconnected
1621 * 1622 *
1622 * @param handle address handle 1623 * @param handle address handle
1623 * @param client the client 1624 * @param client the client
1624 */ 1625 */
1625
1626void 1626void
1627GAS_addresses_preference_client_disconnect (struct GAS_Addresses_Handle *handle, 1627GAS_addresses_preference_client_disconnect (struct GAS_Addresses_Handle *handle,
1628 void *client) 1628 void *client)
1629{ 1629{
1630 struct GAS_Addresses_Preference_Clients * pc; 1630 struct GAS_Addresses_Preference_Clients * pc;
1631 if (NULL != (pc = find_preference_client (handle, client))) 1631 if (NULL != (pc = find_preference_client (handle, client)))
@@ -1640,6 +1640,7 @@ GAS_addresses_preference_client_disconnect (struct GAS_Addresses_Handle *handle,
1640 GAS_normalization_preference_client_disconnect (client); 1640 GAS_normalization_preference_client_disconnect (client);
1641} 1641}
1642 1642
1643
1643/** 1644/**
1644 * Change the preference for a peer 1645 * Change the preference for a peer
1645 * 1646 *
@@ -1679,7 +1680,10 @@ GAS_addresses_preference_change (struct GAS_Addresses_Handle *handle,
1679 GNUNET_CONTAINER_DLL_insert (handle->preference_clients_head, 1680 GNUNET_CONTAINER_DLL_insert (handle->preference_clients_head,
1680 handle->preference_clients_tail, pc); 1681 handle->preference_clients_tail, pc);
1681 handle->pref_clients ++; 1682 handle->pref_clients ++;
1682 GNUNET_STATISTICS_set (handle->stat, "# active performance clients", handle->pref_clients, GNUNET_NO); 1683 GNUNET_STATISTICS_set (handle->stat,
1684 "# active performance clients",
1685 handle->pref_clients,
1686 GNUNET_NO);
1683 } 1687 }
1684 1688
1685 handle->env.sf.s_bulk_start (handle->solver); 1689 handle->env.sf.s_bulk_start (handle->solver);
@@ -1688,6 +1692,7 @@ GAS_addresses_preference_change (struct GAS_Addresses_Handle *handle,
1688 handle->env.sf.s_bulk_stop (handle->solver); 1692 handle->env.sf.s_bulk_stop (handle->solver);
1689} 1693}
1690 1694
1695
1691/** 1696/**
1692 * Change the preference for a peer 1697 * Change the preference for a peer
1693 * 1698 *
@@ -1700,9 +1705,11 @@ GAS_addresses_preference_change (struct GAS_Addresses_Handle *handle,
1700 */ 1705 */
1701void 1706void
1702GAS_addresses_preference_feedback (struct GAS_Addresses_Handle *handle, 1707GAS_addresses_preference_feedback (struct GAS_Addresses_Handle *handle,
1703 void *application, const struct GNUNET_PeerIdentity *peer, 1708 void *application,
1704 const struct GNUNET_TIME_Relative scope, 1709 const struct GNUNET_PeerIdentity *peer,
1705 enum GNUNET_ATS_PreferenceKind kind, float score_abs) 1710 const struct GNUNET_TIME_Relative scope,
1711 enum GNUNET_ATS_PreferenceKind kind,
1712 float score_abs)
1706{ 1713{
1707 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1714 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1708 "Received `%s' for peer `%s' for client %p\n", "PREFERENCE FEEDBACK", 1715 "Received `%s' for peer `%s' for client %p\n", "PREFERENCE FEEDBACK",
@@ -1725,6 +1732,7 @@ GAS_addresses_preference_feedback (struct GAS_Addresses_Handle *handle,
1725 score_abs); 1732 score_abs);
1726} 1733}
1727 1734
1735
1728/** 1736/**
1729 * Load quotas for networks from configuration 1737 * Load quotas for networks from configuration
1730 * 1738 *
@@ -1850,6 +1858,7 @@ load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
1850 return GNUNET_ATS_NetworkTypeCount; 1858 return GNUNET_ATS_NetworkTypeCount;
1851} 1859}
1852 1860
1861
1853/** 1862/**
1854 * Callback for solver to notify about assignment changes 1863 * Callback for solver to notify about assignment changes
1855 * 1864 *
@@ -1945,7 +1954,7 @@ bandwidth_changed_cb (void *cls, struct ATS_Address *address)
1945 */ 1954 */
1946struct GAS_Addresses_Handle * 1955struct GAS_Addresses_Handle *
1947GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, 1956GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
1948 const struct GNUNET_STATISTICS_Handle *stats) 1957 const struct GNUNET_STATISTICS_Handle *stats)
1949{ 1958{
1950 struct GAS_Addresses_Handle *ah; 1959 struct GAS_Addresses_Handle *ah;
1951 unsigned long long quotas_in[GNUNET_ATS_NetworkTypeCount]; 1960 unsigned long long quotas_in[GNUNET_ATS_NetworkTypeCount];
@@ -1964,11 +1973,11 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
1964 GNUNET_assert(NULL != ah->addresses); 1973 GNUNET_assert(NULL != ah->addresses);
1965 1974
1966 /* Figure out configured solution method */ 1975 /* Figure out configured solution method */
1967 if (GNUNET_SYSERR 1976 if (GNUNET_SYSERR ==
1968 == GNUNET_CONFIGURATION_get_value_string (cfg, "ats", "MODE", &mode_str)) 1977 GNUNET_CONFIGURATION_get_value_string (cfg, "ats", "MODE", &mode_str))
1969 { 1978 {
1970 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1979 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1971 "No resource assignment method configured, using proportional approach\n"); 1980 "No resource assignment method configured, using proportional approach\n");
1972 ah->ats_mode = MODE_PROPORTIONAL; 1981 ah->ats_mode = MODE_PROPORTIONAL;
1973 } 1982 }
1974 else 1983 else
@@ -1982,8 +1991,8 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
1982 ah->ats_mode = MODE_MLP; 1991 ah->ats_mode = MODE_MLP;
1983#if !HAVE_LIBGLPK 1992#if !HAVE_LIBGLPK
1984 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1993 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1985 "Assignment method `%s' configured, but GLPK is not available, please install \n", 1994 "Assignment method `%s' configured, but GLPK is not available, please install \n",
1986 mode_str); 1995 mode_str);
1987 ah->ats_mode = MODE_PROPORTIONAL; 1996 ah->ats_mode = MODE_PROPORTIONAL;
1988#endif 1997#endif
1989 } 1998 }
@@ -1992,8 +2001,8 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
1992 else 2001 else
1993 { 2002 {
1994 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 2003 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1995 "Invalid resource assignment method `%s' configured, using proportional approach\n", 2004 "Invalid resource assignment method `%s' configured, using proportional approach\n",
1996 mode_str); 2005 mode_str);
1997 ah->ats_mode = MODE_PROPORTIONAL; 2006 ah->ats_mode = MODE_PROPORTIONAL;
1998 } 2007 }
1999 GNUNET_free(mode_str); 2008 GNUNET_free(mode_str);
@@ -2035,11 +2044,18 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
2035 plugin_short = NULL; 2044 plugin_short = NULL;
2036 break; 2045 break;
2037 } 2046 }
2038 GNUNET_asprintf (&ah->plugin, "libgnunet_plugin_ats_%s", plugin_short); 2047 GNUNET_asprintf (&ah->plugin,
2039 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initializing solver `%s '`%s'\n"), plugin_short, ah->plugin); 2048 "libgnunet_plugin_ats_%s",
2040 if (NULL == (ah->solver = GNUNET_PLUGIN_load (ah->plugin, &ah->env))) 2049 plugin_short);
2050 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2051 _("Initializing solver `%s '`%s'\n"),
2052 plugin_short,
2053 ah->plugin);
2054 if (NULL == (ah->solver = GNUNET_PLUGIN_load (ah->plugin, &ah->env)))
2041 { 2055 {
2042 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Failed to initialize solver `%s'!\n"), ah->plugin); 2056 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2057 _("Failed to initialize solver `%s'!\n"),
2058 ah->plugin);
2043 return NULL; 2059 return NULL;
2044 } 2060 }
2045 2061
@@ -2058,11 +2074,12 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
2058 2074
2059 2075
2060 GAS_normalization_start (&normalized_preference_changed_cb, ah, 2076 GAS_normalization_start (&normalized_preference_changed_cb, ah,
2061 &normalized_property_changed_cb, ah); 2077 &normalized_property_changed_cb, ah);
2062 2078
2063 if (NULL == ah->solver) 2079 if (NULL == ah->solver)
2064 { 2080 {
2065 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Failed to initialize solver!\n")); 2081 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2082 _("Failed to initialize solver!\n"));
2066 GNUNET_free(ah); 2083 GNUNET_free(ah);
2067 return NULL ; 2084 return NULL ;
2068 } 2085 }
@@ -2075,6 +2092,7 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
2075 return ah; 2092 return ah;
2076} 2093}
2077 2094
2095
2078/** 2096/**
2079 * Destroy all addresses iterator 2097 * Destroy all addresses iterator
2080 * 2098 *
@@ -2151,21 +2169,27 @@ GAS_addresses_done (struct GAS_Addresses_Handle *handle)
2151 handle->addresses = NULL; 2169 handle->addresses = NULL;
2152 while (NULL != (cur = handle->pending_requests_head)) 2170 while (NULL != (cur = handle->pending_requests_head))
2153 { 2171 {
2154 GNUNET_CONTAINER_DLL_remove(handle->pending_requests_head, handle->pending_requests_tail, cur); 2172 GNUNET_CONTAINER_DLL_remove (handle->pending_requests_head,
2173 handle->pending_requests_tail,
2174 cur);
2155 GNUNET_free(cur); 2175 GNUNET_free(cur);
2156 } 2176 }
2157 2177
2158 while (NULL != (pcur = handle->preference_clients_head)) 2178 while (NULL != (pcur = handle->preference_clients_head))
2159 { 2179 {
2160 GNUNET_CONTAINER_DLL_remove (handle->preference_clients_head, 2180 GNUNET_CONTAINER_DLL_remove (handle->preference_clients_head,
2161 handle->preference_clients_tail, pcur); 2181 handle->preference_clients_tail,
2182 pcur);
2162 GNUNET_assert (handle->pref_clients > 0); 2183 GNUNET_assert (handle->pref_clients > 0);
2163 handle->pref_clients --; 2184 handle->pref_clients --;
2164 GNUNET_STATISTICS_set (handle->stat, "# active performance clients", handle->pref_clients, GNUNET_NO); 2185 GNUNET_STATISTICS_set (handle->stat,
2186 "# active performance clients",
2187 handle->pref_clients,
2188 GNUNET_NO);
2165 GNUNET_free (pcur); 2189 GNUNET_free (pcur);
2166 } 2190 }
2167 2191 GNUNET_PLUGIN_unload (handle->plugin,
2168 GNUNET_PLUGIN_unload (handle->plugin, handle->solver); 2192 handle->solver);
2169 GNUNET_free (handle->plugin); 2193 GNUNET_free (handle->plugin);
2170 GNUNET_free(handle); 2194 GNUNET_free(handle);
2171 /* Stop configured solution method */ 2195 /* Stop configured solution method */
@@ -2173,76 +2197,19 @@ GAS_addresses_done (struct GAS_Addresses_Handle *handle)
2173} 2197}
2174 2198
2175 2199
2176struct PeerIteratorContext
2177{
2178 GNUNET_ATS_Peer_Iterator it;
2179 void *it_cls;
2180 struct GNUNET_CONTAINER_MultiPeerMap *peers_returned;
2181};
2182
2183
2184/** 2200/**
2185 * Iterator to iterate over all peers 2201 * Closure for #peerinfo_it().
2186 *
2187 * @param cls a PeerIteratorContext
2188 * @param key the peer id
2189 * @param value the ATS_address
2190 * @return #GNUNET_OK to continue
2191 */ 2202 */
2192static int
2193peer_it (void *cls,
2194 const struct GNUNET_PeerIdentity *key,
2195 void *value)
2196{
2197 struct PeerIteratorContext *ip_ctx = cls;
2198
2199 if (GNUNET_NO ==
2200 GNUNET_CONTAINER_multipeermap_contains (ip_ctx->peers_returned, key))
2201 {
2202 GNUNET_CONTAINER_multipeermap_put (ip_ctx->peers_returned, key, NULL,
2203 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
2204 ip_ctx->it (ip_ctx->it_cls, key);
2205 }
2206
2207 return GNUNET_OK;
2208}
2209
2210/**
2211 * Return information all peers currently known to ATS
2212 *
2213 * @param handle the address handle to use
2214 * @param p_it the iterator to call for every peer
2215 * @param p_it_cls the closure for the iterator
2216 */
2217void
2218GAS_addresses_iterate_peers (struct GAS_Addresses_Handle *handle,
2219 GNUNET_ATS_Peer_Iterator p_it, void *p_it_cls)
2220{
2221 struct PeerIteratorContext ip_ctx;
2222 unsigned int size;
2223
2224 if (NULL == p_it)
2225 return;
2226 GNUNET_assert(NULL != handle->addresses);
2227
2228 size = GNUNET_CONTAINER_multipeermap_size (handle->addresses);
2229 if (0 != size)
2230 {
2231 ip_ctx.it = p_it;
2232 ip_ctx.it_cls = p_it_cls;
2233 ip_ctx.peers_returned = GNUNET_CONTAINER_multipeermap_create (size,
2234 GNUNET_NO);
2235 GNUNET_CONTAINER_multipeermap_iterate (handle->addresses,
2236 &peer_it,
2237 &ip_ctx);
2238 GNUNET_CONTAINER_multipeermap_destroy (ip_ctx.peers_returned);
2239 }
2240 p_it (p_it_cls, NULL );
2241}
2242
2243struct PeerInfoIteratorContext 2203struct PeerInfoIteratorContext
2244{ 2204{
2205 /**
2206 * Function to call for each address.
2207 */
2245 GNUNET_ATS_PeerInfo_Iterator it; 2208 GNUNET_ATS_PeerInfo_Iterator it;
2209
2210 /**
2211 * Closure for @e it.
2212 */
2246 void *it_cls; 2213 void *it_cls;
2247}; 2214};
2248 2215
@@ -2263,13 +2230,15 @@ peerinfo_it (void *cls,
2263 struct PeerInfoIteratorContext *pi_ctx = cls; 2230 struct PeerInfoIteratorContext *pi_ctx = cls;
2264 struct ATS_Address *addr = value; 2231 struct ATS_Address *addr = value;
2265 2232
2266 if (NULL != pi_ctx->it) 2233 pi_ctx->it (pi_ctx->it_cls,
2267 { 2234 &addr->peer,
2268 pi_ctx->it (pi_ctx->it_cls, &addr->peer, addr->plugin, addr->addr, 2235 addr->plugin,
2269 addr->addr_len, addr->active, addr->atsi, addr->atsi_count, 2236 addr->addr,
2270 GNUNET_BANDWIDTH_value_init (addr->assigned_bw_out), 2237 addr->addr_len,
2271 GNUNET_BANDWIDTH_value_init (addr->assigned_bw_in)); 2238 addr->active,
2272 } 2239 addr->atsi, addr->atsi_count,
2240 GNUNET_BANDWIDTH_value_init (addr->assigned_bw_out),
2241 GNUNET_BANDWIDTH_value_init (addr->assigned_bw_in));
2273 return GNUNET_YES; 2242 return GNUNET_YES;
2274} 2243}
2275 2244
@@ -2278,36 +2247,40 @@ peerinfo_it (void *cls,
2278 * Return information all peers currently known to ATS 2247 * Return information all peers currently known to ATS
2279 * 2248 *
2280 * @param handle the address handle to use 2249 * @param handle the address handle to use
2281 * @param peer the respective peer 2250 * @param peer the respective peer, NULL for 'all' peers
2282 * @param pi_it the iterator to call for every peer 2251 * @param pi_it the iterator to call for every peer
2283 * @param pi_it_cls the closure for the iterator 2252 * @param pi_it_cls the closure for @a pi_it
2284 */ 2253 */
2285void 2254void
2286GAS_addresses_get_peer_info (struct GAS_Addresses_Handle *handle, 2255GAS_addresses_get_peer_info (struct GAS_Addresses_Handle *handle,
2287 const struct GNUNET_PeerIdentity *peer, GNUNET_ATS_PeerInfo_Iterator pi_it, 2256 const struct GNUNET_PeerIdentity *peer,
2288 void *pi_it_cls) 2257 GNUNET_ATS_PeerInfo_Iterator pi_it,
2258 void *pi_it_cls)
2289{ 2259{
2290 struct PeerInfoIteratorContext pi_ctx; 2260 struct PeerInfoIteratorContext pi_ctx;
2291 2261
2292 GNUNET_assert(NULL != peer);
2293 GNUNET_assert(NULL != handle->addresses);
2294 if (NULL == pi_it) 2262 if (NULL == pi_it)
2295 return; /* does not make sense without callback */ 2263 {
2296 2264 /* does not make sense without callback */
2265 GNUNET_break (0);
2266 return;
2267 }
2297 pi_ctx.it = pi_it; 2268 pi_ctx.it = pi_it;
2298 pi_ctx.it_cls = pi_it_cls; 2269 pi_ctx.it_cls = pi_it_cls;
2299 GNUNET_CONTAINER_multipeermap_get_multiple (handle->addresses, 2270 if (NULL == peer)
2300 peer, 2271 GNUNET_CONTAINER_multipeermap_iterate (handle->addresses,
2301 &peerinfo_it, &pi_ctx); 2272 &peerinfo_it,
2302 2273 &pi_ctx);
2303 if (NULL != pi_it) 2274 else
2304 pi_it (pi_it_cls, 2275 GNUNET_CONTAINER_multipeermap_get_multiple (handle->addresses,
2305 NULL, NULL, NULL, 0, 2276 peer,
2306 GNUNET_NO, 2277 &peerinfo_it, &pi_ctx);
2307 NULL, 0, 2278 pi_it (pi_it_cls,
2308 zero_bw, 2279 NULL, NULL, NULL, 0,
2309 zero_bw); 2280 GNUNET_NO,
2310 2281 NULL, 0,
2282 zero_bw,
2283 zero_bw);
2311} 2284}
2312 2285
2313/* end of gnunet-service-ats_addresses.c */ 2286/* end of gnunet-service-ats_addresses.c */
diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h
index a1f9e69d5..1c6bb288a 100644
--- a/src/ats/gnunet-service-ats_addresses.h
+++ b/src/ats/gnunet-service-ats_addresses.h
@@ -642,30 +642,6 @@ GAS_addresses_preference_feedback (struct GAS_Addresses_Handle *handle,
642 642
643 643
644/** 644/**
645 * Iterator for #GAS_addresses_iterate_peers()
646 *
647 * @param p_it_cls closure
648 * @param id the peer id
649 */
650typedef void
651(*GNUNET_ATS_Peer_Iterator) (void *p_it_cls,
652 const struct GNUNET_PeerIdentity *id);
653
654
655/**
656 * Return all peers currently known to ATS
657 *
658 * @param handle the address handle to use
659 * @param p_it the iterator to call for every peer
660 * @param p_it_cls the closure for @a p_it
661 */
662void
663GAS_addresses_iterate_peers (struct GAS_Addresses_Handle *handle,
664 GNUNET_ATS_Peer_Iterator p_it,
665 void *p_it_cls);
666
667
668/**
669 * Iterator for #GAS_addresses_get_peer_info() 645 * Iterator for #GAS_addresses_get_peer_info()
670 * 646 *
671 * @param p_it_cls closure closure 647 * @param p_it_cls closure closure
diff --git a/src/ats/gnunet-service-ats_performance.c b/src/ats/gnunet-service-ats_performance.c
index 71e176a60..3f90802fe 100644
--- a/src/ats/gnunet-service-ats_performance.c
+++ b/src/ats/gnunet-service-ats_performance.c
@@ -60,23 +60,6 @@ struct PerformanceClient
60 60
61 61
62/** 62/**
63 * We keep clients that are interested in performance in a linked list.
64 */
65struct AddressIteration
66{
67 /**
68 * Actual handle to the client.
69 */
70 struct PerformanceClient *pc;
71
72 int all;
73
74 uint32_t id;
75
76 unsigned int msg_type;
77};
78
79/**
80 * Address handle 63 * Address handle
81 */ 64 */
82static struct GAS_Addresses_Handle *GSA_addresses; 65static struct GAS_Addresses_Handle *GSA_addresses;
@@ -294,37 +277,15 @@ peerinfo_it (void *cls,
294 plugin_name, 277 plugin_name,
295 (unsigned int) ntohl (bandwidth_out.value__), 278 (unsigned int) ntohl (bandwidth_out.value__),
296 (unsigned int) ntohl (bandwidth_in.value__)); 279 (unsigned int) ntohl (bandwidth_in.value__));
297 GAS_performance_notify_client(pc, 280 GAS_performance_notify_client (pc,
298 id, 281 id,
299 plugin_name, 282 plugin_name,
300 plugin_addr, 283 plugin_addr,
301 plugin_addr_len, 284 plugin_addr_len,
302 active, 285 active,
303 atsi, atsi_count, 286 atsi, atsi_count,
304 bandwidth_out, bandwidth_in); 287 bandwidth_out,
305} 288 bandwidth_in);
306
307
308/**
309 * Iterator for #GAS_performance_add_client()
310 *
311 * @param cls the client requesting information
312 * @param id result
313 */
314static void
315peer_it (void *cls,
316 const struct GNUNET_PeerIdentity *id)
317{
318 struct PerformanceClient *pc = cls;
319
320 if (NULL != id)
321 {
322 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
323 "Callback for peer `%s'\n",
324 GNUNET_i2s (id));
325 GAS_addresses_get_peer_info (GSA_addresses, id,
326 &peerinfo_it, pc);
327 }
328} 289}
329 290
330 291
@@ -339,8 +300,8 @@ GAS_performance_add_client (struct GNUNET_SERVER_Client *client,
339 enum StartFlag flag) 300 enum StartFlag flag)
340{ 301{
341 struct PerformanceClient *pc; 302 struct PerformanceClient *pc;
342 GNUNET_break (NULL == find_client (client));
343 303
304 GNUNET_break (NULL == find_client (client));
344 pc = GNUNET_new (struct PerformanceClient); 305 pc = GNUNET_new (struct PerformanceClient);
345 pc->client = client; 306 pc->client = client;
346 pc->flag = flag; 307 pc->flag = flag;
@@ -349,17 +310,43 @@ GAS_performance_add_client (struct GNUNET_SERVER_Client *client,
349 "Adding performance client %s PIC\n", 310 "Adding performance client %s PIC\n",
350 (flag == START_FLAG_PERFORMANCE_WITH_PIC) ? "with" : "without"); 311 (flag == START_FLAG_PERFORMANCE_WITH_PIC) ? "with" : "without");
351 312
352 GNUNET_SERVER_notification_context_add (nc, client); 313 GNUNET_SERVER_notification_context_add (nc,
353 GNUNET_CONTAINER_DLL_insert (pc_head, pc_tail, pc); 314 client);
354 315 GNUNET_CONTAINER_DLL_insert (pc_head,
355 /* Send information about clients */ 316 pc_tail,
356 GAS_addresses_iterate_peers (GSA_addresses, 317 pc);
357 &peer_it, 318 GAS_addresses_get_peer_info (GSA_addresses,
319 NULL,
320 &peerinfo_it,
358 pc); 321 pc);
359} 322}
360 323
361 324
362/** 325/**
326 * Information we need for the callbacks to return a list of addresses
327 * back to the client.
328 */
329struct AddressIteration
330{
331 /**
332 * Actual handle to the client.
333 */
334 struct PerformanceClient *pc;
335
336 /**
337 * Are we sending all addresses, or only those that are active?
338 */
339 int all;
340
341 /**
342 * Which ID should be included in the response?
343 */
344 uint32_t id;
345
346};
347
348
349/**
363 * Send a #GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE with the 350 * Send a #GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE with the
364 * given address details to the client identified in @a ai. 351 * given address details to the client identified in @a ai.
365 * 352 *
@@ -427,13 +414,16 @@ transmit_req_addr (struct AddressIteration *ai,
427 memcpy (addrp, plugin_addr, plugin_addr_len); 414 memcpy (addrp, plugin_addr, plugin_addr_len);
428 if (NULL != plugin_name) 415 if (NULL != plugin_name)
429 strcpy (&addrp[plugin_addr_len], plugin_name); 416 strcpy (&addrp[plugin_addr_len], plugin_name);
430 GNUNET_SERVER_notification_context_unicast (nc, ai->pc->client, &msg->header, 417 GNUNET_SERVER_notification_context_unicast (nc,
418 ai->pc->client,
419 &msg->header,
431 GNUNET_NO); 420 GNUNET_NO);
432} 421}
433 422
434 423
435/** 424/**
436 * Iterator for #GAS_addresses_get_peer_info() 425 * Iterator for #GAS_addresses_get_peer_info(), called with peer-specific
426 * information to be passed back to the client.
437 * 427 *
438 * @param cls closure with our `struct AddressIteration *` 428 * @param cls closure with our `struct AddressIteration *`
439 * @param id the peer id 429 * @param id the peer id
@@ -450,7 +440,8 @@ static void
450req_addr_peerinfo_it (void *cls, 440req_addr_peerinfo_it (void *cls,
451 const struct GNUNET_PeerIdentity *id, 441 const struct GNUNET_PeerIdentity *id,
452 const char *plugin_name, 442 const char *plugin_name,
453 const void *plugin_addr, size_t plugin_addr_len, 443 const void *plugin_addr,
444 size_t plugin_addr_len,
454 int active, 445 int active,
455 const struct GNUNET_ATS_Information *atsi, 446 const struct GNUNET_ATS_Information *atsi,
456 uint32_t atsi_count, 447 uint32_t atsi_count,
@@ -459,30 +450,29 @@ req_addr_peerinfo_it (void *cls,
459{ 450{
460 struct AddressIteration *ai = cls; 451 struct AddressIteration *ai = cls;
461 452
462 GNUNET_assert (NULL != ai); 453 if ( (NULL == id) &&
463 GNUNET_assert (NULL != ai->pc); 454 (NULL == plugin_name) &&
464 if (NULL == find_client (ai->pc->client)) 455 (NULL == plugin_addr) )
465 return; /* Client disconnected */
466
467 if ((NULL == id) && (NULL == plugin_name) && (NULL == plugin_addr))
468 { 456 {
469 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 457 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
470 "Address iteration done\n"); 458 "Address iteration done for one peer\n");
471 return; 459 return;
472 } 460 }
473 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 461 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
474 "Callback for %s peer `%s' plugin `%s' BW out %u, BW in %u\n", 462 "Callback for %s peer `%s' plugin `%s' BW out %u, BW in %u\n",
475 (active == GNUNET_YES) ? "ACTIVE" : "INACTIVE", 463 (active == GNUNET_YES) ? "ACTIVE" : "INACTIVE",
476 GNUNET_i2s (id), 464 GNUNET_i2s (id),
477 plugin_name, 465 plugin_name,
478 (unsigned int) ntohl (bandwidth_out.value__), 466 (unsigned int) ntohl (bandwidth_out.value__),
479 (unsigned int) ntohl (bandwidth_in.value__)); 467 (unsigned int) ntohl (bandwidth_in.value__));
480 468
481 /* Transmit result */ 469 /* Transmit result (either if address is active, or if
482 if ((GNUNET_YES == ai->all) || (GNUNET_YES == active)) 470 client wanted all addresses) */
471 if ( (GNUNET_YES == ai->all) ||
472 (GNUNET_YES == active))
483 { 473 {
484 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 474 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
485 "Sending result for %s peer `%s' plugin `%s' BW out %u, BW in %u\n", 475 "Sending result for %s peer `%s' plugin `%s' BW out %u, BW in %u\n",
486 (active == GNUNET_YES) ? "ACTIVE" : "INACTIVE", 476 (active == GNUNET_YES) ? "ACTIVE" : "INACTIVE",
487 GNUNET_i2s (id), 477 GNUNET_i2s (id),
488 plugin_name, 478 plugin_name,
@@ -495,34 +485,9 @@ req_addr_peerinfo_it (void *cls,
495 active, 485 active,
496 atsi, 486 atsi,
497 atsi_count, 487 atsi_count,
498 bandwidth_out, bandwidth_in); 488 bandwidth_out,
499 } 489 bandwidth_in);
500}
501
502
503/**
504 * Iterator for GAS_handle_request_address_list
505 *
506 * @param cls the client requesting information, a `struct AddressIteration *`
507 * @param id result
508 */
509static void
510req_addr_peer_it (void *cls,
511 const struct GNUNET_PeerIdentity *id)
512{
513 struct AddressIteration *ai = cls;
514
515 if (NULL == id)
516 {
517 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
518 "Peer iteration done\n");
519 return;
520 } 490 }
521 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
522 "Callback for peer `%s'\n",
523 GNUNET_i2s (id));
524 GAS_addresses_get_peer_info (GSA_addresses, id,
525 &req_addr_peerinfo_it, ai);
526} 491}
527 492
528 493
@@ -540,7 +505,7 @@ GAS_handle_request_address_list (void *cls,
540{ 505{
541 struct PerformanceClient *pc; 506 struct PerformanceClient *pc;
542 struct AddressIteration ai; 507 struct AddressIteration ai;
543 struct AddressListRequestMessage * alrm = (struct AddressListRequestMessage *) message; 508 const struct AddressListRequestMessage *alrm;
544 struct GNUNET_PeerIdentity allzeros; 509 struct GNUNET_PeerIdentity allzeros;
545 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_zero; 510 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_zero;
546 511
@@ -552,7 +517,7 @@ GAS_handle_request_address_list (void *cls,
552 GNUNET_break (0); 517 GNUNET_break (0);
553 return; 518 return;
554 } 519 }
555 520 alrm = (const struct AddressListRequestMessage *) message;
556 ai.all = ntohl (alrm->all); 521 ai.all = ntohl (alrm->all);
557 ai.id = ntohl (alrm->id); 522 ai.id = ntohl (alrm->id);
558 ai.pc = pc; 523 ai.pc = pc;
@@ -564,74 +529,27 @@ GAS_handle_request_address_list (void *cls,
564 sizeof (struct GNUNET_PeerIdentity))) 529 sizeof (struct GNUNET_PeerIdentity)))
565 { 530 {
566 /* Return addresses for all peers */ 531 /* Return addresses for all peers */
567 GAS_addresses_iterate_peers (GSA_addresses, &req_addr_peer_it, &ai); 532 GAS_addresses_get_peer_info (GSA_addresses,
568 transmit_req_addr (&ai, NULL, NULL, NULL, 0, GNUNET_NO, NULL, 0, 533 NULL,
569 bandwidth_zero, bandwidth_zero); 534 &req_addr_peerinfo_it,
535 &ai);
570 } 536 }
571 else 537 else
572 { 538 {
573 /* Return addresses for a specific peer */ 539 /* Return addresses for a specific peer */
574 GAS_addresses_get_peer_info (GSA_addresses, 540 GAS_addresses_get_peer_info (GSA_addresses,
575 &alrm->peer, 541 &alrm->peer,
576 &req_addr_peerinfo_it, &ai); 542 &req_addr_peerinfo_it,
577 transmit_req_addr (&ai, NULL, NULL, NULL, 0, GNUNET_NO, NULL, 0, 543 &ai);
578 bandwidth_zero, bandwidth_zero);
579 }
580 GNUNET_SERVER_receive_done (client, GNUNET_OK);
581}
582
583
584/**
585 * FIXME.
586 */
587void
588GAS_handle_performance_update (struct GNUNET_PeerIdentity *peer,
589 const char *plugin_name,
590 const void *plugin_addr, size_t plugin_addr_len,
591 int active,
592 struct GNUNET_ATS_Information *ats,
593 uint32_t ats_count,
594 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
595 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
596{
597 /* Notify here */
598 GAS_performance_notify_all_clients (peer,
599 plugin_name,
600 plugin_addr,
601 plugin_addr_len,
602 active,
603 ats, ats_count,
604 bandwidth_out,
605 bandwidth_in);
606
607#if 0
608 struct PerformanceClient *cur;
609 struct PerformanceMonitorClient *curm;
610 struct MonitorResponseMessage *mrm;
611 size_t msglen;
612
613 msglen = sizeof (struct MonitorResponseMessage) +
614 ats_count * sizeof (struct GNUNET_ATS_Information);
615 mrm = GNUNET_malloc (msglen);
616
617 mrm->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_MONITOR_RESPONSE);
618 mrm->header.size = htons (msglen);
619 mrm->ats_count = htonl (ats_count);
620 mrm->peer = *peer;
621 memcpy (&mrm[1], ats, ats_count * sizeof (struct GNUNET_ATS_Information));
622
623 for (cur = pc_head; NULL != cur; cur = cur->next)
624 for (curm = cur->pm_head; NULL != curm; curm = curm->next)
625 {
626 /* Notify client about update */
627 mrm->id = htonl (curm->id);
628 GNUNET_SERVER_notification_context_unicast (nc,
629 cur->client,
630 (struct GNUNET_MessageHeader *) mrm,
631 GNUNET_YES);
632 } 544 }
633 GNUNET_free (mrm); 545 transmit_req_addr (&ai,
634#endif 546 NULL, NULL, NULL,
547 0, GNUNET_NO,
548 NULL, 0,
549 bandwidth_zero,
550 bandwidth_zero);
551 GNUNET_SERVER_receive_done (client,
552 GNUNET_OK);
635} 553}
636 554
637 555
diff --git a/src/ats/gnunet-service-ats_performance.h b/src/ats/gnunet-service-ats_performance.h
index e5364e0e5..471b24751 100644
--- a/src/ats/gnunet-service-ats_performance.h
+++ b/src/ats/gnunet-service-ats_performance.h
@@ -53,22 +53,6 @@ GAS_performance_remove_client (struct GNUNET_SERVER_Client *client);
53 53
54 54
55/** 55/**
56 * FIXME.
57 */
58void
59GAS_handle_performance_update (struct GNUNET_PeerIdentity *peer,
60 const char *plugin_name,
61 const void *plugin_addr,
62 size_t plugin_addr_len,
63 int active,
64 struct GNUNET_ATS_Information *ats,
65 uint32_t ats_count,
66 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
67 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in);
68
69
70
71/**
72 * Transmit the given performance information to all performance 56 * Transmit the given performance information to all performance
73 * clients. 57 * clients.
74 * 58 *