gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet] branch master updated: GNS: dns2gns now randomizes answers from


From: gnunet
Subject: [gnunet] branch master updated: GNS: dns2gns now randomizes answers from GNS record set
Date: Sun, 21 Jun 2020 22:12:14 +0200

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

martin-schanzenbach pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new 612704d69 GNS: dns2gns now randomizes answers from GNS record set
612704d69 is described below

commit 612704d69e365b8715804d41a57e533f227862bd
Author: Martin Schanzenbach <mschanzenbach@posteo.de>
AuthorDate: Sun Jun 21 22:06:35 2020 +0200

    GNS: dns2gns now randomizes answers from GNS record set
---
 src/gns/gnunet-dns2gns.c | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/src/gns/gnunet-dns2gns.c b/src/gns/gnunet-dns2gns.c
index 1e88ef056..5d8b6f117 100644
--- a/src/gns/gnunet-dns2gns.c
+++ b/src/gns/gnunet-dns2gns.c
@@ -190,6 +190,33 @@ do_shutdown (void *cls)
   }
 }
 
+/**
+ * Shuffle answers
+ * Fisher-Yates (aka Knuth) Shuffle
+ *
+ * @param request context for the request (with answers)
+ */
+static void
+shuffle_answers (struct Request *request)
+{
+  unsigned int idx = request->packet->num_answers;
+  unsigned int r_idx;
+  struct GNUNET_DNSPARSER_Record tmp_answer;
+
+  while (0 != idx)
+  {
+    r_idx = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+                                      request->packet->num_answers);
+    idx--;
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Swapping %u with %u\n", idx, r_idx);
+    tmp_answer = request->packet->answers[idx];
+    memcpy (&request->packet->answers[idx], &request->packet->answers[r_idx],
+            sizeof (struct GNUNET_DNSPARSER_Record));
+    memcpy (&request->packet->answers[r_idx], &tmp_answer,
+            sizeof (struct GNUNET_DNSPARSER_Record));
+  }
+}
 
 /**
  * Send the response for the given request and clean up.
@@ -203,6 +230,7 @@ send_response (struct Request *request)
   size_t size;
   ssize_t sret;
 
+  shuffle_answers (request);
   if (GNUNET_SYSERR ==
       GNUNET_DNSPARSER_pack (request->packet,
                              UINT16_MAX /* is this not too much? */,
@@ -334,8 +362,6 @@ result_processor (void *cls,
   // packet->flags.opcode = GNUNET_TUN_DNS_OPCODE_STATUS; // ???
   for (uint32_t i = 0; i < rd_count; i++)
   {
-    // FIXME: do we need to hanlde #GNUNET_GNSRECORD_RF_SHADOW_RECORD
-    // here? Or should we do this in libgnunetgns?
     rec.expiration_time.abs_value_us = rd[i].expiration_time;
     switch (rd[i].record_type)
     {

-- 
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]