Merge branch 'master' of ssh://gnunet.org/gnunet
[oweals/gnunet.git] / src / util / peer.c
index fa376d33320490327989d7dca26c50290b9a5289..b637dc229c8dadc6dfaac0c4ef5b8486e0432e66 100644 (file)
@@ -1,6 +1,6 @@
 /*
       This file is part of GNUnet
-     (C) 2006, 2008, 2009 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2006, 2008, 2009 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
@@ -26,7 +26,7 @@
 #include "platform.h"
 #include "gnunet_peer_lib.h"
 
-#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
+#define LOG(kind,...) GNUNET_log_from (kind, "util-peer", __VA_ARGS__)
 
 
 struct PeerEntry
@@ -127,12 +127,13 @@ GNUNET_PEER_intern (const struct GNUNET_PeerIdentity *pid)
     GNUNET_array_grow (table, size, size + 16);
     for (i = ret; i < size; i++)
     {
-      table[i] = GNUNET_malloc (sizeof (struct PeerEntry));
+      table[i] = GNUNET_new (struct PeerEntry);
       table[i]->pid = i + 1;
     }
   }
   if (0 == ret)
   {
+    memset (&table[0]->id, 0, sizeof (struct GNUNET_PeerIdentity));
     table[0]->pid = 0;
     table[0]->rc = 1;
     ret = 1;
@@ -243,6 +244,8 @@ GNUNET_PEER_resolve (GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid)
 const struct GNUNET_PeerIdentity *
 GNUNET_PEER_resolve2 (GNUNET_PEER_Id id)
 {
+  GNUNET_assert (id < size);
+  GNUNET_assert (table[id]->rc > 0);
   return &table[id]->id;
 }