gnunet

Main GNUnet Logic
Log | Files | Refs | Submodules | README | LICENSE

commit 7fd0765daec1a60a0397bd34ab52287dfb83be28
parent 6ec7330b4a030591217f2b9e201cf85ba0793498
Author: Jacki <jacki@thejackimonster.de>
Date:   Sun, 22 Feb 2026 16:20:18 +0100

pils: implement initial callback with valid identity for key ring

Signed-off-by: Jacki <jacki@thejackimonster.de>

Diffstat:
Msrc/include/gnunet_pils_service.h | 6+++++-
Msrc/service/cadet/gnunet-service-cadet.c | 15++++++++-------
Msrc/service/core/gnunet-service-core_kx.c | 117++++++++++++++++++++++++++++++++-----------------------------------------------
Msrc/service/dht/gnunet-service-dht.c | 2+-
Msrc/service/dht/plugin_dhtu_gnunet.c | 8+++-----
Msrc/service/exit/gnunet-daemon-exit.c | 8+++-----
Msrc/service/fs/gnunet-service-fs.c | 2+-
Msrc/service/nse/gnunet-service-nse.c | 2+-
Msrc/service/pils/pils_api.c | 34+++++++++++++++++++++++++++++++---
Msrc/service/regex/gnunet-daemon-regexprofiler.c | 2+-
Msrc/service/regex/gnunet-service-regex.c | 2+-
Msrc/service/revocation/gnunet-service-revocation.c | 2+-
Msrc/service/transport/gnunet-communicator-http3.c | 2+-
Msrc/service/transport/gnunet-communicator-quic.c | 2+-
Msrc/service/transport/gnunet-communicator-tcp.c | 2+-
Msrc/service/transport/gnunet-communicator-udp.c | 2+-
Msrc/service/transport/gnunet-communicator-unix.c | 2+-
17 files changed, 108 insertions(+), 102 deletions(-)

