[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] 20/40: PEERSTORE: Moved code to scan and import hello file into
From: |
gnunet |
Subject: |
[gnunet] 20/40: PEERSTORE: Moved code to scan and import hello file into peerstore from peerinfo. |
Date: |
Thu, 05 Oct 2023 08:57:23 +0200 |
This is an automated email from the git hooks/post-receive script.
martin-schanzenbach pushed a commit to branch master
in repository gnunet.
commit 20d6f37424ec5e3bda706329c4a4ec9517041a70
Author: t3sserakt <t3ss@posteo.de>
AuthorDate: Thu Aug 24 13:55:55 2023 +0200
PEERSTORE: Moved code to scan and import hello file into peerstore from
peerinfo.
---
src/peerstore/gnunet-service-peerstore.c | 99 ++++++++++++++++++++++++++++++++
1 file changed, 99 insertions(+)
diff --git a/src/peerstore/gnunet-service-peerstore.c
b/src/peerstore/gnunet-service-peerstore.c
index 959d088f9..052656280 100644
--- a/src/peerstore/gnunet-service-peerstore.c
+++ b/src/peerstore/gnunet-service-peerstore.c
@@ -28,6 +28,7 @@
#include "peerstore.h"
#include "gnunet_peerstore_plugin.h"
#include "peerstore_common.h"
+#include "gnunet_hello_uri_lib.h"
/**
@@ -532,6 +533,76 @@ handle_store (void *cls, const struct StoreRecordMessage
*srm)
}
}
+static void
+store_hello_continuation (void *cls, int success)
+{
+ (void *) cls;
+
+ if (GNUNET_OK != success)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Error storing bootstrap hello!\n");
+ GNUNET_break (0);
+ }
+}
+
+
+static int
+hosts_directory_scan_callback (void *cls, const char *fullname)
+{
+ (void *) cls;
+ const char *filename;
+ ssize_t size_total;
+ char buffer[GNUNET_MAX_MESSAGE_SIZE - 1] GNUNET_ALIGN;
+ const struct GNUNET_MessageHeader *hello;
+ struct GNUNET_HELLO_Builder *builder;
+ struct GNUNET_PeerIdentity *pid;
+
+ if (GNUNET_YES != GNUNET_DISK_file_test (fullname))
+ return GNUNET_OK; /* ignore non-files */
+
+ filename = strrchr (fullname, DIR_SEPARATOR);
+ if ((NULL == filename) || (1 > strlen (filename)))
+ filename = fullname;
+ else
+ filename++;
+
+ if (GNUNET_YES != GNUNET_DISK_file_test (filename))
+ return GNUNET_OK;
+ size_total = GNUNET_DISK_fn_read (fullname, buffer, sizeof(buffer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Read %d bytes from `%s'\n",
+ (int) size_total,
+ fullname);
+ if ((size_total < 0) ||
+ (((size_t) size_total) < sizeof(struct GNUNET_MessageHeader)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Failed to parse HELLO in file `%s': %s\n"),
+ fullname,
+ "File has invalid size");
+ return GNUNET_OK;
+ }
+ hello = (const struct GNUNET_MessageHeader *) &buffer[0];
+ builder = GNUNET_HELLO_builder_from_msg (hello);
+ pid = GNUNET_HELLO_builder_get_id (builder);
+
+ if (GNUNET_OK != db->store_record (db->cls,
+ "peerstore",
+ pid,
+ "",
+ hello,
+ sizeof (hello),
+ GNUNET_TIME_UNIT_FOREVER_ABS,
+ GNUNET_PEERSTORE_STOREOPTION_REPLACE,
+ &store_hello_continuation,
+ NULL))
+ {
+ GNUNET_break (0);
+ }
+ GNUNET_HELLO_builder_free (builder);
+}
+
/**
* Peerstore service runner.
@@ -546,10 +617,38 @@ run (void *cls,
struct GNUNET_SERVICE_Handle *service)
{
char *database;
+ int use_included;
+ char *ip;
+ char *peerdir;
in_shutdown = GNUNET_NO;
num_clients = 0;
cfg = c;
+ use_included = GNUNET_CONFIGURATION_get_value_yesno (cfg,
+ "peerinfo",
+ "USE_INCLUDED_HELLOS");
+ if (GNUNET_SYSERR == use_included)
+ use_included = GNUNET_NO;
+ if (GNUNET_YES == use_included)
+ {
+ ip = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
+ GNUNET_asprintf (&peerdir, "%shellos", ip);
+ GNUNET_free (ip);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _ ("Importing HELLOs from `%s'\n"),
+ peerdir);
+
+ GNUNET_DISK_directory_scan (peerdir,
+ &hosts_directory_scan_callback,
+ NULL);
+ GNUNET_free (peerdir);
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _ ("Skipping import of included HELLOs\n"));
+ }
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg,
"peerstore",
"DATABASE",
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [gnunet] 18/40: NEWS: The old hello design replaced by the new hello design., (continued)
- [gnunet] 18/40: NEWS: The old hello design replaced by the new hello design., gnunet, 2023/10/05
- [gnunet] 39/40: Make fs and cadet build again; cadet hello handling suspicious, gnunet, 2023/10/05
- [gnunet] 25/40: Hello: Changed address and hello format to new TNG format., gnunet, 2023/10/05
- [gnunet] 38/40: Remove more traces of old transport, gnunet, 2023/10/05
- [gnunet] 31/40: BUILD: Make meson build without ats, tesbed, peerinfo, gnunet, 2023/10/05
- [gnunet] 37/40: Remove more traces of ATS, gnunet, 2023/10/05
- [gnunet] 30/40: Merge branch 'master' into l20integration, gnunet, 2023/10/05
- [gnunet] 40/40: Update to new transport binary, gnunet, 2023/10/05
- [gnunet] 10/40: TNG: Added Testcase that just runs two peers, and blocks., gnunet, 2023/10/05
- [gnunet] 14/40: NEWS: Added api to store hellos with peerstore service., gnunet, 2023/10/05
- [gnunet] 20/40: PEERSTORE: Moved code to scan and import hello file into peerstore from peerinfo.,
gnunet <=
- [gnunet] 26/40: Peerstore: Fixed bug in bootstrap code, gnunet, 2023/10/05
- [gnunet] 28/40: DHT: Fixed wrong group name, gnunet, 2023/10/05
- [gnunet] 11/40: CORE: Fixed bug that core is not calling GNUNET_TRANSPORT_core_receive_continue, gnunet, 2023/10/05
- [gnunet] 15/40: NEWS: Added api to get notified when hellos are stored with peerstore service., gnunet, 2023/10/05
- [gnunet] 08/40: TNG: Added generic start script for test cases., gnunet, 2023/10/05
- [gnunet] 21/40: NEWS: Moved code to testing to have more generic test setup, which can be used not only from within transport., gnunet, 2023/10/05
- [gnunet] 23/40: NEWS: Changed method GNUNET_HELLO_builder_get_expiration_time to not need parameter GNUNET_HELLO_Builder., gnunet, 2023/10/05
- [gnunet] 24/40: Peerstore: Changed the behavior of GNUNET_PEERSTORE_watch to also return the values allready stored for the key., gnunet, 2023/10/05
- [gnunet] 27/40: TNG: Fixed validation bug., gnunet, 2023/10/05
- [gnunet] 35/40: Remove old transport struct definitions, gnunet, 2023/10/05