GNUnet  0.11.x
gnunet_service_lib.h
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2009-2013, 2016, 2017 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
35 #ifndef GNUNET_SERVICE_LIB_H
36 #define GNUNET_SERVICE_LIB_H
37 
38 #ifdef __cplusplus
39 extern "C"
40 {
41 #if 0 /* keep Emacsens' auto-indent happy */
42 }
43 #endif
44 #endif
45 
47 #include "gnunet_mq_lib.h"
48 
49 
54 {
60 
67 
73 
78 
84 };
85 
86 
87 /* **************** NEW SERVICE API ********************** */
88 
93 
94 
99 
100 
108 typedef void
110  const struct GNUNET_CONFIGURATION_Handle *cfg,
111  struct GNUNET_SERVICE_Handle *sh);
112 
113 
122 typedef void *
123 (*GNUNET_SERVICE_ConnectHandler)(void *cls,
124  struct GNUNET_SERVICE_Client *c,
125  struct GNUNET_MQ_Handle *mq);
126 
127 
135 typedef void
137  struct GNUNET_SERVICE_Client *c,
138  void *internal_cls);
139 
140 
177 struct GNUNET_SERVICE_Handle *
179  const struct GNUNET_CONFIGURATION_Handle *cfg,
182  void *cls,
183  const struct GNUNET_MQ_MessageHandler *handlers);
184 
185 
191 void
193 
194 
236 int
237 GNUNET_SERVICE_run_ (int argc,
238  char *const *argv,
239  const char *service_name,
244  void *cls,
245  const struct GNUNET_MQ_MessageHandler *handlers);
246 
247 
305 #define GNUNET_SERVICE_MAIN(service_name, service_options, init_cb, connect_cb, \
306  disconnect_cb, cls, ...) \
307  int \
308  main (int argc, \
309  char *const *argv) \
310  { \
311  struct GNUNET_MQ_MessageHandler mh[] = { \
312  __VA_ARGS__ \
313  }; \
314  return GNUNET_SERVICE_run_ (argc, \
315  argv, \
316  service_name, \
317  service_options, \
318  init_cb, \
319  connect_cb, \
320  disconnect_cb, \
321  cls, \
322  mh); \
323  }
324 
325 
332 void
334 
335 
341 void
343 
344 
351 void
353 
354 
361 struct GNUNET_MQ_Handle *
363 
364 
373 void
376 
377 
393 void
395 
396 
402 void
404 
405 
418 void
420 
421 
429 void
431 
432 
433 #if 0 /* keep Emacsens' auto-indent happy */
434 {
435 #endif
436 #ifdef __cplusplus
437 }
438 #endif
439 
440 /* ifndef GNUNET_SERVICE_LIB_H */
441 #endif
442  /* end of group service */
444 
445 /* end of gnunet_service_lib.h */
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 const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
GNUNET_SERVICE_InitCallback service_init_cb
Main service-specific task to run.
Definition: service.c:131
void GNUNET_SERVICE_resume(struct GNUNET_SERVICE_Handle *sh)
Resume accepting connections from the listen socket.
Definition: service.c:2194
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
Handle to a service.
Definition: service.c:116
Bitmask over the shutdown options.
struct GNUNET_MQ_Handle * GNUNET_SERVICE_client_get_mq(struct GNUNET_SERVICE_Client *c)
Obtain the message queue of c.
Definition: service.c:2437
GNUNET_SERVICE_Options
Options for the service (bitmask).
static void disconnect_cb(void *cls, const struct GNUNET_CADET_Channel *channel)
Function called by cadet when a client disconnects.
Do not trigger server shutdown on signal at all; instead, allow for the user to terminate the server ...
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.
Definition: service.c:1878
Handle to a client that is connected to a service.
Definition: service.c:250
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
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.
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.
Trigger a SOFT server shutdown on signals, allowing active non-monitor clients to complete their tran...
static struct SolverHandle * sh
static char * service_name
Option -s: service name (hash to get service descriptor)
Definition: gnunet-vpn.c:51
void GNUNET_SERVICE_client_mark_monitor(struct GNUNET_SERVICE_Client *c)
Set the &#39;monitor&#39; flag on this client.
Definition: service.c:2407
void GNUNET_SERVICE_stop(struct GNUNET_SERVICE_Handle *srv)
Stops a service that was started with GNUNET_SERVICE_start().
Definition: service.c:1911
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Definition: service.c:2324
Message handler for a specific message type.
Instead of listening on lsocks passed by the parent, close them after opening our own listen socket(s...
Handle to a message queue.
Definition: mq.c:85
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:1966
configuration data
Definition: configuration.c:85
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
void GNUNET_SERVICE_suspend(struct GNUNET_SERVICE_Handle *sh)
Suspend accepting connections from the listen socket temporarily.
Definition: service.c:2182
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...
Definition: service.c:2267
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.
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2243
void GNUNET_SERVICE_client_persist(struct GNUNET_SERVICE_Client *c)
Set the persist option on this client.
Definition: service.c:2424
void GNUNET_SERVICE_shutdown(struct GNUNET_SERVICE_Handle *sh)
Explicitly stops the service.
Definition: service.c:2383