diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-03-19 11:01:46 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-03-19 11:01:46 +0000 |
commit | efb6bbbe66d5620ed29951cfd1c7a2d8582f1640 (patch) | |
tree | eeea915f020f6b4aed33a411b0260f9d4adbbfca /src/ats | |
parent | 66c49d17094d8a6c80fe1880a8339f10493f23ee (diff) | |
download | gnunet-efb6bbbe66d5620ed29951cfd1c7a2d8582f1640.tar.gz gnunet-efb6bbbe66d5620ed29951cfd1c7a2d8582f1640.zip |
pre lunch commit
Diffstat (limited to 'src/ats')
-rw-r--r-- | src/ats/ats.h | 20 | ||||
-rw-r--r-- | src/ats/ats_api_performance.c | 116 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats.c | 3 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_performance.c | 29 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_performance.h | 5 | ||||
-rw-r--r-- | src/ats/test_ats_api_performance_monitor.c | 14 |
6 files changed, 173 insertions, 14 deletions
diff --git a/src/ats/ats.h b/src/ats/ats.h index 70b88263d..1d6c1f129 100644 --- a/src/ats/ats.h +++ b/src/ats/ats.h | |||
@@ -192,6 +192,26 @@ struct PeerInformationMessage | |||
192 | 192 | ||
193 | }; | 193 | }; |
194 | 194 | ||
195 | struct MonitorMessage | ||
196 | { | ||
197 | struct GNUNET_MessageHeader header; | ||
198 | |||
199 | uint32_t id GNUNET_PACKED; | ||
200 | |||
201 | uint32_t op GNUNET_PACKED; /* GNUNET_YES to start, GNUNET_NO to stop */ | ||
202 | }; | ||
203 | |||
204 | struct MonitorResponseMessage | ||
205 | { | ||
206 | struct GNUNET_MessageHeader header; | ||
207 | |||
208 | uint32_t id GNUNET_PACKED; | ||
209 | |||
210 | uint32_t ats_count GNUNET_PACKED; | ||
211 | |||
212 | struct GNUNET_PeerIdentity peer; | ||
213 | }; | ||
214 | |||
195 | struct AddressListRequestMessage | 215 | struct AddressListRequestMessage |
196 | { | 216 | { |
197 | struct GNUNET_MessageHeader header; | 217 | struct GNUNET_MessageHeader header; |
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 | |||
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 | |||
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 | */ | ||
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 | 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 | ||
656 | struct 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, | |||
702 | void | 776 | void |
703 | GNUNET_ATS_performance_monitor_stop (struct GNUNET_ATS_PerformanceMonitorHandle * phm) | 777 | GNUNET_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); |
diff --git a/src/ats/gnunet-service-ats.c b/src/ats/gnunet-service-ats.c index 3218769a6..12693f212 100644 --- a/src/ats/gnunet-service-ats.c +++ b/src/ats/gnunet-service-ats.c | |||
@@ -162,6 +162,9 @@ 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)}, | ||
165 | {NULL, NULL, 0, 0} | 168 | {NULL, NULL, 0, 0} |
166 | }; | 169 | }; |
167 | GSA_server = server; | 170 | GSA_server = server; |
diff --git a/src/ats/gnunet-service-ats_performance.c b/src/ats/gnunet-service-ats_performance.c index 35f0223a2..6e4b92bc6 100644 --- a/src/ats/gnunet-service-ats_performance.c +++ b/src/ats/gnunet-service-ats_performance.c | |||
@@ -502,6 +502,35 @@ GAS_handle_request_address_list (void *cls, struct GNUNET_SERVER_Client *client, | |||
502 | } | 502 | } |
503 | 503 | ||
504 | 504 | ||
505 | void | ||
506 | GAS_handle_monitor (void *cls, | ||
507 | struct GNUNET_SERVER_Client *client, | ||
508 | const struct GNUNET_MessageHeader *message) | ||
509 | { | ||
510 | struct MonitorMessage *mm = (struct MonitorMessage *) message; | ||
511 | size_t msg_size; | ||
512 | uint32_t id; | ||
513 | |||
514 | msg_size = ntohs (message->size); | ||
515 | if (msg_size < sizeof (struct MonitorMessage)) | ||
516 | return; | ||
517 | |||
518 | id = ntohl (mm->id); | ||
519 | |||
520 | switch (ntohl (mm->op)) { | ||
521 | case GNUNET_YES: | ||
522 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Received `START' message\n"); | ||
523 | break; | ||
524 | case GNUNET_NO: | ||
525 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Received `STOP' message\n"); | ||
526 | break; | ||
527 | default: | ||
528 | break; | ||
529 | } | ||
530 | |||
531 | |||
532 | } | ||
533 | |||
505 | 534 | ||
506 | /** | 535 | /** |
507 | * Handle 'reservation request' messages from clients. | 536 | * Handle 'reservation request' messages from clients. |
diff --git a/src/ats/gnunet-service-ats_performance.h b/src/ats/gnunet-service-ats_performance.h index 6d527ae19..b0e910cc0 100644 --- a/src/ats/gnunet-service-ats_performance.h +++ b/src/ats/gnunet-service-ats_performance.h | |||
@@ -117,6 +117,11 @@ GAS_handle_preference_change (void *cls, | |||
117 | const struct GNUNET_MessageHeader *message); | 117 | const struct GNUNET_MessageHeader *message); |
118 | 118 | ||
119 | 119 | ||
120 | void | ||
121 | GAS_handle_monitor (void *cls, | ||
122 | struct GNUNET_SERVER_Client *client, | ||
123 | const struct GNUNET_MessageHeader *message); | ||
124 | |||
120 | /** | 125 | /** |
121 | * Initialize performance subsystem. | 126 | * Initialize performance subsystem. |
122 | * | 127 | * |
diff --git a/src/ats/test_ats_api_performance_monitor.c b/src/ats/test_ats_api_performance_monitor.c index 3d1ab79b2..eebe23749 100644 --- a/src/ats/test_ats_api_performance_monitor.c +++ b/src/ats/test_ats_api_performance_monitor.c | |||
@@ -51,6 +51,12 @@ end_now (int res) | |||
51 | die_task = GNUNET_SCHEDULER_NO_TASK; | 51 | die_task = GNUNET_SCHEDULER_NO_TASK; |
52 | } | 52 | } |
53 | 53 | ||
54 | if (NULL != phm) | ||
55 | { | ||
56 | GNUNET_ATS_performance_monitor_stop (phm); | ||
57 | phm = NULL; | ||
58 | } | ||
59 | |||
54 | if (NULL != ph) | 60 | if (NULL != ph) |
55 | { | 61 | { |
56 | GNUNET_ATS_performance_done (ph); | 62 | GNUNET_ATS_performance_done (ph); |
@@ -93,11 +99,11 @@ run (void *cls, | |||
93 | phm = GNUNET_ATS_performance_monitor_start (ph, &perf_mon_cb, &ret); | 99 | phm = GNUNET_ATS_performance_monitor_start (ph, &perf_mon_cb, &ret); |
94 | GNUNET_assert (NULL != phm); | 100 | GNUNET_assert (NULL != phm); |
95 | 101 | ||
96 | GNUNET_ATS_performance_monitor_stop (phm); | 102 | // GNUNET_ATS_performance_monitor_stop (phm); |
97 | 103 | ||
98 | GNUNET_ATS_performance_done (ph); | 104 | //GNUNET_ATS_performance_done (ph); |
99 | ph = NULL; | 105 | // ph = NULL; |
100 | end_now (0); | 106 | //end_now (0); |
101 | } | 107 | } |
102 | 108 | ||
103 | 109 | ||