gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet] branch master updated: -indentation, code cleanup


From: gnunet
Subject: [gnunet] branch master updated: -indentation, code cleanup
Date: Sat, 24 Aug 2024 18:45:16 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new 0cdafccc2 -indentation, code cleanup
0cdafccc2 is described below

commit 0cdafccc2d15aed8908d4da13d78926cefdd6f18
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sat Aug 24 18:45:12 2024 +0200

    -indentation, code cleanup
---
 src/lib/util/service.c                     | 116 +++++++++++++++--------------
 src/service/arm/test_arm_api_data.conf     |  11 +++
 src/service/arm/test_exponential_backoff.c |  75 +++++++++++++------
 3 files changed, 123 insertions(+), 79 deletions(-)

diff --git a/src/lib/util/service.c b/src/lib/util/service.c
index 363210c61..0922c8418 100644
--- a/src/lib/util/service.c
+++ b/src/lib/util/service.c
@@ -467,7 +467,7 @@ check_ipv6_listed (const struct 
GNUNET_STRINGS_IPv6NetworkPolicy *list,
        i++)
   {
     bool match = true;
-    
+
     for (unsigned int j = 0; j < sizeof(struct in6_addr) / sizeof(int); j++)
       if (((((int *) ip)[j] & ((int *) &list[i].netmask)[j])) !=
           (((int *) &list[i].network)[j] & ((int *) &list[i].netmask)[j]))
@@ -1064,7 +1064,7 @@ get_server_addresses (const char *service_name,
                       struct sockaddr ***addrs,
                       socklen_t **addr_lens)
 {
-  int disablev6;
+  bool disablev6;
   struct GNUNET_NETWORK_Handle *desc;
   unsigned long long port;
   char *unixpath;
@@ -1082,53 +1082,49 @@ get_server_addresses (const char *service_name,
   *addrs = NULL;
   *addr_lens = NULL;
   desc = NULL;
-  disablev6 = GNUNET_NO;
-  if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
+  disablev6 = false;
+  if ((GNUNET_NO ==
+       GNUNET_NETWORK_test_pf (PF_INET6)) ||
       (GNUNET_YES ==
-       GNUNET_CONFIGURATION_get_value_yesno (cfg, service_name, "DISABLEV6")))
-    disablev6 = GNUNET_YES;
+       GNUNET_CONFIGURATION_get_value_yesno (cfg,
+                                             service_name,
+                                             "DISABLEV6")))
+    disablev6 = true;
 
   port = 0;
-  if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT"))
+  if (GNUNET_SYSERR ==
+      GNUNET_CONFIGURATION_get_value_number (cfg,
+                                             service_name,
+                                             "PORT",
+                                             &port))
   {
-    if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
-                                                            service_name,
-                                                            "PORT",
-                                                            &port))
-    {
-      LOG (GNUNET_ERROR_TYPE_ERROR,
-           _ ("Require valid port number for service `%s' in 
configuration!\n"),
-           service_name);
-    }
-    if (port > 65535)
-    {
-      LOG (GNUNET_ERROR_TYPE_ERROR,
-           _ ("Require valid port number for service `%s' in 
configuration!\n"),
-           service_name);
-      return GNUNET_SYSERR;
-    }
+    LOG (GNUNET_ERROR_TYPE_ERROR,
+         _ ("Require valid port number for service `%s' in configuration!\n"),
+         service_name);
   }
-
-  if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "BINDTO"))
+  if (port > 65535)
   {
-    GNUNET_break (GNUNET_OK ==
-                  GNUNET_CONFIGURATION_get_value_string (cfg,
-                                                         service_name,
-                                                         "BINDTO",
-                                                         &hostname));
+    LOG (GNUNET_ERROR_TYPE_ERROR,
+         _ ("Require valid port number for service `%s' in configuration!\n"),
+         service_name);
+    return GNUNET_SYSERR;
   }
-  else
-    hostname = NULL;
+
+  hostname = NULL;
+  GNUNET_break (GNUNET_SYSERR !=
+                GNUNET_CONFIGURATION_get_value_string (cfg,
+                                                       service_name,
+                                                       "BINDTO",
+                                                       &hostname));
 
   unixpath = NULL;
 #ifdef AF_UNIX
