aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/plugin_namestore_flat.c
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2015-09-10 14:42:18 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2015-09-10 14:42:18 +0000
commit26cf681cd2fb59b62f8c6de139e00aa15eaf2ec3 (patch)
treebba9c218db3796d5d1fcda8a22ecc4785017e074 /src/namestore/plugin_namestore_flat.c
parentb5e08fdd9c1663e81afef784a6e3bd6b4552e23e (diff)
downloadgnunet-26cf681cd2fb59b62f8c6de139e00aa15eaf2ec3.tar.gz
gnunet-26cf681cd2fb59b62f8c6de139e00aa15eaf2ec3.zip
- update
Diffstat (limited to 'src/namestore/plugin_namestore_flat.c')
-rw-r--r--src/namestore/plugin_namestore_flat.c172
1 files changed, 75 insertions, 97 deletions
diff --git a/src/namestore/plugin_namestore_flat.c b/src/namestore/plugin_namestore_flat.c
index 846eac96a..77a0ef405 100644
--- a/src/namestore/plugin_namestore_flat.c
+++ b/src/namestore/plugin_namestore_flat.c
@@ -93,11 +93,6 @@ struct FlatFileEntry
93 struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key; 93 struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key;
94 94
95 /** 95 /**
96 * Entry zone pkey
97 */
98 struct GNUNET_CRYPTO_EcdsaPublicKey *pkey;
99
100 /**
101 * Record cound 96 * Record cound
102 */ 97 */
103 uint32_t record_count; 98 uint32_t record_count;
@@ -113,6 +108,11 @@ struct FlatFileEntry
113 struct GNUNET_GNSRECORD_Data *record_data; 108 struct GNUNET_GNSRECORD_Data *record_data;
114 109
115 /** 110 /**
111 * Record data size
112 */
113 size_t data_size;
114
115 /**
116 * Label 116 * Label
117 */ 117 */
118 char *label; 118 char *label;
@@ -136,7 +136,6 @@ database_setup (struct Plugin *plugin)
136 char *key_str; 136 char *key_str;
137 char *record_data; 137 char *record_data;
138 char *zone_private_key; 138 char *zone_private_key;
139 char *pkey;
140 char *record_data_b64; 139 char *record_data_b64;
141 char *buffer; 140 char *buffer;
142 char *line; 141 char *line;
@@ -210,53 +209,60 @@ database_setup (struct Plugin *plugin)
210 } 209 }
211 210
212 GNUNET_DISK_file_close (fh); 211 GNUNET_DISK_file_close (fh);
213 212 if (0 < size) {
214 line = strtok ("\n", buffer); 213 line = strtok (buffer, "\n");
215 while (line != NULL) { 214 while (line != NULL) {
216 zone_private_key = strtok (",", line); 215 zone_private_key = strtok (line, ",");
217 pkey = strtok (NULL, line); 216 if (NULL == zone_private_key)
218 rvalue = strtok (NULL, line); 217 break;
219 record_count = strtok (NULL, line); 218 rvalue = strtok (NULL, ",");
220 record_data_b64 = strtok (NULL, line); 219 if (NULL == rvalue)
221 label = strtok (NULL, line); 220 break;
222 line = strtok ("\n", buffer); 221 record_count = strtok (NULL, ",");
223 entry = GNUNET_malloc (sizeof (struct FlatFileEntry)); 222 if (NULL == record_count)
224 GNUNET_CRYPTO_ecdsa_public_key_from_string (pkey, 223 break;
225 strlen (pkey), 224 record_data_b64 = strtok (NULL, ",");
226 entry->pkey); 225 if (NULL == record_data_b64)
227 sscanf (rvalue, "%lu", &entry->rvalue); 226 break;
228 sscanf (record_count, "%u", &entry->record_count); 227 label = strtok (NULL, ",");
229 entry->label = GNUNET_strdup (label); 228 if (NULL == label)
230 record_data_size = GNUNET_STRINGS_base64_decode (record_data_b64, 229 break;
231 strlen (record_data_b64), 230 line = strtok (NULL, "\n");
232 &record_data); 231 entry = GNUNET_malloc (sizeof (struct FlatFileEntry));
233 entry->record_data = 232 sscanf (rvalue, "%lu", &entry->rvalue);
234 GNUNET_malloc (sizeof (struct GNUNET_GNSRECORD_Data) * entry->record_count); 233 sscanf (record_count, "%u", &entry->record_count);
235 GNUNET_GNSRECORD_records_deserialize (record_data_size, 234 entry->label = GNUNET_strdup (label);
236 record_data, 235 record_data_size = GNUNET_STRINGS_base64_decode (record_data_b64,
237 entry->record_count, 236 strlen (record_data_b64),
238 entry->record_data); 237 &record_data);
239 GNUNET_free (record_data); 238 entry->record_data =
240 GNUNET_STRINGS_base64_decode (zone_private_key, 239 GNUNET_malloc (sizeof (struct GNUNET_GNSRECORD_Data) * entry->record_count);
241 strlen (zone_private_key), 240 GNUNET_GNSRECORD_records_deserialize (record_data_size,
242 (char**)&entry->private_key); 241 record_data,
243 key_str = GNUNET_malloc (strlen (label) + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)); 242 entry->record_count,
244 memcpy (key_str, label, strlen (label)); 243 entry->record_data);
245 memcpy (key_str+strlen(label), 244 GNUNET_free (record_data);
246 entry->private_key, 245 GNUNET_STRINGS_base64_decode (zone_private_key,
247 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)); 246 strlen (zone_private_key),
248 GNUNET_CRYPTO_hash (key_str, 247 (char**)&entry->private_key);
249 strlen (key_str), 248 key_str = GNUNET_malloc (strlen (label) + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
250 &hkey); 249 memcpy (key_str, label, strlen (label));
251 GNUNET_free (key_str); 250 memcpy (key_str+strlen(label),
252 if (GNUNET_OK != 251 entry->private_key,
253 GNUNET_CONTAINER_multihashmap_put (plugin->hm, 252 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
254 &hkey, 253 GNUNET_CRYPTO_hash (key_str,
255 entry, 254 strlen (key_str),
256 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 255 &hkey);
257 { 256 GNUNET_free (key_str);
258 GNUNET_free (entry); 257 if (GNUNET_OK !=
259 GNUNET_break (0); 258 GNUNET_CONTAINER_multihashmap_put (plugin->hm,
259 &hkey,
260 entry,
261 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
262 {
263 GNUNET_free (entry);
264 GNUNET_break (0);
265 }
260 } 266 }
261 } 267 }
262 GNUNET_free (buffer); 268 GNUNET_free (buffer);
@@ -278,37 +284,23 @@ store_and_free_entries (void *cls,
278 struct FlatFileEntry *entry = value; 284 struct FlatFileEntry *entry = value;
279 char *line; 285 char *line;
280 char *zone_private_key; 286 char *zone_private_key;
281 char *pkey;
282 char *rvalue; 287 char *rvalue;
283 char *record_count; 288 char *record_count;
284 char *record_data_buf;
285 char *record_data_b64; 289 char *record_data_b64;
286 size_t record_data_len;
287 290
288 GNUNET_STRINGS_base64_encode ((char*)entry->private_key, 291 GNUNET_STRINGS_base64_encode ((char*)entry->private_key,
289 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), 292 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey),
290 &zone_private_key); 293 &zone_private_key);
291 pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (entry->pkey); 294 GNUNET_asprintf (&rvalue, "%lu", entry->rvalue);
292 GNUNET_asprintf (&rvalue, "%hhu", entry->rvalue);
293 GNUNET_asprintf (&record_count, "%u", entry->record_count); 295 GNUNET_asprintf (&record_count, "%u", entry->record_count);
294 296
295 record_data_len = GNUNET_GNSRECORD_records_get_size (entry->record_count, 297 GNUNET_STRINGS_base64_encode ((char*)entry->record_data,
296 entry->record_data); 298 entry->data_size,
297
298 record_data_buf = GNUNET_malloc (record_data_len);
299 GNUNET_GNSRECORD_records_serialize (entry->record_count,
300 entry->record_data,
301 record_data_len,
302 record_data_buf);
303
304 GNUNET_STRINGS_base64_encode (record_data_buf,
305 strlen (record_data_buf),
306 &record_data_b64); 299 &record_data_b64);
307 300
308 GNUNET_asprintf (&line, 301 GNUNET_asprintf (&line,
309 "%s,%s,%s,%s,%s,%s\n", 302 "%s,%s,%s,%s,%s\n",
310 zone_private_key, 303 zone_private_key,
311 pkey,
312 rvalue, 304 rvalue,
313 record_count, 305 record_count,
314 record_data_b64, 306 record_data_b64,
@@ -316,7 +308,6 @@ store_and_free_entries (void *cls,
316 308
317 GNUNET_free (rvalue); 309 GNUNET_free (rvalue);
318 GNUNET_free (record_count); 310 GNUNET_free (record_count);
319 GNUNET_free (record_data_buf);
320 GNUNET_free (record_data_b64); 311 GNUNET_free (record_data_b64);
321 312
322 GNUNET_DISK_file_write (fh, 313 GNUNET_DISK_file_write (fh,
@@ -324,7 +315,6 @@ store_and_free_entries (void *cls,
324 strlen (line)); 315 strlen (line));
325 316
326 GNUNET_free (entry->private_key); 317 GNUNET_free (entry->private_key);
327 GNUNET_free (entry->pkey);
328 GNUNET_free (entry->label); 318 GNUNET_free (entry->label);
329 GNUNET_free (entry->record_data); 319 GNUNET_free (entry->record_data);
330 GNUNET_free (entry); 320 GNUNET_free (entry);
@@ -349,8 +339,8 @@ database_shutdown (struct Plugin *plugin)
349 if (NULL == fh) 339 if (NULL == fh)
350 { 340 {
351 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 341 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
352 _("Unable to initialize file: %s.\n"), 342 _("Unable to initialize file: %s.\n"),
353 plugin->fn); 343 plugin->fn);
354 return; 344 return;
355 } 345 }
356 346
@@ -381,24 +371,12 @@ namestore_store_records (void *cls,
381 const struct GNUNET_GNSRECORD_Data *rd) 371 const struct GNUNET_GNSRECORD_Data *rd)
382{ 372{
383 struct Plugin *plugin = cls; 373 struct Plugin *plugin = cls;
384 struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
385 uint64_t rvalue; 374 uint64_t rvalue;
386 size_t data_size; 375 size_t data_size;
387 unsigned int i;
388 char *key_str; 376 char *key_str;
389 struct GNUNET_HashCode hkey; 377 struct GNUNET_HashCode hkey;
390 struct FlatFileEntry *entry; 378 struct FlatFileEntry *entry;
391 379
392 memset (&pkey, 0, sizeof (pkey));
393 for (i=0;i<rd_count;i++)
394 if (GNUNET_GNSRECORD_TYPE_PKEY == rd[i].record_type)
395 {
396 GNUNET_break (sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) == rd[i].data_size);
397 memcpy (&pkey,
398 rd[i].data,
399 rd[i].data_size);
400 break;
401 }
402 rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); 380 rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
403 data_size = GNUNET_GNSRECORD_records_get_size (rd_count, rd); 381 data_size = GNUNET_GNSRECORD_records_get_size (rd_count, rd);
404 if (data_size > 64 * 65536) 382 if (data_size > 64 * 65536)
@@ -430,17 +408,17 @@ namestore_store_records (void *cls,
430 { 408 {
431 entry = GNUNET_malloc (sizeof (struct FlatFileEntry)); 409 entry = GNUNET_malloc (sizeof (struct FlatFileEntry));
432 entry->private_key = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)); 410 entry->private_key = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
433 memcpy (&entry->private_key, 411 GNUNET_asprintf (&entry->label,
412 label,
413 strlen (label));
414 memcpy (entry->private_key,
434 zone_key, 415 zone_key,
435 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)); 416 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
436 entry->pkey = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
437 memcpy (entry->pkey,
438 &pkey,
439 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
440 entry->rvalue = rvalue; 417 entry->rvalue = rvalue;
441 entry->record_count = rd_count; 418 entry->record_count = rd_count;
419 entry->data_size = data_size;
442 entry->record_data = GNUNET_malloc (data_size); 420 entry->record_data = GNUNET_malloc (data_size);
443 memcpy (&entry->record_data, data, data_size); 421 memcpy (entry->record_data, data, data_size);
444 return GNUNET_CONTAINER_multihashmap_put (plugin->hm, 422 return GNUNET_CONTAINER_multihashmap_put (plugin->hm,
445 &hkey, 423 &hkey,
446 entry, 424 entry,
@@ -606,8 +584,8 @@ namestore_zone_to_name (void *cls,
606 struct Plugin *plugin = cls; 584 struct Plugin *plugin = cls;
607 585
608 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 586 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
609 "Performing reverse lookup for `%s'\n", 587 "Performing reverse lookup for `%s'\n",
610 GNUNET_GNSRECORD_z2s (value_zone)); 588 GNUNET_GNSRECORD_z2s (value_zone));
611 589
612 GNUNET_CONTAINER_multihashmap_iterate (plugin->hm, 590 GNUNET_CONTAINER_multihashmap_iterate (plugin->hm,
613 &zone_to_name, 591 &zone_to_name,
@@ -647,7 +625,7 @@ libgnunet_plugin_namestore_flat_init (void *cls)
647 api->zone_to_name = &namestore_zone_to_name; 625 api->zone_to_name = &namestore_zone_to_name;
648 api->lookup_records = &namestore_lookup_records; 626 api->lookup_records = &namestore_lookup_records;
649 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 627 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
650 _("flat file database running\n")); 628 _("flat file database running\n"));
651 return api; 629 return api;
652} 630}
653 631
@@ -668,7 +646,7 @@ libgnunet_plugin_namestore_flat_done (void *cls)
668 plugin->cfg = NULL; 646 plugin->cfg = NULL;
669 GNUNET_free (api); 647 GNUNET_free (api);
670 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 648 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
671 "flat file plugin is finished\n"); 649 "flat file plugin is finished\n");
672 return NULL; 650 return NULL;
673} 651}
674 652