-starting with new service MQ logic
[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  * Information the service tracks per listen operation.
35  */
36 struct ServiceListenContext
37 {
38
39   /**
40    * Kept in a DLL.
41    */
42   struct ServiceListenContext *next;
43
44   /**
45    * Kept in a DLL.
46    */
47   struct ServiceListenContext *prev;
48
49   /**
50    * Service this listen context belongs to.
51    */
52   struct GNUNET_SERVICE_Handle *sh;
53
54   /**
55    * Socket we are listening on.
56    */
57   struct GNUNET_NETWORK_Handle *listen_socket;
58
59   /**
60    * Task scheduled to do the listening.
61    */
62   struct GNUNET_SCHEDULER_Task *listen_task;
63
64 };
65
66
67 /**
68  * Handle to a service.
69  */
70 struct GNUNET_SERVICE_Handle
71 {
72   /**
73    * Our configuration.
74    */
75   const struct GNUNET_CONFIGURATION_Handle *cfg;
76
77   /**
78    * Name of our service.
79    */
80   const char *service_name;
81
82   /**
83    * Main service-specific task to run.
84    */
85   GNUNET_SERVICE_InitCallback service_init_cb;
86
87   /**
88    * Function to call when clients connect.
89    */
90   GNUNET_SERVICE_ConnectHandler connect_cb;
91
92   /**
93    * Function to call when clients disconnect / are disconnected.
94    */
95   GNUNET_SERVICE_DisconnectHandler disconnect_cb;
96
97   /**
98    * Closure for @e service_init_cb, @e connect_cb, @e disconnect_cb.
99    */
100   void *cb_cls;
101
102   /**
103    * DLL of listen sockets used to accept new connections.
104    */
105   struct ServiceListenContext *slc_head;
106
107   /**
108    * DLL of listen sockets used to accept new connections.
109    */
110   struct ServiceListenContext *slc_tail;
111
112   /**
113    * Our clients, kept in a DLL.
114    */
115   struct GNUNET_SERVICE_Client *clients_head;
116
117   /**
118    * Our clients, kept in a DLL.
119    */
120   struct GNUNET_SERVICE_Client *clients_tail;
121
122   /**
123    * Message handlers to use for all clients.
124    */
125   const struct GNUNET_MQ_MessageHandler *handlers;
126
127   /**
128    * Closure for @e task.
129    */
130   void *task_cls;
131
132   /**
133    * IPv4 addresses that are not allowed to connect.
134    */
135   struct GNUNET_STRINGS_IPv4NetworkPolicy *v4_denied;
136
137   /**
138    * IPv6 addresses that are not allowed to connect.
139    */
140   struct GNUNET_STRINGS_IPv6NetworkPolicy *v6_denied;
141
142   /**
143    * IPv4 addresses that are allowed to connect (if not
144    * set, all are allowed).
145    */
146   struct GNUNET_STRINGS_IPv4NetworkPolicy *v4_allowed;
147
148   /**
149    * IPv6 addresses that are allowed to connect (if not
150    * set, all are allowed).
151    */
152   struct GNUNET_STRINGS_IPv6NetworkPolicy *v6_allowed;
153
154   /**
155    * Do we require a matching UID for UNIX domain socket connections?
156    * #GNUNET_NO means that the UID does not have to match (however,
157    * @e match_gid may still impose other access control checks).
158    */
159   int match_uid;
160
161   /**
162    * Do we require a matching GID for UNIX domain socket connections?
163    * Ignored if @e match_uid is #GNUNET_YES.  Note that this is about
164    * checking that the client's UID is in our group OR that the
165    * client's GID is our GID.  If both "match_gid" and @e match_uid are
166    * #GNUNET_NO, all users on the local system have access.
167    */
168   int match_gid;
169
170   /**
171    * Set to #GNUNET_YES if we got a shutdown signal and terminate
172    * the service if #have_non_monitor_clients() returns #GNUNET_YES.
173    */
174   int got_shutdown;
175
176   /**
177    * Our options.
178    */
179   enum GNUNET_SERVICE_Options options;
180
181 };
182
183
184 /**
185  * Handle to a client that is connected to a service.
186  */
187 struct GNUNET_SERVICE_Client
188 {
189
190   /**
191    * Kept in a DLL.
192    */
193   struct GNUNET_SERVICE_Client *next;
194
195   /**
196    * Kept in a DLL.
197    */
198   struct GNUNET_SERVICE_Client *prev;
199
200   /**
201    * Server that this client belongs to.
202    */
203   struct GNUNET_SERVER_Handle *sh;
204
205   /**
206    * Socket of this client.
207    */
208   struct GNUNET_NETWORK_Handle *sock;
209
210   /**
211    * Message queue for the client.
212    */
213   struct GNUNET_MQ_Handle *mq;
214
215   /**
216    * Tokenizer we use for processing incoming data.
217    */
218   struct GNUNET_SERVER_MessageStreamTokenizer *mst;
219
220   /**
221    * Task that warns about missing calls to
222    * #GNUNET_SERVICE_client_continue().
223    */
224   struct GNUNET_SCHEDULER_Task *warn_task;
225
226   /**
227    * Task that receives data from the client to
228    * pass it to the handlers.
229    */
230   struct GNUNET_SCHEDULER_Task *recv_task;
231
232   /**
233    * Task that transmit data to the client.
234    */
235   struct GNUNET_SCHEDULER_Task *send_task;
236
237   /**
238    * User context value, value returned from
239    * the connect callback.
240    */
241   void *user_context;
242
243   /**
244    * Persist the file handle for this client no matter what happens,
245    * force the OS to close once the process actually dies.  Should only
246    * be used in special cases!
247    */
248   int persist;
249
250   /**
251    * Is this client a 'monitor' client that should not be counted
252    * when deciding on destroying the server during soft shutdown?
253    * (see also #GNUNET_SERVICE_start)
254    */
255   int is_monitor;
256
257   /**
258    * Type of last message processed (for warn_no_receive_done).
259    */
260   uint16_t warn_type;
261 };
262
263
264 /**
265  * Check if any of the clients we have left are unrelated to
266  * monitoring.
267  *
268  * @param sh service to check clients for
269  * @return #GNUNET_YES if we have non-monitoring clients left
270  */
271 static int
272 have_non_monitor_clients (struct GNUNET_SERVICE_Handle *sh)
273 {
274   struct GNUNET_SERVICE_Client *client;
275
276   for (client = sh->clients_head;NULL != client; client = client->next)
277   {
278     if (client->is_monitor)
279       continue;
280     return GNUNET_YES;
281   }
282   return GNUNET_NO;
283 }
284
285
286 /**
287  * Shutdown task triggered when a service should be terminated.
288  * This considers active clients and the service options to see
289  * how this specific service is to be terminated, and depending
290  * on this proceeds with the shutdown logic.
291  *
292  * @param cls our `struct GNUNET_SERVICE_Handle`
293  */
294 static void
295 service_main (void *cls)
296 {
297   struct GNUNET_SERVICE_Handle *sh = cls;
298   struct GNUNET_SERVICE_Client *client;
299   int alive;
300
301   switch (sh->options)
302   {
303   case GNUNET_SERVICE_OPTION_NONE:
304     GNUNET_SERVICE_shutdown (sh);
305     break;
306   case GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN:
307     /* This task should never be run if we are using
308        the manual shutdown. */
309     GNUNET_assert (0);
310     break;
311   case GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN:
312     sh->got_shutdown = GNUNET_YES;
313     GNUNET_SERVICE_suspend (sh);
314     if (GNUNET_NO == have_non_monitor_clients (sh))
315       GNUNET_SERVICE_shutdown (sh);
316     break;
317   }
318 }
319
320
321 /**
322  * First task run by any service.  Initializes our shutdown task,
323  * starts the listening operation on our listen sockets and launches
324  * the custom logic of the application service.
325  *
326  * @param cls our `struct GNUNET_SERVICE_Handle`
327  */
328 static void
329 service_main (void *cls)
330 {
331   struct GNUNET_SERVICE_Handle *sh = cls;
332
333   if (GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN != sh->options)
334     GNUNET_SCHEDULER_add_shutdown (&service_shutdown,
335                                    sh);
336   GNUNET_SERVICE_resume (sh);
337   sh->service_init_cb (sh->cb_cls,
338                        sh->cfg,
339                        sh);
340 }
341
342
343 /**
344  * Creates the "main" function for a GNUnet service.  You
345  * should almost always use the #GNUNET_SERVICE_MAIN macro
346  * instead of calling this function directly (except
347  * for ARM, which should call this function directly).
348  *
349  * The function will launch the service with the name @a service_name
350  * using the @a service_options to configure its shutdown
351  * behavior. Once the service is ready, the @a init_cb will be called
352  * for service-specific initialization.  @a init_cb will be given the
353  * service handler which can be used to control the service's
354  * availability.  When clients connect or disconnect, the respective
355  * @a connect_cb or @a disconnect_cb functions will be called. For
356  * messages received from the clients, the respective @a handlers will
357  * be invoked; for the closure of the handlers we use the return value
358  * from the @a connect_cb invocation of the respective client.
359  *
360  * Each handler MUST call #GNUNET_SERVICE_client_continue() after each
361  * message to receive further messages from this client.  If
362  * #GNUNET_SERVICE_client_continue() is not called within a short
363  * time, a warning will be logged. If delays are expected, services
364  * should call #GNUNET_SERVICE_client_disable_continue_warning() to
365  * disable the warning.
366  *
367  * Clients sending invalid messages (based on @a handlers) will be
368  * dropped. Additionally, clients can be dropped at any time using
369  * #GNUNET_SERVICE_client_drop().
370  *
371  * @param argc number of command-line arguments in @a argv
372  * @param argv array of command-line arguments
373  * @param service_name name of the service to run
374  * @param options options controlling shutdown of the service
375  * @param service_init_cb function to call once the service is ready
376  * @param connect_cb function to call whenever a client connects
377  * @param disconnect_cb function to call whenever a client disconnects
378  * @param cls closure argument for @a service_init_cb, @a connect_cb and @a disconnect_cb
379  * @param handlers NULL-terminated array of message handlers for the service,
380  *                 the closure will be set to the value returned by
381  *                 the @a connect_cb for the respective connection
382  * @return 0 on success, non-zero on error
383  */
384 int
385 GNUNET_SERVICE_ruN_ (int argc,
386                      char *const *argv,
387                      const char *service_name,
388                      enum GNUNET_SERVICE_Options options,
389                      GNUNET_SERVICE_InitCallback service_init_cb,
390                      GNUNET_SERVICE_ConnectHandler connect_cb,
391                      GNUNET_SERVICE_DisconnectHandler disconnect_cb,
392                      void *cls,
393                      const struct GNUNET_MQ_MessageHandler *handlers)
394 {
395   struct GNUNET_SERVICE_Handle sh;
396
397   // FIXME: setup (parse command line, configuration, init sh)
398   GNUNET_SCHEDULER_run (&service_main,
399                         &sh);
400   // FIXME: cleanup
401   return 1;
402 }
403
404
405 /**
406  * Suspend accepting connections from the listen socket temporarily.
407  * Resume activity using #GNUNET_SERVICE_resume.
408  *
409  * @param sh service to stop accepting connections.
410  */
411 void
412 GNUNET_SERVICE_suspend (struct GNUNET_SERVICE_Handle *sh)
413 {
414   struct ServiceListenContext *slc;
415
416   for (slc = slc_head; NULL != slc; slc = slc->next)
417   {
418     if (NULL != slc->listen_task)
419       {
420         GNUNET_SCHEDULER_cancel (slc->listen_task);
421         slc->listen_task = NULL;
422       }
423   }
424 }
425
426
427 /**
428  * Signature of functions implementing the sending functionality of a
429  * message queue.
430  *
431  * @param mq the message queue
432  * @param msg the message to send
433  * @param impl_state state of the implementation
434  */
435 static void
436 service_mq_send (struct GNUNET_MQ_Handle *mq,
437                  const struct GNUNET_MessageHeader *msg,
438                  void *impl_state)
439 {
440   struct GNUNET_SERVICE_Client *client = cls;
441
442   // FIXME 1: setup "client->send_task" for transmission.
443   // FIXME 2: I seriously hope we do not need to make a copy of `msg`!
444   // OPTIMIZATION: ideally, we'd like the ability to peak at the rest of
445   //               the queue and transmit more than one message if possible.
446 }
447
448
449 /**
450  * Implements the destruction of a message queue.  Implementations
451  * must not free @a mq, but should take care of @a impl_state.
452  * Not sure there is anything to do here! (FIXME!)
453  *
454  * @param mq the message queue to destroy
455  * @param impl_state state of the implementation
456  */
457 static void
458 service_mq_destroy (struct GNUNET_MQ_Handle *mq,
459                     void *impl_state)
460 {
461   struct GNUNET_SERVICE_Client *client = cls;
462
463   // FIXME
464 }
465
466
467 /**
468  * Implementation function that cancels the currently sent message.
469  *
470  * @param mq message queue
471  * @param impl_state state specific to the implementation
472  */
473 static void
474 service_mq_cancel (struct GNUNET_MQ_Handle *mq,
475                    void *impl_state)
476 {
477   struct GNUNET_SERVICE_Client *client = cls;
478
479   // FIXME: semantics? What to do!?
480 }
481
482
483 /**
484  * Generic error handler, called with the appropriate
485  * error code and the same closure specified at the creation of
486  * the message queue.
487  * Not every message queue implementation supports an error handler.
488  *
489  * @param cls closure
490  * @param error error code
491  */
492 static void
493 service_mq_error_handler (void *cls,
494                           enum GNUNET_MQ_Error error)
495 {
496   struct GNUNET_SERVICE_Client *client = cls;
497
498   // FIXME!
499 }
500
501
502 /**
503  * Functions with this signature are called whenever a
504  * complete message is received by the tokenizer for a client.
505  *
506  * Do not call #GNUNET_SERVER_mst_destroy() from within
507  * the scope of this callback.
508  *
509  * @param cls closure with the `struct GNUNET_SERVICE_Client *`
510  * @param client closure with the `struct GNUNET_SERVICE_Client *`
511  * @param message the actual message
512  * @return #GNUNET_OK on success (always)
513  */
514 static int
515 service_client_mst_cb (void *cls,
516                        void *client,
517                        const struct GNUNET_MessageHeader *message)
518 {
519   struct GNUNET_SERVICE_Client *client = cls;
520
521   GNUNET_MQ_inject_message (client->mq,
522                             message);
523   return GNUNET_OK;
524 }
525
526
527 /**
528  * A client sent us data. Receive and process it.  If we are done,
529  * reschedule this task.
530  *
531  * @param cls the `struct GNUNET_SERVICE_Client` that sent us data.
532  */
533 static void
534 service_client_recv (void *cls)
535 {
536   struct GNUNET_SERVICE_Client *client = cls;
537
538   // FIXME: read into buffer, pass to MST, then client->mq inject!
539   // FIXME: revise MST API to avoid the memcpy!
540   // i.e.: GNUNET_MST_read (client->sock);
541 }
542
543
544 /**
545  * We have successfully accepted a connection from a client.  Now
546  * setup the client (with the scheduler) and tell the application.
547  *
548  * @param sh service that accepted the client
549  * @param sock socket associated with the client
550  */
551 static void
552 start_client (struct GNUNET_SERVICE_Handle *sh,
553               struct GNUNET_NETWORK_Handle *csock)
554 {
555   struct GNUNET_SERVICE_Client *client;
556
557   client = GNUNET_new (struct GNUNET_SERVICE_Client);
558   GNUNET_CONTAINER_DLL_insert (sh->clients_head,
559                                sh->clients_tail,
560                                client);
561   client->sh = sh;
562   client->sock = csock;
563   client->mq = GNUNET_MQ_queue_for_callbacks (&service_mq_send,
564                                               &service_mq_destroy,
565                                               &service_mq_cancel,
566                                               client,
567                                               sh->handlers,
568                                               &service_mq_error_handler,
569                                               client);
570   client->mst = GNUNET_SERVER_mst_create (&service_client_mst_cb,
571                                           client);
572   client->user_context = sh->connect_cb (sh->cb_cls,
573                                          client,
574                                          client->mq);
575   GNUNET_MQ_set_handlers_closure (client->mq,
576                                   client->user_context);
577   client->recv_task = GNUNET_SCHEDULER_add_read (client->sock,
578                                                  &service_client_recv,
579                                                  client);
580 }
581
582
583 /**
584  * We have a client. Accept the incoming socket(s) (and reschedule
585  * the listen task).
586  *
587  * @param cls the `struct ServiceListenContext` of the ready listen socket
588  */
589 static void
590 accept_client (void *cls)
591 {
592   struct ServiceListenContext *slc = cls;
593
594   slc->listen_task = NULL;
595   while (1)
596     {
597       struct GNUNET_NETWORK_Handle *sock;
598       struct sockaddr_in *v4;
599       struct sockaddr_in6 *v6;
600       struct sockaddr_storage sa;
601       socklen_t addrlen;
602       int ok;
603
604       addrlen = sizeof (sa);
605       sock = GNUNET_NETWORK_socket_accept (slc->listen_socket,
606                                            (struct sockaddr *) &sa,
607                                            &addrlen);
608       if (NULL == sock)
609         break;
610       switch (sa.sa_family)
611       {
612       case AF_INET:
613         GNUNET_assert (addrlen == sizeof (struct sockaddr_in));
614         v4 = (const struct sockaddr_in *) addr;
615         ok = ( ( (NULL == sh->v4_allowed) ||
616                  (check_ipv4_listed (sh->v4_allowed,
617                                      &i4->sin_addr))) &&
618                ( (NULL == sh->v4_denied) ||
619                  (! check_ipv4_listed (sh->v4_denied,
620                                        &i4->sin_addr)) ) );
621         break;
622       case AF_INET6:
623         GNUNET_assert (addrlen == sizeof (struct sockaddr_in6));
624         v6 = (const struct sockaddr_in6 *) addr;
625         ok = ( ( (NULL == sh->v6_allowed) ||
626                  (check_ipv6_listed (sh->v6_allowed,
627                                      &i6->sin6_addr))) &&
628                ( (NULL == sh->v6_denied) ||
629                  (! check_ipv6_listed (sh->v6_denied,
630                                        &i6->sin6_addr)) ) );
631         break;
632 #ifndef WINDOWS
633       case AF_UNIX:
634         ok = GNUNET_OK;            /* controlled using file-system ACL now */
635         break;
636 #endif
637       default:
638         LOG (GNUNET_ERROR_TYPE_WARNING,
639              _("Unknown address family %d\n"),
640              addr->sa_family);
641         return GNUNET_SYSERR;
642       }
643       if (! ok)
644         {
645           LOG (GNUNET_ERROR_TYPE_DEBUG,
646                "Service rejected incoming connection from %s due to policy.\n",
647                GNUNET_a2s ((const struct sockaddr *) &sa,
648                            addrlen));
649           GNUNET_NETWORK_socket_close (sock);
650           continue;
651         }
652       LOG (GNUNET_ERROR_TYPE_DEBUG,
653            "Service accepted incoming connection from %s.\n",
654            GNUNET_a2s ((const struct sockaddr *) &sa,
655                        addrlen));
656       start_client (slc->sh,
657                     sock);
658     }
659   slc->listen_task = GNUNET_SCHEDULER_add_read (slc->listen_socket,
660                                                 &accept_client,
661                                                 slc);
662 }
663
664
665 /**
666  * Resume accepting connections from the listen socket.
667  *
668  * @param sh service to resume accepting connections.
669  */
670 void
671 GNUNET_SERVICE_resume (struct GNUNET_SERVICE_Handle *sh)
672 {
673   struct ServiceListenContext *slc;
674
675   for (slc = slc_head; NULL != slc; slc = slc->next)
676   {
677     GNUNET_assert (NULL == slc->listen_task);
678     slc->listen_task = GNUNET_SCHEDULER_add_read (slc->listen_socket,
679                                                   &accept_client,
680                                                   slc);
681   }
682 }
683
684
685 /**
686  * Continue receiving further messages from the given client.
687  * Must be called after each message received.
688  *
689  * @param c the client to continue receiving from
690  */
691 void
692 GNUNET_SERVICE_client_continue (struct GNUNET_SERVICE_Client *c)
693 {
694   GNUNET_break (0); // not implemented
695 }
696
697
698 /**
699  * Disable the warning the server issues if a message is not
700  * acknowledged in a timely fashion.  Use this call if a client is
701  * intentionally delayed for a while.  Only applies to the current
702  * message.
703  *
704  * @param c client for which to disable the warning
705  */
706 void
707 GNUNET_SERVICE_client_disable_continue_warning (struct GNUNET_SERVICE_Client *c)
708 {
709   GNUNET_break (NULL != c->warn_task);
710   if (NULL != c->warn_task)
711   {
712     GNUNET_SCHEDULER_cancel (c->warn_task);
713     c->warn_task = NULL;
714   }
715 }
716
717
718 /**
719  * Ask the server to disconnect from the given client.  This is the
720  * same as returning #GNUNET_SYSERR within the check procedure when
721  * handling a message, wexcept that it allows dropping of a client even
722  * when not handling a message from that client.  The `disconnect_cb`
723  * will be called on @a c even if the application closes the connection
724  * using this function.
725  *
726  * @param c client to disconnect now
727  */
728 void
729 GNUNET_SERVICE_client_drop (struct GNUNET_SERVICE_Client *c)
730 {
731   struct GNUNET_SERVICE_Handle *sh = c->sh;
732
733   GNUNET_CONTAINER_DLL_remove (sh->clients_head,
734                                sh->clients_tail,
735                                c);
736   sh->disconnect_cb (sh->cb_cls,
737                      c,
738                      c->user_context);
739   if (NULL != c->warn_task)
740   {
741     GNUNET_SCHEDULER_cancel (c->warn_task);
742     c->warn_task = NULL;
743   }
744   if (NULL != c->recv_task)
745   {
746     GNUNET_SCHEDULER_cancel (c->recv_task);
747     c->recv_task = NULL;
748   }
749   if (NULL != c->send_task)
750   {
751     GNUNET_SCHEDULER_cancel (c->send_task);
752     c->send_task = NULL;
753   }
754   GNUNET_SERVER_mst_destroy (c->mst);
755   GNUNET_MQ_destroy (c->mq);
756   if (GNUNET_NO == c->persist)
757   {
758     GNUNET_NETWORK_socket_close (c->sock);
759   }
760   else
761   {
762     GNUNET_NETWORK_socket_free_memory_only_ (c->sock);
763   }
764   GNUNET_free (c);
765   if ( (GNUNET_YES == sh->got_shutdown) &&
766        (GNUNET_NO == have_non_monitor_clients (sh)) )
767     GNUNET_SERVICE_shutdown (sh);
768 }
769
770
771 /**
772  * Explicitly stops the service.
773  *
774  * @param sh server to shutdown
775  */
776 void
777 GNUNET_SERVICE_shutdown (struct GNUNET_SERVICE_Handle *sh)
778 {
779   struct GNUNET_SERVICE_Client *client;
780
781   GNUNET_SERVICE_suspend (sh);
782   sh->got_shutdown = GNUNET_NO;
783   while (NULL != (client = sh->clients_head))
784     GNUNET_SERVICE_client_drop (client);
785 }
786
787
788 /**
789  * Set the 'monitor' flag on this client.  Clients which have been
790  * marked as 'monitors' won't prevent the server from shutting down
791  * once #GNUNET_SERVICE_stop_listening() has been invoked.  The idea is
792  * that for "normal" clients we likely want to allow them to process
793  * their requests; however, monitor-clients are likely to 'never'
794  * disconnect during shutdown and thus will not be considered when
795  * determining if the server should continue to exist after
796  * shutdown has been triggered.
797  *
798  * @param c client to mark as a monitor
799  */
800 void
801 GNUNET_SERVICE_client_mark_monitor (struct GNUNET_SERVICE_Client *c)
802 {
803   c->is_monitor = GNUNET_YES;
804   if ( (GNUNET_YES == sh->got_shutdown) &&
805        (GNUNET_NO == have_non_monitor_clients (sh)) )
806     GNUNET_SERVICE_shutdown (sh);
807 }
808
809
810 /**
811  * Set the persist option on this client.  Indicates that the
812  * underlying socket or fd should never really be closed.  Used for
813  * indicating process death.
814  *
815  * @param c client to persist the socket (never to be closed)
816  */
817 void
818 GNUNET_SERVICE_client_persist (struct GNUNET_SERVICE_Client *c)
819 {
820   c->persist = GNUNET_YES;
821 }
822
823
824 /* end of service_new.c */