Adding a function pick_random_friend ()
[oweals/gnunet.git] / src / dht / gnunet-service-dht_hello.c
index 5be0cbfec1c3b74dab482605519d521e3abba10d..81dd0b2fad4965305f5063e841b32f2e686a9ce1 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2011 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2011 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -40,7 +40,7 @@ static struct GNUNET_PEERINFO_NotifyContext *pnc;
 /**
  * Hash map of peers to HELLOs.
  */
-static struct GNUNET_CONTAINER_MultiHashMap *peer_to_hello;
+static struct GNUNET_CONTAINER_MultiPeerMap *peer_to_hello;
 
 
 /**
@@ -54,8 +54,7 @@ GDS_HELLO_get (const struct GNUNET_PeerIdentity *peer)
 {
   if (NULL == peer_to_hello)
     return NULL;
-  return GNUNET_CONTAINER_multihashmap_get (peer_to_hello,
-                                           &peer->hashPubKey);
+  return GNUNET_CONTAINER_multipeermap_get (peer_to_hello, peer);
 }
 
 
@@ -65,14 +64,13 @@ 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)
+ *
+ * FIXME this is called once per address. Merge instead of replacing?
  */
 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,21 +78,19 @@ process_hello (void *cls,
   if (hello == NULL)
     return;
   ex = GNUNET_HELLO_get_last_expiration (hello);
-  if (GNUNET_TIME_absolute_get_remaining (ex).rel_value == 0)
+  if (0 == GNUNET_TIME_absolute_get_remaining (ex).rel_value_us)
     return;
   GNUNET_STATISTICS_update (GDS_stats,
-                           gettext_noop ("# HELLOs obtained from peerinfo"), 1,
-                           GNUNET_NO);
-  hm = GNUNET_CONTAINER_multihashmap_get (peer_to_hello,
-                                         &peer->hashPubKey);
+                            gettext_noop ("# HELLOs obtained from peerinfo"), 1,
+                            GNUNET_NO);
+  hm = GNUNET_CONTAINER_multipeermap_get (peer_to_hello, peer);
   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_multipeermap_put (peer_to_hello,
+                                                    peer, hm,
+                                                    GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE));
 }
 
 
@@ -104,10 +100,8 @@ process_hello (void *cls,
 void
 GDS_HELLO_init ()
 {
-  pnc = GNUNET_PEERINFO_notify (GDS_cfg,
-                               &process_hello,
-                               NULL);
-  peer_to_hello = GNUNET_CONTAINER_multihashmap_create (256);
+  pnc = GNUNET_PEERINFO_notify (GDS_cfg, GNUNET_NO, &process_hello, NULL);
+  peer_to_hello = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_NO);
 }
 
 
@@ -116,7 +110,7 @@ GDS_HELLO_init ()
  */
 static int
 free_hello (void *cls,
-           const GNUNET_HashCode *key,
+           const struct GNUNET_PeerIdentity *key,
            void *hello)
 {
   GNUNET_free (hello);
@@ -137,10 +131,8 @@ GDS_HELLO_done ()
   }
   if (NULL != peer_to_hello)
   {
-    GNUNET_CONTAINER_multihashmap_iterate (peer_to_hello,
-                                          &free_hello,
-                                          NULL);
-    GNUNET_CONTAINER_multihashmap_destroy (peer_to_hello);
+    GNUNET_CONTAINER_multipeermap_iterate (peer_to_hello, &free_hello, NULL);
+    GNUNET_CONTAINER_multipeermap_destroy (peer_to_hello);
   }
 }