aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2015-10-30 13:23:40 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2015-10-30 13:23:40 +0000
commitcd1a8c319e890e69a6260a6ae99d1023fc6d49ac (patch)
tree32fb7dfb169111bb4b967ff56f08a01387525ea1 /src
parente54eeaca87f5bfbac6cb7cac51ab97c7af9613b6 (diff)
downloadgnunet-cd1a8c319e890e69a6260a6ae99d1023fc6d49ac.tar.gz
gnunet-cd1a8c319e890e69a6260a6ae99d1023fc6d49ac.zip
- fix flat plugin
Diffstat (limited to 'src')
-rw-r--r--src/namestore/plugin_namestore_flat.c114
1 files changed, 59 insertions, 55 deletions
diff --git a/src/namestore/plugin_namestore_flat.c b/src/namestore/plugin_namestore_flat.c
index 77a0ef405..0e6a2934c 100644
--- a/src/namestore/plugin_namestore_flat.c
+++ b/src/namestore/plugin_namestore_flat.c
@@ -108,11 +108,6 @@ struct FlatFileEntry
108 struct GNUNET_GNSRECORD_Data *record_data; 108 struct GNUNET_GNSRECORD_Data *record_data;
109 109
110 /** 110 /**
111 * Record data size
112 */
113 size_t data_size;
114
115 /**
116 * Label 111 * Label
117 */ 112 */
118 char *label; 113 char *label;
@@ -133,7 +128,7 @@ static int
133database_setup (struct Plugin *plugin) 128database_setup (struct Plugin *plugin)
134{ 129{
135 char *afsdir; 130 char *afsdir;
136 char *key_str; 131 char *key;
137 char *record_data; 132 char *record_data;
138 char *zone_private_key; 133 char *zone_private_key;
139 char *record_data_b64; 134 char *record_data_b64;
@@ -144,6 +139,7 @@ database_setup (struct Plugin *plugin)
144 char *record_count; 139 char *record_count;
145 size_t record_data_size; 140 size_t record_data_size;
146 size_t size; 141 size_t size;
142 size_t key_len;
147 struct GNUNET_HashCode hkey; 143 struct GNUNET_HashCode hkey;
148 struct GNUNET_DISK_FileHandle *fh; 144 struct GNUNET_DISK_FileHandle *fh;
149 struct FlatFileEntry *entry; 145 struct FlatFileEntry *entry;
@@ -245,15 +241,16 @@ database_setup (struct Plugin *plugin)
245 GNUNET_STRINGS_base64_decode (zone_private_key, 241 GNUNET_STRINGS_base64_decode (zone_private_key,
246 strlen (zone_private_key), 242 strlen (zone_private_key),
247 (char**)&entry->private_key); 243 (char**)&entry->private_key);
248 key_str = GNUNET_malloc (strlen (label) + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)); 244 key_len = strlen (label) + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey);
249 memcpy (key_str, label, strlen (label)); 245 key = GNUNET_malloc (strlen (label) + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
250 memcpy (key_str+strlen(label), 246 memcpy (key, label, strlen (label));
247 memcpy (key+strlen(label),
251 entry->private_key, 248 entry->private_key,
252 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)); 249 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
253 GNUNET_CRYPTO_hash (key_str, 250 GNUNET_CRYPTO_hash (key,
254 strlen (key_str), 251 key_len,
255 &hkey); 252 &hkey);
256 GNUNET_free (key_str); 253 GNUNET_free (key);
257 if (GNUNET_OK != 254 if (GNUNET_OK !=
258 GNUNET_CONTAINER_multihashmap_put (plugin->hm, 255 GNUNET_CONTAINER_multihashmap_put (plugin->hm,
259 &hkey, 256 &hkey,
@@ -287,15 +284,27 @@ store_and_free_entries (void *cls,
287 char *rvalue; 284 char *rvalue;
288 char *record_count; 285 char *record_count;
289 char *record_data_b64; 286 char *record_data_b64;
287 size_t data_size;
290 288
291 GNUNET_STRINGS_base64_encode ((char*)entry->private_key, 289 GNUNET_STRINGS_base64_encode ((char*)entry->private_key,
292 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), 290 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey),
293 &zone_private_key); 291 &zone_private_key);
294 GNUNET_asprintf (&rvalue, "%lu", entry->rvalue); 292 GNUNET_asprintf (&rvalue, "%lu", entry->rvalue);
295 GNUNET_asprintf (&record_count, "%u", entry->record_count); 293 GNUNET_asprintf (&record_count, "%u", entry->record_count);
296 294
297 GNUNET_STRINGS_base64_encode ((char*)entry->record_data, 295 data_size = GNUNET_GNSRECORD_records_get_size (entry->record_count,
298 entry->data_size, 296 entry->record_data);
297 char data[data_size];
298 if (data_size != GNUNET_GNSRECORD_records_serialize (entry->record_count,
299 entry->record_data,
300 data_size,
301 data))
302 {
303 GNUNET_break (0);
304 return GNUNET_SYSERR;
305 }
306 GNUNET_STRINGS_base64_encode (data,
307 data_size,
299 &record_data_b64); 308 &record_data_b64);
300 309
301 GNUNET_asprintf (&line, 310 GNUNET_asprintf (&line,
@@ -372,39 +381,26 @@ namestore_store_records (void *cls,
372{ 381{
373 struct Plugin *plugin = cls; 382 struct Plugin *plugin = cls;
374 uint64_t rvalue; 383 uint64_t rvalue;
375 size_t data_size; 384 size_t key_len;
376 char *key_str; 385 char *key;
377 struct GNUNET_HashCode hkey; 386 struct GNUNET_HashCode hkey;
378 struct FlatFileEntry *entry; 387 struct FlatFileEntry *entry;
388 int i;
379 389
380 rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); 390 rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
381 data_size = GNUNET_GNSRECORD_records_get_size (rd_count, rd); 391 key_len = strlen (label) + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey);
382 if (data_size > 64 * 65536) 392 key = GNUNET_malloc (key_len);
383 { 393 memcpy (key, label, strlen (label));
384 GNUNET_break (0); 394 memcpy (key+strlen(label),
385 return GNUNET_SYSERR;
386 }
387 char data[data_size];
388
389 if (data_size != GNUNET_GNSRECORD_records_serialize (rd_count, rd,
390 data_size, data))
391 {
392 GNUNET_break (0);
393 return GNUNET_SYSERR;
394 }
395
396 key_str = GNUNET_malloc (strlen (label) + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
397 memcpy (key_str, label, strlen (label));
398 memcpy (key_str+strlen(label),
399 zone_key, 395 zone_key,
400 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)); 396 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
401 GNUNET_CRYPTO_hash (key_str, 397 GNUNET_CRYPTO_hash (key,
402 strlen (key_str), 398 key_len,
403 &hkey); 399 &hkey);
404 400
405 GNUNET_CONTAINER_multihashmap_remove_all (plugin->hm, &hkey); 401 GNUNET_CONTAINER_multihashmap_remove_all (plugin->hm, &hkey);
406 402
407 if (0 != rd_count) 403 if (0 < rd_count)
408 { 404 {
409 entry = GNUNET_malloc (sizeof (struct FlatFileEntry)); 405 entry = GNUNET_malloc (sizeof (struct FlatFileEntry));
410 entry->private_key = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)); 406 entry->private_key = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
@@ -416,9 +412,16 @@ namestore_store_records (void *cls,
416 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)); 412 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
417 entry->rvalue = rvalue; 413 entry->rvalue = rvalue;
418 entry->record_count = rd_count; 414 entry->record_count = rd_count;
419 entry->data_size = data_size; 415 entry->record_data = GNUNET_malloc (sizeof (struct GNUNET_GNSRECORD_Data) * rd_count);
420 entry->record_data = GNUNET_malloc (data_size); 416 for (i = 0; i < rd_count; i++)
421 memcpy (entry->record_data, data, data_size); 417 {
418 entry->record_data[i].expiration_time = rd[i].expiration_time;
419 entry->record_data[i].record_type = rd[i].record_type;
420 entry->record_data[i].flags = rd[i].flags;
421 entry->record_data[i].data_size = rd[i].data_size;
422 entry->record_data[i].data = GNUNET_malloc (rd[i].data_size);
423 memcpy ((char*)entry->record_data[i].data, rd[i].data, rd[i].data_size);
424 }
422 return GNUNET_CONTAINER_multihashmap_put (plugin->hm, 425 return GNUNET_CONTAINER_multihashmap_put (plugin->hm,
423 &hkey, 426 &hkey,
424 entry, 427 entry,
@@ -448,22 +451,24 @@ namestore_lookup_records (void *cls,
448 struct Plugin *plugin = cls; 451 struct Plugin *plugin = cls;
449 struct FlatFileEntry *entry; 452 struct FlatFileEntry *entry;
450 struct GNUNET_HashCode hkey; 453 struct GNUNET_HashCode hkey;
451 char *key_str; 454 char *key;
455 size_t key_len;
452 456
453 if (NULL == zone) 457 if (NULL == zone)
454 { 458 {
455 return GNUNET_SYSERR; 459 return GNUNET_SYSERR;
456 } 460 }
457 key_str = GNUNET_malloc (strlen (label) + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)); 461 key_len = strlen (label) + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey);
458 memcpy (key_str, label, strlen (label)); 462 key = GNUNET_malloc (key_len);
459 memcpy (key_str+strlen(label), 463 memcpy (key, label, strlen (label));
464 memcpy (key+strlen(label),
460 zone, 465 zone,
461 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)); 466 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
462 GNUNET_CRYPTO_hash (key_str, 467 GNUNET_CRYPTO_hash (key,
463 strlen (key_str), 468 key_len,
464 &hkey); 469 &hkey);
465 GNUNET_free (key_str); 470 GNUNET_free (key);
466 471
467 entry = GNUNET_CONTAINER_multihashmap_get (plugin->hm, &hkey); 472 entry = GNUNET_CONTAINER_multihashmap_get (plugin->hm, &hkey);
468 473
469 if (NULL == entry) 474 if (NULL == entry)
@@ -482,15 +487,14 @@ iterate_zones (void *cls,
482 struct Plugin *plugin = cls; 487 struct Plugin *plugin = cls;
483 struct FlatFileEntry *entry = value; 488 struct FlatFileEntry *entry = value;
484 489
485
486 if ((plugin->target_offset > plugin->offset) || 490 if ((plugin->target_offset > plugin->offset) ||
487 (0 != memcmp (entry->private_key, 491 ( (NULL != plugin->iter_zone) &&
488 plugin->iter_zone, 492 (0 != memcmp (entry->private_key,
489 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)))) { 493 plugin->iter_zone,
494 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))))) {
490 plugin->offset++; 495 plugin->offset++;
491 return GNUNET_YES; 496 return GNUNET_YES;
492 } 497 }
493
494 plugin->iter (plugin->iter_cls, 498 plugin->iter (plugin->iter_cls,
495 entry->private_key, 499 entry->private_key,
496 entry->label, 500 entry->label,
@@ -521,7 +525,7 @@ namestore_iterate_records (void *cls,
521 plugin->target_offset = offset; 525 plugin->target_offset = offset;
522 plugin->offset = 0; 526 plugin->offset = 0;
523 plugin->iter = iter; 527 plugin->iter = iter;
524 plugin->iter_cls = cls; 528 plugin->iter_cls = iter_cls;
525 plugin->iter_zone = zone; 529 plugin->iter_zone = zone;
526 plugin->iter_result_found = GNUNET_NO; 530 plugin->iter_result_found = GNUNET_NO;
527 GNUNET_CONTAINER_multihashmap_iterate (plugin->hm, 531 GNUNET_CONTAINER_multihashmap_iterate (plugin->hm,