GNUnet 0.21.1
Service library

Start service processes. More...

Collaboration diagram for Service library:

Macros

#define GNUNET_SERVICE_MAIN(service_name, service_options, init_cb, connect_cb, disconnect_cb, cls, ...)
 Creates the "main" function for a GNUnet service. More...
 

Typedefs

typedef void(* GNUNET_SERVICE_InitCallback) (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_SERVICE_Handle *sh)
 Callback to initialize a service, called exactly once when the service is run. More...
 
typedef void *(* GNUNET_SERVICE_ConnectHandler) (void *cls, struct GNUNET_SERVICE_Client *c, struct GNUNET_MQ_Handle *mq)
 Callback to be called when a client connects to the service. More...
 
typedef void(* GNUNET_SERVICE_DisconnectHandler) (void *cls, struct GNUNET_SERVICE_Client *c, void *internal_cls)
 Callback to be called when a client disconnected from the service. More...
 

Enumerations

enum  GNUNET_SERVICE_Options {
  GNUNET_SERVICE_OPTION_NONE = 0 , GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN = 1 , GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN = 2 , GNUNET_SERVICE_OPTION_SHUTDOWN_BITMASK = 3 ,
  GNUNET_SERVICE_OPTION_CLOSE_LSOCKS = 4
}
 Options for the service (bitmask). More...
 

Functions

struct GNUNET_SERVICE_HandleGNUNET_SERVICE_start (const char *service_name, const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_SERVICE_ConnectHandler connect_cb, GNUNET_SERVICE_DisconnectHandler disconnect_cb, void *cls, const struct GNUNET_MQ_MessageHandler *handlers)
 Low-level function to start a service if the scheduler is already running. More...
 
void GNUNET_SERVICE_stop (struct GNUNET_SERVICE_Handle *srv)
 Stops a service that was started with GNUNET_SERVICE_start(). More...
 
int GNUNET_SERVICE_run_ (int argc, char *const *argv, 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. More...
 
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)
 Registers the GNUnet service to be scheduled as part of a monilithic libgnunet. More...
 
void GNUNET_SERVICE_main (int argc, char *const *argv)
 Run the mainloop in a monolithic libgnunet. More...
 
void GNUNET_SERVICE_suspend (struct GNUNET_SERVICE_Handle *sh)
 Suspend accepting connections from the listen socket temporarily. More...
 
void GNUNET_SERVICE_resume (struct GNUNET_SERVICE_Handle *sh)
 Resume accepting connections from the listen socket. More...
 
void GNUNET_SERVICE_client_continue (struct GNUNET_SERVICE_Client *c)
 Continue receiving further messages from the given client. More...
 
struct GNUNET_MQ_HandleGNUNET_SERVICE_client_get_mq (struct GNUNET_SERVICE_Client *c)
 Obtain the message queue of c. More...
 
void GNUNET_SERVICE_client_disable_continue_warning (struct GNUNET_SERVICE_Client *c)
 Disable the warning the server issues if a message is not acknowledged in a timely fashion. More...
 
void GNUNET_SERVICE_client_drop (struct GNUNET_SERVICE_Client *c)
 Ask the server to disconnect from the given client. More...
 
void GNUNET_SERVICE_shutdown (struct GNUNET_SERVICE_Handle *sh)
 Explicitly stops the service. More...
 
void GNUNET_SERVICE_client_mark_monitor (struct GNUNET_SERVICE_Client *c)
 Set the 'monitor' flag on this client. More...
 
void GNUNET_SERVICE_client_persist (struct GNUNET_SERVICE_Client *c)
 Set the persist option on this client. More...
 

Detailed Description

Start service processes.

See also
Documentation

Macro Definition Documentation

◆ GNUNET_SERVICE_MAIN

#define GNUNET_SERVICE_MAIN (   service_name,
  service_options,
  init_cb,
  connect_cb,
  disconnect_cb,
  cls,
  ... 
)
Value:
main (int argc, \
char *const *argv) \
{ \
__VA_ARGS__ \
}; \
return GNUNET_SERVICE_run_ (argc, \
argv, \
service_options, \
cls, \
mh); \
}
int main(int argc, char *const *argv)
The main function to obtain arm from gnunetd.
Definition: gnunet-arm.c:969
static struct GNUNET_CADET_Handle * mh
Cadet handle.
Definition: gnunet-cadet.c:92
static void disconnect_cb(void *cls, const struct GNUNET_CADET_Channel *channel)
Function called by cadet when a client disconnects.
static void * connect_cb(void *cls, struct GNUNET_CADET_Channel *channel, const struct GNUNET_PeerIdentity *initiator)
Functions of this type are called upon new cadet connection from other peers.
static void init_cb(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_SERVICE_Handle *sh)
Service is starting, initialize everything.
static char * service_name
Option -s: service name (hash to get service descriptor)
Definition: gnunet-vpn.c:50
int GNUNET_SERVICE_run_(int argc, char *const *argv, 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.
Definition: service.c:1927
Message handler for a specific message type.

Creates the "main" function for a GNUnet service.

You MUST use this macro to define GNUnet services (except for ARM, which MUST NOT use the macro). The reason is the GNUnet-as-a-library project, where we will not define a main function anywhere but in ARM.

The macro will launch the service with the name service_name using the service_options to configure its shutdown behavior. Once the service is ready, the init_cb will be called for service-specific initialization. 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 connect_cb or disconnect_cb functions will be called. For messages received from the clients, the respective handlers will be invoked; for the closure of the handlers we use the return value from the 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 handlers) will be dropped. Additionally, clients can be dropped at any time using GNUNET_SERVICE_client_drop().

Parameters
service_namename of the service to run
service_optionsoptions controlling shutdown of the service
init_cbfunction to call once the service is ready
connect_cbfunction to call whenever a client connects
disconnect_cbfunction to call whenever a client disconnects
clsclosure argument for service_init_cb, connect_cb and disconnect_cb
...array of message handlers for the service, terminated by GNUNET_MQ_handler_end(); the closure will be set to the value returned by the connect_cb for the respective connection
Returns
0 on success, non-zero on error

