gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet] 01/02: consider HELLOs also from PUTs, remove exact duplicates


From: gnunet
Subject: [gnunet] 01/02: consider HELLOs also from PUTs, remove exact duplicates even if block type is unknown
Date: Sat, 12 Mar 2022 09:40:01 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository gnunet.

commit aca54f89d9d95caf1b3535185208b83274d937a7
Author: Christian Grothoff <grothoff@gnunet.org>
AuthorDate: Sat Mar 12 08:15:28 2022 +0100

    consider HELLOs also from PUTs, remove exact duplicates even if block type 
is unknown
---
 src/dht/Makefile.am                     |  1 +
 src/dht/gnunet-service-dht_neighbours.c | 43 ++++++++++++++++++++++-----------
 src/dht/gnunet-service-dht_routing.c    | 18 ++++++++++++++
 src/include/gnunet_block_group_lib.h    |  2 +-
 src/include/gnunet_block_lib.h          |  2 +-
 5 files changed, 50 insertions(+), 16 deletions(-)

diff --git a/src/dht/Makefile.am b/src/dht/Makefile.am
index 1f1451e83..68a17723d 100644
--- a/src/dht/Makefile.am
+++ b/src/dht/Makefile.am
@@ -71,6 +71,7 @@ gnunet_service_dht_LDADD = \
   $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \
   $(top_builddir)/src/hello/libgnunethello.la \
   $(top_builddir)/src/block/libgnunetblock.la \
+  $(top_builddir)/src/block/libgnunetblockgroup.la \
   $(top_builddir)/src/datacache/libgnunetdatacache.la \
   $(top_builddir)/src/util/libgnunetutil.la \
   -lm
diff --git a/src/dht/gnunet-service-dht_neighbours.c 
b/src/dht/gnunet-service-dht_neighbours.c
index 9d27d6a88..d9495ce14 100644
--- a/src/dht/gnunet-service-dht_neighbours.c
+++ b/src/dht/gnunet-service-dht_neighbours.c
@@ -1284,6 +1284,31 @@ get_target_peers (const struct GNUNET_HashCode *key,
 }
 
 
