2 This file is part of GNUnet.
3 (C) 2009, 2010, 2011 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @file core/gnunet-service-core_clients.c
23 * @brief code for managing interactions with clients of core service
24 * @author Christian Grothoff
27 #include "gnunet_util_lib.h"
28 #include "gnunet_statistics_service.h"
29 #include "gnunet_transport_service.h"
30 #include "gnunet-service-core.h"
31 #include "gnunet-service-core_clients.h"
32 #include "gnunet-service-core_sessions.h"
33 #include "gnunet-service-core_typemap.h"
38 * How many messages do we queue up at most for optional
39 * notifications to a client? (this can cause notifications
40 * about outgoing messages to be dropped).
42 #define MAX_NOTIFY_QUEUE 1024
46 * Data structure for each client connected to the CORE service.
51 * Clients are kept in a linked list.
53 struct GSC_Client *next;
56 * Clients are kept in a linked list.
58 struct GSC_Client *prev;
61 * Handle for the client with the server API.
63 struct GNUNET_SERVER_Client *client_handle;
66 * Array of the types of messages this peer cares
67 * about (with @e tcnt entries). Allocated as part
68 * of this client struct, do not free!
70 const uint16_t *types;
73 * Map of peer identities to active transmission requests of this
74 * client to the peer (of type `struct GSC_ClientActiveRequest`).
76 struct GNUNET_CONTAINER_MultiPeerMap *requests;
79 * Map containing all peers that this client knows we're connected to.
81 struct GNUNET_CONTAINER_MultiPeerMap *connectmap;
84 * Options for messages this client cares about,
85 * see GNUNET_CORE_OPTION_ values.
90 * Number of types of incoming messages this client
91 * specifically cares about. Size of the @e types array.
99 * Big "or" of all client options.
101 static uint32_t all_client_options;
104 * Head of linked list of our clients.
106 static struct GSC_Client *client_head;
109 * Tail of linked list of our clients.
111 static struct GSC_Client *client_tail;
114 * Context for notifications we need to send to our clients.
116 static struct GNUNET_SERVER_NotificationContext *notifier;
119 * Tokenizer for messages received from clients.
121 static struct GNUNET_SERVER_MessageStreamTokenizer *client_mst;
125 * Lookup our client struct given the server's client handle.
127 * @param client server client handle to look up
128 * @return our client handle for the client
130 static struct GSC_Client *
131 find_client (struct GNUNET_SERVER_Client *client)
133 struct GSC_Client *c;
136 while ((c != NULL) && (c->client_handle != client))
143 * Send a message to one of our clients.
145 * @param client target for the message
146 * @param msg message to transmit
147 * @param can_drop could this message be dropped if the
148 * client's queue is getting too large?
151 send_to_client (struct GSC_Client *client,
152 const struct GNUNET_MessageHeader *msg, int can_drop)
154 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
155 "Preparing to send %u bytes of message of type %u to client.\n",
156 (unsigned int) ntohs (msg->size),
157 (unsigned int) ntohs (msg->type));
158 GNUNET_SERVER_notification_context_unicast (notifier, client->client_handle,
164 * Send a message to one of our clients.
166 * @param client target for the message
167 * @param msg message to transmit
168 * @param can_drop could this message be dropped if the
169 * client's queue is getting too large?
172 GSC_CLIENTS_send_to_client (struct GNUNET_SERVER_Client *client,
173 const struct GNUNET_MessageHeader *msg,
176 struct GSC_Client *c;
178 c = find_client (client);
184 send_to_client (c, msg, can_drop);
189 * Test if the client is interested in messages of the given type.
191 * @param type message type
192 * @param c client to test
193 * @return #GNUNET_YES if @a c is interested, #GNUNET_NO if not.
196 type_match (uint16_t type, struct GSC_Client *c)
201 return GNUNET_YES; /* peer without handlers matches ALL */
202 for (i = 0; i < c->tcnt; i++)
203 if (type == c->types[i])
210 * Send a message to all of our current clients that have the right
213 * @param partner origin (or destination) of the message (used to check that this peer is
214 * known to be connected to the respective client)
215 * @param msg message to multicast
216 * @param can_drop can this message be discarded if the queue is too long
217 * @param options mask to use
218 * @param type type of the embedded message, 0 for none
221 send_to_all_clients (const struct GNUNET_PeerIdentity *partner,
222 const struct GNUNET_MessageHeader *msg, int can_drop,
223 uint32_t options, uint16_t type)
225 struct GSC_Client *c;
228 for (c = client_head; NULL != c; c = c->next)
230 tm = type_match (type, c);
231 if (! ( (0 != (c->options & options)) ||
232 ( (0 != (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) &&
233 (GNUNET_YES == tm) ) ) )
234 continue; /* neither options nor type match permit the message */
235 if ( (0 != (options & GNUNET_CORE_OPTION_SEND_HDR_INBOUND)) &&
236 ( (0 != (c->options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) ||
237 (GNUNET_YES == tm) ) )
239 if ( (0 != (options & GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND)) &&
240 (0 != (c->options & GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND)) )
242 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
243 "Sending %u message with %u bytes to client interested in messages of type %u.\n",
246 (unsigned int) type);
247 GNUNET_assert ( (0 == (c->options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) ||
248 (GNUNET_YES != tm) ||
250 GNUNET_CONTAINER_multipeermap_contains (c->connectmap,
252 send_to_client (c, msg, can_drop);
258 * Handle CORE_INIT request.
261 * @param client new client that sent INIT
262 * @param message the `struct InitMessage` (presumably)
265 handle_client_init (void *cls,
266 struct GNUNET_SERVER_Client *client,
267 const struct GNUNET_MessageHeader *message)
269 const struct InitMessage *im;
270 struct InitReplyMessage irm;
271 struct GSC_Client *c;
273 const uint16_t *types;
277 /* check that we don't have an entry already */
278 c = find_client (client);
282 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
285 msize = ntohs (message->size);
286 if (msize < sizeof (struct InitMessage))
289 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
292 GNUNET_SERVER_notification_context_add (notifier, client);
293 im = (const struct InitMessage *) message;
294 types = (const uint16_t *) &im[1];
295 msize -= sizeof (struct InitMessage);
296 c = GNUNET_malloc (sizeof (struct GSC_Client) + msize);
297 c->client_handle = client;
298 c->tcnt = msize / sizeof (uint16_t);
299 c->options = ntohl (im->options);
300 all_client_options |= c->options;
301 c->types = (const uint16_t *) &c[1];
302 c->connectmap = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_NO);
303 GNUNET_assert (GNUNET_YES ==
304 GNUNET_CONTAINER_multipeermap_put (c->connectmap,
307 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
308 wtypes = (uint16_t *) & c[1];
309 for (i = 0; i < c->tcnt; i++)
310 wtypes[i] = ntohs (types[i]);
311 GSC_TYPEMAP_add (wtypes, c->tcnt);
312 GNUNET_CONTAINER_DLL_insert (client_head, client_tail, c);
313 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
314 "Client connecting to core service is interested in %u message types\n",
315 (unsigned int) c->tcnt);
316 /* send init reply message */
317 irm.header.size = htons (sizeof (struct InitReplyMessage));
318 irm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY);
319 irm.reserved = htonl (0);
320 irm.my_identity = GSC_my_identity;
321 send_to_client (c, &irm.header, GNUNET_NO);
322 GSC_SESSIONS_notify_client_about_sessions (c);
323 GNUNET_SERVER_receive_done (client, GNUNET_OK);
328 * Handle CORE_SEND_REQUEST message.
331 * @param client new client that sent CORE_SEND_REQUEST
332 * @param message the `struct SendMessageRequest` (presumably)
335 handle_client_send_request (void *cls,
336 struct GNUNET_SERVER_Client *client,
337 const struct GNUNET_MessageHeader *message)
339 const struct SendMessageRequest *req;
340 struct GSC_Client *c;
341 struct GSC_ClientActiveRequest *car;
344 req = (const struct SendMessageRequest *) message;
345 c = find_client (client);
348 /* client did not send INIT first! */
350 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
353 if (c->requests == NULL)
354 c->requests = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_NO);
355 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
356 "Client asked for transmission to `%s'\n",
357 GNUNET_i2s (&req->peer));
360 memcmp (&req->peer, &GSC_my_identity,
361 sizeof (struct GNUNET_PeerIdentity)));
362 if ((!is_loopback) &&
364 GNUNET_CONTAINER_multipeermap_contains (c->connectmap,
367 /* neighbour must have disconnected since request was issued,
368 * ignore (client will realize it once it processes the
369 * disconnect notification) */
370 GNUNET_STATISTICS_update (GSC_stats,
372 ("# send requests dropped (disconnected)"), 1,
374 GNUNET_SERVER_receive_done (client, GNUNET_OK);
378 car = GNUNET_CONTAINER_multipeermap_get (c->requests, &req->peer);
381 /* create new entry */
382 car = GNUNET_new (struct GSC_ClientActiveRequest);
383 GNUNET_assert (GNUNET_OK ==
384 GNUNET_CONTAINER_multipeermap_put (c->requests,
387 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
388 car->client_handle = c;
392 GSC_SESSIONS_dequeue_request (car);
394 car->target = req->peer;
395 car->deadline = GNUNET_TIME_absolute_ntoh (req->deadline);
396 car->priority = (enum GNUNET_CORE_Priority) ntohl (req->priority);
397 car->msize = ntohs (req->size);
398 car->smr_id = req->smr_id;
399 car->was_solicited = GNUNET_NO;
402 /* loopback, satisfy immediately */
403 GSC_CLIENTS_solicit_request (car);
404 GNUNET_SERVER_receive_done (client, GNUNET_OK);
407 GSC_SESSIONS_queue_request (car);
408 GNUNET_SERVER_receive_done (client, GNUNET_OK);
413 * Closure for the #client_tokenizer_callback().
415 struct TokenizerContext
419 * Active request handle for the message.
421 struct GSC_ClientActiveRequest *car;
424 * How important is this message.
426 enum GNUNET_CORE_Priority priority;
429 * Is corking allowed (set only once we have the real message).
437 * Handle CORE_SEND request.
440 * @param client the client issuing the request
441 * @param message the `struct SendMessage`
444 handle_client_send (void *cls,
445 struct GNUNET_SERVER_Client *client,
446 const struct GNUNET_MessageHeader *message)
448 const struct SendMessage *sm;
449 struct GSC_Client *c;
450 struct TokenizerContext tc;
453 msize = ntohs (message->size);
455 sizeof (struct SendMessage) + sizeof (struct GNUNET_MessageHeader))
458 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
461 sm = (const struct SendMessage *) message;
462 msize -= sizeof (struct SendMessage);
463 GNUNET_break (0 == ntohl (sm->reserved));
464 c = find_client (client);
467 /* client did not send INIT first! */
469 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
473 GNUNET_CONTAINER_multipeermap_get (c->requests, &sm->peer);
476 /* Must have been that we first approved the request, then got disconnected
477 * (which triggered removal of the 'car') and now the client gives us a message
478 * just *before* the client learns about the disconnect. Theoretically, we
479 * might also now be *again* connected. So this can happen (but should be
480 * rare). If it does happen, the message is discarded. */
481 GNUNET_STATISTICS_update (GSC_stats,
483 ("# messages discarded (session disconnected)"),
485 GNUNET_SERVER_receive_done (client, GNUNET_OK);
488 GNUNET_assert (GNUNET_YES ==
489 GNUNET_CONTAINER_multipeermap_remove (c->requests,
492 tc.cork = ntohl (sm->cork);
493 tc.priority = (enum GNUNET_CORE_Priority) ntohl (sm->priority);
494 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
495 "Client asked for transmission of %u bytes to `%s' %s\n",
497 GNUNET_i2s (&sm->peer), tc.cork ? "now" : "");
498 GNUNET_SERVER_mst_receive (client_mst, &tc,
499 (const char *) &sm[1], msize,
500 GNUNET_YES, GNUNET_NO);
502 memcmp (&tc.car->target, &GSC_my_identity,
503 sizeof (struct GNUNET_PeerIdentity)))
504 GSC_SESSIONS_dequeue_request (tc.car);
505 GNUNET_free (tc.car);
506 GNUNET_SERVER_receive_done (client, GNUNET_OK);
511 * Functions with this signature are called whenever a complete
512 * message is received by the tokenizer. Used by the 'client_mst' for
513 * dispatching messages from clients to either the SESSION subsystem
514 * or other CLIENT (for loopback).
517 * @param client reservation request (`struct GSC_ClientActiveRequest`)
518 * @param message the actual message
521 client_tokenizer_callback (void *cls, void *client,
522 const struct GNUNET_MessageHeader *message)
524 struct TokenizerContext *tc = client;
525 struct GSC_ClientActiveRequest *car = tc->car;
528 GNUNET_snprintf (buf, sizeof (buf),
529 gettext_noop ("# bytes of messages of type %u received"),
530 (unsigned int) ntohs (message->type));
531 GNUNET_STATISTICS_update (GSC_stats, buf, ntohs (message->size), GNUNET_NO);
533 memcmp (&car->target, &GSC_my_identity,
534 sizeof (struct GNUNET_PeerIdentity)))
536 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
537 "Delivering message of type %u to myself\n",
538 ntohs (message->type));
539 GSC_CLIENTS_deliver_message (&GSC_my_identity, message,
540 ntohs (message->size),
541 GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND);
542 GSC_CLIENTS_deliver_message (&GSC_my_identity, message,
543 sizeof (struct GNUNET_MessageHeader),
544 GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND);
545 GSC_CLIENTS_deliver_message (&GSC_my_identity, message,
546 ntohs (message->size),
547 GNUNET_CORE_OPTION_SEND_FULL_INBOUND);
548 GSC_CLIENTS_deliver_message (&GSC_my_identity, message,
549 sizeof (struct GNUNET_MessageHeader),
550 GNUNET_CORE_OPTION_SEND_HDR_INBOUND);
554 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
555 "Delivering message of type %u to %s\n",
556 ntohs (message->type),
557 GNUNET_i2s (&car->target));
558 GSC_CLIENTS_deliver_message (&car->target, message,
559 ntohs (message->size),
560 GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND);
561 GSC_CLIENTS_deliver_message (&car->target, message,
562 sizeof (struct GNUNET_MessageHeader),
563 GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND);
564 GSC_SESSIONS_transmit (car,
574 * Free client request records.
577 * @param key identity of peer for which this is an active request
578 * @param value the `struct GSC_ClientActiveRequest` to free
579 * @return #GNUNET_YES (continue iteration)
582 destroy_active_client_request (void *cls,
583 const struct GNUNET_PeerIdentity *key,
586 struct GSC_ClientActiveRequest *car = value;
588 GNUNET_assert (GNUNET_YES ==
589 GNUNET_CONTAINER_multipeermap_remove (car->
590 client_handle->requests,
593 GSC_SESSIONS_dequeue_request (car);
600 * A client disconnected, clean up.
603 * @param client identification of the client
606 handle_client_disconnect (void *cls,
607 struct GNUNET_SERVER_Client *client)
609 struct GSC_Client *c;
613 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
614 "Client %p has disconnected from core service.\n", client);
615 c = find_client (client);
617 return; /* client never sent INIT */
618 GNUNET_CONTAINER_DLL_remove (client_head, client_tail, c);
619 if (c->requests != NULL)
621 GNUNET_CONTAINER_multipeermap_iterate (c->requests,
622 &destroy_active_client_request,
624 GNUNET_CONTAINER_multipeermap_destroy (c->requests);
626 GNUNET_CONTAINER_multipeermap_destroy (c->connectmap);
627 c->connectmap = NULL;
628 GSC_TYPEMAP_remove (c->types, c->tcnt);
631 /* recalculate 'all_client_options' */
632 all_client_options = 0;
633 for (c = client_head; NULL != c ; c = c->next)
634 all_client_options |= c->options;
639 * Tell a client that we are ready to receive the message.
641 * @param car request that is now ready; the responsibility
642 * for the handle remains shared between CLIENTS
643 * and SESSIONS after this call.
646 GSC_CLIENTS_solicit_request (struct GSC_ClientActiveRequest *car)
648 struct GSC_Client *c;
649 struct SendMessageReady smr;
651 c = car->client_handle;
653 GNUNET_CONTAINER_multipeermap_contains (c->connectmap,
656 /* connection has gone down since, drop request */
658 memcmp (&car->target, &GSC_my_identity,
659 sizeof (struct GNUNET_PeerIdentity)));
660 GSC_SESSIONS_dequeue_request (car);
661 GSC_CLIENTS_reject_request (car);
664 smr.header.size = htons (sizeof (struct SendMessageReady));
665 smr.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SEND_READY);
666 smr.size = htons (car->msize);
667 smr.smr_id = car->smr_id;
668 smr.peer = car->target;
669 send_to_client (c, &smr.header, GNUNET_NO);
674 * Tell a client that we will never be ready to receive the
675 * given message in time (disconnect or timeout).
677 * @param car request that now permanently failed; the
678 * responsibility for the handle is now returned
679 * to CLIENTS (SESSIONS is done with it).
682 GSC_CLIENTS_reject_request (struct GSC_ClientActiveRequest *car)
684 GNUNET_assert (GNUNET_YES ==
685 GNUNET_CONTAINER_multipeermap_remove (car->
686 client_handle->requests,
694 * Notify a particular client about a change to existing connection to
695 * one of our neighbours (check if the client is interested). Called
696 * from 'GSC_SESSIONS_notify_client_about_sessions'.
698 * @param client client to notify
699 * @param neighbour identity of the neighbour that changed status
700 * @param tmap_old previous type map for the neighbour, NULL for connect
701 * @param tmap_new updated type map for the neighbour, NULL for disconnect
704 GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client,
705 const struct GNUNET_PeerIdentity *neighbour,
706 const struct GSC_TypeMap *tmap_old,
707 const struct GSC_TypeMap *tmap_new)
709 struct ConnectNotifyMessage *cnm;
711 char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1] GNUNET_ALIGN;
712 struct DisconnectNotifyMessage dcm;
716 old_match = GSC_TYPEMAP_test_match (tmap_old, client->types, client->tcnt);
717 new_match = GSC_TYPEMAP_test_match (tmap_new, client->types, client->tcnt);
718 if (old_match == new_match)
720 GNUNET_assert (old_match ==
721 GNUNET_CONTAINER_multipeermap_contains (client->connectmap,
723 return; /* no change */
725 if (old_match == GNUNET_NO)
728 GNUNET_assert (GNUNET_NO ==
729 GNUNET_CONTAINER_multipeermap_contains (client->connectmap,
731 GNUNET_assert (GNUNET_YES ==
732 GNUNET_CONTAINER_multipeermap_put (client->connectmap,
735 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
736 size = sizeof (struct ConnectNotifyMessage);
737 cnm = (struct ConnectNotifyMessage *) buf;
738 cnm->header.size = htons (size);
739 cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT);
740 cnm->reserved = htonl (0);
741 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
742 "Sending `%s' message to client.\n",
744 cnm->peer = *neighbour;
745 send_to_client (client, &cnm->header, GNUNET_NO);
749 /* send disconnect */
750 GNUNET_assert (GNUNET_YES ==
751 GNUNET_CONTAINER_multipeermap_contains (client->connectmap,
753 GNUNET_assert (GNUNET_YES ==
754 GNUNET_CONTAINER_multipeermap_remove (client->connectmap,
757 dcm.header.size = htons (sizeof (struct DisconnectNotifyMessage));
758 dcm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT);
759 dcm.reserved = htonl (0);
760 dcm.peer = *neighbour;
761 send_to_client (client, &dcm.header, GNUNET_NO);
767 * Notify all clients about a change to existing session.
768 * Called from SESSIONS whenever there is a change in sessions
769 * or types processed by the respective peer.
771 * @param neighbour identity of the neighbour that changed status
772 * @param tmap_old previous type map for the neighbour, NULL for connect
773 * @param tmap_new updated type map for the neighbour, NULL for disconnect
776 GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity *neighbour,
777 const struct GSC_TypeMap *tmap_old,
778 const struct GSC_TypeMap *tmap_new)
780 struct GSC_Client *c;
782 for (c = client_head; NULL != c; c = c->next)
783 GSC_CLIENTS_notify_client_about_neighbour (c, neighbour,
789 * Deliver P2P message to interested clients. Caller must have checked
790 * that the sending peer actually lists the given message type as one
793 * @param sender peer who sent us the message
794 * @param msg the message
795 * @param msize number of bytes to transmit
796 * @param options options for checking which clients should
797 * receive the message
800 GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender,
801 const struct GNUNET_MessageHeader *msg,
805 size_t size = msize + sizeof (struct NotifyTrafficMessage);
806 char buf[size] GNUNET_ALIGN;
807 struct NotifyTrafficMessage *ntm;
809 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
812 /* recovery strategy: throw performance data away... */
813 size = msize + sizeof (struct NotifyTrafficMessage);
815 if (! ( (0 != (all_client_options & options)) ||
816 (0 != (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) ))
817 return; /* no client cares about this message notification */
818 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
819 "Core service passes message from `%4s' of type %u to client.\n",
820 GNUNET_i2s (sender), (unsigned int) ntohs (msg->type));
821 GSC_SESSIONS_add_to_typemap (sender, ntohs (msg->type));
822 ntm = (struct NotifyTrafficMessage *) buf;
823 ntm->header.size = htons (size);
824 if (0 != (options & (GNUNET_CORE_OPTION_SEND_FULL_INBOUND | GNUNET_CORE_OPTION_SEND_HDR_INBOUND)))
825 ntm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND);
827 ntm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND);
829 memcpy (&ntm[1], msg, msize);
830 send_to_all_clients (sender, &ntm->header, GNUNET_YES, options,
836 * Initialize clients subsystem.
838 * @param server handle to server clients connect to
841 GSC_CLIENTS_init (struct GNUNET_SERVER_Handle *server)
843 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
844 {&handle_client_init, NULL,
845 GNUNET_MESSAGE_TYPE_CORE_INIT, 0},
846 {&GSC_KX_handle_client_monitor_peers, NULL,
847 GNUNET_MESSAGE_TYPE_CORE_MONITOR_PEERS,
848 sizeof (struct GNUNET_MessageHeader)},
849 {&handle_client_send_request, NULL,
850 GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST,
851 sizeof (struct SendMessageRequest)},
852 {&handle_client_send, NULL,
853 GNUNET_MESSAGE_TYPE_CORE_SEND, 0},
857 /* setup notification */
858 client_mst = GNUNET_SERVER_mst_create (&client_tokenizer_callback, NULL);
860 GNUNET_SERVER_notification_context_create (server, MAX_NOTIFY_QUEUE);
861 GNUNET_SERVER_disconnect_notify (server,
862 &handle_client_disconnect, NULL);
863 GNUNET_SERVER_add_handlers (server, handlers);
868 * Shutdown clients subsystem.
873 struct GSC_Client *c;
875 while (NULL != (c = client_head))
876 handle_client_disconnect (NULL, c->client_handle);
877 if (NULL != notifier)
879 GNUNET_SERVER_notification_context_destroy (notifier);
882 if (NULL != client_mst)
884 GNUNET_SERVER_mst_destroy (client_mst);
889 /* end of gnunet-service-core_clients.c */