Sample invocation: GNUNET_SERVICE_MAIN ("resolver", GNUNET_SERVICE_OPTION_NONE, &init_cb, &connect_cb, &disconnect_cb, closure_for_cb, GNUNET_MQ_hd_var_size (get, GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST, struct GNUNET_RESOLVER_GetMessage, NULL), GNUNET_MQ_handler_end ());

Definition at line 367 of file gnunet_service_lib.h.

Typedef Documentation

◆ GNUNET_SERVICE_InitCallback

typedef void(* GNUNET_SERVICE_InitCallback) (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_SERVICE_Handle *sh)

Callback to initialize a service, called exactly once when the service is run.

Parameters
clsclosure passed to GNUNET_SERVICE_MAIN
cfgconfiguration to use for this service
shhandle to the newly create service

Definition at line 120 of file gnunet_service_lib.h.

◆ GNUNET_SERVICE_ConnectHandler

typedef void *(* GNUNET_SERVICE_ConnectHandler) (void *cls, struct GNUNET_SERVICE_Client *c, struct GNUNET_MQ_Handle *mq)

Callback to be called when a client connects to the service.

Parameters
clsclosure for the service
cthe new client that connected to the service
mqthe message queue used to send messages to the client
Returns
the client-specific (‘internal’) closure

Definition at line 134 of file gnunet_service_lib.h.

◆ GNUNET_SERVICE_DisconnectHandler

typedef void(* GNUNET_SERVICE_DisconnectHandler) (void *cls, struct GNUNET_SERVICE_Client *c, void *internal_cls)

Callback to be called when a client disconnected from the service.

Parameters
clsclosure for the service
cthe client that disconnected
internal_clsthe client-specific (‘internal’) closure

Definition at line 147 of file gnunet_service_lib.h.

Enumeration Type Documentation

◆ GNUNET_SERVICE_Options

Options for the service (bitmask).

Enumerator
GNUNET_SERVICE_OPTION_NONE 

Use defaults.

Terminates all client connections and the listen sockets immediately upon receiving the shutdown signal.

GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN 

Do not trigger server shutdown on signal at all; instead, allow for the user to terminate the server explicitly when needed by calling GNUNET_SERVICE_shutdown().

GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN 

Trigger a SOFT server shutdown on signals, allowing active non-monitor clients to complete their transactions.

GNUNET_SERVICE_OPTION_SHUTDOWN_BITMASK 

Bitmask over the shutdown options.

GNUNET_SERVICE_OPTION_CLOSE_LSOCKS 

Instead of listening on lsocks passed by the parent, close them after opening our own listen socket(s).

Definition at line 65 of file gnunet_service_lib.h.

66{
72
79
85
90
96};
@ GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN
Do not trigger server shutdown on signal at all; instead, allow for the user to terminate the server ...
@ GNUNET_SERVICE_OPTION_SHUTDOWN_BITMASK
Bitmask over the shutdown options.
@ GNUNET_SERVICE_OPTION_CLOSE_LSOCKS
Instead of listening on lsocks passed by the parent, close them after opening our own listen socket(s...
@ GNUNET_SERVICE_OPTION_NONE
Use defaults.
@ GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN
Trigger a SOFT server shutdown on signals, allowing active non-monitor clients to complete their tran...

Function Documentation

◆ GNUNET_SERVICE_start()

struct GNUNET_SERVICE_Handle * GNUNET_SERVICE_start ( const char *  service_name,
const struct GNUNET_CONFIGURATION_Handle cfg,
GNUNET_SERVICE_ConnectHandler  connect_cb,
GNUNET_SERVICE_DisconnectHandler  disconnect_cb,
void *  cls,
const struct GNUNET_MQ_MessageHandler handlers 
)

Low-level function to start a service if the scheduler is already running.

Should only be used directly in special cases.

The function will launch the service with the name service_name using the service_options to configure its shutdown behavior. When clients connect or disconnect, the respective connect_cb or disconnect_cb functions will be called. For messages received from the clients, the respective handlers will be invoked; for the closure of the handlers we use the return value from the 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 handlers) will be dropped. Additionally, clients can be dropped at any time using GNUNET_SERVICE_client_drop().

The service must be stopped using GNUNET_SERVICE_stop().

Parameters
service_namename of the service to run
cfgconfiguration to use
connect_cbfunction to call whenever a client connects
disconnect_cbfunction to call whenever a client disconnects
clsclosure argument for connect_cb and disconnect_cb
handlersNULL-terminated array of message handlers for the service, the closure will be set to the value returned by the connect_cb for the respective connection
Returns
NULL on error

Definition at line 1880 of file service.c.

1886{
1887 struct GNUNET_SERVICE_Handle *sh;
1888
1890 sh->service_name = service_name;
1891 sh->cfg = cfg;
1892 sh->connect_cb = connect_cb;
1893 sh->disconnect_cb = disconnect_cb;
1894 sh->cb_cls = cls;
1895 sh->handlers = GNUNET_MQ_copy_handlers2 (handlers, &return_agpl, NULL);
1896 if (GNUNET_OK != setup_service (sh))
1897 {
1898 GNUNET_free (sh->handlers);
1899 GNUNET_free (sh);
1900 return NULL;
1901 }
1903 return sh;
1904}
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
static struct GNUNET_IDENTITY_Handle * sh
Handle to IDENTITY service.
@ GNUNET_OK
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_MQ_MessageHandler * GNUNET_MQ_copy_handlers2(const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_MessageCallback agpl_handler, void *agpl_cls)
Copy an array of handlers, appending AGPL handler.
Definition: mq.c:975
static void do_resume(struct GNUNET_SERVICE_Handle *sh, enum SuspendReason sr)
Resume accepting connections from the listen socket.
Definition: service.c:873
static void return_agpl(void *cls, const struct GNUNET_MessageHeader *msg)
Function to return link to AGPL source upon request.
Definition: service.c:1824
static int setup_service(struct GNUNET_SERVICE_Handle *sh)
Setup service handle.
Definition: service.c:1461
@ SUSPEND_STATE_NONE
We are running normally.
Definition: service.c:90
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition: identity_api.c:101
void * cb_cls
Closure for cb.
Definition: identity_api.c:122
Handle to a service.
Definition: service.c:118