+/**
+ * If we got a HELLO, consider it for our own routing table 
+ *
+ * @param bd block data we got 
+ */
+static void
+hello_check (const struct GDS_DATACACHE_BlockData *bd)
+{
+  struct GNUNET_PeerIdentity pid;
+  struct GNUNET_HELLO_Builder *b;
+
+  if (GNUNET_BLOCK_TYPE_DHT_URL_HELLO != bd->type)
+    return;
+
+  b = GNUNET_HELLO_builder_from_block (bd->data,
+                                       bd->data_size);
+  if (GNUNET_YES != disable_try_connect)
+    GNUNET_HELLO_builder_iterate (b,
+                                  &pid,
+                                  &GDS_try_connect,
+                                  &pid);
+  GNUNET_HELLO_builder_free (b);
+}
+
+
 enum GNUNET_GenericReturnValue
 GDS_NEIGHBOURS_handle_put (const struct GDS_DATACACHE_BlockData *bd,
                            enum GNUNET_DHT_RouteOption options,
@@ -1318,6 +1343,9 @@ GDS_NEIGHBOURS_handle_put (const struct 
GDS_DATACACHE_BlockData *bd,
               GNUNET_h2s (&bd->key),
               (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE) ? "x" : "-",
               (options & GNUNET_DHT_RO_RECORD_ROUTE) ? "R" : "-");
+  
+  /* if we got a HELLO, consider it for our own routing table */
+  hello_check (bd);
   GNUNET_CONTAINER_bloomfilter_add (bf,
                                     &GDS_my_identity_hash);
   GNUNET_STATISTICS_update (GDS_stats,
@@ -2470,20 +2498,7 @@ handle_dht_p2p_result (void *cls,
   }
 
   /* if we got a HELLO, consider it for our own routing table */
-  if (GNUNET_BLOCK_TYPE_DHT_URL_HELLO == bd.type)
-  {
-    struct GNUNET_PeerIdentity pid;
-    struct GNUNET_HELLO_Builder *b;
-
-    b = GNUNET_HELLO_builder_from_block (bd.data,
-                                         bd.data_size);
-    if (GNUNET_YES != disable_try_connect)
-      GNUNET_HELLO_builder_iterate (b,
-                                    &pid,
-                                    &GDS_try_connect,
-                                    &pid);
-    GNUNET_HELLO_builder_free (b);
-  }
+  hello_check (&bd);
 
   /* First, check if 'peer' is already on the path, and if
      so, truncate it instead of expanding. */
diff --git a/src/dht/gnunet-service-dht_routing.c 
b/src/dht/gnunet-service-dht_routing.c
index 05902b941..6deb5fa16 100644
--- a/src/dht/gnunet-service-dht_routing.c
+++ b/src/dht/gnunet-service-dht_routing.c
@@ -27,6 +27,7 @@
 #include "gnunet-service-dht_neighbours.h"
 #include "gnunet-service-dht_routing.h"
 #include "gnunet-service-dht.h"
+#include "gnunet_block_group_lib.h"
 
 
 /**
@@ -174,6 +175,22 @@ process (void *cls,
               GNUNET_h2s (&bdx.key),
               bdx.type,
               eval);
+  if (GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED == eval)
+  {
+    /* If we do not know the block type, we still filter
+       exact duplicates by the block content */
+    struct GNUNET_HashCode chash;
+    
+    GNUNET_CRYPTO_hash (bdx.data,
+                        bdx.data_size,
+                        &chash);
+    if (GNUNET_YES ==
+        GNUNET_BLOCK_GROUP_bf_test_and_set (rr->bg,
+                                            &chash))
+      eval = GNUNET_BLOCK_REPLY_OK_DUPLICATE;
+    else
+      eval = GNUNET_BLOCK_REPLY_OK_MORE;
+  }
   switch (eval)
   {
   case GNUNET_BLOCK_REPLY_OK_MORE:
@@ -319,6 +336,7 @@ try_combine_recent (void *cls,
  *
  * @param sender peer that originated the request
  * @param type type of the block
+ * @param[in] bg block group for filtering duplicate replies
  * @param options options for processing
  * @param key key for the content
  * @param xquery extended query
diff --git a/src/include/gnunet_block_group_lib.h 
b/src/include/gnunet_block_group_lib.h
index 6cb601757..b03e913c6 100644
--- a/src/include/gnunet_block_group_lib.h
+++ b/src/include/gnunet_block_group_lib.h
@@ -94,7 +94,7 @@ GNUNET_BLOCK_GROUP_bf_create (void *cls,
  * @return #GNUNET_YES if @a hc is (likely) a duplicate
  *         #GNUNET_NO if @a hc was definitively not in @bg (but now is)
  */
-int
+enum GNUNET_GenericReturnValue
 GNUNET_BLOCK_GROUP_bf_test_and_set (struct GNUNET_BLOCK_Group *bg,
                                     const struct GNUNET_HashCode *hc);
 
diff --git a/src/include/gnunet_block_lib.h b/src/include/gnunet_block_lib.h
index 463c7af9f..515b8256c 100644
--- a/src/include/gnunet_block_lib.h
+++ b/src/include/gnunet_block_lib.h
@@ -294,7 +294,7 @@ GNUNET_BLOCK_group_destroy (struct GNUNET_BLOCK_Group *bg);
  *
  * @param ctx block contxt
  * @param type block type
- * @param group block group to use for evaluation
+ * @param[in,out] group block group to use for evaluation
  * @param query original query (hash)
  * @param xquery extrended query data (can be NULL, depending on type)
  * @param xquery_size number of bytes in @a xquery

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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