diff --git a/src/include/gnunet_pils_service.h b/src/include/gnunet_pils_service.h @@ -253,10 +253,14 @@ GNUNET_PILS_cancel (struct GNUNET_PILS_Operation *op); * peer identity key. * * @param cfg configuration to use + * @param init_cb initial callback or NULL + * @param cls closure of callback or NULL * @return Handle to the PILS key ring or NULL on failure */ struct GNUNET_PILS_KeyRing* -GNUNET_PILS_create_key_ring (const struct GNUNET_CONFIGURATION_Handle *cfg); +GNUNET_PILS_create_key_ring (const struct GNUNET_CONFIGURATION_Handle *cfg, + GNUNET_SCHEDULER_TaskCallback init_cb, + void *cls); /** * Destroy a key ring handle and free its memory. diff --git a/src/service/cadet/gnunet-service-cadet.c b/src/service/cadet/gnunet-service-cadet.c @@ -484,11 +484,11 @@ handle_port_open (void *cls, "Open port %s requested by %s\n", GNUNET_h2s (&pmsg->port), GSC_2s (c)); - + my_identity = GNUNET_PILS_key_ring_get_identity (key_ring); - if (!my_identity) + if (! my_identity) return; - + if (NULL == c->ports) c->ports = GNUNET_CONTAINER_multihashmap_create (4, GNUNET_NO); @@ -1096,7 +1096,8 @@ GSC_handle_remote_channel_destroy (struct CadetClient *c, GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap32_remove (c->channels, ntohl ( - ccn.channel_of_client), + ccn.channel_of_client + ), ch)); } @@ -1290,7 +1291,7 @@ run (void *cls, LOG (GNUNET_ERROR_TYPE_WARNING, "Remove DROP_PERCENT from config file.\n"); LOG (GNUNET_ERROR_TYPE_WARNING, "**************************************\n"); } - key_ring = GNUNET_PILS_create_key_ring (c); + key_ring = GNUNET_PILS_create_key_ring (c, NULL, NULL); if (NULL == key_ring) { GNUNET_break (0); @@ -1324,8 +1325,8 @@ run (void *cls, * Define "main" method using service macro. */ GNUNET_SERVICE_MAIN -(GNUNET_OS_project_data_gnunet(), - "cadet", + (GNUNET_OS_project_data_gnunet (), + "cadet", GNUNET_SERVICE_OPTION_NONE, &run, &client_connect_cb, diff --git a/src/service/core/gnunet-service-core_kx.c b/src/service/core/gnunet-service-core_kx.c @@ -442,12 +442,6 @@ static struct GNUNET_SCHEDULER_Task *rekey_task; static struct GNUNET_NotificationContext *nc; /** - * Indicates whether we are still in the initialisation phase (waiting for our - * peer id). - */ -static enum GNUNET_GenericReturnValue init_phase; - -/** * Our services info string TODO */ static char *my_services_info = ""; @@ -2853,73 +2847,56 @@ GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx, } -/** - * Callback for PILS to be called once the peer id changes - * @param cls unused - * @param peer_id the new peer id - * @param hash the hash of the addresses corresponding to the fed addresses - */ -static void -peer_id_change_cb (void *cls, - const struct GNUNET_HELLO_Parser *parser, - const struct GNUNET_HashCode *hash) +void +GSC_KX_start (GNUNET_UNUSED void *cls) { const struct GNUNET_PeerIdentity *my_identity; - (void) cls; - my_identity = GNUNET_PILS_key_ring_get_identity (GSC_key_ring); - GNUNET_assert (NULL != my_identity); - // TODO check that hash matches last fed hash - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "This peer has now a new peer id: %s\n", - GNUNET_i2s (my_identity)); - /* Continue initialisation of core */ - if (GNUNET_YES == init_phase) - { - struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_hd_var_size (initiator_hello, - GNUNET_MESSAGE_TYPE_CORE_INITIATOR_HELLO, - struct InitiatorHello, - NULL), - GNUNET_MQ_hd_var_size (initiator_done, - GNUNET_MESSAGE_TYPE_CORE_INITIATOR_DONE, - struct InitiatorDone, - NULL), - GNUNET_MQ_hd_var_size (responder_hello, - GNUNET_MESSAGE_TYPE_CORE_RESPONDER_HELLO, - struct ResponderHello, + struct GNUNET_MQ_MessageHandler handlers[] = { + GNUNET_MQ_hd_var_size (initiator_hello, + GNUNET_MESSAGE_TYPE_CORE_INITIATOR_HELLO, + struct InitiatorHello, + NULL), + GNUNET_MQ_hd_var_size (initiator_done, + GNUNET_MESSAGE_TYPE_CORE_INITIATOR_DONE, + struct InitiatorDone, + NULL), + GNUNET_MQ_hd_var_size (responder_hello, + GNUNET_MESSAGE_TYPE_CORE_RESPONDER_HELLO, + struct ResponderHello, + NULL), + GNUNET_MQ_hd_var_size (encrypted_message, // TODO rename? + GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE_CAKE, // TODO rename! + struct EncryptedMessage, NULL), - GNUNET_MQ_hd_var_size (encrypted_message, // TODO rename? - GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE_CAKE, // TODO rename! - struct EncryptedMessage, - NULL), - GNUNET_MQ_handler_end () - }; - - nc = GNUNET_notification_context_create (1); - transport = - GNUNET_TRANSPORT_core_connect (GSC_cfg, - my_identity, - handlers, - NULL, // cls - this connection-independant - // cls seems not to be needed. - // the connection-specific cls - // will be set as a return value - // of - // handle_transport_notify_connect - &handle_transport_notify_connect, - &handle_transport_notify_disconnect); - if (NULL == transport) - { - GSC_KX_done (); - return; - } + GNUNET_MQ_handler_end () + }; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Connected to TRANSPORT\n"); + my_identity = GNUNET_PILS_key_ring_get_identity (GSC_key_ring); + GNUNET_assert (NULL != my_identity); - GSC_complete_initialization_cb (); - init_phase = GNUNET_NO; + nc = GNUNET_notification_context_create (1); + transport = + GNUNET_TRANSPORT_core_connect (GSC_cfg, + my_identity, + handlers, + NULL, // cls - this connection-independant + // cls seems not to be needed. + // the connection-specific cls + // will be set as a return value + // of + // handle_transport_notify_connect + &handle_transport_notify_connect, + &handle_transport_notify_disconnect); + if (NULL == transport) + { + GSC_KX_done (); + return; } + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Connected to TRANSPORT\n"); + + GSC_complete_initialization_cb (); } @@ -2931,8 +2908,8 @@ peer_id_change_cb (void *cls, int GSC_KX_init (void) { - init_phase = GNUNET_YES; - GSC_key_ring = GNUNET_PILS_create_key_ring (GSC_cfg); + GSC_key_ring = GNUNET_PILS_create_key_ring ( + GSC_cfg, &GSC_KX_start, NULL); if (NULL == GSC_key_ring) { @@ -2941,7 +2918,7 @@ GSC_KX_init (void) } pils = GNUNET_PILS_connect (GSC_cfg, - peer_id_change_cb, + NULL, NULL); if (NULL == pils) { diff --git a/src/service/dht/gnunet-service-dht.c b/src/service/dht/gnunet-service-dht.c @@ -501,7 +501,7 @@ run (void *cls, { GDS_cfg = c; GDS_service = service; - GDS_key_ring = GNUNET_PILS_create_key_ring (GDS_cfg); + GDS_key_ring = GNUNET_PILS_create_key_ring (GDS_cfg, NULL, NULL); GNUNET_assert (NULL != GDS_key_ring); GDS_pils = GNUNET_PILS_connect (GDS_cfg, pid_change_cb, NULL); GNUNET_assert (NULL != GDS_pils); diff --git a/src/service/dht/plugin_dhtu_gnunet.c b/src/service/dht/plugin_dhtu_gnunet.c @@ -463,12 +463,10 @@ static void core_init_cb (void *cls, const struct GNUNET_PeerIdentity *identity) { - const struct GNUNET_PeerIdentity *my_identity; struct Plugin *plugin = cls; - my_identity = GNUNET_PILS_key_ring_get_identity (plugin->key_ring); - GNUNET_assert ((my_identity) && - (0 == GNUNET_memcmp (my_identity, identity))); + if (NULL == identity) + return; plugin->peerstore_notify = GNUNET_PEERSTORE_monitor_start (plugin->env->cfg, GNUNET_YES, @@ -607,7 +605,7 @@ DHTU_gnunet_init (struct GNUNET_DHTU_PluginEnvironment *env) plugin = GNUNET_new (struct Plugin); plugin->key_ring = GNUNET_PILS_create_key_ring ( - env->cfg); + env->cfg, NULL, NULL); plugin->env = env; api = GNUNET_new (struct GNUNET_DHTU_PluginFunctions); api->cls = plugin; diff --git a/src/service/exit/gnunet-daemon-exit.c b/src/service/exit/gnunet-daemon-exit.c @@ -3764,11 +3764,9 @@ advertise_dns_exit () &clean_channel, handlers); /* advertise exit */ - dht = GNUNET_DHT_connect (cfg, - 1); - key_ring = GNUNET_PILS_create_key_ring (cfg); - dht_task = GNUNET_SCHEDULER_add_now (&do_initial_dht_put, - NULL); + dht = GNUNET_DHT_connect (cfg, 1); + dht_task = NULL; + key_ring = GNUNET_PILS_create_key_ring (cfg, &do_initial_dht_put, NULL); GNUNET_free (dns_exit); } diff --git a/src/service/fs/gnunet-service-fs.c b/src/service/fs/gnunet-service-fs.c @@ -1213,7 +1213,7 @@ main_init (const struct GNUNET_CONFIGURATION_Handle *c) "fs", "DISABLE_ANON_TRANSFER") ); - GSF_key_ring = GNUNET_PILS_create_key_ring (GSF_cfg); + GSF_key_ring = GNUNET_PILS_create_key_ring (GSF_cfg, NULL, NULL); if (NULL == GSF_key_ring) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, diff --git a/src/service/nse/gnunet-service-nse.c b/src/service/nse/gnunet-service-nse.c @@ -1567,7 +1567,7 @@ run (void *cls, #endif GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); - key_ring = GNUNET_PILS_create_key_ring (cfg); + key_ring = GNUNET_PILS_create_key_ring (cfg, NULL, NULL); GNUNET_assert (NULL != key_ring); if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "PROOFFILE", &proof)) diff --git a/src/service/pils/pils_api.c b/src/service/pils/pils_api.c @@ -133,6 +133,16 @@ struct GNUNET_PILS_KeyRing struct GNUNET_PILS_Handle *pils; /** + * Initial callback + */ + GNUNET_SCHEDULER_TaskCallback init_cb; + + /** + * Closure for initial callback + */ + void *cls; + + /** * Initial key material */ unsigned char initial_key_material[256 / 8]; @@ -631,6 +641,7 @@ pid_change_cb (void *cls, const struct GNUNET_HashCode *addr_hash) { struct GNUNET_PILS_KeyRing *key_ring; + enum GNUNET_GenericReturnValue initialized; GNUNET_assert ((cls) && (addr_hash)); @@ -640,7 +651,12 @@ pid_change_cb (void *cls, "Got PID to derive from `%s':\n", GNUNET_h2s (addr_hash)); if (NULL == key_ring->private_key) + { key_ring->private_key = GNUNET_new (struct GNUNET_CRYPTO_EddsaPrivateKey); + initialized = GNUNET_YES; + } + else + initialized = GNUNET_NO; GNUNET_PILS_derive_pid (sizeof (key_ring->initial_key_material), key_ring->initial_key_material, @@ -651,6 +667,14 @@ pid_change_cb (void *cls, GNUNET_CRYPTO_hash (&(key_ring->identity), sizeof (key_ring->identity), &(key_ring->hash)); + + if (GNUNET_YES != initialized) + return; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initialize key ring\n"); + + if (key_ring->init_cb) + key_ring->init_cb (key_ring->cls); } @@ -664,7 +688,9 @@ pid_change_cb (void *cls, * */ struct GNUNET_PILS_KeyRing* -GNUNET_PILS_create_key_ring (const struct GNUNET_CONFIGURATION_Handle *cfg) +GNUNET_PILS_create_key_ring (const struct GNUNET_CONFIGURATION_Handle *cfg, + GNUNET_SCHEDULER_TaskCallback init_cb, + void *cls) { char *keyfile; struct GNUNET_CRYPTO_EddsaPrivateKey key; @@ -696,10 +722,12 @@ GNUNET_PILS_create_key_ring (const struct GNUNET_CONFIGURATION_Handle *cfg) GNUNET_free (keyfile); - struct GNUNET_PILS_KeyRing *key_ring = GNUNET_new (struct GNUNET_PILS_KeyRing) - ; + struct GNUNET_PILS_KeyRing *key_ring = + GNUNET_new (struct GNUNET_PILS_KeyRing); if (NULL == key_ring) return NULL; + key_ring->init_cb = init_cb; + key_ring->cls = cls; GNUNET_assert (sizeof (key_ring->initial_key_material) == sizeof key.d); diff --git a/src/service/regex/gnunet-daemon-regexprofiler.c b/src/service/regex/gnunet-daemon-regexprofiler.c @@ -256,7 +256,7 @@ run (void *cls, char *const *args GNUNET_UNUSED, cfg = cfg_; - key_ring = GNUNET_PILS_create_key_ring (cfg); + key_ring = GNUNET_PILS_create_key_ring (cfg, NULL, NULL); GNUNET_assert (NULL != key_ring); if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "REGEXPROFILER", diff --git a/src/service/regex/gnunet-service-regex.c b/src/service/regex/gnunet-service-regex.c @@ -310,7 +310,7 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_SERVICE_Handle *service) { - key_ring = GNUNET_PILS_create_key_ring (cfg); + key_ring = GNUNET_PILS_create_key_ring (cfg, NULL, NULL); if (NULL == key_ring) { GNUNET_SCHEDULER_shutdown (); diff --git a/src/service/revocation/gnunet-service-revocation.c b/src/service/revocation/gnunet-service-revocation.c @@ -1023,7 +1023,7 @@ run (void *cls, peers = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_YES); - key_ring = GNUNET_PILS_create_key_ring (cfg); + key_ring = GNUNET_PILS_create_key_ring (cfg, NULL, NULL); /* Connect to core service and register core handlers */ core_api = GNUNET_CORE_connect (cfg, /* Main configuration */ NULL, /* Closure passed to functions */ diff --git a/src/service/transport/gnunet-communicator-http3.c b/src/service/transport/gnunet-communicator-http3.c @@ -3890,7 +3890,7 @@ run (void *cls, /** * Get our public key for initial packet */ - key_ring = GNUNET_PILS_create_key_ring (cfg); + key_ring = GNUNET_PILS_create_key_ring (cfg, NULL, NULL); if (NULL == key_ring) { GNUNET_log ( diff --git a/src/service/transport/gnunet-communicator-quic.c b/src/service/transport/gnunet-communicator-quic.c @@ -1657,7 +1657,7 @@ run (void *cls, /** * Get our public key for initial packet */ - key_ring = GNUNET_PILS_create_key_ring (cfg); + key_ring = GNUNET_PILS_create_key_ring (cfg, NULL, NULL); if (NULL == key_ring) { GNUNET_log ( diff --git a/src/service/transport/gnunet-communicator-tcp.c b/src/service/transport/gnunet-communicator-tcp.c @@ -4155,7 +4155,7 @@ run (void *cls, { disable_v6 = GNUNET_YES; } - key_ring = GNUNET_PILS_create_key_ring (cfg); + key_ring = GNUNET_PILS_create_key_ring (cfg, NULL, NULL); GNUNET_assert (NULL != key_ring); peerstore = GNUNET_PEERSTORE_connect (cfg); if (NULL == peerstore) diff --git a/src/service/transport/gnunet-communicator-udp.c b/src/service/transport/gnunet-communicator-udp.c @@ -3925,7 +3925,7 @@ run (void *cls, { broadcast_task = GNUNET_SCHEDULER_add_now (&do_broadcast, NULL); } - key_ring = GNUNET_PILS_create_key_ring (cfg); + key_ring = GNUNET_PILS_create_key_ring (cfg, NULL, NULL); GNUNET_assert (NULL != key_ring); nat = GNUNET_NAT_register (cfg, diff --git a/src/service/transport/gnunet-communicator-unix.c b/src/service/transport/gnunet-communicator-unix.c @@ -1015,7 +1015,7 @@ run (void *cls, (void) cls; delivering_messages = 0; - key_ring = GNUNET_PILS_create_key_ring (cfg); + key_ring = GNUNET_PILS_create_key_ring (cfg, NULL, NULL); if (NULL == key_ring) {