-  if ((GNUNET_YES ==
-       GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) &&
-      (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg,
-                                                             service_name,
-                                                             "UNIXPATH",
-                                                             &unixpath)) &&
-      (0 < strlen (unixpath)))
+  if ( (GNUNET_OK ==
+        GNUNET_CONFIGURATION_get_value_filename (cfg,
+                                                 service_name,
+                                                 "UNIXPATH",
+                                                 &unixpath)) &&
+       (0 < strlen (unixpath)) )
   {
     /* probe UNIX support */
     struct sockaddr_un s_un;
@@ -1136,31 +1132,40 @@ get_server_addresses (const char *service_name,
     if (strlen (unixpath) >= sizeof(s_un.sun_path))
     {
       LOG (GNUNET_ERROR_TYPE_WARNING,
-           _ ("UNIXPATH `%s' too long, maximum length is %llu\n"),
+           "UNIXPATH `%s' too long, maximum length is %llu\n",
            unixpath,
            (unsigned long long) sizeof(s_un.sun_path));
       unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath);
-      LOG (GNUNET_ERROR_TYPE_INFO, _ ("Using `%s' instead\n"), unixpath);
+      LOG (GNUNET_ERROR_TYPE_INFO,
+           _ ("Using `%s' instead\n"),
+           unixpath);
     }
-    if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (unixpath))
-      GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mkdir", unixpath);
+    if (GNUNET_OK !=
+        GNUNET_DISK_directory_create_for_file (unixpath))
+      GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+                                "mkdir",
+                                unixpath);
   }
   if (NULL != unixpath)
   {
-    desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
+    desc = GNUNET_NETWORK_socket_create (AF_UNIX,
+                                         SOCK_STREAM,
+                                         0);
     if (NULL == desc)
     {
-      if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) ||
+      if ((ENOBUFS == errno) ||
+          (ENOMEM == errno) ||
+          (ENFILE == errno) ||
           (EACCES == errno))
       {
-        LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket");
+        LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
+                      "socket");
         GNUNET_free (hostname);
         GNUNET_free (unixpath);
         return GNUNET_SYSERR;
       }
-      LOG (GNUNET_ERROR_TYPE_INFO,
-           _ (
-             "Disabling UNIX domain socket support for service `%s', failed to 
create UNIX domain socket: %s\n"),
+      LOG (GNUNET_ERROR_TYPE_WARNING,
+           "Failed to create UNIX domain socket for service %s: %s\n",
            service_name,
            strerror (errno));
       GNUNET_free (unixpath);
@@ -1168,17 +1173,18 @@ get_server_addresses (const char *service_name,
     }
     else
     {
-      GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc));
+      GNUNET_break (GNUNET_OK ==
+                    GNUNET_NETWORK_socket_close (desc));
       desc = NULL;
     }
   }
 #endif
 
