tighten formatting rules
[oweals/gnunet.git] / src / cadet / gnunet-service-cadet_paths.c
index 05f05690478e5354b5ad96c6c0c744357d7d9621..087515a5ec0945f8fc2920b8cf1b8cc24b2f6547 100644 (file)
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      Affero General Public License for more details.
-*/
+
+     You should have received a copy of the GNU Affero General Public License
+     along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+     SPDX-License-Identifier: AGPL3.0-or-later
+ */
 /**
  * @file cadet/gnunet-service-cadet_paths.c
  * @brief Information we track per path.
@@ -25,7 +30,7 @@
 #include "gnunet-service-cadet_paths.h"
 
 
-#define LOG(level, ...) GNUNET_log_from(level,"cadet-pat",__VA_ARGS__)
+#define LOG(level, ...) GNUNET_log_from (level, "cadet-pat", __VA_ARGS__)
 
 
 /**
@@ -33,7 +38,6 @@
  */
 struct CadetPeerPath
 {
-
   /**
    * Array of all the peers on the path.  If @e hn is non-NULL, the
    * last one is our owner.
@@ -56,7 +60,6 @@ struct CadetPeerPath
    * Length of the @e entries array.
    */
   unsigned int entries_length;
-
 };
 
 
@@ -70,7 +73,7 @@ recalculate_path_desirability (struct CadetPeerPath *path)
 {
   double result = 0.0;
 
-  for (unsigned int i=0;i<path->entries_length;i++)
+  for (unsigned int i = 0; i < path->entries_length; i++)
   {
     struct CadetPeer *cp = path->entries[i]->peer;
 
@@ -153,7 +156,6 @@ GCPP_add_connection (struct CadetPeerPath *path,
 }
 
 
-
 /**
  * Notify @a path that it is no longer used for connection @a cc which
  * ended at the path's offset @a off.
@@ -310,7 +312,6 @@ GCPP_update_score (struct CadetPeerPath *path,
  */
 struct CheckMatchContext
 {
-
   /**
    * Set to a matching path, if any.
    */
@@ -325,7 +326,6 @@ struct CheckMatchContext
    * How long is the @e cpath array?
    */
   unsigned int cpath_length;
-
 };
 
 
@@ -347,27 +347,27 @@ check_match (void *cls,
   struct CheckMatchContext *cm_ctx = cls;
 
   GNUNET_assert (path->entries_length > off);
-  if ( (path->entries_length != off + 1) &&
-       (off + 1 != cm_ctx->cpath_length) )
+  if ((path->entries_length != off + 1) &&
+      (off + 1 != cm_ctx->cpath_length))
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG,
-         "check_match missmatch because path %s is too long (%u vs. %u vs. %u)\n",
+         "check_match mismatch because path %s is too long (%u vs. %u vs. %u)\n",
          GCPP_2s (path),
          path->entries_length,
          off + 1,
          cm_ctx->cpath_length);
-    return GNUNET_YES; /* too long, goes somewhere else already, thus cannot be useful */
+    return GNUNET_YES;   /* too long, goes somewhere else already, thus cannot be useful */
   }
-  for (unsigned int i=0;i<off;i++)
+  for (unsigned int i = 0; i < off; i++)
     if (cm_ctx->cpath[i] !=
         GCPP_get_peer_at_offset (path,
                                  i))
     {
       LOG (GNUNET_ERROR_TYPE_DEBUG,
-           "check_match path %s missmatches at offset %u\n",
+           "check_match path %s mismatches at offset %u\n",
            GCPP_2s (path),
            i);
-      return GNUNET_YES; /* missmatch, ignore */
+      return GNUNET_YES;   /* mismatch, ignore */
     }
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "check_match found match with path %s\n",
@@ -400,7 +400,7 @@ extend_path (struct CadetPeerPath *path,
   GNUNET_array_grow (path->entries,
                      path->entries_length,
                      old_len + num_peers);
-  for (i=num_peers-1;i >= 0;i--)
+  for (i = num_peers - 1; i >= 0; i--)
   {
     struct CadetPeerPathEntry *entry = GNUNET_new (struct CadetPeerPathEntry);
 
@@ -408,7 +408,7 @@ extend_path (struct CadetPeerPath *path,
     entry->peer = peers[i];
     entry->path = path;
   }
-  for (i=num_peers-1;i >= 0;i--)
+  for (i = num_peers - 1; i >= 0; i--)
   {
     struct CadetPeerPathEntry *entry = path->entries[old_len + i];
 
@@ -419,7 +419,7 @@ extend_path (struct CadetPeerPath *path,
 
   /* If we extend an existing path, detach it from the
      old owner and re-attach to the new one */
-  GCP_detach_path (path->entries[old_len-1]->peer,
+  GCP_detach_path (path->entries[old_len - 1]->peer,
                    path,
                    path->hn);
   path->hn = NULL;
@@ -432,7 +432,9 @@ extend_path (struct CadetPeerPath *path,
                                 path,
                                 end,
                                 GNUNET_YES);
-  } else {
+  }
+  else
+  {
     attach_path (path, old_len);
   }
   if (NULL == path->hn)
@@ -474,7 +476,6 @@ GCPP_try_path_from_dht (const struct GNUNET_PeerIdentity *get_path,
   struct CadetPeer *cpath[get_path_length + put_path_length];
   struct CheckMatchContext cm_ctx;
   struct CadetPeerPath *path;
-  int i;
   unsigned int skip;
   unsigned int total_len;
 
@@ -482,19 +483,18 @@ GCPP_try_path_from_dht (const struct GNUNET_PeerIdentity *get_path,
   skip = 0;
   memset (cpath,
           0,
-          sizeof (cpath)); /* Just to trigger harder errors later. */
+          sizeof(cpath));  /* Just to trigger harder errors later. */
   total_len = get_path_length + put_path_length;
-  for (unsigned int off=0;off<total_len;off++)
+  for (unsigned int off = 0; off < total_len; off++)
   {
     const struct GNUNET_PeerIdentity *pid;
 
     pid = (off < get_path_length)
-      ? &get_path[get_path_length - off - 1]
-      : &put_path[get_path_length + put_path_length - off - 1];
+          ? &get_path[get_path_length - off - 1]
+          : &put_path[get_path_length + put_path_length - off - 1];
     /* Check that I am not in the path */
-    if (0 == memcmp (&my_full_id,
-                     pid,
-                     sizeof (struct GNUNET_PeerIdentity)))
+    if (0 == GNUNET_memcmp (&my_full_id,
+                            pid))
     {
       skip = off + 1;
       continue;
@@ -502,9 +502,9 @@ GCPP_try_path_from_dht (const struct GNUNET_PeerIdentity *get_path,
     cpath[off - skip] = GCP_get (pid,
                                  GNUNET_YES);
     /* Check that no peer is twice on the path */
-    for (unsigned int i=0;i<off - skip;i++)
+    for (unsigned int i = 0; i < off - skip; i++)
     {
-     if (cpath[i] == cpath[off - skip])
+      if (cpath[i] == cpath[off - skip])
       {
         skip = off - i;
         break;
@@ -524,7 +524,7 @@ GCPP_try_path_from_dht (const struct GNUNET_PeerIdentity *get_path,
   cm_ctx.cpath_length = total_len;
   cm_ctx.cpath = cpath;
   cm_ctx.match = NULL;
-  for (i=total_len-1;i>=0;i--)
+  for (int i = total_len - 1; i >= 0; i--)
   {
     GCP_iterate_paths_at (cpath[i],
                           (unsigned int) i,
@@ -559,7 +559,7 @@ GCPP_try_path_from_dht (const struct GNUNET_PeerIdentity *get_path,
   path->entries_length = total_len;
   path->entries = GNUNET_new_array (path->entries_length,
                                     struct CadetPeerPathEntry *);
-  for (i=path->entries_length-1;i>=0;i--)
+  for (int i = path->entries_length - 1; i >= 0; i--)
   {
     struct CadetPeerPathEntry *entry = GNUNET_new (struct CadetPeerPathEntry);
 
@@ -567,7 +567,7 @@ GCPP_try_path_from_dht (const struct GNUNET_PeerIdentity *get_path,
     entry->peer = cpath[i];
     entry->path = path;
   }
-  for (i=path->entries_length-1;i>=0;i--)
+  for (int i = path->entries_length - 1; i >= 0; i--)
   {
     struct CadetPeerPathEntry *entry = path->entries[i];
 
@@ -611,7 +611,7 @@ GCPP_get_path_from_route (unsigned int path_length,
 
   /* precompute inverted 'cpath' so we can avoid doing the lookups and
      have the correct order */
-  for (unsigned int off=0;off<path_length;off++)
+  for (unsigned int off = 0; off < path_length; off++)
     cpath[off] = GCP_get (&pids[path_length - 1 - off],
                           GNUNET_YES);
 
@@ -620,7 +620,7 @@ GCPP_get_path_from_route (unsigned int path_length,
   cm_ctx.cpath = cpath;
   cm_ctx.cpath_length = path_length;
   cm_ctx.match = NULL;
-  for (int i=path_length-1;i>=0;i--)
+  for (int i = path_length - 1; i >= 0; i--)
   {
     GCP_iterate_paths_at (cpath[i],
                           (unsigned int) i,
@@ -660,7 +660,7 @@ GCPP_get_path_from_route (unsigned int path_length,
   path->entries_length = path_length;
   path->entries = GNUNET_new_array (path->entries_length,
                                     struct CadetPeerPathEntry *);
-  for (int i=path_length-1;i>=0;i--)
+  for (int i = path_length - 1; i >= 0; i--)
   {
     struct CadetPeerPathEntry *entry = GNUNET_new (struct CadetPeerPathEntry);
 
@@ -668,7 +668,7 @@ GCPP_get_path_from_route (unsigned int path_length,
     entry->peer = cpath[i];
     entry->path = path;
   }
-  for (int i=path_length-1;i>=0;i--)
+  for (int i = path_length - 1; i >= 0; i--)
   {
     struct CadetPeerPathEntry *entry = path->entries[i];
 
@@ -757,24 +757,25 @@ GCPP_2s (struct CadetPeerPath *path)
        i < path->entries_length;
        i++)
   {
-    if ( (path->entries_length > max_plen) &&
-         (i == max_plen / 2) )
+    if ((path->entries_length > max_plen) &&
+        (i == max_plen / 2))
       off += GNUNET_snprintf (&buf[off],
-                              sizeof (buf) - off,
+                              sizeof(buf) - off,
                               "...-");
-    if ( (path->entries_length > max_plen) &&
-         (i > max_plen / 2) &&
-         (i < path->entries_length - max_plen / 2) )
+    if ((path->entries_length > max_plen) &&
+        (i > max_plen / 2) &&
+        (i < path->entries_length - max_plen / 2))
       continue;
     off += GNUNET_snprintf (&buf[off],
-                            sizeof (buf) - off,
+                            sizeof(buf) - off,
                             "%s%s",
-                            GNUNET_i2s (GCP_get_id (GCPP_get_peer_at_offset (path,
-                                                                             i))),
-                            (i == path->entries_length -1) ? "" : "-");
+                            GNUNET_i2s (GCP_get_id (GCPP_get_peer_at_offset (
+                                                      path,
+                                                      i))),
+                            (i == path->entries_length - 1) ? "" : "-");
   }
   GNUNET_snprintf (&buf[off],
-                   sizeof (buf) - off,
+                   sizeof(buf) - off,
                    "(%p)",
                    path);
   return buf;