uncrustify as demanded.
[oweals/gnunet.git] / src / core / gnunet-service-core_typemap.c
index 9dd3c71c8718db52ea826f9d1b3cced3d814a4b5..55cd9fb14ce331799f6c1cb66b81f9d07792a401 100644 (file)
@@ -16,7 +16,7 @@
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
      SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
 
 /**
  * @file core/gnunet-service-core_typemap.c
@@ -36,8 +36,7 @@
  * A type map describing which messages a given neighbour is able
  * to process.
  */
-struct GSC_TypeMap
-{
+struct GSC_TypeMap {
   uint32_t bits[(UINT16_MAX + 1) / 32];
 };
 
@@ -67,7 +66,7 @@ static int hash_current;
  * Our type map changed, recompute its hash.
  */
 static void
-rehash_typemap ()
+rehash_typemap()
 {
   hash_current = GNUNET_NO;
 }
@@ -80,9 +79,9 @@ rehash_typemap ()
  * @param hc where to store the hash code
  */
 void
-GSC_TYPEMAP_hash (const struct GSC_TypeMap *tm, struct GNUNET_HashCode *hc)
+GSC_TYPEMAP_hash(const struct GSC_TypeMap *tm, struct GNUNET_HashCode *hc)
 {
-  GNUNET_CRYPTO_hash (tm, sizeof (struct GSC_TypeMap), hc);
+  GNUNET_CRYPTO_hash(tm, sizeof(struct GSC_TypeMap), hc);
 }
 
 
@@ -93,16 +92,16 @@ GSC_TYPEMAP_hash (const struct GSC_TypeMap *tm, struct GNUNET_HashCode *hc)
  * @return #GNUNET_YES if the hash matches, #GNUNET_NO if not
  */
 int
-GSC_TYPEMAP_check_hash (const struct GNUNET_HashCode *hc)
+GSC_TYPEMAP_check_hash(const struct GNUNET_HashCode *hc)
 {
   if (GNUNET_NO == hash_current)
-  {
-    GSC_TYPEMAP_hash (&my_type_map, &my_tm_hash);
-    hash_current = GNUNET_YES;
-  }
-  return (0 == memcmp (hc, &my_tm_hash, sizeof (struct GNUNET_HashCode)))
-           ? GNUNET_YES
-           : GNUNET_NO;
+    {
+      GSC_TYPEMAP_hash(&my_type_map, &my_tm_hash);
+      hash_current = GNUNET_YES;
+    }
+  return (0 == memcmp(hc, &my_tm_hash, sizeof(struct GNUNET_HashCode)))
+         ? GNUNET_YES
+         : GNUNET_NO;
 }
 
 
@@ -112,39 +111,39 @@ GSC_TYPEMAP_check_hash (const struct GNUNET_HashCode *hc)
  * @return this peers current type map message.
  */
 struct GNUNET_MessageHeader *
-GSC_TYPEMAP_compute_type_map_message ()
+GSC_TYPEMAP_compute_type_map_message()
 {
   char *tmp;
   uLongf dlen;
   struct GNUNET_MessageHeader *hdr;
 
 #ifdef compressBound
-  dlen = compressBound (sizeof (my_type_map));
+  dlen = compressBound(sizeof(my_type_map));
 #else
-  dlen = sizeof (my_type_map) + (sizeof (my_type_map) / 100) + 20;
+  dlen = sizeof(my_type_map) + (sizeof(my_type_map) / 100) + 20;
   /* documentation says 100.1% oldSize + 12 bytes, but we
    * should be able to overshoot by more to be safe */
 #endif
-  hdr = GNUNET_malloc (dlen + sizeof (struct GNUNET_MessageHeader));
-  tmp = (char *) &hdr[1];
-  if ((Z_OK != compress2 ((Bytef *) tmp,
-                          &dlen,
-                          (const Bytef *) &my_type_map,
-                          sizeof (my_type_map),
-                          9)) ||
-      (dlen >= sizeof (my_type_map)))
-  {
-    /* compression failed, use uncompressed map */
-    dlen = sizeof (my_type_map);
-    GNUNET_memcpy (tmp, &my_type_map, sizeof (my_type_map));
-    hdr->type = htons (GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP);
-  }
+  hdr = GNUNET_malloc(dlen + sizeof(struct GNUNET_MessageHeader));
+  tmp = (char *)&hdr[1];
+  if ((Z_OK != compress2((Bytef *)tmp,
+                         &dlen,
+                         (const Bytef *)&my_type_map,
+                         sizeof(my_type_map),
+                         9)) ||
+      (dlen >= sizeof(my_type_map)))
+    {
+      /* compression failed, use uncompressed map */
+      dlen = sizeof(my_type_map);
+      GNUNET_memcpy(tmp, &my_type_map, sizeof(my_type_map));
+      hdr->type = htons(GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP);
+    }
   else
-  {
-    /* compression worked, use compressed map */
-    hdr->type = htons (GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP);
-  }
-  hdr->size = htons ((uint16_t) dlen + sizeof (struct GNUNET_MessageHeader));
+    {
+      /* compression worked, use compressed map */
+      hdr->type = htons(GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP);
+    }
+  hdr->size = htons((uint16_t)dlen + sizeof(struct GNUNET_MessageHeader));
   return hdr;
 }
 
@@ -156,50 +155,52 @@ GSC_TYPEMAP_compute_type_map_message ()
  * @return NULL on error
  */
 struct GSC_TypeMap *
-GSC_TYPEMAP_get_from_message (const struct GNUNET_MessageHeader *msg)
+GSC_TYPEMAP_get_from_message(const struct GNUNET_MessageHeader *msg)
 {
   struct GSC_TypeMap *ret;
   uint16_t size;
   uLongf dlen;
 
-  size = ntohs (msg->size);
-  switch (ntohs (msg->type))
-  {
-  case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP:
-    GNUNET_STATISTICS_update (GSC_stats,
-                              gettext_noop ("# type maps received"),
-                              1,
-                              GNUNET_NO);
-    if (size != sizeof (struct GSC_TypeMap))
+  size = ntohs(msg->size);
+  switch (ntohs(msg->type))
     {
-      GNUNET_break_op (0);
+    case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP:
+      GNUNET_STATISTICS_update(GSC_stats,
+                               gettext_noop("# type maps received"),
+                               1,
+                               GNUNET_NO);
+      if (size != sizeof(struct GSC_TypeMap))
+        {
+          GNUNET_break_op(0);
+          return NULL;
+        }
+      ret = GNUNET_new(struct GSC_TypeMap);
+      GNUNET_memcpy(ret, &msg[1], sizeof(struct GSC_TypeMap));
+      return ret;
+
+    case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP:
+      GNUNET_STATISTICS_update(GSC_stats,
+                               gettext_noop("# type maps received"),
+                               1,
+                               GNUNET_NO);
+      ret = GNUNET_new(struct GSC_TypeMap);
+      dlen = sizeof(struct GSC_TypeMap);
+      if ((Z_OK != uncompress((Bytef *)ret,
+                              &dlen,
+                              (const Bytef *)&msg[1],
+                              (uLong)size)) ||
+          (dlen != sizeof(struct GSC_TypeMap)))
+        {
+          GNUNET_break_op(0);
+          GNUNET_free(ret);
+          return NULL;
+        }
+      return ret;
+
+    default:
+      GNUNET_break(0);
       return NULL;
     }
-    ret = GNUNET_new (struct GSC_TypeMap);
-    GNUNET_memcpy (ret, &msg[1], sizeof (struct GSC_TypeMap));
-    return ret;
-  case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP:
-    GNUNET_STATISTICS_update (GSC_stats,
-                              gettext_noop ("# type maps received"),
-                              1,
-                              GNUNET_NO);
-    ret = GNUNET_new (struct GSC_TypeMap);
-    dlen = sizeof (struct GSC_TypeMap);
-    if ((Z_OK != uncompress ((Bytef *) ret,
-                             &dlen,
-                             (const Bytef *) &msg[1],
-                             (uLong) size)) ||
-        (dlen != sizeof (struct GSC_TypeMap)))
-    {
-      GNUNET_break_op (0);
-      GNUNET_free (ret);
-      return NULL;
-    }
-    return ret;
-  default:
-    GNUNET_break (0);
-    return NULL;
-  }
 }
 
 
@@ -207,17 +208,17 @@ GSC_TYPEMAP_get_from_message (const struct GNUNET_MessageHeader *msg)
  * Send my type map to all connected peers (it got changed).
  */
 static void
-broadcast_my_type_map ()
+broadcast_my_type_map()
 {
   struct GNUNET_MessageHeader *hdr;
 
-  hdr = GSC_TYPEMAP_compute_type_map_message ();
-  GNUNET_STATISTICS_update (GSC_stats,
-                            gettext_noop ("# updates to my type map"),
-                            1,
-                            GNUNET_NO);
-  GSC_SESSIONS_broadcast_typemap (hdr);
-  GNUNET_free (hdr);
+  hdr = GSC_TYPEMAP_compute_type_map_message();
+  GNUNET_STATISTICS_update(GSC_stats,
+                           gettext_noop("# updates to my type map"),
+                           1,
+                           GNUNET_NO);
+  GSC_SESSIONS_broadcast_typemap(hdr);
+  GNUNET_free(hdr);
 }
 
 
@@ -228,26 +229,26 @@ broadcast_my_type_map ()
  * @param tlen number of entries in @a types
  */
 void
-GSC_TYPEMAP_add (const uint16_t *types, unsigned int tlen)
+GSC_TYPEMAP_add(const uint16_t *types, unsigned int tlen)
 {
   unsigned int i;
   int changed;
 
   changed = GNUNET_NO;
   for (i = 0; i < tlen; i++)
-  {
-    if (0 == map_counters[types[i]]++)
     {
-      my_type_map.bits[types[i] / 32] |= (1 << (types[i] % 32));
-      changed = GNUNET_YES;
+      if (0 == map_counters[types[i]]++)
+        {
+          my_type_map.bits[types[i] / 32] |= (1 << (types[i] % 32));
+          changed = GNUNET_YES;
+        }
     }
-  }
   if (GNUNET_YES == changed)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Typemap changed, broadcasting!\n");
-    rehash_typemap ();
-    broadcast_my_type_map ();
-  }
+    {
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Typemap changed, broadcasting!\n");
+      rehash_typemap();
+      broadcast_my_type_map();
+    }
 }
 
 
