diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-03-25 16:06:07 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-03-25 16:06:07 +0000 |
commit | 4596a20eb4c61cf84e3a88a881597ba05114d482 (patch) | |
tree | 4659b0eac3f0d4ee862516e59372c0c568b98ffd /src/ats | |
parent | cc67bae38c54cbaf2122ee3aa0762e7f2cb04edf (diff) | |
download | gnunet-4596a20eb4c61cf84e3a88a881597ba05114d482.tar.gz gnunet-4596a20eb4c61cf84e3a88a881597ba05114d482.zip |
ats api change
Diffstat (limited to 'src/ats')
-rw-r--r-- | src/ats/ats_api_performance.c | 241 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats.c | 3 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_performance.c | 160 | ||||
-rw-r--r-- | src/ats/test_ats_api_performance.c | 74 | ||||
-rw-r--r-- | src/ats/test_ats_api_performance_monitor.c | 21 | ||||
-rw-r--r-- | src/ats/test_ats_simplistic_change_preference.c | 2 | ||||
-rw-r--r-- | src/ats/test_ats_simplistic_pref_aging.c | 2 |
7 files changed, 93 insertions, 410 deletions
diff --git a/src/ats/ats_api_performance.c b/src/ats/ats_api_performance.c index ec0b52fe1..16495b604 100644 --- a/src/ats/ats_api_performance.c +++ b/src/ats/ats_api_performance.c | |||
@@ -159,20 +159,6 @@ struct GNUNET_ATS_AddressListHandle | |||
159 | 159 | ||
160 | 160 | ||
161 | 161 | ||
162 | struct GNUNET_ATS_PerformanceMonitorHandle | ||
163 | { | ||
164 | struct GNUNET_ATS_PerformanceMonitorHandle *next; | ||
165 | struct GNUNET_ATS_PerformanceMonitorHandle *prev; | ||
166 | |||
167 | struct GNUNET_ATS_PerformanceHandle * ph; | ||
168 | |||
169 | GNUNET_ATS_PerformanceMonitorCb moncb; | ||
170 | void *moncb_cls; | ||
171 | |||
172 | uint32_t id; | ||
173 | }; | ||
174 | |||
175 | |||
176 | /** | 162 | /** |
177 | * ATS Handle to obtain and/or modify performance information. | 163 | * ATS Handle to obtain and/or modify performance information. |
178 | */ | 164 | */ |
@@ -185,14 +171,24 @@ struct GNUNET_ATS_PerformanceHandle | |||
185 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 171 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
186 | 172 | ||
187 | /** | 173 | /** |
188 | * Callback to invoke on performance changes. | 174 | * Callback to invoke when an address has performance changes. |
175 | */ | ||
176 | GNUNET_ATS_AddressInformationCallback addr_info_cb; | ||
177 | |||
178 | /** | ||
179 | * Closure for 'addr_info_cb'. | ||
189 | */ | 180 | */ |
190 | GNUNET_ATS_AddressInformationCallback infocb; | 181 | void *addr_info_cb_cls; |
191 | 182 | ||
192 | /** | 183 | /** |
193 | * Closure for 'infocb'. | 184 | * Callback to invoke when a peer has performance changes. |
194 | */ | 185 | */ |
195 | void *infocb_cls; | 186 | GNUNET_ATS_PerformanceMonitorCb perf_monitor_cb; |
187 | |||
188 | /** | ||
189 | * Closure for 'perf_monitor_cb'. | ||
190 | */ | ||
191 | void *perf_monitor_cb_cls; | ||
196 | 192 | ||
197 | /** | 193 | /** |
198 | * Connection to ATS service. | 194 | * Connection to ATS service. |
@@ -229,15 +225,6 @@ struct GNUNET_ATS_PerformanceHandle | |||
229 | */ | 225 | */ |
230 | struct GNUNET_ATS_AddressListHandle *addresslist_tail; | 226 | struct GNUNET_ATS_AddressListHandle *addresslist_tail; |
231 | 227 | ||
232 | /** | ||
233 | * Head of linked list of pending performance monitors. | ||
234 | */ | ||
235 | struct GNUNET_ATS_PerformanceMonitorHandle *monitor_head; | ||
236 | |||
237 | /** | ||
238 | * Tail of linked list of pending performance monitors. | ||
239 | */ | ||
240 | struct GNUNET_ATS_PerformanceMonitorHandle *monitor_tail; | ||
241 | 228 | ||
242 | /** | 229 | /** |
243 | * Current request for transmission to ATS. | 230 | * Current request for transmission to ATS. |
@@ -372,6 +359,7 @@ process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
372 | uint16_t plugin_address_length; | 359 | uint16_t plugin_address_length; |
373 | uint16_t plugin_name_length; | 360 | uint16_t plugin_name_length; |
374 | uint32_t ats_count; | 361 | uint32_t ats_count; |
362 | int addr_active; | ||
375 | 363 | ||
376 | if (ntohs (msg->size) < sizeof (struct PeerInformationMessage)) | 364 | if (ntohs (msg->size) < sizeof (struct PeerInformationMessage)) |
377 | { | 365 | { |
@@ -383,6 +371,7 @@ process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
383 | ats_count = ntohl (pi->ats_count); | 371 | ats_count = ntohl (pi->ats_count); |
384 | plugin_address_length = ntohs (pi->address_length); | 372 | plugin_address_length = ntohs (pi->address_length); |
385 | plugin_name_length = ntohs (pi->plugin_name_length); | 373 | plugin_name_length = ntohs (pi->plugin_name_length); |
374 | addr_active = ntohl (pi->address_active); | ||
386 | atsi = (const struct GNUNET_ATS_Information *) &pi[1]; | 375 | atsi = (const struct GNUNET_ATS_Information *) &pi[1]; |
387 | plugin_address = (const char *) &atsi[ats_count]; | 376 | plugin_address = (const char *) &atsi[ats_count]; |
388 | plugin_name = &plugin_address[plugin_address_length]; | 377 | plugin_name = &plugin_address[plugin_address_length]; |
@@ -396,17 +385,26 @@ process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
396 | GNUNET_break (0); | 385 | GNUNET_break (0); |
397 | return GNUNET_SYSERR; | 386 | return GNUNET_SYSERR; |
398 | } | 387 | } |
399 | if (ph->infocb == NULL) | 388 | |
389 | if (NULL != ph->addr_info_cb) | ||
400 | { | 390 | { |
401 | return GNUNET_OK; | 391 | address.peer = pi->peer; |
402 | } | 392 | address.address = plugin_address; |
393 | address.address_length = plugin_address_length; | ||
394 | address.transport_name = plugin_name; | ||
403 | 395 | ||
404 | address.peer = pi->peer; | 396 | ph->addr_info_cb (ph->addr_info_cb_cls, &address, addr_active, pi->bandwidth_out, pi->bandwidth_in, |
405 | address.address = plugin_address; | ||
406 | address.address_length = plugin_address_length; | ||
407 | address.transport_name = plugin_name; | ||
408 | ph->infocb (ph->infocb_cls, &address, pi->bandwidth_out, pi->bandwidth_in, | ||
409 | atsi, ats_count); | 397 | atsi, ats_count); |
398 | } | ||
399 | if ((NULL != ph->perf_monitor_cb) && | ||
400 | (GNUNET_YES == addr_active)) | ||
401 | { | ||
402 | ph->perf_monitor_cb (ph->perf_monitor_cb_cls, | ||
403 | &pi->peer, | ||
404 | pi->bandwidth_out, | ||
405 | pi->bandwidth_in, | ||
406 | atsi, ats_count); | ||
407 | } | ||
410 | return GNUNET_OK; | 408 | return GNUNET_OK; |
411 | } | 409 | } |
412 | 410 | ||
@@ -539,8 +537,9 @@ process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
539 | _("Received last message for %s \n"), "ATS_ADDRESSLIST_RESPONSE"); | 537 | _("Received last message for %s \n"), "ATS_ADDRESSLIST_RESPONSE"); |
540 | bandwidth_zero.value__ = htonl (0); | 538 | bandwidth_zero.value__ = htonl (0); |
541 | if (NULL != alh->cb) | 539 | if (NULL != alh->cb) |
542 | alh->cb (ph->infocb_cls, | 540 | alh->cb (ph->addr_info_cb_cls, |
543 | NULL, | 541 | NULL, |
542 | GNUNET_NO, | ||
544 | bandwidth_zero, bandwidth_zero, | 543 | bandwidth_zero, bandwidth_zero, |
545 | NULL, 0); | 544 | NULL, 0); |
546 | GNUNET_CONTAINER_DLL_remove (ph->addresslist_head, ph->addresslist_tail, alh); | 545 | GNUNET_CONTAINER_DLL_remove (ph->addresslist_head, ph->addresslist_tail, alh); |
@@ -556,71 +555,15 @@ process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph, | |||
556 | if ((GNUNET_YES == alh->all_addresses) || (GNUNET_YES == active)) | 555 | if ((GNUNET_YES == alh->all_addresses) || (GNUNET_YES == active)) |
557 | { | 556 | { |
558 | if (NULL != alh->cb) | 557 | if (NULL != alh->cb) |
559 | alh->cb (ph->infocb_cls, | 558 | alh->cb (ph->addr_info_cb_cls, |
560 | &address, | 559 | &address, |
560 | active, | ||
561 | pi->bandwidth_out, pi->bandwidth_in, | 561 | pi->bandwidth_out, pi->bandwidth_in, |
562 | atsi, ats_count); | 562 | atsi, ats_count); |
563 | } | 563 | } |
564 | return GNUNET_OK; | 564 | return GNUNET_OK; |
565 | } | 565 | } |
566 | 566 | ||
567 | /** | ||
568 | * We received a monitor response message. Validate and process it. | ||
569 | * | ||
570 | * @param ph our context with the callback | ||
571 | * @param msg the message | ||
572 | * @return GNUNET_OK if the message was well-formed | ||
573 | */ | ||
574 | static int | ||
575 | process_mr_message (struct GNUNET_ATS_PerformanceHandle *ph, | ||
576 | const struct GNUNET_MessageHeader *msg) | ||
577 | { | ||
578 | struct MonitorResponseMessage *mrm = (struct MonitorResponseMessage *) msg; | ||
579 | struct GNUNET_ATS_PerformanceMonitorHandle *cur; | ||
580 | struct GNUNET_ATS_Information *ats; | ||
581 | size_t msg_size; | ||
582 | uint32_t ats_count; | ||
583 | uint32_t id; | ||
584 | |||
585 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
586 | _("Received %s message\n"), "ATS_MONITOR_RESPONSE"); | ||
587 | |||
588 | msg_size = ntohs (msg->size); | ||
589 | if (msg_size < sizeof (struct MonitorResponseMessage)) | ||
590 | { | ||
591 | GNUNET_break (0); | ||
592 | return GNUNET_SYSERR; | ||
593 | } | ||
594 | |||
595 | ats_count = ntohl (mrm->ats_count); | ||
596 | if (msg_size != (sizeof (struct MonitorResponseMessage) + | ||
597 | ats_count * sizeof (struct GNUNET_ATS_Information))) | ||
598 | { | ||
599 | GNUNET_break (0); | ||
600 | return GNUNET_SYSERR; | ||
601 | } | ||
602 | |||
603 | id = ntohl (mrm->id); | ||
604 | /* Do work here */ | ||
605 | for (cur = ph->monitor_head; NULL != cur; cur = cur->next) | ||
606 | { | ||
607 | if (id == cur->id) | ||
608 | break; | ||
609 | } | ||
610 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
611 | _("Received %s message for id %u\n"), "ATS_MONITOR_RESPONSE", id); | ||
612 | if (NULL == cur) | ||
613 | { | ||
614 | GNUNET_break (0); | ||
615 | return GNUNET_SYSERR; | ||
616 | } | ||
617 | |||
618 | ats = (struct GNUNET_ATS_Information *) &mrm[1]; | ||
619 | cur->moncb (cur->moncb_cls, &mrm->peer, ats, ats_count); | ||
620 | |||
621 | return GNUNET_OK; | ||
622 | } | ||
623 | |||
624 | 567 | ||
625 | /** | 568 | /** |
626 | * Type of a function to call when we receive a message | 569 | * Type of a function to call when we receive a message |
@@ -650,10 +593,6 @@ process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg) | |||
650 | if (GNUNET_OK != process_ar_message (ph, msg)) | 593 | if (GNUNET_OK != process_ar_message (ph, msg)) |
651 | goto reconnect; | 594 | goto reconnect; |
652 | break; | 595 | break; |
653 | case GNUNET_MESSAGE_TYPE_ATS_MONITOR_RESPONSE: | ||
654 | if (GNUNET_OK != process_mr_message (ph, msg)) | ||
655 | goto reconnect; | ||
656 | break; | ||
657 | default: | 596 | default: |
658 | GNUNET_break (0); | 597 | GNUNET_break (0); |
659 | goto reconnect; | 598 | goto reconnect; |
@@ -701,9 +640,8 @@ reconnect (struct GNUNET_ATS_PerformanceHandle *ph) | |||
701 | init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START); | 640 | init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START); |
702 | init->header.size = htons (sizeof (struct ClientStartMessage)); | 641 | init->header.size = htons (sizeof (struct ClientStartMessage)); |
703 | init->start_flag = | 642 | init->start_flag = |
704 | htonl ((ph->infocb == | 643 | htonl (((NULL ==ph->addr_info_cb) && (NULL == ph->perf_monitor_cb)) ? |
705 | NULL) ? START_FLAG_PERFORMANCE_NO_PIC : | 644 | START_FLAG_PERFORMANCE_NO_PIC : START_FLAG_PERFORMANCE_WITH_PIC); |
706 | START_FLAG_PERFORMANCE_WITH_PIC); | ||
707 | GNUNET_CONTAINER_DLL_insert (ph->pending_head, ph->pending_tail, p); | 645 | GNUNET_CONTAINER_DLL_insert (ph->pending_head, ph->pending_tail, p); |
708 | } | 646 | } |
709 | do_transmit (ph); | 647 | do_transmit (ph); |
@@ -715,100 +653,34 @@ reconnect (struct GNUNET_ATS_PerformanceHandle *ph) | |||
715 | * Get handle to access performance API of the ATS subsystem. | 653 | * Get handle to access performance API of the ATS subsystem. |
716 | * | 654 | * |
717 | * @param cfg configuration to use | 655 | * @param cfg configuration to use |
718 | * @param infocb function to call on allocation changes, can be NULL | 656 | * @param perf_monitor_cb callback called when performance characteristics for |
719 | * @param infocb_cls closure for infocb | 657 | * a peer change |
658 | * @param perf_monitor_cb closure for the perf_monitor_cb | ||
659 | * @param addr_info_cb callback called when performance characteristics for | ||
660 | * an address change | ||
661 | * @param addr_info_cb_cls closure for infocb | ||
720 | * @return ats performance context | 662 | * @return ats performance context |
721 | */ | 663 | */ |
722 | struct GNUNET_ATS_PerformanceHandle * | 664 | struct GNUNET_ATS_PerformanceHandle * |
723 | GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | 665 | GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg, |
724 | GNUNET_ATS_AddressInformationCallback infocb, | 666 | GNUNET_ATS_PerformanceMonitorCb perf_monitor_cb, |
725 | void *infocb_cls) | 667 | void *perf_monitor_cb_cls, |
668 | GNUNET_ATS_AddressInformationCallback addr_info_cb, | ||
669 | void *addr_info_cb_cls) | ||
726 | { | 670 | { |
727 | struct GNUNET_ATS_PerformanceHandle *ph; | 671 | struct GNUNET_ATS_PerformanceHandle *ph; |
728 | 672 | ||
729 | ph = GNUNET_malloc (sizeof (struct GNUNET_ATS_PerformanceHandle)); | 673 | ph = GNUNET_malloc (sizeof (struct GNUNET_ATS_PerformanceHandle)); |
730 | ph->cfg = cfg; | 674 | ph->cfg = cfg; |
731 | ph->infocb = infocb; | 675 | ph->addr_info_cb = addr_info_cb; |
732 | ph->infocb_cls = infocb_cls; | 676 | ph->addr_info_cb_cls = addr_info_cb_cls; |
677 | ph->perf_monitor_cb = perf_monitor_cb; | ||
678 | ph->perf_monitor_cb_cls = perf_monitor_cb_cls; | ||
733 | ph->id = 0; | 679 | ph->id = 0; |
734 | reconnect (ph); | 680 | reconnect (ph); |
735 | return ph; | 681 | return ph; |
736 | } | 682 | } |
737 | 683 | ||
738 | |||
739 | /** | ||
740 | * Start monitoring performance information | ||
741 | * | ||
742 | * @param ph performance handle to use | ||
743 | * @param monitor_cb function to call on performance changes | ||
744 | * @param monitor_cb_cls closure for infocb | ||
745 | * @return a performance monitor handle | ||
746 | */ | ||
747 | struct GNUNET_ATS_PerformanceMonitorHandle * | ||
748 | GNUNET_ATS_performance_monitor_start (struct GNUNET_ATS_PerformanceHandle * ph, | ||
749 | GNUNET_ATS_PerformanceMonitorCb monitor_cb, | ||
750 | void * monitor_cb_cls) | ||
751 | { | ||
752 | struct MonitorMessage *m; | ||
753 | struct PendingMessage *p; | ||
754 | GNUNET_assert (NULL != ph); | ||
755 | |||
756 | if (NULL == monitor_cb) | ||
757 | return NULL; | ||
758 | |||
759 | struct GNUNET_ATS_PerformanceMonitorHandle *phm = | ||
760 | GNUNET_malloc (sizeof (struct GNUNET_ATS_PerformanceMonitorHandle)); | ||
761 | |||
762 | ph->monitor_id ++; | ||
763 | phm->id = ph->monitor_id; | ||
764 | phm->ph = ph; | ||
765 | phm->moncb = monitor_cb; | ||
766 | phm->moncb_cls = monitor_cb_cls; | ||
767 | GNUNET_CONTAINER_DLL_insert (ph->monitor_head, ph->monitor_tail, phm); | ||
768 | |||
769 | p = GNUNET_malloc (sizeof (struct PendingMessage) + | ||
770 | sizeof (struct MonitorMessage)); | ||
771 | p->size = sizeof (struct MonitorMessage); | ||
772 | m = (struct MonitorMessage *) &p[1]; | ||
773 | m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_MONITOR); | ||
774 | m->header.size = htons (sizeof (struct MonitorMessage)); | ||
775 | m->id = htonl (phm->id); | ||
776 | m->op = htonl (GNUNET_YES); | ||
777 | GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head, ph->pending_tail, p); | ||
778 | do_transmit (ph); | ||
779 | |||
780 | return phm; | ||
781 | } | ||
782 | |||
783 | |||
784 | /** | ||
785 | * Stop monitoring performance information | ||
786 | * | ||
787 | * @param phm performance monitor handle to use | ||
788 | */ | ||
789 | void | ||
790 | GNUNET_ATS_performance_monitor_stop (struct GNUNET_ATS_PerformanceMonitorHandle * phm) | ||
791 | { | ||
792 | struct MonitorMessage *m; | ||
793 | struct PendingMessage *p; | ||
794 | |||
795 | GNUNET_assert (NULL != phm); | ||
796 | |||
797 | p = GNUNET_malloc (sizeof (struct PendingMessage) + | ||
798 | sizeof (struct MonitorMessage)); | ||
799 | p->size = sizeof (struct MonitorMessage); | ||
800 | m = (struct MonitorMessage *) &p[1]; | ||
801 | m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_MONITOR); | ||
802 | m->header.size = htons (sizeof (struct MonitorMessage)); | ||
803 | m->id = htonl (phm->id); | ||
804 | m->op = htonl (GNUNET_NO); | ||
805 | GNUNET_CONTAINER_DLL_insert_tail (phm->ph->pending_head, phm->ph->pending_tail, p); | ||
806 | do_transmit (phm->ph); | ||
807 | |||
808 | GNUNET_CONTAINER_DLL_remove (phm->ph->monitor_head, phm->ph->monitor_tail, phm); | ||
809 | GNUNET_free (phm); | ||
810 | } | ||
811 | |||
812 | /** | 684 | /** |
813 | * Client is done using the ATS performance subsystem, release resources. | 685 | * Client is done using the ATS performance subsystem, release resources. |
814 | * | 686 | * |
@@ -820,7 +692,6 @@ GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph) | |||
820 | struct PendingMessage *p; | 692 | struct PendingMessage *p; |
821 | struct GNUNET_ATS_ReservationContext *rc; | 693 | struct GNUNET_ATS_ReservationContext *rc; |
822 | struct GNUNET_ATS_AddressListHandle *alh; | 694 | struct GNUNET_ATS_AddressListHandle *alh; |
823 | struct GNUNET_ATS_PerformanceMonitorHandle *phm; | ||
824 | 695 | ||
825 | while (NULL != (p = ph->pending_head)) | 696 | while (NULL != (p = ph->pending_head)) |
826 | { | 697 | { |
@@ -840,11 +711,7 @@ GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph) | |||
840 | GNUNET_break (NULL == rc->rcb); | 711 | GNUNET_break (NULL == rc->rcb); |
841 | GNUNET_free (rc); | 712 | GNUNET_free (rc); |
842 | } | 713 | } |
843 | while (NULL != (phm = ph->monitor_head)) | 714 | |
844 | { | ||
845 | GNUNET_CONTAINER_DLL_remove (ph->monitor_head, ph->monitor_tail, phm); | ||
846 | GNUNET_free (phm); | ||
847 | } | ||
848 | if (GNUNET_SCHEDULER_NO_TASK != ph->task) | 715 | if (GNUNET_SCHEDULER_NO_TASK != ph->task) |
849 | { | 716 | { |
850 | GNUNET_SCHEDULER_cancel (ph->task); | 717 | GNUNET_SCHEDULER_cancel (ph->task); |
diff --git a/src/ats/gnunet-service-ats.c b/src/ats/gnunet-service-ats.c index 12693f212..3218769a6 100644 --- a/src/ats/gnunet-service-ats.c +++ b/src/ats/gnunet-service-ats.c | |||
@@ -162,9 +162,6 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
162 | {&GAS_handle_reset_backoff, NULL, | 162 | {&GAS_handle_reset_backoff, NULL, |
163 | GNUNET_MESSAGE_TYPE_ATS_RESET_BACKOFF, | 163 | GNUNET_MESSAGE_TYPE_ATS_RESET_BACKOFF, |
164 | sizeof (struct ResetBackoffMessage)}, | 164 | sizeof (struct ResetBackoffMessage)}, |
165 | {&GAS_handle_monitor, NULL, | ||
166 | GNUNET_MESSAGE_TYPE_ATS_MONITOR, | ||
167 | sizeof (struct MonitorMessage)}, | ||
168 | {NULL, NULL, 0, 0} | 165 | {NULL, NULL, 0, 0} |
169 | }; | 166 | }; |
170 | GSA_server = server; | 167 | GSA_server = server; |
diff --git a/src/ats/gnunet-service-ats_performance.c b/src/ats/gnunet-service-ats_performance.c index 3be0bf0bf..8eb969dfd 100644 --- a/src/ats/gnunet-service-ats_performance.c +++ b/src/ats/gnunet-service-ats_performance.c | |||
@@ -31,16 +31,6 @@ | |||
31 | #include "gnunet-service-ats_reservations.h" | 31 | #include "gnunet-service-ats_reservations.h" |
32 | #include "ats.h" | 32 | #include "ats.h" |
33 | 33 | ||
34 | struct PerformanceMonitorClient | ||
35 | { | ||
36 | struct PerformanceMonitorClient *next; | ||
37 | struct PerformanceMonitorClient *prev; | ||
38 | |||
39 | struct GNUNET_SERVER_Client *client; | ||
40 | |||
41 | uint32_t id; | ||
42 | }; | ||
43 | |||
44 | /** | 34 | /** |
45 | * We keep clients that are interested in performance in a linked list. | 35 | * We keep clients that are interested in performance in a linked list. |
46 | */ | 36 | */ |
@@ -138,18 +128,9 @@ void | |||
138 | GAS_performance_remove_client (struct GNUNET_SERVER_Client *client) | 128 | GAS_performance_remove_client (struct GNUNET_SERVER_Client *client) |
139 | { | 129 | { |
140 | struct PerformanceClient *pc; | 130 | struct PerformanceClient *pc; |
141 | struct PerformanceMonitorClient *cur; | ||
142 | struct PerformanceMonitorClient *next; | ||
143 | pc = find_client (client); | 131 | pc = find_client (client); |
144 | if (NULL == pc) | 132 | if (NULL == pc) |
145 | return; | 133 | return; |
146 | next = pc->pm_head; | ||
147 | while (NULL != (cur = next)) | ||
148 | { | ||
149 | next = cur->next; | ||
150 | GNUNET_CONTAINER_DLL_remove (pc->pm_head, pc->pm_tail, cur); | ||
151 | GNUNET_free (cur); | ||
152 | } | ||
153 | GNUNET_CONTAINER_DLL_remove (pc_head, pc_tail, pc); | 134 | GNUNET_CONTAINER_DLL_remove (pc_head, pc_tail, pc); |
154 | GNUNET_SERVER_client_drop (client); | 135 | GNUNET_SERVER_client_drop (client); |
155 | GNUNET_free (pc); | 136 | GNUNET_free (pc); |
@@ -293,7 +274,9 @@ peerinfo_it (void *cls, | |||
293 | ntohl (bandwidth_in.value__)); | 274 | ntohl (bandwidth_in.value__)); |
294 | GAS_performance_notify_client(pc, | 275 | GAS_performance_notify_client(pc, |
295 | id, | 276 | id, |
296 | plugin_name, plugin_addr, plugin_addr_len, | 277 | plugin_name, |
278 | plugin_addr, | ||
279 | plugin_addr_len, | ||
297 | active, | 280 | active, |
298 | atsi, atsi_count, | 281 | atsi, atsi_count, |
299 | bandwidth_out, bandwidth_in); | 282 | bandwidth_out, bandwidth_in); |
@@ -529,6 +512,9 @@ GAS_handle_performance_update (struct GNUNET_PeerIdentity *peer, | |||
529 | struct GNUNET_ATS_Information *ats, | 512 | struct GNUNET_ATS_Information *ats, |
530 | uint32_t ats_count) | 513 | uint32_t ats_count) |
531 | { | 514 | { |
515 | /* Notify here */ | ||
516 | |||
517 | #if 0 | ||
532 | struct PerformanceClient *cur; | 518 | struct PerformanceClient *cur; |
533 | struct PerformanceMonitorClient *curm; | 519 | struct PerformanceMonitorClient *curm; |
534 | struct MonitorResponseMessage *mrm; | 520 | struct MonitorResponseMessage *mrm; |
@@ -555,139 +541,7 @@ GAS_handle_performance_update (struct GNUNET_PeerIdentity *peer, | |||
555 | GNUNET_YES); | 541 | GNUNET_YES); |
556 | } | 542 | } |
557 | GNUNET_free (mrm); | 543 | GNUNET_free (mrm); |
558 | } | 544 | #endif |
559 | |||
560 | |||
561 | static void | ||
562 | mon_peerinfo_it (void *cls, | ||
563 | const struct GNUNET_PeerIdentity *id, | ||
564 | const char *plugin_name, | ||
565 | const void *plugin_addr, size_t plugin_addr_len, | ||
566 | const int active, | ||
567 | const struct GNUNET_ATS_Information *atsi, | ||
568 | uint32_t atsi_count, | ||
569 | struct GNUNET_BANDWIDTH_Value32NBO | ||
570 | bandwidth_out, | ||
571 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | ||
572 | { | ||
573 | struct PerformanceMonitorClient *pmc = cls; | ||
574 | struct MonitorResponseMessage *mrm; | ||
575 | size_t msglen; | ||
576 | |||
577 | if (NULL == id) | ||
578 | return; /* last callback */ | ||
579 | |||
580 | msglen = sizeof (struct MonitorResponseMessage) + | ||
581 | atsi_count * sizeof (struct GNUNET_ATS_Information); | ||
582 | mrm = GNUNET_malloc (msglen); | ||
583 | |||
584 | mrm->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_MONITOR_RESPONSE); | ||
585 | mrm->header.size = htons (msglen); | ||
586 | mrm->id = htonl(pmc->id); | ||
587 | mrm->ats_count = htonl (atsi_count); | ||
588 | mrm->peer = *id; | ||
589 | memcpy (&mrm[1], atsi, atsi_count * sizeof (struct GNUNET_ATS_Information)); | ||
590 | |||
591 | /* Send initial information about peers to client */ | ||
592 | |||
593 | GNUNET_SERVER_notification_context_unicast (nc, | ||
594 | pmc->client, | ||
595 | (struct GNUNET_MessageHeader *) mrm, | ||
596 | GNUNET_YES); | ||
597 | GNUNET_free (mrm); | ||
598 | } | ||
599 | |||
600 | /** | ||
601 | * Iterator for GAS_handle_monitor | ||
602 | * | ||
603 | * @param cls the performance monitoring client requesting information | ||
604 | * @param id result | ||
605 | */ | ||
606 | static void | ||
607 | mon_peer_it (void *cls, | ||
608 | const struct GNUNET_PeerIdentity *id) | ||
609 | { | ||
610 | struct PerformanceMonitorClient *pmc = cls; | ||
611 | if (NULL != id) | ||
612 | GAS_addresses_get_peer_info (GSA_addresses, id, &mon_peerinfo_it, pmc); | ||
613 | } | ||
614 | |||
615 | |||
616 | void | ||
617 | GAS_handle_monitor (void *cls, | ||
618 | struct GNUNET_SERVER_Client *client, | ||
619 | const struct GNUNET_MessageHeader *message) | ||
620 | { | ||
621 | struct PerformanceClient *pc; | ||
622 | struct PerformanceMonitorClient *pmc; | ||
623 | struct MonitorMessage *mm = (struct MonitorMessage *) message; | ||
624 | size_t msg_size; | ||
625 | uint32_t id; | ||
626 | uint32_t op; | ||
627 | |||
628 | pc = find_client (client); | ||
629 | if (NULL == pc) | ||
630 | { | ||
631 | GNUNET_break (0); | ||
632 | return; | ||
633 | } | ||
634 | |||
635 | msg_size = ntohs (message->size); | ||
636 | if (msg_size < sizeof (struct MonitorMessage)) | ||
637 | { | ||
638 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
639 | return; | ||
640 | } | ||
641 | |||
642 | id = ntohl (mm->id); | ||
643 | op = ntohl (mm->op); | ||
644 | |||
645 | for (pmc = pc->pm_head; NULL != pmc; pmc = pmc->next) | ||
646 | if ((pmc->id == id) && (client == pmc->client)) | ||
647 | break; | ||
648 | |||
649 | if (GNUNET_YES == op) | ||
650 | { | ||
651 | /* Start monitoring */ | ||
652 | if (NULL != pmc) | ||
653 | { | ||
654 | GNUNET_break (0); | ||
655 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
656 | return; /* Duplicate*/ | ||
657 | } | ||
658 | pmc = GNUNET_malloc (sizeof (struct PerformanceMonitorClient)); | ||
659 | pmc->client = client; | ||
660 | pmc->id = id; | ||
661 | GNUNET_CONTAINER_DLL_insert (pc->pm_head, pc->pm_tail, pmc); | ||
662 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
663 | "Added performance monitoring client %p id %u\n", | ||
664 | client, id); | ||
665 | /* Return all values here */ | ||
666 | GAS_addresses_iterate_peers (GSA_addresses, &mon_peer_it, pmc); | ||
667 | |||
668 | } | ||
669 | else if (GNUNET_NO == op) | ||
670 | { | ||
671 | /* Stop monitoring */ | ||
672 | if (NULL == pmc) | ||
673 | { | ||
674 | GNUNET_break (0); | ||
675 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
676 | return; /* Not existing */ | ||
677 | } | ||
678 | GNUNET_CONTAINER_DLL_remove (pc->pm_head, pc->pm_tail, pmc); | ||
679 | GNUNET_free (pmc); | ||
680 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
681 | "Removed performance monitoring client %p id %u\n", | ||
682 | client, id); | ||
683 | } | ||
684 | else | ||
685 | { | ||
686 | GNUNET_break (0); | ||
687 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
688 | return; | ||
689 | } | ||
690 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
691 | } | 545 | } |
692 | 546 | ||
693 | 547 | ||
diff --git a/src/ats/test_ats_api_performance.c b/src/ats/test_ats_api_performance.c index 64737d8ba..a49b33de1 100644 --- a/src/ats/test_ats_api_performance.c +++ b/src/ats/test_ats_api_performance.c | |||
@@ -129,18 +129,12 @@ static void | |||
129 | test_performance_api (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 129 | test_performance_api (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
130 | 130 | ||
131 | void all_active_addresses_peer_cb (void *cls, | 131 | void all_active_addresses_peer_cb (void *cls, |
132 | const struct | 132 | const struct GNUNET_HELLO_Address *address, |
133 | GNUNET_HELLO_Address * | 133 | unsigned int active, |
134 | address, | 134 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
135 | struct | 135 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, |
136 | GNUNET_BANDWIDTH_Value32NBO | 136 | const struct GNUNET_ATS_Information *ats, |
137 | bandwidth_out, | 137 | uint32_t ats_count) |
138 | struct | ||
139 | GNUNET_BANDWIDTH_Value32NBO | ||
140 | bandwidth_in, | ||
141 | const struct | ||
142 | GNUNET_ATS_Information * | ||
143 | ats, uint32_t ats_count) | ||
144 | { | 138 | { |
145 | static int cb = 0; | 139 | static int cb = 0; |
146 | int fail = GNUNET_NO; | 140 | int fail = GNUNET_NO; |
@@ -198,18 +192,12 @@ void all_active_addresses_peer_cb (void *cls, | |||
198 | } | 192 | } |
199 | 193 | ||
200 | void all_active_addresses_cb (void *cls, | 194 | void all_active_addresses_cb (void *cls, |
201 | const struct | 195 | const struct GNUNET_HELLO_Address *address, |
202 | GNUNET_HELLO_Address * | 196 | unsigned int active, |
203 | address, | 197 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
204 | struct | 198 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, |
205 | GNUNET_BANDWIDTH_Value32NBO | 199 | const struct GNUNET_ATS_Information *ats, |
206 | bandwidth_out, | 200 | uint32_t ats_count) |
207 | struct | ||
208 | GNUNET_BANDWIDTH_Value32NBO | ||
209 | bandwidth_in, | ||
210 | const struct | ||
211 | GNUNET_ATS_Information * | ||
212 | ats, uint32_t ats_count) | ||
213 | { | 201 | { |
214 | static int cb = 0; | 202 | static int cb = 0; |
215 | int fail = GNUNET_NO; | 203 | int fail = GNUNET_NO; |
@@ -279,18 +267,12 @@ void all_active_addresses_cb (void *cls, | |||
279 | 267 | ||
280 | 268 | ||
281 | void all_addresses_peer_cb (void *cls, | 269 | void all_addresses_peer_cb (void *cls, |
282 | const struct | 270 | const struct GNUNET_HELLO_Address *address, |
283 | GNUNET_HELLO_Address * | 271 | unsigned int active, |
284 | address, | 272 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
285 | struct | 273 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, |
286 | GNUNET_BANDWIDTH_Value32NBO | 274 | const struct GNUNET_ATS_Information *ats, |
287 | bandwidth_out, | 275 | uint32_t ats_count) |
288 | struct | ||
289 | GNUNET_BANDWIDTH_Value32NBO | ||
290 | bandwidth_in, | ||
291 | const struct | ||
292 | GNUNET_ATS_Information * | ||
293 | ats, uint32_t ats_count) | ||
294 | { | 276 | { |
295 | static int cb = 0; | 277 | static int cb = 0; |
296 | int fail = GNUNET_NO; | 278 | int fail = GNUNET_NO; |
@@ -334,18 +316,12 @@ void all_addresses_peer_cb (void *cls, | |||
334 | } | 316 | } |
335 | 317 | ||
336 | void all_addresses_cb (void *cls, | 318 | void all_addresses_cb (void *cls, |
337 | const struct | 319 | const struct GNUNET_HELLO_Address *address, |
338 | GNUNET_HELLO_Address * | 320 | unsigned int active, |
339 | address, | 321 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
340 | struct | 322 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, |
341 | GNUNET_BANDWIDTH_Value32NBO | 323 | const struct GNUNET_ATS_Information *ats, |
342 | bandwidth_out, | 324 | uint32_t ats_count) |
343 | struct | ||
344 | GNUNET_BANDWIDTH_Value32NBO | ||
345 | bandwidth_in, | ||
346 | const struct | ||
347 | GNUNET_ATS_Information * | ||
348 | ats, uint32_t ats_count) | ||
349 | { | 325 | { |
350 | static int cb = 0; | 326 | static int cb = 0; |
351 | 327 | ||
@@ -404,7 +380,7 @@ static void | |||
404 | test_performance_api (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 380 | test_performance_api (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
405 | { | 381 | { |
406 | if (NULL == ph) | 382 | if (NULL == ph) |
407 | ph = GNUNET_ATS_performance_init (cfg, NULL, NULL); | 383 | ph = GNUNET_ATS_performance_init (cfg, NULL, NULL, NULL, NULL); |
408 | if (NULL == ph) | 384 | if (NULL == ph) |
409 | { | 385 | { |
410 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to initialize performance handle\n"); | 386 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to initialize performance handle\n"); |
diff --git a/src/ats/test_ats_api_performance_monitor.c b/src/ats/test_ats_api_performance_monitor.c index 44159aa09..9682b8dc9 100644 --- a/src/ats/test_ats_api_performance_monitor.c +++ b/src/ats/test_ats_api_performance_monitor.c | |||
@@ -42,8 +42,6 @@ static struct GNUNET_ATS_SchedulingHandle *sh; | |||
42 | 42 | ||
43 | static struct GNUNET_ATS_PerformanceHandle *ph; | 43 | static struct GNUNET_ATS_PerformanceHandle *ph; |
44 | 44 | ||
45 | static struct GNUNET_ATS_PerformanceMonitorHandle *phm; | ||
46 | |||
47 | static struct GNUNET_HELLO_Address addr; | 45 | static struct GNUNET_HELLO_Address addr; |
48 | 46 | ||
49 | static struct GNUNET_ATS_Information atsi[ATS_COUNT]; | 47 | static struct GNUNET_ATS_Information atsi[ATS_COUNT]; |
@@ -91,12 +89,6 @@ end_now (int res) | |||
91 | 89 | ||
92 | cleanup_addresses (); | 90 | cleanup_addresses (); |
93 | 91 | ||
94 | if (NULL != phm) | ||
95 | { | ||
96 | GNUNET_ATS_performance_monitor_stop (phm); | ||
97 | phm = NULL; | ||
98 | } | ||
99 | |||
100 | if (NULL != ph) | 92 | if (NULL != ph) |
101 | { | 93 | { |
102 | GNUNET_ATS_performance_done (ph); | 94 | GNUNET_ATS_performance_done (ph); |
@@ -129,9 +121,6 @@ next_stage (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
129 | { | 121 | { |
130 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stop performance monitoring\n"); | 122 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stop performance monitoring\n"); |
131 | 123 | ||
132 | GNUNET_ATS_performance_monitor_stop (phm); | ||
133 | phm = NULL; | ||
134 | |||
135 | stage_task = GNUNET_SCHEDULER_add_delayed (SHUTDOWN_CORRECT, &next_stage, NULL); | 124 | stage_task = GNUNET_SCHEDULER_add_delayed (SHUTDOWN_CORRECT, &next_stage, NULL); |
136 | stage_counter++; | 125 | stage_counter++; |
137 | return; | 126 | return; |
@@ -151,8 +140,10 @@ static void end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
151 | 140 | ||
152 | static void | 141 | static void |
153 | perf_mon_cb (void *cls, | 142 | perf_mon_cb (void *cls, |
154 | struct GNUNET_PeerIdentity *peer, | 143 | const struct GNUNET_PeerIdentity *peer, |
155 | struct GNUNET_ATS_Information *ats, | 144 | const struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
145 | const struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | ||
146 | const struct GNUNET_ATS_Information *ats, | ||
156 | uint32_t ats_count) | 147 | uint32_t ats_count) |
157 | { | 148 | { |
158 | static int stage_counter = 0; | 149 | static int stage_counter = 0; |
@@ -273,11 +264,9 @@ run (void *cls, | |||
273 | 264 | ||
274 | setup_addresses (); | 265 | setup_addresses (); |
275 | 266 | ||
276 | ph = GNUNET_ATS_performance_init (cfg, NULL, NULL); | 267 | ph = GNUNET_ATS_performance_init (cfg, &perf_mon_cb, &ret, NULL, NULL); |
277 | GNUNET_assert (NULL != ph); | 268 | GNUNET_assert (NULL != ph); |
278 | 269 | ||
279 | phm = GNUNET_ATS_performance_monitor_start (ph, &perf_mon_cb, &ret); | ||
280 | GNUNET_assert (NULL != phm); | ||
281 | 270 | ||
282 | stage_task = GNUNET_SCHEDULER_add_delayed (SHUTDOWN_CORRECT, &next_stage, NULL); | 271 | stage_task = GNUNET_SCHEDULER_add_delayed (SHUTDOWN_CORRECT, &next_stage, NULL); |
283 | } | 272 | } |
diff --git a/src/ats/test_ats_simplistic_change_preference.c b/src/ats/test_ats_simplistic_change_preference.c index 793d0cb4b..0cf22fb3c 100644 --- a/src/ats/test_ats_simplistic_change_preference.c +++ b/src/ats/test_ats_simplistic_change_preference.c | |||
@@ -318,7 +318,7 @@ run (void *cls, | |||
318 | return; | 318 | return; |
319 | } | 319 | } |
320 | 320 | ||
321 | perf_ats = GNUNET_ATS_performance_init (cfg, NULL, NULL); | 321 | perf_ats = GNUNET_ATS_performance_init (cfg, NULL, NULL, NULL, NULL); |
322 | if (perf_ats == NULL) | 322 | if (perf_ats == NULL) |
323 | { | 323 | { |
324 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS performance!\n"); | 324 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS performance!\n"); |
diff --git a/src/ats/test_ats_simplistic_pref_aging.c b/src/ats/test_ats_simplistic_pref_aging.c index 2681b87f5..14b45f91c 100644 --- a/src/ats/test_ats_simplistic_pref_aging.c +++ b/src/ats/test_ats_simplistic_pref_aging.c | |||
@@ -368,7 +368,7 @@ run (void *cls, | |||
368 | } | 368 | } |
369 | 369 | ||
370 | /* Connect to ATS performance */ | 370 | /* Connect to ATS performance */ |
371 | perf_ats = GNUNET_ATS_performance_init(cfg, NULL, NULL); | 371 | perf_ats = GNUNET_ATS_performance_init(cfg, NULL, NULL, NULL, NULL); |
372 | if (sched_ats == NULL) | 372 | if (sched_ats == NULL) |
373 | { | 373 | { |
374 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n"); | 374 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n"); |