2 This file is part of GNUnet
3 (C) 2013 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 2, 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 set/gnunet-service-set.c
23 * @brief two-peer set operations
24 * @author Florian Dold
26 #include "gnunet-service-set.h"
27 #include "set_protocol.h"
31 * Peer that has connected to us, but is not yet evaluating a set operation.
32 * Once the peer has sent a request, and the client has
33 * accepted or rejected it, this information will be deleted.
38 * Incoming peers are held in a linked list
40 struct Incoming *next;
43 * Incoming peers are held in a linked list
45 struct Incoming *prev;
48 * Detail information about the operation.
49 * NULL as long as we did not receive the operation
50 * request from the remote peer.
52 struct OperationSpecification *spec;
55 * The identity of the requesting peer. Needs to
56 * be stored here as the op spec might not have been created yet.
58 struct GNUNET_PeerIdentity peer;
63 struct GNUNET_MESH_Tunnel *tunnel;
66 * Unique request id for the request from
67 * a remote peer, sent to the client, which will
68 * accept or reject the request.
69 * Set to '0' iff the request has not been
75 * Timeout task, if the incoming peer has not been accepted
76 * after the timeout, it will be disconnected.
78 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
81 * Tunnel context, needs to be stored here as a client's accept will change
84 struct TunnelContext *tc;
89 * A listener is inhabited by a client, and
90 * waits for evaluation requests from remote peers.
95 * Listeners are held in a doubly linked list.
97 struct Listener *next;
100 * Listeners are held in a doubly linked list.
102 struct Listener *prev;
105 * Client that owns the listener.
106 * Only one client may own a listener.
108 struct GNUNET_SERVER_Client *client;
111 * Message queue for the client
113 struct GNUNET_MQ_Handle *client_mq;
116 * The type of the operation.
118 enum GNUNET_SET_OperationType operation;
121 * Application ID for the operation, used to distinguish
122 * multiple operations of the same type with the same peer.
124 struct GNUNET_HashCode app_id;
129 * Configuration of our local peer.
131 static const struct GNUNET_CONFIGURATION_Handle *configuration;
134 * Handle to the mesh service, used
135 * to listen for and connect to remote peers.
137 static struct GNUNET_MESH_Handle *mesh;
140 * Sets are held in a doubly linked list.
142 static struct Set *sets_head;
145 * Sets are held in a doubly linked list.
147 static struct Set *sets_tail;
150 * Listeners are held in a doubly linked list.
152 static struct Listener *listeners_head;
155 * Listeners are held in a doubly linked list.
157 static struct Listener *listeners_tail;
160 * Incoming sockets from remote peers are
161 * held in a doubly linked list.
163 static struct Incoming *incoming_head;
166 * Incoming sockets from remote peers are
167 * held in a doubly linked list.
169 static struct Incoming *incoming_tail;
172 * Counter for allocating unique IDs for clients,
173 * used to identify incoming operation requests from remote peers,
174 * that the client can choose to accept or refuse.
176 static uint32_t suggest_id = 1;
180 * Get set that is owned by the given client, if any.
182 * @param client client to look for
183 * @return set that the client owns, NULL if the client
187 set_get (struct GNUNET_SERVER_Client *client)
191 for (set = sets_head; NULL != set; set = set->next)
192 if (set->client == client)
199 * Get the listener associated with the given client, if any.
201 * @param client the client
202 * @return listener associated with the client, NULL
205 static struct Listener *
206 listener_get (struct GNUNET_SERVER_Client *client)
208 struct Listener *listener;
210 for (listener = listeners_head; NULL != listener; listener = listener->next)
211 if (listener->client == client)
218 * Get the incoming socket associated with the given id.
220 * @param id id to look for
221 * @return the incoming socket associated with the id,
222 * or NULL if there is none
224 static struct Incoming *
225 get_incoming (uint32_t id)
227 struct Incoming *incoming;
229 for (incoming = incoming_head; NULL != incoming; incoming = incoming->next)
230 if (incoming->suggest_id == id)
237 * Destroy a listener, free all resources associated with it.
239 * @param listener listener to destroy
242 listener_destroy (struct Listener *listener)
244 /* If the client is not dead yet, destroy it.
245 * The client's destroy callback will destroy the listener again. */
246 if (NULL != listener->client)
248 struct GNUNET_SERVER_Client *client = listener->client;
249 listener->client = NULL;
250 GNUNET_SERVER_client_disconnect (client);
253 if (NULL != listener->client_mq)
255 GNUNET_MQ_destroy (listener->client_mq);
256 listener->client_mq = NULL;
258 GNUNET_CONTAINER_DLL_remove (listeners_head, listeners_tail, listener);
259 GNUNET_free (listener);
264 * Destroy a set, and free all resources associated with it.
266 * @param set the set to destroy
269 set_destroy (struct Set *set)
271 /* If the client is not dead yet, destroy it.
272 * The client's destroy callback will destroy the set again. */
273 if (NULL != set->client)
275 struct GNUNET_SERVER_Client *client = set->client;
277 GNUNET_SERVER_client_disconnect (client);
280 if (NULL != set->client_mq)
282 GNUNET_MQ_destroy (set->client_mq);
283 set->client_mq = NULL;
285 GNUNET_assert (NULL != set->state);
286 set->vt->destroy_set (set->state);
288 GNUNET_CONTAINER_DLL_remove (sets_head, sets_tail, set);
294 * Clean up after a client after it is
295 * disconnected (either by us or by itself)
297 * @param cls closure, unused
298 * @param client the client to clean up after
301 handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
304 struct Listener *listener;
306 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "client disconnected, cleaning up\n");
308 set = set_get (client);
313 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "(client's set destroyed)\n");
315 listener = listener_get (client);
316 if (NULL != listener)
318 listener->client = NULL;
319 listener_destroy (listener);
320 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "(client's listener destroyed)\n");
326 * Destroy an incoming request from a remote peer
328 * @param incoming remote request to destroy
331 incoming_destroy (struct Incoming *incoming)
333 GNUNET_CONTAINER_DLL_remove (incoming_head, incoming_tail, incoming);
334 if (NULL != incoming->tunnel)
336 struct GNUNET_MESH_Tunnel *t = incoming->tunnel;
337 incoming->tunnel = NULL;
338 GNUNET_MESH_tunnel_destroy (t);
341 GNUNET_free (incoming);
345 static struct Listener *
346 listener_get_by_target (enum GNUNET_SET_OperationType op,
347 const struct GNUNET_HashCode *app_id)
351 for (l = listeners_head; NULL != l; l = l->next)
353 if (l->operation != op)
355 if (0 != GNUNET_CRYPTO_hash_cmp (app_id, &l->app_id))
364 * Suggest the given request to the listener,
365 * who can accept or reject the request.
367 * @param incoming the incoming peer with the request to suggest
368 * @param listener the listener to suggest the request to
371 incoming_suggest (struct Incoming *incoming, struct Listener *listener)
373 struct GNUNET_MQ_Envelope *mqm;
374 struct GNUNET_SET_RequestMessage *cmsg;
376 GNUNET_assert (0 == incoming->suggest_id);
377 GNUNET_assert (NULL != incoming->spec);
378 incoming->suggest_id = suggest_id++;
380 GNUNET_SCHEDULER_cancel (incoming->timeout_task);
381 mqm = GNUNET_MQ_msg_nested_mh (cmsg, GNUNET_MESSAGE_TYPE_SET_REQUEST,
382 incoming->spec->context_msg);
383 GNUNET_assert (NULL != mqm);
384 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "suggesting request with accept id %u\n", incoming->suggest_id);
385 cmsg->accept_id = htonl (incoming->suggest_id);
386 cmsg->peer_id = incoming->spec->peer;
387 GNUNET_MQ_send (listener->client_mq, mqm);
393 * Handle a request for a set operation from
396 * @param op the operation state
397 * @param mh the received message
398 * @return GNUNET_OK if the tunnel should be kept alive,
399 * GNUNET_SYSERR to destroy the tunnel
402 handle_incoming_msg (struct OperationState *op,
403 const struct GNUNET_MessageHeader *mh)
405 struct Incoming *incoming = (struct Incoming *) op;
406 const struct OperationRequestMessage *msg = (const struct OperationRequestMessage *) mh;
407 struct Listener *listener;
408 struct OperationSpecification *spec;
410 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "got op request\n");
412 if (GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST != ntohs (mh->type))
415 return GNUNET_SYSERR;
418 if (NULL != incoming->spec)
420 /* double operation request */
422 return GNUNET_SYSERR;
425 spec = GNUNET_new (struct OperationSpecification);
426 spec->context_msg = GNUNET_MQ_extract_nested_mh (msg);
427 if (NULL != spec->context_msg)
428 spec->context_msg = GNUNET_copy_message (spec->context_msg);
429 spec->operation = ntohl (msg->operation);
430 spec->app_id = msg->app_id;
431 spec->salt = ntohl (msg->salt);
432 spec->peer = incoming->peer;
434 incoming->spec = spec;
436 if ( (NULL != spec->context_msg) &&
437 (ntohs (spec->context_msg->size) > GNUNET_SET_CONTEXT_MESSAGE_MAX_SIZE) )
440 return GNUNET_SYSERR;
443 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "received P2P operation request (op %u, app %s)\n",
444 ntohs (msg->operation), GNUNET_h2s (&msg->app_id));
445 listener = listener_get_by_target (ntohs (msg->operation), &msg->app_id);
446 if (NULL == listener)
448 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
449 "no listener matches incoming request, waiting with timeout\n");
452 incoming_suggest (incoming, listener);
458 * Called when a client wants to create a new set.
461 * @param client client that sent the message
462 * @param m message sent by the client
465 handle_client_create (void *cls,
466 struct GNUNET_SERVER_Client *client,
467 const struct GNUNET_MessageHeader *m)
469 struct GNUNET_SET_CreateMessage *msg = (struct GNUNET_SET_CreateMessage *) m;
472 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "client created new set (operation %u)\n",
473 ntohs (msg->operation));
475 if (NULL != set_get (client))
478 GNUNET_SERVER_client_disconnect (client);
482 set = GNUNET_new (struct Set);
484 switch (ntohs (msg->operation))
486 case GNUNET_SET_OPERATION_INTERSECTION:
489 case GNUNET_SET_OPERATION_UNION:
490 set->vt = _GSS_union_vt ();
495 GNUNET_SERVER_client_disconnect (client);
499 set->state = set->vt->create ();
500 set->client = client;
501 set->client_mq = GNUNET_MQ_queue_for_server_client (client);
502 GNUNET_CONTAINER_DLL_insert (sets_head, sets_tail, set);
503 GNUNET_SERVER_receive_done (client, GNUNET_OK);
508 * Called when a client wants to create a new listener.
511 * @param client client that sent the message
512 * @param m message sent by the client
515 handle_client_listen (void *cls,
516 struct GNUNET_SERVER_Client *client,
517 const struct GNUNET_MessageHeader *m)
519 struct GNUNET_SET_ListenMessage *msg = (struct GNUNET_SET_ListenMessage *) m;
520 struct Listener *listener;
521 struct Incoming *incoming;
523 if (NULL != listener_get (client))
526 GNUNET_SERVER_client_disconnect (client);
529 listener = GNUNET_new (struct Listener);
530 listener->client = client;
531 listener->client_mq = GNUNET_MQ_queue_for_server_client (client);
532 listener->app_id = msg->app_id;
533 listener->operation = ntohs (msg->operation);
534 GNUNET_CONTAINER_DLL_insert_tail (listeners_head, listeners_tail, listener);
535 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "new listener created (op %u, app %s)\n",
536 listener->operation, GNUNET_h2s (&listener->app_id));
537 for (incoming = incoming_head; NULL != incoming; incoming = incoming->next)
539 if ( (NULL == incoming->spec) ||
540 (0 != incoming->suggest_id) )
542 if (listener->operation != incoming->spec->operation)
544 if (0 != GNUNET_CRYPTO_hash_cmp (&listener->app_id, &incoming->spec->app_id))
546 incoming_suggest (incoming, listener);
548 GNUNET_SERVER_receive_done (client, GNUNET_OK);
553 * Called when the client wants to reject an operation
554 * request from another peer.
557 * @param client client that sent the message
558 * @param m message sent by the client
561 handle_client_reject (void *cls,
562 struct GNUNET_SERVER_Client *client,
563 const struct GNUNET_MessageHeader *m)
565 struct Incoming *incoming;
566 const struct GNUNET_SET_AcceptRejectMessage *msg;
568 msg = (const struct GNUNET_SET_AcceptRejectMessage *) m;
569 GNUNET_break (0 == ntohl (msg->request_id));
571 incoming = get_incoming (ntohl (msg->accept_reject_id));
572 if (NULL == incoming)
574 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
577 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "peer request rejected by client\n");
578 GNUNET_MESH_tunnel_destroy (incoming->tunnel);
579 GNUNET_SERVER_receive_done (client, GNUNET_OK);
584 * Called when a client wants to add an element to a
588 * @param client client that sent the message
589 * @param m message sent by the client
592 handle_client_add_remove (void *cls,
593 struct GNUNET_SERVER_Client *client,
594 const struct GNUNET_MessageHeader *m)
597 const struct GNUNET_SET_ElementMessage *msg;
598 struct GNUNET_SET_Element el;
600 set = set_get (client);
604 GNUNET_SERVER_client_disconnect (client);
607 msg = (const struct GNUNET_SET_ElementMessage *) m;
608 el.size = ntohs (m->size) - sizeof *msg;
609 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
610 "client ins/rem element of size %u\n", el.size);
612 if (GNUNET_MESSAGE_TYPE_SET_REMOVE == ntohs (m->type))
613 set->vt->remove (set->state, &el);
615 set->vt->add (set->state, &el);
616 GNUNET_SERVER_receive_done (client, GNUNET_OK);
621 * Called when a client wants to evaluate a set operation with another peer.
624 * @param client client that sent the message
625 * @param m message sent by the client
628 handle_client_evaluate (void *cls,
629 struct GNUNET_SERVER_Client *client,
630 const struct GNUNET_MessageHeader *m)
633 struct TunnelContext *tc;
634 struct GNUNET_MESH_Tunnel *tunnel;
635 struct GNUNET_SET_EvaluateMessage *msg;
636 struct OperationSpecification *spec;
638 set = set_get (client);
642 GNUNET_SERVER_client_disconnect (client);
646 msg = (struct GNUNET_SET_EvaluateMessage *) m;
647 tc = GNUNET_new (struct TunnelContext);
648 spec = GNUNET_new (struct OperationSpecification);
649 spec->operation = set->operation;
650 spec->app_id = msg->app_id;
651 spec->salt = ntohl (msg->salt);
652 spec->peer = msg->target_peer;
654 spec->client_request_id = ntohl (msg->request_id);
656 tunnel = GNUNET_MESH_tunnel_create (mesh, tc, &msg->target_peer,
657 GNUNET_APPLICATION_TYPE_SET,
661 set->vt->evaluate (spec, tunnel, tc);
663 GNUNET_SERVER_receive_done (client, GNUNET_OK);
668 * Handle an ack from a client.
671 * @param client the client
672 * @param m the message
675 handle_client_ack (void *cls,
676 struct GNUNET_SERVER_Client *client,
677 const struct GNUNET_MessageHeader *m)
679 /* FIXME: implement */
680 GNUNET_SERVER_receive_done (client, GNUNET_OK);
685 * Handle a request from the client to accept
686 * a set operation that came from a remote peer.
689 * @param client the client
690 * @param mh the message
693 handle_client_cancel (void *cls,
694 struct GNUNET_SERVER_Client *client,
695 const struct GNUNET_MessageHeader *mh)
697 const struct GNUNET_SET_CancelMessage *msg =
698 (const struct GNUNET_SET_CancelMessage *) mh;
701 set = set_get (client);
705 GNUNET_SERVER_client_disconnect (client);
708 /* FIXME: maybe cancel should return success/error code? */
709 set->vt->cancel (set->state, ntohl (msg->request_id));
714 * Handle a request from the client to accept
715 * a set operation that came from a remote peer.
718 * @param client the client
719 * @param mh the message
722 handle_client_accept (void *cls,
723 struct GNUNET_SERVER_Client *client,
724 const struct GNUNET_MessageHeader *mh)
727 struct Incoming *incoming;
728 struct GNUNET_SET_AcceptRejectMessage *msg = (struct GNUNET_SET_AcceptRejectMessage *) mh;
730 incoming = get_incoming (ntohl (msg->accept_reject_id));
732 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "client accepting %u\n", ntohl (msg->accept_reject_id));
734 if (NULL == incoming)
738 GNUNET_SERVER_client_disconnect (client);
742 set = set_get (client);
747 GNUNET_SERVER_client_disconnect (client);
751 incoming->spec->set = set;
752 incoming->spec->client_request_id = ntohl (msg->request_id);
753 set->vt->accept (incoming->spec, incoming->tunnel, incoming->tc);
754 /* tunnel ownership goes to operation */
755 incoming->tunnel = NULL;
756 incoming_destroy (incoming);
757 GNUNET_SERVER_receive_done (client, GNUNET_OK);
762 * Called to clean up, after a shutdown has been requested.
765 * @param tc context information (why was this task triggered now)
768 shutdown_task (void *cls,
769 const struct GNUNET_SCHEDULER_TaskContext *tc)
771 while (NULL != incoming_head)
772 incoming_destroy (incoming_head);
774 while (NULL != listeners_head)
775 listener_destroy (listeners_head);
777 while (NULL != sets_head)
778 set_destroy (sets_head);
781 /* it's important to destroy mesh at the end, as tunnels
782 * must be destroyed first! */
785 GNUNET_MESH_disconnect (mesh);
789 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "handled shutdown request\n");
794 * Signature of the main function of a task.
797 * @param tc context information (why was this task triggered now)
800 incoming_timeout_cb (void *cls,
801 const struct GNUNET_SCHEDULER_TaskContext *tc)
803 struct Incoming *incoming = cls;
805 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "remote peer timed out\n");
806 incoming_destroy (incoming);
811 handle_incoming_disconnect (struct OperationState *op_state)
813 struct Incoming *incoming = (struct Incoming *) op_state;
814 if (NULL == incoming->tunnel)
817 incoming_destroy (incoming);
822 * Method called whenever another peer has added us to a tunnel
823 * the other peer initiated.
824 * Only called (once) upon reception of data with a message type which was
825 * subscribed to in GNUNET_MESH_connect. A call to GNUNET_MESH_tunnel_destroy
826 * causes te tunnel to be ignored and no further notifications are sent about
830 * @param tunnel new handle to the tunnel
831 * @param initiator peer that started the tunnel
832 * @param port Port this tunnel is for.
833 * @return initial tunnel context for the tunnel
834 * (can be NULL -- that's not an error)
837 tunnel_new_cb (void *cls,
838 struct GNUNET_MESH_Tunnel *tunnel,
839 const struct GNUNET_PeerIdentity *initiator,
842 struct Incoming *incoming;
843 static const struct SetVT incoming_vt = {
844 .msg_handler = handle_incoming_msg,
845 .peer_disconnect = handle_incoming_disconnect
848 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "new incoming tunnel\n");
850 GNUNET_assert (port == GNUNET_APPLICATION_TYPE_SET);
851 incoming = GNUNET_new (struct Incoming);
852 incoming->peer = *initiator;
853 incoming->tunnel = tunnel;
854 incoming->tc = GNUNET_new (struct TunnelContext);;
855 incoming->tc->vt = &incoming_vt;
856 incoming->tc->op = (struct OperationState *) incoming;
857 incoming->timeout_task =
858 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, incoming_timeout_cb, incoming);
859 GNUNET_CONTAINER_DLL_insert_tail (incoming_head, incoming_tail, incoming);
866 * Function called whenever a tunnel is destroyed. Should clean up
867 * any associated state.
868 * GNUNET_MESH_tunnel_destroy. It must NOT call GNUNET_MESH_tunnel_destroy on
871 * @param cls closure (set from GNUNET_MESH_connect)
872 * @param tunnel connection to the other end (henceforth invalid)
873 * @param tunnel_ctx place where local state associated
874 * with the tunnel is stored
877 tunnel_end_cb (void *cls,
878 const struct GNUNET_MESH_Tunnel *tunnel, void *tunnel_ctx)
880 struct TunnelContext *ctx = tunnel_ctx;
882 ctx->vt->peer_disconnect (ctx->op);
883 /* mesh will never call us with the context again! */
884 GNUNET_free (tunnel_ctx);
889 * Functions with this signature are called whenever a message is
892 * Each time the function must call GNUNET_MESH_receive_done on the tunnel
893 * in order to receive the next message. This doesn't need to be immediate:
894 * can be delayed if some processing is done on the message.
896 * @param cls Closure (set from GNUNET_MESH_connect).
897 * @param tunnel Connection to the other end.
898 * @param tunnel_ctx Place to store local state associated with the tunnel.
899 * @param message The actual message.
901 * @return GNUNET_OK to keep the tunnel open,
902 * GNUNET_SYSERR to close it (signal serious error).
905 dispatch_p2p_message (void *cls,
906 struct GNUNET_MESH_Tunnel *tunnel,
908 const struct GNUNET_MessageHeader *message)
910 struct TunnelContext *tc = *tunnel_ctx;
913 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "dispatching mesh message (type: %u)\n",
914 ntohs (message->type));
915 ret = tc->vt->msg_handler (tc->op, message);
916 GNUNET_MESH_receive_done (tunnel);
917 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "handled mesh message\n");
924 * Function called by the service's run
925 * method to run service-specific setup code.
928 * @param server the initialized server
929 * @param cfg configuration to use
932 run (void *cls, struct GNUNET_SERVER_Handle *server,
933 const struct GNUNET_CONFIGURATION_Handle *cfg)
935 static const struct GNUNET_SERVER_MessageHandler server_handlers[] = {
936 {handle_client_accept, NULL, GNUNET_MESSAGE_TYPE_SET_ACCEPT,
937 sizeof (struct GNUNET_SET_AcceptRejectMessage)},
938 {handle_client_ack, NULL, GNUNET_MESSAGE_TYPE_SET_ACK, 0},
939 {handle_client_add_remove, NULL, GNUNET_MESSAGE_TYPE_SET_ADD, 0},
940 {handle_client_create, NULL, GNUNET_MESSAGE_TYPE_SET_CREATE,
941 sizeof (struct GNUNET_SET_CreateMessage)},
942 {handle_client_evaluate, NULL, GNUNET_MESSAGE_TYPE_SET_EVALUATE, 0},
943 {handle_client_listen, NULL, GNUNET_MESSAGE_TYPE_SET_LISTEN,
944 sizeof (struct GNUNET_SET_ListenMessage)},
945 {handle_client_reject, NULL, GNUNET_MESSAGE_TYPE_SET_REJECT,
946 sizeof (struct GNUNET_SET_AcceptRejectMessage)},
947 {handle_client_add_remove, NULL, GNUNET_MESSAGE_TYPE_SET_REMOVE, 0},
948 {handle_client_cancel, NULL, GNUNET_MESSAGE_TYPE_SET_REMOVE,
949 sizeof (struct GNUNET_SET_CancelMessage)},
952 static const struct GNUNET_MESH_MessageHandler mesh_handlers[] = {
953 {dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, 0},
954 {dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_P2P_IBF, 0},
955 {dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS, 0},
956 {dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_P2P_DONE, 0},
957 {dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENT_REQUESTS, 0},
958 {dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_P2P_SE, 0},
961 static const uint32_t mesh_ports[] = {GNUNET_APPLICATION_TYPE_SET, 0};
964 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
965 &shutdown_task, NULL);
966 GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
967 GNUNET_SERVER_add_handlers (server, server_handlers);
969 mesh = GNUNET_MESH_connect (cfg, NULL, tunnel_new_cb, tunnel_end_cb,
970 mesh_handlers, mesh_ports);
973 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not connect to mesh\n");
977 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "started\n");
982 * The main function for the set service.
984 * @param argc number of arguments from the command line
985 * @param argv command line arguments
986 * @return 0 ok, 1 on error
989 main (int argc, char *const *argv)
992 ret = GNUNET_SERVICE_run (argc, argv, "set",
993 GNUNET_SERVICE_OPTION_NONE, &run, NULL);
994 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "exit\n");
995 return (GNUNET_OK == ret) ? 0 : 1;