aboutsummaryrefslogtreecommitdiff
path: root/src/ats/gnunet-service-ats_performance.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-03-20 09:13:10 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-03-20 09:13:10 +0000
commit110f7cda16a96257ad4bdcf604b1e188a00a1200 (patch)
tree21e62439333dc25107cf75deb04e26bb5b0d845d /src/ats/gnunet-service-ats_performance.c
parent10c3f79a9c8e9aa777329874cff6d9ef15d41751 (diff)
downloadgnunet-110f7cda16a96257ad4bdcf604b1e188a00a1200.tar.gz
gnunet-110f7cda16a96257ad4bdcf604b1e188a00a1200.zip
changes
Diffstat (limited to 'src/ats/gnunet-service-ats_performance.c')
-rw-r--r--src/ats/gnunet-service-ats_performance.c83
1 files changed, 70 insertions, 13 deletions
diff --git a/src/ats/gnunet-service-ats_performance.c b/src/ats/gnunet-service-ats_performance.c
index a6760b368..74b9650c9 100644
--- a/src/ats/gnunet-service-ats_performance.c
+++ b/src/ats/gnunet-service-ats_performance.c
@@ -534,7 +534,6 @@ GAS_handle_performance_update (struct GNUNET_PeerIdentity *peer,
534 struct MonitorResponseMessage *mrm; 534 struct MonitorResponseMessage *mrm;
535 size_t msglen; 535 size_t msglen;
536 536
537
538 msglen = sizeof (struct MonitorResponseMessage) + 537 msglen = sizeof (struct MonitorResponseMessage) +
539 ats_count * sizeof (struct GNUNET_ATS_Information); 538 ats_count * sizeof (struct GNUNET_ATS_Information);
540 mrm = GNUNET_malloc (msglen); 539 mrm = GNUNET_malloc (msglen);
@@ -551,13 +550,67 @@ GAS_handle_performance_update (struct GNUNET_PeerIdentity *peer,
551 mrm->id = curm->id; 550 mrm->id = curm->id;
552 GNUNET_SERVER_notification_context_unicast (nc, 551 GNUNET_SERVER_notification_context_unicast (nc,
553 cur->client, 552 cur->client,
554 (struct GNUNET_MessageHeader *) &mrm, 553 (struct GNUNET_MessageHeader *) mrm,
555 GNUNET_YES); 554 GNUNET_YES);
556 } 555 }
557 GNUNET_free (mrm); 556 GNUNET_free (mrm);
558} 557}
559 558
560 559
560static void
561mon_peerinfo_it (void *cls,
562 const struct GNUNET_PeerIdentity *id,
563 const char *plugin_name,
564 const void *plugin_addr, size_t plugin_addr_len,
565 const int active,
566 const struct GNUNET_ATS_Information *atsi,
567 uint32_t atsi_count,
568 struct GNUNET_BANDWIDTH_Value32NBO
569 bandwidth_out,
570 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
571{
572 struct PerformanceMonitorClient *pmc = cls;
573 struct MonitorResponseMessage *mrm;
574 size_t msglen;
575
576 if (NULL == id)
577 return; /* last callback */
578
579 msglen = sizeof (struct MonitorResponseMessage) +
580 atsi_count * sizeof (struct GNUNET_ATS_Information);
581 mrm = GNUNET_malloc (msglen);
582
583 mrm->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_MONITOR_RESPONSE);
584 mrm->header.size = htons (msglen);
585 mrm->ats_count = htonl (atsi_count);
586 mrm->peer = *id;
587 mrm->id = pmc->id;
588
589 /* Send initial information about peers to client */
590/*
591 GNUNET_SERVER_notification_context_unicast (nc,
592 pmc->client,
593 (struct GNUNET_MessageHeader *) mrm,
594 GNUNET_YES);
595*/
596 GNUNET_free (mrm);
597}
598
599/**
600 * Iterator for GAS_handle_monitor
601 *
602 * @param cls the performance monitoring client requesting information
603 * @param id result
604 */
605static void
606mon_peer_it (void *cls,
607 const struct GNUNET_PeerIdentity *id)
608{
609 struct PerformanceMonitorClient *pmc = cls;
610 if (NULL != id)
611 GAS_addresses_get_peer_info (GSA_addresses, id, &mon_peerinfo_it, pmc);
612}
613
561 614
562void 615void
563GAS_handle_monitor (void *cls, 616GAS_handle_monitor (void *cls,
@@ -565,7 +618,7 @@ GAS_handle_monitor (void *cls,
565 const struct GNUNET_MessageHeader *message) 618 const struct GNUNET_MessageHeader *message)
566{ 619{
567 struct PerformanceClient *pc; 620 struct PerformanceClient *pc;
568 struct PerformanceMonitorClient *res; 621 struct PerformanceMonitorClient *pmc;
569 struct MonitorMessage *mm = (struct MonitorMessage *) message; 622 struct MonitorMessage *mm = (struct MonitorMessage *) message;
570 size_t msg_size; 623 size_t msg_size;
571 uint32_t id; 624 uint32_t id;
@@ -588,38 +641,42 @@ GAS_handle_monitor (void *cls,
588 id = ntohl (mm->id); 641 id = ntohl (mm->id);
589 op = ntohl (mm->op); 642 op = ntohl (mm->op);
590 643
591 for (res = pc->pm_head; NULL != res; res = res->next) 644 for (pmc = pc->pm_head; NULL != pmc; pmc = pmc->next)
592 if ((res->id == id) && (client == res->client)) 645 if ((pmc->id == id) && (client == pmc->client))
593 break; 646 break;
594 647
595 if (GNUNET_YES == op) 648 if (GNUNET_YES == op)
596 { 649 {
597 /* Start monitoring */ 650 /* Start monitoring */
598 if (NULL != res) 651 if (NULL != pmc)
599 { 652 {
600 GNUNET_break (0); 653 GNUNET_break (0);
601 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 654 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
602 return; /* Duplicate*/ 655 return; /* Duplicate*/
603 } 656 }
604 res = GNUNET_malloc (sizeof (struct PerformanceMonitorClient)); 657 pmc = GNUNET_malloc (sizeof (struct PerformanceMonitorClient));
605 res->client = client; 658 pmc->client = client;
606 res->id = id; 659 pmc->id = id;
607 GNUNET_CONTAINER_DLL_insert (pc->pm_head, pc->pm_tail, res); 660 GNUNET_CONTAINER_DLL_insert (pc->pm_head, pc->pm_tail, pmc);
608 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 661 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
609 "Added performance monitoring client %p id %u\n", 662 "Added performance monitoring client %p id %u\n",
610 client, id); 663 client, id);
664
665 /* Return all values here */
666 GAS_addresses_iterate_peers (GSA_addresses, &mon_peer_it, pc);
667
611 } 668 }
612 else if (GNUNET_NO == op) 669 else if (GNUNET_NO == op)
613 { 670 {
614 /* Stop monitoring */ 671 /* Stop monitoring */
615 if (NULL == res) 672 if (NULL == pmc)
616 { 673 {
617 GNUNET_break (0); 674 GNUNET_break (0);
618 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 675 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
619 return; /* Not existing */ 676 return; /* Not existing */
620 } 677 }
621 GNUNET_CONTAINER_DLL_remove (pc->pm_head, pc->pm_tail, res); 678 GNUNET_CONTAINER_DLL_remove (pc->pm_head, pc->pm_tail, pmc);
622 GNUNET_free (res); 679 GNUNET_free (pmc);
623 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 680 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
624 "Removed performance monitoring client %p id %u\n", 681 "Removed performance monitoring client %p id %u\n",
625 client, id); 682 client, id);