References GNUNET_IDENTITY_Handle::cb_cls, cfg, GNUNET_IDENTITY_Handle::cfg, connect_cb(), disconnect_cb(), do_resume(), GNUNET_free, GNUNET_MQ_copy_handlers2(), GNUNET_new, GNUNET_OK, handlers, return_agpl(), service_name, setup_service(), sh, and SUSPEND_STATE_NONE.

Referenced by transport_communicator_start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SERVICE_stop()

void GNUNET_SERVICE_stop ( struct GNUNET_SERVICE_Handle srv)

Stops a service that was started with GNUNET_SERVICE_start().

Parameters
srvservice to stop

Definition at line 1913 of file service.c.

1914{
1915 struct GNUNET_SERVICE_Client *client;
1916
1918 while (NULL != (client = srv->clients_head))
1920 teardown_service (srv);
1921 GNUNET_free (srv->handlers);
1922 GNUNET_free (srv);
1923}
void GNUNET_SERVICE_suspend(struct GNUNET_SERVICE_Handle *sh)
Suspend accepting connections from the listen socket temporarily.
Definition: service.c:2347
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Definition: service.c:2489
static void teardown_service(struct GNUNET_SERVICE_Handle *sh)
Tear down the service, closing the listen sockets and freeing the ACLs.
Definition: service.c:1797
Handle to a client that is connected to a service.
Definition: service.c:252
struct GNUNET_MQ_MessageHandler * handlers
Message handlers to use for all clients.
Definition: service.c:172
struct GNUNET_SERVICE_Client * clients_head
Our clients, kept in a DLL.
Definition: service.c:162

References GNUNET_SERVICE_Handle::clients_head, GNUNET_free, GNUNET_SERVICE_client_drop(), GNUNET_SERVICE_suspend(), GNUNET_SERVICE_Handle::handlers, and teardown_service().

Referenced by shutdown_service().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SERVICE_run_()

int GNUNET_SERVICE_run_ ( int  argc,
char *const *  argv,
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 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 service_name using the service_options to configure its shutdown behavior. Once the service is ready, the init_cb will be called for service-specific initialization. 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 connect_cb or disconnect_cb functions will be called. For messages received from the clients, the respective handlers will be invoked; for the closure of the handlers we use the return value from the 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 handlers) will be dropped. Additionally, clients can be dropped at any time using GNUNET_SERVICE_client_drop().

Parameters
argcnumber of command-line arguments in argv
argvarray of command-line arguments
service_namename of the service to run
optionsoptions controlling shutdown of the service
service_init_cbfunction to call once the service is ready
connect_cbfunction to call whenever a client connects
disconnect_cbfunction to call whenever a client disconnects
clsclosure argument for service_init_cb, connect_cb and disconnect_cb
handlersNULL-terminated array of message handlers for the service, the closure will be set to the value returned by the connect_cb for the respective connection
Returns
0 on success, non-zero on error

Definition at line 1927 of file service.c.

