aboutsummaryrefslogtreecommitdiff
path: root/src/ats
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-03-19 12:21:20 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-03-19 12:21:20 +0000
commite730731a43c5fc878b298fb185d99a012d16e145 (patch)
tree74e4cd66ab876ca72c7a2a1f709812a39425440f /src/ats
parent963060fd10b77167b3850dc3f4fe2cf8a69dee34 (diff)
downloadgnunet-e730731a43c5fc878b298fb185d99a012d16e145.tar.gz
gnunet-e730731a43c5fc878b298fb185d99a012d16e145.zip
changes
Diffstat (limited to 'src/ats')
-rw-r--r--src/ats/gnunet-service-ats_performance.c85
1 files changed, 74 insertions, 11 deletions
diff --git a/src/ats/gnunet-service-ats_performance.c b/src/ats/gnunet-service-ats_performance.c
index 6e4b92bc6..71db0cb07 100644
--- a/src/ats/gnunet-service-ats_performance.c
+++ b/src/ats/gnunet-service-ats_performance.c
@@ -31,6 +31,15 @@
31#include "gnunet-service-ats_reservations.h" 31#include "gnunet-service-ats_reservations.h"
32#include "ats.h" 32#include "ats.h"
33 33
34struct PerformanceMonitorClient
35{
36 struct PerformanceMonitorClient *next;
37 struct PerformanceMonitorClient *prev;
38
39 struct GNUNET_SERVER_Client *client;
40
41 uint32_t id;
42};
34 43
35/** 44/**
36 * We keep clients that are interested in performance in a linked list. 45 * We keep clients that are interested in performance in a linked list.
@@ -47,6 +56,10 @@ struct PerformanceClient
47 */ 56 */
48 struct PerformanceClient *prev; 57 struct PerformanceClient *prev;
49 58
59 struct PerformanceMonitorClient *pm_head;
60
61 struct PerformanceMonitorClient *pm_tail;
62
50 /** 63 /**
51 * Actual handle to the client. 64 * Actual handle to the client.
52 */ 65 */
@@ -125,9 +138,18 @@ void
125GAS_performance_remove_client (struct GNUNET_SERVER_Client *client) 138GAS_performance_remove_client (struct GNUNET_SERVER_Client *client)
126{ 139{
127 struct PerformanceClient *pc; 140 struct PerformanceClient *pc;
141 struct PerformanceMonitorClient *cur;
142 struct PerformanceMonitorClient *next;
128 pc = find_client (client); 143 pc = find_client (client);
129 if (NULL == pc) 144 if (NULL == pc)
130 return; 145 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 }
131 GNUNET_CONTAINER_DLL_remove (pc_head, pc_tail, pc); 153 GNUNET_CONTAINER_DLL_remove (pc_head, pc_tail, pc);
132 GNUNET_SERVER_client_drop (client); 154 GNUNET_SERVER_client_drop (client);
133 GNUNET_free (pc); 155 GNUNET_free (pc);
@@ -502,32 +524,73 @@ GAS_handle_request_address_list (void *cls, struct GNUNET_SERVER_Client *client,
502} 524}
503 525
504 526
527
528
505void 529void
506GAS_handle_monitor (void *cls, 530GAS_handle_monitor (void *cls,
507 struct GNUNET_SERVER_Client *client, 531 struct GNUNET_SERVER_Client *client,
508 const struct GNUNET_MessageHeader *message) 532 const struct GNUNET_MessageHeader *message)
509{ 533{
534 struct PerformanceClient *pc;
535 struct PerformanceMonitorClient *res;
510 struct MonitorMessage *mm = (struct MonitorMessage *) message; 536 struct MonitorMessage *mm = (struct MonitorMessage *) message;
511 size_t msg_size; 537 size_t msg_size;
512 uint32_t id; 538 uint32_t id;
539 uint32_t op;
540
541 pc = find_client (client);
542 if (NULL == pc)
543 {
544 GNUNET_break (0);
545 return;
546 }
513 547
514 msg_size = ntohs (message->size); 548 msg_size = ntohs (message->size);
515 if (msg_size < sizeof (struct MonitorMessage)) 549 if (msg_size < sizeof (struct MonitorMessage))
516 return; 550 return;
517 551
518 id = ntohl (mm->id); 552 id = ntohl (mm->id);
553 op = ntohl (mm->op);
519 554
520 switch (ntohl (mm->op)) { 555 for (res = pc->pm_head; NULL != res; res = res->next)
521 case GNUNET_YES: 556 if ((res->id == id) && (client == res->client))
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; 557 break;
529 }
530 558
559 if (GNUNET_YES == op)
560 {
561 /* Start monitoring */
562 if (NULL != res)
563 {
564 GNUNET_break (0);
565 return; /* Duplicate*/
566 }
567 res = GNUNET_malloc (sizeof (struct PerformanceMonitorClient));
568 res->client = client;
569 res->id = id;
570 GNUNET_CONTAINER_DLL_insert (pc->pm_head, pc->pm_tail, res);
571 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
572 "Added performance monitoring client %p id %u\n",
573 client, id);
574 }
575 else if (GNUNET_NO == op)
576 {
577 /* Stop monitoring */
578 if (NULL == res)
579 {
580 GNUNET_break (0);
581 return; /* Not existing */
582 }
583 GNUNET_CONTAINER_DLL_remove (pc->pm_head, pc->pm_tail, res);
584 GNUNET_free (res);
585 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
586 "Removed performance monitoring client %p id %u\n",
587 client, id);
588 }
589 else
590 {
591 GNUNET_break (0);
592 return;
593 }
531 594
532} 595}
533 596