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 "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_MultiHashMap *requests;
79 * Map containing all peers that this client knows we're connected to.
81 struct GNUNET_CONTAINER_MultiHashMap *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 "types" array.
99 * Head of linked list of our clients.
101 static struct GSC_Client *client_head;
104 * Tail of linked list of our clients.
106 static struct GSC_Client *client_tail;
109 * Context for notifications we need to send to our clients.
111 static struct GNUNET_SERVER_NotificationContext *notifier;
114 * Tokenizer for messages received from clients.
116 static struct GNUNET_SERVER_MessageStreamTokenizer *client_mst;
120 * Lookup our client struct given the server's client handle.
122 * @param client server client handle to look up
123 * @return our client handle for the client
125 static struct GSC_Client *
126 find_client (struct GNUNET_SERVER_Client *client)
128 struct GSC_Client *c;
131 while ((c != NULL) && (c->client_handle != client))
138 * Send a message to one of our clients.
140 * @param client target for the message
141 * @param msg message to transmit
142 * @param can_drop could this message be dropped if the
143 * client's queue is getting too large?
146 send_to_client (struct GSC_Client *client,
147 const struct GNUNET_MessageHeader *msg, int can_drop)
150 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
151 "Preparing to send %u bytes of message of type %u to client.\n",
152 (unsigned int) ntohs (msg->size),
153 (unsigned int) ntohs (msg->type));
155 GNUNET_SERVER_notification_context_unicast (notifier, client->client_handle,
161 * Send a message to one of our clients.
163 * @param client target for the message
164 * @param msg message to transmit
165 * @param can_drop could this message be dropped if the
166 * client's queue is getting too large?
169 GSC_CLIENTS_send_to_client (struct GNUNET_SERVER_Client *client,
170 const struct GNUNET_MessageHeader *msg,
173 struct GSC_Client *c;
175 c = find_client (client);
181 send_to_client (c, msg, can_drop);
186 * Test if the client is interested in messages of the given type.
188 * @param type message type
189 * @param c client to test
190 * @return GNUNET_YES if 'c' is interested, GNUNET_NO if not.
193 type_match (uint16_t type, struct GSC_Client *c)
198 return GNUNET_YES; /* peer without handlers matches ALL */
199 for (i = 0; i < c->tcnt; i++)
200 if (type == c->types[i])
207 * Send a message to all of our current clients that have the right
210 * @param sender origin of the message (used to check that this peer is
211 * known to be connected to the respective client)
212 * @param msg message to multicast
213 * @param can_drop can this message be discarded if the queue is too long
214 * @param options mask to use
215 * @param type type of the embedded message, 0 for none
218 send_to_all_clients (const struct GNUNET_PeerIdentity *sender,
219 const struct GNUNET_MessageHeader *msg, int can_drop,
220 int options, uint16_t type)
222 struct GSC_Client *c;
224 for (c = client_head; c != NULL; c = c->next)
226 if ((0 == (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) &&
227 (GNUNET_YES == type_match (type, c)))
228 continue; /* not the full message, but we'd like the full one! */
229 if ((0 == (c->options & options)) && (GNUNET_YES != type_match (type, c)))
230 continue; /* neither options nor type match permit the message */
232 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
233 "Sending message to client interested in messages of type %u.\n",
234 (unsigned int) type);
236 GNUNET_assert (GNUNET_YES ==
237 GNUNET_CONTAINER_multihashmap_contains (c->connectmap,
238 &sender->hashPubKey));
239 send_to_client (c, msg, can_drop);
245 * Handle CORE_INIT request.
248 * @param client new client that sent INIT
249 * @param message the 'struct InitMessage' (presumably)
252 handle_client_init (void *cls, struct GNUNET_SERVER_Client *client,
253 const struct GNUNET_MessageHeader *message)
255 const struct InitMessage *im;
256 struct InitReplyMessage irm;
257 struct GSC_Client *c;
259 const uint16_t *types;
263 /* check that we don't have an entry already */
264 c = find_client (client);
268 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
271 msize = ntohs (message->size);
272 if (msize < sizeof (struct InitMessage))
275 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
278 GNUNET_SERVER_notification_context_add (notifier, client);
279 im = (const struct InitMessage *) message;
280 types = (const uint16_t *) &im[1];
281 msize -= sizeof (struct InitMessage);
282 c = GNUNET_malloc (sizeof (struct GSC_Client) + msize);
283 c->client_handle = client;
284 c->tcnt = msize / sizeof (uint16_t);
285 c->options = ntohl (im->options);
286 c->types = (const uint16_t *) &c[1];
287 c->connectmap = GNUNET_CONTAINER_multihashmap_create (16);
288 GNUNET_assert (GNUNET_YES ==
289 GNUNET_CONTAINER_multihashmap_put (c->connectmap,
290 &GSC_my_identity.hashPubKey,
292 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
293 wtypes = (uint16_t *) & c[1];
294 for (i = 0; i < c->tcnt; i++)
295 wtypes[i] = ntohs (types[i]);
296 GSC_TYPEMAP_add (wtypes, c->tcnt);
297 GNUNET_CONTAINER_DLL_insert (client_head, client_tail, c);
299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
300 "Client connecting to core service is interested in %u message types\n",
301 (unsigned int) c->tcnt);
303 /* send init reply message */
304 irm.header.size = htons (sizeof (struct InitReplyMessage));
305 irm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY);
306 irm.reserved = htonl (0);
307 irm.my_identity = GSC_my_identity;
308 send_to_client (c, &irm.header, GNUNET_NO);
309 GSC_SESSIONS_notify_client_about_sessions (c);
310 GNUNET_SERVER_receive_done (client, GNUNET_OK);
315 * Handle CORE_SEND_REQUEST message.
318 * @param client new client that sent CORE_SEND_REQUEST
319 * @param message the 'struct SendMessageRequest' (presumably)
322 handle_client_send_request (void *cls, struct GNUNET_SERVER_Client *client,
323 const struct GNUNET_MessageHeader *message)
325 const struct SendMessageRequest *req;
326 struct GSC_Client *c;
327 struct GSC_ClientActiveRequest *car;
330 req = (const struct SendMessageRequest *) message;
331 c = find_client (client);
334 /* client did not send INIT first! */
336 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
339 if (c->requests == NULL)
340 c->requests = GNUNET_CONTAINER_multihashmap_create (16);
342 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
343 "Client asked for transmission to `%s'\n",
344 GNUNET_i2s (&req->peer));
348 memcmp (&req->peer, &GSC_my_identity,
349 sizeof (struct GNUNET_PeerIdentity)));
350 if ((!is_loopback) &&
352 GNUNET_CONTAINER_multihashmap_contains (c->connectmap,
353 &req->peer.hashPubKey)))
355 /* neighbour must have disconnected since request was issued,
356 * ignore (client will realize it once it processes the
357 * disconnect notification) */
358 GNUNET_STATISTICS_update (GSC_stats,
360 ("# send requests dropped (disconnected)"), 1,
362 GNUNET_SERVER_receive_done (client, GNUNET_OK);
366 car = GNUNET_CONTAINER_multihashmap_get (c->requests, &req->peer.hashPubKey);
369 /* create new entry */
370 car = GNUNET_malloc (sizeof (struct GSC_ClientActiveRequest));
371 GNUNET_assert (GNUNET_OK ==
372 GNUNET_CONTAINER_multihashmap_put (c->requests,
373 &req->peer.hashPubKey,
375 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
376 car->client_handle = c;
380 GSC_SESSIONS_dequeue_request (car);
382 car->target = req->peer;
383 car->deadline = GNUNET_TIME_absolute_ntoh (req->deadline);
384 car->priority = ntohl (req->priority);
385 car->msize = ntohs (req->size);
386 car->smr_id = req->smr_id;
387 car->was_solicited = GNUNET_NO;
390 /* loopback, satisfy immediately */
391 GSC_CLIENTS_solicit_request (car);
392 GNUNET_SERVER_receive_done (client, GNUNET_OK);
395 GSC_SESSIONS_queue_request (car);
396 GNUNET_SERVER_receive_done (client, GNUNET_OK);
401 * Closure for the 'client_tokenizer_callback'.
403 struct TokenizerContext
407 * Active request handle for the message.
409 struct GSC_ClientActiveRequest *car;
412 * Is corking allowed (set only once we have the real message).
420 * Handle CORE_SEND request.
423 * @param client the client issuing the request
424 * @param message the "struct SendMessage"
427 handle_client_send (void *cls, struct GNUNET_SERVER_Client *client,
428 const struct GNUNET_MessageHeader *message)
430 const struct SendMessage *sm;
431 struct GSC_Client *c;
432 struct TokenizerContext tc;
435 msize = ntohs (message->size);
437 sizeof (struct SendMessage) + sizeof (struct GNUNET_MessageHeader))
440 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
443 sm = (const struct SendMessage *) message;
444 msize -= sizeof (struct SendMessage);
445 GNUNET_break (0 == ntohl (sm->reserved));
446 c = find_client (client);
449 /* client did not send INIT first! */
451 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
455 GNUNET_CONTAINER_multihashmap_get (c->requests, &sm->peer.hashPubKey);
458 /* Must have been that we first approved the request, then got disconnected
459 * (which triggered removal of the 'car') and now the client gives us a message
460 * just *before* the client learns about the disconnect. Theoretically, we
461 * might also now be *again* connected. So this can happen (but should be
462 * rare). If it does happen, the message is discarded. */
463 GNUNET_STATISTICS_update (GSC_stats,
465 ("# messages discarded (session disconnected)"),
467 GNUNET_SERVER_receive_done (client, GNUNET_OK);
470 GNUNET_assert (GNUNET_YES ==
471 GNUNET_CONTAINER_multihashmap_remove (c->requests,
472 &sm->peer.hashPubKey,
474 tc.cork = ntohl (sm->cork);
476 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
477 "Client asked for transmission of %u bytes to `%s' %s\n", msize,
478 GNUNET_i2s (&sm->peer), tc.cork ? "now" : "");
480 GNUNET_SERVER_mst_receive (client_mst, &tc, (const char *) &sm[1], msize,
481 GNUNET_YES, GNUNET_NO);
483 memcmp (&tc.car->target, &GSC_my_identity,
484 sizeof (struct GNUNET_PeerIdentity)))
485 GSC_SESSIONS_dequeue_request (tc.car);
486 GNUNET_free (tc.car);
487 GNUNET_SERVER_receive_done (client, GNUNET_OK);
492 * Functions with this signature are called whenever a complete
493 * message is received by the tokenizer. Used by the 'client_mst' for
494 * dispatching messages from clients to either the SESSION subsystem
495 * or other CLIENT (for loopback).
498 * @param client reservation request ('struct GSC_ClientActiveRequest')
499 * @param message the actual message
502 client_tokenizer_callback (void *cls, void *client,
503 const struct GNUNET_MessageHeader *message)
505 struct TokenizerContext *tc = client;
506 struct GSC_ClientActiveRequest *car = tc->car;
509 memcmp (&car->target, &GSC_my_identity,
510 sizeof (struct GNUNET_PeerIdentity)))
513 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
514 "Delivering message of type %u to myself\n",
515 ntohs (message->type));
517 GSC_CLIENTS_deliver_message (&GSC_my_identity, NULL, 0, message,
518 ntohs (message->size),
519 GNUNET_CORE_OPTION_SEND_FULL_INBOUND |
520 GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND);
521 GSC_CLIENTS_deliver_message (&GSC_my_identity, NULL, 0, message,
522 sizeof (struct GNUNET_MessageHeader),
523 GNUNET_CORE_OPTION_SEND_HDR_INBOUND |
524 GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND);
529 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
530 "Delivering message of type %u to %s\n", ntohs (message->type),
531 GNUNET_i2s (&car->target));
533 GSC_SESSIONS_transmit (car, message, tc->cork);
539 * Free client request records.
542 * @param key identity of peer for which this is an active request
543 * @param value the 'struct GSC_ClientActiveRequest' to free
544 * @return GNUNET_YES (continue iteration)
547 destroy_active_client_request (void *cls, const GNUNET_HashCode * key,
550 struct GSC_ClientActiveRequest *car = value;
552 GNUNET_assert (GNUNET_YES ==
553 GNUNET_CONTAINER_multihashmap_remove (car->
554 client_handle->requests,
555 &car->target.hashPubKey,
557 GSC_SESSIONS_dequeue_request (car);
564 * A client disconnected, clean up.
567 * @param client identification of the client
570 handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
572 struct GSC_Client *c;
577 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
578 "Client %p has disconnected from core service.\n", client);
580 c = find_client (client);
582 return; /* client never sent INIT */
583 GNUNET_CONTAINER_DLL_remove (client_head, client_tail, c);
584 if (c->requests != NULL)
586 GNUNET_CONTAINER_multihashmap_iterate (c->requests,
587 &destroy_active_client_request,
589 GNUNET_CONTAINER_multihashmap_destroy (c->requests);
591 GNUNET_CONTAINER_multihashmap_destroy (c->connectmap);
592 c->connectmap = NULL;
593 GSC_TYPEMAP_remove (c->types, c->tcnt);
599 * Tell a client that we are ready to receive the message.
601 * @param car request that is now ready; the responsibility
602 * for the handle remains shared between CLIENTS
603 * and SESSIONS after this call.
606 GSC_CLIENTS_solicit_request (struct GSC_ClientActiveRequest *car)
608 struct GSC_Client *c;
609 struct SendMessageReady smr;
611 c = car->client_handle;
613 GNUNET_CONTAINER_multihashmap_contains (c->connectmap,
614 &car->target.hashPubKey))
616 /* connection has gone down since, drop request */
618 memcmp (&car->target, &GSC_my_identity,
619 sizeof (struct GNUNET_PeerIdentity)));
620 GSC_SESSIONS_dequeue_request (car);
621 GSC_CLIENTS_reject_request (car);
624 smr.header.size = htons (sizeof (struct SendMessageReady));
625 smr.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SEND_READY);
626 smr.size = htons (car->msize);
627 smr.smr_id = car->smr_id;
628 smr.peer = car->target;
629 send_to_client (c, &smr.header, GNUNET_NO);
634 * Tell a client that we will never be ready to receive the
635 * given message in time (disconnect or timeout).
637 * @param car request that now permanently failed; the
638 * responsibility for the handle is now returned
639 * to CLIENTS (SESSIONS is done with it).
642 GSC_CLIENTS_reject_request (struct GSC_ClientActiveRequest *car)
644 GNUNET_assert (GNUNET_YES ==
645 GNUNET_CONTAINER_multihashmap_remove (car->
646 client_handle->requests,
647 &car->target.hashPubKey,
654 * Notify a particular client about a change to existing connection to
655 * one of our neighbours (check if the client is interested). Called
656 * from 'GSC_SESSIONS_notify_client_about_sessions'.
658 * @param client client to notify
659 * @param neighbour identity of the neighbour that changed status
660 * @param atsi performance information about neighbour
661 * @param atsi_count number of entries in 'ats' array
662 * @param tmap_old previous type map for the neighbour, NULL for disconnect
663 * @param tmap_new updated type map for the neighbour, NULL for disconnect
666 GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client,
667 const struct GNUNET_PeerIdentity
669 const struct GNUNET_ATS_Information
670 *atsi, unsigned int atsi_count,
671 const struct GSC_TypeMap *tmap_old,
672 const struct GSC_TypeMap *tmap_new)
674 struct ConnectNotifyMessage *cnm;
676 char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
677 struct GNUNET_ATS_Information *a;
678 struct DisconnectNotifyMessage dcm;
682 old_match = GSC_TYPEMAP_test_match (tmap_old, client->types, client->tcnt);
683 new_match = GSC_TYPEMAP_test_match (tmap_new, client->types, client->tcnt);
684 if (old_match == new_match)
686 GNUNET_assert (old_match ==
687 GNUNET_CONTAINER_multihashmap_contains (client->connectmap,
688 &neighbour->hashPubKey));
689 return; /* no change */
691 if (old_match == GNUNET_NO)
694 GNUNET_assert (GNUNET_NO ==
695 GNUNET_CONTAINER_multihashmap_contains (client->connectmap,
696 &neighbour->hashPubKey));
697 GNUNET_assert (GNUNET_YES ==
698 GNUNET_CONTAINER_multihashmap_put (client->connectmap,
699 &neighbour->hashPubKey,
701 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
703 sizeof (struct ConnectNotifyMessage) +
704 (atsi_count) * sizeof (struct GNUNET_ATS_Information);
705 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
708 /* recovery strategy: throw away performance data */
710 size = sizeof (struct ConnectNotifyMessage);
712 cnm = (struct ConnectNotifyMessage *) buf;
713 cnm->header.size = htons (size);
714 cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT);
715 cnm->ats_count = htonl (atsi_count);
716 a = (struct GNUNET_ATS_Information *) &cnm[1];
717 memcpy (a, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count);
719 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message to client.\n",
722 cnm->peer = *neighbour;
723 send_to_client (client, &cnm->header, GNUNET_NO);
727 /* send disconnect */
728 GNUNET_assert (GNUNET_YES ==
729 GNUNET_CONTAINER_multihashmap_contains (client->connectmap,
730 &neighbour->hashPubKey));
731 GNUNET_assert (GNUNET_YES ==
732 GNUNET_CONTAINER_multihashmap_remove (client->connectmap,
733 &neighbour->hashPubKey,
735 dcm.header.size = htons (sizeof (struct DisconnectNotifyMessage));
736 dcm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT);
737 dcm.reserved = htonl (0);
738 dcm.peer = *neighbour;
739 send_to_client (client, &dcm.header, GNUNET_NO);
745 * Notify all clients about a change to existing session.
746 * Called from SESSIONS whenever there is a change in sessions
747 * or types processed by the respective peer.
749 * @param neighbour identity of the neighbour that changed status
750 * @param atsi performance information about neighbour
751 * @param atsi_count number of entries in 'ats' array
752 * @param tmap_old previous type map for the neighbour, NULL for disconnect
753 * @param tmap_new updated type map for the neighbour, NULL for disconnect
756 GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity
758 const struct GNUNET_ATS_Information
759 *atsi, unsigned int atsi_count,
760 const struct GSC_TypeMap *tmap_old,
761 const struct GSC_TypeMap *tmap_new)
763 struct GSC_Client *c;
765 for (c = client_head; c != NULL; c = c->next)
766 GSC_CLIENTS_notify_client_about_neighbour (c, neighbour, atsi, atsi_count,
772 * Deliver P2P message to interested clients. Caller must have checked
773 * that the sending peer actually lists the given message type as one
776 * @param sender peer who sent us the message
777 * @param atsi performance information about neighbour
778 * @param atsi_count number of entries in 'ats' array
779 * @param msg the message
780 * @param msize number of bytes to transmit
781 * @param options options for checking which clients should
782 * receive the message
785 GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender,
786 const struct GNUNET_ATS_Information *atsi,
787 unsigned int atsi_count,
788 const struct GNUNET_MessageHeader *msg,
789 uint16_t msize, int options)
792 msize + sizeof (struct NotifyTrafficMessage) +
793 atsi_count * sizeof (struct GNUNET_ATS_Information);
795 struct NotifyTrafficMessage *ntm;
796 struct GNUNET_ATS_Information *a;
800 GNUNET_snprintf (buf, sizeof (buf),
801 gettext_noop ("# bytes of messages of type %u received"),
802 (unsigned int) ntohs (msg->type));
803 GNUNET_STATISTICS_update (GSC_stats, buf, msize, GNUNET_NO);
805 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
808 /* recovery strategy: throw performance data away... */
810 size = msize + sizeof (struct NotifyTrafficMessage);
813 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
814 "Core service passes message from `%4s' of type %u to client.\n",
815 GNUNET_i2s (sender), (unsigned int) ntohs (msg->type));
817 GSC_SESSIONS_add_to_typemap (sender, ntohs (msg->type));
818 ntm = (struct NotifyTrafficMessage *) buf;
819 ntm->header.size = htons (size);
820 ntm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND);
821 ntm->ats_count = htonl (atsi_count);
824 memcpy (a, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count);
825 a[atsi_count].type = htonl (GNUNET_ATS_ARRAY_TERMINATOR);
826 a[atsi_count].value = htonl (0);
827 memcpy (&a[atsi_count + 1], msg, msize);
828 send_to_all_clients (sender, &ntm->header, GNUNET_YES, options,
834 * Initialize clients subsystem.
836 * @param server handle to server clients connect to
839 GSC_CLIENTS_init (struct GNUNET_SERVER_Handle *server)
841 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
842 {&handle_client_init, NULL,
843 GNUNET_MESSAGE_TYPE_CORE_INIT, 0},
844 {&GSC_SESSIONS_handle_client_iterate_peers, NULL,
845 GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS,
846 sizeof (struct GNUNET_MessageHeader)},
847 {&GSC_SESSIONS_handle_client_have_peer, NULL,
848 GNUNET_MESSAGE_TYPE_CORE_PEER_CONNECTED,
849 sizeof (struct GNUNET_MessageHeader) +
850 sizeof (struct GNUNET_PeerIdentity)},
851 {&handle_client_send_request, NULL,
852 GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST,
853 sizeof (struct SendMessageRequest)},
854 {&handle_client_send, NULL,
855 GNUNET_MESSAGE_TYPE_CORE_SEND, 0},
859 /* setup notification */
860 client_mst = GNUNET_SERVER_mst_create (&client_tokenizer_callback, NULL);
862 GNUNET_SERVER_notification_context_create (server, MAX_NOTIFY_QUEUE);
863 GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
864 GNUNET_SERVER_add_handlers (server, handlers);
869 * Shutdown clients subsystem.
874 struct GSC_Client *c;
876 while (NULL != (c = client_head))
877 handle_client_disconnect (NULL, c->client_handle);
878 if (NULL != notifier)
880 GNUNET_SERVER_notification_context_destroy (notifier);
883 GNUNET_SERVER_mst_destroy (client_mst);
887 /* end of gnunet-service-core_clients.c */