gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r17061 - gnunet/src/dht


From: gnunet
Subject: [GNUnet-SVN] r17061 - gnunet/src/dht
Date: Tue, 27 Sep 2011 16:26:23 +0200

Author: grothoff
Date: 2011-09-27 16:26:23 +0200 (Tue, 27 Sep 2011)
New Revision: 17061

Added:
   gnunet/src/dht/gnunet-service-dht_hello.c
   gnunet/src/dht/gnunet-service-dht_hello.h
Modified:
   gnunet/src/dht/Makefile.am
   gnunet/src/dht/gnunet-service-dht-new.c
   gnunet/src/dht/gnunet-service-dht_neighbours.c
Log:
track HELLOs from peerinfo

Modified: gnunet/src/dht/Makefile.am
===================================================================
--- gnunet/src/dht/Makefile.am  2011-09-27 14:20:12 UTC (rev 17060)
+++ gnunet/src/dht/Makefile.am  2011-09-27 14:26:23 UTC (rev 17061)
@@ -122,6 +122,7 @@
  gnunet-service-dht-new.c gnunet-service-dht.h \
  gnunet-service-dht_clients.c gnunet-service-dht_clients.h \
  gnunet-service-dht_datacache.c gnunet-service-dht_datacache.h \
+ gnunet-service-dht_hello.c gnunet-service-dht_hello.h \
  gnunet-service-dht_nse.c gnunet-service-dht_nse.h \
  gnunet-service-dht_neighbours.c gnunet-service-dht_neighbours.h \
  gnunet-service-dht_routing.c gnunet-service-dht_routing.h 

Modified: gnunet/src/dht/gnunet-service-dht-new.c
===================================================================
--- gnunet/src/dht/gnunet-service-dht-new.c     2011-09-27 14:20:12 UTC (rev 
17060)
+++ gnunet/src/dht/gnunet-service-dht-new.c     2011-09-27 14:26:23 UTC (rev 
17061)
@@ -34,6 +34,7 @@
 #include "gnunet-service-dht.h"
 #include "gnunet-service-dht_clients.h"
 #include "gnunet-service-dht_datacache.h"
+#include "gnunet-service-dht_hello.h"
 #include "gnunet-service-dht_neighbours.h"
 #include "gnunet-service-dht_nse.h"
 #include "gnunet-service-dht_routing.h"
@@ -114,6 +115,7 @@
   GDS_DATACACHE_done ();
   GDS_ROUTING_done ();
   GDS_CLIENTS_done ();