-  if ((0 == port) && (NULL == unixpath))
+  if ( (0 == port) &&
+       (NULL == unixpath) )
   {
     LOG (GNUNET_ERROR_TYPE_ERROR,
-         _ (
-           "Have neither PORT nor UNIXPATH for service `%s', but one is 
required\n"),
+         "Have neither PORT nor UNIXPATH for service `%s', but one is 
required\n",
          service_name);
     GNUNET_free (hostname);
     return GNUNET_SYSERR;
@@ -1496,7 +1502,7 @@ setup_service (struct GNUNET_SERVICE_Handle *sh)
   errno = 0;
   if ( (NULL != (nfds = getenv ("LISTEN_FDS"))) &&
        (1 == sscanf (nfds, "%u%1s", &cnt, dummy)) && (cnt > 0) &&
-      (cnt < FD_SETSIZE) && (cnt + 4 < FD_SETSIZE))
+       (cnt < FD_SETSIZE) && (cnt + 4 < FD_SETSIZE))
   {
     lsocks = GNUNET_new_array (cnt + 1, struct GNUNET_NETWORK_Handle *);
     while (0 < cnt--)
@@ -2309,7 +2315,7 @@ GNUNET_SERVICE_main (int argc,
     GNUNET_GETOPT_option_version (pd->version),
     GNUNET_GETOPT_OPTION_END
   };
-  
+
   xdg = getenv ("XDG_CONFIG_HOME");
   if (NULL != xdg)
     GNUNET_asprintf (&cfg_filename,
diff --git a/src/service/arm/test_arm_api_data.conf 
b/src/service/arm/test_arm_api_data.conf
index 25a644524..6b86e9fed 100644
--- a/src/service/arm/test_arm_api_data.conf
+++ b/src/service/arm/test_arm_api_data.conf
@@ -31,3 +31,14 @@ START_ON_DEMAND = NO
 [transport]
 START_ON_DEMAND = NO
 
+[nat]
+START_ON_DEMAND = NO
+
+[peerstore]
+IMMEDIATE_START = NO
+
+[communicator-udp]
+IMMEDIATE_START = NO
+
+[communicator-tcp]
+IMMEDIATE_START = NO
diff --git a/src/service/arm/test_exponential_backoff.c 
b/src/service/arm/test_exponential_backoff.c
index a9c7443c5..50ea11e73 100644
--- a/src/service/arm/test_exponential_backoff.c
+++ b/src/service/arm/test_exponential_backoff.c
@@ -27,7 +27,7 @@
 #include "gnunet_util_lib.h"
 #include "gnunet_protocols.h"
 
-#define LOG(...) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
+#define LOG(...) GNUNET_log (GNUNET_ERROR_TYPE_INFO, __VA_ARGS__)
 
 #define LOG_BACKOFF GNUNET_NO
 
@@ -36,7 +36,7 @@
 #define SERVICE_TEST_TIMEOUT GNUNET_TIME_UNIT_FOREVER_REL
 
 #define FIVE_MILLISECONDS GNUNET_TIME_relative_multiply ( \
-    GNUNET_TIME_UNIT_MILLISECONDS, 5)
+          GNUNET_TIME_UNIT_MILLISECONDS, 5)
 
 #define SERVICE "do-nothing"
 
@@ -51,6 +51,8 @@ static struct GNUNET_ARM_Handle *arm;
 
 static struct GNUNET_ARM_MonitorHandle *mon;
 
+static struct GNUNET_ARM_Operation *op;
+
 static struct GNUNET_SCHEDULER_Task *kt;
 
 static int ok = 1;
@@ -101,7 +103,9 @@ kill_task (void *cbData);
 static void
 service_shutdown_timeout (void *cls)
 {
-  GNUNET_assert (0);
+  GNUNET_break (0);
+  ok = 32;
+  GNUNET_SCHEDULER_shutdown ();
 }
 
 
@@ -173,6 +177,11 @@ kill_task (void *cbData)
 static void
 trigger_disconnect (void *cls)
 {
+  if (NULL != op)
+  {
+    GNUNET_ARM_operation_cancel (op);
+    op = NULL;
+  }
   GNUNET_ARM_disconnect (arm);
   GNUNET_ARM_monitor_stop (mon);
   if (NULL != kt)
@@ -188,6 +197,7 @@ arm_stop_cb (void *cls,
              enum GNUNET_ARM_RequestStatus status,
              enum GNUNET_ARM_Result result)
 {
+  op = NULL;
   GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
   GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED);
   LOG ("ARM service stopped\n");
@@ -195,6 +205,15 @@ arm_stop_cb (void *cls,
 }
 
 
+static void
+clear_op_cb (void *cls,
+             enum GNUNET_ARM_RequestStatus status,
+             enum GNUNET_ARM_Result result)
+{
+  op = NULL;
+}
+
+
 static void
 srv_status (void *cls,
             const char *service,
@@ -204,14 +223,16 @@ srv_status (void *cls,
   {
     LOG ("ARM monitor started, starting mock service\n");
     phase++;
-    GNUNET_ARM_request_service_start (arm,
-                                      SERVICE,
-                                      GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
-                                      NULL,
-                                      NULL);
+    GNUNET_assert (NULL == op);
+    op = GNUNET_ARM_request_service_start (arm,
+                                           SERVICE,
+                                           GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
+                                           &clear_op_cb,
+                                           NULL);
     return;
   }
-  if (0 != strcasecmp (service, SERVICE))
+  if (0 != strcasecmp (service,
+                       SERVICE))
     return; /* not what we care about */
   if (phase == 1)
   {
@@ -240,17 +261,20 @@ srv_status (void *cls,
 
       LOG ("do-nothing is starting, killing it...\n");
       GNUNET_assert (NULL == kt);
-      kt = GNUNET_SCHEDULER_add_now (&kill_task, &ok);
+      kt = GNUNET_SCHEDULER_add_now (&kill_task,
+                                     &ok);
     }
-    else if ((status == GNUNET_ARM_SERVICE_STOPPED) && (trialCount == 14))
+    else if ( (status == GNUNET_ARM_SERVICE_STOPPED) &&
+              (trialCount == 14))
     {
       phase++;
       LOG ("do-nothing stopped working %u times, we are done here\n",
            (unsigned int) trialCount);
-      GNUNET_ARM_request_service_stop (arm,
-                                       "arm",
-                                       &arm_stop_cb,
-                                       NULL);
+      GNUNET_assert (NULL == op);
+      op = GNUNET_ARM_request_service_stop (arm,
+                                            "arm",
+                                            &arm_stop_cb,
+                                            NULL);
     }
   }
 }
@@ -261,12 +285,14 @@ arm_start_cb (void *cls,
               enum GNUNET_ARM_RequestStatus status,
               enum GNUNET_ARM_Result result)
 {
+  op = NULL;
   GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK);
   GNUNET_break (result == GNUNET_ARM_RESULT_STARTING);
   GNUNET_break (phase == 0);
   LOG ("Sent 'START' request for arm to ARM %s\n",
-       (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" :
-       "unsuccessfully");
+       (status == GNUNET_ARM_REQUEST_SENT_OK)
+       ? "successfully"
+       : "unsuccessfully");
 }
 
 
@@ -295,11 +321,12 @@ task (void *cls,
     arm = NULL;
     return;
   }
-  GNUNET_ARM_request_service_start (arm,
-                                    "arm",
-                                    GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
-                                    &arm_start_cb,
-                                    NULL);
+  GNUNET_assert (NULL == op);
+  op = GNUNET_ARM_request_service_start (arm,
+                                         "arm",
+                                         GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
+                                         &arm_start_cb,
+                                         NULL);
   GNUNET_SCHEDULER_add_shutdown (&trigger_disconnect,
                                  NULL);
 }
@@ -349,7 +376,7 @@ init ()
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_parse (cfg,
                                   "test_arm_api_data.conf"))
-    {
+  {
     GNUNET_CONFIGURATION_destroy (cfg);
     return GNUNET_SYSERR;
   }
@@ -406,7 +433,7 @@ main (int argc, char *argv[])
   int ret;
 
   GNUNET_log_setup ("test-exponential-backoff",
-                    "WARNING",
+                    "DEBUG",
                     NULL);
 
   if (GNUNET_OK != init ())

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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