2 This file is part of GNUnet.
3 Copyright (C) 2009 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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @file multicast/gnunet-service-multicast.c
23 * @brief program that does multicast
24 * @author Christian Grothoff
27 #include "gnunet_util_lib.h"
28 #include "gnunet_signatures.h"
29 #include "gnunet_applications.h"
30 #include "gnunet_statistics_service.h"
31 #include "gnunet_core_service.h"
32 #include "gnunet_cadet_service.h"
33 #include "gnunet_multicast_service.h"
34 #include "multicast.h"
37 * Handle to our current configuration.
39 static const struct GNUNET_CONFIGURATION_Handle *cfg;
44 static struct GNUNET_SERVER_Handle *server;
48 * Only used during initialization.
50 static struct GNUNET_CORE_Handle *core;
55 static struct GNUNET_CADET_Handle *cadet;
58 * Identity of this peer.
60 static struct GNUNET_PeerIdentity this_peer;
63 * Handle to the statistics service.
65 static struct GNUNET_STATISTICS_Handle *stats;
68 * Notification context, simplifies client broadcasts.
70 static struct GNUNET_SERVER_NotificationContext *nc;
73 * All connected origin clients.
74 * Group's pub_key_hash -> struct Origin * (uniq)
76 static struct GNUNET_CONTAINER_MultiHashMap *origins;
79 * All connected member clients.
80 * Group's pub_key_hash -> struct Member * (multi)
82 static struct GNUNET_CONTAINER_MultiHashMap *members;
85 * Connected member clients per group.
86 * Group's pub_key_hash -> Member's pub_key_hash (uniq) -> struct Member * (uniq)
88 static struct GNUNET_CONTAINER_MultiHashMap *group_members;
91 * Incoming CADET channels with connected children in the tree.
92 * Group's pub_key_hash -> struct Channel * (multi)
94 static struct GNUNET_CONTAINER_MultiHashMap *channels_in;
97 * Outgoing CADET channels connecting to parents in the tree.
98 * Group's pub_key_hash -> struct Channel * (multi)
100 static struct GNUNET_CONTAINER_MultiHashMap *channels_out;
103 * Incoming replay requests from CADET.
104 * Group's pub_key_hash ->
105 * H(fragment_id, message_id, fragment_offset, flags) -> struct Channel *
107 static struct GNUNET_CONTAINER_MultiHashMap *replay_req_cadet;
110 * Incoming replay requests from clients.
111 * Group's pub_key_hash ->
112 * H(fragment_id, message_id, fragment_offset, flags) -> struct GNUNET_SERVER_Client *
114 static struct GNUNET_CONTAINER_MultiHashMap *replay_req_client;
118 * Join status of a remote peer.
128 enum ChannelDirection
136 * Context for a CADET channel.
141 * Group the channel belongs to.
143 * Only set for outgoing channels.
150 struct GNUNET_CADET_Channel *channel;
153 * CADET transmission handle.
155 struct GNUNET_CADET_TransmitHandle *tmit_handle;
158 * Public key of the target group.
160 struct GNUNET_CRYPTO_EddsaPublicKey group_key;
163 * Hash of @a group_key.
165 struct GNUNET_HashCode group_key_hash;
168 * Public key of the joining member.
170 struct GNUNET_CRYPTO_EcdsaPublicKey member_key;
173 * Remote peer identity.
175 struct GNUNET_PeerIdentity peer;
178 * Is the remote peer admitted to the group?
179 * @see enum JoinStatus
184 * Number of messages waiting to be sent to CADET.
186 uint8_t msgs_pending;
190 * @see enum ChannelDirection
197 * List of connected clients.
201 struct ClientList *prev;
202 struct ClientList *next;
203 struct GNUNET_SERVER_Client *client;
207 * Common part of the client context for both an origin and member.
211 struct ClientList *clients_head;
212 struct ClientList *clients_tail;
215 * Public key of the group.
217 struct GNUNET_CRYPTO_EddsaPublicKey pub_key;
220 * Hash of @a pub_key.
222 struct GNUNET_HashCode pub_key_hash;
225 * Is this an origin (#GNUNET_YES), or member (#GNUNET_NO)?
230 * Is the client disconnected? #GNUNET_YES or #GNUNET_NO
232 uint8_t disconnected;
237 * Client context for a group's origin.
244 * Private key of the group.
246 struct GNUNET_CRYPTO_EddsaPrivateKey priv_key;
249 * Last message fragment ID sent to the group.
251 uint64_t max_fragment_id;
256 * Client context for a group member.
263 * Private key of the member.
265 struct GNUNET_CRYPTO_EcdsaPrivateKey priv_key;
268 * Public key of the member.
270 struct GNUNET_CRYPTO_EcdsaPublicKey pub_key;
273 * Hash of @a pub_key.
275 struct GNUNET_HashCode pub_key_hash;
278 * Join request sent to the origin / members.
280 struct MulticastJoinRequestMessage *join_req;
283 * Join decision sent in reply to our request.
285 * Only a positive decision is stored here, in case of a negative decision the
286 * client is disconnected.
288 struct MulticastJoinDecisionMessageHeader *join_dcsn;
291 * CADET channel to the origin.
293 struct Channel *origin_channel;
296 * Peer identity of origin.
298 struct GNUNET_PeerIdentity origin;
301 * Peer identity of relays (other members to connect).
303 struct GNUNET_PeerIdentity *relays;
306 * Last request fragment ID sent to the origin.
308 uint64_t max_fragment_id;
311 * Number of @a relays.
313 uint32_t relay_count;
317 struct ReplayRequestKey
319 uint64_t fragment_id;
321 uint64_t fragment_offset;
327 * Task run during shutdown.
333 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
337 GNUNET_CORE_disconnect (core);
342 GNUNET_CADET_disconnect (cadet);
347 GNUNET_STATISTICS_destroy (stats, GNUNET_YES);
350 /* FIXME: do more clean up here */
355 * Clean up origin data structures after a client disconnected.
358 cleanup_origin (struct Origin *orig)
360 struct Group *grp = &orig->grp;
361 GNUNET_CONTAINER_multihashmap_remove (origins, &grp->pub_key_hash, orig);
366 * Clean up member data structures after a client disconnected.
369 cleanup_member (struct Member *mem)
371 struct Group *grp = &mem->grp;
372 struct GNUNET_CONTAINER_MultiHashMap *
373 grp_mem = GNUNET_CONTAINER_multihashmap_get (group_members,
375 GNUNET_assert (NULL != grp_mem);
376 GNUNET_CONTAINER_multihashmap_remove (grp_mem, &mem->pub_key_hash, mem);
378 if (0 == GNUNET_CONTAINER_multihashmap_size (grp_mem))
380 GNUNET_CONTAINER_multihashmap_remove (group_members, &grp->pub_key_hash,
382 GNUNET_CONTAINER_multihashmap_destroy (grp_mem);
384 if (NULL != mem->join_dcsn)
386 GNUNET_free (mem->join_dcsn);
387 mem->join_dcsn = NULL;
389 GNUNET_CONTAINER_multihashmap_remove (members, &grp->pub_key_hash, mem);
394 * Clean up group data structures after a client disconnected.
397 cleanup_group (struct Group *grp)
399 (GNUNET_YES == grp->is_origin)
400 ? cleanup_origin ((struct Origin *) grp)
401 : cleanup_member ((struct Member *) grp);
408 replay_key_hash (uint64_t fragment_id, uint64_t message_id,
409 uint64_t fragment_offset, uint64_t flags,
410 struct GNUNET_HashCode *key_hash)
412 struct ReplayRequestKey key = {
413 .fragment_id = fragment_id,
414 .message_id = message_id,
415 .fragment_offset = fragment_offset,
418 GNUNET_CRYPTO_hash (&key, sizeof (key), key_hash);
423 * Remove channel from replay request hashmap.
428 * @return #GNUNET_YES if there are more entries to process,
429 * #GNUNET_NO when reached end of hashmap.
432 replay_req_remove_cadet (struct Channel *chn)
434 struct GNUNET_CONTAINER_MultiHashMap *
435 grp_replay_req = GNUNET_CONTAINER_multihashmap_get (replay_req_cadet,
436 &chn->grp->pub_key_hash);
437 if (NULL == grp_replay_req)
440 struct GNUNET_CONTAINER_MultiHashMapIterator *
441 it = GNUNET_CONTAINER_multihashmap_iterator_create (grp_replay_req);
442 struct GNUNET_HashCode key;
443 const struct Channel *c;
445 == GNUNET_CONTAINER_multihashmap_iterator_next (it, &key,
450 GNUNET_CONTAINER_multihashmap_remove (grp_replay_req, &key, chn);
454 GNUNET_CONTAINER_multihashmap_iterator_destroy (it);
460 * Remove client from replay request hashmap.
465 * @return #GNUNET_YES if there are more entries to process,
466 * #GNUNET_NO when reached end of hashmap.
469 replay_req_remove_client (struct Group *grp, struct GNUNET_SERVER_Client *client)
471 struct GNUNET_CONTAINER_MultiHashMap *
472 grp_replay_req = GNUNET_CONTAINER_multihashmap_get (replay_req_client,
474 if (NULL == grp_replay_req)
477 struct GNUNET_CONTAINER_MultiHashMapIterator *
478 it = GNUNET_CONTAINER_multihashmap_iterator_create (grp_replay_req);
479 struct GNUNET_HashCode key;
480 const struct GNUNET_SERVER_Client *c;
482 == GNUNET_CONTAINER_multihashmap_iterator_next (it, &key,
487 GNUNET_CONTAINER_multihashmap_remove (replay_req_client, &key, client);
491 GNUNET_CONTAINER_multihashmap_iterator_destroy (it);
497 * Called whenever a client is disconnected.
499 * Frees our resources associated with that client.
501 * @param cls Closure.
502 * @param client Client handle.
505 client_notify_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
511 = GNUNET_SERVER_client_get_user_context (client, struct Group);
515 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
516 "%p User context is NULL in client_disconnect()\n", grp);
521 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
522 "%p Client (%s) disconnected from group %s\n",
523 grp, (GNUNET_YES == grp->is_origin) ? "origin" : "member",
524 GNUNET_h2s (&grp->pub_key_hash));
526 struct ClientList *cl = grp->clients_head;
529 if (cl->client == client)
531 GNUNET_CONTAINER_DLL_remove (grp->clients_head, grp->clients_tail, cl);
538 while (GNUNET_YES == replay_req_remove_client (grp, client));
540 if (NULL == grp->clients_head)
541 { /* Last client disconnected. */
543 if (NULL != grp->tmit_head)
544 { /* Send pending messages via CADET before cleanup. */
545 transmit_message (grp);
557 * Send message to a client.
560 client_send (struct GNUNET_SERVER_Client *client,
561 const struct GNUNET_MessageHeader *msg)
563 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
564 "%p Sending message to client.\n", client);
566 GNUNET_SERVER_notification_context_add (nc, client);
567 GNUNET_SERVER_notification_context_unicast (nc, client, msg, GNUNET_NO);
572 * Send message to all clients connected to the group.
575 client_send_group (const struct Group *grp,
576 const struct GNUNET_MessageHeader *msg)
578 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
579 "%p Sending message to all clients of the group.\n", grp);
581 struct ClientList *cl = grp->clients_head;
584 GNUNET_SERVER_notification_context_add (nc, cl->client);
585 GNUNET_SERVER_notification_context_unicast (nc, cl->client, msg, GNUNET_NO);
592 * Iterator callback for sending a message to origin clients.
595 client_send_origin_cb (void *cls, const struct GNUNET_HashCode *pub_key_hash,
598 const struct GNUNET_MessageHeader *msg = cls;
599 struct Member *orig = origin;
601 client_send_group (&orig->grp, msg);
607 * Iterator callback for sending a message to member clients.
610 client_send_member_cb (void *cls, const struct GNUNET_HashCode *pub_key_hash,
613 const struct GNUNET_MessageHeader *msg = cls;
614 struct Member *mem = member;
616 if (NULL != mem->join_dcsn)
617 { /* Only send message to admitted members */
618 client_send_group (&mem->grp, msg);
625 * Send message to all origin and member clients connected to the group.
627 * @param pub_key_hash
628 * H(key_pub) of the group.
633 client_send_all (struct GNUNET_HashCode *pub_key_hash,
634 const struct GNUNET_MessageHeader *msg)
637 n += GNUNET_CONTAINER_multihashmap_get_multiple (origins, pub_key_hash,
638 client_send_origin_cb,
640 n += GNUNET_CONTAINER_multihashmap_get_multiple (members, pub_key_hash,
641 client_send_member_cb,
648 * Send message to a random origin client or a random member client.
650 * @param grp The group to send @a msg to.
651 * @param msg Message to send.
654 client_send_random (struct GNUNET_HashCode *pub_key_hash,
655 const struct GNUNET_MessageHeader *msg)
658 n = GNUNET_CONTAINER_multihashmap_get_random (origins, client_send_origin_cb,
661 n = GNUNET_CONTAINER_multihashmap_get_random (members, client_send_member_cb,
668 * Send message to all origin clients connected to the group.
670 * @param pub_key_hash
671 * H(key_pub) of the group.
676 client_send_origin (struct GNUNET_HashCode *pub_key_hash,
677 const struct GNUNET_MessageHeader *msg)
680 n += GNUNET_CONTAINER_multihashmap_get_multiple (origins, pub_key_hash,
681 client_send_origin_cb,
688 * Send fragment acknowledgement to all clients of the channel.
690 * @param pub_key_hash
691 * H(key_pub) of the group.
694 client_send_ack (struct GNUNET_HashCode *pub_key_hash)
696 static struct GNUNET_MessageHeader *msg = NULL;
699 msg = GNUNET_malloc (sizeof (*msg));
700 msg->type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_FRAGMENT_ACK);
701 msg->size = htons (sizeof (*msg));
703 client_send_all (pub_key_hash, msg);
707 struct CadetTransmitClosure
710 const struct GNUNET_MessageHeader *msg;
715 * CADET is ready to transmit a message.
718 cadet_notify_transmit_ready (void *cls, size_t buf_size, void *buf)
722 /* FIXME: connection closed */
725 struct CadetTransmitClosure *tcls = cls;
726 struct Channel *chn = tcls->chn;
727 uint16_t msg_size = ntohs (tcls->msg->size);
728 GNUNET_assert (msg_size <= buf_size);
729 memcpy (buf, tcls->msg, msg_size);
732 if (0 == chn->msgs_pending)
736 else if (0 == --chn->msgs_pending)
738 client_send_ack (&chn->group_key_hash);
745 * Send a message to a CADET channel.
747 * @param chn Channel.
748 * @param msg Message.
751 cadet_send_channel (struct Channel *chn, const struct GNUNET_MessageHeader *msg)
753 struct CadetTransmitClosure *tcls = GNUNET_malloc (sizeof (*tcls));
759 = GNUNET_CADET_notify_transmit_ready (chn->channel, GNUNET_NO,
760 GNUNET_TIME_UNIT_FOREVER_REL,
762 &cadet_notify_transmit_ready,
764 GNUNET_assert (NULL != chn->tmit_handle);
769 * Create new outgoing CADET channel.
772 * Peer to connect to.
774 * Public key of group the channel belongs to.
775 * @param group_key_hash
776 * Hash of @a group_key.
780 static struct Channel *
781 cadet_channel_create (struct Group *grp, struct GNUNET_PeerIdentity *peer)
783 struct Channel *chn = GNUNET_malloc (sizeof (*chn));
785 chn->group_key = grp->pub_key;
786 chn->group_key_hash = grp->pub_key_hash;
788 chn->direction = DIR_OUTGOING;
789 chn->join_status = JOIN_WAITING;
790 chn->channel = GNUNET_CADET_channel_create (cadet, chn, &chn->peer,
791 GNUNET_APPLICATION_TYPE_MULTICAST,
792 GNUNET_CADET_OPTION_RELIABLE);
793 GNUNET_CONTAINER_multihashmap_put (channels_out, &chn->group_key_hash, chn,
794 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
800 * Create CADET channel and send a join request.
803 cadet_send_join_request (struct Member *mem)
805 mem->origin_channel = cadet_channel_create (&mem->grp, &mem->origin);
806 cadet_send_channel (mem->origin_channel, &mem->join_req->header);
809 for (i = 0; i < mem->relay_count; i++)
812 chn = cadet_channel_create (&mem->grp, &mem->relays[i]);
813 cadet_send_channel (chn, &mem->join_req->header);
819 cadet_send_join_decision_cb (void *cls,
820 const struct GNUNET_HashCode *group_key_hash,
823 const struct MulticastJoinDecisionMessageHeader *hdcsn = cls;
824 struct Channel *chn = channel;
826 if (0 == memcmp (&hdcsn->member_key, &chn->member_key, sizeof (chn->member_key))
827 && 0 == memcmp (&hdcsn->peer, &chn->peer, sizeof (chn->peer)))
829 cadet_send_channel (chn, &hdcsn->header);
837 * Send join decision to a remote peer.
840 cadet_send_join_decision (struct Group *grp,
841 const struct MulticastJoinDecisionMessageHeader *hdcsn)
843 GNUNET_CONTAINER_multihashmap_get_multiple (channels_in, &grp->pub_key_hash,
844 &cadet_send_join_decision_cb,
850 * Iterator callback for sending a message to origin clients.
853 cadet_send_cb (void *cls, const struct GNUNET_HashCode *pub_key_hash,
856 const struct GNUNET_MessageHeader *msg = cls;
857 struct Channel *chn = channel;
858 if (JOIN_ADMITTED == chn->join_status)
859 cadet_send_channel (chn, msg);
865 * Send message to all connected children.
868 cadet_send_children (struct GNUNET_HashCode *pub_key_hash,
869 const struct GNUNET_MessageHeader *msg)
872 if (channels_in != NULL)
873 n += GNUNET_CONTAINER_multihashmap_get_multiple (channels_in, pub_key_hash,
874 cadet_send_cb, (void *) msg);
880 * Send message to all connected parents.
883 cadet_send_parents (struct GNUNET_HashCode *pub_key_hash,
884 const struct GNUNET_MessageHeader *msg)
887 if (channels_in != NULL)
888 n += GNUNET_CONTAINER_multihashmap_get_multiple (channels_out, pub_key_hash,
889 cadet_send_cb, (void *) msg);
895 * Handle a connecting client starting an origin.
898 client_recv_origin_start (void *cls, struct GNUNET_SERVER_Client *client,
899 const struct GNUNET_MessageHeader *m)
901 const struct MulticastOriginStartMessage *
902 msg = (const struct MulticastOriginStartMessage *) m;
904 struct GNUNET_CRYPTO_EddsaPublicKey pub_key;
905 struct GNUNET_HashCode pub_key_hash;
907 GNUNET_CRYPTO_eddsa_key_get_public (&msg->group_key, &pub_key);
908 GNUNET_CRYPTO_hash (&pub_key, sizeof (pub_key), &pub_key_hash);
911 orig = GNUNET_CONTAINER_multihashmap_get (origins, &pub_key_hash);
916 orig = GNUNET_new (struct Origin);
917 orig->priv_key = msg->group_key;
918 orig->max_fragment_id = GNUNET_ntohll (msg->max_fragment_id);
920 grp->is_origin = GNUNET_YES;
921 grp->pub_key = pub_key;
922 grp->pub_key_hash = pub_key_hash;
924 GNUNET_CONTAINER_multihashmap_put (origins, &grp->pub_key_hash, orig,
925 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
932 struct ClientList *cl = GNUNET_new (struct ClientList);
934 GNUNET_CONTAINER_DLL_insert (grp->clients_head, grp->clients_tail, cl);
936 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
937 "%p Client connected as origin to group %s.\n",
938 orig, GNUNET_h2s (&grp->pub_key_hash));
940 GNUNET_SERVER_client_set_user_context (client, grp);
941 GNUNET_SERVER_receive_done (client, GNUNET_OK);
946 * Handle a connecting client joining a group.
949 client_recv_member_join (void *cls, struct GNUNET_SERVER_Client *client,
950 const struct GNUNET_MessageHeader *m)
952 const struct MulticastMemberJoinMessage *
953 msg = (const struct MulticastMemberJoinMessage *) m;
954 uint16_t msg_size = ntohs (msg->header.size);
956 struct GNUNET_CRYPTO_EcdsaPublicKey mem_pub_key;
957 struct GNUNET_HashCode pub_key_hash, mem_pub_key_hash;
959 GNUNET_CRYPTO_ecdsa_key_get_public (&msg->member_key, &mem_pub_key);
960 GNUNET_CRYPTO_hash (&mem_pub_key, sizeof (mem_pub_key), &mem_pub_key_hash);
961 GNUNET_CRYPTO_hash (&msg->group_key, sizeof (msg->group_key), &pub_key_hash);
963 struct GNUNET_CONTAINER_MultiHashMap *
964 grp_mem = GNUNET_CONTAINER_multihashmap_get (group_members, &pub_key_hash);
965 struct Member *mem = NULL;
970 mem = GNUNET_CONTAINER_multihashmap_get (grp_mem, &mem_pub_key_hash);
974 mem = GNUNET_new (struct Member);
975 mem->priv_key = msg->member_key;
976 mem->pub_key = mem_pub_key;
977 mem->pub_key_hash = mem_pub_key_hash;
978 mem->max_fragment_id = 0; // FIXME
981 grp->is_origin = GNUNET_NO;
982 grp->pub_key = msg->group_key;
983 grp->pub_key_hash = pub_key_hash;
987 grp_mem = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_YES);
988 GNUNET_CONTAINER_multihashmap_put (group_members, &grp->pub_key_hash, grp_mem,
989 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
991 GNUNET_CONTAINER_multihashmap_put (grp_mem, &mem->pub_key_hash, mem,
992 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
993 GNUNET_CONTAINER_multihashmap_put (members, &grp->pub_key_hash, mem,
994 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1001 struct ClientList *cl = GNUNET_new (struct ClientList);
1002 cl->client = client;
1003 GNUNET_CONTAINER_DLL_insert (grp->clients_head, grp->clients_tail, cl);
1005 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1006 "%p Client connected to group %s..\n",
1007 mem, GNUNET_h2s (&grp->pub_key_hash));
1008 char *str = GNUNET_CRYPTO_ecdsa_public_key_to_string (&mem->pub_key);
1009 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1010 "%p ..as member %s (%s).\n",
1011 mem, GNUNET_h2s (&mem->pub_key_hash), str);
1014 GNUNET_SERVER_client_set_user_context (client, grp);
1016 if (NULL != mem->join_dcsn)
1017 { /* Already got a join decision, send it to client. */
1018 GNUNET_SERVER_notification_context_add (nc, client);
1019 GNUNET_SERVER_notification_context_unicast (nc, client,
1020 (struct GNUNET_MessageHeader *)
1025 { /* First client of the group, send join request. */
1026 struct GNUNET_PeerIdentity *relays = (struct GNUNET_PeerIdentity *) &msg[1];
1027 uint32_t relay_count = ntohl (msg->relay_count);
1028 uint16_t relay_size = relay_count * sizeof (*relays);
1029 struct GNUNET_MessageHeader *join_msg = NULL;
1030 uint16_t join_msg_size = 0;
1031 if (sizeof (*msg) + relay_size + sizeof (struct GNUNET_MessageHeader)
1034 join_msg = (struct GNUNET_MessageHeader *)
1035 (((char *) &msg[1]) + relay_size);
1036 join_msg_size = ntohs (join_msg->size);
1038 if (sizeof (*msg) + relay_size + join_msg_size != msg_size)
1041 GNUNET_SERVER_client_disconnect (client);
1045 struct MulticastJoinRequestMessage *
1046 req = GNUNET_malloc (sizeof (*req) + join_msg_size);
1047 req->header.size = htons (sizeof (*req) + join_msg_size);
1048 req->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_REQUEST);
1049 req->group_key = grp->pub_key;
1050 req->peer = this_peer;
1051 GNUNET_CRYPTO_ecdsa_key_get_public (&mem->priv_key, &req->member_key);
1052 if (0 < join_msg_size)
1053 memcpy (&req[1], join_msg, join_msg_size);
1055 req->member_key = mem->pub_key;
1056 req->purpose.size = htonl (msg_size
1057 - sizeof (req->header)
1058 - sizeof (req->reserved)
1059 - sizeof (req->signature));
1060 req->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_MULTICAST_REQUEST);
1062 if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_sign (&mem->priv_key, &req->purpose,
1065 /* FIXME: handle error */
1069 if (NULL != mem->join_req)
1070 GNUNET_free (mem->join_req);
1071 mem->join_req = req;
1073 if (0 == client_send_origin (&grp->pub_key_hash, &mem->join_req->header))
1074 { /* No local origins, send to remote origin */
1075 cadet_send_join_request (mem);
1078 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1083 client_send_join_decision (struct Member *mem,
1084 const struct MulticastJoinDecisionMessageHeader *hdcsn)
1086 client_send_group (&mem->grp, &hdcsn->header);
1088 const struct MulticastJoinDecisionMessage *
1089 dcsn = (const struct MulticastJoinDecisionMessage *) &hdcsn[1];
1090 if (GNUNET_YES == ntohl (dcsn->is_admitted))
1091 { /* Member admitted, store join_decision. */
1092 uint16_t dcsn_size = ntohs (dcsn->header.size);
1093 mem->join_dcsn = GNUNET_malloc (dcsn_size);
1094 memcpy (mem->join_dcsn, dcsn, dcsn_size);
1097 { /* Refused entry, but replay would be still possible for past members. */
1103 * Join decision from client.
1106 client_recv_join_decision (void *cls, struct GNUNET_SERVER_Client *client,
1107 const struct GNUNET_MessageHeader *m)
1110 grp = GNUNET_SERVER_client_get_user_context (client, struct Group);
1111 const struct MulticastJoinDecisionMessageHeader *
1112 hdcsn = (const struct MulticastJoinDecisionMessageHeader *) m;
1117 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1121 "%p Got join decision from client for group %s..\n",
1122 grp, GNUNET_h2s (&grp->pub_key_hash));
1124 struct GNUNET_CONTAINER_MultiHashMap *
1125 grp_mem = GNUNET_CONTAINER_multihashmap_get (group_members,
1126 &grp->pub_key_hash);
1127 struct Member *mem = NULL;
1128 if (NULL != grp_mem)
1130 struct GNUNET_HashCode member_key_hash;
1131 GNUNET_CRYPTO_hash (&hdcsn->member_key, sizeof (hdcsn->member_key),
1133 mem = GNUNET_CONTAINER_multihashmap_get (grp_mem, &member_key_hash);
1134 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1135 "%p ..and member %s: %p\n",
1136 grp, GNUNET_h2s (&member_key_hash), mem);
1139 { /* Found local member */
1140 client_send_join_decision (mem, hdcsn);
1143 { /* Look for remote member */
1144 cadet_send_join_decision (grp, hdcsn);
1146 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1151 * Incoming message from a client.
1154 client_recv_multicast_message (void *cls, struct GNUNET_SERVER_Client *client,
1155 const struct GNUNET_MessageHeader *m)
1158 grp = GNUNET_SERVER_client_get_user_context (client, struct Group);
1159 struct GNUNET_MULTICAST_MessageHeader *out;
1160 struct Origin *orig;
1165 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1168 GNUNET_assert (GNUNET_YES == grp->is_origin);
1169 orig = (struct Origin *) grp;
1171 /* FIXME: yucky, should use separate message structs for P2P and CS! */
1172 out = (struct GNUNET_MULTICAST_MessageHeader *) GNUNET_copy_message (m);
1173 out->fragment_id = GNUNET_htonll (++orig->max_fragment_id);
1174 out->purpose.size = htonl (ntohs (out->header.size)
1175 - sizeof (out->header)
1176 - sizeof (out->hop_counter)
1177 - sizeof (out->signature));
1178 out->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_MULTICAST_MESSAGE);
1180 if (GNUNET_OK != GNUNET_CRYPTO_eddsa_sign (&orig->priv_key, &out->purpose,
1186 client_send_all (&grp->pub_key_hash, &out->header);
1187 if (0 == cadet_send_children (&grp->pub_key_hash, &out->header))
1189 client_send_ack (&grp->pub_key_hash);
1193 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1198 * Incoming request from a client.
1201 client_recv_multicast_request (void *cls, struct GNUNET_SERVER_Client *client,
1202 const struct GNUNET_MessageHeader *m)
1204 struct Group *grp = GNUNET_SERVER_client_get_user_context (client, struct Group);
1206 struct GNUNET_MULTICAST_RequestHeader *out;
1210 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1213 GNUNET_assert (GNUNET_NO == grp->is_origin);
1214 mem = (struct Member *) grp;
1216 /* FIXME: yucky, should use separate message structs for P2P and CS! */
1217 out = (struct GNUNET_MULTICAST_RequestHeader *) GNUNET_copy_message (m);
1218 out->member_key = mem->pub_key;
1219 out->fragment_id = GNUNET_ntohll (++mem->max_fragment_id);
1220 out->purpose.size = htonl (ntohs (out->header.size)
1221 - sizeof (out->header)
1222 - sizeof (out->member_key)
1223 - sizeof (out->signature));
1224 out->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_MULTICAST_REQUEST);
1226 if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_sign (&mem->priv_key, &out->purpose,
1232 uint8_t send_ack = GNUNET_YES;
1233 if (0 == client_send_origin (&grp->pub_key_hash, &out->header))
1234 { /* No local origins, send to remote origin */
1235 if (NULL != mem->origin_channel)
1237 cadet_send_channel (mem->origin_channel, &out->header);
1238 send_ack = GNUNET_NO;
1242 /* FIXME: not yet connected to origin */
1243 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1248 if (GNUNET_YES == send_ack)
1250 client_send_ack (&grp->pub_key_hash);
1253 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1258 * Incoming replay request from a client.
1261 client_recv_replay_request (void *cls, struct GNUNET_SERVER_Client *client,
1262 const struct GNUNET_MessageHeader *m)
1264 struct Group *grp = GNUNET_SERVER_client_get_user_context (client, struct Group);
1269 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1272 GNUNET_assert (GNUNET_NO == grp->is_origin);
1273 mem = (struct Member *) grp;
1275 struct GNUNET_CONTAINER_MultiHashMap *
1276 grp_replay_req = GNUNET_CONTAINER_multihashmap_get (replay_req_client,
1277 &grp->pub_key_hash);
1278 if (NULL == grp_replay_req)
1280 grp_replay_req = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO);
1281 GNUNET_CONTAINER_multihashmap_put (replay_req_client,
1282 &grp->pub_key_hash, grp_replay_req,
1283 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
1285 struct MulticastReplayRequestMessage *
1286 rep = (struct MulticastReplayRequestMessage *) m;
1287 struct GNUNET_HashCode key_hash;
1288 replay_key_hash (rep->fragment_id, rep->message_id, rep->fragment_offset,
1289 rep->flags, &key_hash);
1290 GNUNET_CONTAINER_multihashmap_put (grp_replay_req, &key_hash, client,
1291 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1293 if (0 == client_send_origin (&grp->pub_key_hash, m))
1294 { /* No local origin, replay from remote members / origin. */
1295 if (NULL != mem->origin_channel)
1297 cadet_send_channel (mem->origin_channel, m);
1301 /* FIXME: not yet connected to origin */
1302 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1306 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1311 cadet_send_replay_response_cb (void *cls,
1312 const struct GNUNET_HashCode *key_hash,
1315 struct Channel *chn = value;
1316 struct GNUNET_MessageHeader *msg = cls;
1318 cadet_send_channel (chn, msg);
1324 client_send_replay_response_cb (void *cls,
1325 const struct GNUNET_HashCode *key_hash,
1328 struct GNUNET_SERVER_Client *client = value;
1329 struct GNUNET_MessageHeader *msg = cls;
1331 client_send (client, msg);
1337 * End of replay response from a client.
1340 client_recv_replay_response_end (void *cls, struct GNUNET_SERVER_Client *client,
1341 const struct GNUNET_MessageHeader *m)
1343 struct Group *grp = GNUNET_SERVER_client_get_user_context (client, struct Group);
1347 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1351 struct MulticastReplayResponseMessage *
1352 res = (struct MulticastReplayResponseMessage *) m;
1354 struct GNUNET_HashCode key_hash;
1355 replay_key_hash (res->fragment_id, res->message_id, res->fragment_offset,
1356 res->flags, &key_hash);
1358 struct GNUNET_CONTAINER_MultiHashMap *
1359 grp_replay_req_cadet = GNUNET_CONTAINER_multihashmap_get (replay_req_cadet,
1360 &grp->pub_key_hash);
1361 if (NULL != grp_replay_req_cadet)
1363 GNUNET_CONTAINER_multihashmap_remove_all (grp_replay_req_cadet, &key_hash);
1365 struct GNUNET_CONTAINER_MultiHashMap *
1366 grp_replay_req_client = GNUNET_CONTAINER_multihashmap_get (replay_req_client,
1367 &grp->pub_key_hash);
1368 if (NULL != grp_replay_req_client)
1370 GNUNET_CONTAINER_multihashmap_remove_all (grp_replay_req_client, &key_hash);
1372 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1377 * Incoming replay response from a client.
1379 * Respond with a multicast message on success, or otherwise with an error code.
1382 client_recv_replay_response (void *cls, struct GNUNET_SERVER_Client *client,
1383 const struct GNUNET_MessageHeader *m)
1385 struct Group *grp = GNUNET_SERVER_client_get_user_context (client, struct Group);
1389 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1393 struct MulticastReplayResponseMessage *
1394 res = (struct MulticastReplayResponseMessage *) m;
1396 const struct GNUNET_MessageHeader *msg = m;
1397 if (GNUNET_MULTICAST_REC_OK == res->error_code)
1399 msg = (struct GNUNET_MessageHeader *) &res[1];
1402 struct GNUNET_HashCode key_hash;
1403 replay_key_hash (res->fragment_id, res->message_id, res->fragment_offset,
1404 res->flags, &key_hash);
1406 struct GNUNET_CONTAINER_MultiHashMap *
1407 grp_replay_req_cadet = GNUNET_CONTAINER_multihashmap_get (replay_req_cadet,
1408 &grp->pub_key_hash);
1409 if (NULL != grp_replay_req_cadet)
1411 GNUNET_CONTAINER_multihashmap_get_multiple (grp_replay_req_cadet, &key_hash,
1412 cadet_send_replay_response_cb,
1415 if (GNUNET_MULTICAST_REC_OK == res->error_code)
1417 struct GNUNET_CONTAINER_MultiHashMap *
1418 grp_replay_req_client = GNUNET_CONTAINER_multihashmap_get (replay_req_client,
1419 &grp->pub_key_hash);
1420 if (NULL != grp_replay_req_client)
1422 GNUNET_CONTAINER_multihashmap_get_multiple (grp_replay_req_client, &key_hash,
1423 client_send_replay_response_cb,
1429 client_recv_replay_response_end (cls, client, m);
1432 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1437 * A new client connected.
1440 client_notify_connect (void *cls, struct GNUNET_SERVER_Client *client)
1442 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client connected: %p\n", client);
1443 /* FIXME: send connect ACK */
1448 * Message handlers for the server.
1450 static const struct GNUNET_SERVER_MessageHandler server_handlers[] = {
1451 { client_recv_origin_start, NULL,
1452 GNUNET_MESSAGE_TYPE_MULTICAST_ORIGIN_START, 0 },
1454 { client_recv_member_join, NULL,
1455 GNUNET_MESSAGE_TYPE_MULTICAST_MEMBER_JOIN, 0 },
1457 { client_recv_join_decision, NULL,
1458 GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION, 0 },
1460 { client_recv_multicast_message, NULL,
1461 GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE, 0 },
1463 { client_recv_multicast_request, NULL,
1464 GNUNET_MESSAGE_TYPE_MULTICAST_REQUEST, 0 },
1466 { client_recv_replay_request, NULL,
1467 GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_REQUEST, 0 },
1469 { client_recv_replay_response, NULL,
1470 GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_RESPONSE, 0 },
1472 { client_recv_replay_response_end, NULL,
1473 GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_RESPONSE_END, 0 },
1475 { NULL, NULL, 0, 0 }
1480 * New incoming CADET channel.
1483 cadet_notify_channel_new (void *cls,
1484 struct GNUNET_CADET_Channel *channel,
1485 const struct GNUNET_PeerIdentity *initiator,
1487 enum GNUNET_CADET_ChannelOption options)
1494 * CADET channel is being destroyed.
1497 cadet_notify_channel_end (void *cls,
1498 const struct GNUNET_CADET_Channel *channel,
1504 struct Channel *chn = ctx;
1505 if (NULL != chn->grp)
1507 if (GNUNET_NO == chn->grp->is_origin)
1509 struct Member *mem = (struct Member *) chn->grp;
1510 if (chn == mem->origin_channel)
1511 mem->origin_channel = NULL;
1515 while (GNUNET_YES == replay_req_remove_cadet (chn));
1522 * Incoming join request message from CADET.
1525 cadet_recv_join_request (void *cls,
1526 struct GNUNET_CADET_Channel *channel,
1528 const struct GNUNET_MessageHeader *m)
1530 const struct MulticastJoinRequestMessage *
1531 req = (const struct MulticastJoinRequestMessage *) m;
1532 uint16_t size = ntohs (m->size);
1533 if (size < sizeof (*req))
1535 GNUNET_break_op (0);
1536 return GNUNET_SYSERR;
1540 GNUNET_break_op (0);
1541 return GNUNET_SYSERR;
1543 if (ntohl (req->purpose.size) != (size
1544 - sizeof (req->header)
1545 - sizeof (req->reserved)
1546 - sizeof (req->signature)))
1548 GNUNET_break_op (0);
1549 return GNUNET_SYSERR;
1552 GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_MULTICAST_REQUEST,
1553 &req->purpose, &req->signature,
1556 GNUNET_break_op (0);
1557 return GNUNET_SYSERR;
1560 struct GNUNET_HashCode group_key_hash;
1561 GNUNET_CRYPTO_hash (&req->group_key, sizeof (req->group_key), &group_key_hash);
1563 struct Channel *chn = GNUNET_malloc (sizeof *chn);
1564 chn->channel = channel;
1565 chn->group_key = req->group_key;
1566 chn->group_key_hash = group_key_hash;
1567 chn->member_key = req->member_key;
1568 chn->peer = req->peer;
1569 chn->join_status = JOIN_WAITING;
1570 GNUNET_CONTAINER_multihashmap_put (channels_in, &chn->group_key_hash, chn,
1571 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1573 client_send_all (&group_key_hash, m);
1579 * Incoming join decision message from CADET.
1582 cadet_recv_join_decision (void *cls,
1583 struct GNUNET_CADET_Channel *channel,
1585 const struct GNUNET_MessageHeader *m)
1587 const struct MulticastJoinDecisionMessage *
1588 dcsn = (const struct MulticastJoinDecisionMessage *) m;
1589 uint16_t size = ntohs (m->size);
1590 if (size < sizeof (*dcsn))
1592 GNUNET_break_op (0);
1593 return GNUNET_SYSERR;
1595 struct Channel *chn = *ctx;
1598 GNUNET_break_op (0);
1599 return GNUNET_SYSERR;
1601 if (NULL == chn->grp || GNUNET_NO != chn->grp->is_origin)
1603 GNUNET_break_op (0);
1604 return GNUNET_SYSERR;
1606 switch (chn->join_status)
1609 return GNUNET_SYSERR;
1614 case JOIN_NOT_ASKED:
1619 struct MulticastJoinDecisionMessageHeader *
1620 hdcsn = GNUNET_malloc (sizeof (*hdcsn) + size);
1621 hdcsn->peer = chn->peer;
1622 memcpy (&hdcsn[1], dcsn, sizeof (*hdcsn) + size);
1624 struct Member *mem = (struct Member *) chn->grp;
1625 client_send_join_decision (mem, hdcsn);
1626 GNUNET_free (hdcsn);
1627 if (GNUNET_YES == ntohs (dcsn->is_admitted))
1629 chn->join_status = JOIN_ADMITTED;
1634 chn->join_status = JOIN_REFUSED;
1635 return GNUNET_SYSERR;
1640 * Incoming multicast message from CADET.
1643 cadet_recv_message (void *cls,
1644 struct GNUNET_CADET_Channel *channel,
1646 const struct GNUNET_MessageHeader *m)
1648 const struct GNUNET_MULTICAST_MessageHeader *
1649 msg = (const struct GNUNET_MULTICAST_MessageHeader *) m;
1650 uint16_t size = ntohs (m->size);
1651 if (size < sizeof (*msg))
1653 GNUNET_break_op (0);
1654 return GNUNET_SYSERR;
1656 struct Channel *chn = *ctx;
1659 GNUNET_break_op (0);
1660 return GNUNET_SYSERR;
1662 if (ntohl (msg->purpose.size) != (size
1663 - sizeof (msg->header)
1664 - sizeof (msg->hop_counter)
1665 - sizeof (msg->signature)))
1667 GNUNET_break_op (0);
1668 return GNUNET_SYSERR;
1671 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_MULTICAST_MESSAGE,
1672 &msg->purpose, &msg->signature,
1675 GNUNET_break_op (0);
1676 return GNUNET_SYSERR;
1679 client_send_all (&chn->group_key_hash, m);
1685 * Incoming multicast request message from CADET.
1688 cadet_recv_request (void *cls,
1689 struct GNUNET_CADET_Channel *channel,
1691 const struct GNUNET_MessageHeader *m)
1693 const struct GNUNET_MULTICAST_RequestHeader *
1694 req = (const struct GNUNET_MULTICAST_RequestHeader *) m;
1695 uint16_t size = ntohs (m->size);
1696 if (size < sizeof (*req))
1698 GNUNET_break_op (0);
1699 return GNUNET_SYSERR;
1701 struct Channel *chn = *ctx;
1704 GNUNET_break_op (0);
1705 return GNUNET_SYSERR;
1707 if (ntohl (req->purpose.size) != (size
1708 - sizeof (req->header)
1709 - sizeof (req->member_key)
1710 - sizeof (req->signature)))
1712 GNUNET_break_op (0);
1713 return GNUNET_SYSERR;
1716 GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_MULTICAST_REQUEST,
1717 &req->purpose, &req->signature,
1720 GNUNET_break_op (0);
1721 return GNUNET_SYSERR;
1724 client_send_origin (&chn->group_key_hash, m);
1730 * Incoming multicast replay request from CADET.
1733 cadet_recv_replay_request (void *cls,
1734 struct GNUNET_CADET_Channel *channel,
1736 const struct GNUNET_MessageHeader *m)
1738 struct MulticastReplayRequestMessage rep;
1739 uint16_t size = ntohs (m->size);
1740 if (size < sizeof (rep))
1742 GNUNET_break_op (0);
1743 return GNUNET_SYSERR;
1745 struct Channel *chn = *ctx;
1747 memcpy (&rep, m, sizeof (rep));
1748 memcpy (&rep.member_key, &chn->member_key, sizeof (chn->member_key));
1750 struct GNUNET_CONTAINER_MultiHashMap *
1751 grp_replay_req = GNUNET_CONTAINER_multihashmap_get (replay_req_cadet,
1752 &chn->grp->pub_key_hash);
1753 if (NULL == grp_replay_req)
1755 grp_replay_req = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO);
1756 GNUNET_CONTAINER_multihashmap_put (replay_req_cadet,
1757 &chn->grp->pub_key_hash, grp_replay_req,
1758 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
1760 struct GNUNET_HashCode key_hash;
1761 replay_key_hash (rep.fragment_id, rep.message_id, rep.fragment_offset,
1762 rep.flags, &key_hash);
1763 GNUNET_CONTAINER_multihashmap_put (grp_replay_req, &key_hash, chn,
1764 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1766 client_send_random (&chn->group_key_hash, &rep.header);
1772 * Incoming multicast replay response from CADET.
1775 cadet_recv_replay_response (void *cls,
1776 struct GNUNET_CADET_Channel *channel,
1778 const struct GNUNET_MessageHeader *m)
1780 struct Channel *chn = *ctx;
1782 /* @todo FIXME: got replay error response, send request to other members */
1789 * Message handlers for CADET.
1791 static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
1792 { cadet_recv_join_request,
1793 GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_REQUEST, 0 },
1795 { cadet_recv_message,
1796 GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE, 0 },
1798 { cadet_recv_request,
1799 GNUNET_MESSAGE_TYPE_MULTICAST_REQUEST, 0 },
1801 { cadet_recv_replay_request,
1802 GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_REQUEST, 0 },
1804 { cadet_recv_replay_response,
1805 GNUNET_MESSAGE_TYPE_MULTICAST_REPLAY_RESPONSE, 0 },
1812 * Listening ports for CADET.
1814 static const uint32_t cadet_ports[] = { GNUNET_APPLICATION_TYPE_MULTICAST, 0 };
1818 * Connected to core service.
1821 core_connected_cb (void *cls, const struct GNUNET_PeerIdentity *my_identity)
1823 this_peer = *my_identity;
1825 stats = GNUNET_STATISTICS_create ("multicast", cfg);
1826 origins = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_YES);
1827 members = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_YES);
1828 group_members = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO);
1829 channels_in = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_YES);
1830 channels_out = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_YES);
1831 replay_req_cadet = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO);
1832 replay_req_client = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO);
1834 cadet = GNUNET_CADET_connect (cfg, NULL,
1835 &cadet_notify_channel_new,
1836 &cadet_notify_channel_end,
1837 cadet_handlers, cadet_ports);
1839 nc = GNUNET_SERVER_notification_context_create (server, 1);
1840 GNUNET_SERVER_add_handlers (server, server_handlers);
1841 GNUNET_SERVER_disconnect_notify (server, &client_notify_disconnect, NULL);
1843 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
1851 * @param cls closure
1852 * @param server the initialized server
1853 * @param cfg configuration to use
1856 run (void *cls, struct GNUNET_SERVER_Handle *srv,
1857 const struct GNUNET_CONFIGURATION_Handle *c)
1861 GNUNET_SERVER_connect_notify (server, &client_notify_connect, NULL);
1862 core = GNUNET_CORE_connect (cfg, NULL, &core_connected_cb, NULL, NULL,
1863 NULL, GNUNET_NO, NULL, GNUNET_NO, NULL);
1868 * The main function for the multicast service.
1870 * @param argc number of arguments from the command line
1871 * @param argv command line arguments
1872 * @return 0 ok, 1 on error
1875 main (int argc, char *const *argv)
1877 return (GNUNET_OK ==
1878 GNUNET_SERVICE_run (argc, argv, "multicast",
1879 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
1882 /* end of gnunet-service-multicast.c */