aboutsummaryrefslogtreecommitdiff
path: root/src/gns/gnunet-dns2gns.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gns/gnunet-dns2gns.c')
-rw-r--r--src/gns/gnunet-dns2gns.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/gns/gnunet-dns2gns.c b/src/gns/gnunet-dns2gns.c
index 1e88ef056..74309f554 100644
--- a/src/gns/gnunet-dns2gns.c
+++ b/src/gns/gnunet-dns2gns.c
@@ -190,6 +190,31 @@ 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 tmp_answer = request->packet->answers[idx];
212 memcpy (&request->packet->answers[idx], &request->packet->answers[r_idx],
213 sizeof (struct GNUNET_DNSPARSER_Record));
214 memcpy (&request->packet->answers[r_idx], &tmp_answer,
215 sizeof (struct GNUNET_DNSPARSER_Record));
216 }
217}
193 218
194/** 219/**
195 * Send the response for the given request and clean up. 220 * Send the response for the given request and clean up.
@@ -203,6 +228,7 @@ send_response (struct Request *request)
203 size_t size; 228 size_t size;
204 ssize_t sret; 229 ssize_t sret;
205 230
231 shuffle_answers (request);
206 if (GNUNET_SYSERR == 232 if (GNUNET_SYSERR ==
207 GNUNET_DNSPARSER_pack (request->packet, 233 GNUNET_DNSPARSER_pack (request->packet,
208 UINT16_MAX /* is this not too much? */, 234 UINT16_MAX /* is this not too much? */,
@@ -334,8 +360,6 @@ result_processor (void *cls,
334 // packet->flags.opcode = GNUNET_TUN_DNS_OPCODE_STATUS; // ??? 360 // packet->flags.opcode = GNUNET_TUN_DNS_OPCODE_STATUS; // ???
335 for (uint32_t i = 0; i < rd_count; i++) 361 for (uint32_t i = 0; i < rd_count; i++)
336 { 362 {
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; 363 rec.expiration_time.abs_value_us = rd[i].expiration_time;
340 switch (rd[i].record_type) 364 switch (rd[i].record_type)
341 { 365 {