aboutsummaryrefslogtreecommitdiff
path: root/src/gns/gnunet-service-gns.c
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2012-02-26 19:10:50 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2012-02-26 19:10:50 +0000
commit2ccdea00105e6821140f85b871f75fffe4439000 (patch)
tree60004b96a1adadcf437b7bcdbf78fd747c351d54 /src/gns/gnunet-service-gns.c
parent8be6916ef54f9952b099276d63ef1ebe4b88d4d6 (diff)
downloadgnunet-2ccdea00105e6821140f85b871f75fffe4439000.tar.gz
gnunet-2ccdea00105e6821140f85b871f75fffe4439000.zip
-adjusted dht block layout
Diffstat (limited to 'src/gns/gnunet-service-gns.c')
-rw-r--r--src/gns/gnunet-service-gns.c128
1 files changed, 34 insertions, 94 deletions
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c
index 135ed82d5..cb1c5fc7d 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -36,6 +36,7 @@
36#include "gnunet_dht_service.h" 36#include "gnunet_dht_service.h"
37#include "gnunet_namestore_service.h" 37#include "gnunet_namestore_service.h"
38#include "gnunet_gns_service.h" 38#include "gnunet_gns_service.h"
39#include "block_gns.h"
39#include "gns.h" 40#include "gns.h"
40 41
41/* Ignore for now not used anyway and probably never will */ 42/* Ignore for now not used anyway and probably never will */
@@ -207,85 +208,57 @@ process_authority_dht_result(void* cls,
207 size_t size, const void *data) 208 size_t size, const void *data)
208{ 209{
209 struct GNUNET_GNS_ResolverHandle *rh; 210 struct GNUNET_GNS_ResolverHandle *rh;
211 struct GNSNameRecordBlock *nrb;
212 struct GNSRecordBlock *rb;
210 uint32_t num_records; 213 uint32_t num_records;
211 uint16_t namelen;
212 char* name = NULL; 214 char* name = NULL;
213 struct GNUNET_CRYPTO_RsaSignature *signature;
214 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key;
215 int i; 215 int i;
216 char* pos;
217 GNUNET_HashCode zone, name_hash; 216 GNUNET_HashCode zone, name_hash;
217
218 //FIXME GNS block check
218 219
219 if (data == NULL) 220 if (data == NULL)
220 return; 221 return;
221 222
222 //FIXME check expiration? 223 //FIXME check expiration?
223 rh = (struct GNUNET_GNS_ResolverHandle *)cls; 224 rh = (struct GNUNET_GNS_ResolverHandle *)cls;
224 pos = (char*)data; 225 nrb = (struct GNSNameRecordBlock*)data;
225 226
226 GNUNET_DHT_get_stop (rh->get_handle); 227 GNUNET_DHT_get_stop (rh->get_handle);
227 rh->get_handle = NULL; 228 rh->get_handle = NULL;
228 num_records = ntohl(*pos); 229 num_records = ntohl(nrb->rd_count);
229 struct GNUNET_NAMESTORE_RecordData rd[num_records]; 230 struct GNUNET_NAMESTORE_RecordData rd[num_records];
231 name = (char*)&nrb[1];
232 rb = (struct GNSRecordBlock *)(&nrb[1] + strlen(name));
230 233
231 pos += sizeof(uint32_t);
232
233 for (i=0; i<num_records; i++) 234 for (i=0; i<num_records; i++)
234 { 235 {
235 namelen = ntohs(*pos);
236 pos += sizeof(uint16_t);
237
238 //name must be 0 terminated
239 name = pos;
240 pos += namelen;
241
242 rd[i].record_type = ntohl(*pos);
243 pos += sizeof(uint32_t);
244 236
245 rd[i].data_size = ntohl(*pos); 237 rd[i].record_type = ntohl(rb->type);
246 pos += sizeof(uint32_t); 238 rd[i].data_size = ntohl(rb->data_length);
247 239 rd[i].data = &rb[1];
248 rd[i].data = pos; 240 rd[i].expiration = GNUNET_TIME_absolute_ntoh(rb->expiration);
249 pos += rd[i].data_size; 241 rd[i].flags = ntohs(rb->flags);
250
251 rd[i].expiration = GNUNET_TIME_absolute_ntoh(
252 *((struct GNUNET_TIME_AbsoluteNBO*)pos));
253 pos += sizeof(struct GNUNET_TIME_AbsoluteNBO);
254
255 rd[i].flags = ntohs(*pos);
256 pos += sizeof(uint16_t);
257 242
258 if (strcmp(name, rh->query->name) && rd[i].record_type == rh->query->type) 243 if (strcmp(name, rh->query->name) &&
244 (rd[i].record_type == rh->query->type))
259 { 245 {
260 rh->answered = 1; 246 rh->answered = 1;
261 } 247 }
262 248
263 } 249 }
264 250
265 if ((((char*)data)-pos) <
266 (sizeof(struct GNUNET_CRYPTO_RsaSignature) +
267 sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)))
268 {
269 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
270 "Cannot parse signature/key in DHT response. Corrupted or Missing");
271 return;
272 }
273
274 signature = (struct GNUNET_CRYPTO_RsaSignature*)pos;
275 pos += sizeof(struct GNUNET_CRYPTO_RsaSignature);
276
277 public_key = (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded*)pos;
278 GNUNET_CRYPTO_hash(name, strlen(name), &name_hash); 251 GNUNET_CRYPTO_hash(name, strlen(name), &name_hash);
279 GNUNET_CRYPTO_hash_xor(key, &name_hash, &zone); 252 GNUNET_CRYPTO_hash_xor(key, &name_hash, &zone);
280 253
281 //Save to namestore 254 //Save to namestore
282 GNUNET_NAMESTORE_record_put (namestore_handle, 255 GNUNET_NAMESTORE_record_put (namestore_handle,
283 public_key, 256 &nrb->public_key,
284 name, 257 name,
285 exp, 258 exp,
286 num_records, 259 num_records,
287 rd, 260 rd,
288 signature, 261 &nrb->signature,
289 &on_namestore_record_put_result, //cont 262 &on_namestore_record_put_result, //cont
290 NULL); //cls 263 NULL); //cls
291 264
@@ -360,78 +333,45 @@ process_name_dht_result(void* cls,
360 size_t size, const void *data) 333 size_t size, const void *data)
361{ 334{
362 struct GNUNET_GNS_ResolverHandle *rh; 335 struct GNUNET_GNS_ResolverHandle *rh;
336 struct GNSNameRecordBlock *nrb;
337 struct GNSRecordBlock *rb;
363 uint32_t num_records; 338 uint32_t num_records;
364 uint16_t namelen;
365 char* name = NULL; 339 char* name = NULL;
366 struct GNUNET_CRYPTO_RsaSignature *signature;
367 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key;
368 int i; 340 int i;
369 char* pos;
370 GNUNET_HashCode zone, name_hash; 341 GNUNET_HashCode zone, name_hash;
371 342
372 if (data == NULL) 343 if (data == NULL)
373 return; 344 return;
374 345
375 //FIXME maybe check expiration here 346 //FIXME maybe check expiration here, check block type
376 347
377 rh = (struct GNUNET_GNS_ResolverHandle *)cls; 348 rh = (struct GNUNET_GNS_ResolverHandle *)cls;
378 pos = (char*)data; 349 nrb = (struct GNSNameRecordBlock*)data;
379
380 350
381 GNUNET_DHT_get_stop (rh->get_handle); 351 GNUNET_DHT_get_stop (rh->get_handle);
382 rh->get_handle = NULL; 352 rh->get_handle = NULL;
383 num_records = ntohl(*pos); 353 num_records = ntohl(nrb->rd_count);
384 struct GNUNET_NAMESTORE_RecordData rd[num_records]; 354 struct GNUNET_NAMESTORE_RecordData rd[num_records];
385 355
386 pos += sizeof(uint32_t); 356 name = (char*)&nrb[1];
357 rb = (struct GNSRecordBlock*)(&nrb[1] + strlen(name));
387 358
388 for (i=0; i<num_records; i++) 359 for (i=0; i<num_records; i++)
389 { 360 {
390 namelen = ntohs(*pos); 361 rd[i].record_type = ntohl(rb->type);
391 pos += sizeof(uint16_t); 362 rd[i].data_size = ntohl(rb->data_length);
392 363 rd[i].data = (char*)&rb[1];
393 //name must be 0 terminated 364 rd[i].expiration = GNUNET_TIME_absolute_ntoh(rb->expiration);
394 name = pos; 365 rd[i].flags = ntohs(rb->flags);
395 pos += namelen;
396
397 rd[i].record_type = ntohl(*pos);
398 pos += sizeof(uint32_t);
399
400 rd[i].data_size = ntohl(*pos);
401 pos += sizeof(uint32_t);
402
403 rd[i].data = pos;
404 pos += rd[i].data_size;
405
406 rd[i].expiration = GNUNET_TIME_absolute_ntoh(
407 *((struct GNUNET_TIME_AbsoluteNBO*)pos));
408 pos += sizeof(struct GNUNET_TIME_AbsoluteNBO);
409
410 rd[i].flags = ntohs(*pos);
411 pos += sizeof(uint16_t);
412 //FIXME class? 366 //FIXME class?
413 // 367 if (strcmp(name, rh->query->name) &&
414 if (strcmp(name, rh->query->name) && rd[i].record_type == rh->query->type) 368 (rd[i].record_type == rh->query->type))
415 { 369 {
416 rh->answered++; 370 rh->answered++;
417 } 371 }
418 372
419 } 373 }
420 374
421 if ((((char*)data)-pos) <
422 (sizeof(struct GNUNET_CRYPTO_RsaSignature) +
423 sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)))
424 {
425 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
426 "Cannot parse signature/key in DHT response. Corrupted or Missing");
427 return;
428 }
429
430 signature = (struct GNUNET_CRYPTO_RsaSignature*)pos;
431 pos += sizeof(struct GNUNET_CRYPTO_RsaSignature);
432
433 public_key = (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded*)pos;
434
435 GNUNET_CRYPTO_hash(name, strlen(name), &name_hash); 375 GNUNET_CRYPTO_hash(name, strlen(name), &name_hash);
436 GNUNET_CRYPTO_hash_xor(key, &name_hash, &zone); 376 GNUNET_CRYPTO_hash_xor(key, &name_hash, &zone);
437 377
@@ -440,12 +380,12 @@ process_name_dht_result(void* cls,
440 380
441 //Save to namestore 381 //Save to namestore
442 GNUNET_NAMESTORE_record_put (namestore_handle, 382 GNUNET_NAMESTORE_record_put (namestore_handle,
443 public_key, 383 &nrb->public_key,
444 name, 384 name,
445 exp, 385 exp,
446 num_records, 386 num_records,
447 rd, 387 rd,
448 signature, 388 &nrb->signature,
449 &on_namestore_record_put_result, //cont 389 &on_namestore_record_put_result, //cont
450 NULL); //cls 390 NULL); //cls
451 391