1936{
1938
1939#if ENABLE_NLS
1940 char *path;
1941#endif
1942 char *cfg_filename;
1943 char *opt_cfg_filename;
1944 char *loglev;
1945 const char *xdg;
1946 char *logfile;
1947 int do_daemonize;
1948 unsigned long long skew_offset;
1949 unsigned long long skew_variance;
1950 long long clock_offset;
1952 int ret;
1953 int err;
1955 struct GNUNET_GETOPT_CommandLineOption service_options[] = {
1956 GNUNET_GETOPT_option_cfgfile (&opt_cfg_filename),
1958 "daemonize",
1959 gettext_noop (
1960 "do daemonize (detach from terminal)"),
1961 &do_daemonize),
1967 };
1968
1969 err = 1;
1970 memset (&sh, 0, sizeof(sh));
1971 xdg = getenv ("XDG_CONFIG_HOME");
1972 if (NULL != xdg)
1974 "%s%s%s",
1975 xdg,
1977 pd->config_file);
1978 else
1980 sh.ready_confirm_fd = -1;
1981 sh.options = options;
1983 sh.service_init_cb = service_init_cb;
1984 sh.connect_cb = connect_cb;
1985 sh.disconnect_cb = disconnect_cb;
1986 sh.cb_cls = cls;
1987 sh.handlers = (NULL == pd->agpl_url)
1990 sh.service_name = service_name;
1991 sh.ret = 0;
1992 /* setup subsystems */
1993 loglev = NULL;
1994 logfile = NULL;
1995 opt_cfg_filename = NULL;
1996 do_daemonize = 0;
1997#if ENABLE_NLS
1998 if (NULL != pd->gettext_domain)
1999 {
2000 setlocale (LC_ALL, "");
2001 path = (NULL == pd->gettext_path) ?
2004 if (NULL != path)
2005 {
2006 bindtextdomain (pd->gettext_domain, path);
2007 GNUNET_free (path);
2008 }
2010 }
2011#endif
2013 service_options,
2014 argc,
2015 argv);
2016 if (GNUNET_SYSERR == ret)
2017 goto shutdown;
2018 if (GNUNET_NO == ret)
2019 {
2020 err = 0;
2021 goto shutdown;
2022 }
2024 loglev,
2025 logfile))
2026 {
2027 GNUNET_break (0);
2028 goto shutdown;
2029 }
2030 if (NULL != opt_cfg_filename)
2031 {
2032 if ((GNUNET_YES != GNUNET_DISK_file_test (opt_cfg_filename)) ||
2033 (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, opt_cfg_filename)))
2034 {
2036 _ ("Malformed configuration file `%s', exit ...\n"),
2037 opt_cfg_filename);
2038 goto shutdown;
2039 }
2040 }
2041 else
2042 {
2044 {
2046 {
2048 _ ("Malformed configuration file `%s', exit ...\n"),
2049 cfg_filename);
2050 goto shutdown;
2051 }
2052 }
2053 else
2054 {
2056 {
2058 _ ("Malformed configuration, exit ...\n"));
2059 goto shutdown;
2060 }
2061 }
2062 }
2063 if (GNUNET_OK != setup_service (&sh))
2064 goto shutdown;
2065 if ((1 == do_daemonize) && (GNUNET_OK != detach_terminal (&sh)))
2066 {
2067 GNUNET_break (0);
2068 goto shutdown;
2069 }
2070 if (GNUNET_OK != set_user_id (&sh))
2071 goto shutdown;
2073 "Service `%s' runs with configuration from `%s'\n",
2075 (NULL != opt_cfg_filename) ? opt_cfg_filename : cfg_filename);
2077 "TESTING",
2078 "SKEW_OFFSET",
2079 &skew_offset)) &&
2081 "TESTING",
2082 "SKEW_VARIANCE",
2083 &skew_variance)))
2084 {
2085 clock_offset = skew_offset - skew_variance;
2086 GNUNET_TIME_set_offset (clock_offset);
2088 "Skewing clock by %lld ms\n",
2089 (long long) clock_offset);
2090 }
2092
2093 /* actually run service */
2094 err = 0;
2096 /* shutdown */
2097 if (1 == do_daemonize)
2099
2100shutdown:
2101 if (-1 != sh.ready_confirm_fd)
2102 {
2103 if (1 != write (sh.ready_confirm_fd, err ? "I" : "S", 1))
2105 GNUNET_break (0 == close (sh.ready_confirm_fd));
2106 }
2107#if HAVE_MALLINFO2
2108 {
2109 char *counter;
2110
2113 "GAUGER_HEAP")) &&
2116 "GAUGER_HEAP",
2117 &counter)))
2118 {
2119 struct mallinfo2 mi;
2120
2121 mi = mallinfo2 ();
2122 GAUGER (service_name, counter, mi.usmblks, "blocks");
2123 GNUNET_free (counter);
2124 }
2125 }
2126#endif
2128 GNUNET_free (sh.handlers);
2131 GNUNET_free (logfile);
2132 GNUNET_free (loglev);
2134 GNUNET_free (opt_cfg_filename);
2135
2136 return err ? GNUNET_SYSERR : sh.ret;
2137}
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define GAUGER(category, counter, value, unit)
Definition: gauger.h:19
char * getenv()
#define gettext_noop(String)
Definition: gettext.h:70
#define textdomain(Domainname)
Definition: gettext.h:57
#define bindtextdomain(Domainname, Dirname)
Definition: gettext.h:58
static int ret
Final status code.
Definition: gnunet-arm.c:94
static char * cfg_filename
Name of the configuration file.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load configuration.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_have_value(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Test if we have a value for a particular option.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
Definition: disk.c:482
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_cfgfile(char **fn)
Allow user to specify configuration file name (-c option)
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_logfile(char **logfn)
Allow user to specify log file name (-l option)
int GNUNET_GETOPT_run(const char *binaryOptions, const struct GNUNET_GETOPT_CommandLineOption *allOptions, unsigned int argc, char *const *argv)
Parse the command line.
Definition: getopt.c:884
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_help(const char *about)
Defining the option to print the command line help text (-h option).
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_loglevel(char **level)
Define the '-L' log level option.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag(char shortName, const char *name, const char *description, int *val)
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_version(const char *version)
Define the option to print the version of the application (-v option)
#define GNUNET_log(kind,...)
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
enum GNUNET_GenericReturnValue GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
struct GNUNET_MQ_MessageHandler * GNUNET_MQ_copy_handlers(const struct GNUNET_MQ_MessageHandler *handlers)
Copy an array of handlers.
Definition: mq.c:957
char * GNUNET_OS_installation_get_path(enum GNUNET_OS_InstallationPathKind dirkind)
Get the path to a specific GNUnet installation directory or, with GNUNET_OS_IPK_SELF_PREFIX,...
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_get(void)
@ GNUNET_OS_IPK_LOCALEDIR
Return the directory where translations are installed (share/locale/)
void GNUNET_RESOLVER_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create the connection to the resolver service.
Definition: resolver_api.c:258
void GNUNET_SCHEDULER_run(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Initialize and run scheduler.
Definition: scheduler.c:720
void GNUNET_TIME_set_offset(long long offset)
Set the timestamp offset for this instance.
Definition: time.c:49
#define DIR_SEPARATOR_STR
Definition: platform.h:166
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
static int detach_terminal(struct GNUNET_SERVICE_Handle *sh)
Detach from terminal.
Definition: service.c:1717
static int set_user_id(struct GNUNET_SERVICE_Handle *sh)
Set user ID.
Definition: service.c:1628
static void pid_file_delete(struct GNUNET_SERVICE_Handle *sh)
Delete the PID file that was created by our parent.
Definition: service.c:1698
static void service_main(void *cls)
First task run by any service.
Definition: service.c:901
#define LOG(kind,...)
Definition: service.c:41
#define LOG_STRERROR(kind, syscall)
Definition: service.c:43
void GNUNET_SPEEDUP_stop_()
Stop tasks that modify clock behavior.
Definition: speedup.c:100
Definition of a command line option.
Project-specific data used to help the OS subsystem find installation paths.
char * gettext_path
Gettext directory, e.g.
const char * user_config_file
Configuration file name to use (if $XDG_CONFIG_HOME is not set).
const char * config_file
Configuration file name (in $XDG_CONFIG_HOME) to use.
char * gettext_domain
Gettext domain for localisation, e.g.
const char * version
String identifying the current project version.
char * agpl_url
URL pointing to the source code of the application.

References _, GNUNET_OS_ProjectData::agpl_url, bindtextdomain, GNUNET_IDENTITY_Handle::cb_cls, cfg, GNUNET_IDENTITY_Handle::cfg, cfg_filename, GNUNET_OS_ProjectData::config_file, connect_cb(), detach_terminal(), DIR_SEPARATOR_STR, disconnect_cb(), GAUGER, getenv(), GNUNET_OS_ProjectData::gettext_domain, gettext_noop, GNUNET_OS_ProjectData::gettext_path, GNUNET_asprintf(), GNUNET_break, GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_have_value(), GNUNET_CONFIGURATION_load(), GNUNET_DISK_file_test(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_GETOPT_option_cfgfile(), GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_flag(), GNUNET_GETOPT_option_help(), GNUNET_GETOPT_option_logfile(), GNUNET_GETOPT_option_loglevel(), GNUNET_GETOPT_option_version(), GNUNET_GETOPT_run(), GNUNET_log, GNUNET_log_setup(), GNUNET_MQ_copy_handlers(), GNUNET_MQ_copy_handlers2(), GNUNET_NO, GNUNET_OK, GNUNET_OS_installation_get_path(), GNUNET_OS_IPK_LOCALEDIR, GNUNET_OS_project_data_get(), GNUNET_RESOLVER_connect(), GNUNET_SCHEDULER_run(), GNUNET_SPEEDUP_stop_(), GNUNET_strdup, GNUNET_SYSERR, GNUNET_TIME_set_offset(), GNUNET_YES, handlers, LOG, LOG_STRERROR, options, pid_file_delete(), ret, return_agpl(), service_main(), service_name, set_user_id(), setup_service(), sh, teardown_service(), textdomain, GNUNET_OS_ProjectData::user_config_file, and GNUNET_OS_ProjectData::version.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SERVICE_register_()

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 
)

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 service_name using the service_options to configure its shutdown behavior. Once the service is ready, the init_cb will be called for service-specific initialization. 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 connect_cb or disconnect_cb functions will be called. For messages received from the clients, the respective handlers will be invoked; for the closure of the handlers we use the return value from the 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 handlers) will be dropped. Additionally, clients can be dropped at any time using GNUNET_SERVICE_client_drop().

Parameters
service_namename of the service to run
optionsoptions controlling shutdown of the service
service_init_cbfunction to call once the service is ready
connect_cbfunction to call whenever a client connects
disconnect_cbfunction to call whenever a client disconnects
clsclosure argument for service_init_cb, connect_cb and disconnect_cb
handlersNULL-terminated array of message handlers for the service, the closure will be set to the value returned by the connect_cb for the respective connection
Returns
0 on success, non-zero on error

Definition at line 2162 of file service.c.

2169{
2170 struct ServiceHandleList *hle;
2173
2174 sh->ready_confirm_fd = -1;
2175 sh->options = options;
2176 sh->service_init_cb = service_init_cb;
2177 sh->connect_cb = connect_cb;
2178 sh->disconnect_cb = disconnect_cb;
2179 sh->cb_cls = cls;
2180 sh->handlers = (NULL == pd->agpl_url)
2183 sh->service_name = service_name;
2184 sh->ret = 0;
2185 hle = GNUNET_new (struct ServiceHandleList);
2186 hle->sh = sh;
2188 return GNUNET_OK;
2189}
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
static struct ServiceHandleList * hll_head
Definition: service.c:2156
static struct ServiceHandleList * hll_tail
Definition: service.c:2159
struct GNUNET_SERVICE_Handle * sh
Definition: service.c:2152

References GNUNET_OS_ProjectData::agpl_url, GNUNET_IDENTITY_Handle::cb_cls, connect_cb(), disconnect_cb(), GNUNET_CONTAINER_DLL_insert, GNUNET_MQ_copy_handlers(), GNUNET_MQ_copy_handlers2(), GNUNET_new, GNUNET_OK, GNUNET_OS_project_data_get(), handlers, hll_head, hll_tail, options, return_agpl(), service_name, sh, and ServiceHandleList::sh.

Here is the call graph for this function:

◆ GNUNET_SERVICE_main()

void GNUNET_SERVICE_main ( int  argc,
char *const *  argv 
)

Run the mainloop in a monolithic libgnunet.

Must be called such that services are actually launched.

Definition at line 2237 of file service.c.

2239{
2240 char *cfg_filename;
2241 char *opt_cfg_filename;
2242 char *logfile;
2243 char *loglev;
2244 const char *xdg;
2245 int do_daemonize;
2246 int ret;
2249
2250 struct GNUNET_GETOPT_CommandLineOption service_options[] = {
2251 GNUNET_GETOPT_option_cfgfile (&opt_cfg_filename),
2253 "daemonize",
2254 gettext_noop (
2255 "do daemonize (detach from terminal)"),
2256 &do_daemonize),
2262 };
2263 xdg = getenv ("XDG_CONFIG_HOME");
2264 if (NULL != xdg)
2266 "%s%s%s",
2267 xdg,
2269 pd->config_file);
2270 else
2273 // FIXME we need to set this up for each service!
2274 ret = GNUNET_GETOPT_run ("libgnunet",
2275 service_options,
2276 argc,
2277 argv);
2278 if (GNUNET_SYSERR == ret)
2279 goto shutdown;
2280 if (GNUNET_NO == ret)
2281 {
2282 goto shutdown;
2283 }
2284 // FIXME we need to set this up for each service!
2285 if (GNUNET_OK != GNUNET_log_setup ("libgnunet",
2286 loglev,
2287 logfile))
2288 {
2289 GNUNET_break (0);
2290 goto shutdown;
2291 }
2292 if (NULL != opt_cfg_filename)
2293 {
2294 if ((GNUNET_YES != GNUNET_DISK_file_test (opt_cfg_filename)) ||
2295 (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, opt_cfg_filename)))
2296 {
2298 _ ("Malformed configuration file `%s', exit ...\n"),
2299 opt_cfg_filename);
2300 goto shutdown;
2301 }
2302 }
2303 else
2304 {
2306 {
2308 {
2310 _ ("Malformed configuration file `%s', exit ...\n"),
2311 cfg_filename);
2313 return;
2314 }
2315 }
2316 else
2317 {
2319 {
2321 _ ("Malformed configuration, exit ...\n"));
2323 return;
2324 }
2325 }
2326 }
2328
2330shutdown:
2333 GNUNET_free (logfile);
2334 GNUNET_free (loglev);
2336 GNUNET_free (opt_cfg_filename);
2337}
static void launch_registered_services(void *cls)
Definition: service.c:2217

