GNUnet 0.22.2
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
21
22#if ! defined (__GNUNET_UTIL_LIB_H_INSIDE__)
23#error "Only <gnunet_util_lib.h> can be included directly."
24#endif
25
47#ifndef GNUNET_SERVICE_LIB_H
48#define GNUNET_SERVICE_LIB_H
49
50#ifdef __cplusplus
51extern "C"
52{
53#if 0 /* keep Emacsens' auto-indent happy */
54}
55#endif
56#endif
57
58#include "gnunet_util_lib.h"
60
61
66{
72
79
85
90
96};
97
98
99/* **************** NEW SERVICE API ********************** */
100
105
106
111
112
120typedef void
121(*GNUNET_SERVICE_InitCallback)(void *cls,
122 const struct GNUNET_CONFIGURATION_Handle *cfg,
123 struct GNUNET_SERVICE_Handle *sh);
124
125
134typedef void *
135(*GNUNET_SERVICE_ConnectHandler)(void *cls,
136 struct GNUNET_SERVICE_Client *c,
137 struct GNUNET_MQ_Handle *mq);
138
139
147typedef void
149 struct GNUNET_SERVICE_Client *c,
150 void *internal_cls);
151
152
192 const char *service_name,
193 const struct GNUNET_CONFIGURATION_Handle *cfg,
196 void *cls,
197 const struct GNUNET_MQ_MessageHandler *handlers);
198
199
205void
207
250int
252 int argc,
253 char *const *argv,
254 const char *service_name,
259 void *cls,
260 const struct GNUNET_MQ_MessageHandler *handlers);
261
262
303int
305 const struct GNUNET_OS_ProjectData *pd,
306 const char *service_name,
311 void *cls,
312 const struct GNUNET_MQ_MessageHandler *handlers);
313
314
372#ifndef HAVE_GNUNET_MONOLITH
373#define GNUNET_SERVICE_MAIN(pd, service_name, service_options, init_cb, \
374 connect_cb, \
375 disconnect_cb, cls, ...) \
376 int \
377 main (int argc, \
378 char *const *argv) \
379 { \
380 struct GNUNET_MQ_MessageHandler mh[] = { \
381 __VA_ARGS__ \
382 }; \
383 return GNUNET_SERVICE_run_ (pd, \
384 argc, \
385 argv, \
386 service_name, \
387 service_options, \
388 init_cb, \
389 connect_cb, \
390 disconnect_cb, \
391 cls, \
392 mh); \
393 }
394#else
395#define GNUNET_SERVICE_MAIN(pd, service_name, service_options, init_cb, \
396 connect_cb, \
397 disconnect_cb, cls, ...) \
398 static int __attribute__ ((constructor)) \
399 init (void) \
400 { \
401 struct GNUNET_MQ_MessageHandler mh[] = { \
402 __VA_ARGS__ \
403 }; \
404 return GNUNET_SERVICE_register_ (pd, \
405 service_name, \
406 service_options, \
407 init_cb, \
408 connect_cb, \
409 disconnect_cb, \
410 cls, \
411 mh); \
412 }
413#endif
414
419void
421 int argc,
422 char *const *argv,
424 enum GNUNET_GenericReturnValue with_scheduler);
425
432void
434
435
441void
443
444
451void
453
454
461struct GNUNET_MQ_Handle *
463
464
473void
475 struct GNUNET_SERVICE_Client *c);
476
477
493void
495
496
502void
504
505
518void
520
521
529void
531
532
533#if 0 /* keep Emacsens' auto-indent happy */
534{
535#endif
536#ifdef __cplusplus
537}
538#endif
539
540/* ifndef GNUNET_SERVICE_LIB_H */
541#endif
542 /* end of group service */
544 /* end of group addition to networking*/
546 /* end of group addition to libgnunetutil */
548
549/* end of gnunet_service_lib.h */
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
static struct GNUNET_IDENTITY_Handle * sh
Handle to IDENTITY service.
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 char * service_name
Option -s: service name (hash to get service descriptor)
Definition: gnunet-vpn.c:50
Configuration API.
GNUNET_GenericReturnValue
Named constants for return values.
void GNUNET_SERVICE_suspend(struct GNUNET_SERVICE_Handle *sh)
Suspend accepting connections from the listen socket temporarily.
Definition: service.c:2336
void GNUNET_SERVICE_stop(struct GNUNET_SERVICE_Handle *srv)
Stops a service that was started with GNUNET_SERVICE_start().
Definition: service.c:1958
void GNUNET_SERVICE_shutdown(struct GNUNET_SERVICE_Handle *sh)
Explicitly stops the service.
Definition: service.c:2467
int GNUNET_SERVICE_run_(const struct GNUNET_OS_ProjectData *pd, 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:1977
GNUNET_SERVICE_Options
Options for the service (bitmask).
void GNUNET_SERVICE_client_mark_monitor(struct GNUNET_SERVICE_Client *c)
Set the 'monitor' flag on this client.
Definition: service.c:2483
int GNUNET_SERVICE_register_(const struct GNUNET_OS_ProjectData *pd, 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.
Definition: service.c:2209
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.
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Definition: service.c:2418
struct GNUNET_SERVICE_Handle * GNUNET_SERVICE_start(const struct GNUNET_OS_ProjectData *pd, 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:1883
void GNUNET_SERVICE_client_persist(struct GNUNET_SERVICE_Client *c)
Set the persist option on this client.
Definition: service.c:2493
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:2406
void GNUNET_SERVICE_main(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, struct GNUNET_CONFIGURATION_Handle *cfg, enum GNUNET_GenericReturnValue with_scheduler)
Run the mainloop in a monolithic libgnunet.
Definition: service.c:2303
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_ConnectHandler)(void *cls, struct GNUNET_SERVICE_Client *c, struct GNUNET_MQ_Handle *mq)
Callback to be called when a client connects to the service.
struct GNUNET_MQ_Handle * GNUNET_SERVICE_client_get_mq(struct GNUNET_SERVICE_Client *c)
Obtain the message queue of c.
Definition: service.c:2500
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2389
void GNUNET_SERVICE_resume(struct GNUNET_SERVICE_Handle *sh)
Resume accepting connections from the listen socket.
Definition: service.c:2344
@ 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...
Handle to a message queue.
Definition: mq.c:87
Message handler for a specific message type.
Project-specific data used to help the OS subsystem find installation paths.
Handle to a client that is connected to a service.
Definition: service.c:249
Handle to a service.
Definition: service.c:116
GNUNET_SERVICE_InitCallback service_init_cb
Main service-specific task to run.
Definition: service.c:135
const struct GNUNET_OS_ProjectData * pd
Project data of this service.
Definition: service.c:125