-eliminating duplicate code
[oweals/gnunet.git] / src / util / server.c
1 /*
2      This file is part of GNUnet.
3      (C) 2009 Christian Grothoff (and other contributing authors)
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 2, 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., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file util/server.c
23  * @brief library for building GNUnet network servers
24  * @author Christian Grothoff
25  */
26
27 #include "platform.h"
28 #include "gnunet_common.h"
29 #include "gnunet_connection_lib.h"
30 #include "gnunet_scheduler_lib.h"
31 #include "gnunet_server_lib.h"
32 #include "gnunet_time_lib.h"
33 #include "gnunet_disk_lib.h"
34 #include "gnunet_protocols.h"
35
36 #define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
37
38 #define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util", syscall)
39
40 #define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util", syscall, filename)
41
42 #define DEBUG_SERVER GNUNET_EXTRA_LOGGING
43
44 /**
45  * List of arrays of message handlers.
46  */
47 struct HandlerList
48 {
49   /**
50    * This is a linked list.
51    */
52   struct HandlerList *next;
53
54   /**
55    * NULL-terminated array of handlers.
56    */
57   const struct GNUNET_SERVER_MessageHandler *handlers;
58 };
59
60
61 /**
62  * List of arrays of message handlers.
63  */
64 struct NotifyList
65 {
66   /**
67    * This is a linked list.
68    */
69   struct NotifyList *next;
70
71   /**
72    * Function to call.
73    */
74   GNUNET_SERVER_DisconnectCallback callback;
75
76   /**
77    * Closure for callback.
78    */
79   void *callback_cls;
80 };
81
82
83 /**
84  * @brief handle for a server
85  */
86 struct GNUNET_SERVER_Handle
87 {
88   /**
89    * List of handlers for incoming messages.
90    */
91   struct HandlerList *handlers;
92
93   /**
94    * List of our current clients.
95    */
96   struct GNUNET_SERVER_Client *clients;
97
98   /**
99    * Linked list of functions to call on disconnects by clients.
100    */
101   struct NotifyList *disconnect_notify_list;
102
103   /**
104    * Function to call for access control.
105    */
106   GNUNET_CONNECTION_AccessCheck access;
107
108   /**
109    * Closure for access.
110    */
111   void *access_cls;
112
113   /**
114    * NULL-terminated array of sockets used to listen for new
115    * connections.
116    */
117   struct GNUNET_NETWORK_Handle **listen_sockets;
118
119   /**
120    * After how long should an idle connection time
121    * out (on write).
122    */
123   struct GNUNET_TIME_Relative idle_timeout;
124
125   /**
126    * Task scheduled to do the listening.
127    */
128   GNUNET_SCHEDULER_TaskIdentifier listen_task;
129
130   /**
131    * Do we ignore messages of types that we do not understand or do we
132    * require that a handler is found (and if not kill the connection)?
133    */
134   int require_found;
135
136   /**
137    * Should all of the clients of this server continue to process
138    * connections as usual even if we get a shutdown request? (the
139    * listen socket always ignores shutdown).
140    */
141   int clients_ignore_shutdown;
142
143   GNUNET_SERVER_MstCreateCallback mst_create;
144   GNUNET_SERVER_MstDestroyCallback mst_destroy;
145   GNUNET_SERVER_MstReceiveCallback mst_receive;
146   void *mst_cls;
147 };
148
149
150 /**
151  * @brief handle for a client of the server
152  */
153 struct GNUNET_SERVER_Client
154 {
155
156   /**
157    * This is a linked list.
158    */
159   struct GNUNET_SERVER_Client *next;
160
161   /**
162    * Processing of incoming data.
163    */
164   void *mst;
165
166   /**
167    * Server that this client belongs to.
168    */
169   struct GNUNET_SERVER_Handle *server;
170
171   /**
172    * Client closure for callbacks.
173    */
174   struct GNUNET_CONNECTION_Handle *connection;
175
176   /**
177    * ID of task used to restart processing.
178    */
179   GNUNET_SCHEDULER_TaskIdentifier restart_task;
180
181   /**
182    * Task that warns about missing calls to 'GNUNET_SERVER_receive_done'.
183    */
184   GNUNET_SCHEDULER_TaskIdentifier warn_task;
185
186   /**
187    * Time when the warn task was started.
188    */
189   struct GNUNET_TIME_Absolute warn_start;
190
191   /**
192    * Last activity on this socket (used to time it out
193    * if reference_count == 0).
194    */
195   struct GNUNET_TIME_Absolute last_activity;
196
197   /**
198    *
199    */
200   GNUNET_CONNECTION_TransmitReadyNotify callback;
201
202   /**
203    * callback
204    */
205   void *callback_cls;
206
207   /**
208    * After how long should an idle connection time
209    * out (on write).
210    */
211   struct GNUNET_TIME_Relative idle_timeout;
212
213   /**
214    * Number of external entities with a reference to
215    * this client object.
216    */
217   unsigned int reference_count;
218
219   /**
220    * Was processing if incoming messages suspended while
221    * we were still processing data already received?
222    * This is a counter saying how often processing was
223    * suspended (once per handler invoked).
224    */
225   unsigned int suspended;
226
227   /**
228    * Are we currently in the "process_client_buffer" function (and
229    * will hence restart the receive job on exit if suspended == 0 once
230    * we are done?).  If this is set, then "receive_done" will
231    * essentially only decrement suspended; if this is not set, then
232    * "receive_done" may need to restart the receive process (either
233    * from the side-buffer or via select/recv).
234    */
235   int in_process_client_buffer;
236
237   /**
238    * We're about to close down this client due to some serious
239    * error.
240    */
241   int shutdown_now;
242
243   /**
244    * Are we currently trying to receive? (YES if we are, NO if we are not,
245    * SYSERR if data is already available in MST).
246    */
247   int receive_pending;
248
249   /**
250    * Finish pending write when disconnecting?
251    */
252   int finish_pending_write;
253
254   /**
255    * Persist the file handle for this client no matter what happens,
256    * force the OS to close once the process actually dies.  Should only
257    * be used in special cases!
258    */
259   int persist;
260
261   /**
262    * Type of last message processed (for warn_no_receive_done).
263    */
264   uint16_t warn_type;
265 };
266
267
268 /**
269  * Scheduler says our listen socket is ready.  Process it!
270  *
271  * @param cls handle to our server for which we are processing the listen
272  *        socket
273  * @param tc reason why we are running right now
274  */
275 static void
276 process_listen_socket (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
277 {
278   struct GNUNET_SERVER_Handle *server = cls;
279   struct GNUNET_CONNECTION_Handle *sock;
280   struct GNUNET_SERVER_Client *client;
281   struct GNUNET_NETWORK_FDSet *r;
282   unsigned int i;
283
284   server->listen_task = GNUNET_SCHEDULER_NO_TASK;
285   r = GNUNET_NETWORK_fdset_create ();
286   i = 0;
287   while (NULL != server->listen_sockets[i])
288     GNUNET_NETWORK_fdset_set (r, server->listen_sockets[i++]);
289   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
290   {
291     /* ignore shutdown, someone else will take care of it! */
292     server->listen_task =
293         GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
294                                      GNUNET_SCHEDULER_NO_TASK,
295                                      GNUNET_TIME_UNIT_FOREVER_REL, r, NULL,
296                                      &process_listen_socket, server);
297     GNUNET_NETWORK_fdset_destroy (r);
298     return;
299   }
300   i = 0;
301   while (NULL != server->listen_sockets[i])
302   {
303     if (GNUNET_NETWORK_fdset_isset (tc->read_ready, server->listen_sockets[i]))
304     {
305       sock =
306           GNUNET_CONNECTION_create_from_accept (server->access,
307                                                 server->access_cls,
308                                                 server->listen_sockets[i]);
309       if (sock != NULL)
310       {
311 #if DEBUG_SERVER
312         LOG (GNUNET_ERROR_TYPE_DEBUG, "Server accepted incoming connection.\n");
313 #endif
314         client = GNUNET_SERVER_connect_socket (server, sock);
315         GNUNET_CONNECTION_ignore_shutdown (sock,
316                                            server->clients_ignore_shutdown);
317         /* decrement reference count, we don't keep "client" alive */
318         GNUNET_SERVER_client_drop (client);
319       }
320     }
321     i++;
322   }
323   /* listen for more! */
324   server->listen_task =
325       GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
326                                    GNUNET_SCHEDULER_NO_TASK,
327                                    GNUNET_TIME_UNIT_FOREVER_REL, r, NULL,
328                                    &process_listen_socket, server);
329   GNUNET_NETWORK_fdset_destroy (r);
330 }
331
332
333 /**
334  * Create and initialize a listen socket for the server.
335  *
336  * @param serverAddr address to listen on
337  * @param socklen length of address
338  * @return NULL on error, otherwise the listen socket
339  */
340 static struct GNUNET_NETWORK_Handle *
341 open_listen_socket (const struct sockaddr *serverAddr, socklen_t socklen)
342 {
343   const static int on = 1;
344   struct GNUNET_NETWORK_Handle *sock;
345   uint16_t port;
346   int eno;
347
348   switch (serverAddr->sa_family)
349   {
350   case AF_INET:
351     port = ntohs (((const struct sockaddr_in *) serverAddr)->sin_port);
352     break;
353   case AF_INET6:
354     port = ntohs (((const struct sockaddr_in6 *) serverAddr)->sin6_port);
355     break;
356   case AF_UNIX:
357     port = 0;
358     break;
359   default:
360     GNUNET_break (0);
361     port = 0;
362     break;
363   }
364   sock = GNUNET_NETWORK_socket_create (serverAddr->sa_family, SOCK_STREAM, 0);
365   if (NULL == sock)
366   {
367     LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket");
368     errno = 0;
369     return NULL;
370   }
371   if (port != 0)
372   {
373     if (GNUNET_NETWORK_socket_setsockopt
374         (sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK)
375       LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
376                     "setsockopt");
377 #ifdef IPV6_V6ONLY
378     if ((serverAddr->sa_family == AF_INET6) &&
379         (GNUNET_NETWORK_socket_setsockopt
380          (sock, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof (on)) != GNUNET_OK))
381       LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
382                     "setsockopt");
383 #endif
384   }
385   /* bind the socket */
386   if (GNUNET_NETWORK_socket_bind (sock, serverAddr, socklen) != GNUNET_OK)
387   {
388     eno = errno;
389     if (errno != EADDRINUSE)
390     {
391       /* we don't log 'EADDRINUSE' here since an IPv4 bind may
392        * fail if we already took the port on IPv6; if both IPv4 and
393        * IPv6 binds fail, then our caller will log using the
394        * errno preserved in 'eno' */
395       LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "bind");
396       if (port != 0)
397         LOG (GNUNET_ERROR_TYPE_ERROR, _("`%s' failed for port %d (%s).\n"),
398              "bind", port,
399              (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6");
400       eno = 0;
401     }
402     else
403     {
404       if (port != 0)
405         LOG (GNUNET_ERROR_TYPE_WARNING,
406              _("`%s' failed for port %d (%s): address already in use\n"),
407              "bind", port,
408              (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6");
409       else if (serverAddr->sa_family == AF_UNIX)
410         LOG (GNUNET_ERROR_TYPE_WARNING,
411              _("`%s' failed for `%s': address already in use\n"), "bind",
412              ((const struct sockaddr_un *) serverAddr)->sun_path);
413
414     }
415     GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
416     errno = eno;
417     return NULL;
418   }
419   if (GNUNET_OK != GNUNET_NETWORK_socket_listen (sock, 5))
420   {
421     LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "listen");
422     GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
423     errno = 0;
424     return NULL;
425   }
426 #if DEBUG_SERVER
427   if (port != 0)
428     LOG (GNUNET_ERROR_TYPE_DEBUG, "Server starts to listen on port %u.\n",
429          port);
430 #endif
431   return sock;
432 }
433
434
435 /**
436  * Create a new server.
437  *
438  * @param access function for access control
439  * @param access_cls closure for access
440  * @param lsocks NULL-terminated array of listen sockets
441  * @param idle_timeout after how long should we timeout idle connections?
442  * @param require_found if YES, connections sending messages of unknown type
443  *        will be closed
444  * @return handle for the new server, NULL on error
445  *         (typically, "port" already in use)
446  */
447 struct GNUNET_SERVER_Handle *
448 GNUNET_SERVER_create_with_sockets (GNUNET_CONNECTION_AccessCheck access,
449                                    void *access_cls,
450                                    struct GNUNET_NETWORK_Handle **lsocks,
451                                    struct GNUNET_TIME_Relative idle_timeout,
452                                    int require_found)
453 {
454   struct GNUNET_SERVER_Handle *ret;
455   struct GNUNET_NETWORK_FDSet *r;
456   int i;
457
458   ret = GNUNET_malloc (sizeof (struct GNUNET_SERVER_Handle));
459   ret->idle_timeout = idle_timeout;
460   ret->listen_sockets = lsocks;
461   ret->access = access;
462   ret->access_cls = access_cls;
463   ret->require_found = require_found;
464   if (lsocks != NULL)
465   {
466     r = GNUNET_NETWORK_fdset_create ();
467     i = 0;
468     while (NULL != ret->listen_sockets[i])
469       GNUNET_NETWORK_fdset_set (r, ret->listen_sockets[i++]);
470     ret->listen_task =
471         GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
472                                      GNUNET_SCHEDULER_NO_TASK,
473                                      GNUNET_TIME_UNIT_FOREVER_REL, r, NULL,
474                                      &process_listen_socket, ret);
475     GNUNET_NETWORK_fdset_destroy (r);
476   }
477   return ret;
478 }
479
480
481 /**
482  * Create a new server.
483  *
484  * @param access function for access control
485  * @param access_cls closure for access
486  * @param serverAddr address to listen on (including port), NULL terminated array
487  * @param socklen length of serverAddr
488  * @param idle_timeout after how long should we timeout idle connections?
489  * @param require_found if YES, connections sending messages of unknown type
490  *        will be closed
491  * @return handle for the new server, NULL on error
492  *         (typically, "port" already in use)
493  */
494 struct GNUNET_SERVER_Handle *
495 GNUNET_SERVER_create (GNUNET_CONNECTION_AccessCheck access, void *access_cls,
496                       struct sockaddr *const *serverAddr,
497                       const socklen_t * socklen,
498                       struct GNUNET_TIME_Relative idle_timeout,
499                       int require_found)
500 {
501   struct GNUNET_NETWORK_Handle **lsocks;
502   unsigned int i;
503   unsigned int j;
504
505   i = 0;
506   while (serverAddr[i] != NULL)
507     i++;
508   if (i > 0)
509   {
510     lsocks = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (i + 1));
511     i = 0;
512     j = 0;
513     while (serverAddr[i] != NULL)
514     {
515       lsocks[j] = open_listen_socket (serverAddr[i], socklen[i]);
516       if (lsocks[j] != NULL)
517         j++;
518       i++;
519     }
520     if (j == 0)
521     {
522       if (errno != 0)
523         LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "bind");
524       GNUNET_free (lsocks);
525       lsocks = NULL;
526     }
527   }
528   else
529   {
530     lsocks = NULL;
531   }
532   return GNUNET_SERVER_create_with_sockets (access, access_cls, lsocks,
533                                             idle_timeout, require_found);
534 }
535
536
537 /**
538  * Free resources held by this server.
539  *
540  * @param s server to destroy
541  */
542 void
543 GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *s)
544 {
545   struct HandlerList *hpos;
546   struct NotifyList *npos;
547   unsigned int i;
548
549 #if DEBUG_SERVER
550   LOG (GNUNET_ERROR_TYPE_DEBUG, "Server shutting down.\n");
551 #endif
552   if (GNUNET_SCHEDULER_NO_TASK != s->listen_task)
553   {
554     GNUNET_SCHEDULER_cancel (s->listen_task);
555     s->listen_task = GNUNET_SCHEDULER_NO_TASK;
556   }
557   if (s->listen_sockets != NULL)
558   {
559     i = 0;
560     while (s->listen_sockets[i] != NULL)
561       GNUNET_break (GNUNET_OK ==
562                     GNUNET_NETWORK_socket_close (s->listen_sockets[i++]));
563     GNUNET_free (s->listen_sockets);
564     s->listen_sockets = NULL;
565   }
566   while (s->clients != NULL)
567     GNUNET_SERVER_client_disconnect (s->clients);
568   while (NULL != (hpos = s->handlers))
569   {
570     s->handlers = hpos->next;
571     GNUNET_free (hpos);
572   }
573   while (NULL != (npos = s->disconnect_notify_list))
574   {
575     npos->callback (npos->callback_cls, NULL);
576     s->disconnect_notify_list = npos->next;
577     GNUNET_free (npos);
578   }
579   GNUNET_free (s);
580 }
581
582
583 /**
584  * Add additional handlers to an existing server.
585  *
586  * @param server the server to add handlers to
587  * @param handlers array of message handlers for
588  *        incoming messages; the last entry must
589  *        have "NULL" for the "callback"; multiple
590  *        entries for the same type are allowed,
591  *        they will be called in order of occurence.
592  *        These handlers can be removed later;
593  *        the handlers array must exist until removed
594  *        (or server is destroyed).
595  */
596 void
597 GNUNET_SERVER_add_handlers (struct GNUNET_SERVER_Handle *server,
598                             const struct GNUNET_SERVER_MessageHandler *handlers)
599 {
600   struct HandlerList *p;
601
602   p = GNUNET_malloc (sizeof (struct HandlerList));
603   p->handlers = handlers;
604   p->next = server->handlers;
605   server->handlers = p;
606 }
607
608
609 void
610 GNUNET_SERVER_set_callbacks (struct GNUNET_SERVER_Handle *server,
611                              GNUNET_SERVER_MstCreateCallback create,
612                              GNUNET_SERVER_MstDestroyCallback destroy,
613                              GNUNET_SERVER_MstReceiveCallback receive,
614                              void *cls)
615 {
616   server->mst_create = create;
617   server->mst_destroy = destroy;
618   server->mst_receive = receive;
619   server->mst_cls = cls;
620 }
621
622
623 /**
624  * Task run to warn about missing calls to 'GNUNET_SERVER_receive_done'.
625  *
626  * @param cls our 'struct GNUNET_SERVER_Client*' to process more requests from
627  * @param tc scheduler context (unused)
628  */
629 static void
630 warn_no_receive_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
631 {
632   struct GNUNET_SERVER_Client *client = cls;
633
634   client->warn_task =
635       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
636                                     &warn_no_receive_done, client);
637   if (0 == (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
638     LOG (GNUNET_ERROR_TYPE_WARNING,
639          _
640          ("Processing code for message of type %u did not call GNUNET_SERVER_receive_done after %llums\n"),
641          (unsigned int) client->warn_type,
642          (unsigned long long)
643          GNUNET_TIME_absolute_get_duration (client->warn_start).rel_value);
644 }
645
646
647 /**
648  * Disable the warning the server issues if a message is not acknowledged
649  * in a timely fashion.  Use this call if a client is intentionally delayed
650  * for a while.  Only applies to the current message.
651  *
652  * @param client client for which to disable the warning
653  */
654 void
655 GNUNET_SERVER_disable_receive_done_warning (struct GNUNET_SERVER_Client *client)
656 {
657   if (GNUNET_SCHEDULER_NO_TASK != client->warn_task)
658   {
659     GNUNET_SCHEDULER_cancel (client->warn_task);
660     client->warn_task = GNUNET_SCHEDULER_NO_TASK;
661   }
662 }
663
664
665 /**
666  * Inject a message into the server, pretend it came
667  * from the specified client.  Delivery of the message
668  * will happen instantly (if a handler is installed;
669  * otherwise the call does nothing).
670  *
671  * @param server the server receiving the message
672  * @param sender the "pretended" sender of the message
673  *        can be NULL!
674  * @param message message to transmit
675  * @return GNUNET_OK if the message was OK and the
676  *                   connection can stay open
677  *         GNUNET_SYSERR if the connection to the
678  *         client should be shut down
679  */
680 int
681 GNUNET_SERVER_inject (struct GNUNET_SERVER_Handle *server,
682                       struct GNUNET_SERVER_Client *sender,
683                       const struct GNUNET_MessageHeader *message)
684 {
685   struct HandlerList *pos;
686   const struct GNUNET_SERVER_MessageHandler *mh;
687   unsigned int i;
688   uint16_t type;
689   uint16_t size;
690   int found;
691
692   type = ntohs (message->type);
693   size = ntohs (message->size);
694 #if DEBUG_SERVER
695
696   LOG (GNUNET_ERROR_TYPE_DEBUG,
697        "Server schedules transmission of %u-byte message of type %u to client.\n",
698        size, type);
699 #endif
700   pos = server->handlers;
701   found = GNUNET_NO;
702   while (pos != NULL)
703   {
704     i = 0;
705     while (pos->handlers[i].callback != NULL)
706     {
707       mh = &pos->handlers[i];
708       if ((mh->type == type) || (mh->type == GNUNET_MESSAGE_TYPE_ALL))
709       {
710         if ((mh->expected_size != 0) && (mh->expected_size != size))
711         {
712 #if GNUNET8_NETWORK_IS_DEAD
713           LOG (GNUNET_ERROR_TYPE_WARNING,
714                "Expected %u bytes for message of type %u, got %u\n",
715                mh->expected_size, mh->type, size);
716           GNUNET_break_op (0);
717 #endif
718           return GNUNET_SYSERR;
719         }
720         if (sender != NULL)
721         {
722           if (0 == sender->suspended)
723           {
724             sender->warn_start = GNUNET_TIME_absolute_get ();
725             sender->warn_task =
726                 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
727                                               &warn_no_receive_done, sender);
728             sender->warn_type = type;
729           }
730           sender->suspended++;
731         }
732         mh->callback (mh->callback_cls, sender, message);
733         found = GNUNET_YES;
734       }
735       i++;
736     }
737     pos = pos->next;
738   }
739   if (found == GNUNET_NO)
740   {
741     LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
742          "Received message of unknown type %d\n", type);
743     if (server->require_found == GNUNET_YES)
744       return GNUNET_SYSERR;
745   }
746   return GNUNET_OK;
747 }
748
749
750 /**
751  * We are receiving an incoming message.  Process it.
752  *
753  * @param cls our closure (handle for the client)
754  * @param buf buffer with data received from network
755  * @param available number of bytes available in buf
756  * @param addr address of the sender
757  * @param addrlen length of addr
758  * @param errCode code indicating errors receiving, 0 for success
759  */
760 static void
761 process_incoming (void *cls, const void *buf, size_t available,
762                   const struct sockaddr *addr, socklen_t addrlen, int errCode);
763
764
765 /**
766  * Process messages from the client's message tokenizer until either
767  * the tokenizer is empty (and then schedule receiving more), or
768  * until some handler is not immediately done (then wait for restart_processing)
769  * or shutdown.
770  *
771  * @param client the client to process, RC must have already been increased
772  *        using GNUNET_SERVER_client_keep and will be decreased by one in this
773  *        function
774  * @param ret GNUNET_NO to start processing from the buffer,
775  *            GNUNET_OK if the mst buffer is drained and we should instantly go back to receiving
776  *            GNUNET_SYSERR if we should instantly abort due to error in a previous step
777  */
778 static void
779 process_mst (struct GNUNET_SERVER_Client *client, int ret)
780 {
781   while ((ret != GNUNET_SYSERR) && (client->server != NULL) &&
782          (GNUNET_YES != client->shutdown_now) && (0 == client->suspended))
783   {
784     if (ret == GNUNET_OK)
785     {
786       client->receive_pending = GNUNET_YES;
787 #if DEBUG_SERVER
788       LOG (GNUNET_ERROR_TYPE_DEBUG,
789            "Server re-enters receive loop, timeout: %llu.\n",
790            client->idle_timeout.rel_value);
791 #endif
792       GNUNET_CONNECTION_receive (client->connection,
793                                  GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
794                                  client->idle_timeout, &process_incoming,
795                                  client);
796       break;
797     }
798 #if DEBUG_SERVER
799     LOG (GNUNET_ERROR_TYPE_DEBUG,
800          "Server processes additional messages instantly.\n");
801 #endif
802     if (client->server->mst_receive != NULL)
803       ret =
804           client->server->mst_receive (client->server->mst_cls, client->mst,
805                                        client, NULL, 0, GNUNET_NO, GNUNET_YES);
806     else
807       ret =
808           GNUNET_SERVER_mst_receive (client->mst, client, NULL, 0, GNUNET_NO,
809                                      GNUNET_YES);
810   }
811 #if DEBUG_SERVER
812   LOG (GNUNET_ERROR_TYPE_DEBUG,
813        "Server leaves instant processing loop: ret = %d, server = %p, shutdown = %d, suspended = %u\n",
814        ret, client->server, client->shutdown_now, client->suspended);
815 #endif
816
817   if (ret == GNUNET_NO)
818   {
819 #if DEBUG_SERVER
820     LOG (GNUNET_ERROR_TYPE_DEBUG,
821          "Server has more data pending but is suspended.\n");
822 #endif
823     client->receive_pending = GNUNET_SYSERR;    /* data pending */
824   }
825   if ((ret == GNUNET_SYSERR) || (GNUNET_YES == client->shutdown_now))
826     GNUNET_SERVER_client_disconnect (client);
827   GNUNET_SERVER_client_drop (client);
828 }
829
830
831 /**
832  * We are receiving an incoming message.  Process it.
833  *
834  * @param cls our closure (handle for the client)
835  * @param buf buffer with data received from network
836  * @param available number of bytes available in buf
837  * @param addr address of the sender
838  * @param addrlen length of addr
839  * @param errCode code indicating errors receiving, 0 for success
840  */
841 static void
842 process_incoming (void *cls, const void *buf, size_t available,
843                   const struct sockaddr *addr, socklen_t addrlen, int errCode)
844 {
845   struct GNUNET_SERVER_Client *client = cls;
846   struct GNUNET_SERVER_Handle *server = client->server;
847   struct GNUNET_TIME_Absolute end;
848   struct GNUNET_TIME_Absolute now;
849   int ret;
850
851   GNUNET_assert (client->receive_pending == GNUNET_YES);
852   client->receive_pending = GNUNET_NO;
853   now = GNUNET_TIME_absolute_get ();
854   end = GNUNET_TIME_absolute_add (client->last_activity, client->idle_timeout);
855
856   if ((buf == NULL) && (available == 0) && (addr == NULL) && (errCode == 0) &&
857       (client->shutdown_now != GNUNET_YES) && (server != NULL) &&
858       (GNUNET_YES == GNUNET_CONNECTION_check (client->connection)) &&
859       (end.abs_value > now.abs_value))
860   {
861     /* wait longer, timeout changed (i.e. due to us sending) */
862 #if DEBUG_SERVER
863     LOG (GNUNET_ERROR_TYPE_DEBUG,
864          "Receive time out, but no disconnect due to sending (%p)\n",
865          GNUNET_a2s (addr, addrlen));
866 #endif
867     client->receive_pending = GNUNET_YES;
868     GNUNET_CONNECTION_receive (client->connection,
869                                GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
870                                GNUNET_TIME_absolute_get_remaining (end),
871                                &process_incoming, client);
872     return;
873   }
874   if ((buf == NULL) || (available == 0) || (errCode != 0) || (server == NULL) ||
875       (client->shutdown_now == GNUNET_YES) ||
876       (GNUNET_YES != GNUNET_CONNECTION_check (client->connection)))
877   {
878     /* other side closed connection, error connecting, etc. */
879     GNUNET_SERVER_client_disconnect (client);
880     return;
881   }
882 #if DEBUG_SERVER
883   LOG (GNUNET_ERROR_TYPE_DEBUG, "Server receives %u bytes from `%s'.\n",
884        (unsigned int) available, GNUNET_a2s (addr, addrlen));
885 #endif
886   GNUNET_SERVER_client_keep (client);
887   client->last_activity = now;
888
889   if (server->mst_receive != NULL)
890     ret =
891         client->server->mst_receive (client->server->mst_cls, client->mst,
892                                      client, buf, available, GNUNET_NO, GNUNET_YES);
893   else
894     ret =
895         GNUNET_SERVER_mst_receive (client->mst, client, buf, available, GNUNET_NO,
896                                    GNUNET_YES);
897
898   process_mst (client, ret);
899 }
900
901
902 /**
903  * Task run to start again receiving from the network
904  * and process requests.
905  *
906  * @param cls our 'struct GNUNET_SERVER_Client*' to process more requests from
907  * @param tc scheduler context (unused)
908  */
909 static void
910 restart_processing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
911 {
912   struct GNUNET_SERVER_Client *client = cls;
913   struct GNUNET_SERVER_Handle *server = client->server;
914
915   client->restart_task = GNUNET_SCHEDULER_NO_TASK;
916   if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) &&
917       (GNUNET_NO == server->clients_ignore_shutdown))
918   {
919     GNUNET_SERVER_client_disconnect (client);
920     return;
921   }
922   if (client->receive_pending == GNUNET_NO)
923   {
924 #if DEBUG_SERVER
925     LOG (GNUNET_ERROR_TYPE_DEBUG, "Server begins to read again from client.\n");
926 #endif
927     client->receive_pending = GNUNET_YES;
928     GNUNET_CONNECTION_receive (client->connection,
929                                GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
930                                client->idle_timeout, &process_incoming, client);
931     return;
932   }
933 #if DEBUG_SERVER
934   LOG (GNUNET_ERROR_TYPE_DEBUG,
935        "Server continues processing messages still in the buffer.\n");
936 #endif
937   GNUNET_SERVER_client_keep (client);
938   client->receive_pending = GNUNET_NO;
939   process_mst (client, GNUNET_NO);
940 }
941
942
943 /**
944  * This function is called whenever our inbound message tokenizer has
945  * received a complete message.
946  *
947  * @param cls closure (struct GNUNET_SERVER_Handle)
948  * @param client identification of the client (struct GNUNET_SERVER_Client*)
949  * @param message the actual message
950  */
951 static void
952 client_message_tokenizer_callback (void *cls, void *client,
953                                    const struct GNUNET_MessageHeader *message)
954 {
955   struct GNUNET_SERVER_Handle *server = cls;
956   struct GNUNET_SERVER_Client *sender = client;
957   int ret;
958
959 #if DEBUG_SERVER
960
961   LOG (GNUNET_ERROR_TYPE_DEBUG,
962        "Tokenizer gives server message of type %u from client\n",
963        ntohs (message->type));
964 #endif
965   sender->in_process_client_buffer = GNUNET_YES;
966   ret = GNUNET_SERVER_inject (server, sender, message);
967   sender->in_process_client_buffer = GNUNET_NO;
968   if (GNUNET_OK != ret)
969     GNUNET_SERVER_client_disconnect (sender);
970 }
971
972
973 /**
974  * Add a TCP socket-based connection to the set of handles managed by
975  * this server.  Use this function for outgoing (P2P) connections that
976  * we initiated (and where this server should process incoming
977  * messages).
978  *
979  * @param server the server to use
980  * @param connection the connection to manage (client must
981  *        stop using this connection from now on)
982  * @return the client handle (client should call
983  *         "client_drop" on the return value eventually)
984  */
985 struct GNUNET_SERVER_Client *
986 GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server,
987                               struct GNUNET_CONNECTION_Handle *connection)
988 {
989   struct GNUNET_SERVER_Client *client;
990
991   client = GNUNET_malloc (sizeof (struct GNUNET_SERVER_Client));
992   client->connection = connection;
993   client->reference_count = 1;
994   client->server = server;
995   client->last_activity = GNUNET_TIME_absolute_get ();
996   client->next = server->clients;
997   client->idle_timeout = server->idle_timeout;
998   server->clients = client;
999   client->receive_pending = GNUNET_YES;
1000   client->callback = NULL;
1001   client->callback_cls = NULL;
1002
1003   if (server->mst_create != NULL)
1004     client->mst =
1005         server->mst_create (server->mst_cls, client);
1006   else
1007     client->mst =
1008         GNUNET_SERVER_mst_create (&client_message_tokenizer_callback, server);
1009
1010   GNUNET_CONNECTION_receive (client->connection,
1011                              GNUNET_SERVER_MAX_MESSAGE_SIZE - 1,
1012                              client->idle_timeout, &process_incoming, client);
1013   return client;
1014 }
1015
1016
1017 /**
1018  * Change the timeout for a particular client.  Decreasing the timeout
1019  * may not go into effect immediately (only after the previous timeout
1020  * times out or activity happens on the socket).
1021  *
1022  * @param client the client to update
1023  * @param timeout new timeout for activities on the socket
1024  */
1025 void
1026 GNUNET_SERVER_client_set_timeout (struct GNUNET_SERVER_Client *client,
1027                                   struct GNUNET_TIME_Relative timeout)
1028 {
1029   client->idle_timeout = timeout;
1030 }
1031
1032
1033 void
1034 GNUNET_SERVER_client_set_finish_pending_write (struct GNUNET_SERVER_Client *client,
1035                                                int finish)
1036 {
1037   client->finish_pending_write = finish;
1038 }
1039
1040
1041 /**
1042  * Notify the server that the given client handle should
1043  * be kept (keeps the connection up if possible, increments
1044  * the internal reference counter).
1045  *
1046  * @param client the client to keep
1047  */
1048 void
1049 GNUNET_SERVER_client_keep (struct GNUNET_SERVER_Client *client)
1050 {
1051   client->reference_count++;
1052 }
1053
1054
1055 /**
1056  * Notify the server that the given client handle is no
1057  * longer required.  Decrements the reference counter.  If
1058  * that counter reaches zero an inactive connection maybe
1059  * closed.
1060  *
1061  * @param client the client to drop
1062  */
1063 void
1064 GNUNET_SERVER_client_drop (struct GNUNET_SERVER_Client *client)
1065 {
1066   GNUNET_assert (client->reference_count > 0);
1067   client->reference_count--;
1068   if ((client->shutdown_now == GNUNET_YES) && (client->reference_count == 0))
1069     GNUNET_SERVER_client_disconnect (client);
1070 }
1071
1072
1073 /**
1074  * Obtain the network address of the other party.
1075  *
1076  * @param client the client to get the address for
1077  * @param addr where to store the address
1078  * @param addrlen where to store the length of the address
1079  * @return GNUNET_OK on success
1080  */
1081 int
1082 GNUNET_SERVER_client_get_address (struct GNUNET_SERVER_Client *client,
1083                                   void **addr, size_t * addrlen)
1084 {
1085   return GNUNET_CONNECTION_get_address (client->connection, addr, addrlen);
1086 }
1087
1088
1089 /**
1090  * Ask the server to notify us whenever a client disconnects.
1091  * This function is called whenever the actual network connection
1092  * is closed; the reference count may be zero or larger than zero
1093  * at this point.
1094  *
1095  * @param server the server manageing the clients
1096  * @param callback function to call on disconnect
1097  * @param callback_cls closure for callback
1098  */
1099 void
1100 GNUNET_SERVER_disconnect_notify (struct GNUNET_SERVER_Handle *server,
1101                                  GNUNET_SERVER_DisconnectCallback callback,
1102                                  void *callback_cls)
1103 {
1104   struct NotifyList *n;
1105
1106   n = GNUNET_malloc (sizeof (struct NotifyList));
1107   n->callback = callback;
1108   n->callback_cls = callback_cls;
1109   n->next = server->disconnect_notify_list;
1110   server->disconnect_notify_list = n;
1111 }
1112
1113
1114 /**
1115  * Ask the server to stop notifying us whenever a client disconnects.
1116  *
1117  * @param server the server manageing the clients
1118  * @param callback function to call on disconnect
1119  * @param callback_cls closure for callback
1120  */
1121 void
1122 GNUNET_SERVER_disconnect_notify_cancel (struct GNUNET_SERVER_Handle *server,
1123                                         GNUNET_SERVER_DisconnectCallback
1124                                         callback, void *callback_cls)
1125 {
1126   struct NotifyList *pos;
1127   struct NotifyList *prev;
1128
1129   prev = NULL;
1130   pos = server->disconnect_notify_list;
1131   while (pos != NULL)
1132   {
1133     if ((pos->callback == callback) && (pos->callback_cls == callback_cls))
1134       break;
1135     prev = pos;
1136     pos = pos->next;
1137   }
1138   if (pos == NULL)
1139   {
1140     GNUNET_break (0);
1141     return;
1142   }
1143   if (prev == NULL)
1144     server->disconnect_notify_list = pos->next;
1145   else
1146     prev->next = pos->next;
1147   GNUNET_free (pos);
1148 }
1149
1150
1151 /**
1152  * Ask the server to disconnect from the given client.
1153  * This is the same as returning GNUNET_SYSERR from a message
1154  * handler, except that it allows dropping of a client even
1155  * when not handling a message from that client.
1156  *
1157  * @param client the client to disconnect from
1158  */
1159 void
1160 GNUNET_SERVER_client_disconnect (struct GNUNET_SERVER_Client *client)
1161 {
1162   struct GNUNET_SERVER_Client *prev;
1163   struct GNUNET_SERVER_Client *pos;
1164   struct GNUNET_SERVER_Handle *server;
1165   struct NotifyList *n;
1166   unsigned int rc;
1167
1168 #if DEBUG_SERVER
1169   LOG (GNUNET_ERROR_TYPE_DEBUG,
1170        "Client is being disconnected from the server.\n");
1171 #endif
1172   if (client->restart_task != GNUNET_SCHEDULER_NO_TASK)
1173   {
1174     GNUNET_SCHEDULER_cancel (client->restart_task);
1175     client->restart_task = GNUNET_SCHEDULER_NO_TASK;
1176   }
1177   if (client->warn_task != GNUNET_SCHEDULER_NO_TASK)
1178   {
1179     GNUNET_SCHEDULER_cancel (client->warn_task);
1180     client->warn_task = GNUNET_SCHEDULER_NO_TASK;
1181   }
1182   if (GNUNET_YES == client->receive_pending)
1183   {
1184     GNUNET_CONNECTION_receive_cancel (client->connection);
1185     client->receive_pending = GNUNET_NO;
1186   }
1187
1188   rc = client->reference_count;
1189   if (client->shutdown_now != GNUNET_YES)
1190   {
1191     server = client->server;
1192     client->shutdown_now = GNUNET_YES;
1193     prev = NULL;
1194     pos = server->clients;
1195     while ((pos != NULL) && (pos != client))
1196     {
1197       prev = pos;
1198       pos = pos->next;
1199     }
1200     GNUNET_assert (pos != NULL);
1201     if (prev == NULL)
1202       server->clients = pos->next;
1203     else
1204       prev->next = pos->next;
1205     if (client->restart_task != GNUNET_SCHEDULER_NO_TASK)
1206     {
1207       GNUNET_SCHEDULER_cancel (client->restart_task);
1208       client->restart_task = GNUNET_SCHEDULER_NO_TASK;
1209     }
1210     if (client->warn_task != GNUNET_SCHEDULER_NO_TASK)
1211     {
1212       GNUNET_SCHEDULER_cancel (client->warn_task);
1213       client->warn_task = GNUNET_SCHEDULER_NO_TASK;
1214     }
1215     n = server->disconnect_notify_list;
1216     while (n != NULL)
1217     {
1218       n->callback (n->callback_cls, client);
1219       n = n->next;
1220     }
1221   }
1222   if (rc > 0)
1223   {
1224 #if DEBUG_SERVER
1225     LOG (GNUNET_ERROR_TYPE_DEBUG,
1226          "RC still positive, not destroying everything.\n");
1227 #endif
1228     return;
1229   }
1230   if (client->in_process_client_buffer == GNUNET_YES)
1231   {
1232 #if DEBUG_SERVER
1233     LOG (GNUNET_ERROR_TYPE_DEBUG,
1234          "Still processing inputs, not destroying everything.\n");
1235 #endif
1236     return;
1237   }
1238
1239   if (client->persist == GNUNET_YES)
1240     GNUNET_CONNECTION_persist_ (client->connection);
1241   GNUNET_CONNECTION_destroy (client->connection, client->finish_pending_write);
1242
1243   if (client->server->mst_destroy != NULL)
1244     client->server->mst_destroy (client->server->mst_cls, client->mst);
1245   else
1246     GNUNET_SERVER_mst_destroy (client->mst);
1247
1248   GNUNET_free (client);
1249 }
1250
1251
1252 /**
1253  * Disable the "CORK" feature for communication with the given client,
1254  * forcing the OS to immediately flush the buffer on transmission
1255  * instead of potentially buffering multiple messages.
1256  *
1257  * @param client handle to the client
1258  * @return GNUNET_OK on success
1259  */
1260 int
1261 GNUNET_SERVER_client_disable_corking (struct GNUNET_SERVER_Client *client)
1262 {
1263   return GNUNET_CONNECTION_disable_corking (client->connection);
1264 }
1265
1266
1267 /**
1268  * Wrapper for transmission notification that calls the original
1269  * callback and update the last activity time for our connection.
1270  *
1271  * @param cls the 'struct GNUNET_SERVER_Client'
1272  * @param size number of bytes we can transmit
1273  * @param buf where to copy the message
1274  * @return number of bytes actually transmitted
1275  */
1276 static size_t
1277 transmit_ready_callback_wrapper (void *cls, size_t size, void *buf)
1278 {
1279   struct GNUNET_SERVER_Client *client = cls;
1280   size_t ret;
1281
1282   ret = client->callback (client->callback_cls, size, buf);
1283   if (ret > 0)
1284     client->last_activity = GNUNET_TIME_absolute_get ();
1285   return ret;
1286 }
1287
1288
1289 /**
1290  * Notify us when the server has enough space to transmit
1291  * a message of the given size to the given client.
1292  *
1293  * @param client client to transmit message to
1294  * @param size requested amount of buffer space
1295  * @param timeout after how long should we give up (and call
1296  *        notify with buf NULL and size 0)?
1297  * @param callback function to call when space is available
1298  * @param callback_cls closure for callback
1299  * @return non-NULL if the notify callback was queued; can be used
1300  *           to cancel the request using
1301  *           GNUNET_CONNECTION_notify_transmit_ready_cancel.
1302  *         NULL if we are already going to notify someone else (busy)
1303  */
1304 struct GNUNET_CONNECTION_TransmitHandle *
1305 GNUNET_SERVER_notify_transmit_ready (struct GNUNET_SERVER_Client *client,
1306                                      size_t size,
1307                                      struct GNUNET_TIME_Relative timeout,
1308                                      GNUNET_CONNECTION_TransmitReadyNotify
1309                                      callback, void *callback_cls)
1310 {
1311   client->callback_cls = callback_cls;
1312   client->callback = callback;
1313   return GNUNET_CONNECTION_notify_transmit_ready (client->connection, size,
1314                                                   timeout,
1315                                                   &transmit_ready_callback_wrapper,
1316                                                   client);
1317 }
1318
1319
1320 /**
1321  * Set the persistent flag on this client, used to setup client connection
1322  * to only be killed when the service it's connected to is actually dead.
1323  *
1324  * @param client the client to set the persistent flag on
1325  */
1326 void
1327 GNUNET_SERVER_client_persist_ (struct GNUNET_SERVER_Client *client)
1328 {
1329   client->persist = GNUNET_YES;
1330 }
1331
1332
1333 /**
1334  * Resume receiving from this client, we are done processing the
1335  * current request.  This function must be called from within each
1336  * GNUNET_SERVER_MessageCallback (or its respective continuations).
1337  *
1338  * @param client client we were processing a message of
1339  * @param success GNUNET_OK to keep the connection open and
1340  *                          continue to receive
1341  *                GNUNET_NO to close the connection (normal behavior)
1342  *                GNUNET_SYSERR to close the connection (signal
1343  *                          serious error)
1344  */
1345 void
1346 GNUNET_SERVER_receive_done (struct GNUNET_SERVER_Client *client, int success)
1347 {
1348   if (client == NULL)
1349     return;
1350   GNUNET_assert (client->suspended > 0);
1351   client->suspended--;
1352   if (success != GNUNET_OK)
1353   {
1354 #if DEBUG_SERVER
1355     LOG (GNUNET_ERROR_TYPE_DEBUG,
1356          "GNUNET_SERVER_receive_done called with failure indication\n");
1357 #endif
1358     GNUNET_SERVER_client_disconnect (client);
1359     return;
1360   }
1361   if (client->suspended > 0)
1362   {
1363 #if DEBUG_SERVER
1364     LOG (GNUNET_ERROR_TYPE_DEBUG,
1365          "GNUNET_SERVER_receive_done called, but more clients pending\n");
1366 #endif
1367     return;
1368   }
1369   if (GNUNET_SCHEDULER_NO_TASK != client->warn_task)
1370   {
1371     GNUNET_SCHEDULER_cancel (client->warn_task);
1372     client->warn_task = GNUNET_SCHEDULER_NO_TASK;
1373   }
1374   if (client->in_process_client_buffer == GNUNET_YES)
1375   {
1376 #if DEBUG_SERVER
1377     LOG (GNUNET_ERROR_TYPE_DEBUG,
1378          "GNUNET_SERVER_receive_done called while still in processing loop\n");
1379 #endif
1380     return;
1381   }
1382   if ((client->server == NULL) || (GNUNET_YES == client->shutdown_now))
1383   {
1384     GNUNET_SERVER_client_disconnect (client);
1385     return;
1386   }
1387 #if DEBUG_SERVER
1388   LOG (GNUNET_ERROR_TYPE_DEBUG,
1389        "GNUNET_SERVER_receive_done causes restart in reading from the socket\n");
1390 #endif
1391   GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == client->restart_task);
1392   client->restart_task = GNUNET_SCHEDULER_add_now (&restart_processing, client);
1393 }
1394
1395
1396 /**
1397  * Configure this server's connections to continue handling client
1398  * requests as usual even after we get a shutdown signal.  The change
1399  * only applies to clients that connect to the server from the outside
1400  * using TCP after this call.  Clients managed previously or those
1401  * added using GNUNET_SERVER_connect_socket and
1402  * GNUNET_SERVER_connect_callback are not affected by this option.
1403  *
1404  * @param h server handle
1405  * @param do_ignore GNUNET_YES to ignore, GNUNET_NO to restore default
1406  */
1407 void
1408 GNUNET_SERVER_ignore_shutdown (struct GNUNET_SERVER_Handle *h, int do_ignore)
1409 {
1410   h->clients_ignore_shutdown = do_ignore;
1411 }
1412
1413 /* end of server.c */