diff options
Diffstat (limited to 'src/ats/gnunet-service-ats_performance.c')
-rw-r--r-- | src/ats/gnunet-service-ats_performance.c | 160 |
1 files changed, 7 insertions, 153 deletions
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 | ||