References _, cfg, cfg_filename, GNUNET_OS_ProjectData::config_file, DIR_SEPARATOR_STR, getenv(), gettext_noop, GNUNET_asprintf(), GNUNET_break, GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_load(), GNUNET_DISK_file_test(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_GETOPT_option_cfgfile(), GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_flag(), GNUNET_GETOPT_option_help(), GNUNET_GETOPT_option_logfile(), GNUNET_GETOPT_option_loglevel(), GNUNET_GETOPT_option_version(), GNUNET_GETOPT_run(), GNUNET_log, GNUNET_log_setup(), GNUNET_NO, GNUNET_OK, GNUNET_OS_project_data_get(), GNUNET_RESOLVER_connect(), GNUNET_SCHEDULER_run(), GNUNET_SPEEDUP_stop_(), GNUNET_strdup, GNUNET_SYSERR, GNUNET_YES, launch_registered_services(), ret, GNUNET_OS_ProjectData::user_config_file, and GNUNET_OS_ProjectData::version.

Here is the call graph for this function:

◆ GNUNET_SERVICE_suspend()

void GNUNET_SERVICE_suspend ( struct GNUNET_SERVICE_Handle sh)

Suspend accepting connections from the listen socket temporarily.

Resume activity using GNUNET_SERVICE_resume.

Parameters
shservice to stop accepting connections.

Definition at line 2347 of file service.c.

2348{
2350}
static void do_suspend(struct GNUNET_SERVICE_Handle *sh, enum SuspendReason sr)
Suspend accepting connections from the listen socket temporarily.
Definition: service.c:383
@ SUSPEND_STATE_APP
Application requested it.
Definition: service.c:95

References do_suspend(), sh, and SUSPEND_STATE_APP.

Referenced by GNUNET_SERVICE_stop(), and run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SERVICE_resume()

void GNUNET_SERVICE_resume ( struct GNUNET_SERVICE_Handle sh)

Resume accepting connections from the listen socket.

Parameters
shservice to resume accepting connections.

Definition at line 2359 of file service.c.

2360{
2362}

References do_resume(), sh, and SUSPEND_STATE_APP.

Referenced by begin_service(), and run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SERVICE_client_continue()

void GNUNET_SERVICE_client_continue ( struct GNUNET_SERVICE_Client c)

Continue receiving further messages from the given client.

Must be called after each message received.

Parameters
cthe client to continue receiving from

Definition at line 2408 of file service.c.

2409{
2410 GNUNET_assert (NULL == c->drop_task);
2412 GNUNET_assert (NULL == c->recv_task);
2414 if (NULL != c->warn_task)
2415 {
2417 c->warn_task = NULL;
2418 }
2420}
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1299
static void resume_client_receive(void *cls)
Task run to resume receiving data from the client after the client called GNUNET_SERVICE_client_conti...
Definition: service.c:2372
int needs_continue
Are we waiting for the application to call GNUNET_SERVICE_client_continue()?
Definition: service.c:345
struct GNUNET_SCHEDULER_Task * drop_task
Task run to finish dropping the client after the stack has properly unwound.
Definition: service.c:293
struct GNUNET_SCHEDULER_Task * warn_task
Task that warns about missing calls to GNUNET_SERVICE_client_continue().
Definition: service.c:287
struct GNUNET_SCHEDULER_Task * recv_task
Task that receives data from the client to pass it to the handlers.
Definition: service.c:299

References GNUNET_SERVICE_Client::drop_task, GNUNET_assert, GNUNET_NO, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_YES, GNUNET_SERVICE_Client::needs_continue, GNUNET_SERVICE_Client::recv_task, resume_client_receive(), and GNUNET_SERVICE_Client::warn_task.

Referenced by conclude_autoconfig_request(), continue_store_activity(), finish_cmc_handling_with_continue(), handle_add_address(), handle_add_queue_message(), handle_alice_client_message(), handle_alice_client_message_multipart(), handle_announce(), handle_attribute_delete_message(), handle_attribute_store_message(), handle_block_cache(), handle_bob_client_message(), handle_bob_client_message_multipart(), handle_channel_create(), handle_channel_destroy(), handle_client_accept(), handle_client_audio_message(), handle_client_call_message(), handle_client_cancel(), handle_client_conclude(), handle_client_copy_lazy_connect(), handle_client_copy_lazy_prepare(), handle_client_create_set(), handle_client_decrypt(), handle_client_evaluate(), handle_client_hangup_message(), handle_client_index_list_get(), handle_client_init(), handle_client_insert(), handle_client_iter_ack(), handle_client_iterate(), handle_client_join(), handle_client_keygen(), handle_client_listen(), handle_client_loc_sign(), handle_client_monitor_peers(), handle_client_mutation(), handle_client_pickup_message(), handle_client_recv_ok(), handle_client_redirect_to_ip(), handle_client_redirect_to_service(), handle_client_register_message(), handle_client_reject(), handle_client_response(), handle_client_resume_message(), handle_client_seed(), handle_client_send(), handle_client_send_request(), handle_client_set_add(), handle_client_start(), handle_client_start_search(), handle_client_start_sub(), handle_client_stop_sub(), handle_client_stream_cancel(), handle_client_stream_request(), handle_client_suspend_message(), handle_client_unindex(), handle_client_view_cancel(), handle_client_view_request(), handle_collect(), handle_communicator_available(), handle_communicator_backchannel(), handle_consume_ticket_message(), handle_create(), handle_create_message(), handle_credential_delete_message(), handle_credential_iteration_next(), handle_credential_iteration_start(), handle_credential_iteration_stop(), handle_credential_store_message(), handle_del_address(), handle_del_queue_message(), handle_delete_message(), handle_dht_local_get(), handle_dht_local_get_stop(), handle_dht_local_hello_get(), handle_dht_local_hello_offer(), handle_dht_local_monitor(), handle_dht_local_monitor_stop(), handle_dht_local_put(), handle_disconnect(), handle_drop(), handle_drop_message(), handle_edit_record_set(), handle_edit_record_set_cancel(), handle_get(), handle_get_key(), handle_get_message(), handle_get_peers(), handle_get_replication(), handle_get_zero_anonymity(), handle_incoming_msg(), handle_info_tunnels(), handle_issue_ticket_message(), handle_iterate_stop(), handle_iteration_next(), handle_iteration_start(), handle_iteration_stop(), handle_list(), handle_local_ack(), handle_local_data(), handle_lookup(), handle_lookup_block(), handle_lookup_by_suffix_message(), handle_lookup_message(), handle_monitor(), handle_monitor_next(), handle_monitor_start(), handle_port_close(), handle_port_open(), handle_put(), handle_query_message(), handle_queue_create_fail(), handle_queue_create_ok(), handle_record_lookup(), handle_record_store(), handle_register(), handle_release_reserve(), handle_remove(), handle_rename_message(), handle_request_connection_reversal(), handle_request_hello_validation(), handle_reserve(), handle_revoke_message(), handle_revoke_ticket_message(), handle_room_close(), handle_room_entry(), handle_room_open(), handle_room_sync(), handle_search(), handle_send_message(), handle_send_message_ack(), handle_set(), handle_show_path(), handle_start(), handle_start_message(), handle_stop(), handle_stun(), handle_suggest(), handle_suggest_cancel(), handle_test(), handle_ticket_iteration_next(), handle_ticket_iteration_start(), handle_ticket_iteration_stop(), handle_update_queue_message(), handle_verify(), handle_watch(), handle_zone_to_name(), hash_for_index_val(), iteration_done_client_continue(), return_agpl(), service_mq_error_handler(), signal_index_ok(), start_p2p_processing(), store_record_continuation(), and zone_iteration_done_client_continue().

Here is the call graph for this function:

◆ GNUNET_SERVICE_client_get_mq()

struct GNUNET_MQ_Handle * GNUNET_SERVICE_client_get_mq ( struct GNUNET_SERVICE_Client c)

Obtain the message queue of c.

Convenience function.

Parameters
cthe client to continue receiving from
Returns
the message queue of c

Definition at line 2602 of file service.c.

2603{
2604 return c->mq;
2605}
struct GNUNET_MQ_Handle * mq
Message queue for the client.
Definition: service.c:276

References GNUNET_SERVICE_Client::mq.

Referenced by broadcast_status(), handle_list(), handle_lookup_by_suffix_message(), handle_lookup_message(), handle_monitor(), handle_query_message(), handle_revoke_message(), handle_start(), handle_start_message(), handle_test(), return_agpl(), send_client_reply(), send_end_msg(), send_intermediate_response(), send_lookup_response(), send_reply(), send_result_code(), signal_result(), transmit_item(), and transmit_status().

Here is the caller graph for this function:

◆ GNUNET_SERVICE_client_disable_continue_warning()

void GNUNET_SERVICE_client_disable_continue_warning ( struct GNUNET_SERVICE_Client c)

Disable the warning the server issues if a message is not acknowledged in a timely fashion.

Use this call if a client is intentionally delayed for a while. Only applies to the current message.

Parameters
cclient for which to disable the warning

Definition at line 2432 of file service.c.

2433{
2434 GNUNET_break (NULL != c->warn_task);
2435 if (NULL != c->warn_task)
2436 {
2438 c->warn_task = NULL;
2439 }
2440}

References GNUNET_break, GNUNET_SCHEDULER_cancel(), and GNUNET_SERVICE_Client::warn_task.

Referenced by handle_start_message().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SERVICE_client_drop()

void GNUNET_SERVICE_client_drop ( struct GNUNET_SERVICE_Client c)

Ask the server to disconnect from the given client.

This is the same as returning GNUNET_SYSERR within the check procedure when handling a message, except that it allows dropping of a client even when not handling a message from that client. The disconnect_cb will be called on c even if the application closes the connection using this function.

This function should be called (outside of util's internal logic) if (and usually only if) the client has violated the protocol. Otherwise, we should leave it to the client to disconnect from the service.

Parameters
cclient to disconnect now

This is the same as returning GNUNET_SYSERR within the check procedure when handling a message, wexcept that it allows dropping of a client even when not handling a message from that client. The disconnect_cb will be called on c even if the application closes the connection using this function.

Parameters
cclient to disconnect now

Definition at line 2489 of file service.c.

2490{
2491 struct GNUNET_SERVICE_Handle *sh = c->sh;
2492
2494 "Client dropped: %p (MQ: %p)\n",
2495 c,
2496 c->mq);
2497#if EXECINFO
2498 {
2499 void *backtrace_array[MAX_TRACE_DEPTH];
2500 int num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH);
2501 char **backtrace_strings =
2502 backtrace_symbols (backtrace_array, t->num_backtrace_strings);
2503 for (unsigned int i = 0; i < num_backtrace_strings; i++)
2505 "client drop trace %u: %s\n",
2506 i,
2507 backtrace_strings[i]);
2508 }
2509#endif
2510 if (NULL != c->drop_task)
2511 {
2512 /* asked to drop twice! */
2513 GNUNET_assert (0);
2514 return;
2515 }
2516 GNUNET_CONTAINER_DLL_remove (sh->clients_head,
2517 sh->clients_tail,
2518 c);
2519 if (NULL != sh->disconnect_cb)
2520 sh->disconnect_cb (sh->cb_cls,
2521 c,
2522 c->user_context);
2523 if (NULL != c->warn_task)
2524 {
2526 c->warn_task = NULL;
2527 }
2528 if (NULL != c->recv_task)
2529 {
2531 c->recv_task = NULL;
2532 }
2533 if (NULL != c->send_task)
2534 {
2536 c->send_task = NULL;
2537 }
2539}
static struct GNUNET_SCHEDULER_Task * t
Main task.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static void finish_client_drop(void *cls)
Asynchronously finish dropping the client.
Definition: service.c:2449
struct GNUNET_SCHEDULER_Task * send_task
Task that transmit data to the client.
Definition: service.c:304
struct GNUNET_SERVICE_Handle * sh
Service that this client belongs to.
Definition: service.c:266
void * user_context
User context value, value returned from the connect callback.
Definition: service.c:315

References GNUNET_IDENTITY_Handle::cb_cls, GNUNET_SERVICE_Client::drop_task, finish_client_drop(), GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), LOG, GNUNET_SERVICE_Client::mq, GNUNET_SERVICE_Client::recv_task, GNUNET_SERVICE_Client::send_task, sh, GNUNET_SERVICE_Client::sh, t, GNUNET_SERVICE_Client::user_context, and GNUNET_SERVICE_Client::warn_task.

Referenced by check_client_seed(), demultiplex_with_cmc(), destroy_service_session(), force_timeout(), GNUNET_SERVICE_shutdown(), GNUNET_SERVICE_stop(), GSC_CLIENTS_reject_request(), handle_add_queue_message(), handle_announce(), handle_attribute_delete_message(), handle_attribute_store_message(), handle_autoconfig_request(), handle_bob_client_message(), handle_channel_create(), handle_client_accept(), handle_client_audio_message(), handle_client_call_message(), handle_client_cancel(), handle_client_conclude(), handle_client_copy_lazy_connect(), handle_client_copy_lazy_prepare(), handle_client_create_set(), handle_client_decrypt(), handle_client_evaluate(), handle_client_hangup_message(), handle_client_insert(), handle_client_iter_ack(), handle_client_iterate(), handle_client_keygen(), handle_client_listen(), handle_client_mutation(), handle_client_pickup_message(), handle_client_recv_ok(), handle_client_redirect_to_ip(), handle_client_redirect_to_service(), handle_client_register_message(), handle_client_response(), handle_client_resume_message(), handle_client_set_add(), handle_client_start(), handle_client_suspend_message(), handle_consume_ticket_message(), handle_create_message(), handle_credential_delete_message(), handle_credential_iteration_next(), handle_credential_iteration_start(), handle_credential_iteration_stop(), handle_credential_store_message(), handle_del_address(), handle_del_queue_message(), handle_destroy(), handle_dht_local_get_result_seen(), handle_dht_local_hello_offer(), handle_edit_record_set(), handle_edit_record_set_cancel(), handle_fragment_box(), handle_get_zero_anonymity(), handle_issue_ticket_message(), handle_iterate_next(), handle_iterate_stop(), handle_iteration_next(), handle_iteration_start(), handle_iteration_stop(), handle_local_data(), handle_lookup_block(), handle_monitor_next(), handle_monitor_start(), handle_port_close(), handle_port_open(), handle_query_message(), handle_queue_create_fail(), handle_queue_create_ok(), handle_raw_message(), handle_record_lookup(), handle_record_store(), handle_register(), handle_request_connection_reversal(), handle_revoke_message(), handle_revoke_ticket_message(), handle_search(), handle_send_message_ack(), handle_store(), handle_stun(), handle_suggest(), handle_suggest_cancel(), handle_test(), handle_ticket_iteration_next(), handle_ticket_iteration_start(), handle_ticket_iteration_stop(), handle_watch(), handle_zone_to_name(), monitor_iteration_next(), process_get(), resume_client_receive(), send_lookup_response(), send_lookup_response_with_filter(), service_client_recv(), service_mq_error_handler(), and shutdown_task().

Here is the call graph for this function:

◆ GNUNET_SERVICE_shutdown()

void GNUNET_SERVICE_shutdown ( struct GNUNET_SERVICE_Handle sh)

Explicitly stops the service.

Parameters
shserver to shutdown

Definition at line 2548 of file service.c.

2549{
2550 struct GNUNET_SERVICE_Client *client;
2551
2552 if (0 == (sh->suspend_state & SUSPEND_STATE_SHUTDOWN))
2554 while (NULL != (client = sh->clients_head))
2556}
@ SUSPEND_STATE_SHUTDOWN
Suspension because service was permanently shutdown.
Definition: service.c:110

References do_suspend(), GNUNET_SERVICE_client_drop(), sh, and SUSPEND_STATE_SHUTDOWN.

Referenced by destroy_service(), do_shutdown(), finish_client_drop(), GNUNET_SERVICE_client_mark_monitor(), and service_shutdown().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SERVICE_client_mark_monitor()

void GNUNET_SERVICE_client_mark_monitor ( struct GNUNET_SERVICE_Client c)

Set the 'monitor' flag on this client.

Clients which have been marked as 'monitors' won't prevent the server from shutting down once #GNUNET_SERVICE_stop_listening() has been invoked. The idea is that for "normal" clients we likely want to allow them to process their requests; however, monitor-clients are likely to 'never' disconnect during shutdown and thus will not be considered when determining if the server should continue to exist after shutdown has been triggered.

