gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r26487 - gnunet/src/ats


From: gnunet
Subject: [GNUnet-SVN] r26487 - gnunet/src/ats
Date: Tue, 19 Mar 2013 12:01:46 +0100

Author: wachs
Date: 2013-03-19 12:01:46 +0100 (Tue, 19 Mar 2013)
New Revision: 26487

Modified:
   gnunet/src/ats/ats.h
   gnunet/src/ats/ats_api_performance.c
   gnunet/src/ats/gnunet-service-ats.c
   gnunet/src/ats/gnunet-service-ats_performance.c
   gnunet/src/ats/gnunet-service-ats_performance.h
   gnunet/src/ats/test_ats_api_performance_monitor.c
Log:
pre lunch commit


Modified: gnunet/src/ats/ats.h
===================================================================
--- gnunet/src/ats/ats.h        2013-03-19 10:05:42 UTC (rev 26486)
+++ gnunet/src/ats/ats.h        2013-03-19 11:01:46 UTC (rev 26487)
@@ -192,6 +192,26 @@
 
 };
 
+struct MonitorMessage
+{
+  struct GNUNET_MessageHeader header;
+
+  uint32_t id GNUNET_PACKED;
+
+  uint32_t op GNUNET_PACKED; /* GNUNET_YES to start, GNUNET_NO to stop */
+};
+
+struct MonitorResponseMessage
+{
+  struct GNUNET_MessageHeader header;
+
+  uint32_t id GNUNET_PACKED;
+
+  uint32_t ats_count GNUNET_PACKED;
+
+  struct GNUNET_PeerIdentity peer;
+};
+
 struct AddressListRequestMessage
 {
   struct GNUNET_MessageHeader header;

Modified: gnunet/src/ats/ats_api_performance.c
===================================================================
--- gnunet/src/ats/ats_api_performance.c        2013-03-19 10:05:42 UTC (rev 
26486)
+++ gnunet/src/ats/ats_api_performance.c        2013-03-19 11:01:46 UTC (rev 
26487)
@@ -157,6 +157,22 @@
   uint32_t id;
 };
 
+
+
+struct GNUNET_ATS_PerformanceMonitorHandle
+{
+       struct GNUNET_ATS_PerformanceMonitorHandle *next;
+       struct GNUNET_ATS_PerformanceMonitorHandle *prev;
+
+       struct GNUNET_ATS_PerformanceHandle * ph;
+
+       GNUNET_ATS_PerformanceMonitorCb moncb;
+       void *moncb_cls;
+
+       uint32_t id;
+};
+
+
 /**
  * ATS Handle to obtain and/or modify performance information.
  */
@@ -234,6 +250,11 @@
   GNUNET_SCHEDULER_TaskIdentifier task;
 
   /**
+   * Monitor request multiplexing
+   */
+  uint32_t monitor_id;
+
+  /**
    * Request multiplexing
    */
   uint32_t id;
@@ -543,7 +564,51 @@
   return GNUNET_OK;
 }
 
