diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-02-13 23:18:43 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-02-13 23:18:43 +0100 |
commit | 443454a6212e5596f7caaadf3b666fa4857edb64 (patch) | |
tree | aa018ceda1b44b958f6057e3196a97b81cd41cfe /src/namestore | |
parent | 7285ae216aeb5dad89055085f2d7710c4ed5934e (diff) | |
download | gnunet-443454a6212e5596f7caaadf3b666fa4857edb64.tar.gz gnunet-443454a6212e5596f7caaadf3b666fa4857edb64.zip |
clarifying namestore api (#5458), fixing code duplication and a memory leak while at it
Diffstat (limited to 'src/namestore')
-rw-r--r-- | src/namestore/gnunet-service-namestore.c | 45 | ||||
-rw-r--r-- | src/namestore/plugin_namestore_heap.c | 93 | ||||
-rw-r--r-- | src/namestore/plugin_namestore_postgres.c | 1 | ||||
-rw-r--r-- | src/namestore/plugin_namestore_sqlite.c | 1 |
4 files changed, 73 insertions, 67 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index b1f8fcf4c..45be0fe75 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -124,7 +124,7 @@ struct ZoneIteration | |||
124 | * message and free the data structure once @e cache_ops is zero. | 124 | * message and free the data structure once @e cache_ops is zero. |
125 | */ | 125 | */ |
126 | int send_end; | 126 | int send_end; |
127 | 127 | ||
128 | }; | 128 | }; |
129 | 129 | ||
130 | 130 | ||
@@ -268,7 +268,7 @@ struct CacheOperation | |||
268 | * for if applicable, can be NULL. | 268 | * for if applicable, can be NULL. |
269 | */ | 269 | */ |
270 | struct ZoneIteration *zi; | 270 | struct ZoneIteration *zi; |
271 | 271 | ||
272 | /** | 272 | /** |
273 | * Client's request ID. | 273 | * Client's request ID. |
274 | */ | 274 | */ |
@@ -318,12 +318,12 @@ struct StoreActivity | |||
318 | 318 | ||
319 | /** | 319 | /** |
320 | * Entry in list of cached nick resolutions. | 320 | * Entry in list of cached nick resolutions. |
321 | */ | 321 | */ |
322 | struct NickCache | 322 | struct NickCache |
323 | { | 323 | { |
324 | /** | 324 | /** |
325 | * Zone the cache entry is for. | 325 | * Zone the cache entry is for. |
326 | */ | 326 | */ |
327 | struct GNUNET_CRYPTO_EcdsaPrivateKey zone; | 327 | struct GNUNET_CRYPTO_EcdsaPrivateKey zone; |
328 | 328 | ||
329 | /** | 329 | /** |
@@ -339,7 +339,7 @@ struct NickCache | |||
339 | 339 | ||
340 | 340 | ||
341 | /** | 341 | /** |
342 | * We cache nick records to reduce DB load. | 342 | * We cache nick records to reduce DB load. |
343 | */ | 343 | */ |
344 | static struct NickCache nick_cache[NC_SIZE]; | 344 | static struct NickCache nick_cache[NC_SIZE]; |
345 | 345 | ||
@@ -489,7 +489,7 @@ free_store_activity (struct StoreActivity *sa) | |||
489 | * record, which (if found) is then copied to @a cls for future use. | 489 | * record, which (if found) is then copied to @a cls for future use. |
490 | * | 490 | * |
491 | * @param cls a `struct GNUNET_GNSRECORD_Data **` for storing the nick (if found) | 491 | * @param cls a `struct GNUNET_GNSRECORD_Data **` for storing the nick (if found) |
492 | * @param seq sequence number of the record | 492 | * @param seq sequence number of the record, MUST NOT BE ZERO |
493 | * @param private_key the private key of the zone (unused) | 493 | * @param private_key the private key of the zone (unused) |
494 | * @param label should be #GNUNET_GNS_EMPTY_LABEL_AT | 494 | * @param label should be #GNUNET_GNS_EMPTY_LABEL_AT |
495 | * @param rd_count number of records in @a rd | 495 | * @param rd_count number of records in @a rd |
@@ -506,7 +506,7 @@ lookup_nick_it (void *cls, | |||
506 | struct GNUNET_GNSRECORD_Data **res = cls; | 506 | struct GNUNET_GNSRECORD_Data **res = cls; |
507 | 507 | ||
508 | (void) private_key; | 508 | (void) private_key; |
509 | (void) seq; | 509 | GNUNET_assert (0 != seq); |
510 | if (0 != strcmp (label, GNUNET_GNS_EMPTY_LABEL_AT)) | 510 | if (0 != strcmp (label, GNUNET_GNS_EMPTY_LABEL_AT)) |
511 | { | 511 | { |
512 | GNUNET_break (0); | 512 | GNUNET_break (0); |
@@ -607,7 +607,7 @@ get_nick_record (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone) | |||
607 | return nick; | 607 | return nick; |
608 | } | 608 | } |
609 | } | 609 | } |
610 | 610 | ||
611 | nick = NULL; | 611 | nick = NULL; |
612 | res = GSN_database->lookup_records (GSN_database->cls, | 612 | res = GSN_database->lookup_records (GSN_database->cls, |
613 | zone, | 613 | zone, |
@@ -872,7 +872,7 @@ zone_iteration_done_client_continue (struct ZoneIteration *zi) | |||
872 | em->r_id = htonl (zi->request_id); | 872 | em->r_id = htonl (zi->request_id); |
873 | GNUNET_MQ_send (zi->nc->mq, | 873 | GNUNET_MQ_send (zi->nc->mq, |
874 | env); | 874 | env); |
875 | 875 | ||
876 | GNUNET_CONTAINER_DLL_remove (zi->nc->op_head, | 876 | GNUNET_CONTAINER_DLL_remove (zi->nc->op_head, |
877 | zi->nc->op_tail, | 877 | zi->nc->op_tail, |
878 | zi); | 878 | zi); |
@@ -1270,9 +1270,16 @@ struct RecordLookupContext | |||
1270 | 1270 | ||
1271 | 1271 | ||
1272 | /** | 1272 | /** |
1273 | * FIXME. | 1273 | * Function called by the namestore plugin when we are trying to lookup |
1274 | * a record as part of #handle_record_lookup(). Merges all results into | ||
1275 | * the context. | ||
1274 | * | 1276 | * |
1275 | * @param seq sequence number of the record | 1277 | * @param cls closure with a `struct RecordLookupContext` |
1278 | * @param seq unique serial number of the record, MUST NOT BE ZERO | ||
1279 | * @param zone_key private key of the zone | ||
1280 | * @param label name that is being mapped (at most 255 characters long) | ||
1281 | * @param rd_count number of entries in @a rd array | ||
1282 | * @param rd array of records with data to store | ||
1276 | */ | 1283 | */ |
1277 | static void | 1284 | static void |
1278 | lookup_it (void *cls, | 1285 | lookup_it (void *cls, |
@@ -1285,7 +1292,7 @@ lookup_it (void *cls, | |||
1285 | struct RecordLookupContext *rlc = cls; | 1292 | struct RecordLookupContext *rlc = cls; |
1286 | 1293 | ||
1287 | (void) private_key; | 1294 | (void) private_key; |
1288 | (void) seq; | 1295 | GNUNET_assert (0 != seq); |
1289 | if (0 != strcmp (label, | 1296 | if (0 != strcmp (label, |
1290 | rlc->label)) | 1297 | rlc->label)) |
1291 | return; | 1298 | return; |
@@ -1609,7 +1616,7 @@ handle_record_store (void *cls, | |||
1609 | conv_name)) || | 1616 | conv_name)) || |
1610 | (GNUNET_GNSRECORD_TYPE_NICK != rd[i].record_type) ) | 1617 | (GNUNET_GNSRECORD_TYPE_NICK != rd[i].record_type) ) |
1611 | rd_clean_off++; | 1618 | rd_clean_off++; |
1612 | 1619 | ||
1613 | if ( (0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, | 1620 | if ( (0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, |
1614 | conv_name)) && | 1621 | conv_name)) && |
1615 | (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) ) | 1622 | (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type) ) |
@@ -1680,7 +1687,7 @@ struct ZoneToNameCtx | |||
1680 | * Zone to name iterator | 1687 | * Zone to name iterator |
1681 | * | 1688 | * |
1682 | * @param cls struct ZoneToNameCtx * | 1689 | * @param cls struct ZoneToNameCtx * |
1683 | * @param seq sequence number of the record | 1690 | * @param seq sequence number of the record, MUST NOT BE ZERO |
1684 | * @param zone_key the zone key | 1691 | * @param zone_key the zone key |
1685 | * @param name name | 1692 | * @param name name |
1686 | * @param rd_count number of records in @a rd | 1693 | * @param rd_count number of records in @a rd |
@@ -1704,7 +1711,7 @@ handle_zone_to_name_it (void *cls, | |||
1704 | char *name_tmp; | 1711 | char *name_tmp; |
1705 | char *rd_tmp; | 1712 | char *rd_tmp; |
1706 | 1713 | ||
1707 | (void) seq; | 1714 | GNUNET_assert (0 != seq); |
1708 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1715 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1709 | "Found result for zone-to-name lookup: `%s'\n", | 1716 | "Found result for zone-to-name lookup: `%s'\n", |
1710 | name); | 1717 | name); |
@@ -1822,7 +1829,7 @@ struct ZoneIterationProcResult | |||
1822 | * Process results for zone iteration from database | 1829 | * Process results for zone iteration from database |
1823 | * | 1830 | * |
1824 | * @param cls struct ZoneIterationProcResult | 1831 | * @param cls struct ZoneIterationProcResult |
1825 | * @param seq sequence number of the record | 1832 | * @param seq sequence number of the record, MUST NOT BE ZERO |
1826 | * @param zone_key the zone key | 1833 | * @param zone_key the zone key |
1827 | * @param name name | 1834 | * @param name name |
1828 | * @param rd_count number of records for this name | 1835 | * @param rd_count number of records for this name |
@@ -1839,6 +1846,7 @@ zone_iterate_proc (void *cls, | |||
1839 | struct ZoneIterationProcResult *proc = cls; | 1846 | struct ZoneIterationProcResult *proc = cls; |
1840 | int do_refresh_block; | 1847 | int do_refresh_block; |
1841 | 1848 | ||
1849 | GNUNET_assert (0 != seq); | ||
1842 | if ( (NULL == zone_key) && | 1850 | if ( (NULL == zone_key) && |
1843 | (NULL == name) ) | 1851 | (NULL == name) ) |
1844 | { | 1852 | { |
@@ -1876,7 +1884,7 @@ zone_iterate_proc (void *cls, | |||
1876 | do_refresh_block = GNUNET_YES; | 1884 | do_refresh_block = GNUNET_YES; |
1877 | break; | 1885 | break; |
1878 | } | 1886 | } |
1879 | if (GNUNET_YES == do_refresh_block) | 1887 | if (GNUNET_YES == do_refresh_block) |
1880 | refresh_block (NULL, | 1888 | refresh_block (NULL, |
1881 | proc->zi, | 1889 | proc->zi, |
1882 | 0, | 1890 | 0, |
@@ -2116,7 +2124,7 @@ monitor_iteration_next (void *cls); | |||
2116 | * A #GNUNET_NAMESTORE_RecordIterator for monitors. | 2124 | * A #GNUNET_NAMESTORE_RecordIterator for monitors. |
2117 | * | 2125 | * |
2118 | * @param cls a 'struct ZoneMonitor *' with information about the monitor | 2126 | * @param cls a 'struct ZoneMonitor *' with information about the monitor |
2119 | * @param seq sequence number of the record | 2127 | * @param seq sequence number of the record, MUST NOT BE ZERO |
2120 | * @param zone_key zone key of the zone | 2128 | * @param zone_key zone key of the zone |
2121 | * @param name name | 2129 | * @param name name |
2122 | * @param rd_count number of records in @a rd | 2130 | * @param rd_count number of records in @a rd |
@@ -2132,6 +2140,7 @@ monitor_iterate_cb (void *cls, | |||
2132 | { | 2140 | { |
2133 | struct ZoneMonitor *zm = cls; | 2141 | struct ZoneMonitor *zm = cls; |
2134 | 2142 | ||
2143 | GNUNET_assert (0 != seq); | ||
2135 | zm->seq = seq; | 2144 | zm->seq = seq; |
2136 | GNUNET_assert (NULL != name); | 2145 | GNUNET_assert (NULL != name); |
2137 | GNUNET_STATISTICS_update (statistics, | 2146 | GNUNET_STATISTICS_update (statistics, |
diff --git a/src/namestore/plugin_namestore_heap.c b/src/namestore/plugin_namestore_heap.c index 78e99442c..01cf592ea 100644 --- a/src/namestore/plugin_namestore_heap.c +++ b/src/namestore/plugin_namestore_heap.c | |||
@@ -79,11 +79,42 @@ struct FlatFileEntry | |||
79 | */ | 79 | */ |
80 | char *label; | 80 | char *label; |
81 | 81 | ||
82 | |||
83 | }; | 82 | }; |
84 | 83 | ||
85 | 84 | ||
86 | /** | 85 | /** |
86 | * Hash contactenation of @a pkey and @a label into @a h | ||
87 | * | ||
88 | * @param pkey a key | ||
89 | * @param label a label | ||
90 | * @param h[out] initialized hash | ||
91 | */ | ||
92 | static void | ||
93 | hash_pkey_and_label (const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, | ||
94 | const char *label, | ||
95 | struct GNUNET_HashCode *h) | ||
96 | { | ||
97 | char *key; | ||
98 | size_t label_len; | ||
99 | size_t key_len; | ||
100 | |||
101 | label_len = strlen (label); | ||
102 | key_len = label_len + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey); | ||
103 | key = GNUNET_malloc (key_len); | ||
104 | GNUNET_memcpy (key, | ||
105 | label, | ||
106 | label_len); | ||
107 | GNUNET_memcpy (key + label_len, | ||
108 | pkey, | ||
109 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)); | ||
110 | GNUNET_CRYPTO_hash (key, | ||
111 | key_len, | ||
112 | h); | ||
113 | GNUNET_free (key); | ||
114 | } | ||
115 | |||
116 | |||
117 | /** | ||
87 | * Initialize the database connections and associated | 118 | * Initialize the database connections and associated |
88 | * data structures (create tables and indices | 119 | * data structures (create tables and indices |
89 | * as needed as well). | 120 | * as needed as well). |
@@ -262,23 +293,9 @@ database_setup (struct Plugin *plugin) | |||
262 | GNUNET_free (private_key); | 293 | GNUNET_free (private_key); |
263 | } | 294 | } |
264 | 295 | ||
265 | { | 296 | hash_pkey_and_label (&entry->private_key, |
266 | char *key; | 297 | label, |
267 | size_t key_len; | 298 | &hkey); |
268 | |||
269 | key_len = strlen (label) + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey); | ||
270 | key = GNUNET_malloc (strlen (label) + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)); | ||
271 | GNUNET_memcpy (key, | ||
272 | label, | ||
273 | strlen (label)); | ||
274 | GNUNET_memcpy (key+strlen(label), | ||
275 | &entry->private_key, | ||
276 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)); | ||
277 | GNUNET_CRYPTO_hash (key, | ||
278 | key_len, | ||
279 | &hkey); | ||
280 | GNUNET_free (key); | ||
281 | } | ||
282 | if (GNUNET_OK != | 299 | if (GNUNET_OK != |
283 | GNUNET_CONTAINER_multihashmap_put (plugin->hm, | 300 | GNUNET_CONTAINER_multihashmap_put (plugin->hm, |
284 | &hkey, | 301 | &hkey, |
@@ -425,24 +442,14 @@ namestore_heap_store_records (void *cls, | |||
425 | { | 442 | { |
426 | struct Plugin *plugin = cls; | 443 | struct Plugin *plugin = cls; |
427 | uint64_t rvalue; | 444 | uint64_t rvalue; |
428 | size_t key_len; | ||
429 | char *key; | ||
430 | struct GNUNET_HashCode hkey; | 445 | struct GNUNET_HashCode hkey; |
431 | struct FlatFileEntry *entry; | 446 | struct FlatFileEntry *entry; |
432 | 447 | ||
433 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 448 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
434 | UINT64_MAX); | 449 | UINT64_MAX); |
435 | key_len = strlen (label) + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey); | 450 | hash_pkey_and_label (zone_key, |
436 | key = GNUNET_malloc (key_len); | 451 | label, |
437 | GNUNET_memcpy (key, | 452 | &hkey); |
438 | label, | ||
439 | strlen (label)); | ||
440 | GNUNET_memcpy (key + strlen(label), | ||
441 | zone_key, | ||
442 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)); | ||
443 | GNUNET_CRYPTO_hash (key, | ||
444 | key_len, | ||
445 | &hkey); | ||
446 | GNUNET_CONTAINER_multihashmap_remove_all (plugin->hm, | 453 | GNUNET_CONTAINER_multihashmap_remove_all (plugin->hm, |
447 | &hkey); | 454 | &hkey); |
448 | if (0 == rd_count) | 455 | if (0 == rd_count) |
@@ -501,27 +508,15 @@ namestore_heap_lookup_records (void *cls, | |||
501 | struct Plugin *plugin = cls; | 508 | struct Plugin *plugin = cls; |
502 | struct FlatFileEntry *entry; | 509 | struct FlatFileEntry *entry; |
503 | struct GNUNET_HashCode hkey; | 510 | struct GNUNET_HashCode hkey; |
504 | char *key; | ||
505 | size_t key_len; | ||
506 | 511 | ||
507 | if (NULL == zone) | 512 | if (NULL == zone) |
508 | { | 513 | { |
509 | GNUNET_break (0); | 514 | GNUNET_break (0); |
510 | return GNUNET_SYSERR; | 515 | return GNUNET_SYSERR; |
511 | } | 516 | } |
512 | key_len = strlen (label) + sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey); | 517 | hash_pkey_and_label (zone, |
513 | key = GNUNET_malloc (key_len); | 518 | label, |
514 | GNUNET_memcpy (key, | 519 | &hkey); |
515 | label, | ||
516 | strlen (label)); | ||
517 | GNUNET_memcpy (key+strlen(label), | ||
518 | zone, | ||
519 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)); | ||
520 | GNUNET_CRYPTO_hash (key, | ||
521 | key_len, | ||
522 | &hkey); | ||
523 | GNUNET_free (key); | ||
524 | |||
525 | entry = GNUNET_CONTAINER_multihashmap_get (plugin->hm, | 520 | entry = GNUNET_CONTAINER_multihashmap_get (plugin->hm, |
526 | &hkey); | 521 | &hkey); |
527 | 522 | ||
@@ -529,7 +524,7 @@ namestore_heap_lookup_records (void *cls, | |||
529 | return GNUNET_NO; | 524 | return GNUNET_NO; |
530 | if (NULL != iter) | 525 | if (NULL != iter) |
531 | iter (iter_cls, | 526 | iter (iter_cls, |
532 | 0, | 527 | 1, /* zero is illegal */ |
533 | &entry->private_key, | 528 | &entry->private_key, |
534 | entry->label, | 529 | entry->label, |
535 | entry->record_count, | 530 | entry->record_count, |
@@ -609,7 +604,7 @@ iterate_zones (void *cls, | |||
609 | } | 604 | } |
610 | ic->iter (ic->iter_cls, | 605 | ic->iter (ic->iter_cls, |
611 | ic->pos, | 606 | ic->pos, |
612 | (NULL == ic->zone) | 607 | (NULL == ic->zone) |
613 | ? &entry->private_key | 608 | ? &entry->private_key |
614 | : ic->zone, | 609 | : ic->zone, |
615 | entry->label, | 610 | entry->label, |
@@ -695,7 +690,7 @@ zone_to_name (void *cls, | |||
695 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) | 690 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) |
696 | { | 691 | { |
697 | ztn->iter (ztn->iter_cls, | 692 | ztn->iter (ztn->iter_cls, |
698 | 0, | 693 | i + 1, /* zero is illegal! */ |
699 | &entry->private_key, | 694 | &entry->private_key, |
700 | entry->label, | 695 | entry->label, |
701 | entry->record_count, | 696 | entry->record_count, |
diff --git a/src/namestore/plugin_namestore_postgres.c b/src/namestore/plugin_namestore_postgres.c index 57a8ae2be..f2e065882 100644 --- a/src/namestore/plugin_namestore_postgres.c +++ b/src/namestore/plugin_namestore_postgres.c | |||
@@ -400,6 +400,7 @@ parse_result_call_iterator (void *cls, | |||
400 | { | 400 | { |
401 | struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(record_count)]; | 401 | struct GNUNET_GNSRECORD_Data rd[GNUNET_NZL(record_count)]; |
402 | 402 | ||
403 | GNUNET_assert (0 != serial); | ||
403 | if (GNUNET_OK != | 404 | if (GNUNET_OK != |
404 | GNUNET_GNSRECORD_records_deserialize (data_size, | 405 | GNUNET_GNSRECORD_records_deserialize (data_size, |
405 | data, | 406 | data, |
diff --git a/src/namestore/plugin_namestore_sqlite.c b/src/namestore/plugin_namestore_sqlite.c index 96b0d6457..e4bfcde16 100644 --- a/src/namestore/plugin_namestore_sqlite.c +++ b/src/namestore/plugin_namestore_sqlite.c | |||
@@ -521,6 +521,7 @@ get_records_and_call_iterator (struct Plugin *plugin, | |||
521 | { | 521 | { |
522 | struct GNUNET_GNSRECORD_Data rd[record_count]; | 522 | struct GNUNET_GNSRECORD_Data rd[record_count]; |
523 | 523 | ||
524 | GNUNET_assert (0 != seq); | ||
524 | if (GNUNET_OK != | 525 | if (GNUNET_OK != |
525 | GNUNET_GNSRECORD_records_deserialize (data_size, | 526 | GNUNET_GNSRECORD_records_deserialize (data_size, |
526 | data, | 527 | data, |