[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] branch master updated: peerstore/core: Move peerstore HELLO fun
From: |
gnunet |
Subject: |
[gnunet] branch master updated: peerstore/core: Move peerstore HELLO functions to CORE; remove peerstore CLI; Fixes #9043 |
Date: |
Tue, 06 Aug 2024 10:49:50 +0200 |
This is an automated email from the git hooks/post-receive script.
martin-schanzenbach pushed a commit to branch master
in repository gnunet.
The following commit(s) were added to refs/heads/master by this push:
new 362f6e526 peerstore/core: Move peerstore HELLO functions to CORE;
remove peerstore CLI; Fixes #9043
362f6e526 is described below
commit 362f6e526f5d70aef6fd3101056891c43b2d6f40
Author: Martin Schanzenbach <schanzen@gnunet.org>
AuthorDate: Tue Aug 6 10:49:42 2024 +0200
peerstore/core: Move peerstore HELLO functions to CORE; remove peerstore
CLI; Fixes #9043
---
configure.ac | 1 -
doc/man/gnunet-core.1 | 10 ++
src/cli/Makefile.am | 1 -
src/cli/core/gnunet-core.c | 214 ++++++++++++++++++++++++++++---
src/cli/core/meson.build | 5 +-
src/cli/meson.build | 1 -
src/cli/peerstore/Makefile.am | 24 ----
src/cli/peerstore/gnunet-peerstore.c | 237 -----------------------------------
src/cli/peerstore/meson.build | 10 --
9 files changed, 214 insertions(+), 289 deletions(-)
diff --git a/configure.ac b/configure.ac
index 0e338c242..467ffebc4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1326,7 +1326,6 @@ src/cli/identity/Makefile
src/cli/messenger/Makefile
src/cli/namecache/Makefile
src/cli/namestore/Makefile
-src/cli/peerstore/Makefile
src/cli/nat/Makefile
src/cli/nat-auto/Makefile
src/cli/nse/Makefile
diff --git a/doc/man/gnunet-core.1 b/doc/man/gnunet-core.1
index 921f2ead6..f301ecab1 100644
--- a/doc/man/gnunet-core.1
+++ b/doc/man/gnunet-core.1
@@ -32,6 +32,9 @@
.Op Fl c Ar FILENAME | Fl -config= Ns Ar FILENAME
.Op Fl h | -help
.Op Fl L Ar LOGLEVEL | Fl -loglevel= Ns Ar LOGLEVEL
+.Op Fl I Ar HELLOURI | Fl -import-hello= Ns Ar HELLOURI
+.Op Fl H | -export-hello
+.Op Fl D | -dump-hellos
.Op Fl m | -monitor
.Op Fl v | -version
.Op Fl V | -verbose
@@ -47,6 +50,13 @@ Print the help page.
.It Fl L Ar LOGLEVEL | Fl -loglevel= Ns Ar LOGLEVEL
Change the loglevel.
Possible values for LOGLEVEL are ERROR, WARNING, INFO and DEBUG.
+.It Fl I Ar HELLOURI | Fl -import-hello= Ns Ar HELLOURI
+Import a HELLO URI (into the peerstore and make it available to core).
+.It Fl H | -export-hello
+Print a freshly signed HELLO URI for our peer.
+.It Fl D | -dump-hellos
+Print all known HELLOs (peer IDs and addresses).
+These are only all known, and not necessarily connected peers.
.It Fl m | -monitor
In monitor mode, gnunet-core will continuously print the connection status,
instead of giving just a snapshot.
diff --git a/src/cli/Makefile.am b/src/cli/Makefile.am
index 6ad6dd70a..d7584b2c4 100644
--- a/src/cli/Makefile.am
+++ b/src/cli/Makefile.am
@@ -2,7 +2,6 @@ SUBDIRS = \
util \
arm \
statistics \
- peerstore \
core \
nat \
nat-auto \
diff --git a/src/cli/core/gnunet-core.c b/src/cli/core/gnunet-core.c
index 00b08eefc..bbbccc928 100644
--- a/src/cli/core/gnunet-core.c
+++ b/src/cli/core/gnunet-core.c
@@ -23,10 +23,18 @@
* @brief Print information about other peers known to CORE.
* @author Nathan Evans
*/
+#include "gnunet_time_lib.h"
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_core_service.h"
+#include "gnunet_hello_uri_lib.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_peerstore_service.h"
+/**
+ * Return code
+ */
+static int ret;
/**
* Option -m.
@@ -48,6 +56,45 @@ static int show_conns;
*/
static struct GNUNET_CORE_MonitorHandle *mh;
+/*
+ * Handle to PEERSTORE service
+ */
+static struct GNUNET_PEERSTORE_Handle *peerstore_handle;
+
+/**
+ * PEERSTORE iteration context
+ */
+static struct GNUNET_PEERSTORE_IterateContext *iter_ctx;
+
+/**
+ * HELLO store context handle
+ */
+static struct GNUNET_PEERSTORE_StoreHelloContext *shc;
+
+/**
+ * Peer private key
+ */
+static struct GNUNET_CRYPTO_EddsaPrivateKey my_private_key;
+
+/**
+ * Peer identity
+ */
+static struct GNUNET_PeerIdentity my_full_id;
+
+/**
+ * HELLO URI export option -H
+ */
+static int export_own_hello_uri;
+
+/**
+ * Hello list option -D
+ */
+static int print_hellos;
+
+/**
+ * HELLO URI import option -I
+ */
+static char *import_uri;
/**
* Task run in monitor mode when the user presses CTRL-C to abort.
@@ -64,6 +111,20 @@ shutdown_task (void *cls)
GNUNET_CORE_monitor_stop (mh);
mh = NULL;
}
+ if (NULL != shc)
+ {
+ GNUNET_PEERSTORE_hello_add_cancel (shc);
+ shc = NULL;
+ }
+ if (NULL != iter_ctx)
+ {
+ GNUNET_PEERSTORE_iteration_stop (iter_ctx);
+ }
+ if (NULL != peerstore_handle)
+ {
+ GNUNET_PEERSTORE_disconnect (peerstore_handle);
+ peerstore_handle = NULL;
+ }
}
@@ -146,6 +207,91 @@ monitor_cb (void *cls,
}
+/**
+ * Callback function used to extract URIs from a builder.
+ * Called when we should consider connecting to a peer.
+ *
+ * @param cls closure pointing to a `struct GNUNET_PeerIdentity *`
+ * @param uri one of the URIs
+ */
+void
+print_hello_addrs (void *cls,
+ const struct GNUNET_PeerIdentity *pid,
+ const char *uri)
+{
+ (void) cls;
+
+
+ printf ("|- %s\n", uri);
+}
+
+
+void
+hello_iter (void *cls, const struct GNUNET_PEERSTORE_Record *record,
+ const char *emsg)
+{
+ struct GNUNET_HELLO_Builder *hb;
+ struct GNUNET_TIME_Absolute hello_exp;
+ const struct GNUNET_PeerIdentity *pid;
+ char *url;
+
+ if ((NULL == record) && (NULL == emsg))
+ {
+ /** If we ever get here, we are newer than the existing record
+ * or the only/first record.
+ */
+ iter_ctx = NULL;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ if (NULL != emsg)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", emsg);
+ GNUNET_PEERSTORE_iteration_next (iter_ctx, 1);
+ return;
+ }
+ hb = GNUNET_HELLO_builder_from_msg (record->value);
+ hello_exp = GNUNET_HELLO_builder_get_expiration_time (record->value);
+ pid = GNUNET_HELLO_builder_get_id (hb);
+ if (export_own_hello_uri)
+ {
+ if (0 == GNUNET_memcmp (&my_full_id,
+ pid))
+ {
+ url = GNUNET_HELLO_builder_to_url (hb, &my_private_key);
+ printf ("%s\n", url);
+ GNUNET_free (url);
+ GNUNET_PEERSTORE_iteration_stop (iter_ctx);
+ iter_ctx = NULL;
+ GNUNET_HELLO_builder_free (hb);
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ }
+ else if (print_hellos)
+ {
+ printf ("`%s' (expires: %s):\n", GNUNET_i2s (pid),
+ GNUNET_STRINGS_absolute_time_to_string (hello_exp));
+ GNUNET_HELLO_builder_iterate (hb, &print_hello_addrs, NULL);
+ }
+ GNUNET_HELLO_builder_free (hb);
+ GNUNET_PEERSTORE_iteration_next (iter_ctx, 1);
+}
+
+
+static void
+hello_store_success (void *cls, int success)
+{
+ shc = NULL;
+ if (GNUNET_OK != success)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Storing hello uri failed\n");
+ }
+ GNUNET_SCHEDULER_shutdown ();
+}
+
+
/**
* Main function that will be run by the scheduler.
*
@@ -160,16 +306,26 @@ run (void *cls,
const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
- struct GNUNET_CRYPTO_EddsaPrivateKey pk;
- struct GNUNET_CRYPTO_EddsaPublicKey pub;
+ struct GNUNET_HELLO_Builder *hb;
+ struct GNUNET_MQ_Envelope *env;
char *keyfile;
(void) cls;
(void) cfgfile;
+
if (NULL != args[0])
{
fprintf (stderr, _ ("Invalid command line argument `%s'\n"), args[0]);
return;
}
+ if (! show_pid && ! show_conns && ! monitor_connections &&
+ ! print_hellos && ! export_own_hello_uri && (NULL == import_uri))
+ {
+ fprintf (stderr, "%s", _ ("No argument given.\n"));
+ ret = 1;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (cfg,
"PEER",
@@ -180,42 +336,58 @@ run (void *cls,
GNUNET_ERROR_TYPE_ERROR,
_ ("Core service is lacking HOSTKEY configuration setting.
Exiting.\n"));
GNUNET_SCHEDULER_shutdown ();
+ ret = 1;
return;
}
if (GNUNET_SYSERR ==
GNUNET_CRYPTO_eddsa_key_from_file (keyfile,
GNUNET_YES,
- &pk))
+ &my_private_key))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to read peer's private key!\n");
GNUNET_SCHEDULER_shutdown ();
+ ret = 1;
GNUNET_free (keyfile);
return;
}
- GNUNET_CRYPTO_eddsa_key_get_public (&pk, &pub);
+ GNUNET_free (keyfile);
+ GNUNET_CRYPTO_eddsa_key_get_public (&my_private_key, &my_full_id.public_key);
if (show_pid)
fprintf (stdout,
_ ("Current local peer identity: %s\n"),
- GNUNET_i2s_full ((struct GNUNET_PeerIdentity*) &pub));
+ GNUNET_i2s_full (&my_full_id));
if (show_conns || monitor_connections)
{
mh = GNUNET_CORE_monitor_start (cfg, &monitor_cb, NULL);
if (NULL == mh)
{
fprintf (stderr, "%s", _ ("Failed to connect to CORE service!\n"));
- GNUNET_free (keyfile);
- return;
+ ret = 1;
+ GNUNET_SCHEDULER_shutdown();
}
+ return;
}
- if (! show_pid && ! show_conns && ! monitor_connections)
+ peerstore_handle = GNUNET_PEERSTORE_connect (cfg);
+ GNUNET_assert (NULL != peerstore_handle);
+ if (NULL != import_uri)
{
- fprintf (stderr, "%s", _ ("No argument given.\n"));
- GNUNET_free (keyfile);
+ hb = GNUNET_HELLO_builder_from_url (import_uri);
+ env = GNUNET_HELLO_builder_to_env (hb, NULL, GNUNET_TIME_UNIT_ZERO);
+ shc = GNUNET_PEERSTORE_hello_add (peerstore_handle,
+ GNUNET_MQ_env_get_msg (env),
+ &hello_store_success, NULL);
+ GNUNET_HELLO_builder_free (hb);
return;
}
- GNUNET_free (keyfile);
- GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
+
+ iter_ctx = GNUNET_PEERSTORE_iteration_start (peerstore_handle,
+ "peerstore",
+ NULL,
+ GNUNET_PEERSTORE_HELLO_KEY,
+ &hello_iter,
+ NULL);
+
}
@@ -251,7 +423,21 @@ main (int argc, char *const *argv)
"Show current connections"
),
&show_conns),
- GNUNET_GETOPT_OPTION_END };
+ GNUNET_GETOPT_option_flag ('H',
+ "export-hello-uri",
+ gettext_noop (
+ "Print a HELLO URI for our peer identity"),
+ &export_own_hello_uri),
+ GNUNET_GETOPT_option_string ('I',
+ "import-hello",
+ gettext_noop ("Import a HELLO URI"),
+ "URI",
+ &import_uri),
+ GNUNET_GETOPT_option_flag ('D',
+ "dump-hellos",
+ gettext_noop (
+ "List all known HELLOs in peerstore"),
+ &print_hellos), GNUNET_GETOPT_OPTION_END };
if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
@@ -266,7 +452,7 @@ main (int argc, char *const *argv)
GNUNET_free_nz ((void *) argv);
if (GNUNET_OK == res)
- return 0;
+ return ret;
return 1;
}
diff --git a/src/cli/core/meson.build b/src/cli/core/meson.build
index db246a3c4..144c911dc 100644
--- a/src/cli/core/meson.build
+++ b/src/cli/core/meson.build
@@ -1,6 +1,9 @@
executable ('gnunet-core',
['gnunet-core.c'],
- dependencies: [libgnunetcore_dep, libgnunetutil_dep],
+ dependencies: [libgnunetcore_dep,
+ libgnunetutil_dep,
+ libgnunethello_dep,
+ libgnunetpeerstore_dep],
include_directories: [incdir, configuration_inc],
install: true,
install_dir: get_option('bindir'))
diff --git a/src/cli/meson.build b/src/cli/meson.build
index 12662933d..5c1fded1a 100644
--- a/src/cli/meson.build
+++ b/src/cli/meson.build
@@ -1,7 +1,6 @@
subdir('util')
subdir('arm')
subdir('statistics')
-subdir('peerstore')
subdir('datastore')
subdir('nat')
subdir('nat-auto')
diff --git a/src/cli/peerstore/Makefile.am b/src/cli/peerstore/Makefile.am
deleted file mode 100644
index 3627fb9fc..000000000
--- a/src/cli/peerstore/Makefile.am
+++ /dev/null
@@ -1,24 +0,0 @@
-# This Makefile.am is in the public domain
-AM_CPPFLAGS = -I$(top_srcdir)/src/include
-
-plugindir = $(libdir)/gnunet
-
-pkgcfgdir= $(pkgdatadir)/config.d/
-
-libexecdir= $(pkglibdir)/libexec/
-
-if USE_COVERAGE
- AM_CFLAGS = -fprofile-arcs -ftest-coverage
-endif
-
-# This program does not do anything.
-bin_PROGRAMS = \
- gnunet-peerstore
-
-gnunet_peerstore_SOURCES = \
- gnunet-peerstore.c
-gnunet_peerstore_LDADD = \
- $(top_builddir)/src/lib/hello/libgnunethello.la \
- $(top_builddir)/src/lib/util/libgnunetutil.la \
- $(top_builddir)/src/service/peerstore/libgnunetpeerstore.la \
- $(GN_LIBINTL)
diff --git a/src/cli/peerstore/gnunet-peerstore.c
b/src/cli/peerstore/gnunet-peerstore.c
deleted file mode 100644
index f5c05fd9b..000000000
--- a/src/cli/peerstore/gnunet-peerstore.c
+++ /dev/null
@@ -1,237 +0,0 @@
-/*
- This file is part of GNUnet.
- Copyright (C)
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-
-/**
- * @file peerstore/gnunet-peerstore.c
- * @brief peerstore tool
- * @author Omar Tarabai
- */
-#include "gnunet_common.h"
-#include "gnunet_dht_service.h"
-#include "gnunet_scheduler_lib.h"
-#include "gnunet_time_lib.h"
-#include "platform.h"
-#include "gnunet_hello_uri_lib.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_peerstore_service.h"
-
-static int ret;
-
-/*
- * Handle to PEERSTORE service
- */
-static struct GNUNET_PEERSTORE_Handle *peerstore_handle;
-
-static struct GNUNET_PEERSTORE_IterateContext *iter_ctx;
-
-static struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key;
-
-static struct GNUNET_PeerIdentity my_full_id;
-
-static int export_own_hello_uri;
-
-static int print_hellos;
-
-static char *import_uri;
-
-/**
- * Run on shutdown
- *
- * @param cls unused
- */
-static void
-shutdown_task (void *cls)
-{
- if (NULL != peerstore_handle)
- {
- GNUNET_PEERSTORE_disconnect (peerstore_handle);
- peerstore_handle = NULL;
- }
-}
-
-
-/**
- * Callback function used to extract URIs from a builder.
- * Called when we should consider connecting to a peer.
- *
- * @param cls closure pointing to a `struct GNUNET_PeerIdentity *`
- * @param uri one of the URIs
- */
-void
-print_hello_addrs (void *cls,
- const struct GNUNET_PeerIdentity *pid,
- const char *uri)
-{
- (void) cls;
-
-
- printf (" `%s'\n", uri);
-}
-
-
-void
-hello_iter (void *cls, const struct GNUNET_PEERSTORE_Record *record,
- const char *emsg)
-{
- struct GNUNET_HELLO_Builder *hb;
- const struct GNUNET_PeerIdentity *pid;
- char *url;
-
- if ((NULL == record) && (NULL == emsg))
- {
- /** If we ever get here, we are newer than the existing record
- * or the only/first record.
- */
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
- if (NULL != emsg)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", emsg);
- GNUNET_PEERSTORE_iteration_next (iter_ctx, 1);
- return;
- }
- hb = GNUNET_HELLO_builder_from_msg (record->value);
- pid = GNUNET_HELLO_builder_get_id (hb);
- if (export_own_hello_uri)
- {
- if (0 == GNUNET_memcmp (&my_full_id,
- pid))
- {
- url = GNUNET_HELLO_builder_to_url (hb, my_private_key);
- printf ("%s\n", url);
- GNUNET_free (url);
- GNUNET_PEERSTORE_iteration_stop (iter_ctx);
- GNUNET_HELLO_builder_free (hb);
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
- }
- else if (print_hellos)
- {
- printf ("`%s':\n", GNUNET_i2s (pid));
- GNUNET_HELLO_builder_iterate (hb, &print_hello_addrs, NULL);
- }
- GNUNET_HELLO_builder_free (hb);
- GNUNET_PEERSTORE_iteration_next (iter_ctx, 1);
-}
-
-
-static void
-hello_store_success (void *cls, int success)
-{
- if (GNUNET_OK != success)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Storing hello uri failed\n");
- }
- GNUNET_SCHEDULER_shutdown ();
-}
-
-
-/**
- * Main function that will be run by the scheduler.
- *
- * @param cls closure
- * @param args remaining command-line arguments
- * @param cfgfile name of the configuration file used (for saving, can be
NULL!)
- * @param cfg configuration
- */
-static void
-run (void *cls,
- char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- struct GNUNET_HELLO_Builder *hb;
- struct GNUNET_MQ_Envelope *env;
-
- GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
- NULL);
- peerstore_handle = GNUNET_PEERSTORE_connect (cfg);
- GNUNET_assert (NULL != peerstore_handle);
- if (NULL != import_uri)
- {
- hb = GNUNET_HELLO_builder_from_url (import_uri);
- env = GNUNET_HELLO_builder_to_env (hb, NULL, GNUNET_TIME_UNIT_ZERO);
- GNUNET_PEERSTORE_hello_add (peerstore_handle,
- GNUNET_MQ_env_get_msg (env),
- &hello_store_success, NULL);
- GNUNET_HELLO_builder_free (hb);
- return;
- }
- if (! print_hellos && ! export_own_hello_uri)
- {
- fprintf (stderr, "No arguments provided\n");
- GNUNET_SCHEDULER_shutdown ();
- ret = 1;
- return;
- }
- my_private_key =
- GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg);
- GNUNET_CRYPTO_eddsa_key_get_public (my_private_key,
- &my_full_id.public_key);
- iter_ctx = GNUNET_PEERSTORE_iteration_start (peerstore_handle,
- "peerstore",
- NULL,
- GNUNET_PEERSTORE_HELLO_KEY,
- &hello_iter,
- NULL);
- ret = 0;
-}
-
-
-/**
- * The main function to peerstore.
- *
- * @param argc number of arguments from the command line
- * @param argv command line arguments
- * @return 0 ok, 1 on error
- */
-int
-main (int argc, char *const *argv)
-{
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_option_flag ('H',
- "export-hello-uri",
- gettext_noop (
- "Print a HELLO URI for our peer identity"),
- &export_own_hello_uri),
- GNUNET_GETOPT_option_string ('I',
- "import-hello",
- gettext_noop ("Import a HELLO URI"),
- "URI",
- &import_uri),
- GNUNET_GETOPT_option_flag ('D',
- "dump",
- gettext_noop (
- "List all known HELLOs in peerstore"),
- &print_hellos),
- GNUNET_GETOPT_OPTION_END
- };
-
- return (GNUNET_OK ==
- GNUNET_PROGRAM_run (argc, argv, "gnunet-peerstore [options [value]]",
- gettext_noop ("peerstore"), options, &run,
- NULL)) ? ret : 1;
-}
-
-
-/* end of gnunet-peerstore.c */
diff --git a/src/cli/peerstore/meson.build b/src/cli/peerstore/meson.build
deleted file mode 100644
index 33de80f4f..000000000
--- a/src/cli/peerstore/meson.build
+++ /dev/null
@@ -1,10 +0,0 @@
-executable ('gnunet-peerstore',
- 'gnunet-peerstore.c',
- dependencies: [libgnunetpeerstore_dep,
- libgnunetutil_dep,
- libgnunethello_dep
- ],
- include_directories: [incdir, configuration_inc],
- install: true,
- install_dir: get_option('bindir'))
-
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnunet] branch master updated: peerstore/core: Move peerstore HELLO functions to CORE; remove peerstore CLI; Fixes #9043,
gnunet <=