fix
[oweals/gnunet.git] / src / util / peer.c
index acb1b3922c2d38810e2c27ce1dfe3e06661a2f95..f30c720aa073ad8e97165d8af1a079165bec3103 100644 (file)
 struct PeerEntry
 {
   /**
-   * the identifier itself
+   * The identifier itself
    */
   struct GNUNET_PeerIdentity id;
 
   /**
-   * Short version of the identifier;
-   * if the RC==0, then index of next
-   * free slot in table, otherwise 
-   * equal to this slot in the table. 
+   * Short version of the identifier; if the RC==0, then index of next
+   * free slot in table, otherwise equal to this slot in the table.
    */
   GNUNET_PEER_Id pid;
 
   /**
-   * Reference counter, 0 if this slot
-   * is not used.
+   * Reference counter, 0 if this slot is not used.
    */
   unsigned int rc;
 };
@@ -83,7 +80,7 @@ static unsigned int free_list_start;
  * @return the interned identity.
  */
 GNUNET_PEER_Id
-GNUNET_PEER_intern (const struct GNUNET_PeerIdentity * pid)
+GNUNET_PEER_intern (const struct GNUNET_PeerIdentity *pid)
 {
   GNUNET_PEER_Id ret;
   struct PeerEntry *e;
@@ -93,8 +90,7 @@ GNUNET_PEER_intern (const struct GNUNET_PeerIdentity * pid)
     return 0;
   if (NULL == map)
     map = GNUNET_CONTAINER_multihashmap_create (32);
-  e = GNUNET_CONTAINER_multihashmap_get (map,
-                                        &pid->hashPubKey);
+  e = GNUNET_CONTAINER_multihashmap_get (map, &pid->hashPubKey);
   if (e != NULL)
     {
       GNUNET_assert (e->rc > 0);
@@ -105,8 +101,8 @@ GNUNET_PEER_intern (const struct GNUNET_PeerIdentity * pid)
   if (ret == size)
     {
       GNUNET_array_grow (table, size, size + 16);
-      for (i=ret;i<size;i++)
-       table[i].pid = i + 1;
+      for (i = ret; i < size; i++)
+        table[i].pid = i + 1;
     }
   if (ret == 0)
     {
@@ -120,10 +116,11 @@ GNUNET_PEER_intern (const struct GNUNET_PeerIdentity * pid)
   table[ret].id = *pid;
   table[ret].rc = 1;
   table[ret].pid = ret;
-  GNUNET_CONTAINER_multihashmap_put (map,
-                                    &pid->hashPubKey,
-                                    &table[ret],
-                                    GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+  GNUNET_break (GNUNET_OK ==
+               GNUNET_CONTAINER_multihashmap_put (map,
+                                                  &pid->hashPubKey,
+                                                  &table[ret],
+                                                  GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
   return ret;
 }
 
@@ -135,8 +132,7 @@ GNUNET_PEER_intern (const struct GNUNET_PeerIdentity * pid)
  * @param count size of the ids array
  */
 void
-GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id * ids, 
-                          unsigned int count)
+GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id * ids, unsigned int count)
 {
   int i;
   GNUNET_PEER_Id id;
@@ -146,17 +142,20 @@ GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id * ids,
   for (i = count - 1; i >= 0; i--)
     {
       id = ids[i];
+      if (id == 0)
+       continue;
       GNUNET_assert (id < size);
       GNUNET_assert (table[id].rc > 0);
       table[id].rc--;
       if (table[id].rc == 0)
-       {
-         GNUNET_CONTAINER_multihashmap_remove (map,
-                                               &table[id].id.hashPubKey,
-                                               &table[id]);
-         table[id].pid = free_list_start;
-         free_list_start = id;
-       }
+        {
+          GNUNET_break (GNUNET_OK ==
+                       GNUNET_CONTAINER_multihashmap_remove (map,
+                                                             &table[id].id.hashPubKey,
+                                                             &table[id]));
+          table[id].pid = free_list_start;
+          free_list_start = id;
+        }
     }
 }
 
@@ -178,9 +177,10 @@ GNUNET_PEER_change_rc (GNUNET_PEER_Id id, int delta)
   table[id].rc += delta;
   if (table[id].rc == 0)
     {
-      GNUNET_CONTAINER_multihashmap_remove (map,
-                                           &table[id].id.hashPubKey,
-                                           &table[id]);
+      GNUNET_break (GNUNET_OK ==
+                   GNUNET_CONTAINER_multihashmap_remove (map,
+                                                         &table[id].id.hashPubKey,
+                                                         &table[id]));
       table[id].pid = free_list_start;
       free_list_start = id;
     }
@@ -194,8 +194,7 @@ GNUNET_PEER_change_rc (GNUNET_PEER_Id id, int delta)
  * @param pid where to write the normal peer identity
  */
 void
-GNUNET_PEER_resolve (GNUNET_PEER_Id id, 
-                    struct GNUNET_PeerIdentity * pid)
+GNUNET_PEER_resolve (GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid)
 {
   if (id == 0)
     {