GNUnet  0.10.x
Macros | Typedefs | Enumerations | Functions
Service library

Start service processes. More...

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 }
 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...
 
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); \
}
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 void disconnect_cb(void *cls, const struct GNUNET_CADET_Channel *channel)
Function called by cadet when a client disconnects.
static struct GNUNET_CADET_Handle * mh
Cadet handle.
Definition: gnunet-cadet.c:92
int main(int argc, char *const *argv)
The main function to obtain arm from gnunetd.
Definition: gnunet-arm.c:739
static char * service_name
Option -s: service name (hash to get service descriptor)
Definition: gnunet-vpn.c:51
Message handler for a specific message type.
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:2248

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
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
...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 295 of file gnunet_service_lib.h.

Referenced by run().

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 99 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 113 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 126 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.

Definition at line 53 of file gnunet_service_lib.h.

54 {
60 
67 
73 };
Do not trigger server shutdown on signal at all; instead, allow for the user to terminate the server ...
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 2157 of file service.c.

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

Referenced by GST_barriers_init(), and transport_communicator_start().

2163 {
2164  struct GNUNET_SERVICE_Handle *sh;
2165 
2166  sh = GNUNET_new (struct GNUNET_SERVICE_Handle);
2167  sh->service_name = service_name;
2168  sh->cfg = cfg;
2169  sh->connect_cb = connect_cb;
2171  sh->cb_cls = cls;
2172  sh->handlers = GNUNET_MQ_copy_handlers2 (handlers,
2173  &return_agpl,
2174  NULL);
2175  if (GNUNET_OK != setup_service (sh))
2176  {
2178  GNUNET_free (sh);
2179  return NULL;
2180  }
2181  do_resume (sh,
2183  return sh;
2184 }
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 return_agpl(void *cls, const struct GNUNET_MessageHeader *msg)
Function to return link to AGPL source upon request.
Definition: service.c:2096
struct GNUNET_MQ_MessageHandler * handlers
Message handlers to use for all clients.
Definition: service.c:171
Handle to a service.
Definition: service.c:116
static int setup_service(struct GNUNET_SERVICE_Handle *sh)
Setup service handle.
Definition: service.c:1685
static void disconnect_cb(void *cls, const struct GNUNET_CADET_Channel *channel)
Function called by cadet when a client disconnects.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
We are running normally.
Definition: service.c:89
static struct SolverHandle * sh
static char * service_name
Option -s: service name (hash to get service descriptor)
Definition: gnunet-vpn.c:51
GNUNET_SERVICE_ConnectHandler connect_cb
Function to call when clients connect.
Definition: service.c:136
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:1223
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
static void do_resume(struct GNUNET_SERVICE_Handle *sh, enum SuspendReason sr)
Resume accepting connections from the listen socket.
Definition: service.c:903
const char * service_name
Name of our service.
Definition: service.c:126
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: service.c:121
GNUNET_SERVICE_DisconnectHandler disconnect_cb
Function to call when clients disconnect / are disconnected.
Definition: service.c:141
void * cb_cls
Closure for service_init_cb, connect_cb, disconnect_cb.
Definition: service.c:146
#define GNUNET_free(ptr)
Wrapper around free.
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 2193 of file service.c.

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

Referenced by GST_barriers_destroy(), and shutdown_service().

2194 {
2195  struct GNUNET_SERVICE_Client *client;
2196 
2197  GNUNET_SERVICE_suspend (srv);
2198  while (NULL != (client = srv->clients_head))
2199  GNUNET_SERVICE_client_drop (client);
2200  teardown_service (srv);
2202  GNUNET_free (srv);
2203 }
struct GNUNET_MQ_MessageHandler * handlers
Message handlers to use for all clients.
Definition: service.c:171
struct GNUNET_SERVICE_Client * clients_head
Our clients, kept in a DLL.
Definition: service.c:161
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
Handle to a client that is connected to a service.
Definition: service.c:249
static void teardown_service(struct GNUNET_SERVICE_Handle *sh)
Tear down the service, closing the listen sockets and freeing the ACLs.
Definition: service.c:2067
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Definition: service.c:2618
void GNUNET_SERVICE_suspend(struct GNUNET_SERVICE_Handle *sh)
Suspend accepting connections from the listen socket temporarily.
Definition: service.c:2468
#define GNUNET_free(ptr)
Wrapper around free.
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 2248 of file service.c.

References _, GNUNET_SERVICE_Handle::cb_cls, cfg, GNUNET_SERVICE_Handle::cfg, cfg_filename, CLOSE, config_file, GNUNET_SERVICE_Handle::connect_cb, connect_cb(), detach_terminal(), DIR_SEPARATOR_STR, GNUNET_SERVICE_Handle::disconnect_cb, disconnect_cb(), GAUGER, getenv(), gettext_noop, 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_free_non_null, 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_NO, GNUNET_OK, GNUNET_OS_project_data_get(), GNUNET_RESOLVER_connect(), GNUNET_SCHEDULER_run(), GNUNET_SPEEDUP_stop_(), GNUNET_strdup, GNUNET_SYSERR, GNUNET_TIME_set_offset(), GNUNET_YES, GNUNET_SERVICE_Handle::handlers, LOG, LOG_STRERROR, options, GNUNET_SERVICE_Handle::options, pid_file_delete(), GNUNET_SERVICE_Handle::ready_confirm_fd, ret, GNUNET_SERVICE_Handle::ret, GNUNET_SERVICE_Handle::service_init_cb, service_main(), service_name, GNUNET_SERVICE_Handle::service_name, set_user_id(), setup_service(), teardown_service(), and WRITE.

Referenced by main().

2257 {
2258  struct GNUNET_SERVICE_Handle sh;
2259  char *cfg_filename;
2260  char *opt_cfg_filename;
2261  char *loglev;
2262  const char *xdg;
2263  char *logfile;
2264  int do_daemonize;
2265  unsigned long long skew_offset;
2266  unsigned long long skew_variance;
2267  long long clock_offset;
2269  int ret;
2270  int err;
2271 
2272  struct GNUNET_GETOPT_CommandLineOption service_options[] = {
2273  GNUNET_GETOPT_option_cfgfile (&opt_cfg_filename),
2275  "daemonize",
2276  gettext_noop ("do daemonize (detach from terminal)"),
2277  &do_daemonize),
2280  GNUNET_GETOPT_option_logfile (&logfile),
2281  GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION),
2283  };
2284 
2285  err = 1;
2286  memset (&sh,
2287  0,
2288  sizeof (sh));
2289  xdg = getenv ("XDG_CONFIG_HOME");
2290  if (NULL != xdg)
2291  GNUNET_asprintf (&cfg_filename,
2292  "%s%s%s",
2293  xdg,
2296  else
2297  cfg_filename = GNUNET_strdup (GNUNET_OS_project_data_get ()->user_config_file);
2298  sh.ready_confirm_fd = -1;
2299  sh.options = options;
2300  sh.cfg = cfg = GNUNET_CONFIGURATION_create ();
2301  sh.service_init_cb = service_init_cb;
2302  sh.connect_cb = connect_cb;
2303  sh.disconnect_cb = disconnect_cb;
2304  sh.cb_cls = cls;
2305  sh.handlers = GNUNET_MQ_copy_handlers (handlers);
2306  sh.service_name = service_name;
2307 
2308  /* setup subsystems */
2309  loglev = NULL;
2310  logfile = NULL;
2311  opt_cfg_filename = NULL;
2312  do_daemonize = 0;
2314  service_options,
2315  argc,
2316  argv);
2317  if (GNUNET_SYSERR == ret)
2318  goto shutdown;
2319  if (GNUNET_NO == ret)
2320  {
2321  err = 0;
2322  goto shutdown;
2323  }
2325  loglev,
2326  logfile))
2327  {
2328  GNUNET_break (0);
2329  goto shutdown;
2330  }
2331  if (NULL != opt_cfg_filename)
2332  {
2333  if ( (GNUNET_YES !=
2334  GNUNET_DISK_file_test (opt_cfg_filename)) ||
2335  (GNUNET_SYSERR ==
2337  opt_cfg_filename)) )
2338  {
2340  _("Malformed configuration file `%s', exit ...\n"),
2341  opt_cfg_filename);
2342  goto shutdown;
2343  }
2344  }
2345  else
2346  {
2347  if (GNUNET_YES ==
2348  GNUNET_DISK_file_test (cfg_filename))
2349  {
2350  if (GNUNET_SYSERR ==
2352  cfg_filename))
2353  {
2355  _("Malformed configuration file `%s', exit ...\n"),
2356  cfg_filename);
2357  goto shutdown;
2358  }
2359  }
2360  else
2361  {
2362  if (GNUNET_SYSERR ==
2364  NULL))
2365  {
2367  _("Malformed configuration, exit ...\n"));
2368  goto shutdown;
2369  }
2370  }
2371  }
2372  if (GNUNET_OK != setup_service (&sh))
2373  goto shutdown;
2374  if ( (1 == do_daemonize) &&
2375  (GNUNET_OK != detach_terminal (&sh)) )
2376  {
2377  GNUNET_break (0);
2378  goto shutdown;
2379  }
2380  if (GNUNET_OK != set_user_id (&sh))
2381  goto shutdown;
2383  "Service `%s' runs with configuration from `%s'\n",
2384  service_name,
2385  (NULL != opt_cfg_filename) ? opt_cfg_filename : cfg_filename);
2386  if ((GNUNET_OK ==
2388  "TESTING",
2389  "SKEW_OFFSET",
2390  &skew_offset)) &&
2391  (GNUNET_OK ==
2393  "TESTING",
2394  "SKEW_VARIANCE",
2395  &skew_variance)))
2396  {
2397  clock_offset = skew_offset - skew_variance;
2398  GNUNET_TIME_set_offset (clock_offset);
2400  "Skewing clock by %dll ms\n",
2401  clock_offset);
2402  }
2404 
2405  /* actually run service */
2406  err = 0;
2408  &sh);
2409  /* shutdown */
2410  if (1 == do_daemonize)
2411  pid_file_delete (&sh);
2412 
2413 shutdown:
2414  if (-1 != sh.ready_confirm_fd)
2415  {
2416  if (1 != WRITE (sh.ready_confirm_fd,
2417  err ? "I" : "S",
2418  1))
2420  "write");
2421  GNUNET_break (0 == CLOSE (sh.ready_confirm_fd));
2422  }
2423 #if HAVE_MALLINFO
2424  {
2425  char *counter;
2426 
2427  if ( (GNUNET_YES ==
2429  service_name,
2430  "GAUGER_HEAP")) &&
2431  (GNUNET_OK ==
2433  service_name,
2434  "GAUGER_HEAP",
2435  &counter)) )
2436  {
2437  struct mallinfo mi;
2438 
2439  mi = mallinfo ();
2441  counter,
2442  mi.usmblks,
2443  "blocks");
2444  GNUNET_free (counter);
2445  }
2446  }
2447 #endif
2448  teardown_service (&sh);
2449  GNUNET_free_non_null (sh.handlers);
2452  GNUNET_free_non_null (logfile);
2453  GNUNET_free_non_null (loglev);
2454  GNUNET_free (cfg_filename);
2455  GNUNET_free_non_null (opt_cfg_filename);
2456 
2457  return err ? GNUNET_SYSERR : sh.ret;
2458 }
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.
int 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:669
static char * cfg_filename
Name of the configuration file.
int 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.
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
Handle to a service.
Definition: service.c:116
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_help(const char *about)
Defining the option to print the command line help text (-h option).
static int setup_service(struct GNUNET_SERVICE_Handle *sh)
Setup service handle.
Definition: service.c:1685
static void disconnect_cb(void *cls, const struct GNUNET_CADET_Channel *channel)
Function called by cadet when a client disconnects.
struct GNUNET_MQ_MessageHandler * GNUNET_MQ_copy_handlers(const struct GNUNET_MQ_MessageHandler *handlers)
Copy an array of handlers.
Definition: mq.c:1193
static char * config_file
Set to the name of the config file used.
Definition: gnunet-arm.c:79
void GNUNET_SCHEDULER_run(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Initialize and run scheduler.
Definition: scheduler.c:716
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
Definition of a command line option.
static void service_main(void *cls)
First task run by any service.
Definition: service.c:933
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
void GNUNET_TIME_set_offset(long long offset)
Set the timestamp offset for this instance.
Definition: time.c:53
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_logfile(char **logfn)
Allow user to specify log file name (-l option)
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static void pid_file_delete(struct GNUNET_SERVICE_Handle *sh)
Delete the PID file that was created by our parent.
Definition: service.c:1955
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
static int set_user_id(struct GNUNET_SERVICE_Handle *sh)
Set user ID.
Definition: service.c:1879
int GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load configuration.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_version(const char *version)
Define the option to print the version of the application (-v option)
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
int 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.
static struct SolverHandle * sh
static char * service_name
Option -s: service name (hash to get service descriptor)
Definition: gnunet-vpn.c:51
static void teardown_service(struct GNUNET_SERVICE_Handle *sh)
Tear down the service, closing the listen sockets and freeing the ACLs.
Definition: service.c:2067
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
#define CLOSE(f)
Definition: plibc.h:653
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_loglevel(char **level)
Define the '-L' log level option.
int 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.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
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:893
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define WRITE(f, b, n)
Definition: plibc.h:667
char * getenv()
#define GAUGER(category, counter, value, unit)
Definition: gauger.h:20
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_cfgfile(char **fn)
Allow user to specify configuration file name (-c option)
#define LOG(kind,...)
Definition: service.c:40
configuration data
Definition: configuration.c:85
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.
#define GNUNET_log(kind,...)
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_get(void)
#define GNUNET_YES
Definition: gnunet_common.h:80
#define DIR_SEPARATOR_STR
Definition: plibc.h:632
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
#define LOG_STRERROR(kind, syscall)
Definition: service.c:42
static int detach_terminal(struct GNUNET_SERVICE_Handle *sh)
Detach from terminal.
Definition: service.c:1976
void GNUNET_RESOLVER_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create the connection to the resolver service.
Definition: resolver_api.c:254
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
void GNUNET_SPEEDUP_stop_()
Stop tasks that modify clock behavior.
Definition: speedup.c:105
Here is the call graph for this function:
Here is the caller 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 2468 of file service.c.

References do_suspend(), and SUSPEND_STATE_APP.

Referenced by GNUNET_SERVICE_stop(), and run().

2469 {
2470  do_suspend (sh,
2472 }
static void do_suspend(struct GNUNET_SERVICE_Handle *sh, enum SuspendReason sr)
Suspend accepting connections from the listen socket temporarily.
Definition: service.c:383
Application requested it.
Definition: service.c:94
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 2481 of file service.c.

References do_resume(), and SUSPEND_STATE_APP.

Referenced by begin_service(), core_init(), and run().

2482 {
2483  do_resume (sh,
2485 }
static void do_resume(struct GNUNET_SERVICE_Handle *sh, enum SuspendReason sr)
Resume accepting connections from the listen socket.
Definition: service.c:903
Application requested it.
Definition: service.c:94
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 2533 of file service.c.

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(), do_blacklist_check(), finish_cmc_handling(), get_ip_from_hostname(), handle_add_address(), handle_add_host(), handle_add_queue_message(), handle_address_add(), handle_address_destroyed(), handle_address_update(), handle_alice_client_message(), handle_alice_client_message_multipart(), handle_announce(), handle_ats_start(), handle_attribute_delete_message(), handle_attribute_store_message(), handle_barrier_cancel(), handle_barrier_init(), handle_barrier_status(), handle_barrier_wait(), 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_blacklist_reply(), 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_hello(), 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_metric(), 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_del_address(), handle_del_queue_message(), handle_delete_message(), handle_dht_local_get(), handle_dht_local_get_stop(), handle_dht_local_monitor(), handle_dht_local_monitor_stop(), handle_dht_local_put(), handle_disconnect(), handle_drop(), handle_feedback(), handle_get(), handle_get_all(), handle_get_default_message(), handle_get_key(), handle_get_peers(), handle_get_replication(), handle_get_zero_anonymity(), handle_hello(), handle_incoming_msg(), handle_info_tunnels(), handle_init(), handle_issue_ticket_message(), handle_iteration_next(), handle_iteration_start(), handle_iteration_stop(), handle_link_controllers(), handle_list(), handle_local_ack(), handle_local_data(), handle_log_msg(), handle_lookup(), handle_lookup_block(), handle_lookup_by_suffix_message(), handle_lookup_message(), handle_manage_peer_service(), handle_monitor(), handle_monitor_next(), handle_monitor_start(), handle_notify(), handle_overlay_connect(), handle_peer_create(), handle_peer_destroy(), handle_peer_get_config(), handle_peer_reconfigure(), handle_peer_start(), handle_peer_stop(), handle_port_close(), handle_port_open(), handle_preference_change(), 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_remote_overlay_connect(), handle_remove(), handle_rename_message(), handle_request_address(), handle_request_address_cancel(), handle_request_address_list(), handle_request_connection_reversal(), handle_request_hello_validation(), handle_reservation_request(), handle_reserve(), handle_revoke_message(), handle_revoke_ticket_message(), handle_search(), handle_send_message_ack(), handle_session_add(), handle_session_del(), handle_session_update(), handle_set(), handle_set_default_message(), handle_show_path(), handle_shutdown_peers(), handle_slave_get_config(), 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_verify(), handle_watch(), handle_watch_cancel(), handle_zone_to_name(), hash_for_index_val(), record_iterator(), return_agpl(), send_push(), service_mq_error_handler(), signal_index_ok(), slave_status_cb(), start_p2p_processing(), store_record_continuation(), and zone_iteration_done_client_continue().

2534 {
2535  GNUNET_assert (NULL == c->drop_task);
2537  GNUNET_assert (NULL == c->recv_task);
2539  if (NULL != c->warn_task)
2540  {
2542  c->warn_task = NULL;
2543  }
2544  c->recv_task
2546  c);
2547 }
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:2495
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:81
struct GNUNET_SCHEDULER_Task * warn_task
Task that warns about missing calls to GNUNET_SERVICE_client_continue().
Definition: service.c:286
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:1273
int needs_continue
Are we waiting for the application to call GNUNET_SERVICE_client_continue()?
Definition: service.c:344
#define GNUNET_YES
Definition: gnunet_common.h:80
struct GNUNET_SCHEDULER_Task * recv_task
Task that receives data from the client to pass it to the handlers.
Definition: service.c:298
struct GNUNET_SCHEDULER_Task * drop_task
Task run to finish dropping the client after the stack has properly unwound.
Definition: service.c:292
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
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 2734 of file service.c.

References GNUNET_SERVICE_Client::mq.

Referenced by add_to_tc(), broadcast_status(), GAS_handle_address_destroyed(), GAS_handle_reservation_request(), GAS_performance_add_client(), GAS_scheduling_transmit_address_suggestion(), GST_forwarded_operation_reply_relay(), GST_send_operation_fail_msg(), GST_send_operation_success_msg(), handle_add_host(), handle_barrier_status(), handle_get(), handle_get_all(), handle_get_default_message(), handle_list(), handle_lookup_by_suffix_message(), handle_lookup_message(), handle_monitor(), handle_notify(), handle_peer_create(), handle_peer_get_config(), handle_peer_start(), handle_peer_stop(), handle_query_message(), handle_revoke_message(), handle_slave_get_config(), handle_start(), handle_start_message(), handle_test(), notify_client(), process_lookup_result(), record_iterator(), return_agpl(), send_client_reply(), send_client_status_msg(), send_controller_link_response(), send_end_msg(), send_lookup_response(), send_overlay_connect_success_msg(), send_reply(), send_result_code(), signal_result(), transmit_item(), transmit_req_addr(), transmit_status(), and watch_notifier_it().

2735 {
2736  return c->mq;
2737 }
struct GNUNET_MQ_Handle * mq
Message queue for the client.
Definition: service.c:275
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 2559 of file service.c.

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

Referenced by handle_client_address_to_string(), handle_client_monitor_peers(), handle_client_monitor_plugins(), and handle_start_message().

2560 {
2561  GNUNET_break (NULL != c->warn_task);
2562  if (NULL != c->warn_task)
2563  {
2565  c->warn_task = NULL;
2566  }
2567 }
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_SCHEDULER_Task * warn_task
Task that warns about missing calls to GNUNET_SERVICE_client_continue().
Definition: service.c:286
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
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 2618 of file service.c.

References GNUNET_SERVICE_Handle::cb_cls, GNUNET_SERVICE_Handle::clients_head, GNUNET_SERVICE_Handle::clients_tail, GNUNET_SERVICE_Handle::disconnect_cb, 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, 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(), get_ip_from_hostname(), GNUNET_SERVICE_shutdown(), GNUNET_SERVICE_stop(), GSC_CLIENTS_reject_request(), handle_add_host(), handle_add_queue_message(), handle_announce(), handle_ats_start(), handle_autoconfig_request(), handle_barrier_cancel(), handle_barrier_init(), handle_barrier_status(), handle_barrier_wait(), handle_bob_client_message(), handle_channel_create(), handle_client_accept(), handle_client_audio_message(), handle_client_blacklist_init(), handle_client_blacklist_reply(), 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_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_response(), handle_client_resume_message(), handle_client_start(), handle_client_suspend_message(), handle_del_address(), handle_del_queue_message(), handle_dht_local_get_result_seen(), handle_fragment_box(), handle_get_zero_anonymity(), handle_iterate(), handle_iteration_next(), handle_iteration_stop(), handle_link_controllers(), handle_local_data(), handle_lookup_block(), handle_monitor_next(), handle_monitor_start(), handle_overlay_connect(), handle_peer_create(), handle_port_close(), handle_port_open(), 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_search(), handle_send_message_ack(), handle_session_add(), handle_session_del(), handle_session_update(), handle_start(), handle_store(), handle_stun(), handle_suggest(), handle_suggest_cancel(), handle_test(), handle_ticket_iteration_next(), handle_ticket_iteration_stop(), handle_watch(), handle_watch_cancel(), handle_zone_to_name(), monitor_iteration_next(), process_get(), record_iterator(), resume_client_receive(), send_lookup_response(), send_push(), service_client_recv(), service_mq_error_handler(), shutdown_task(), and store_record_continuation().

2619 {
2620  struct GNUNET_SERVICE_Handle *sh = c->sh;
2621 
2623  "Client dropped: %p (MQ: %p)\n",
2624  c,
2625  c->mq);
2626 #if EXECINFO
2627  {
2628  void *backtrace_array[MAX_TRACE_DEPTH];
2629  int num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH);
2630  char **backtrace_strings =
2631  backtrace_symbols (backtrace_array,
2632  t->num_backtrace_strings);
2633  for (unsigned int i = 0; i < num_backtrace_strings; i++)
2635  "client drop trace %u: %s\n",
2636  i,
2637  backtrace_strings[i]);
2638  }
2639 #endif
2640  if (NULL != c->drop_task)
2641  {
2642  /* asked to drop twice! */
2643  GNUNET_assert (0);
2644  return;
2645  }
2647  sh->clients_tail,
2648  c);
2649  if (NULL != sh->disconnect_cb)
2650  sh->disconnect_cb (sh->cb_cls,
2651  c,
2652  c->user_context);
2653  if (NULL != c->warn_task)
2654  {
2656  c->warn_task = NULL;
2657  }
2658  if (NULL != c->recv_task)
2659  {
2661  c->recv_task = NULL;
2662  }
2663  if (NULL != c->send_task)
2664  {
2666  c->send_task = NULL;
2667  }
2669  c);
2670 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_SERVICE_Client * clients_head
Our clients, kept in a DLL.
Definition: service.c:161
struct GNUNET_SERVICE_Client * clients_tail
Our clients, kept in a DLL.
Definition: service.c:166
struct GNUNET_SCHEDULER_Task * send_task
Task that transmit data to the client.
Definition: service.c:303
Handle to a service.
Definition: service.c:116
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_SCHEDULER_Task * t
Main task.
struct GNUNET_MQ_Handle * mq
Message queue for the client.
Definition: service.c:275
void * user_context
User context value, value returned from the connect callback.
Definition: service.c:314
static void finish_client_drop(void *cls)
Asynchronously finish dropping the client.
Definition: service.c:2576
struct GNUNET_SCHEDULER_Task * warn_task
Task that warns about missing calls to GNUNET_SERVICE_client_continue().
Definition: service.c:286
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:1273
static struct SolverHandle * sh
#define LOG(kind,...)
Definition: service.c:40
#define GNUNET_log(kind,...)
struct GNUNET_SERVICE_Handle * sh
Service that this client belongs to.
Definition: service.c:265
GNUNET_SERVICE_DisconnectHandler disconnect_cb
Function to call when clients disconnect / are disconnected.
Definition: service.c:141
struct GNUNET_SCHEDULER_Task * recv_task
Task that receives data from the client to pass it to the handlers.
Definition: service.c:298
struct GNUNET_SCHEDULER_Task * drop_task
Task run to finish dropping the client after the stack has properly unwound.
Definition: service.c:292
void * cb_cls
Closure for service_init_cb, connect_cb, disconnect_cb.
Definition: service.c:146
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
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 2679 of file service.c.