Parameters
cclient to mark as a monitor

Definition at line 2572 of file service.c.

2573{
2575 if (((0 != (SUSPEND_STATE_SHUTDOWN & c->sh->suspend_state)) &&
2578}
void GNUNET_SERVICE_shutdown(struct GNUNET_SERVICE_Handle *sh)
Explicitly stops the service.
Definition: service.c:2548
static int have_non_monitor_clients(struct GNUNET_SERVICE_Handle *sh)
Check if any of the clients we have left are unrelated to monitoring.
Definition: service.c:362
int is_monitor
Is this client a 'monitor' client that should not be counted when deciding on destroying the server d...
Definition: service.c:340
enum SuspendReason suspend_state
Are we suspended, and if so, why?
Definition: service.c:221

References GNUNET_NO, GNUNET_SERVICE_shutdown(), GNUNET_YES, have_non_monitor_clients(), GNUNET_SERVICE_Client::is_monitor, GNUNET_SERVICE_Client::sh, GNUNET_SERVICE_Handle::suspend_state, and SUSPEND_STATE_SHUTDOWN.

Referenced by client_connect_cb(), handle_monitor_start(), handle_start_message(), and handle_watch().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SERVICE_client_persist()

void GNUNET_SERVICE_client_persist ( struct GNUNET_SERVICE_Client c)

Set the persist option on this client.

Indicates that the underlying socket or fd should never really be closed. Used for indicating process death.

Parameters
cclient to persist the socket (never to be closed)

Definition at line 2589 of file service.c.

2590{
2591 c->persist = GNUNET_YES;
2592}
int persist
Persist the file handle for this client no matter what happens, force the OS to close once the proces...
Definition: service.c:333

References GNUNET_YES, and GNUNET_SERVICE_Client::persist.

Referenced by handle_stop().

Here is the caller graph for this function: