[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] branch master updated: meson: start working on libgnunet main l
From: |
gnunet |
Subject: |
[gnunet] branch master updated: meson: start working on libgnunet main loop |
Date: |
Tue, 17 Oct 2023 08:41:15 +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 a497ce624 meson: start working on libgnunet main loop
a497ce624 is described below
commit a497ce624d9460ceeb78d9c1d288aab94ffdb929
Author: Martin Schanzenbach <schanzen@gnunet.org>
AuthorDate: Tue Oct 17 08:41:09 2023 +0200
meson: start working on libgnunet main loop
---
src/include/gnunet_service_lib.h | 103 ++++++++++++++++++++++------
src/util/service.c | 142 +++++++++++++++++++++++++++------------
2 files changed, 182 insertions(+), 63 deletions(-)
diff --git a/src/include/gnunet_service_lib.h b/src/include/gnunet_service_lib.h
index 3ebfae581..6109d6e5e 100644
--- a/src/include/gnunet_service_lib.h
+++ b/src/include/gnunet_service_lib.h
@@ -19,7 +19,7 @@
*/
-#if !defined (__GNUNET_UTIL_LIB_H_INSIDE__)
+#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
#error "Only <gnunet_util_lib.h> can be included directly."
#endif
@@ -203,7 +203,6 @@ GNUNET_SERVICE_start (const char *service_name,
void
GNUNET_SERVICE_stop (struct GNUNET_SERVICE_Handle *srv);
-
/**
* Creates the "main" function for a GNUnet service. You
* should almost always use the #GNUNET_SERVICE_MAIN macro
@@ -257,6 +256,56 @@ GNUNET_SERVICE_run_ (int argc,
const struct GNUNET_MQ_MessageHandler *handlers);
+/**
+ * Registers the GNUnet service to be scheduled as part of a monilithic
+ * libgnunet.
+ * You should almost always use the #GNUNET_SERVICE_MAIN macro
+ * instead of calling this function directly.
+ *
+ * The function will launch the service with the name @a service_name
+ * using the @a service_options to configure its shutdown
+ * behavior. Once the service is ready, the @a init_cb will be called
+ * for service-specific initialization. @a init_cb will be given the
+ * service handler which can be used to control the service's
+ * availability. When clients connect or disconnect, the respective
+ * @a connect_cb or @a disconnect_cb functions will be called. For
+ * messages received from the clients, the respective @a handlers will
+ * be invoked; for the closure of the handlers we use the return value
+ * from the @a connect_cb invocation of the respective client.
+ *
+ * Each handler MUST call #GNUNET_SERVICE_client_continue() after each
+ * message to receive further messages from this client. If
+ * #GNUNET_SERVICE_client_continue() is not called within a short
+ * time, a warning will be logged. If delays are expected, services
+ * should call #GNUNET_SERVICE_client_disable_continue_warning() to
+ * disable the warning.
+ *
+ * Clients sending invalid messages (based on @a handlers) will be
+ * dropped. Additionally, clients can be dropped at any time using
+ * #GNUNET_SERVICE_client_drop().
+ *
+ * @param service_name name of the service to run
+ * @param options options controlling shutdown of the service
+ * @param service_init_cb function to call once the service is ready
+ * @param connect_cb function to call whenever a client connects
+ * @param disconnect_cb function to call whenever a client disconnects
+ * @param cls closure argument for @a service_init_cb, @a connect_cb and @a
disconnect_cb
+ * @param handlers NULL-terminated array of message handlers for the service,
+ * the closure will be set to the value returned by
+ * the @a connect_cb for the respective connection
+ * @return 0 on success, non-zero on error
+ */
+int
+GNUNET_SERVICE_register_ (
+ const char *service_name,
+ enum GNUNET_SERVICE_Options options,
+ GNUNET_SERVICE_InitCallback service_init_cb,
+ GNUNET_SERVICE_ConnectHandler connect_cb,
+ GNUNET_SERVICE_DisconnectHandler disconnect_cb,
+ void *cls,
+ const struct GNUNET_MQ_MessageHandler *handlers);
+
+
/**
* Creates the "main" function for a GNUnet service. You
* MUST use this macro to define GNUnet services (except
@@ -317,26 +366,40 @@ GNUNET_SERVICE_run_ (int argc,
#ifndef HAVE_GNUNET_MONOLITH
#define GNUNET_SERVICE_MAIN(service_name, service_options, init_cb,
connect_cb, \
disconnect_cb, cls, ...) \
- int \
- main (int argc, \
- char *const *argv) \
- { \
- struct GNUNET_MQ_MessageHandler mh[] = { \
- __VA_ARGS__ \
- }; \
- return GNUNET_SERVICE_run_ (argc, \
- argv, \
- service_name, \
- service_options, \
- init_cb, \
- connect_cb, \
- disconnect_cb, \
- cls, \
- mh); \
- }
+ int \
+ main (int argc, \
+ char *const *argv) \
+ { \
+ struct GNUNET_MQ_MessageHandler mh[] = { \
+ __VA_ARGS__ \
+ }; \
+ return GNUNET_SERVICE_run_ (argc, \
+ argv, \
+ service_name, \
+ service_options, \
+ init_cb, \
+ connect_cb, \
+ disconnect_cb, \
+ cls, \
+ mh); \
+ }
#else
#define GNUNET_SERVICE_MAIN(service_name, service_options, init_cb,
connect_cb, \
- disconnect_cb, cls, ...)
+ disconnect_cb, cls, ...) \
+ static int __attribute__ ((constructor)) \
+ init (void) \
+ { \
+ struct GNUNET_MQ_MessageHandler mh[] = { \
+ __VA_ARGS__ \
+ }; \
+ return GNUNET_SERVICE_register_ (service_name, \
+ service_options, \
+ init_cb, \
+ connect_cb, \
+ disconnect_cb, \
+ cls, \
+ mh); \
+ }
#endif
/**
diff --git a/src/util/service.c b/src/util/service.c
index 2c280f5a1..194251af2 100644
--- a/src/util/service.c
+++ b/src/util/service.c
@@ -41,10 +41,10 @@
#define LOG(kind, ...) GNUNET_log_from (kind, "util-service", __VA_ARGS__)
#define LOG_STRERROR(kind, syscall) \
- GNUNET_log_from_strerror (kind, "util-service", syscall)
+ GNUNET_log_from_strerror (kind, "util-service", syscall)
#define LOG_STRERROR_FILE(kind, syscall, filename) \
- GNUNET_log_from_strerror_file (kind, "util-service", syscall, filename)
+ GNUNET_log_from_strerror_file (kind, "util-service", syscall, filename)
/**
@@ -1923,47 +1923,6 @@ GNUNET_SERVICE_stop (struct GNUNET_SERVICE_Handle *srv)
}
-/**
- * Creates the "main" function for a GNUnet service. You
- * should almost always use the #GNUNET_SERVICE_MAIN macro
- * instead of calling this function directly (except
- * for ARM, which should call this function directly).
- *
- * The function will launch the service with the name @a service_name
- * using the @a service_options to configure its shutdown
- * behavior. Once the service is ready, the @a init_cb will be called
- * for service-specific initialization. @a init_cb will be given the
- * service handler which can be used to control the service's
- * availability. When clients connect or disconnect, the respective
- * @a connect_cb or @a disconnect_cb functions will be called. For
- * messages received from the clients, the respective @a handlers will
- * be invoked; for the closure of the handlers we use the return value
- * from the @a connect_cb invocation of the respective client.
- *
- * Each handler MUST call #GNUNET_SERVICE_client_continue() after each
- * message to receive further messages from this client. If
- * #GNUNET_SERVICE_client_continue() is not called within a short
- * time, a warning will be logged. If delays are expected, services
- * should call #GNUNET_SERVICE_client_disable_continue_warning() to
- * disable the warning.
- *
- * Clients sending invalid messages (based on @a handlers) will be
- * dropped. Additionally, clients can be dropped at any time using
- * #GNUNET_SERVICE_client_drop().
- *
- * @param argc number of command-line arguments in @a argv
- * @param argv array of command-line arguments
- * @param service_name name of the service to run
- * @param options options controlling shutdown of the service
- * @param service_init_cb function to call once the service is ready
- * @param connect_cb function to call whenever a client connects
- * @param disconnect_cb function to call whenever a client disconnects
- * @param cls closure argument for @a service_init_cb, @a connect_cb and @a
disconnect_cb
- * @param handlers NULL-terminated array of message handlers for the service,
- * the closure will be set to the value returned by
- * the @a connect_cb for the respective connection
- * @return 0 on success, non-zero on error
- */
int
GNUNET_SERVICE_run_ (int argc,
char *const *argv,
@@ -2177,6 +2136,103 @@ shutdown:
return err ? GNUNET_SYSERR : sh.ret;
}
+struct ServiceHandleList
+{
+ struct ServiceHandleList *prev;
+ struct ServiceHandleList *next;
+
+ struct GNUNET_SERVICE_Handle *sh;
+};
+
+int
+GNUNET_SERVICE_register_ (const char *service_name,
+ enum GNUNET_SERVICE_Options options,
+ GNUNET_SERVICE_InitCallback service_init_cb,
+ GNUNET_SERVICE_ConnectHandler connect_cb,
+ GNUNET_SERVICE_DisconnectHandler disconnect_cb,
+ void *cls,
+ const struct GNUNET_MQ_MessageHandler *handlers)
+{
+ static struct ServiceHandleList *hll_head = NULL;
+ static struct ServiceHandleList *hll_tail = NULL;
+ struct ServiceHandleList *hle;
+ struct GNUNET_CONFIGURATION_Handle *cfg;
+ struct GNUNET_SERVICE_Handle *sh = GNUNET_new (struct GNUNET_SERVICE_Handle);
+ const char *xdg;
+ char *cfg_filename;
+ const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get ();
+ int err;
+
+ err = 1;
+ xdg = getenv ("XDG_CONFIG_HOME");
+ if (NULL != xdg)
+ GNUNET_asprintf (&cfg_filename,
+ "%s%s%s",
+ xdg,
+ DIR_SEPARATOR_STR,
+ pd->config_file);
+ else
+ cfg_filename = GNUNET_strdup (pd->user_config_file);
+ sh->ready_confirm_fd = -1;
+ sh->options = options;
+ cfg = GNUNET_CONFIGURATION_create ();
+ sh->cfg = cfg;
+ sh->service_init_cb = service_init_cb;
+ sh->connect_cb = connect_cb;
+ sh->disconnect_cb = disconnect_cb;
+ sh->cb_cls = cls;
+ sh->handlers = (NULL == pd->agpl_url)
+ ? GNUNET_MQ_copy_handlers (handlers)
+ : GNUNET_MQ_copy_handlers2 (handlers, &return_agpl, NULL);
+ sh->service_name = service_name;
+ sh->ret = 0;
+ if (GNUNET_YES == GNUNET_DISK_file_test (cfg_filename))
+ {
+ if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, cfg_filename))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Malformed configuration file `%s', exit ...\n"),
+ cfg_filename);
+ goto fail;
+ }
+ }
+ else
+ {
+ if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, NULL))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Malformed configuration, exit ...\n"));
+ goto fail;
+ }
+ }
+ if (GNUNET_OK != setup_service (sh))
+ goto fail;
+ if (GNUNET_OK != set_user_id (sh))
+ goto fail;
+ GNUNET_RESOLVER_connect (sh->cfg);
+
+ /* actually run service */
+ err = 0;
+ hle = GNUNET_new (struct ServiceHandleList);
+ hle->sh = sh;
+ GNUNET_CONTAINER_DLL_insert (hll_head, hll_tail, hle);
+ /* shutdown */
+fail:
+ if (-1 != sh->ready_confirm_fd)
+ {
+ if (1 != write (sh->ready_confirm_fd, err ? "I" : "S", 1))
+ LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "write");
+ GNUNET_break (0 == close (sh->ready_confirm_fd));
+ }
+ teardown_service (sh);
+ GNUNET_free (sh->handlers);
+ GNUNET_SPEEDUP_stop_ ();
+ GNUNET_CONFIGURATION_destroy (cfg);
+ GNUNET_free (cfg_filename);
+ GNUNET_free (sh);
+ return err ? GNUNET_SYSERR : sh->ret;
+}
+
/**
* Suspend accepting connections from the listen socket temporarily.
--
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: meson: start working on libgnunet main loop,
gnunet <=