-consistently use struct GNUNET_HashCode
[oweals/gnunet.git] / src / dht / gnunet-service-dht_hello.c
index 2ee60c91f6449aaad429645ab4a58ff70406c4ca..b4c5150c9153731a92cc81ce2eef4b288f4fc4a5 100644 (file)
@@ -52,8 +52,9 @@ static struct GNUNET_CONTAINER_MultiHashMap *peer_to_hello;
 const struct GNUNET_HELLO_Message *
 GDS_HELLO_get (const struct GNUNET_PeerIdentity *peer)
 {
-  return GNUNET_CONTAINER_multihashmap_get (peer_to_hello,
-                                           &peer->hashPubKey);
+  if (NULL == peer_to_hello)
+    return NULL;
+  return GNUNET_CONTAINER_multihashmap_get (peer_to_hello, &peer->hashPubKey);
 }
 
 
@@ -63,14 +64,11 @@ GDS_HELLO_get (const struct GNUNET_PeerIdentity *peer)
  * @param cls closure
  * @param peer id of the peer, NULL for last call
  * @param hello hello message for the peer (can be NULL)
- * @param error message
+ * @param err_msg error message (not used)
  */
 static void
-process_hello (void *cls,
-              const struct GNUNET_PeerIdentity *
-              peer,
-              const struct GNUNET_HELLO_Message *
-              hello, const char *err_msg)
+process_hello (void *cls, const struct GNUNET_PeerIdentity *peer,
+               const struct GNUNET_HELLO_Message *hello, const char *err_msg)
 {
   struct GNUNET_TIME_Absolute ex;
   struct GNUNET_HELLO_Message *hm;
@@ -80,16 +78,17 @@ process_hello (void *cls,
   ex = GNUNET_HELLO_get_last_expiration (hello);
   if (GNUNET_TIME_absolute_get_remaining (ex).rel_value == 0)
     return;
-  hm = GNUNET_CONTAINER_multihashmap_get (peer_to_hello,
-                                         &peer->hashPubKey);
+  GNUNET_STATISTICS_update (GDS_stats,
+                            gettext_noop ("# HELLOs obtained from peerinfo"), 1,
+                            GNUNET_NO);
+  hm = GNUNET_CONTAINER_multihashmap_get (peer_to_hello, &peer->hashPubKey);
   GNUNET_free_non_null (hm);
   hm = GNUNET_malloc (GNUNET_HELLO_size (hello));
   memcpy (hm, hello, GNUNET_HELLO_size (hello));
   GNUNET_assert (GNUNET_SYSERR !=
-                GNUNET_CONTAINER_multihashmap_put (peer_to_hello,
-                                                   &peer->hashPubKey,
-                                                   hm,
-                                                   GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE));
+                 GNUNET_CONTAINER_multihashmap_put (peer_to_hello,
+                                                    &peer->hashPubKey, hm,
+                                                    GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE));
 }
 
 
@@ -99,9 +98,7 @@ process_hello (void *cls,
 void
 GDS_HELLO_init ()
 {
-  pnc = GNUNET_PEERINFO_notify (GDS_cfg,
-                               &process_hello,
-                               NULL);
+  pnc = GNUNET_PEERINFO_notify (GDS_cfg, &process_hello, NULL);
   peer_to_hello = GNUNET_CONTAINER_multihashmap_create (256);
 }
 
@@ -110,9 +107,7 @@ GDS_HELLO_init ()
  * Free memory occopied by the HELLO.
  */
 static int
-free_hello (void *cls,
-           const GNUNET_HashCode *key,
-           void *hello)
+free_hello (void *cls, const struct GNUNET_HashCode * key, void *hello)
 {
   GNUNET_free (hello);
   return GNUNET_OK;
@@ -130,10 +125,11 @@ GDS_HELLO_done ()
     GNUNET_PEERINFO_notify_cancel (pnc);
     pnc = NULL;
   }
-  GNUNET_CONTAINER_multihashmap_iterate (peer_to_hello,
-                                        &free_hello,
-                                        NULL);
-  GNUNET_CONTAINER_multihashmap_destroy (peer_to_hello);
+  if (NULL != peer_to_hello)
+  {
+    GNUNET_CONTAINER_multihashmap_iterate (peer_to_hello, &free_hello, NULL);
+    GNUNET_CONTAINER_multihashmap_destroy (peer_to_hello);
+  }
 }
 
 /* end of gnunet-service-dht_hello.c */