+  GDS_HELLO_done ();
   GDS_NSE_done ();
   if (GDS_block_context != NULL)
   {
@@ -147,6 +149,7 @@
   GDS_ROUTING_init ();
   GDS_NSE_init ();
   GDS_DATACACHE_init ();
+  GDS_HELLO_init ();
   GDS_CLIENTS_init (server);
   if (GNUNET_OK !=
       GDS_NEIGHBOURS_init ())

Added: gnunet/src/dht/gnunet-service-dht_hello.c
===================================================================
--- gnunet/src/dht/gnunet-service-dht_hello.c                           (rev 0)
+++ gnunet/src/dht/gnunet-service-dht_hello.c   2011-09-27 14:26:23 UTC (rev 
17061)
@@ -0,0 +1,139 @@
+/*
+     This file is part of GNUnet.
+     (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
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file dht/gnunet-service-dht_hello.c
+ * @brief GNUnet DHT integration with peerinfo
+ * @author Christian Grothoff
+ *
+ * TODO:
+ * - consider adding mechanism to remove expired HELLOs
+ */
+#include "platform.h"
+#include "gnunet-service-dht.h"
+#include "gnunet-service-dht_hello.h"
+#include "gnunet_peerinfo_service.h"
+
+
+/**
+ * Handle for peerinfo notifications.
+ */
+static struct GNUNET_PEERINFO_NotifyContext *pnc;
+
+/**
+ * Hash map of peers to HELLOs.
+ */
+static struct GNUNET_CONTAINER_MultiHashMap *peer_to_hello;
+
+
+/**
+ * Obtain a peer's HELLO if available
+ *
+ * @param peer peer to look for a HELLO from
+ * @return HELLO for the given peer
+ */
+const struct GNUNET_HELLO_Message *
+GDS_HELLO_get (const struct GNUNET_PeerIdentity *peer)
+{
+  return GNUNET_CONTAINER_multihashmap_get (peer_to_hello,
+                                           &peer->hashPubKey);
+}
+
+
+/**
+ * Function called for each HELLO known to PEERINFO.
+ *
+ * @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
+ */
+static void
+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;
+
+  if (hello == NULL)
+    return;
+  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_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));
+}
+
+
+/**
+ * Initialize HELLO subsystem.
+ */
+void
+GDS_HELLO_init ()
+{
+  pnc = GNUNET_PEERINFO_notify (GDS_cfg,
+                               &process_hello,
+                               NULL);
+  peer_to_hello = GNUNET_CONTAINER_multihashmap_create (256);
+}
+
+
+/**
+ * Free memory occopied by the HELLO.
+ */
+static int
+free_hello (void *cls,
+           const GNUNET_HashCode *key,
+           void *hello)
+{
+  GNUNET_free (hello);
+  return GNUNET_OK;
+}
+
+
+/**
+ * Shutdown HELLO subsystem.
+ */
+void
+GDS_HELLO_done ()
+{
+  if (NULL != pnc)
+  {
+    GNUNET_PEERINFO_notify_cancel (pnc);
+    pnc = NULL;
+  }
+  GNUNET_CONTAINER_multihashmap_iterate (peer_to_hello,
+                                        &free_hello,
+                                        NULL);
+  GNUNET_CONTAINER_multihashmap_destroy (peer_to_hello);
+}
+
+/* end of gnunet-service-dht_hello.c */

Added: gnunet/src/dht/gnunet-service-dht_hello.h
===================================================================
--- gnunet/src/dht/gnunet-service-dht_hello.h                           (rev 0)
+++ gnunet/src/dht/gnunet-service-dht_hello.h   2011-09-27 14:26:23 UTC (rev 
17061)
@@ -0,0 +1,55 @@
+/*
+     This file is part of GNUnet.
+     (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
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file dht/gnunet-service-dht_hello.h
+ * @brief GNUnet DHT integration with peerinfo
+ * @author Christian Grothoff
+ */
+#ifndef GNUNET_SERVICE_DHT_HELLO_H
+#define GNUNET_SERVICE_DHT_HELLO_H
+
+#include "gnunet_util_lib.h"
+#include "gnunet_hello_lib.h"
+
+/**
+ * Obtain a peer's HELLO if available
+ *
+ * @param peer peer to look for a HELLO from
+ * @return HELLO for the given peer
+ */
+const struct GNUNET_HELLO_Message *
+GDS_HELLO_get (const struct GNUNET_PeerIdentity *peer);
+
+
+/**
+ * Initialize HELLO subsystem.
+ */
+void
+GDS_HELLO_init (void);
+
+
+/**
+ * Shutdown HELLO subsystem.
+ */
+void
+GDS_HELLO_done (void);
+
+#endif

Modified: gnunet/src/dht/gnunet-service-dht_neighbours.c
===================================================================
--- gnunet/src/dht/gnunet-service-dht_neighbours.c      2011-09-27 14:20:12 UTC 
(rev 17060)
+++ gnunet/src/dht/gnunet-service-dht_neighbours.c      2011-09-27 14:26:23 UTC 
(rev 17061)
@@ -38,11 +38,11 @@
 #include "gnunet_hello_lib.h"
 #include "gnunet_dht_service.h"
 #include "gnunet_statistics_service.h"
