skeleton for service reimplementation
[oweals/gnunet.git] / src / util / service_new.c
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2016 GNUnet e.V.
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      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      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18      Boston, MA 02110-1301, USA.
19 */
20
21 /**
22  * @file util/service_new.c
23  * @brief functions related to starting services (redesign)
24  * @author Christian Grothoff
25  */
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
28 #include "gnunet_protocols.h"
29 #include "gnunet_constants.h"
30 #include "gnunet_resolver_service.h"
31
32
33 /**
34  * Creates the "main" function for a GNUnet service.  You
35  * should almost always use the #GNUNET_SERVICE_MAIN macro
36  * instead of calling this function directly (except
37  * for ARM, which should call this function directly).
38  *
39  * The function will launch the service with the name @a service_name
40  * using the @a service_options to configure its shutdown
41  * behavior. Once the service is ready, the @a init_cb will be called
42  * for service-specific initialization.  @a init_cb will be given the
43  * service handler which can be used to control the service's
44  * availability.  When clients connect or disconnect, the respective
45  * @a connect_cb or @a disconnect_cb functions will be called. For
46  * messages received from the clients, the respective @a handlers will
47  * be invoked; for the closure of the handlers we use the return value
48  * from the @a connect_cb invocation of the respective client.
49  *
50  * Each handler MUST call #GNUNET_SERVICE_client_continue() after each
51  * message to receive further messages from this client.  If
52  * #GNUNET_SERVICE_client_continue() is not called within a short
53  * time, a warning will be logged. If delays are expected, services
54  * should call #GNUNET_SERVICE_client_disable_continue_warning() to
55  * disable the warning.
56  *
57  * Clients sending invalid messages (based on @a handlers) will be
58  * dropped. Additionally, clients can be dropped at any time using
59  * #GNUNET_SERVICE_client_drop().
60  *
61  * @param argc number of command-line arguments in @a argv
62  * @param argv array of command-line arguments
63  * @param service_name name of the service to run
64  * @param options options controlling shutdown of the service
65  * @param service_init_cb function to call once the service is ready
66  * @param connect_cb function to call whenever a client connects
67  * @param disconnect_cb function to call whenever a client disconnects
68  * @param cls closure argument for @a service_init_cb, @a connect_cb and @a disconnect_cb
69  * @param handlers NULL-terminated array of message handlers for the service,
70  *                 the closure will be set to the value returned by
71  *                 the @a connect_cb for the respective connection
72  * @return 0 on success, non-zero on error
73  */
74 int
75 GNUNET_SERVICE_ruN_ (int argc,
76                      char *const *argv,
77                      const char *service_name,
78                      enum GNUNET_SERVICE_Options options,
79                      GNUNET_SERVICE_InitCallback service_init_cb,
80                      GNUNET_SERVICE_ConnectHandler connect_cb,
81                      GNUNET_SERVICE_DisconnectHandler disconnect_cb,
82                      void *cls,
83                      const struct GNUNET_MQ_MessageHandler *handlers)
84 {
85   GNUNET_break (0); // not implemented
86   return 1;
87 }
88
89
90 /**
91  * Suspend accepting connections from the listen socket temporarily.
92  * Resume activity using #GNUNET_SERVICE_resume.
93  *
94  * @param sh service to stop accepting connections.
95  */
96 void
97 GNUNET_SERVICE_suspend (struct GNUNET_SERVICE_Handle *sh)
98 {
99   GNUNET_break (0); // not implemented
100 }
101
102
103 /**
104  * Resume accepting connections from the listen socket.
105  *
106  * @param sh service to resume accepting connections.
107  */
108 void
109 GNUNET_SERVICE_resume (struct GNUNET_SERVICE_Handle *sh)
110 {
111   GNUNET_break (0); // not implemented
112 }
113
114
115 /**
116  * Continue receiving further messages from the given client.
117  * Must be called after each message received.
118  *
119  * @param c the client to continue receiving from
120  */
121 void
122 GNUNET_SERVICE_client_continue (struct GNUNET_SERVICE_Client *c)
123 {
124   GNUNET_break (0); // not implemented
125 }
126
127
128 /**
129  * Disable the warning the server issues if a message is not
130  * acknowledged in a timely fashion.  Use this call if a client is
131  * intentionally delayed for a while.  Only applies to the current
132  * message.
133  *
134  * @param c client for which to disable the warning
135  */
136 void
137 GNUNET_SERVICE_client_disable_continue_warning (struct GNUNET_SERVICE_Client *c)
138 {
139   GNUNET_break (0); // not implemented
140 }
141
142
143 /**
144  * Ask the server to disconnect from the given client.  This is the
145  * same as returning #GNUNET_SYSERR within the check procedure when
146  * handling a message, wexcept that it allows dropping of a client even
147  * when not handling a message from that client.  The `disconnect_cb`
148  * will be called on @a c even if the application closes the connection
149  * using this function.
150  *
151  * @param c client to disconnect now
152  */
153 void
154 GNUNET_SERVICE_client_drop (struct GNUNET_SERVICE_Client *c)
155 {
156   GNUNET_break (0); // not implemented
157 }
158
159
160 /**
161  * Stop the listen socket and get ready to shutdown the server once
162  * only clients marked using #GNUNET_SERVER_client_mark_monitor are
163  * left.
164  *
165  * @param sh server to stop listening on
166  */
167 void
168 GNUNET_SERVICE_stop_listening (struct GNUNET_SERVICE_Handle *sh)
169 {
170   GNUNET_break (0); // not implemented
171 }
172
173
174 /**
175  * Set the 'monitor' flag on this client.  Clients which have been
176  * marked as 'monitors' won't prevent the server from shutting down
177  * once #GNUNET_SERVICE_stop_listening() has been invoked.  The idea is
178  * that for "normal" clients we likely want to allow them to process
179  * their requests; however, monitor-clients are likely to 'never'
180  * disconnect during shutdown and thus will not be considered when
181  * determining if the server should continue to exist after
182  * shutdown has been triggered.
183  *
184  * @param c client to mark as a monitor
185  */
186 void
187 GNUNET_SERVICE_client_mark_monitor (struct GNUNET_SERVICE_Client *c)
188 {
189   GNUNET_break (0); // not implemented
190 }
191
192
193 /**
194  * Set the persist option on this client.  Indicates that the
195  * underlying socket or fd should never really be closed.  Used for
196  * indicating process death.
197  *
198  * @param c client to persist the socket (never to be closed)
199  */
200 void
201 GNUNET_SERVICE_client_persist (struct GNUNET_SERVICE_Client *c)
202 {
203   GNUNET_break (0); // not implemented
204 }
205
206
207
208 /* end of service_new.c */