aboutsummaryrefslogtreecommitdiff
path: root/src/ats/ats_api_performance.c
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/ats/ats_api_performance.c
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/ats/ats_api_performance.c')
-rw-r--r--src/ats/ats_api_performance.c175
1 files changed, 106 insertions, 69 deletions
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);