+/**
+ * We received a monitor response message.  Validate and process it.
+ *
+ * @param ph our context with the callback
+ * @param msg the message
+ * @return GNUNET_OK if the message was well-formed
+ */
+static int
+process_mr_message (struct GNUNET_ATS_PerformanceHandle *ph,
+                    const struct GNUNET_MessageHeader *msg)
+{
+       struct MonitorResponseMessage *mrm = (struct MonitorResponseMessage *) 
msg;
+       struct GNUNET_ATS_PerformanceMonitorHandle *cur;
+       struct GNUNET_ATS_Information *ats;
+       size_t msg_size;
+       uint32_t ats_count;
+       uint32_t id;
 
+       msg_size = ntohs (msg->size);
+       if (msg_size < sizeof (struct MonitorResponseMessage))
+               return GNUNET_SYSERR;
+
+       ats_count = ntohl (mrm->ats_count);
+       if (msg_size != (sizeof (struct MonitorResponseMessage) +
+                       ats_count * sizeof (struct GNUNET_ATS_Information)))
+               return GNUNET_SYSERR;
+
+       id = ntohl (mrm->id);
+       /* Do work here */
+       for (cur = ph->monitor_head; NULL != cur; cur = cur->next)
+       {
+                       if (id == cur->id)
+                               break;
+       }
+
+       if (NULL == cur)
+               return GNUNET_SYSERR;
+
+       ats = (struct GNUNET_ATS_Information *) &mrm[1];
+       cur->moncb (cur->moncb_cls, &mrm->peer, ats, ats_count);
+
+       return GNUNET_OK;
+}
+
+
 /**
  * Type of a function to call when we receive a message
  * from the service.
@@ -572,6 +637,10 @@
     if (GNUNET_OK != process_ar_message (ph, msg))
       goto reconnect;
     break;
+  case GNUNET_MESSAGE_TYPE_ATS_MONITOR_RESPONSE:
+    if (GNUNET_OK != process_mr_message (ph, msg))
+      goto reconnect;
+    break;
   default:
     GNUNET_break (0);
     goto reconnect;
@@ -653,17 +722,7 @@
   return ph;
 }
 
-struct GNUNET_ATS_PerformanceMonitorHandle
-{
-       struct GNUNET_ATS_PerformanceMonitorHandle *next;
-       struct GNUNET_ATS_PerformanceMonitorHandle *prev;
 
-       struct GNUNET_ATS_PerformanceHandle * ph;
-
-       GNUNET_ATS_PerformanceMonitorCb moncb;
-       void *moncb_cls;
-};
-
 /**
  * Start monitoring performance information
  *
@@ -677,16 +736,31 @@
                                                                                
                                                                        
GNUNET_ATS_PerformanceMonitorCb monitor_cb,
                                                                                
                                                                        void * 
monitor_cb_cls)
 {
+       struct MonitorMessage *m;
+       struct PendingMessage *p;
        GNUNET_assert (NULL != ph);
 
        struct GNUNET_ATS_PerformanceMonitorHandle *phm =
                        GNUNET_malloc (sizeof (struct 
GNUNET_ATS_PerformanceMonitorHandle));
 
+       ph->monitor_id ++;
+       phm->id = ph->monitor_id;
        phm->ph = ph;
        phm->moncb = monitor_cb;
        phm->moncb_cls = monitor_cb_cls;
        GNUNET_CONTAINER_DLL_insert (ph->monitor_head, ph->monitor_tail, phm);
 
+  p = GNUNET_malloc (sizeof (struct PendingMessage) +
+                     sizeof (struct MonitorMessage));
+  p->size = sizeof (struct MonitorMessage);
+  m = (struct MonitorMessage *) &p[1];
+  m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_MONITOR);
+  m->header.size = htons (sizeof (struct MonitorMessage));
+  m->id = htonl (phm->id);
+  m->op = htonl (GNUNET_YES);
+  GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head, ph->pending_tail, p);
+  do_transmit (ph);
+
        return phm;
 }
 
@@ -702,6 +776,22 @@
 void
 GNUNET_ATS_performance_monitor_stop (struct 
GNUNET_ATS_PerformanceMonitorHandle * phm)
 {
+       struct MonitorMessage *m;
+       struct PendingMessage *p;
+
+       GNUNET_assert (NULL != phm);
+
+  p = GNUNET_malloc (sizeof (struct PendingMessage) +
+                     sizeof (struct MonitorMessage));
+  p->size = sizeof (struct MonitorMessage);
+  m = (struct MonitorMessage *) &p[1];
+  m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_MONITOR);
+  m->header.size = htons (sizeof (struct MonitorMessage));
+  m->id = htonl (phm->id);
+  m->op = htonl (GNUNET_NO);
+  GNUNET_CONTAINER_DLL_insert_tail (phm->ph->pending_head, 
phm->ph->pending_tail, p);
+  do_transmit (phm->ph);
+
        GNUNET_CONTAINER_DLL_remove (phm->ph->monitor_head, 
phm->ph->monitor_tail, phm);
        GNUNET_free (phm);
 }
@@ -717,6 +807,7 @@
   struct PendingMessage *p;
   struct GNUNET_ATS_ReservationContext *rc;
   struct GNUNET_ATS_AddressListHandle *alh;
+  struct GNUNET_ATS_PerformanceMonitorHandle *phm;
 
   while (NULL != (p = ph->pending_head))
   {
@@ -736,6 +827,11 @@
     GNUNET_break (NULL == rc->rcb);
     GNUNET_free (rc);
   }
+  while (NULL != (phm = ph->monitor_head))
+  {
+    GNUNET_CONTAINER_DLL_remove (ph->monitor_head, ph->monitor_tail, phm);
+    GNUNET_free (phm);
+  }
   if (GNUNET_SCHEDULER_NO_TASK != ph->task)
   {
     GNUNET_SCHEDULER_cancel (ph->task);

Modified: gnunet/src/ats/gnunet-service-ats.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats.c 2013-03-19 10:05:42 UTC (rev 26486)
+++ gnunet/src/ats/gnunet-service-ats.c 2013-03-19 11:01:46 UTC (rev 26487)
@@ -162,6 +162,9 @@
     {&GAS_handle_reset_backoff, NULL,
      GNUNET_MESSAGE_TYPE_ATS_RESET_BACKOFF,
      sizeof (struct ResetBackoffMessage)},
+    {&GAS_handle_monitor, NULL,
+     GNUNET_MESSAGE_TYPE_ATS_MONITOR,
+     sizeof (struct MonitorMessage)},
     {NULL, NULL, 0, 0}
   };
   GSA_server = server;

Modified: gnunet/src/ats/gnunet-service-ats_performance.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_performance.c     2013-03-19 10:05:42 UTC 
(rev 26486)
+++ gnunet/src/ats/gnunet-service-ats_performance.c     2013-03-19 11:01:46 UTC 
(rev 26487)
@@ -502,7 +502,36 @@
 }
 
 
+void
+GAS_handle_monitor (void *cls,
+                                                                               
                        struct GNUNET_SERVER_Client *client,
+                          const struct GNUNET_MessageHeader *message)
+{
+       struct MonitorMessage *mm = (struct MonitorMessage *) message;
+       size_t msg_size;
+       uint32_t id;
 
+       msg_size = ntohs (message->size);
+       if (msg_size < sizeof (struct MonitorMessage))
+               return;
+
+       id = ntohl (mm->id);
+
+       switch (ntohl (mm->op)) {
+               case GNUNET_YES:
+                 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Received `START' 
message\n");
+                       break;
+               case GNUNET_NO:
+                       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Received `STOP' 
message\n");
+                       break;
+               default:
+                       break;
+       }
+
+
+}
+
+
 /**
  * Handle 'reservation request' messages from clients.
  *

Modified: gnunet/src/ats/gnunet-service-ats_performance.h
===================================================================
--- gnunet/src/ats/gnunet-service-ats_performance.h     2013-03-19 10:05:42 UTC 
(rev 26486)
+++ gnunet/src/ats/gnunet-service-ats_performance.h     2013-03-19 11:01:46 UTC 
(rev 26487)
@@ -117,6 +117,11 @@
                               const struct GNUNET_MessageHeader *message);
 
 
+void
+GAS_handle_monitor (void *cls,
+                                                                               
                        struct GNUNET_SERVER_Client *client,
+                          const struct GNUNET_MessageHeader *message);
+
 /**
  * Initialize performance subsystem.
  *

Modified: gnunet/src/ats/test_ats_api_performance_monitor.c
===================================================================
--- gnunet/src/ats/test_ats_api_performance_monitor.c   2013-03-19 10:05:42 UTC 
(rev 26486)
+++ gnunet/src/ats/test_ats_api_performance_monitor.c   2013-03-19 11:01:46 UTC 
(rev 26487)
@@ -51,6 +51,12 @@
                        die_task = GNUNET_SCHEDULER_NO_TASK;
        }
 
+       if (NULL != phm)
+       {
+               GNUNET_ATS_performance_monitor_stop (phm);
+               phm = NULL;
+       }
+
        if (NULL != ph)
        {
                GNUNET_ATS_performance_done (ph);
@@ -93,11 +99,11 @@
   phm = GNUNET_ATS_performance_monitor_start (ph, &perf_mon_cb, &ret);
   GNUNET_assert (NULL != phm);
 
-  GNUNET_ATS_performance_monitor_stop (phm);
+//  GNUNET_ATS_performance_monitor_stop (phm);
 
-       GNUNET_ATS_performance_done (ph);
-       ph = NULL;
-  end_now (0);
+       //GNUNET_ATS_performance_done (ph);
+//     ph = NULL;
+  //end_now (0);
 }
 
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]