Removal of GNUNET_CONFIGURATION_default() in 0.23

Alessio Vanni <[email protected]> Tue, 10 Dec 2024 17:27:25 +0100
Newsgroups gmane.network.gnunet.devel
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------FB433F1CB8C33405F578A852
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit

Hello,

GNUnet 0.23 changed the way GNUNET_OS_ProjectData is used, moving it 
from being global state to a function parameter in commit 
9ab62c62c3d508033d31ea5289013255ec7a0c87.

The same commit also removes the GNUNET_CONFIGURATION_default function 
to return a new configuration object with GNUnet's "default" values.

This removal breaks third-party applications with a 
GNUNET_OS_ProjectData that is different from GNUnet's own, because the 
configuration object given as argument to the "main" function called by 
e.g. GNUNET_PROGRAM_run does not contain the values GNUnet expects.

I have attached a minimal test program to explain the issue. Compile it 
with:
gcc -o mybinary $(pkg-config --cflags gnunetutil) test.c $(pkg-config 
--libs gnunetutil)

then start GNUnet and execute the mybinary program. You will see that 
the program is not able to detect whether the GNS service is available 
or not despite being running.

The only way to make it work is to use GNUnet's configuration, but there 
is no way to obtain it without replicating GNUnet's logic (reading env 
variables, expanding paths, using defaults, etc.) which is something 
third-party applications should never do.

GNUNET_CONFIGURATION_create() only sets some path values, it does not 
load the actual configuration and that makes it unsuitable to connect to 
services due to missing important values found in each service's section 
of the configuration.

Applications which do not need to set a different project data value are 
not affected, since they can use GNUnet's own one.

Thank you,
A. V.

--------------FB433F1CB8C33405F578A852
Content-Type: text/x-csrc; charset=UTF-8;
 name="test.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="test.c"

#include <stdio.h>
#include <gnunet/gnunet_util_lib.h>

static struct GNUNET_OS_ProjectData project_data = {
     .libname = NULL,
     .project_dirname = NULL,
     .binary_name = "mybinary",
     .env_varname = "MYBINARY_ENV",
     .env_varname_alt = NULL,
     .base_config_varname = NULL,
     .bug_email = "",
     .homepage = NULL,
     .config_file = "mybinary.conf",
     .user_config_file = "~/.config/mybinary.conf",
     .version = "1.0",
     .is_gnu = 0,
     .gettext_domain = NULL,
     .gettext_path = NULL,
     .agpl_url = NULL,
};

static void
run_program(void *cls,
            char *const *args,
            const char *cfgfile,
            const struct GNUNET_CONFIGURATION_Handle *cfg) {
     if (GNUNET_YES == GNUNET_CLIENT_test(cfg, "gns")) {
          printf("I can reach GNUnet!\n");
     } else {
          printf("I cannot reach GNUnet!\n");
     }
}

int
main(int argc, char *argv[]) {
     struct GNUNET_GETOPT_CommandLineOption options[] = {
          GNUNET_GETOPT_OPTION_END,
     };

     enum GNUNET_GenericReturnValue code =
          GNUNET_PROGRAM_run(&project_data,
                             argc,
                             argv,
                             "mybinary",
                             "A test program",
                             options,
                             &run_program,
                             NULL);

     return 0;
}

--------------FB433F1CB8C33405F578A852--