diff options
author | tg(x) <*@tg-x.net> | 2017-03-22 10:08:01 +0100 |
---|---|---|
committer | tg(x) <*@tg-x.net> | 2017-03-22 10:08:01 +0100 |
commit | aa98f144e6db0da5a0a4cad83fe64a80bbab6692 (patch) | |
tree | 5a072b4e1b689bf4330b2a412bdadc705d33ff75 /src/peerstore/plugin_peerstore_flat.c | |
parent | caeeec6cacaa5354883494cb64b0a38e5c75da5d (diff) | |
parent | b424335cc632a11bd76bad5791cef10e8c985720 (diff) | |
download | gnunet-aa98f144e6db0da5a0a4cad83fe64a80bbab6692.tar.gz gnunet-aa98f144e6db0da5a0a4cad83fe64a80bbab6692.zip |
Merge branch 'master' of gnunet.org:gnunet
Diffstat (limited to 'src/peerstore/plugin_peerstore_flat.c')
-rw-r--r-- | src/peerstore/plugin_peerstore_flat.c | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/src/peerstore/plugin_peerstore_flat.c b/src/peerstore/plugin_peerstore_flat.c index 2b90719d9..c75b2b1e4 100644 --- a/src/peerstore/plugin_peerstore_flat.c +++ b/src/peerstore/plugin_peerstore_flat.c | |||
@@ -107,7 +107,9 @@ delete_entries (void *cls, | |||
107 | struct GNUNET_PEERSTORE_Record *entry = value; | 107 | struct GNUNET_PEERSTORE_Record *entry = value; |
108 | if (0 != strcmp (plugin->iter_key, entry->key)) | 108 | if (0 != strcmp (plugin->iter_key, entry->key)) |
109 | return GNUNET_YES; | 109 | return GNUNET_YES; |
110 | if (0 != memcmp (plugin->iter_peer, entry->peer, sizeof (struct GNUNET_PeerIdentity))) | 110 | if (0 != memcmp (plugin->iter_peer, |
111 | &entry->peer, | ||
112 | sizeof (struct GNUNET_PeerIdentity))) | ||
111 | return GNUNET_YES; | 113 | return GNUNET_YES; |
112 | if (0 != strcmp (plugin->iter_sub_system, entry->sub_system)) | 114 | if (0 != strcmp (plugin->iter_sub_system, entry->sub_system)) |
113 | return GNUNET_YES; | 115 | return GNUNET_YES; |
@@ -153,7 +155,7 @@ expire_entries (void *cls, | |||
153 | struct Plugin *plugin = cls; | 155 | struct Plugin *plugin = cls; |
154 | struct GNUNET_PEERSTORE_Record *entry = value; | 156 | struct GNUNET_PEERSTORE_Record *entry = value; |
155 | 157 | ||
156 | if (entry->expiry->abs_value_us < plugin->iter_now.abs_value_us) | 158 | if (entry->expiry.abs_value_us < plugin->iter_now.abs_value_us) |
157 | { | 159 | { |
158 | GNUNET_CONTAINER_multihashmap_remove (plugin->hm, key, value); | 160 | GNUNET_CONTAINER_multihashmap_remove (plugin->hm, key, value); |
159 | plugin->exp_changes++; | 161 | plugin->exp_changes++; |
@@ -204,7 +206,7 @@ iterate_entries (void *cls, | |||
204 | 206 | ||
205 | if ((NULL != plugin->iter_peer) && | 207 | if ((NULL != plugin->iter_peer) && |
206 | (0 != memcmp (plugin->iter_peer, | 208 | (0 != memcmp (plugin->iter_peer, |
207 | entry->peer, | 209 | &entry->peer, |
208 | sizeof (struct GNUNET_PeerIdentity)))) | 210 | sizeof (struct GNUNET_PeerIdentity)))) |
209 | { | 211 | { |
210 | return GNUNET_YES; | 212 | return GNUNET_YES; |
@@ -296,10 +298,8 @@ peerstore_flat_store_record (void *cls, const char *sub_system, | |||
296 | entry->value = GNUNET_malloc (size); | 298 | entry->value = GNUNET_malloc (size); |
297 | GNUNET_memcpy (entry->value, value, size); | 299 | GNUNET_memcpy (entry->value, value, size); |
298 | entry->value_size = size; | 300 | entry->value_size = size; |
299 | entry->peer = GNUNET_new (struct GNUNET_PeerIdentity); | 301 | entry->peer = *peer; |
300 | GNUNET_memcpy (entry->peer, peer, sizeof (struct GNUNET_PeerIdentity)); | 302 | entry->expiry = expiry; |
301 | entry->expiry = GNUNET_new (struct GNUNET_TIME_Absolute); | ||
302 | entry->expiry->abs_value_us = expiry.abs_value_us; | ||
303 | 303 | ||
304 | peer_id = GNUNET_i2s (peer); | 304 | peer_id = GNUNET_i2s (peer); |
305 | GNUNET_CRYPTO_hash (peer_id, | 305 | GNUNET_CRYPTO_hash (peer_id, |
@@ -409,7 +409,7 @@ database_setup (struct Plugin *plugin) | |||
409 | GNUNET_free (buffer); | 409 | GNUNET_free (buffer); |
410 | return GNUNET_SYSERR; | 410 | return GNUNET_SYSERR; |
411 | } | 411 | } |
412 | 412 | ||
413 | buffer[size] = '\0'; | 413 | buffer[size] = '\0'; |
414 | GNUNET_DISK_file_close (fh); | 414 | GNUNET_DISK_file_close (fh); |
415 | if (0 < size) { | 415 | if (0 < size) { |
@@ -433,22 +433,35 @@ database_setup (struct Plugin *plugin) | |||
433 | entry = GNUNET_new (struct GNUNET_PEERSTORE_Record); | 433 | entry = GNUNET_new (struct GNUNET_PEERSTORE_Record); |
434 | entry->sub_system = GNUNET_strdup (sub_system); | 434 | entry->sub_system = GNUNET_strdup (sub_system); |
435 | entry->key = GNUNET_strdup (key); | 435 | entry->key = GNUNET_strdup (key); |
436 | GNUNET_STRINGS_base64_decode (peer, | 436 | { |
437 | strlen (peer), | 437 | size_t s; |
438 | (char**)&entry->peer); | 438 | char *o; |
439 | |||
440 | o = NULL; | ||
441 | s = GNUNET_STRINGS_base64_decode (peer, | ||
442 | strlen (peer), | ||
443 | &o); | ||
444 | if (sizeof (struct GNUNET_PeerIdentity) == s) | ||
445 | GNUNET_memcpy (&entry->peer, | ||
446 | o, | ||
447 | s); | ||
448 | else | ||
449 | GNUNET_break (0); | ||
450 | GNUNET_free_non_null (o); | ||
451 | } | ||
439 | entry->value_size = GNUNET_STRINGS_base64_decode (value, | 452 | entry->value_size = GNUNET_STRINGS_base64_decode (value, |
440 | strlen (value), | 453 | strlen (value), |
441 | (char**)&entry->value); | 454 | (char**)&entry->value); |
442 | if (GNUNET_SYSERR == GNUNET_STRINGS_fancy_time_to_absolute (expiry, | 455 | if (GNUNET_SYSERR == |
443 | entry->expiry)) | 456 | GNUNET_STRINGS_fancy_time_to_absolute (expiry, |
457 | &entry->expiry)) | ||
444 | { | 458 | { |
445 | GNUNET_free (entry->sub_system); | 459 | GNUNET_free (entry->sub_system); |
446 | GNUNET_free (entry->key); | 460 | GNUNET_free (entry->key); |
447 | GNUNET_free (entry->peer); | ||
448 | GNUNET_free (entry); | 461 | GNUNET_free (entry); |
449 | break; | 462 | break; |
450 | } | 463 | } |
451 | peer_id = GNUNET_i2s (entry->peer); | 464 | peer_id = GNUNET_i2s (&entry->peer); |
452 | GNUNET_CRYPTO_hash (peer_id, | 465 | GNUNET_CRYPTO_hash (peer_id, |
453 | strlen (peer_id), | 466 | strlen (peer_id), |
454 | &hkey); | 467 | &hkey); |
@@ -479,8 +492,8 @@ store_and_free_entries (void *cls, | |||
479 | GNUNET_STRINGS_base64_encode (entry->value, | 492 | GNUNET_STRINGS_base64_encode (entry->value, |
480 | entry->value_size, | 493 | entry->value_size, |
481 | &val); | 494 | &val); |
482 | expiry = GNUNET_STRINGS_absolute_time_to_string (*entry->expiry); | 495 | expiry = GNUNET_STRINGS_absolute_time_to_string (entry->expiry); |
483 | GNUNET_STRINGS_base64_encode ((char*)entry->peer, | 496 | GNUNET_STRINGS_base64_encode ((char*)&entry->peer, |
484 | sizeof (struct GNUNET_PeerIdentity), | 497 | sizeof (struct GNUNET_PeerIdentity), |
485 | &peer); | 498 | &peer); |
486 | GNUNET_asprintf (&line, | 499 | GNUNET_asprintf (&line, |
@@ -496,10 +509,8 @@ store_and_free_entries (void *cls, | |||
496 | line, | 509 | line, |
497 | strlen (line)); | 510 | strlen (line)); |
498 | GNUNET_free (entry->sub_system); | 511 | GNUNET_free (entry->sub_system); |
499 | GNUNET_free (entry->peer); | ||
500 | GNUNET_free (entry->key); | 512 | GNUNET_free (entry->key); |
501 | GNUNET_free (entry->value); | 513 | GNUNET_free (entry->value); |
502 | GNUNET_free (entry->expiry); | ||
503 | GNUNET_free (entry); | 514 | GNUNET_free (entry); |
504 | GNUNET_free (line); | 515 | GNUNET_free (line); |
505 | return GNUNET_YES; | 516 | return GNUNET_YES; |