aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2020-06-21 22:06:35 +0200
committerMartin Schanzenbach <mschanzenbach@posteo.de>2020-06-21 22:06:35 +0200
commit612704d69e365b8715804d41a57e533f227862bd (patch)
treecb8ce04c4b38daec6823ea4a559bcfc9eb8e2e9a /src
parentd6d7bf7df8e6ff09aa470b4334b9418646c617b5 (diff)
downloadgnunet-612704d69e365b8715804d41a57e533f227862bd.tar.gz
gnunet-612704d69e365b8715804d41a57e533f227862bd.zip
GNS: dns2gns now randomizes answers from GNS record set
Diffstat (limited to 'src')
-rw-r--r--src/gns/gnunet-dns2gns.c30
1 files 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)
190 } 190 }
191} 191}
192 192
193/**
194 * Shuffle answers
195 * Fisher-Yates (aka Knuth) Shuffle
196 *
197 * @param request context for the request (with answers)
198 */
199static void
200shuffle_answers (struct Request *request)
201{
202 unsigned int idx = request->packet->num_answers;
203 unsigned int r_idx;
204 struct GNUNET_DNSPARSER_Record tmp_answer;
205
206 while (0 != idx)
207 {
208 r_idx = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
209 request->packet->num_answers);
210 idx--;
211 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
212 "Swapping %u with %u\n", idx, r_idx);
213 tmp_answer = request->packet->answers[idx];
214 memcpy (&request->packet->answers[idx], &request->packet->answers[r_idx],
215 sizeof (struct GNUNET_DNSPARSER_Record));
216 memcpy (&request->packet->answers[r_idx], &tmp_answer,
217 sizeof (struct GNUNET_DNSPARSER_Record));
218 }
219}
193 220
194/** 221/**
195 * Send the response for the given request and clean up. 222 * Send the response for the given request and clean up.
@@ -203,6 +230,7 @@ send_response (struct Request *request)
203 size_t size; 230 size_t size;
204 ssize_t sret; 231 ssize_t sret;
205 232
233 shuffle_answers (request);
206 if (GNUNET_SYSERR == 234 if (GNUNET_SYSERR ==
207 GNUNET_DNSPARSER_pack (request->packet, 235 GNUNET_DNSPARSER_pack (request->packet,
208 UINT16_MAX /* is this not too much? */, 236 UINT16_MAX /* is this not too much? */,
@@ -334,8 +362,6 @@ result_processor (void *cls,
334 // packet->flags.opcode = GNUNET_TUN_DNS_OPCODE_STATUS; // ??? 362 // packet->flags.opcode = GNUNET_TUN_DNS_OPCODE_STATUS; // ???
335 for (uint32_t i = 0; i < rd_count; i++) 363 for (uint32_t i = 0; i < rd_count; i++)
336 { 364 {
337 // FIXME: do we need to hanlde #GNUNET_GNSRECORD_RF_SHADOW_RECORD
338 // here? Or should we do this in libgnunetgns?
339 rec.expiration_time.abs_value_us = rd[i].expiration_time; 365 rec.expiration_time.abs_value_us = rd[i].expiration_time;
340 switch (rd[i].record_type) 366 switch (rd[i].record_type)
341 { 367 {