first batch of license fixes (boring)
[oweals/gnunet.git] / src / statistics / statistics_api.c
index 5ba78521c5d7150161962e7ad9bd3ac16c2d5542..66a4c3a642528c6a118cf4eb31088a778bdf9577 100644 (file)
@@ -2,20 +2,15 @@
      This file is part of GNUnet.
      Copyright (C) 2009, 2010, 2011, 2016 GNUnet e.V.
 
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 3, or (at your
-     option) any later version.
+     GNUnet is free software: you can redistribute it and/or modify it
+     under the terms of the GNU General Public License as published
+     by the Free Software Foundation, either version 3 of the License,
+     or (at your option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
-
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-     Boston, MA 02110-1301, USA.
+     Affero General Public License for more details.
 */
 
 /**
@@ -295,12 +290,18 @@ update_memory_statistics (struct GNUNET_STATISTICS_Handle *h)
   if (current_heap_size > h->peak_heap_size)
   {
     h->peak_heap_size = current_heap_size;
-    GNUNET_STATISTICS_set (h, "# peak heap size", current_heap_size, GNUNET_NO);
+    GNUNET_STATISTICS_set (h,
+                          "# peak heap size",
+                          current_heap_size,
+                          GNUNET_NO);
   }
   if (current_rss > h->peak_rss)
   {
     h->peak_rss = current_rss;
-    GNUNET_STATISTICS_set (h, "# peak resident set size", current_rss, GNUNET_NO);
+    GNUNET_STATISTICS_set (h,
+                          "# peak resident set size",
+                          current_rss,
+                          GNUNET_NO);
   }
 #endif
 }
@@ -343,7 +344,7 @@ schedule_watch_request (struct GNUNET_STATISTICS_Handle *h,
   slen = strlen (watch->subsystem) + 1;
   nlen = strlen (watch->name) + 1;
   nsize = sizeof (struct GNUNET_MessageHeader) + slen + nlen;
-  if (nsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
+  if (nsize >= GNUNET_MAX_MESSAGE_SIZE)
   {
     GNUNET_break (0);
     return;
@@ -570,16 +571,16 @@ do_destroy (void *cls)
 
 
 /**
- * Handle a #GNUNET_MESSAGE_TYPE_TEST (sic) message. We receive this
- * message at the end of the shutdown when the service confirms that
- * all data has been written to disk.
+ * Handle a #GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT_CONFIRM
+ * message. We receive this message at the end of the shutdown when
+ * the service confirms that all data has been written to disk.
  *
  * @param cls our `struct GNUNET_STATISTICS_Handle *`
  * @param msg the message
  */
 static void
-handle_test (void *cls,
-             const struct GNUNET_MessageHeader *msg)
+handle_disconnect_confirm (void *cls,
+                          const struct GNUNET_MessageHeader *msg)
 {
   struct GNUNET_STATISTICS_Handle *h = cls;
 
@@ -592,7 +593,7 @@ handle_test (void *cls,
     return;
   }
   LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Received TEST message from statistics, can complete disconnect\n");
+       "Received DISCONNNECT_CONFIRM message from statistics, can complete disconnect\n");
   if (NULL != h->destroy_task)
     GNUNET_SCHEDULER_cancel (h->destroy_task);
   h->destroy_task = GNUNET_SCHEDULER_add_now (&do_destroy,
@@ -647,8 +648,8 @@ static int
 try_connect (struct GNUNET_STATISTICS_Handle *h)
 {
   struct GNUNET_MQ_MessageHandler handlers[] = {
-    GNUNET_MQ_hd_fixed_size (test,
-                             GNUNET_MESSAGE_TYPE_TEST,
+    GNUNET_MQ_hd_fixed_size (disconnect_confirm,
+                             GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT_CONFIRM,
                              struct GNUNET_MessageHeader,
                              h),
     GNUNET_MQ_hd_fixed_size (statistics_end,
@@ -672,7 +673,7 @@ try_connect (struct GNUNET_STATISTICS_Handle *h)
     return GNUNET_NO;
   if (NULL != h->mq)
     return GNUNET_YES;
-  h->mq = GNUNET_CLIENT_connecT (h->cfg,
+  h->mq = GNUNET_CLIENT_connect (h->cfg,
                                  "statistics",
                                  handlers,
                                  &mq_error_handler,
@@ -739,7 +740,8 @@ reconnect_later (struct GNUNET_STATISTICS_Handle *h)
      */
     loss = GNUNET_NO;
     for (gh = h->action_head; NULL != gh; gh = gh->next)
-      if ( (gh->make_persistent) && (ACTION_SET == gh->type) )
+      if ( (gh->make_persistent) &&
+          (ACTION_SET == gh->type) )
        loss = GNUNET_YES;
     if (GNUNET_YES == loss)
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -922,8 +924,7 @@ GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h,
   GNUNET_assert (GNUNET_NO == h->do_destroy); /* Don't call twice. */
   if ( (sync_first) &&
        (NULL != h->mq) &&
-       (0 != GNUNET_MQ_get_length (h->mq))
-       (GNUNET_YES == try_connect (h)) )
+       (0 != GNUNET_MQ_get_length (h->mq)) )
   {
     if ( (NULL != h->current) &&
          (ACTION_GET == h->current->type) )
@@ -933,8 +934,7 @@ GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h,
     {
       next = pos->next;
       if ( (ACTION_GET == pos->type) ||
-           (ACTION_WATCH == pos->type) ||
-           (GNUNET_NO == pos->make_persistent) )
+           (ACTION_WATCH == pos->type) )
       {
        GNUNET_CONTAINER_DLL_remove (h->action_head,
                                     h->action_tail,
@@ -1009,8 +1009,8 @@ schedule_action (void *cls)
     reconnect_later (h);
     return;
   }
-  if (0 < GNUNET_MQ_get_length (h->mq) )
-    return; /* Wait for queue to be reduced more */
+  if (0 < GNUNET_MQ_get_length (h->mq))
+    return; /* Wait for queue to be reduced more */    
   /* schedule next action */
   while (NULL == h->current)
   {
@@ -1027,7 +1027,7 @@ schedule_action (void *cls)
                   "Notifying service that we are done\n");
       h->do_destroy = GNUNET_SYSERR; /* in 'TEST' mode */
       env = GNUNET_MQ_msg (hdr,
-                           GNUNET_MESSAGE_TYPE_TEST);
+                           GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT);
       GNUNET_MQ_notify_sent (env,
                              &schedule_action,
                              h);
@@ -1093,7 +1093,7 @@ GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle,
   slen1 = strlen (subsystem) + 1;
   slen2 = strlen (name) + 1;
   GNUNET_assert (slen1 + slen2 + sizeof (struct GNUNET_MessageHeader) <
-                 GNUNET_SERVER_MAX_MESSAGE_SIZE);
+                 GNUNET_MAX_MESSAGE_SIZE);
   ai = GNUNET_new (struct GNUNET_STATISTICS_GetHandle);
   ai->sh = handle;
   ai->subsystem = GNUNET_strdup (subsystem);
@@ -1200,8 +1200,10 @@ GNUNET_STATISTICS_watch_cancel (struct GNUNET_STATISTICS_Handle *handle,
       continue;
     if ( (w->proc == proc) &&
         (w->proc_cls == proc_cls) &&
-        (0 == strcmp (w->name, name)) &&
-        (0 == strcmp (w->subsystem, subsystem)) )
+        (0 == strcmp (w->name,
+                      name)) &&
+        (0 == strcmp (w->subsystem,
+                      subsystem)) )
     {
       GNUNET_free (w->name);
       GNUNET_free (w->subsystem);
@@ -1239,15 +1241,17 @@ add_setter_action (struct GNUNET_STATISTICS_Handle *h,
   slen = strlen (h->subsystem) + 1;
   nlen = strlen (name) + 1;
   nsize = sizeof (struct GNUNET_STATISTICS_SetMessage) + slen + nlen;
-  if (nsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
+  if (nsize >= GNUNET_MAX_MESSAGE_SIZE)
   {
     GNUNET_break (0);
     return;
   }
   for (ai = h->action_head; NULL != ai; ai = ai->next)
   {
-    if (! ( (0 == strcmp (ai->subsystem, h->subsystem)) &&
-           (0 == strcmp (ai->name, name)) &&
+    if (! ( (0 == strcmp (ai->subsystem,
+                         h->subsystem)) &&
+           (0 == strcmp (ai->name,
+                         name)) &&
            ( (ACTION_UPDATE == ai->type) ||
              (ACTION_SET == ai->type) ) ) )
       continue;
@@ -1291,8 +1295,10 @@ add_setter_action (struct GNUNET_STATISTICS_Handle *h,
        ai->type = type;
       }
     }
-    ai->timeout = GNUNET_TIME_relative_to_absolute (SET_TRANSMIT_TIMEOUT);
-    ai->make_persistent = make_persistent;
+    ai->timeout
+      = GNUNET_TIME_relative_to_absolute (SET_TRANSMIT_TIMEOUT);
+    ai->make_persistent
+      = make_persistent;
     return;
   }
   /* no existing entry matches, create a fresh one */