@@ -258,24 +259,24 @@ GSC_TYPEMAP_add (const uint16_t *types, unsigned int tlen)
  * @param tlen length of the @a types array
  */
 void
-GSC_TYPEMAP_remove (const uint16_t *types, unsigned int tlen)
+GSC_TYPEMAP_remove(const uint16_t *types, unsigned int tlen)
 {
   int changed;
 
   changed = GNUNET_NO;
   for (unsigned int i = 0; i < tlen; i++)
-  {
-    if (0 == --map_counters[types[i]])
     {
-      my_type_map.bits[types[i] / 32] &= ~(1 << (types[i] % 32));
-      changed = GNUNET_YES;
+      if (0 == --map_counters[types[i]])
+        {
+          my_type_map.bits[types[i] / 32] &= ~(1 << (types[i] % 32));
+          changed = GNUNET_YES;
+        }
     }
-  }
   if (GNUNET_YES == changed)
-  {
-    rehash_typemap ();
-    broadcast_my_type_map ();
-  }
+    {
+      rehash_typemap();
+      broadcast_my_type_map();
+    }
 }
 
 
@@ -289,9 +290,9 @@ GSC_TYPEMAP_remove (const uint16_t *types, unsigned int tlen)
  * @return #GNUNET_YES if a type is in the map, #GNUNET_NO if not
  */
 int
-GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap,
-                        const uint16_t *types,
-                        unsigned int tcnt)
+GSC_TYPEMAP_test_match(const struct GSC_TypeMap *tmap,
+                       const uint16_t *types,
+                       unsigned int tcnt)
 {
   if (NULL == tmap)
     return GNUNET_NO;
@@ -313,15 +314,15 @@ GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap,
  * @return updated type map (fresh copy)
  */
 struct GSC_TypeMap *
-GSC_TYPEMAP_extend (const struct GSC_TypeMap *tmap,
-                    const uint16_t *types,
-                    unsigned int tcnt)
+GSC_TYPEMAP_extend(const struct GSC_TypeMap *tmap,
+                   const uint16_t *types,
+                   unsigned int tcnt)
 {
   struct GSC_TypeMap *ret;
 
-  ret = GNUNET_new (struct GSC_TypeMap);
+  ret = GNUNET_new(struct GSC_TypeMap);
   if (NULL != tmap)
-    GNUNET_memcpy (ret, tmap, sizeof (struct GSC_TypeMap));
+    GNUNET_memcpy(ret, tmap, sizeof(struct GSC_TypeMap));
   for (unsigned int i = 0; i < tcnt; i++)
     ret->bits[types[i] / 32] |= (1 << (types[i] % 32));
   return ret;
@@ -334,9 +335,9 @@ GSC_TYPEMAP_extend (const struct GSC_TypeMap *tmap,
  * @return an empty type map
  */
 struct GSC_TypeMap *
-GSC_TYPEMAP_create ()
+GSC_TYPEMAP_create()
 {
-  return GNUNET_new (struct GSC_TypeMap);
+  return GNUNET_new(struct GSC_TypeMap);
 }
 
 
@@ -346,9 +347,9 @@ GSC_TYPEMAP_create ()
  * @param tmap a type map
  */
 void
-GSC_TYPEMAP_destroy (struct GSC_TypeMap *tmap)
+GSC_TYPEMAP_destroy(struct GSC_TypeMap *tmap)
 {
-  GNUNET_free (tmap);
+  GNUNET_free(tmap);
 }
 
 
@@ -356,7 +357,7 @@ GSC_TYPEMAP_destroy (struct GSC_TypeMap *tmap)
  * Initialize typemap subsystem.
  */
 void
-GSC_TYPEMAP_init ()
+GSC_TYPEMAP_init()
 {
   /* nothing to do */
 }
@@ -366,7 +367,7 @@ GSC_TYPEMAP_init ()
  * Shutdown typemap subsystem.
  */
 void
-GSC_TYPEMAP_done ()
+GSC_TYPEMAP_done()
 {
   /* nothing to do */
 }