aboutsummaryrefslogtreecommitdiff
path: root/src/ats/ats_api_performance.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-03-25 16:06:07 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-03-25 16:06:07 +0000
commit4596a20eb4c61cf84e3a88a881597ba05114d482 (patch)
tree4659b0eac3f0d4ee862516e59372c0c568b98ffd /src/ats/ats_api_performance.c
parentcc67bae38c54cbaf2122ee3aa0762e7f2cb04edf (diff)
downloadgnunet-4596a20eb4c61cf84e3a88a881597ba05114d482.tar.gz
gnunet-4596a20eb4c61cf84e3a88a881597ba05114d482.zip
ats api change
Diffstat (limited to 'src/ats/ats_api_performance.c')
-rw-r--r--src/ats/ats_api_performance.c241
1 files changed, 54 insertions, 187 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
162struct 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 */
574static int
575process_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 */
722struct GNUNET_ATS_PerformanceHandle * 664struct GNUNET_ATS_PerformanceHandle *
723GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg, 665GNUNET_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 */
747struct GNUNET_ATS_PerformanceMonitorHandle *
748GNUNET_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 */
789void
790GNUNET_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);