-#include "gnunet_peerinfo_service.h"
 #include "dht.h"
 #include "gnunet-service-dht.h"
 #include "gnunet-service-dht_clients.h"
 #include "gnunet-service-dht_datacache.h"
+#include "gnunet-service-dht_hello.h"
 #include "gnunet-service-dht_neighbours.h"
 #include "gnunet-service-dht_nse.h"
 #include "gnunet-service-dht_routing.h"
@@ -329,12 +329,6 @@
   struct GNUNET_CORE_InformationRequestContext *info_ctx;
 
   /**
-   * HELLO message for the peer, NULL if not known.  FIXME: track
-   * separately? FIXME: free!?
-   */
-  struct GNUNET_HELLO_Message *hello;
-
-  /**
    * Task for scheduling preference updates
    */
   GNUNET_SCHEDULER_TaskIdentifier preference_task;
@@ -422,12 +416,7 @@
  */
 static struct GNUNET_CORE_Handle *coreAPI;
 
-/**
- * Handle for peerinfo notifications.
- */
-static struct GNUNET_PEERINFO_NotifyContext *pnc;
 
-
 /**
  * Find the optimal bucket for this key.
  *
@@ -1533,6 +1522,7 @@
   struct PeerInfo *peer;
   unsigned int choice;
   GNUNET_HashCode mhash;
+  const struct GNUNET_HELLO_Message *hello;
 
   /* first, check about our own HELLO */
   if (NULL != GDS_my_hello)
@@ -1574,8 +1564,9 @@
       if (peer == NULL)
        peer = bucket->head;
       GNUNET_BLOCK_mingle_hash (&peer->id.hashPubKey, bf_mutator, &mhash);
+      hello = GDS_HELLO_get (&peer->id);
     }
-  while ( (peer->hello == NULL) ||
+  while ( (hello == NULL) ||
          (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (bf, &mhash)) );
   GDS_NEIGHBOURS_handle_reply (sender,
                               GNUNET_BLOCK_TYPE_DHT_HELLO,
@@ -1583,8 +1574,8 @@
                               key,
                               0, NULL,
                               0, NULL,
-                              peer->hello,
-                              GNUNET_HELLO_size (peer->hello));    
+                              hello,
+                              GNUNET_HELLO_size (hello));    
 }
 
 
@@ -1832,29 +1823,6 @@
 
 
 /**
- * Function called for each HELLO known to PEERINFO.
- *
- * @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
- */
-static void
-process_hello (void *cls,
-              const struct GNUNET_PeerIdentity *
-              peer,
-              const struct GNUNET_HELLO_Message *
-              hello, const char *err_msg)
-{
-  // FIXME: consider moving HELLO processing to another file!
-  // FIXME: first, filter HELLOs without addresses (!)
-  // FIXME: track HELLOs (for responding to FIND PEER requests)
-  // FIXME: add code to possibly ask core to establish connections
-  //        (using our own peerinfo is better than using FIND PEER!)
-}
-
-
-/**
  * Initialize neighbours subsystem.
  *
  * @return GNUNET_OK on success, GNUNET_SYSERR on error
@@ -1887,9 +1855,6 @@
   if (coreAPI == NULL)
     return GNUNET_SYSERR;
   all_known_peers = GNUNET_CONTAINER_multihashmap_create (256);
-  pnc = GNUNET_PEERINFO_notify (GDS_cfg,
-                               &process_hello,
-                               NULL);
   return GNUNET_OK;
 }
 
@@ -1902,11 +1867,6 @@
 {
   if (coreAPI == NULL)
     return;
-  if (NULL != pnc)
-  {
-    GNUNET_PEERINFO_notify_cancel (pnc);
-    pnc = NULL;
-  }
   GNUNET_CORE_disconnect (coreAPI);
   coreAPI = NULL;    
   GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (all_known_peers));




reply via email to

[Prev in Thread] Current Thread [Next in Thread]