2 This file is part of GNUnet
3 Copyright (C) 2013, 2014 GNUnet e.V.
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.
21 * @file set/gnunet-service-set.c
22 * @brief two-peer set operations
23 * @author Florian Dold
24 * @author Christian Grothoff
26 #include "gnunet-service-set.h"
27 #include "gnunet-service-set_protocol.h"
28 #include "gnunet_statistics_service.h"
31 * How long do we hold on to an incoming channel if there is
32 * no local listener before giving up?
34 #define INCOMING_CHANNEL_TIMEOUT GNUNET_TIME_UNIT_MINUTES
37 * A listener is inhabited by a client, and waits for evaluation
38 * requests from remote peers.
43 * Listeners are held in a doubly linked list.
45 struct Listener *next;
48 * Listeners are held in a doubly linked list.
50 struct Listener *prev;
53 * Client that owns the listener.
54 * Only one client may own a listener.
56 struct GNUNET_SERVER_Client *client;
59 * Message queue for the client
61 struct GNUNET_MQ_Handle *client_mq;
64 * Application ID for the operation, used to distinguish
65 * multiple operations of the same type with the same peer.
67 struct GNUNET_HashCode app_id;
70 * The port we are listening on with CADET.
72 struct GNUNET_CADET_Port *open_port;
75 * The type of the operation.
77 enum GNUNET_SET_OperationType operation;
81 struct LazyCopyRequest
83 struct Set *source_set;
86 struct LazyCopyRequest *prev;
87 struct LazyCopyRequest *next;
92 * Configuration of our local peer.
94 static const struct GNUNET_CONFIGURATION_Handle *configuration;
97 * Handle to the cadet service, used to listen for and connect to
100 static struct GNUNET_CADET_Handle *cadet;
103 * Sets are held in a doubly linked list.
105 static struct Set *sets_head;
108 * Sets are held in a doubly linked list.
110 static struct Set *sets_tail;
113 * Listeners are held in a doubly linked list.
115 static struct Listener *listeners_head;
118 * Listeners are held in a doubly linked list.
120 static struct Listener *listeners_tail;
123 * Incoming sockets from remote peers are held in a doubly linked
126 static struct Operation *incoming_head;
129 * Incoming sockets from remote peers are held in a doubly linked
132 static struct Operation *incoming_tail;
134 static struct LazyCopyRequest *lazy_copy_head;
135 static struct LazyCopyRequest *lazy_copy_tail;
137 static uint32_t lazy_copy_cookie = 1;
140 * Counter for allocating unique IDs for clients, used to identify
141 * incoming operation requests from remote peers, that the client can
142 * choose to accept or refuse.
144 static uint32_t suggest_id = 1;
149 struct GNUNET_STATISTICS_Handle *_GSS_statistics;
153 * Get set that is owned by the given client, if any.
155 * @param client client to look for
156 * @return set that the client owns, NULL if the client
160 set_get (struct GNUNET_SERVER_Client *client)
164 for (set = sets_head; NULL != set; set = set->next)
165 if (set->client == client)
172 * Get the listener associated with the given client, if any.
174 * @param client the client
175 * @return listener associated with the client, NULL
178 static struct Listener *
179 listener_get (struct GNUNET_SERVER_Client *client)
181 struct Listener *listener;
183 for (listener = listeners_head; NULL != listener; listener = listener->next)
184 if (listener->client == client)
191 * Get the incoming socket associated with the given id.
193 * @param id id to look for
194 * @return the incoming socket associated with the id,
195 * or NULL if there is none
197 static struct Operation *
198 get_incoming (uint32_t id)
200 struct Operation *op;
202 for (op = incoming_head; NULL != op; op = op->next)
203 if (op->suggest_id == id)
205 GNUNET_assert (GNUNET_YES == op->is_incoming);
213 * Destroy a listener, free all resources associated with it.
215 * @param listener listener to destroy
218 listener_destroy (struct Listener *listener)
220 /* If the client is not dead yet, destroy it.
221 * The client's destroy callback will destroy the listener again. */
222 if (NULL != listener->client)
224 struct GNUNET_SERVER_Client *client = listener->client;
226 listener->client = NULL;
227 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
228 "Disconnecting listener client\n");
229 GNUNET_SERVER_client_disconnect (client);
232 if (NULL != listener->client_mq)
234 GNUNET_MQ_destroy (listener->client_mq);
235 listener->client_mq = NULL;
237 GNUNET_CADET_close_port (listener->open_port);
238 GNUNET_CONTAINER_DLL_remove (listeners_head,
241 GNUNET_free (listener);
246 * Context for the #garbage_collect_cb().
248 struct GarbageContext
252 * Map for which we are garbage collecting removed elements.
254 struct GNUNET_CONTAINER_MultiHashMap *map;
257 * Lowest generation for which an operation is still pending.
259 unsigned int min_op_generation;
262 * Largest generation for which an operation is still pending.
264 unsigned int max_op_generation;
270 * Function invoked to check if an element can be removed from
271 * the set's history because it is no longer needed.
273 * @param cls the `struct GarbageContext *`
274 * @param key key of the element in the map
275 * @param value the `struct ElementEntry *`
276 * @return #GNUNET_OK (continue to iterate)
279 garbage_collect_cb (void *cls,
280 const struct GNUNET_HashCode *key,
283 //struct GarbageContext *gc = cls;
284 //struct ElementEntry *ee = value;
286 //if (GNUNET_YES != ee->removed)
288 //if ( (gc->max_op_generation < ee->generation_added) ||
289 // (ee->generation_removed > gc->min_op_generation) )
291 // GNUNET_assert (GNUNET_YES ==
292 // GNUNET_CONTAINER_multihashmap_remove (gc->map,
302 * Collect and destroy elements that are not needed anymore, because
303 * their lifetime (as determined by their generation) does not overlap
304 * with any active set operation.
306 * @param set set to garbage collect
309 collect_generation_garbage (struct Set *set)
311 struct Operation *op;
312 struct GarbageContext gc;
314 gc.min_op_generation = UINT_MAX;
315 gc.max_op_generation = 0;
316 for (op = set->ops_head; NULL != op; op = op->next)
318 gc.min_op_generation = GNUNET_MIN (gc.min_op_generation,
319 op->generation_created);
320 gc.max_op_generation = GNUNET_MAX (gc.max_op_generation,
321 op->generation_created);
323 gc.map = set->content->elements;
324 GNUNET_CONTAINER_multihashmap_iterate (set->content->elements,
331 is_excluded_generation (unsigned int generation,
332 struct GenerationRange *excluded,
333 unsigned int excluded_size)
337 for (i = 0; i < excluded_size; i++)
339 if ( (generation >= excluded[i].start) && (generation < excluded[i].end) )
348 is_element_of_generation (struct ElementEntry *ee,
349 unsigned int query_generation,
350 struct GenerationRange *excluded,
351 unsigned int excluded_size)
353 struct MutationEvent *mut;
357 GNUNET_assert (NULL != ee->mutations);
359 if (GNUNET_YES == is_excluded_generation (query_generation, excluded, excluded_size))
365 is_present = GNUNET_NO;
367 /* Could be made faster with binary search, but lists
368 are small, so why bother. */
369 for (i = 0; i < ee->mutations_size; i++)
371 mut = &ee->mutations[i];
373 if (mut->generation > query_generation)
375 /* The mutation doesn't apply to our generation
376 anymore. We can'b break here, since mutations aren't
377 sorted by generation. */
381 if (GNUNET_YES == is_excluded_generation (mut->generation, excluded, excluded_size))
383 /* The generation is excluded (because it belongs to another
384 fork via a lazy copy) and thus mutations aren't considered
385 for membership testing. */
389 /* This would be an inconsistency in how we manage mutations. */
390 if ( (GNUNET_YES == is_present) && (GNUNET_YES == mut->added) )
394 if ( (GNUNET_NO == is_present) && (GNUNET_NO == mut->added) )
397 is_present = mut->added;
405 _GSS_is_element_of_set (struct ElementEntry *ee,
408 return is_element_of_generation (ee,
409 set->current_generation,
410 set->excluded_generations,
411 set->excluded_generations_size);
416 is_element_of_iteration (struct ElementEntry *ee,
419 return is_element_of_generation (ee,
420 set->iter_generation,
421 set->excluded_generations,
422 set->excluded_generations_size);
427 _GSS_is_element_of_operation (struct ElementEntry *ee,
428 struct Operation *op)
430 return is_element_of_generation (ee,
431 op->generation_created,
432 op->spec->set->excluded_generations,
433 op->spec->set->excluded_generations_size);
438 * Destroy the given operation. Call the implementation-specific
439 * cancel function of the operation. Disconnects from the remote
440 * peer. Does not disconnect the client, as there may be multiple
441 * operations per set.
443 * @param op operation to destroy
444 * @param gc #GNUNET_YES to perform garbage collection on the set
447 _GSS_operation_destroy (struct Operation *op,
451 struct GNUNET_CADET_Channel *channel;
455 /* already in #_GSS_operation_destroy() */
458 GNUNET_assert (GNUNET_NO == op->is_incoming);
459 GNUNET_assert (NULL != op->spec);
461 GNUNET_CONTAINER_DLL_remove (set->ops_head,
466 if (NULL != op->spec)
468 if (NULL != op->spec->context_msg)
470 GNUNET_free (op->spec->context_msg);
471 op->spec->context_msg = NULL;
473 GNUNET_free (op->spec);
478 GNUNET_MQ_destroy (op->mq);
481 if (NULL != (channel = op->channel))
484 GNUNET_CADET_channel_destroy (channel);
486 if (GNUNET_YES == gc)
487 collect_generation_garbage (set);
488 /* We rely on the channel end handler to free 'op'. When 'op->channel' was NULL,
489 * there was a channel end handler that will free 'op' on the call stack. */
494 * Iterator over hash map entries to free element entries.
497 * @param key current key code
498 * @param value a `struct ElementEntry *` to be free'd
499 * @return #GNUNET_YES (continue to iterate)
502 destroy_elements_iterator (void *cls,
503 const struct GNUNET_HashCode *key,
506 struct ElementEntry *ee = value;
508 GNUNET_free_non_null (ee->mutations);
516 * Destroy a set, and free all resources and operations associated with it.
518 * @param set the set to destroy
521 set_destroy (struct Set *set)
523 if (NULL != set->client)
525 /* If the client is not dead yet, destroy it. The client's destroy
526 * callback will call `set_destroy()` again in this case. We do
527 * this so that the channel end handler still has a valid set handle
529 struct GNUNET_SERVER_Client *client = set->client;
532 GNUNET_SERVER_client_disconnect (client);
535 GNUNET_assert (NULL != set->state);
536 while (NULL != set->ops_head)
537 _GSS_operation_destroy (set->ops_head, GNUNET_NO);
538 set->vt->destroy_set (set->state);
540 if (NULL != set->client_mq)
542 GNUNET_MQ_destroy (set->client_mq);
543 set->client_mq = NULL;
545 if (NULL != set->iter)
547 GNUNET_CONTAINER_multihashmap_iterator_destroy (set->iter);
552 struct SetContent *content;
553 struct PendingMutation *pm;
554 struct PendingMutation *pm_current;
556 content = set->content;
558 // discard any pending mutations that reference this set
559 pm = content->pending_mutations_head;
564 if (pm_current-> set == set)
565 GNUNET_CONTAINER_DLL_remove (content->pending_mutations_head,
566 content->pending_mutations_tail,
572 GNUNET_assert (0 != content->refcount);
573 content->refcount -= 1;
574 if (0 == content->refcount)
576 GNUNET_assert (NULL != content->elements);
577 GNUNET_CONTAINER_multihashmap_iterate (content->elements,
578 &destroy_elements_iterator,
580 GNUNET_CONTAINER_multihashmap_destroy (content->elements);
581 content->elements = NULL;
582 GNUNET_free (content);
585 GNUNET_free_non_null (set->excluded_generations);
586 set->excluded_generations = NULL;
587 GNUNET_CONTAINER_DLL_remove (sets_head,
591 // remove set from pending copy requests
593 struct LazyCopyRequest *lcr;
594 lcr = lazy_copy_head;
597 struct LazyCopyRequest *lcr_current;
600 if (lcr_current->source_set == set)
601 GNUNET_CONTAINER_DLL_remove (lazy_copy_head,
612 * Clean up after a client has disconnected
614 * @param cls closure, unused
615 * @param client the client to clean up after
618 handle_client_disconnect (void *cls,
619 struct GNUNET_SERVER_Client *client)
621 struct Listener *listener;
624 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
625 "client disconnected, cleaning up\n");
626 set = set_get (client);
631 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
632 "Client's set destroyed\n");
634 listener = listener_get (client);
635 if (NULL != listener)
637 listener->client = NULL;
638 listener_destroy (listener);
639 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
640 "Client's listener destroyed\n");
646 * Destroy an incoming request from a remote peer
648 * @param incoming remote request to destroy
651 incoming_destroy (struct Operation *incoming)
653 struct GNUNET_CADET_Channel *channel;
655 GNUNET_assert (GNUNET_YES == incoming->is_incoming);
656 GNUNET_CONTAINER_DLL_remove (incoming_head,
659 if (NULL != incoming->timeout_task)
661 GNUNET_SCHEDULER_cancel (incoming->timeout_task);
662 incoming->timeout_task = NULL;
664 /* make sure that the tunnel end handler will not destroy us again */
666 if (NULL != incoming->spec)
668 GNUNET_free (incoming->spec);
669 incoming->spec = NULL;
671 if (NULL != incoming->mq)
673 GNUNET_MQ_destroy (incoming->mq);
676 if (NULL != (channel = incoming->channel))
678 incoming->channel = NULL;
679 GNUNET_CADET_channel_destroy (channel);
685 * Suggest the given request to the listener. The listening client can
686 * then accept or reject the remote request.
688 * @param incoming the incoming peer with the request to suggest
689 * @param listener the listener to suggest the request to
692 incoming_suggest (struct Operation *incoming,
693 struct Listener *listener)
695 struct GNUNET_MQ_Envelope *mqm;
696 struct GNUNET_SET_RequestMessage *cmsg;
698 GNUNET_assert (GNUNET_YES == incoming->is_incoming);
699 GNUNET_assert (NULL != incoming->spec);
700 GNUNET_assert (0 == incoming->suggest_id);
701 incoming->suggest_id = suggest_id++;
704 GNUNET_assert (NULL != incoming->timeout_task);
705 GNUNET_SCHEDULER_cancel (incoming->timeout_task);
706 incoming->timeout_task = NULL;
707 mqm = GNUNET_MQ_msg_nested_mh (cmsg,
708 GNUNET_MESSAGE_TYPE_SET_REQUEST,
709 incoming->spec->context_msg);
710 GNUNET_assert (NULL != mqm);
711 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
712 "Suggesting incoming request with accept id %u to listener\n",
713 incoming->suggest_id);
714 cmsg->accept_id = htonl (incoming->suggest_id);
715 cmsg->peer_id = incoming->spec->peer;
716 GNUNET_MQ_send (listener->client_mq,
722 * Handle a request for a set operation from another peer. Checks if we
723 * have a listener waiting for such a request (and in that case initiates
724 * asking the listener about accepting the connection). If no listener
725 * is waiting, we queue the operation request in hope that a listener
726 * shows up soon (before timeout).
728 * This msg is expected as the first and only msg handled through the
729 * non-operation bound virtual table, acceptance of this operation replaces
730 * our virtual table and subsequent msgs would be routed differently (as
731 * we then know what type of operation this is).
733 * @param op the operation state
734 * @param mh the received message
735 * @return #GNUNET_OK if the channel should be kept alive,
736 * #GNUNET_SYSERR to destroy the channel
739 handle_incoming_msg (struct Operation *op,
740 const struct GNUNET_MessageHeader *mh)
742 const struct OperationRequestMessage *msg;
743 struct Listener *listener = op->listener;
744 struct OperationSpecification *spec;
745 const struct GNUNET_MessageHeader *nested_context;
747 msg = (const struct OperationRequestMessage *) mh;
748 GNUNET_assert (GNUNET_YES == op->is_incoming);
749 if (GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST != ntohs (mh->type))
752 return GNUNET_SYSERR;
754 /* double operation request */
755 if (NULL != op->spec)
758 return GNUNET_SYSERR;
760 spec = GNUNET_new (struct OperationSpecification);
761 nested_context = GNUNET_MQ_extract_nested_mh (msg);
762 if ( (NULL != nested_context) &&
763 (ntohs (nested_context->size) > GNUNET_SET_CONTEXT_MESSAGE_MAX_SIZE) )
767 return GNUNET_SYSERR;
769 /* Make a copy of the nested_context (application-specific context
770 information that is opaque to set) so we can pass it to the
772 if (NULL != nested_context)
773 spec->context_msg = GNUNET_copy_message (nested_context);
774 spec->operation = ntohl (msg->operation);
775 spec->app_id = listener->app_id;
776 spec->salt = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
778 spec->peer = op->peer;
779 spec->remote_element_count = ntohl (msg->element_count);
782 listener = op->listener;
783 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
784 "Received P2P operation request (op %u, port %s) for active listener\n",
785 ntohl (msg->operation),
786 GNUNET_h2s (&listener->app_id));
787 incoming_suggest (op,
794 execute_add (struct Set *set,
795 const struct GNUNET_MessageHeader *m)
797 const struct GNUNET_SET_ElementMessage *msg;
798 struct GNUNET_SET_Element el;
799 struct ElementEntry *ee;
800 struct GNUNET_HashCode hash;
802 GNUNET_assert (GNUNET_MESSAGE_TYPE_SET_ADD == ntohs (m->type));
804 msg = (const struct GNUNET_SET_ElementMessage *) m;
805 el.size = ntohs (m->size) - sizeof *msg;
807 el.element_type = ntohs (msg->element_type);
808 GNUNET_SET_element_hash (&el, &hash);
809 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
810 "Client inserts element %s of size %u\n",
814 ee = GNUNET_CONTAINER_multihashmap_get (set->content->elements,
819 ee = GNUNET_malloc (el.size + sizeof *ee);
820 ee->element.size = el.size;
821 GNUNET_memcpy (&ee[1],
824 ee->element.data = &ee[1];
825 ee->element.element_type = el.element_type;
826 ee->remote = GNUNET_NO;
827 ee->mutations = NULL;
828 ee->mutations_size = 0;
829 ee->element_hash = hash;
830 GNUNET_break (GNUNET_YES ==
831 GNUNET_CONTAINER_multihashmap_put (set->content->elements,
834 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
836 else if (GNUNET_YES == _GSS_is_element_of_set (ee, set))
838 /* same element inserted twice */
843 struct MutationEvent mut = {
844 .generation = set->current_generation,
847 GNUNET_array_append (ee->mutations, ee->mutations_size, mut);
850 set->vt->add (set->state, ee);
855 execute_remove (struct Set *set,
856 const struct GNUNET_MessageHeader *m)
858 const struct GNUNET_SET_ElementMessage *msg;
859 struct GNUNET_SET_Element el;
860 struct ElementEntry *ee;
861 struct GNUNET_HashCode hash;
863 GNUNET_assert (GNUNET_MESSAGE_TYPE_SET_REMOVE == ntohs (m->type));
865 msg = (const struct GNUNET_SET_ElementMessage *) m;
866 el.size = ntohs (m->size) - sizeof *msg;
867 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
868 "Client removes element of size %u\n",
871 el.element_type = ntohs (msg->element_type);
872 GNUNET_SET_element_hash (&el, &hash);
873 ee = GNUNET_CONTAINER_multihashmap_get (set->content->elements,
877 /* Client tried to remove non-existing element. */
880 if (GNUNET_NO == _GSS_is_element_of_set (ee, set))
882 /* Client tried to remove element twice */
887 struct MutationEvent mut = {
888 .generation = set->current_generation,
891 GNUNET_array_append (ee->mutations, ee->mutations_size, mut);
893 set->vt->remove (set->state, ee);
899 execute_mutation (struct Set *set,
900 const struct GNUNET_MessageHeader *m)
902 switch (ntohs (m->type))
904 case GNUNET_MESSAGE_TYPE_SET_ADD:
905 execute_add (set, m);
907 case GNUNET_MESSAGE_TYPE_SET_REMOVE:
908 execute_remove (set, m);
918 * Send the next element of a set to the set's client. The next element is given by
919 * the set's current hashmap iterator. The set's iterator will be set to NULL if there
920 * are no more elements in the set. The caller must ensure that the set's iterator is
923 * The client will acknowledge each received element with a
924 * #GNUNET_MESSAGE_TYPE_SET_ITER_ACK message. Our
925 * #handle_client_iter_ack() will then trigger the next transmission.
926 * Note that the #GNUNET_MESSAGE_TYPE_SET_ITER_DONE is not acknowledged.
928 * @param set set that should send its next element to its client
931 send_client_element (struct Set *set)
934 struct ElementEntry *ee;
935 struct GNUNET_MQ_Envelope *ev;
936 struct GNUNET_SET_IterResponseMessage *msg;
938 GNUNET_assert (NULL != set->iter);
942 ret = GNUNET_CONTAINER_multihashmap_iterator_next (set->iter,
944 (const void **) &ee);
945 if (GNUNET_NO == ret)
947 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
948 "Iteration on %p done.\n",
950 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_ITER_DONE);
951 GNUNET_CONTAINER_multihashmap_iterator_destroy (set->iter);
955 GNUNET_assert (set->content->iterator_count > 0);
956 set->content->iterator_count -= 1;
958 if (0 == set->content->iterator_count)
960 while (NULL != set->content->pending_mutations_head)
962 struct PendingMutation *pm;
964 pm = set->content->pending_mutations_head;
965 GNUNET_CONTAINER_DLL_remove (set->content->pending_mutations_head,
966 set->content->pending_mutations_tail,
968 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
969 "Executing pending mutation on %p.\n",
971 execute_mutation (pm->set, pm->mutation_message);
972 GNUNET_free (pm->mutation_message);
980 GNUNET_assert (NULL != ee);
982 if (GNUNET_NO == is_element_of_iteration (ee, set))
985 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
986 "Sending iteration element on %p.\n",
988 ev = GNUNET_MQ_msg_extra (msg,
990 GNUNET_MESSAGE_TYPE_SET_ITER_ELEMENT);
991 GNUNET_memcpy (&msg[1],
994 msg->element_type = htons (ee->element.element_type);
995 msg->iteration_id = htons (set->iteration_id);
997 GNUNET_MQ_send (set->client_mq, ev);
1002 * Called when a client wants to iterate the elements of a set.
1003 * Checks if we have a set associated with the client and if we
1004 * can right now start an iteration. If all checks out, starts
1005 * sending the elements of the set to the client.
1008 * @param client client that sent the message
1009 * @param m message sent by the client
1012 handle_client_iterate (void *cls,
1013 struct GNUNET_SERVER_Client *client,
1014 const struct GNUNET_MessageHeader *m)
1018 set = set_get (client);
1021 /* attempt to iterate over a non existing set */
1023 GNUNET_SERVER_client_disconnect (client);
1026 if (NULL != set->iter)
1028 /* Only one concurrent iterate-action allowed per set */
1030 GNUNET_SERVER_client_disconnect (client);
1033 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1034 "Iterating set %p in gen %u with %u content elements\n",
1036 set->current_generation,
1037 GNUNET_CONTAINER_multihashmap_size (set->content->elements));
1038 GNUNET_SERVER_receive_done (client,
1040 set->content->iterator_count += 1;
1041 set->iter = GNUNET_CONTAINER_multihashmap_iterator_create (set->content->elements);
1042 set->iter_generation = set->current_generation;
1043 send_client_element (set);
1048 * Called when a client wants to create a new set. This is typically
1049 * the first request from a client, and includes the type of set
1050 * operation to be performed.
1053 * @param client client that sent the message
1054 * @param m message sent by the client
1057 handle_client_create_set (void *cls,
1058 struct GNUNET_SERVER_Client *client,
1059 const struct GNUNET_MessageHeader *m)
1061 const struct GNUNET_SET_CreateMessage *msg;
1064 msg = (const struct GNUNET_SET_CreateMessage *) m;
1065 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1066 "Client created new set (operation %u)\n",
1067 ntohl (msg->operation));
1068 if (NULL != set_get (client))
1070 /* There can only be one set per client */
1072 GNUNET_SERVER_client_disconnect (client);
1075 set = GNUNET_new (struct Set);
1076 switch (ntohl (msg->operation))
1078 case GNUNET_SET_OPERATION_INTERSECTION:
1079 set->vt = _GSS_intersection_vt ();
1081 case GNUNET_SET_OPERATION_UNION:
1082 set->vt = _GSS_union_vt ();
1087 GNUNET_SERVER_client_disconnect (client);
1090 set->operation = ntohl (msg->operation);
1091 set->state = set->vt->create ();
1092 if (NULL == set->state)
1094 /* initialization failed (i.e. out of memory) */
1096 GNUNET_SERVER_client_disconnect (client);
1099 set->content = GNUNET_new (struct SetContent);
1100 set->content->refcount = 1;
1101 set->content->elements = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_YES);
1102 set->client = client;
1103 set->client_mq = GNUNET_MQ_queue_for_server_client (client);
1104 GNUNET_CONTAINER_DLL_insert (sets_head,
1107 GNUNET_SERVER_receive_done (client,
1113 * Timeout happens iff:
1114 * - we suggested an operation to our listener,
1115 * but did not receive a response in time
1116 * - we got the channel from a peer but no #GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST
1118 * @param cls channel context
1119 * @param tc context information (why was this task triggered now)
1122 incoming_timeout_cb (void *cls)
1124 struct Operation *incoming = cls;
1126 incoming->timeout_task = NULL;
1127 GNUNET_assert (GNUNET_YES == incoming->is_incoming);
1128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1129 "Remote peer's incoming request timed out\n");
1130 incoming_destroy (incoming);
1135 * Terminates an incoming operation in case we have not yet received an
1136 * operation request. Called by the channel destruction handler.
1138 * @param op the channel context
1141 handle_incoming_disconnect (struct Operation *op)
1143 GNUNET_assert (GNUNET_YES == op->is_incoming);
1144 /* channel is already dead, incoming_destroy must not
1147 incoming_destroy (op);
1153 * Method called whenever another peer has added us to a channel the
1154 * other peer initiated. Only called (once) upon reception of data
1155 * from a channel we listen on.
1157 * The channel context represents the operation itself and gets added
1158 * to a DLL, from where it gets looked up when our local listener
1159 * client responds to a proposed/suggested operation or connects and
1160 * associates with this operation.
1162 * @param cls closure
1163 * @param channel new handle to the channel
1164 * @param initiator peer that started the channel
1165 * @param port Port this channel is for.
1166 * @param options Unused.
1167 * @return initial channel context for the channel
1168 * returns NULL on error
1171 channel_new_cb (void *cls,
1172 struct GNUNET_CADET_Channel *channel,
1173 const struct GNUNET_PeerIdentity *initiator,
1174 const struct GNUNET_HashCode *port,
1175 enum GNUNET_CADET_ChannelOption options)
1177 static const struct SetVT incoming_vt = {
1178 .msg_handler = &handle_incoming_msg,
1179 .peer_disconnect = &handle_incoming_disconnect
1181 struct Listener *listener = cls;
1182 struct Operation *incoming;
1184 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1185 "New incoming channel\n");
1186 incoming = GNUNET_new (struct Operation);
1187 incoming->listener = listener;
1188 incoming->is_incoming = GNUNET_YES;
1189 incoming->peer = *initiator;
1190 incoming->channel = channel;
1191 incoming->mq = GNUNET_CADET_mq_create (incoming->channel);
1192 incoming->vt = &incoming_vt;
1193 incoming->timeout_task
1194 = GNUNET_SCHEDULER_add_delayed (INCOMING_CHANNEL_TIMEOUT,
1195 &incoming_timeout_cb,
1197 GNUNET_CONTAINER_DLL_insert_tail (incoming_head,
1200 // incoming_suggest (incoming,
1207 * Called when a client wants to create a new listener.
1210 * @param client client that sent the message
1211 * @param m message sent by the client
1214 handle_client_listen (void *cls,
1215 struct GNUNET_SERVER_Client *client,
1216 const struct GNUNET_MessageHeader *m)
1218 const struct GNUNET_SET_ListenMessage *msg;
1219 struct Listener *listener;
1220 struct Operation *op;
1222 msg = (const struct GNUNET_SET_ListenMessage *) m;
1223 if (NULL != listener_get (client))
1225 /* max. one active listener per client! */
1227 GNUNET_SERVER_client_disconnect (client);
1230 listener = GNUNET_new (struct Listener);
1231 listener->client = client;
1232 listener->client_mq = GNUNET_MQ_queue_for_server_client (client);
1233 listener->app_id = msg->app_id;
1234 listener->operation = ntohl (msg->operation);
1235 GNUNET_CONTAINER_DLL_insert_tail (listeners_head,
1238 listener->open_port = GNUNET_CADET_open_port (cadet,
1242 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1243 "New listener created (op %u, port %s)\n",
1244 listener->operation,
1245 GNUNET_h2s (&listener->app_id));
1247 /* check for existing incoming requests the listener might be interested in */
1248 for (op = incoming_head; NULL != op; op = op->next)
1250 if (NULL == op->spec)
1251 continue; /* no details available yet */
1252 if (0 != op->suggest_id)
1253 continue; /* this one has been already suggested to a listener */
1254 if (listener->operation != op->spec->operation)
1255 continue; /* incompatible operation */
1256 if (0 != GNUNET_CRYPTO_hash_cmp (&listener->app_id,
1258 continue; /* incompatible appliation */
1259 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1260 "Found matching existing request\n");
1261 incoming_suggest (op,
1264 GNUNET_SERVER_receive_done (client,
1270 * Called when the listening client rejects an operation
1271 * request by another peer.
1274 * @param client client that sent the message
1275 * @param m message sent by the client
1278 handle_client_reject (void *cls,
1279 struct GNUNET_SERVER_Client *client,
1280 const struct GNUNET_MessageHeader *m)
1282 struct Operation *incoming;
1283 const struct GNUNET_SET_RejectMessage *msg;
1285 msg = (const struct GNUNET_SET_RejectMessage *) m;
1286 incoming = get_incoming (ntohl (msg->accept_reject_id));
1287 if (NULL == incoming)
1289 /* no matching incoming operation for this reject */
1291 GNUNET_SERVER_receive_done (client,
1295 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1296 "Peer request (op %u, app %s) rejected by client\n",
1297 incoming->spec->operation,
1298 GNUNET_h2s (&incoming->spec->app_id));
1299 GNUNET_CADET_channel_destroy (incoming->channel);
1300 GNUNET_SERVER_receive_done (client,
1307 * Called when a client wants to add or remove an element to a set it inhabits.
1310 * @param client client that sent the message
1311 * @param m message sent by the client
1314 handle_client_mutation (void *cls,
1315 struct GNUNET_SERVER_Client *client,
1316 const struct GNUNET_MessageHeader *m)
1320 set = set_get (client);
1323 /* client without a set requested an operation */
1325 GNUNET_SERVER_client_disconnect (client);
1329 GNUNET_SERVER_receive_done (client,
1332 if (0 != set->content->iterator_count)
1334 struct PendingMutation *pm;
1336 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1337 "Scheduling mutation on set\n");
1339 pm = GNUNET_new (struct PendingMutation);
1340 pm->mutation_message = GNUNET_copy_message (m);
1342 GNUNET_CONTAINER_DLL_insert (set->content->pending_mutations_head,
1343 set->content->pending_mutations_tail,
1348 execute_mutation (set, m);
1353 * Advance the current generation of a set,
1354 * adding exclusion ranges if necessary.
1356 * @param set the set where we want to advance the generation
1359 advance_generation (struct Set *set)
1361 struct GenerationRange r;
1363 if (set->current_generation == set->content->latest_generation)
1365 set->content->latest_generation += 1;
1366 set->current_generation += 1;
1370 GNUNET_assert (set->current_generation < set->content->latest_generation);
1372 r.start = set->current_generation + 1;
1373 r.end = set->content->latest_generation + 1;
1375 set->content->latest_generation = r.end;
1376 set->current_generation = r.end;
1378 GNUNET_array_append (set->excluded_generations,
1379 set->excluded_generations_size,
1385 * Called when a client wants to initiate a set operation with another
1386 * peer. Initiates the CADET connection to the listener and sends the
1390 * @param client client that sent the message
1391 * @param m message sent by the client
1394 handle_client_evaluate (void *cls,
1395 struct GNUNET_SERVER_Client *client,
1396 const struct GNUNET_MessageHeader *m)
1399 const struct GNUNET_SET_EvaluateMessage *msg;
1400 struct OperationSpecification *spec;
1401 struct Operation *op;
1402 const struct GNUNET_MessageHeader *context;
1404 set = set_get (client);
1408 GNUNET_SERVER_client_disconnect (client);
1411 msg = (const struct GNUNET_SET_EvaluateMessage *) m;
1412 spec = GNUNET_new (struct OperationSpecification);
1413 spec->operation = set->operation;
1414 spec->app_id = msg->app_id;
1415 spec->salt = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
1417 spec->peer = msg->target_peer;
1419 spec->result_mode = ntohl (msg->result_mode);
1420 spec->client_request_id = ntohl (msg->request_id);
1421 context = GNUNET_MQ_extract_nested_mh (msg);
1422 op = GNUNET_new (struct Operation);
1425 // Advance generation values, so that
1426 // mutations won't interfer with the running operation.
1427 op->generation_created = set->current_generation;
1428 advance_generation (set);
1431 GNUNET_CONTAINER_DLL_insert (set->ops_head,
1434 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1435 "Creating new CADET channel to port %s\n",
1436 GNUNET_h2s (&msg->app_id));
1437 op->channel = GNUNET_CADET_channel_create (cadet,
1441 GNUNET_CADET_OPTION_RELIABLE);
1442 op->mq = GNUNET_CADET_mq_create (op->channel);
1443 set->vt->evaluate (op,
1445 GNUNET_SERVER_receive_done (client,
1451 * Handle an ack from a client, and send the next element. Note
1452 * that we only expect acks for set elements, not after the
1453 * #GNUNET_MESSAGE_TYPE_SET_ITER_DONE message.
1456 * @param client the client
1457 * @param m the message
1460 handle_client_iter_ack (void *cls,
1461 struct GNUNET_SERVER_Client *client,
1462 const struct GNUNET_MessageHeader *m)
1464 const struct GNUNET_SET_IterAckMessage *ack;
1467 set = set_get (client);
1470 /* client without a set acknowledged receiving a value */
1472 GNUNET_SERVER_client_disconnect (client);
1475 if (NULL == set->iter)
1477 /* client sent an ack, but we were not expecting one (as
1478 set iteration has finished) */
1480 GNUNET_SERVER_client_disconnect (client);
1483 ack = (const struct GNUNET_SET_IterAckMessage *) m;
1484 GNUNET_SERVER_receive_done (client,
1486 if (ntohl (ack->send_more))
1488 send_client_element (set);
1492 GNUNET_CONTAINER_multihashmap_iterator_destroy (set->iter);
1494 set->iteration_id++;
1500 * Handle a request from the client to
1504 * @param client the client
1505 * @param mh the message
1508 handle_client_copy_lazy_prepare (void *cls,
1509 struct GNUNET_SERVER_Client *client,
1510 const struct GNUNET_MessageHeader *mh)
1513 struct LazyCopyRequest *cr;
1514 struct GNUNET_MQ_Envelope *ev;
1515 struct GNUNET_SET_CopyLazyResponseMessage *resp_msg;
1517 set = set_get (client);
1520 /* client without a set requested an operation */
1522 GNUNET_SERVER_client_disconnect (client);
1526 cr = GNUNET_new (struct LazyCopyRequest);
1528 cr->cookie = lazy_copy_cookie;
1529 lazy_copy_cookie += 1;
1530 cr->source_set = set;
1532 GNUNET_CONTAINER_DLL_insert (lazy_copy_head,
1537 ev = GNUNET_MQ_msg (resp_msg,
1538 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_RESPONSE);
1539 resp_msg->cookie = cr->cookie;
1540 GNUNET_MQ_send (set->client_mq, ev);
1543 GNUNET_SERVER_receive_done (client,
1546 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1547 "Client requested lazy copy\n");
1552 * Handle a request from the client to
1553 * connect to a copy of a set.
1556 * @param client the client
1557 * @param mh the message
1560 handle_client_copy_lazy_connect (void *cls,
1561 struct GNUNET_SERVER_Client *client,
1562 const struct GNUNET_MessageHeader *mh)
1564 struct LazyCopyRequest *cr;
1565 const struct GNUNET_SET_CopyLazyConnectMessage *msg =
1566 (const struct GNUNET_SET_CopyLazyConnectMessage *) mh;
1570 if (NULL != set_get (client))
1572 /* There can only be one set per client */
1574 GNUNET_SERVER_client_disconnect (client);
1580 for (cr = lazy_copy_head; NULL != cr; cr = cr->next)
1582 if (cr->cookie == msg->cookie)
1589 if (GNUNET_NO == found)
1591 /* client asked for copy with cookie we don't know */
1593 GNUNET_SERVER_client_disconnect (client);
1597 GNUNET_CONTAINER_DLL_remove (lazy_copy_head,
1601 set = GNUNET_new (struct Set);
1603 switch (cr->source_set->operation)
1605 case GNUNET_SET_OPERATION_INTERSECTION:
1606 set->vt = _GSS_intersection_vt ();
1608 case GNUNET_SET_OPERATION_UNION:
1609 set->vt = _GSS_union_vt ();
1616 if (NULL == set->vt->copy_state)
1618 /* Lazy copy not supported for this set operation */
1622 GNUNET_SERVER_client_disconnect (client);
1626 set->operation = cr->source_set->operation;
1627 set->state = set->vt->copy_state (cr->source_set);
1628 set->content = cr->source_set->content;
1629 set->content->refcount += 1;
1631 set->current_generation = cr->source_set->current_generation;
1632 set->excluded_generations_size = cr->source_set->excluded_generations_size;
1633 set->excluded_generations = GNUNET_memdup (cr->source_set->excluded_generations,
1634 set->excluded_generations_size * sizeof (struct GenerationRange));
1636 /* Advance the generation of the new set, so that mutations to the
1637 of the cloned set and the source set are independent. */
1638 advance_generation (set);
1641 set->client = client;
1642 set->client_mq = GNUNET_MQ_queue_for_server_client (client);
1643 GNUNET_CONTAINER_DLL_insert (sets_head,
1649 GNUNET_SERVER_receive_done (client,
1652 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1653 "Client connected to lazy set\n");
1658 * Handle a request from the client to
1659 * cancel a running set operation.
1662 * @param client the client
1663 * @param mh the message
1666 handle_client_cancel (void *cls,
1667 struct GNUNET_SERVER_Client *client,
1668 const struct GNUNET_MessageHeader *mh)
1670 const struct GNUNET_SET_CancelMessage *msg =
1671 (const struct GNUNET_SET_CancelMessage *) mh;
1673 struct Operation *op;
1676 set = set_get (client);
1679 /* client without a set requested an operation */
1681 GNUNET_SERVER_client_disconnect (client);
1684 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1685 "Client requested cancel for op %u\n",
1686 ntohl (msg->request_id));
1688 for (op = set->ops_head; NULL != op; op = op->next)
1690 if (op->spec->client_request_id == ntohl (msg->request_id))
1696 if (GNUNET_NO == found)
1698 /* It may happen that the operation was already destroyed due to
1699 * the other peer disconnecting. The client may not know about this
1700 * yet and try to cancel the (just barely non-existent) operation.
1701 * So this is not a hard error.
1703 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1704 "Client canceled non-existent op\n");
1708 _GSS_operation_destroy (op,
1711 GNUNET_SERVER_receive_done (client,
1717 * Handle a request from the client to accept a set operation that
1718 * came from a remote peer. We forward the accept to the associated
1719 * operation for handling
1722 * @param client the client
1723 * @param mh the message
1726 handle_client_accept (void *cls,
1727 struct GNUNET_SERVER_Client *client,
1728 const struct GNUNET_MessageHeader *mh)
1731 const struct GNUNET_SET_AcceptMessage *msg;
1732 struct Operation *op;
1733 struct GNUNET_SET_ResultMessage *result_message;
1734 struct GNUNET_MQ_Envelope *ev;
1736 msg = (const struct GNUNET_SET_AcceptMessage *) mh;
1737 set = set_get (client);
1740 /* client without a set requested to accept */
1742 GNUNET_SERVER_client_disconnect (client);
1745 op = get_incoming (ntohl (msg->accept_reject_id));
1748 /* It is not an error if the set op does not exist -- it may
1749 * have been destroyed when the partner peer disconnected. */
1750 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1751 "Client accepted request that is no longer active\n");
1752 ev = GNUNET_MQ_msg (result_message,
1753 GNUNET_MESSAGE_TYPE_SET_RESULT);
1754 result_message->request_id = msg->request_id;
1755 result_message->element_type = 0;
1756 result_message->result_status = htons (GNUNET_SET_STATUS_FAILURE);
1757 GNUNET_MQ_send (set->client_mq, ev);
1758 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1762 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1763 "Client accepting request %u\n",
1764 ntohl (msg->accept_reject_id));
1765 GNUNET_assert (GNUNET_YES == op->is_incoming);
1766 op->is_incoming = GNUNET_NO;
1767 GNUNET_CONTAINER_DLL_remove (incoming_head,
1770 op->spec->set = set;
1771 GNUNET_CONTAINER_DLL_insert (set->ops_head,
1774 op->spec->client_request_id = ntohl (msg->request_id);
1775 op->spec->result_mode = ntohl (msg->result_mode);
1777 // Advance generation values, so that
1778 // mutations won't interfer with the running operation.
1779 op->generation_created = set->current_generation;
1780 advance_generation (set);
1783 op->vt->accept (op);
1784 GNUNET_SERVER_receive_done (client,
1790 * Called to clean up, after a shutdown has been requested.
1792 * @param cls closure
1795 shutdown_task (void *cls)
1797 while (NULL != incoming_head)
1798 incoming_destroy (incoming_head);
1799 while (NULL != listeners_head)
1800 listener_destroy (listeners_head);
1801 while (NULL != sets_head)
1802 set_destroy (sets_head);
1804 /* it's important to destroy cadet at the end, as all channels
1805 * must be destroyed before the cadet handle! */
1808 GNUNET_CADET_disconnect (cadet);
1811 GNUNET_STATISTICS_destroy (_GSS_statistics, GNUNET_YES);
1812 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1813 "handled shutdown request\n");
1818 * Function called whenever a channel is destroyed. Should clean up
1819 * any associated state. It must NOT call
1820 * GNUNET_CADET_channel_destroy() on the channel.
1822 * The peer_disconnect function is part of a a virtual table set initially either
1823 * when a peer creates a new channel with us, or once we create
1824 * a new channel ourselves (evaluate).
1826 * Once we know the exact type of operation (union/intersection), the vt is
1827 * replaced with an operation specific instance (_GSS_[op]_vt).
1829 * @param cls closure (set from GNUNET_CADET_connect())
1830 * @param channel connection to the other end (henceforth invalid)
1831 * @param channel_ctx place where local state associated
1832 * with the channel is stored
1835 channel_end_cb (void *cls,
1836 const struct GNUNET_CADET_Channel *channel,
1839 struct Operation *op = channel_ctx;
1841 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1842 "channel_end_cb called\n");
1845 /* the vt can be null if a client already requested canceling op. */
1848 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1849 "calling peer disconnect due to channel end\n");
1850 op->vt->peer_disconnect (op);
1855 /* cadet will never call us with the context again! */
1858 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1859 "channel_end_cb finished\n");
1864 * Functions with this signature are called whenever a message is
1865 * received via a cadet channel.
1867 * The msg_handler is a virtual table set in initially either when a peer
1868 * creates a new channel with us, or once we create a new channel
1869 * ourselves (evaluate).
1871 * Once we know the exact type of operation (union/intersection), the vt is
1872 * replaced with an operation specific instance (_GSS_[op]_vt).
1874 * @param cls Closure (set from GNUNET_CADET_connect()).
1875 * @param channel Connection to the other end.
1876 * @param channel_ctx Place to store local state associated with the channel.
1877 * @param message The actual message.
1878 * @return #GNUNET_OK to keep the channel open,
1879 * #GNUNET_SYSERR to close it (signal serious error).
1882 dispatch_p2p_message (void *cls,
1883 struct GNUNET_CADET_Channel *channel,
1885 const struct GNUNET_MessageHeader *message)
1887 struct Operation *op = *channel_ctx;
1890 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1891 "Dispatching cadet message (type: %u)\n",
1892 ntohs (message->type));
1893 /* do this before the handler, as the handler might kill the channel */
1894 GNUNET_CADET_receive_done (channel);
1896 ret = op->vt->msg_handler (op,
1899 ret = GNUNET_SYSERR;
1900 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1901 "Handled cadet message (type: %u)\n",
1902 ntohs (message->type));
1908 * Function called by the service's run
1909 * method to run service-specific setup code.
1911 * @param cls closure
1912 * @param server the initialized server
1913 * @param cfg configuration to use
1917 struct GNUNET_SERVER_Handle *server,
1918 const struct GNUNET_CONFIGURATION_Handle *cfg)
1920 static const struct GNUNET_SERVER_MessageHandler server_handlers[] = {
1921 { &handle_client_accept, NULL,
1922 GNUNET_MESSAGE_TYPE_SET_ACCEPT,
1923 sizeof (struct GNUNET_SET_AcceptMessage)},
1924 { &handle_client_iter_ack, NULL,
1925 GNUNET_MESSAGE_TYPE_SET_ITER_ACK,
1926 sizeof (struct GNUNET_SET_IterAckMessage) },
1927 { &handle_client_mutation, NULL,
1928 GNUNET_MESSAGE_TYPE_SET_ADD,
1930 { &handle_client_create_set, NULL,
1931 GNUNET_MESSAGE_TYPE_SET_CREATE,
1932 sizeof (struct GNUNET_SET_CreateMessage)},
1933 { &handle_client_iterate, NULL,
1934 GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST,
1935 sizeof (struct GNUNET_MessageHeader)},
1936 { &handle_client_evaluate, NULL,
1937 GNUNET_MESSAGE_TYPE_SET_EVALUATE,
1939 { &handle_client_listen, NULL,
1940 GNUNET_MESSAGE_TYPE_SET_LISTEN,
1941 sizeof (struct GNUNET_SET_ListenMessage)},
1942 { &handle_client_reject, NULL,
1943 GNUNET_MESSAGE_TYPE_SET_REJECT,
1944 sizeof (struct GNUNET_SET_RejectMessage)},
1945 { &handle_client_mutation, NULL,
1946 GNUNET_MESSAGE_TYPE_SET_REMOVE,
1948 { &handle_client_cancel, NULL,
1949 GNUNET_MESSAGE_TYPE_SET_CANCEL,
1950 sizeof (struct GNUNET_SET_CancelMessage)},
1951 { &handle_client_copy_lazy_prepare, NULL,
1952 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_PREPARE,
1953 sizeof (struct GNUNET_MessageHeader)},
1954 { &handle_client_copy_lazy_connect, NULL,
1955 GNUNET_MESSAGE_TYPE_SET_COPY_LAZY_CONNECT,
1956 sizeof (struct GNUNET_SET_CopyLazyConnectMessage)},
1959 static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
1960 { &dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, 0},
1961 { &dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF, 0},
1962 { &dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS, 0},
1963 { &dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_UNION_P2P_OFFER, 0},
1964 { &dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_UNION_P2P_INQUIRY, 0},
1965 { &dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DEMAND, 0},
1966 { &dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENT_REQUESTS, 0},
1967 { &dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_UNION_P2P_DONE, 0},
1968 { &dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SE, 0},
1969 { &dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_UNION_P2P_SEC, 0},
1970 { &dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_ELEMENT_INFO, 0},
1971 { &dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_BF, 0},
1972 { &dispatch_p2p_message, GNUNET_MESSAGE_TYPE_SET_INTERSECTION_P2P_DONE, 0},
1976 configuration = cfg;
1977 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1978 GNUNET_SERVER_disconnect_notify (server,
1979 &handle_client_disconnect,
1981 GNUNET_SERVER_add_handlers (server,
1983 _GSS_statistics = GNUNET_STATISTICS_create ("set", cfg);
1984 cadet = GNUNET_CADET_connect (cfg,
1990 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1991 _("Could not connect to cadet service\n"));
1998 * The main function for the set service.
2000 * @param argc number of arguments from the command line
2001 * @param argv command line arguments
2002 * @return 0 ok, 1 on error
2010 ret = GNUNET_SERVICE_run (argc, argv, "set",
2011 GNUNET_SERVICE_OPTION_NONE,
2013 return (GNUNET_OK == ret) ? 0 : 1;
2016 /* end of gnunet-service-set.c */