aboutsummaryrefslogtreecommitdiff
path: root/src/ats/ats_api_performance.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-03-19 11:01:46 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-03-19 11:01:46 +0000
commitefb6bbbe66d5620ed29951cfd1c7a2d8582f1640 (patch)
treeeeea915f020f6b4aed33a411b0260f9d4adbbfca /src/ats/ats_api_performance.c
parent66c49d17094d8a6c80fe1880a8339f10493f23ee (diff)
downloadgnunet-efb6bbbe66d5620ed29951cfd1c7a2d8582f1640.tar.gz
gnunet-efb6bbbe66d5620ed29951cfd1c7a2d8582f1640.zip
pre lunch commit
Diffstat (limited to 'src/ats/ats_api_performance.c')
-rw-r--r--src/ats/ats_api_performance.c116
1 files changed, 106 insertions, 10 deletions
diff --git a/src/ats/ats_api_performance.c b/src/ats/ats_api_performance.c
index fc2d6647e..f29cced6c 100644
--- a/src/ats/ats_api_performance.c
+++ b/src/ats/ats_api_performance.c
@@ -157,6 +157,22 @@ struct GNUNET_ATS_AddressListHandle
157 uint32_t id; 157 uint32_t id;
158}; 158};
159 159
160
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
160/** 176/**
161 * ATS Handle to obtain and/or modify performance information. 177 * ATS Handle to obtain and/or modify performance information.
162 */ 178 */
@@ -234,6 +250,11 @@ struct GNUNET_ATS_PerformanceHandle
234 GNUNET_SCHEDULER_TaskIdentifier task; 250 GNUNET_SCHEDULER_TaskIdentifier task;
235 251
236 /** 252 /**
253 * Monitor request multiplexing
254 */
255 uint32_t monitor_id;
256
257 /**
237 * Request multiplexing 258 * Request multiplexing
238 */ 259 */
239 uint32_t id; 260 uint32_t id;
@@ -543,6 +564,50 @@ process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph,
543 return GNUNET_OK; 564 return GNUNET_OK;
544} 565}
545 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 msg_size = ntohs (msg->size);
586 if (msg_size < sizeof (struct MonitorResponseMessage))
587 return GNUNET_SYSERR;
588
589 ats_count = ntohl (mrm->ats_count);
590 if (msg_size != (sizeof (struct MonitorResponseMessage) +
591 ats_count * sizeof (struct GNUNET_ATS_Information)))
592 return GNUNET_SYSERR;
593
594 id = ntohl (mrm->id);
595 /* Do work here */
596 for (cur = ph->monitor_head; NULL != cur; cur = cur->next)
597 {
598 if (id == cur->id)
599 break;
600 }
601
602 if (NULL == cur)
603 return GNUNET_SYSERR;
604
605 ats = (struct GNUNET_ATS_Information *) &mrm[1];
606 cur->moncb (cur->moncb_cls, &mrm->peer, ats, ats_count);
607
608 return GNUNET_OK;
609}
610
546 611
547/** 612/**
548 * Type of a function to call when we receive a message 613 * Type of a function to call when we receive a message
@@ -572,6 +637,10 @@ process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg)
572 if (GNUNET_OK != process_ar_message (ph, msg)) 637 if (GNUNET_OK != process_ar_message (ph, msg))
573 goto reconnect; 638 goto reconnect;
574 break; 639 break;
640 case GNUNET_MESSAGE_TYPE_ATS_MONITOR_RESPONSE:
641 if (GNUNET_OK != process_mr_message (ph, msg))
642 goto reconnect;
643 break;
575 default: 644 default:
576 GNUNET_break (0); 645 GNUNET_break (0);
577 goto reconnect; 646 goto reconnect;
@@ -653,16 +722,6 @@ GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
653 return ph; 722 return ph;
654} 723}
655 724
656struct GNUNET_ATS_PerformanceMonitorHandle
657{
658 struct GNUNET_ATS_PerformanceMonitorHandle *next;
659 struct GNUNET_ATS_PerformanceMonitorHandle *prev;
660
661 struct GNUNET_ATS_PerformanceHandle * ph;
662
663 GNUNET_ATS_PerformanceMonitorCb moncb;
664 void *moncb_cls;
665};
666 725
667/** 726/**
668 * Start monitoring performance information 727 * Start monitoring performance information
@@ -677,16 +736,31 @@ GNUNET_ATS_performance_monitor_start (struct GNUNET_ATS_PerformanceHandle * ph,
677 GNUNET_ATS_PerformanceMonitorCb monitor_cb, 736 GNUNET_ATS_PerformanceMonitorCb monitor_cb,
678 void * monitor_cb_cls) 737 void * monitor_cb_cls)
679{ 738{
739 struct MonitorMessage *m;
740 struct PendingMessage *p;
680 GNUNET_assert (NULL != ph); 741 GNUNET_assert (NULL != ph);
681 742
682 struct GNUNET_ATS_PerformanceMonitorHandle *phm = 743 struct GNUNET_ATS_PerformanceMonitorHandle *phm =
683 GNUNET_malloc (sizeof (struct GNUNET_ATS_PerformanceMonitorHandle)); 744 GNUNET_malloc (sizeof (struct GNUNET_ATS_PerformanceMonitorHandle));
684 745
746 ph->monitor_id ++;
747 phm->id = ph->monitor_id;
685 phm->ph = ph; 748 phm->ph = ph;
686 phm->moncb = monitor_cb; 749 phm->moncb = monitor_cb;
687 phm->moncb_cls = monitor_cb_cls; 750 phm->moncb_cls = monitor_cb_cls;
688 GNUNET_CONTAINER_DLL_insert (ph->monitor_head, ph->monitor_tail, phm); 751 GNUNET_CONTAINER_DLL_insert (ph->monitor_head, ph->monitor_tail, phm);
689 752
753 p = GNUNET_malloc (sizeof (struct PendingMessage) +
754 sizeof (struct MonitorMessage));
755 p->size = sizeof (struct MonitorMessage);
756 m = (struct MonitorMessage *) &p[1];
757 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_MONITOR);
758 m->header.size = htons (sizeof (struct MonitorMessage));
759 m->id = htonl (phm->id);
760 m->op = htonl (GNUNET_YES);
761 GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head, ph->pending_tail, p);
762 do_transmit (ph);
763
690 return phm; 764 return phm;
691} 765}
692 766
@@ -702,6 +776,22 @@ GNUNET_ATS_performance_monitor_start (struct GNUNET_ATS_PerformanceHandle * ph,
702void 776void
703GNUNET_ATS_performance_monitor_stop (struct GNUNET_ATS_PerformanceMonitorHandle * phm) 777GNUNET_ATS_performance_monitor_stop (struct GNUNET_ATS_PerformanceMonitorHandle * phm)
704{ 778{
779 struct MonitorMessage *m;
780 struct PendingMessage *p;
781
782 GNUNET_assert (NULL != phm);
783
784 p = GNUNET_malloc (sizeof (struct PendingMessage) +
785 sizeof (struct MonitorMessage));
786 p->size = sizeof (struct MonitorMessage);
787 m = (struct MonitorMessage *) &p[1];
788 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_MONITOR);
789 m->header.size = htons (sizeof (struct MonitorMessage));
790 m->id = htonl (phm->id);
791 m->op = htonl (GNUNET_NO);
792 GNUNET_CONTAINER_DLL_insert_tail (phm->ph->pending_head, phm->ph->pending_tail, p);
793 do_transmit (phm->ph);
794
705 GNUNET_CONTAINER_DLL_remove (phm->ph->monitor_head, phm->ph->monitor_tail, phm); 795 GNUNET_CONTAINER_DLL_remove (phm->ph->monitor_head, phm->ph->monitor_tail, phm);
706 GNUNET_free (phm); 796 GNUNET_free (phm);
707} 797}
@@ -717,6 +807,7 @@ GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph)
717 struct PendingMessage *p; 807 struct PendingMessage *p;
718 struct GNUNET_ATS_ReservationContext *rc; 808 struct GNUNET_ATS_ReservationContext *rc;
719 struct GNUNET_ATS_AddressListHandle *alh; 809 struct GNUNET_ATS_AddressListHandle *alh;
810 struct GNUNET_ATS_PerformanceMonitorHandle *phm;
720 811
721 while (NULL != (p = ph->pending_head)) 812 while (NULL != (p = ph->pending_head))
722 { 813 {
@@ -736,6 +827,11 @@ GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph)
736 GNUNET_break (NULL == rc->rcb); 827 GNUNET_break (NULL == rc->rcb);
737 GNUNET_free (rc); 828 GNUNET_free (rc);
738 } 829 }
830 while (NULL != (phm = ph->monitor_head))
831 {
832 GNUNET_CONTAINER_DLL_remove (ph->monitor_head, ph->monitor_tail, phm);
833 GNUNET_free (phm);
834 }
739 if (GNUNET_SCHEDULER_NO_TASK != ph->task) 835 if (GNUNET_SCHEDULER_NO_TASK != ph->task)
740 { 836 {
741 GNUNET_SCHEDULER_cancel (ph->task); 837 GNUNET_SCHEDULER_cancel (ph->task);