References GNUNET_SERVICE_Handle::clients_head, do_suspend(), GNUNET_SERVICE_client_drop(), GNUNET_SERVICE_Handle::suspend_state, and SUSPEND_STATE_SHUTDOWN.

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

2680 {
2681  struct GNUNET_SERVICE_Client *client;
2682 
2683  if (0 == (sh->suspend_state & SUSPEND_STATE_SHUTDOWN))
2684  do_suspend (sh,
2686  while (NULL != (client = sh->clients_head))
2687  GNUNET_SERVICE_client_drop (client);
2688 }
enum SuspendReason suspend_state
Are we suspended, and if so, why?
Definition: service.c:219
struct GNUNET_SERVICE_Client * clients_head
Our clients, kept in a DLL.
Definition: service.c:161
static void do_suspend(struct GNUNET_SERVICE_Handle *sh, enum SuspendReason sr)
Suspend accepting connections from the listen socket temporarily.
Definition: service.c:383
Handle to a client that is connected to a service.
Definition: service.c:249
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Definition: service.c:2618
Suspension because service was permanently shutdown.
Definition: service.c:109
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 2704 of file service.c.

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_client_blacklist_init(), handle_client_monitor_peers(), handle_client_monitor_plugins(), handle_monitor_start(), handle_notify(), handle_start_message(), and handle_watch().

2705 {
2706  c->is_monitor = GNUNET_YES;
2707  if ( (0 != (SUSPEND_STATE_SHUTDOWN & c->sh->suspend_state) &&
2708  (GNUNET_NO == have_non_monitor_clients (c->sh)) ) )
2710 }
enum SuspendReason suspend_state
Are we suspended, and if so, why?
Definition: service.c:219
int is_monitor
Is this client a &#39;monitor&#39; client that should not be counted when deciding on destroying the server d...
Definition: service.c:339
#define GNUNET_NO
Definition: gnunet_common.h:81
struct GNUNET_SERVICE_Handle * sh
Service that this client belongs to.
Definition: service.c:265
Suspension because service was permanently shutdown.
Definition: service.c:109
#define GNUNET_YES
Definition: gnunet_common.h:80
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:361
void GNUNET_SERVICE_shutdown(struct GNUNET_SERVICE_Handle *sh)
Explicitly stops the service.
Definition: service.c:2679
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 2721 of file service.c.

References GNUNET_YES, and GNUNET_SERVICE_Client::persist.

Referenced by client_connect_cb(), and handle_stop().

2722 {
2723  c->persist = GNUNET_YES;
2724 }
int persist
Persist the file handle for this client no matter what happens, force the OS to close once the proces...
Definition: service.c:332
#define GNUNET_YES
Definition: gnunet_common.h:80
Here is the caller graph for this function: