commit 6ec7330b4a030591217f2b9e201cf85ba0793498
parent 9114db5e9dd135c8c0294b0236a4a855c66bf849
Author: Jacki <jacki@thejackimonster.de>
Date: Sun, 22 Feb 2026 15:23:17 +0100
fs: use key ring for access to current peer identity
Signed-off-by: Jacki <jacki@thejackimonster.de>
Diffstat:
3 files changed, 32 insertions(+), 94 deletions(-)
diff --git a/src/service/fs/gnunet-service-fs.c b/src/service/fs/gnunet-service-fs.c
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- Copyright (C) 2009-2014, 2016 GNUnet e.V.
+ Copyright (C) 2009-2014, 2016, 2026 GNUnet e.V.
GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
@@ -289,21 +289,16 @@ struct GNUNET_BLOCK_Context *GSF_block_ctx;
struct GNUNET_CORE_Handle *GSF_core;
/**
- * Pointer to handle to the pils service (points to NULL until we've
+ * Pointer to handle of the pils key ring (points to NULL until we've
* connected to it).
*/
-struct GNUNET_PILS_Handle *GSF_pils;
+struct GNUNET_PILS_KeyRing *GSF_key_ring;
/**
* Are we introducing randomized delays for better anonymity?
*/
int GSF_enable_randomized_delays;
-/**
- * Identity of this peer.
- */
-struct GNUNET_PeerIdentity GSF_my_id;
-
/* ***************************** locals ******************************* */
/**
@@ -1138,16 +1133,16 @@ static void
shutdown_task (void *cls)
{
GSF_cadet_stop_server ();
- if (NULL != GSF_pils)
- {
- GNUNET_PILS_disconnect (GSF_pils);
- GSF_pils = NULL;
- }
if (NULL != GSF_core)
{
GNUNET_CORE_disconnect (GSF_core);
GSF_core = NULL;
}
+ if (NULL != GSF_key_ring)
+ {
+ GNUNET_PILS_destroy_key_ring (GSF_key_ring);
+ GSF_key_ring = NULL;
+ }
GSF_put_done_ ();
GSF_push_done_ ();
GSF_pending_request_done_ ();
@@ -1178,35 +1173,6 @@ shutdown_task (void *cls)
/**
- * Function called after GNUNET_PILS_connect has succeeded
- * (or failed for good). Note that the private key of the
- * peer is intentionally not exposed here; if you need it,
- * your process should try to read the private key file
- * directly (which should work if you are authorized...).
- *
- * @param cls closure
- * @param my_identity ID of this peer, NULL if we failed
- * @param cls closure given to #GNUNET_PILS_connect
- * @param parser the new HELLO from which the PID can be extracted
- * @param hash The hash of addresses the peer id is based on.
- * This hash is also returned by #GNUNET_PILS_feed_address.
- */
-static void
-pils_pid_change_cb (void *cls,
- const struct GNUNET_HELLO_Parser *parser,
- const struct GNUNET_HashCode *hash)
-{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "My current identity is `%s'\n",
- GNUNET_i2s_full (&GSF_my_id));
- GSF_my_id = *GNUNET_HELLO_parser_get_id (parser);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "My new identity is `%s'\n",
- GNUNET_i2s_full (&GSF_my_id));
-}
-
-
-/**
* Process fs requests.
*
* @param c configuration to use
@@ -1233,7 +1199,6 @@ main_init (const struct GNUNET_CONFIGURATION_Handle *c)
GNUNET_MQ_handler_end ()
};
int anon_p2p_off;
- char *keyfile;
struct GNUNET_CORE_ServiceInfo service_info = {
.service = GNUNET_CORE_SERVICE_FS,
.version = { 1, 0 },
@@ -1248,37 +1213,14 @@ main_init (const struct GNUNET_CONFIGURATION_Handle *c)
"fs",
"DISABLE_ANON_TRANSFER")
);
-
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (GSF_cfg,
- "PEER",
- "PRIVATE_KEY",
- &keyfile))
+ GSF_key_ring = GNUNET_PILS_create_key_ring (GSF_cfg);
+ if (NULL == GSF_key_ring)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _ (
- "FS service is lacking HOSTKEY configuration setting. Exiting.\n"));
- GNUNET_SCHEDULER_shutdown ();
- return GNUNET_SYSERR;
- }
- if (GNUNET_SYSERR ==
- GNUNET_CRYPTO_eddsa_key_from_file (keyfile,
- GNUNET_YES,
- &pk))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to setup peer's private key\n");
- GNUNET_SCHEDULER_shutdown ();
- GNUNET_free (keyfile);
+ _ ("Failed to connect to `%s' service.\n"),
+ "pils");
return GNUNET_SYSERR;
}
- GNUNET_free (keyfile);
- GNUNET_CRYPTO_eddsa_key_get_public (&pk,
- &GSF_my_id.public_key);
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "I am peer %s\n",
- GNUNET_i2s (&GSF_my_id));
GSF_core
= GNUNET_CORE_connect (GSF_cfg,
NULL,
@@ -1296,17 +1238,6 @@ main_init (const struct GNUNET_CONFIGURATION_Handle *c)
"core");
return GNUNET_SYSERR;
}
- GSF_pils
- = GNUNET_PILS_connect (GSF_cfg,
- &pils_pid_change_cb,
- NULL);
- if (NULL == GSF_pils)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _ ("Failed to connect to `%s' service.\n"),
- "pils");
- return GNUNET_SYSERR;
- }
cover_age_task =
GNUNET_SCHEDULER_add_delayed (COVER_AGE_FREQUENCY,
&age_cover_counters,
diff --git a/src/service/fs/gnunet-service-fs.h b/src/service/fs/gnunet-service-fs.h
@@ -26,6 +26,7 @@
#ifndef GNUNET_SERVICE_FS_H
#define GNUNET_SERVICE_FS_H
+#include "gnunet_pils_service.h"
#include "gnunet_util_lib.h"
#include "gnunet_statistics_service.h"
#include "gnunet_core_service.h"
@@ -47,7 +48,7 @@
* load must be going down).
*/
#define DATASTORE_LOAD_AUTODECLINE GNUNET_TIME_relative_multiply ( \
- GNUNET_TIME_UNIT_MILLISECONDS, 250)
+ GNUNET_TIME_UNIT_MILLISECONDS, 250)
/**
* Only the (mandatory) query is included.
@@ -217,9 +218,9 @@ extern struct GNUNET_TIME_Relative GSF_avg_latency;
extern struct GNUNET_ATS_PerformanceHandle *GSF_ats;
/**
- * Identity of this peer.
+ * PILS key ring.
*/
-extern struct GNUNET_PeerIdentity GSF_my_id;
+extern struct GNUNET_PILS_KeyRing *GSF_key_ring;
/**
* Typical priorities we're seeing from other peers right now. Since
diff --git a/src/service/fs/gnunet-service-fs_cp.c b/src/service/fs/gnunet-service-fs_cp.c
@@ -22,6 +22,8 @@
* @brief API to handle 'connected peers'
* @author Christian Grothoff
*/
+#include "gnunet_common.h"
+#include "gnunet_pils_service.h"
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_load_lib.h"
@@ -458,11 +460,13 @@ GSF_peer_connect_handler (void *cls,
struct GNUNET_MQ_Handle *mq,
enum GNUNET_CORE_PeerClass class)
{
+ const struct GNUNET_PeerIdentity *my_identity;
struct GSF_ConnectedPeer *cp;
- if (0 ==
- GNUNET_memcmp (&GSF_my_id,
- peer))
+ my_identity = GNUNET_PILS_key_ring_get_identity (GSF_key_ring);
+ GNUNET_assert (my_identity);
+
+ if (0 == GNUNET_memcmp (my_identity, peer))
return NULL;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Connected to peer %s\n",
@@ -477,7 +481,8 @@ GSF_peer_connect_handler (void *cls,
GNUNET_YES);
GNUNET_break (GNUNET_OK ==
GNUNET_CONTAINER_multipeermap_put (cp_map,
- GSF_connected_peer_get_identity2_ (
+ GSF_connected_peer_get_identity2_
+ (
cp),
cp,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
@@ -487,11 +492,11 @@ GSF_peer_connect_handler (void *cls,
GNUNET_NO);
cp->respect_iterate_req
= GNUNET_PEERSTORE_iteration_start (peerstore,
- "fs",
- peer,
- "respect",
- &peer_respect_cb,
- cp);
+ "fs",
+ peer,
+ "respect",
+ &peer_respect_cb,
+ cp);
GSF_iterate_pending_requests_ (&consider_peer_for_forwarding,
cp);
return cp;
@@ -1007,7 +1012,8 @@ test_exist_cb (void *cls,
"Have existing request with higher TTL, dropping new request.\n");
GNUNET_STATISTICS_update (GSF_stats,
gettext_noop
- ("# requests dropped due to higher-TTL request"),
+ ("# requests dropped due to higher-TTL request")
+ ,
1, GNUNET_NO);
tec->finished = GNUNET_YES;
return GNUNET_NO;