diff options
author | Florian Dold <florian.dold@gmail.com> | 2013-06-19 10:48:54 +0000 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2013-06-19 10:48:54 +0000 |
commit | a900b29ddaa9ea46c731b054b5e3ef3e725b95a8 (patch) | |
tree | 52e1a9697b0abf4618cd5684359ec5f0a040898a /src/set | |
parent | 17353bc0a47c89bda205f23e7995377c9bfe7769 (diff) | |
download | gnunet-a900b29ddaa9ea46c731b054b5e3ef3e725b95a8.tar.gz gnunet-a900b29ddaa9ea46c731b054b5e3ef3e725b95a8.zip |
- opaque mq structs
- mq for mesh
- faster hashing for IBFs
- mesh replaces stream in set
- new set profiler (work in progress)
Diffstat (limited to 'src/set')
-rw-r--r-- | src/set/Makefile.am | 24 | ||||
-rw-r--r-- | src/set/gnunet-service-set.c | 278 | ||||
-rw-r--r-- | src/set/gnunet-service-set.h | 73 | ||||
-rw-r--r-- | src/set/gnunet-service-set_union.c | 212 | ||||
-rw-r--r-- | src/set/gnunet-set-ibf-profiler.c (renamed from src/set/gnunet-set-ibf.c) | 19 | ||||
-rw-r--r-- | src/set/gnunet-set-profiler.c | 320 | ||||
-rw-r--r-- | src/set/gnunet-set.c | 203 | ||||
-rw-r--r-- | src/set/ibf.c | 40 | ||||
-rw-r--r-- | src/set/ibf.h | 2 | ||||
-rw-r--r-- | src/set/set_api.c | 57 | ||||
-rw-r--r-- | src/set/strata_estimator.c | 2 | ||||
-rw-r--r-- | src/set/strata_estimator.h | 2 | ||||
-rw-r--r-- | src/set/test_set_api.c | 10 |
13 files changed, 755 insertions, 487 deletions
diff --git a/src/set/Makefile.am b/src/set/Makefile.am index 71e71c867..c2449e0ea 100644 --- a/src/set/Makefile.am +++ b/src/set/Makefile.am | |||
@@ -16,7 +16,7 @@ if USE_COVERAGE | |||
16 | endif | 16 | endif |
17 | 17 | ||
18 | bin_PROGRAMS = \ | 18 | bin_PROGRAMS = \ |
19 | gnunet-set | 19 | gnunet-set-profiler gnunet-set-ibf-profiler |
20 | 20 | ||
21 | libexec_PROGRAMS = \ | 21 | libexec_PROGRAMS = \ |
22 | gnunet-service-set | 22 | gnunet-service-set |
@@ -24,17 +24,24 @@ libexec_PROGRAMS = \ | |||
24 | lib_LTLIBRARIES = \ | 24 | lib_LTLIBRARIES = \ |
25 | libgnunetset.la | 25 | libgnunetset.la |
26 | 26 | ||
27 | gnunet_set_SOURCES = \ | 27 | gnunet_set_profiler_SOURCES = \ |
28 | gnunet-set.c | 28 | gnunet-set-profiler.c |
29 | gnunet_set_LDADD = \ | 29 | gnunet_set_profiler_LDADD = \ |
30 | $(top_builddir)/src/util/libgnunetutil.la \ | 30 | $(top_builddir)/src/util/libgnunetutil.la \ |
31 | $(top_builddir)/src/set/libgnunetset.la \ | 31 | $(top_builddir)/src/set/libgnunetset.la \ |
32 | $(top_builddir)/src/stream/libgnunetstream.la \ | 32 | $(top_builddir)/src/testing/libgnunettesting.la \ |
33 | $(top_builddir)/src/testbed/libgnunettestbed.la \ | ||
34 | $(GN_LIBINTL) | 33 | $(GN_LIBINTL) |
35 | gnunet_set_DEPENDENCIES = \ | 34 | gnunet_set_profiler_DEPENDENCIES = \ |
36 | libgnunetset.la | 35 | libgnunetset.la |
37 | 36 | ||
37 | |||
38 | gnunet_set_ibf_profiler_SOURCES = \ | ||
39 | gnunet-set-ibf-profiler.c \ | ||
40 | ibf.c | ||
41 | gnunet_set_ibf_profiler_LDADD = \ | ||
42 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
43 | $(GN_LIBINTL) | ||
44 | |||
38 | gnunet_service_set_SOURCES = \ | 45 | gnunet_service_set_SOURCES = \ |
39 | gnunet-service-set.c \ | 46 | gnunet-service-set.c \ |
40 | gnunet-service-set_union.c \ | 47 | gnunet-service-set_union.c \ |
@@ -43,8 +50,7 @@ gnunet_service_set_SOURCES = \ | |||
43 | gnunet_service_set_LDADD = \ | 50 | gnunet_service_set_LDADD = \ |
44 | $(top_builddir)/src/util/libgnunetutil.la \ | 51 | $(top_builddir)/src/util/libgnunetutil.la \ |
45 | $(top_builddir)/src/core/libgnunetcore.la \ | 52 | $(top_builddir)/src/core/libgnunetcore.la \ |
46 | $(top_builddir)/src/stream/libgnunetstream.la \ | 53 | $(top_builddir)/src/mesh/libgnunetmesh2.la \ |
47 | $(top_builddir)/src/mesh/libgnunetmesh.la \ | ||
48 | $(GN_LIBINTL) | 54 | $(GN_LIBINTL) |
49 | 55 | ||
50 | libgnunetset_la_SOURCES = \ | 56 | libgnunetset_la_SOURCES = \ |
diff --git a/src/set/gnunet-service-set.c b/src/set/gnunet-service-set.c index d2f0b48d5..bd934de84 100644 --- a/src/set/gnunet-service-set.c +++ b/src/set/gnunet-service-set.c | |||
@@ -29,13 +29,16 @@ | |||
29 | 29 | ||
30 | /** | 30 | /** |
31 | * Configuration of our local peer. | 31 | * Configuration of our local peer. |
32 | * (Not declared 'static' as also needed in gnunet-service-set_union.c) | ||
32 | */ | 33 | */ |
33 | const struct GNUNET_CONFIGURATION_Handle *configuration; | 34 | const struct GNUNET_CONFIGURATION_Handle *configuration; |
34 | 35 | ||
35 | /** | 36 | /** |
36 | * Socket listening for other peers via stream. | 37 | * Handle to the mesh service, used |
38 | * to listen for and connect to remote peers. | ||
39 | * (Not declared 'static' as also needed in gnunet-service-set_union.c) | ||
37 | */ | 40 | */ |
38 | static struct GNUNET_STREAM_ListenSocket *stream_listen_socket; | 41 | struct GNUNET_MESH_Handle *mesh; |
39 | 42 | ||
40 | /** | 43 | /** |
41 | * Sets are held in a doubly linked list. | 44 | * Sets are held in a doubly linked list. |
@@ -78,14 +81,14 @@ static uint32_t accept_id = 1; | |||
78 | 81 | ||
79 | 82 | ||
80 | /** | 83 | /** |
81 | * Get set that is owned by the client, if any. | 84 | * Get set that is owned by the given client, if any. |
82 | * | 85 | * |
83 | * @param client client to look for | 86 | * @param client client to look for |
84 | * @return set that the client owns, NULL if the client | 87 | * @return set that the client owns, NULL if the client |
85 | * does not own a set | 88 | * does not own a set |
86 | */ | 89 | */ |
87 | static struct Set * | 90 | static struct Set * |
88 | get_set (struct GNUNET_SERVER_Client *client) | 91 | set_get (struct GNUNET_SERVER_Client *client) |
89 | { | 92 | { |
90 | struct Set *set; | 93 | struct Set *set; |
91 | for (set = sets_head; NULL != set; set = set->next) | 94 | for (set = sets_head; NULL != set; set = set->next) |
@@ -137,7 +140,7 @@ get_incoming (uint32_t id) | |||
137 | * @param listener listener to destroy | 140 | * @param listener listener to destroy |
138 | */ | 141 | */ |
139 | static void | 142 | static void |
140 | destroy_listener (struct Listener *listener) | 143 | listener_destroy (struct Listener *listener) |
141 | { | 144 | { |
142 | if (NULL != listener->client_mq) | 145 | if (NULL != listener->client_mq) |
143 | { | 146 | { |
@@ -155,7 +158,7 @@ destroy_listener (struct Listener *listener) | |||
155 | * @param set the set to destroy | 158 | * @param set the set to destroy |
156 | */ | 159 | */ |
157 | static void | 160 | static void |
158 | destroy_set (struct Set *set) | 161 | set_destroy (struct Set *set) |
159 | { | 162 | { |
160 | switch (set->operation) | 163 | switch (set->operation) |
161 | { | 164 | { |
@@ -187,12 +190,12 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | |||
187 | struct Set *set; | 190 | struct Set *set; |
188 | struct Listener *listener; | 191 | struct Listener *listener; |
189 | 192 | ||
190 | set = get_set (client); | 193 | set = set_get (client); |
191 | if (NULL != set) | 194 | if (NULL != set) |
192 | destroy_set (set); | 195 | set_destroy (set); |
193 | listener = get_listener (client); | 196 | listener = get_listener (client); |
194 | if (NULL != listener) | 197 | if (NULL != listener) |
195 | destroy_listener (listener); | 198 | listener_destroy (listener); |
196 | } | 199 | } |
197 | 200 | ||
198 | 201 | ||
@@ -202,17 +205,14 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | |||
202 | * @param incoming remote request to destroy | 205 | * @param incoming remote request to destroy |
203 | */ | 206 | */ |
204 | static void | 207 | static void |
205 | destroy_incoming (struct Incoming *incoming) | 208 | incoming_destroy (struct Incoming *incoming) |
206 | { | 209 | { |
207 | if (NULL != incoming->mq) | 210 | if (NULL != incoming->tc) |
208 | { | 211 | { |
209 | GNUNET_MQ_destroy (incoming->mq); | 212 | GNUNET_free (incoming->tc); |
210 | incoming->mq = NULL; | 213 | GNUNET_assert (NULL != incoming->tc->tunnel); |
211 | } | 214 | GNUNET_MESH_tunnel_destroy (incoming->tc->tunnel); |
212 | if (NULL != incoming->socket) | 215 | incoming->tc = NULL; |
213 | { | ||
214 | GNUNET_STREAM_close (incoming->socket); | ||
215 | incoming->socket = NULL; | ||
216 | } | 216 | } |
217 | GNUNET_CONTAINER_DLL_remove (incoming_head, incoming_tail, incoming); | 217 | GNUNET_CONTAINER_DLL_remove (incoming_head, incoming_tail, incoming); |
218 | GNUNET_free (incoming); | 218 | GNUNET_free (incoming); |
@@ -237,6 +237,15 @@ get_listener_by_target (enum GNUNET_SET_OperationType op, | |||
237 | } | 237 | } |
238 | 238 | ||
239 | 239 | ||
240 | |||
241 | static void | ||
242 | tunnel_context_destroy (struct TunnelContext *tc) | ||
243 | { | ||
244 | GNUNET_free (tc); | ||
245 | /* FIXME destroy the rest */ | ||
246 | } | ||
247 | |||
248 | |||
240 | /** | 249 | /** |
241 | * Handle a request for a set operation from | 250 | * Handle a request for a set operation from |
242 | * another peer. | 251 | * another peer. |
@@ -244,16 +253,31 @@ get_listener_by_target (enum GNUNET_SET_OperationType op, | |||
244 | * @param cls the incoming socket | 253 | * @param cls the incoming socket |
245 | * @param mh the message | 254 | * @param mh the message |
246 | */ | 255 | */ |
247 | static void | 256 | static int |
248 | handle_p2p_operation_request (void *cls, const struct GNUNET_MessageHeader *mh) | 257 | handle_p2p_operation_request (void *cls, |
258 | struct GNUNET_MESH_Tunnel *tunnel, | ||
259 | void **tunnel_ctx, | ||
260 | const struct GNUNET_PeerIdentity *sender, | ||
261 | const struct GNUNET_MessageHeader *mh) | ||
249 | { | 262 | { |
250 | struct Incoming *incoming = cls; | 263 | struct TunnelContext *tc = *tunnel_ctx; |
264 | struct Incoming *incoming; | ||
251 | const struct OperationRequestMessage *msg = (const struct OperationRequestMessage *) mh; | 265 | const struct OperationRequestMessage *msg = (const struct OperationRequestMessage *) mh; |
252 | struct GNUNET_MQ_Message *mqm; | 266 | struct GNUNET_MQ_Envelope *mqm; |
253 | struct GNUNET_SET_RequestMessage *cmsg; | 267 | struct GNUNET_SET_RequestMessage *cmsg; |
254 | struct Listener *listener; | 268 | struct Listener *listener; |
255 | const struct GNUNET_MessageHeader *context_msg; | 269 | const struct GNUNET_MessageHeader *context_msg; |
256 | 270 | ||
271 | if (CONTEXT_INCOMING != tc->type) | ||
272 | { | ||
273 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "unexpected operation request\n"); | ||
274 | tunnel_context_destroy (tc); | ||
275 | /* don't kill the whole mesh connection */ | ||
276 | return GNUNET_OK; | ||
277 | } | ||
278 | |||
279 | incoming = tc->data; | ||
280 | |||
257 | context_msg = GNUNET_MQ_extract_nested_mh (msg); | 281 | context_msg = GNUNET_MQ_extract_nested_mh (msg); |
258 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "received P2P operation request (op %u, app %s)\n", | 282 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "received P2P operation request (op %u, app %s)\n", |
259 | ntohs (msg->operation), GNUNET_h2s (&msg->app_id)); | 283 | ntohs (msg->operation), GNUNET_h2s (&msg->app_id)); |
@@ -263,20 +287,26 @@ handle_p2p_operation_request (void *cls, const struct GNUNET_MessageHeader *mh) | |||
263 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 287 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
264 | "set operation request from peer failed: " | 288 | "set operation request from peer failed: " |
265 | "no set with matching application ID and operation type\n"); | 289 | "no set with matching application ID and operation type\n"); |
266 | return; | 290 | tunnel_context_destroy (tc); |
291 | /* don't kill the whole mesh connection */ | ||
292 | return GNUNET_OK; | ||
267 | } | 293 | } |
268 | mqm = GNUNET_MQ_msg_nested_mh (cmsg, GNUNET_MESSAGE_TYPE_SET_REQUEST, context_msg); | 294 | mqm = GNUNET_MQ_msg_nested_mh (cmsg, GNUNET_MESSAGE_TYPE_SET_REQUEST, context_msg); |
269 | if (NULL == mqm) | 295 | if (NULL == mqm) |
270 | { | 296 | { |
271 | /* FIXME: disconnect the peer */ | 297 | /* FIXME: disconnect the peer */ |
272 | GNUNET_break_op (0); | 298 | GNUNET_break_op (0); |
273 | return; | 299 | tunnel_context_destroy (tc); |
300 | /* don't kill the whole mesh connection */ | ||
301 | return GNUNET_OK; | ||
274 | } | 302 | } |
275 | incoming->accept_id = accept_id++; | 303 | incoming->accept_id = accept_id++; |
276 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "sending request with accept id %u\n", incoming->accept_id); | 304 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "sending request with accept id %u\n", incoming->accept_id); |
277 | cmsg->accept_id = htonl (incoming->accept_id); | 305 | cmsg->accept_id = htonl (incoming->accept_id); |
278 | cmsg->peer_id = incoming->peer; | 306 | cmsg->peer_id = incoming->tc->peer; |
279 | GNUNET_MQ_send (listener->client_mq, mqm); | 307 | GNUNET_MQ_send (listener->client_mq, mqm); |
308 | |||
309 | return GNUNET_OK; | ||
280 | } | 310 | } |
281 | 311 | ||
282 | 312 | ||
@@ -298,7 +328,7 @@ handle_client_create (void *cls, | |||
298 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "client created new set (operation %u)\n", | 328 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "client created new set (operation %u)\n", |
299 | ntohs (msg->operation)); | 329 | ntohs (msg->operation)); |
300 | 330 | ||
301 | if (NULL != get_set (client)) | 331 | if (NULL != set_get (client)) |
302 | { | 332 | { |
303 | GNUNET_break (0); | 333 | GNUNET_break (0); |
304 | GNUNET_SERVER_client_disconnect (client); | 334 | GNUNET_SERVER_client_disconnect (client); |
@@ -379,7 +409,7 @@ handle_client_remove (void *cls, | |||
379 | { | 409 | { |
380 | struct Set *set; | 410 | struct Set *set; |
381 | 411 | ||
382 | set = get_set (client); | 412 | set = set_get (client); |
383 | if (NULL == set) | 413 | if (NULL == set) |
384 | { | 414 | { |
385 | GNUNET_break (0); | 415 | GNUNET_break (0); |
@@ -428,7 +458,7 @@ handle_client_reject (void *cls, | |||
428 | return; | 458 | return; |
429 | } | 459 | } |
430 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "peer request rejected by client\n"); | 460 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "peer request rejected by client\n"); |
431 | destroy_incoming (incoming); | 461 | incoming_destroy (incoming); |
432 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 462 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
433 | } | 463 | } |
434 | 464 | ||
@@ -449,7 +479,7 @@ handle_client_add (void *cls, | |||
449 | { | 479 | { |
450 | struct Set *set; | 480 | struct Set *set; |
451 | 481 | ||
452 | set = get_set (client); | 482 | set = set_get (client); |
453 | if (NULL == set) | 483 | if (NULL == set) |
454 | { | 484 | { |
455 | GNUNET_break (0); | 485 | GNUNET_break (0); |
@@ -486,7 +516,7 @@ handle_client_evaluate (void *cls, | |||
486 | { | 516 | { |
487 | struct Set *set; | 517 | struct Set *set; |
488 | 518 | ||
489 | set = get_set (client); | 519 | set = set_get (client); |
490 | if (NULL == set) | 520 | if (NULL == set) |
491 | { | 521 | { |
492 | GNUNET_break (0); | 522 | GNUNET_break (0); |
@@ -558,8 +588,7 @@ handle_client_accept (void *cls, | |||
558 | return; | 588 | return; |
559 | } | 589 | } |
560 | 590 | ||
561 | 591 | set = set_get (client); | |
562 | set = get_set (client); | ||
563 | 592 | ||
564 | if (NULL == set) | 593 | if (NULL == set) |
565 | { | 594 | { |
@@ -584,51 +613,12 @@ handle_client_accept (void *cls, | |||
584 | 613 | ||
585 | /* note: _GSS_*_accept has to make sure the socket and mq are set to NULL, | 614 | /* note: _GSS_*_accept has to make sure the socket and mq are set to NULL, |
586 | * otherwise they will be destroyed and disconnected */ | 615 | * otherwise they will be destroyed and disconnected */ |
587 | destroy_incoming (incoming); | 616 | incoming_destroy (incoming); |
588 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 617 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
589 | } | 618 | } |
590 | 619 | ||
591 | 620 | ||
592 | /** | 621 | /** |
593 | * Functions of this type are called upon new stream connection from other peers | ||
594 | * or upon binding error which happen when the app_port given in | ||
595 | * GNUNET_STREAM_listen() is already taken. | ||
596 | * | ||
597 | * @param cls the closure from GNUNET_STREAM_listen | ||
598 | * @param socket the socket representing the stream; NULL on binding error | ||
599 | * @param initiator the identity of the peer who wants to establish a stream | ||
600 | * with us; NULL on binding error | ||
601 | * @return GNUNET_OK to keep the socket open, GNUNET_SYSERR to close the | ||
602 | * stream (the socket will be invalid after the call) | ||
603 | */ | ||
604 | static int | ||
605 | stream_listen_cb (void *cls, | ||
606 | struct GNUNET_STREAM_Socket *socket, | ||
607 | const struct GNUNET_PeerIdentity *initiator) | ||
608 | { | ||
609 | struct Incoming *incoming; | ||
610 | static const struct GNUNET_MQ_Handler handlers[] = { | ||
611 | {handle_p2p_operation_request, GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST}, | ||
612 | GNUNET_MQ_HANDLERS_END | ||
613 | }; | ||
614 | |||
615 | if (NULL == socket) | ||
616 | { | ||
617 | GNUNET_break (0); | ||
618 | return GNUNET_SYSERR; | ||
619 | } | ||
620 | |||
621 | incoming = GNUNET_new (struct Incoming); | ||
622 | incoming->peer = *initiator; | ||
623 | incoming->socket = socket; | ||
624 | incoming->mq = GNUNET_STREAM_mq_create (incoming->socket, handlers, NULL, incoming); | ||
625 | /* FIXME: timeout for peers that only connect but don't send anything */ | ||
626 | GNUNET_CONTAINER_DLL_insert_tail (incoming_head, incoming_tail, incoming); | ||
627 | return GNUNET_OK; | ||
628 | } | ||
629 | |||
630 | |||
631 | /** | ||
632 | * Called to clean up, after a shutdown has been requested. | 622 | * Called to clean up, after a shutdown has been requested. |
633 | * | 623 | * |
634 | * @param cls closure | 624 | * @param cls closure |
@@ -638,31 +628,126 @@ static void | |||
638 | shutdown_task (void *cls, | 628 | shutdown_task (void *cls, |
639 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 629 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
640 | { | 630 | { |
641 | if (NULL != stream_listen_socket) | 631 | if (NULL != mesh) |
642 | { | 632 | { |
643 | GNUNET_STREAM_listen_close (stream_listen_socket); | 633 | GNUNET_MESH_disconnect (mesh); |
644 | stream_listen_socket = NULL; | 634 | mesh = NULL; |
645 | } | 635 | } |
646 | 636 | ||
647 | while (NULL != incoming_head) | 637 | while (NULL != incoming_head) |
648 | { | 638 | { |
649 | destroy_incoming (incoming_head); | 639 | incoming_destroy (incoming_head); |
650 | } | 640 | } |
651 | 641 | ||
652 | while (NULL != listeners_head) | 642 | while (NULL != listeners_head) |
653 | { | 643 | { |
654 | destroy_listener (listeners_head); | 644 | listener_destroy (listeners_head); |
655 | } | 645 | } |
656 | 646 | ||
657 | while (NULL != sets_head) | 647 | while (NULL != sets_head) |
658 | { | 648 | { |
659 | destroy_set (sets_head); | 649 | set_destroy (sets_head); |
660 | } | 650 | } |
661 | 651 | ||
662 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "handled shutdown request\n"); | 652 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "handled shutdown request\n"); |
663 | } | 653 | } |
664 | 654 | ||
665 | 655 | ||
656 | |||
657 | /** | ||
658 | * Signature of the main function of a task. | ||
659 | * | ||
660 | * @param cls closure | ||
661 | * @param tc context information (why was this task triggered now) | ||
662 | */ | ||
663 | static void | ||
664 | incoming_timeout_cb (void *cls, | ||
665 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
666 | { | ||
667 | struct Incoming *incoming = cls; | ||
668 | |||
669 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "remote peer timed out"); | ||
670 | incoming_destroy (incoming); | ||
671 | } | ||
672 | |||
673 | |||
674 | /** | ||
675 | * Method called whenever another peer has added us to a tunnel | ||
676 | * the other peer initiated. | ||
677 | * Only called (once) upon reception of data with a message type which was | ||
678 | * subscribed to in GNUNET_MESH_connect. A call to GNUNET_MESH_tunnel_destroy | ||
679 | * causes te tunnel to be ignored and no further notifications are sent about | ||
680 | * the same tunnel. | ||
681 | * | ||
682 | * @param cls closure | ||
683 | * @param tunnel new handle to the tunnel | ||
684 | * @param initiator peer that started the tunnel | ||
685 | * @param port Port this tunnel is for. | ||
686 | * @return initial tunnel context for the tunnel | ||
687 | * (can be NULL -- that's not an error) | ||
688 | */ | ||
689 | static void * | ||
690 | tunnel_new_cb (void *cls, | ||
691 | struct GNUNET_MESH_Tunnel *tunnel, | ||
692 | const struct GNUNET_PeerIdentity *initiator, | ||
693 | uint32_t port) | ||
694 | { | ||
695 | struct Incoming *incoming; | ||
696 | struct TunnelContext *tc; | ||
697 | |||
698 | GNUNET_assert (port == GNUNET_APPLICATION_TYPE_SET); | ||
699 | tc = GNUNET_new (struct TunnelContext); | ||
700 | incoming = GNUNET_new (struct Incoming); | ||
701 | incoming->tc = tc; | ||
702 | tc->peer = *initiator; | ||
703 | tc->tunnel = tunnel; | ||
704 | tc->mq = GNUNET_MESH_mq_create (tunnel); | ||
705 | tc->data = incoming; | ||
706 | tc->type = CONTEXT_INCOMING; | ||
707 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, incoming_timeout_cb, incoming); | ||
708 | GNUNET_CONTAINER_DLL_insert_tail (incoming_head, incoming_tail, incoming); | ||
709 | |||
710 | return tc; | ||
711 | } | ||
712 | |||
713 | |||
714 | /** | ||
715 | * Function called whenever a tunnel is destroyed. Should clean up | ||
716 | * any associated state. This function is NOT called if the client has | ||
717 | * explicitly asked for the tunnel to be destroyed using | ||
718 | * GNUNET_MESH_tunnel_destroy. It must NOT call GNUNET_MESH_tunnel_destroy on | ||
719 | * the tunnel. | ||
720 | * | ||
721 | * @param cls closure (set from GNUNET_MESH_connect) | ||
722 | * @param tunnel connection to the other end (henceforth invalid) | ||
723 | * @param tunnel_ctx place where local state associated | ||
724 | * with the tunnel is stored | ||
725 | */ | ||
726 | static void | ||
727 | tunnel_end_cb (void *cls, | ||
728 | const struct GNUNET_MESH_Tunnel *tunnel, void *tunnel_ctx) | ||
729 | { | ||
730 | struct TunnelContext *ctx = tunnel_ctx; | ||
731 | |||
732 | switch (ctx->type) | ||
733 | { | ||
734 | case CONTEXT_INCOMING: | ||
735 | incoming_destroy ((struct Incoming *) ctx->data); | ||
736 | break; | ||
737 | case CONTEXT_OPERATION_UNION: | ||
738 | _GSS_union_operation_destroy ((struct UnionEvaluateOperation *) ctx->data); | ||
739 | break; | ||
740 | case CONTEXT_OPERATION_INTERSECTION: | ||
741 | GNUNET_assert (0); | ||
742 | /* FIXME: cfuchs */ | ||
743 | break; | ||
744 | default: | ||
745 | GNUNET_assert (0); | ||
746 | } | ||
747 | |||
748 | } | ||
749 | |||
750 | |||
666 | /** | 751 | /** |
667 | * Function called by the service's run | 752 | * Function called by the service's run |
668 | * method to run service-specific setup code. | 753 | * method to run service-specific setup code. |
@@ -686,16 +771,40 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
686 | {handle_client_remove, NULL, GNUNET_MESSAGE_TYPE_SET_REMOVE, 0}, | 771 | {handle_client_remove, NULL, GNUNET_MESSAGE_TYPE_SET_REMOVE, 0}, |
687 | {NULL, NULL, 0, 0} | 772 | {NULL, NULL, 0, 0} |
688 | }; | 773 | }; |
774 | static const struct GNUNET_MESH_MessageHandler mesh_handlers[] = { | ||
775 | {handle_p2p_operation_request, | ||
776 | GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, 0}, | ||
777 | /* messages for the union operation */ | ||
778 | {_GSS_union_handle_p2p_message, | ||
779 | GNUNET_MESSAGE_TYPE_SET_P2P_IBF, 0}, | ||
780 | {_GSS_union_handle_p2p_message, | ||
781 | GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS, 0}, | ||
782 | {_GSS_union_handle_p2p_message, | ||
783 | GNUNET_MESSAGE_TYPE_SET_P2P_DONE, 0}, | ||
784 | {_GSS_union_handle_p2p_message, | ||
785 | GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENT_REQUESTS, 0}, | ||
786 | {_GSS_union_handle_p2p_message, | ||
787 | GNUNET_MESSAGE_TYPE_SET_P2P_SE, 0}, | ||
788 | /* FIXME: messages for intersection operation */ | ||
789 | {NULL, 0, 0} | ||
790 | }; | ||
791 | static const uint32_t mesh_ports[] = {GNUNET_APPLICATION_TYPE_SET, 0}; | ||
689 | 792 | ||
690 | configuration = cfg; | 793 | configuration = cfg; |
691 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, NULL); | 794 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
795 | &shutdown_task, NULL); | ||
692 | GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); | 796 | GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); |
693 | GNUNET_SERVER_add_handlers (server, server_handlers); | 797 | GNUNET_SERVER_add_handlers (server, server_handlers); |
694 | stream_listen_socket = GNUNET_STREAM_listen (cfg, GNUNET_APPLICATION_TYPE_SET, | ||
695 | &stream_listen_cb, NULL, | ||
696 | GNUNET_STREAM_OPTION_END); | ||
697 | 798 | ||
698 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "set service running\n"); | 799 | mesh = GNUNET_MESH_connect (cfg, NULL, tunnel_new_cb, tunnel_end_cb, |
800 | mesh_handlers, mesh_ports); | ||
801 | if (NULL == mesh) | ||
802 | { | ||
803 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not connect to mesh\n"); | ||
804 | return; | ||
805 | } | ||
806 | |||
807 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "service started\n"); | ||
699 | } | 808 | } |
700 | 809 | ||
701 | 810 | ||
@@ -710,7 +819,8 @@ int | |||
710 | main (int argc, char *const *argv) | 819 | main (int argc, char *const *argv) |
711 | { | 820 | { |
712 | int ret; | 821 | int ret; |
713 | ret = GNUNET_SERVICE_run (argc, argv, "set", GNUNET_SERVICE_OPTION_NONE, &run, NULL); | 822 | ret = GNUNET_SERVICE_run (argc, argv, "set", |
823 | GNUNET_SERVICE_OPTION_NONE, &run, NULL); | ||
714 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "exit\n"); | 824 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "exit\n"); |
715 | return (GNUNET_OK == ret) ? 0 : 1; | 825 | return (GNUNET_OK == ret) ? 0 : 1; |
716 | } | 826 | } |
diff --git a/src/set/gnunet-service-set.h b/src/set/gnunet-service-set.h index 15199eba4..66bff4ff1 100644 --- a/src/set/gnunet-service-set.h +++ b/src/set/gnunet-service-set.h | |||
@@ -33,7 +33,7 @@ | |||
33 | #include "gnunet_applications.h" | 33 | #include "gnunet_applications.h" |
34 | #include "gnunet_util_lib.h" | 34 | #include "gnunet_util_lib.h" |
35 | #include "gnunet_core_service.h" | 35 | #include "gnunet_core_service.h" |
36 | #include "gnunet_stream_lib.h" | 36 | #include "gnunet_mesh2_service.h" |
37 | #include "gnunet_set_service.h" | 37 | #include "gnunet_set_service.h" |
38 | #include "set.h" | 38 | #include "set.h" |
39 | 39 | ||
@@ -47,6 +47,8 @@ struct IntersectionState; | |||
47 | */ | 47 | */ |
48 | struct UnionState; | 48 | struct UnionState; |
49 | 49 | ||
50 | struct UnionEvaluateOperation; | ||
51 | |||
50 | 52 | ||
51 | /** | 53 | /** |
52 | * A set that supports a specific operation | 54 | * A set that supports a specific operation |
@@ -63,7 +65,7 @@ struct Set | |||
63 | /** | 65 | /** |
64 | * Message queue for the client | 66 | * Message queue for the client |
65 | */ | 67 | */ |
66 | struct GNUNET_MQ_MessageQueue *client_mq; | 68 | struct GNUNET_MQ_Handle *client_mq; |
67 | 69 | ||
68 | /** | 70 | /** |
69 | * Type of operation supported for this set | 71 | * Type of operation supported for this set |
@@ -116,7 +118,7 @@ struct Listener | |||
116 | /** | 118 | /** |
117 | * Message queue for the client | 119 | * Message queue for the client |
118 | */ | 120 | */ |
119 | struct GNUNET_MQ_MessageQueue *client_mq; | 121 | struct GNUNET_MQ_Handle *client_mq; |
120 | 122 | ||
121 | /** | 123 | /** |
122 | * Type of operation supported for this set | 124 | * Type of operation supported for this set |
@@ -148,19 +150,17 @@ struct Incoming | |||
148 | struct Incoming *prev; | 150 | struct Incoming *prev; |
149 | 151 | ||
150 | /** | 152 | /** |
151 | * Identity of the peer that connected to us | 153 | * Tunnel context, stores information about |
154 | * the tunnel and its peer. | ||
152 | */ | 155 | */ |
153 | struct GNUNET_PeerIdentity peer; | 156 | struct TunnelContext *tc; |
154 | 157 | ||
155 | /** | 158 | /** |
156 | * Socket connected to the peer | 159 | * GNUNET_YES if the incoming peer has sent |
160 | * an operation request (and we are waiting | ||
161 | * for the client to ack/nack), GNUNET_NO otherwise. | ||
157 | */ | 162 | */ |
158 | struct GNUNET_STREAM_Socket *socket; | 163 | int received_request; |
159 | |||
160 | /** | ||
161 | * Message queue for the peer | ||
162 | */ | ||
163 | struct GNUNET_MQ_MessageQueue *mq; | ||
164 | 164 | ||
165 | /** | 165 | /** |
166 | * App code, set once the peer has | 166 | * App code, set once the peer has |
@@ -187,18 +187,37 @@ struct Incoming | |||
187 | 187 | ||
188 | /** | 188 | /** |
189 | * Unique request id for the request from | 189 | * Unique request id for the request from |
190 | * a remote peer, sent to the client with will | 190 | * a remote peer, sent to the client, which will |
191 | * accept or reject the request. | 191 | * accept or reject the request. |
192 | */ | 192 | */ |
193 | uint32_t accept_id; | 193 | uint32_t accept_id; |
194 | }; | 194 | }; |
195 | 195 | ||
196 | 196 | ||
197 | enum TunnelContextType { | ||
198 | CONTEXT_INCOMING, | ||
199 | CONTEXT_OPERATION_UNION, | ||
200 | CONTEXT_OPERATION_INTERSECTION, | ||
201 | }; | ||
202 | |||
203 | struct TunnelContext | ||
204 | { | ||
205 | struct GNUNET_MESH_Tunnel *tunnel; | ||
206 | struct GNUNET_PeerIdentity peer; | ||
207 | struct GNUNET_MQ_Handle *mq; | ||
208 | enum TunnelContextType type; | ||
209 | void *data; | ||
210 | }; | ||
211 | |||
212 | |||
213 | |||
197 | /** | 214 | /** |
198 | * Configuration of the local peer | 215 | * Configuration of the local peer |
199 | */ | 216 | */ |
200 | extern const struct GNUNET_CONFIGURATION_Handle *configuration; | 217 | extern const struct GNUNET_CONFIGURATION_Handle *configuration; |
201 | 218 | ||
219 | extern struct GNUNET_MESH_Handle *mesh; | ||
220 | |||
202 | 221 | ||
203 | /** | 222 | /** |
204 | * Create a new set supporting the union operation | 223 | * Create a new set supporting the union operation |
@@ -262,4 +281,32 @@ _GSS_union_accept (struct GNUNET_SET_AcceptRejectMessage *m, struct Set *set, | |||
262 | struct Incoming *incoming); | 281 | struct Incoming *incoming); |
263 | 282 | ||
264 | 283 | ||
284 | /** | ||
285 | * Destroy a union operation, and free all resources | ||
286 | * associated with it. | ||
287 | * | ||
288 | * @param eo the union operation to destroy | ||
289 | */ | ||
290 | void | ||
291 | _GSS_union_operation_destroy (struct UnionEvaluateOperation *eo); | ||
292 | |||
293 | |||
294 | /** | ||
295 | * Dispatch messages for a union operation. | ||
296 | * | ||
297 | * @param cls closure | ||
298 | * @param tunnel mesh tunnel | ||
299 | * @param tunnel_ctx tunnel context | ||
300 | * @param sender ??? | ||
301 | * @param mh message to process | ||
302 | * @return ??? | ||
303 | */ | ||
304 | int | ||
305 | _GSS_union_handle_p2p_message (void *cls, | ||
306 | struct GNUNET_MESH_Tunnel *tunnel, | ||
307 | void **tunnel_ctx, | ||
308 | const struct GNUNET_PeerIdentity *sender, | ||
309 | const struct GNUNET_MessageHeader *mh); | ||
310 | |||
311 | |||
265 | #endif | 312 | #endif |
diff --git a/src/set/gnunet-service-set_union.c b/src/set/gnunet-service-set_union.c index 6d9658ee5..2b7a0ccba 100644 --- a/src/set/gnunet-service-set_union.c +++ b/src/set/gnunet-service-set_union.c | |||
@@ -124,15 +124,10 @@ struct UnionEvaluateOperation | |||
124 | struct GNUNET_MessageHeader *context_msg; | 124 | struct GNUNET_MessageHeader *context_msg; |
125 | 125 | ||
126 | /** | 126 | /** |
127 | * Stream socket connected to the other peer | 127 | * Tunnel context for the peer we |
128 | * evaluate the union operation with. | ||
128 | */ | 129 | */ |
129 | struct GNUNET_STREAM_Socket *socket; | 130 | struct TunnelContext *tc; |
130 | |||
131 | /** | ||
132 | * Message queue for the peer on the other | ||
133 | * end | ||
134 | */ | ||
135 | struct GNUNET_MQ_MessageQueue *mq; | ||
136 | 131 | ||
137 | /** | 132 | /** |
138 | * Request ID to multiplex set operations to | 133 | * Request ID to multiplex set operations to |
@@ -397,22 +392,19 @@ destroy_key_to_element_iter (void *cls, | |||
397 | * | 392 | * |
398 | * @param eo the union operation to destroy | 393 | * @param eo the union operation to destroy |
399 | */ | 394 | */ |
400 | static void | 395 | void |
401 | destroy_union_operation (struct UnionEvaluateOperation *eo) | 396 | _GSS_union_operation_destroy (struct UnionEvaluateOperation *eo) |
402 | { | 397 | { |
403 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "destroying union op\n"); | 398 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "destroying union op\n"); |
404 | 399 | ||
405 | if (NULL != eo->mq) | 400 | if (NULL != eo->tc) |
406 | { | 401 | { |
407 | GNUNET_MQ_destroy (eo->mq); | 402 | GNUNET_MQ_destroy (eo->tc->mq); |
408 | eo->mq = NULL; | 403 | GNUNET_MESH_tunnel_destroy (eo->tc->tunnel); |
404 | GNUNET_free (eo->tc); | ||
405 | eo->tc = NULL; | ||
409 | } | 406 | } |
410 | 407 | ||
411 | if (NULL != eo->socket) | ||
412 | { | ||
413 | GNUNET_STREAM_close (eo->socket); | ||
414 | eo->socket = NULL; | ||
415 | } | ||
416 | if (NULL != eo->remote_ibf) | 408 | if (NULL != eo->remote_ibf) |
417 | { | 409 | { |
418 | ibf_destroy (eo->remote_ibf); | 410 | ibf_destroy (eo->remote_ibf); |
@@ -457,14 +449,14 @@ destroy_union_operation (struct UnionEvaluateOperation *eo) | |||
457 | static void | 449 | static void |
458 | fail_union_operation (struct UnionEvaluateOperation *eo) | 450 | fail_union_operation (struct UnionEvaluateOperation *eo) |
459 | { | 451 | { |
460 | struct GNUNET_MQ_Message *mqm; | 452 | struct GNUNET_MQ_Envelope *mqm; |
461 | struct GNUNET_SET_ResultMessage *msg; | 453 | struct GNUNET_SET_ResultMessage *msg; |
462 | 454 | ||
463 | mqm = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SET_RESULT); | 455 | mqm = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SET_RESULT); |
464 | msg->result_status = htons (GNUNET_SET_STATUS_FAILURE); | 456 | msg->result_status = htons (GNUNET_SET_STATUS_FAILURE); |
465 | msg->request_id = htonl (eo->request_id); | 457 | msg->request_id = htonl (eo->request_id); |
466 | GNUNET_MQ_send (eo->set->client_mq, mqm); | 458 | GNUNET_MQ_send (eo->set->client_mq, mqm); |
467 | destroy_union_operation (eo); | 459 | _GSS_union_operation_destroy (eo); |
468 | } | 460 | } |
469 | 461 | ||
470 | 462 | ||
@@ -498,7 +490,7 @@ get_ibf_key (struct GNUNET_HashCode *src, uint16_t salt) | |||
498 | static void | 490 | static void |
499 | send_operation_request (struct UnionEvaluateOperation *eo) | 491 | send_operation_request (struct UnionEvaluateOperation *eo) |
500 | { | 492 | { |
501 | struct GNUNET_MQ_Message *mqm; | 493 | struct GNUNET_MQ_Envelope *mqm; |
502 | struct OperationRequestMessage *msg; | 494 | struct OperationRequestMessage *msg; |
503 | 495 | ||
504 | mqm = GNUNET_MQ_msg_nested_mh (msg, GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, eo->context_msg); | 496 | mqm = GNUNET_MQ_msg_nested_mh (msg, GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, eo->context_msg); |
@@ -512,7 +504,7 @@ send_operation_request (struct UnionEvaluateOperation *eo) | |||
512 | } | 504 | } |
513 | msg->operation = htons (GNUNET_SET_OPERATION_UNION); | 505 | msg->operation = htons (GNUNET_SET_OPERATION_UNION); |
514 | msg->app_id = eo->app_id; | 506 | msg->app_id = eo->app_id; |
515 | GNUNET_MQ_send (eo->mq, mqm); | 507 | GNUNET_MQ_send (eo->tc->mq, mqm); |
516 | 508 | ||
517 | if (NULL != eo->context_msg) | 509 | if (NULL != eo->context_msg) |
518 | { | 510 | { |
@@ -562,7 +554,7 @@ insert_element_iterator (void *cls, | |||
562 | * Insert an element into the union operation's | 554 | * Insert an element into the union operation's |
563 | * key-to-element mapping | 555 | * key-to-element mapping |
564 | * | 556 | * |
565 | * @param the union operation | 557 | * @param eo the union operation |
566 | * @param ee the element entry | 558 | * @param ee the element entry |
567 | */ | 559 | */ |
568 | static void | 560 | static void |
@@ -685,7 +677,7 @@ send_ibf (struct UnionEvaluateOperation *eo, uint16_t ibf_order) | |||
685 | while (buckets_sent < (1 << ibf_order)) | 677 | while (buckets_sent < (1 << ibf_order)) |
686 | { | 678 | { |
687 | unsigned int buckets_in_message; | 679 | unsigned int buckets_in_message; |
688 | struct GNUNET_MQ_Message *mqm; | 680 | struct GNUNET_MQ_Envelope *mqm; |
689 | struct IBFMessage *msg; | 681 | struct IBFMessage *msg; |
690 | 682 | ||
691 | buckets_in_message = (1 << ibf_order) - buckets_sent; | 683 | buckets_in_message = (1 << ibf_order) - buckets_sent; |
@@ -700,7 +692,7 @@ send_ibf (struct UnionEvaluateOperation *eo, uint16_t ibf_order) | |||
700 | ibf_write_slice (ibf, buckets_sent, | 692 | ibf_write_slice (ibf, buckets_sent, |
701 | buckets_in_message, &msg[1]); | 693 | buckets_in_message, &msg[1]); |
702 | buckets_sent += buckets_in_message; | 694 | buckets_sent += buckets_in_message; |
703 | GNUNET_MQ_send (eo->mq, mqm); | 695 | GNUNET_MQ_send (eo->tc->mq, mqm); |
704 | } | 696 | } |
705 | 697 | ||
706 | eo->phase = PHASE_EXPECT_ELEMENTS_AND_REQUESTS; | 698 | eo->phase = PHASE_EXPECT_ELEMENTS_AND_REQUESTS; |
@@ -715,14 +707,14 @@ send_ibf (struct UnionEvaluateOperation *eo, uint16_t ibf_order) | |||
715 | static void | 707 | static void |
716 | send_strata_estimator (struct UnionEvaluateOperation *eo) | 708 | send_strata_estimator (struct UnionEvaluateOperation *eo) |
717 | { | 709 | { |
718 | struct GNUNET_MQ_Message *mqm; | 710 | struct GNUNET_MQ_Envelope *mqm; |
719 | struct GNUNET_MessageHeader *strata_msg; | 711 | struct GNUNET_MessageHeader *strata_msg; |
720 | 712 | ||
721 | mqm = GNUNET_MQ_msg_header_extra (strata_msg, | 713 | mqm = GNUNET_MQ_msg_header_extra (strata_msg, |
722 | SE_STRATA_COUNT * IBF_BUCKET_SIZE * SE_IBF_SIZE, | 714 | SE_STRATA_COUNT * IBF_BUCKET_SIZE * SE_IBF_SIZE, |
723 | GNUNET_MESSAGE_TYPE_SET_P2P_SE); | 715 | GNUNET_MESSAGE_TYPE_SET_P2P_SE); |
724 | strata_estimator_write (eo->set->state.u->se, &strata_msg[1]); | 716 | strata_estimator_write (eo->set->state.u->se, &strata_msg[1]); |
725 | GNUNET_MQ_send (eo->mq, mqm); | 717 | GNUNET_MQ_send (eo->tc->mq, mqm); |
726 | eo->phase = PHASE_EXPECT_IBF; | 718 | eo->phase = PHASE_EXPECT_IBF; |
727 | } | 719 | } |
728 | 720 | ||
@@ -751,7 +743,7 @@ get_order_from_difference (unsigned int diff) | |||
751 | /** | 743 | /** |
752 | * Handle a strata estimator from a remote peer | 744 | * Handle a strata estimator from a remote peer |
753 | * | 745 | * |
754 | * @param the union operation | 746 | * @param cls the union operation |
755 | * @param mh the message | 747 | * @param mh the message |
756 | */ | 748 | */ |
757 | static void | 749 | static void |
@@ -804,7 +796,7 @@ send_element_iterator (void *cls, | |||
804 | while (NULL != ke) | 796 | while (NULL != ke) |
805 | { | 797 | { |
806 | const struct GNUNET_SET_Element *const element = &ke->element->element; | 798 | const struct GNUNET_SET_Element *const element = &ke->element->element; |
807 | struct GNUNET_MQ_Message *mqm; | 799 | struct GNUNET_MQ_Envelope *mqm; |
808 | struct GNUNET_MessageHeader *mh; | 800 | struct GNUNET_MessageHeader *mh; |
809 | 801 | ||
810 | GNUNET_assert (ke->ibf_key.key_val == ibf_key.key_val); | 802 | GNUNET_assert (ke->ibf_key.key_val == ibf_key.key_val); |
@@ -817,7 +809,7 @@ send_element_iterator (void *cls, | |||
817 | } | 809 | } |
818 | memcpy (&mh[1], element->data, element->size); | 810 | memcpy (&mh[1], element->data, element->size); |
819 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "sending element to client\n"); | 811 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "sending element to client\n"); |
820 | GNUNET_MQ_send (eo->mq, mqm); | 812 | GNUNET_MQ_send (eo->tc->mq, mqm); |
821 | ke = ke->next_colliding; | 813 | ke = ke->next_colliding; |
822 | } | 814 | } |
823 | return GNUNET_NO; | 815 | return GNUNET_NO; |
@@ -889,11 +881,11 @@ decode_and_send (struct UnionEvaluateOperation *eo) | |||
889 | } | 881 | } |
890 | if (GNUNET_NO == res) | 882 | if (GNUNET_NO == res) |
891 | { | 883 | { |
892 | struct GNUNET_MQ_Message *mqm; | 884 | struct GNUNET_MQ_Envelope *mqm; |
893 | 885 | ||
894 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "transmitted all values, sending DONE\n"); | 886 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "transmitted all values, sending DONE\n"); |
895 | mqm = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_P2P_DONE); | 887 | mqm = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_P2P_DONE); |
896 | GNUNET_MQ_send (eo->mq, mqm); | 888 | GNUNET_MQ_send (eo->tc->mq, mqm); |
897 | break; | 889 | break; |
898 | } | 890 | } |
899 | if (1 == side) | 891 | if (1 == side) |
@@ -902,7 +894,7 @@ decode_and_send (struct UnionEvaluateOperation *eo) | |||
902 | } | 894 | } |
903 | else | 895 | else |
904 | { | 896 | { |
905 | struct GNUNET_MQ_Message *mqm; | 897 | struct GNUNET_MQ_Envelope *mqm; |
906 | struct GNUNET_MessageHeader *msg; | 898 | struct GNUNET_MessageHeader *msg; |
907 | 899 | ||
908 | /* FIXME: before sending the request, check if we may just have the element */ | 900 | /* FIXME: before sending the request, check if we may just have the element */ |
@@ -910,7 +902,7 @@ decode_and_send (struct UnionEvaluateOperation *eo) | |||
910 | mqm = GNUNET_MQ_msg_header_extra (msg, sizeof (struct IBF_Key), | 902 | mqm = GNUNET_MQ_msg_header_extra (msg, sizeof (struct IBF_Key), |
911 | GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENT_REQUESTS); | 903 | GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENT_REQUESTS); |
912 | *(struct IBF_Key *) &msg[1] = key; | 904 | *(struct IBF_Key *) &msg[1] = key; |
913 | GNUNET_MQ_send (eo->mq, mqm); | 905 | GNUNET_MQ_send (eo->tc->mq, mqm); |
914 | } | 906 | } |
915 | } | 907 | } |
916 | ibf_destroy (diff_ibf); | 908 | ibf_destroy (diff_ibf); |
@@ -987,7 +979,7 @@ static void | |||
987 | send_client_element (struct UnionEvaluateOperation *eo, | 979 | send_client_element (struct UnionEvaluateOperation *eo, |
988 | struct GNUNET_SET_Element *element) | 980 | struct GNUNET_SET_Element *element) |
989 | { | 981 | { |
990 | struct GNUNET_MQ_Message *mqm; | 982 | struct GNUNET_MQ_Envelope *mqm; |
991 | struct GNUNET_SET_ResultMessage *rm; | 983 | struct GNUNET_SET_ResultMessage *rm; |
992 | 984 | ||
993 | GNUNET_assert (0 != eo->request_id); | 985 | GNUNET_assert (0 != eo->request_id); |
@@ -1006,39 +998,17 @@ send_client_element (struct UnionEvaluateOperation *eo, | |||
1006 | 998 | ||
1007 | 999 | ||
1008 | /** | 1000 | /** |
1009 | * Completion callback for shutdown | ||
1010 | * | ||
1011 | * @param cls the closure from GNUNET_STREAM_shutdown call | ||
1012 | * @param operation the operation that was shutdown (SHUT_RD, SHUT_WR, | ||
1013 | * SHUT_RDWR) | ||
1014 | */ | ||
1015 | /* | ||
1016 | static void | ||
1017 | stream_shutdown_cb (void *cls, | ||
1018 | int operation) | ||
1019 | { | ||
1020 | //struct UnionEvaluateOperation *eo = cls; | ||
1021 | |||
1022 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "stream shutdown\n"); | ||
1023 | |||
1024 | // destroy_union_operation (eo); | ||
1025 | } | ||
1026 | */ | ||
1027 | |||
1028 | |||
1029 | /** | ||
1030 | * Send a result message to the client indicating | 1001 | * Send a result message to the client indicating |
1031 | * that the operation is over. | 1002 | * that the operation is over. |
1032 | * After the result done message has been sent to the client, | 1003 | * After the result done message has been sent to the client, |
1033 | * destroy the evaluate operation. | 1004 | * destroy the evaluate operation. |
1034 | * | 1005 | * |
1035 | * @param eo union operation | 1006 | * @param eo union operation |
1036 | * @param element element to send | ||
1037 | */ | 1007 | */ |
1038 | static void | 1008 | static void |
1039 | send_client_done_and_destroy (struct UnionEvaluateOperation *eo) | 1009 | send_client_done_and_destroy (struct UnionEvaluateOperation *eo) |
1040 | { | 1010 | { |
1041 | struct GNUNET_MQ_Message *mqm; | 1011 | struct GNUNET_MQ_Envelope *mqm; |
1042 | struct GNUNET_SET_ResultMessage *rm; | 1012 | struct GNUNET_SET_ResultMessage *rm; |
1043 | 1013 | ||
1044 | GNUNET_assert (0 != eo->request_id); | 1014 | GNUNET_assert (0 != eo->request_id); |
@@ -1047,7 +1017,6 @@ send_client_done_and_destroy (struct UnionEvaluateOperation *eo) | |||
1047 | rm->result_status = htons (GNUNET_SET_STATUS_DONE); | 1017 | rm->result_status = htons (GNUNET_SET_STATUS_DONE); |
1048 | GNUNET_MQ_send (eo->set->client_mq, mqm); | 1018 | GNUNET_MQ_send (eo->set->client_mq, mqm); |
1049 | 1019 | ||
1050 | // GNUNET_STREAM_shutdown (eo->socket, SHUT_RDWR, stream_shutdown_cb, eo); | ||
1051 | } | 1020 | } |
1052 | 1021 | ||
1053 | 1022 | ||
@@ -1153,13 +1122,13 @@ handle_p2p_done (void *cls, const struct GNUNET_MessageHeader *mh) | |||
1153 | if (eo->phase == PHASE_EXPECT_ELEMENTS_AND_REQUESTS) | 1122 | if (eo->phase == PHASE_EXPECT_ELEMENTS_AND_REQUESTS) |
1154 | { | 1123 | { |
1155 | /* we got all requests, but still have to send our elements as response */ | 1124 | /* we got all requests, but still have to send our elements as response */ |
1156 | struct GNUNET_MQ_Message *mqm; | 1125 | struct GNUNET_MQ_Envelope *mqm; |
1157 | 1126 | ||
1158 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "got DONE, sending final DONE after elements\n"); | 1127 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "got DONE, sending final DONE after elements\n"); |
1159 | eo->phase = PHASE_FINISHED; | 1128 | eo->phase = PHASE_FINISHED; |
1160 | mqm = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_P2P_DONE); | 1129 | mqm = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_P2P_DONE); |
1161 | GNUNET_MQ_notify_sent (mqm, peer_done_sent_cb, eo); | 1130 | GNUNET_MQ_notify_sent (mqm, peer_done_sent_cb, eo); |
1162 | GNUNET_MQ_send (eo->mq, mqm); | 1131 | GNUNET_MQ_send (eo->tc->mq, mqm); |
1163 | return; | 1132 | return; |
1164 | } | 1133 | } |
1165 | if (eo->phase == PHASE_EXPECT_ELEMENTS) | 1134 | if (eo->phase == PHASE_EXPECT_ELEMENTS) |
@@ -1175,48 +1144,11 @@ handle_p2p_done (void *cls, const struct GNUNET_MessageHeader *mh) | |||
1175 | 1144 | ||
1176 | 1145 | ||
1177 | /** | 1146 | /** |
1178 | * The handlers array, used for both evaluate and accept | ||
1179 | */ | ||
1180 | static const struct GNUNET_MQ_Handler union_handlers[] = { | ||
1181 | {handle_p2p_elements, GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS}, | ||
1182 | {handle_p2p_strata_estimator, GNUNET_MESSAGE_TYPE_SET_P2P_SE}, | ||
1183 | {handle_p2p_ibf, GNUNET_MESSAGE_TYPE_SET_P2P_IBF}, | ||
1184 | {handle_p2p_element_requests, GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENT_REQUESTS}, | ||
1185 | {handle_p2p_done, GNUNET_MESSAGE_TYPE_SET_P2P_DONE}, | ||
1186 | GNUNET_MQ_HANDLERS_END | ||
1187 | }; | ||
1188 | |||
1189 | |||
1190 | /** | ||
1191 | * Functions of this type will be called when a stream is established | ||
1192 | * | ||
1193 | * @param cls the closure from GNUNET_STREAM_open | ||
1194 | * @param socket socket to use to communicate with the | ||
1195 | * other side (read/write) | ||
1196 | */ | ||
1197 | static void | ||
1198 | stream_open_cb (void *cls, | ||
1199 | struct GNUNET_STREAM_Socket *socket) | ||
1200 | { | ||
1201 | struct UnionEvaluateOperation *eo = cls; | ||
1202 | |||
1203 | GNUNET_assert (NULL == eo->mq); | ||
1204 | GNUNET_assert (socket == eo->socket); | ||
1205 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1206 | "open cb successful\n"); | ||
1207 | eo->mq = GNUNET_STREAM_mq_create (eo->socket, union_handlers, NULL, eo); | ||
1208 | /* we started the operation, thus we have to send the operation request */ | ||
1209 | send_operation_request (eo); | ||
1210 | eo->phase = PHASE_EXPECT_SE; | ||
1211 | } | ||
1212 | |||
1213 | |||
1214 | /** | ||
1215 | * Evaluate a union operation with | 1147 | * Evaluate a union operation with |
1216 | * a remote peer. | 1148 | * a remote peer. |
1217 | * | 1149 | * |
1218 | * @param m the evaluate request message from the client | 1150 | * @param m the evaluate request message from the client |
1219 | * @parem set the set to evaluate the operation with | 1151 | * @param set the set to evaluate the operation with |
1220 | */ | 1152 | */ |
1221 | void | 1153 | void |
1222 | _GSS_union_evaluate (struct GNUNET_SET_EvaluateMessage *m, struct Set *set) | 1154 | _GSS_union_evaluate (struct GNUNET_SET_EvaluateMessage *m, struct Set *set) |
@@ -1243,14 +1175,20 @@ _GSS_union_evaluate (struct GNUNET_SET_EvaluateMessage *m, struct Set *set) | |||
1243 | "evaluating union operation, (app %s)\n", | 1175 | "evaluating union operation, (app %s)\n", |
1244 | GNUNET_h2s (&eo->app_id)); | 1176 | GNUNET_h2s (&eo->app_id)); |
1245 | 1177 | ||
1246 | eo->socket = | 1178 | eo->tc = GNUNET_new (struct TunnelContext); |
1247 | GNUNET_STREAM_open (configuration, &eo->peer, GNUNET_APPLICATION_TYPE_SET, | 1179 | eo->tc->tunnel = GNUNET_MESH_tunnel_create (mesh, eo->tc, &eo->peer, |
1248 | &stream_open_cb, eo, | 1180 | GNUNET_APPLICATION_TYPE_SET); |
1249 | GNUNET_STREAM_OPTION_END); | 1181 | GNUNET_assert (NULL != eo->tc->tunnel); |
1182 | eo->tc->peer = eo->peer; | ||
1183 | eo->tc->mq = GNUNET_MESH_mq_create (eo->tc->tunnel); | ||
1184 | /* we started the operation, thus we have to send the operation request */ | ||
1185 | eo->phase = PHASE_EXPECT_SE; | ||
1186 | |||
1250 | GNUNET_CONTAINER_DLL_insert (eo->set->state.u->ops_head, | 1187 | GNUNET_CONTAINER_DLL_insert (eo->set->state.u->ops_head, |
1251 | eo->set->state.u->ops_tail, | 1188 | eo->set->state.u->ops_tail, |
1252 | eo); | 1189 | eo); |
1253 | /* the stream open callback will kick off the operation */ | 1190 | |
1191 | send_operation_request (eo); | ||
1254 | } | 1192 | } |
1255 | 1193 | ||
1256 | 1194 | ||
@@ -1270,25 +1208,17 @@ _GSS_union_accept (struct GNUNET_SET_AcceptRejectMessage *m, struct Set *set, | |||
1270 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "accepting set union operation\n"); | 1208 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "accepting set union operation\n"); |
1271 | 1209 | ||
1272 | eo = GNUNET_new (struct UnionEvaluateOperation); | 1210 | eo = GNUNET_new (struct UnionEvaluateOperation); |
1211 | eo->tc = incoming->tc; | ||
1273 | eo->generation_created = set->state.u->current_generation++; | 1212 | eo->generation_created = set->state.u->current_generation++; |
1274 | eo->set = set; | 1213 | eo->set = set; |
1275 | eo->peer = incoming->peer; | ||
1276 | eo->salt = ntohs (incoming->salt); | 1214 | eo->salt = ntohs (incoming->salt); |
1277 | GNUNET_assert (0 != ntohl (m->request_id)); | 1215 | GNUNET_assert (0 != ntohl (m->request_id)); |
1278 | eo->request_id = ntohl (m->request_id); | 1216 | eo->request_id = ntohl (m->request_id); |
1279 | eo->se = strata_estimator_dup (set->state.u->se); | 1217 | eo->se = strata_estimator_dup (set->state.u->se); |
1280 | eo->mq = incoming->mq; | ||
1281 | /* transfer ownership of mq and socket from incoming to eo */ | 1218 | /* transfer ownership of mq and socket from incoming to eo */ |
1282 | incoming->mq = NULL; | ||
1283 | eo->socket = incoming->socket; | ||
1284 | incoming->socket = NULL; | ||
1285 | /* the peer's socket is now ours, we'll receive all messages */ | ||
1286 | GNUNET_MQ_replace_handlers (eo->mq, union_handlers, eo); | ||
1287 | |||
1288 | GNUNET_CONTAINER_DLL_insert (eo->set->state.u->ops_head, | 1219 | GNUNET_CONTAINER_DLL_insert (eo->set->state.u->ops_head, |
1289 | eo->set->state.u->ops_tail, | 1220 | eo->set->state.u->ops_tail, |
1290 | eo); | 1221 | eo); |
1291 | |||
1292 | /* kick off the operation */ | 1222 | /* kick off the operation */ |
1293 | send_strata_estimator (eo); | 1223 | send_strata_estimator (eo); |
1294 | } | 1224 | } |
@@ -1384,7 +1314,7 @@ _GSS_union_set_destroy (struct Set *set) | |||
1384 | 1314 | ||
1385 | while (NULL != set->state.u->ops_head) | 1315 | while (NULL != set->state.u->ops_head) |
1386 | { | 1316 | { |
1387 | destroy_union_operation (set->state.u->ops_head); | 1317 | _GSS_union_operation_destroy (set->state.u->ops_head); |
1388 | } | 1318 | } |
1389 | } | 1319 | } |
1390 | 1320 | ||
@@ -1418,3 +1348,57 @@ _GSS_union_remove (struct GNUNET_SET_ElementMessage *m, struct Set *set) | |||
1418 | ee->generation_removed = set->state.u->current_generation; | 1348 | ee->generation_removed = set->state.u->current_generation; |
1419 | } | 1349 | } |
1420 | 1350 | ||
1351 | |||
1352 | /** | ||
1353 | * Dispatch messages for a union operation. | ||
1354 | * | ||
1355 | * @param cls closure | ||
1356 | * @param tunnel mesh tunnel | ||
1357 | * @param tunnel_ctx tunnel context | ||
1358 | * @param sender ??? | ||
1359 | * @param mh message to process | ||
1360 | * @return ??? | ||
1361 | */ | ||
1362 | int | ||
1363 | _GSS_union_handle_p2p_message (void *cls, | ||
1364 | struct GNUNET_MESH_Tunnel *tunnel, | ||
1365 | void **tunnel_ctx, | ||
1366 | const struct GNUNET_PeerIdentity *sender, | ||
1367 | const struct GNUNET_MessageHeader *mh) | ||
1368 | { | ||
1369 | struct TunnelContext *tc = *tunnel_ctx; | ||
1370 | struct UnionEvaluateOperation *eo; | ||
1371 | |||
1372 | if (CONTEXT_OPERATION_UNION != tc->type) | ||
1373 | { | ||
1374 | /* FIXME: kill the tunnel */ | ||
1375 | /* never kill mesh */ | ||
1376 | return GNUNET_OK; | ||
1377 | } | ||
1378 | |||
1379 | eo = tc->data; | ||
1380 | |||
1381 | switch (ntohs (mh->type)) | ||
1382 | { | ||
1383 | case GNUNET_MESSAGE_TYPE_SET_P2P_IBF: | ||
1384 | handle_p2p_ibf (eo, mh); | ||
1385 | break; | ||
1386 | case GNUNET_MESSAGE_TYPE_SET_P2P_SE: | ||
1387 | handle_p2p_strata_estimator (eo, mh); | ||
1388 | break; | ||
1389 | case GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENTS: | ||
1390 | handle_p2p_elements (eo, mh); | ||
1391 | break; | ||
1392 | case GNUNET_MESSAGE_TYPE_SET_P2P_ELEMENT_REQUESTS: | ||
1393 | handle_p2p_element_requests (eo, mh); | ||
1394 | break; | ||
1395 | case GNUNET_MESSAGE_TYPE_SET_P2P_DONE: | ||
1396 | handle_p2p_done (eo, mh); | ||
1397 | break; | ||
1398 | default: | ||
1399 | /* something wrong with mesh's message handlers? */ | ||
1400 | GNUNET_assert (0); | ||
1401 | } | ||
1402 | /* never kill mesh! */ | ||
1403 | return GNUNET_OK; | ||
1404 | } | ||
diff --git a/src/set/gnunet-set-ibf.c b/src/set/gnunet-set-ibf-profiler.c index d431795f1..92feb3db4 100644 --- a/src/set/gnunet-set-ibf.c +++ b/src/set/gnunet-set-ibf-profiler.c | |||
@@ -19,8 +19,8 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file consensus/gnunet-consensus-ibf.c | 22 | * @file set/gnunet-set-ibf-profiler.c |
23 | * @brief tool for reconciling data with invertible bloom filters | 23 | * @brief tool for profiling the invertible bloom filter implementation |
24 | * @author Florian Dold | 24 | * @author Florian Dold |
25 | */ | 25 | */ |
26 | 26 | ||
@@ -35,7 +35,7 @@ | |||
35 | static unsigned int asize = 10; | 35 | static unsigned int asize = 10; |
36 | static unsigned int bsize = 10; | 36 | static unsigned int bsize = 10; |
37 | static unsigned int csize = 10; | 37 | static unsigned int csize = 10; |
38 | static unsigned int hash_num = 3; | 38 | static unsigned int hash_num = 4; |
39 | static unsigned int ibf_size = 80; | 39 | static unsigned int ibf_size = 80; |
40 | 40 | ||
41 | /* FIXME: add parameter for this */ | 41 | /* FIXME: add parameter for this */ |
@@ -181,12 +181,14 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
181 | 181 | ||
182 | start_time = GNUNET_TIME_absolute_get (); | 182 | start_time = GNUNET_TIME_absolute_get (); |
183 | 183 | ||
184 | for (;;) | 184 | for (i = 0; i <= asize + bsize; i++) |
185 | { | 185 | { |
186 | res = ibf_decode (ibf_a, &side, &ibf_key); | 186 | res = ibf_decode (ibf_a, &side, &ibf_key); |
187 | if (GNUNET_SYSERR == res) | 187 | if (GNUNET_SYSERR == res) |
188 | { | 188 | { |
189 | printf ("decode failed\n"); | 189 | printf ("decode failed, %u/%u elements left\n", |
190 | GNUNET_CONTAINER_multihashmap_size (set_a) + GNUNET_CONTAINER_multihashmap_size (set_b), | ||
191 | asize + bsize); | ||
190 | return; | 192 | return; |
191 | } | 193 | } |
192 | if (GNUNET_NO == res) | 194 | if (GNUNET_NO == res) |
@@ -198,7 +200,9 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
198 | printf ("decoded successfully in: %s\n", GNUNET_STRINGS_relative_time_to_string (delta_time, GNUNET_NO)); | 200 | printf ("decoded successfully in: %s\n", GNUNET_STRINGS_relative_time_to_string (delta_time, GNUNET_NO)); |
199 | } | 201 | } |
200 | else | 202 | else |
201 | printf ("decode missed elements\n"); | 203 | { |
204 | printf ("decode missed elements (should never happen)\n"); | ||
205 | } | ||
202 | return; | 206 | return; |
203 | } | 207 | } |
204 | 208 | ||
@@ -207,6 +211,9 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
207 | if (side == -1) | 211 | if (side == -1) |
208 | iter_hashcodes (ibf_key, remove_iterator, set_b); | 212 | iter_hashcodes (ibf_key, remove_iterator, set_b); |
209 | } | 213 | } |
214 | printf("cyclic IBF, %u/%u elements left\n", | ||
215 | GNUNET_CONTAINER_multihashmap_size (set_a) + GNUNET_CONTAINER_multihashmap_size (set_b), | ||
216 | asize + bsize); | ||
210 | } | 217 | } |
211 | 218 | ||
212 | int | 219 | int |
diff --git a/src/set/gnunet-set-profiler.c b/src/set/gnunet-set-profiler.c new file mode 100644 index 000000000..bbaef7c43 --- /dev/null +++ b/src/set/gnunet-set-profiler.c | |||
@@ -0,0 +1,320 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2013 Christian Grothoff (and other contributing authors) | ||
4 | |||
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. | ||
9 | |||
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. | ||
14 | |||
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. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file set/gnunet-set-profiler.c | ||
23 | * @brief profiling tool for set | ||
24 | * @author Florian Dold | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_common.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_set_service.h" | ||
30 | #include "gnunet_testbed_service.h" | ||
31 | |||
32 | |||
33 | static int ret; | ||
34 | |||
35 | static unsigned int num_a = 5; | ||
36 | static unsigned int num_b = 5; | ||
37 | static unsigned int num_c = 20; | ||
38 | |||
39 | static unsigned int salt = 42; | ||
40 | |||
41 | static char* op_str = "union"; | ||
42 | |||
43 | const static struct GNUNET_CONFIGURATION_Handle *config; | ||
44 | |||
45 | struct GNUNET_CONTAINER_MultiHashMap *map_a; | ||
46 | struct GNUNET_CONTAINER_MultiHashMap *map_b; | ||
47 | struct GNUNET_CONTAINER_MultiHashMap *map_c; | ||
48 | |||
49 | |||
50 | /** | ||
51 | * Elements that set a received, should match map_c | ||
52 | * in the end. | ||
53 | */ | ||
54 | struct GNUNET_CONTAINER_MultiHashMap *map_a_received; | ||
55 | |||
56 | /** | ||
57 | * Elements that set b received, should match map_c | ||
58 | * in the end. | ||
59 | */ | ||
60 | struct GNUNET_CONTAINER_MultiHashMap *map_b_received; | ||
61 | |||
62 | struct GNUNET_SET_Handle *set_a; | ||
63 | struct GNUNET_SET_Handle *set_b; | ||
64 | |||
65 | struct GNUNET_HashCode app_id; | ||
66 | |||
67 | struct GNUNET_PeerIdentity local_peer; | ||
68 | |||
69 | struct GNUNET_SET_ListenHandle *set_listener; | ||
70 | |||
71 | struct GNUNET_SET_OperationHandle *set_oh1; | ||
72 | struct GNUNET_SET_OperationHandle *set_oh2; | ||
73 | |||
74 | |||
75 | int a_done; | ||
76 | int b_done; | ||
77 | |||
78 | |||
79 | |||
80 | static int | ||
81 | map_remove_iterator (void *cls, | ||
82 | const struct GNUNET_HashCode *key, | ||
83 | void *value) | ||
84 | { | ||
85 | struct GNUNET_CONTAINER_MultiHashMap *m = cls; | ||
86 | int ret; | ||
87 | |||
88 | ret = GNUNET_CONTAINER_multihashmap_remove (m, key, NULL); | ||
89 | GNUNET_assert (GNUNET_OK == ret); | ||
90 | return GNUNET_YES; | ||
91 | |||
92 | } | ||
93 | |||
94 | |||
95 | static void | ||
96 | set_result_cb_1 (void *cls, | ||
97 | const struct GNUNET_SET_Element *element, | ||
98 | enum GNUNET_SET_Status status) | ||
99 | { | ||
100 | GNUNET_assert (GNUNET_NO == a_done); | ||
101 | GNUNET_assert (element->size == sizeof (struct GNUNET_HashCode)); | ||
102 | switch (status) | ||
103 | { | ||
104 | case GNUNET_SET_STATUS_DONE: | ||
105 | case GNUNET_SET_STATUS_HALF_DONE: | ||
106 | a_done = GNUNET_YES; | ||
107 | GNUNET_CONTAINER_multihashmap_iterate (map_c, map_remove_iterator, map_a_received); | ||
108 | GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (map_a_received)); | ||
109 | return; | ||
110 | case GNUNET_SET_STATUS_FAILURE: | ||
111 | GNUNET_assert (0); | ||
112 | return; | ||
113 | case GNUNET_SET_STATUS_OK: | ||
114 | break; | ||
115 | default: | ||
116 | GNUNET_assert (0); | ||
117 | } | ||
118 | GNUNET_CONTAINER_multihashmap_put (map_a_received, | ||
119 | element->data, NULL, | ||
120 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); | ||
121 | } | ||
122 | |||
123 | |||
124 | static void | ||
125 | set_result_cb_2 (void *cls, | ||
126 | const struct GNUNET_SET_Element *element, | ||
127 | enum GNUNET_SET_Status status) | ||
128 | { | ||
129 | GNUNET_assert (GNUNET_NO == b_done); | ||
130 | GNUNET_assert (element->size == sizeof (struct GNUNET_HashCode)); | ||
131 | switch (status) | ||
132 | { | ||
133 | case GNUNET_SET_STATUS_DONE: | ||
134 | case GNUNET_SET_STATUS_HALF_DONE: | ||
135 | b_done = GNUNET_YES; | ||
136 | GNUNET_CONTAINER_multihashmap_iterate (map_c, map_remove_iterator, map_b_received); | ||
137 | GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (map_b_received)); | ||
138 | return; | ||
139 | case GNUNET_SET_STATUS_FAILURE: | ||
140 | GNUNET_assert (0); | ||
141 | return; | ||
142 | case GNUNET_SET_STATUS_OK: | ||
143 | break; | ||
144 | default: | ||
145 | GNUNET_assert (0); | ||
146 | } | ||
147 | GNUNET_CONTAINER_multihashmap_put (map_b_received, | ||
148 | element->data, NULL, | ||
149 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); | ||
150 | } | ||
151 | |||
152 | |||
153 | static void | ||
154 | set_listen_cb (void *cls, | ||
155 | const struct GNUNET_PeerIdentity *other_peer, | ||
156 | const struct GNUNET_MessageHeader *context_msg, | ||
157 | struct GNUNET_SET_Request *request) | ||
158 | { | ||
159 | GNUNET_assert (NULL == set_oh2); | ||
160 | set_oh2 = GNUNET_SET_accept (request, GNUNET_SET_RESULT_ADDED, | ||
161 | set_result_cb_2, NULL); | ||
162 | GNUNET_SET_commit (set_oh2, set_b); | ||
163 | } | ||
164 | |||
165 | |||
166 | |||
167 | static int | ||
168 | set_insert_iterator (void *cls, | ||
169 | const struct GNUNET_HashCode *key, | ||
170 | void *value) | ||
171 | { | ||
172 | struct GNUNET_SET_Handle *set = cls; | ||
173 | struct GNUNET_SET_Element *el; | ||
174 | |||
175 | el = GNUNET_malloc (sizeof *el + sizeof *key); | ||
176 | el->type = 0; | ||
177 | memcpy (&el[1], key, sizeof *key); | ||
178 | el->data = &el[1]; | ||
179 | el->size = sizeof *key; | ||
180 | GNUNET_SET_add_element (set, el, NULL, NULL); | ||
181 | GNUNET_free (el); | ||
182 | return GNUNET_YES; | ||
183 | } | ||
184 | |||
185 | |||
186 | /** | ||
187 | * Signature of the 'main' function for a (single-peer) testcase that | ||
188 | * is run using 'GNUNET_TESTING_peer_run'. | ||
189 | * | ||
190 | * @param cls closure | ||
191 | * @param cfg configuration of the peer that was started | ||
192 | * @param peer identity of the peer that was created | ||
193 | */ | ||
194 | static void | ||
195 | test_main (void *cls, | ||
196 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
197 | struct GNUNET_TESTING_Peer *peer) | ||
198 | { | ||
199 | unsigned int i; | ||
200 | struct GNUNET_HashCode hash; | ||
201 | |||
202 | config = cfg; | ||
203 | |||
204 | if (GNUNET_OK != GNUNET_CRYPTO_get_host_identity (cfg, &local_peer)) | ||
205 | { | ||
206 | GNUNET_assert (0); | ||
207 | return; | ||
208 | } | ||
209 | |||
210 | map_a = GNUNET_CONTAINER_multihashmap_create (num_a, GNUNET_NO); | ||
211 | map_b = GNUNET_CONTAINER_multihashmap_create (num_b, GNUNET_NO); | ||
212 | map_c = GNUNET_CONTAINER_multihashmap_create (num_c, GNUNET_NO); | ||
213 | |||
214 | for (i = 0; i < num_a; i++) | ||
215 | { | ||
216 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, &hash); | ||
217 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (map_a, &hash)) | ||
218 | { | ||
219 | i--; | ||
220 | continue; | ||
221 | } | ||
222 | GNUNET_CONTAINER_multihashmap_put (map_a, &hash, &hash, | ||
223 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | ||
224 | } | ||
225 | |||
226 | for (i = 0; i < num_b; i++) | ||
227 | { | ||
228 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, &hash); | ||
229 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (map_a, &hash)) | ||
230 | { | ||
231 | i--; | ||
232 | continue; | ||
233 | } | ||
234 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (map_b, &hash)) | ||
235 | { | ||
236 | i--; | ||
237 | continue; | ||
238 | } | ||
239 | GNUNET_CONTAINER_multihashmap_put (map_b, &hash, NULL, | ||
240 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); | ||
241 | } | ||
242 | |||
243 | for (i = 0; i < num_c; i++) | ||
244 | { | ||
245 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, &hash); | ||
246 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (map_a, &hash)) | ||
247 | { | ||
248 | i--; | ||
249 | continue; | ||
250 | } | ||
251 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (map_b, &hash)) | ||
252 | { | ||
253 | i--; | ||
254 | continue; | ||
255 | } | ||
256 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (map_c, &hash)) | ||
257 | { | ||
258 | i--; | ||
259 | continue; | ||
260 | } | ||
261 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, &hash); | ||
262 | GNUNET_CONTAINER_multihashmap_put (map_c, &hash, NULL, | ||
263 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); | ||
264 | } | ||
265 | |||
266 | /* use last hash for app id */ | ||
267 | app_id = hash; | ||
268 | |||
269 | /* FIXME: also implement intersection etc. */ | ||
270 | set_a = GNUNET_SET_create (config, GNUNET_SET_OPERATION_UNION); | ||
271 | set_b = GNUNET_SET_create (config, GNUNET_SET_OPERATION_UNION); | ||
272 | |||
273 | GNUNET_CONTAINER_multihashmap_iterate (map_a, set_insert_iterator, set_a); | ||
274 | GNUNET_CONTAINER_multihashmap_iterate (map_b, set_insert_iterator, set_b); | ||
275 | GNUNET_CONTAINER_multihashmap_iterate (map_c, set_insert_iterator, set_a); | ||
276 | GNUNET_CONTAINER_multihashmap_iterate (map_c, set_insert_iterator, set_b); | ||
277 | |||
278 | set_listener = GNUNET_SET_listen (config, GNUNET_SET_OPERATION_UNION, | ||
279 | &app_id, set_listen_cb, NULL); | ||
280 | |||
281 | set_oh1 = GNUNET_SET_prepare (&local_peer, &app_id, NULL, salt, GNUNET_SET_RESULT_ADDED, | ||
282 | set_result_cb_1, NULL); | ||
283 | GNUNET_SET_commit (set_oh1, set_a); | ||
284 | } | ||
285 | |||
286 | static void | ||
287 | run (void *cls, char *const *args, const char *cfgfile, | ||
288 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
289 | { | ||
290 | |||
291 | ret = GNUNET_TESTING_peer_run ("test_set_api", | ||
292 | "test_set.conf", | ||
293 | &test_main, NULL); | ||
294 | } | ||
295 | |||
296 | |||
297 | int | ||
298 | main (int argc, char **argv) | ||
299 | { | ||
300 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
301 | { 'A', "num-first", NULL, | ||
302 | gettext_noop ("number of values"), | ||
303 | GNUNET_YES, &GNUNET_GETOPT_set_uint, &num_a }, | ||
304 | { 'B', "num-second", NULL, | ||
305 | gettext_noop ("number of values"), | ||
306 | GNUNET_YES, &GNUNET_GETOPT_set_uint, &num_b }, | ||
307 | { 'B', "num-common", NULL, | ||
308 | gettext_noop ("number of values"), | ||
309 | GNUNET_YES, &GNUNET_GETOPT_set_uint, &num_c }, | ||
310 | { 'x', "operation", NULL, | ||
311 | gettext_noop ("oeration to execute"), | ||
312 | GNUNET_YES, &GNUNET_GETOPT_set_string, &op_str }, | ||
313 | GNUNET_GETOPT_OPTION_END | ||
314 | }; | ||
315 | GNUNET_PROGRAM_run2 (argc, argv, "gnunet-consensus", | ||
316 | "help", | ||
317 | options, &run, NULL, GNUNET_YES); | ||
318 | return ret; | ||
319 | } | ||
320 | |||
diff --git a/src/set/gnunet-set.c b/src/set/gnunet-set.c deleted file mode 100644 index ae84610fc..000000000 --- a/src/set/gnunet-set.c +++ /dev/null | |||
@@ -1,203 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2012 Christian Grothoff (and other contributing authors) | ||
4 | |||
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. | ||
9 | |||
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. | ||
14 | |||
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. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file set/gnunet-set.c | ||
23 | * @brief profiling tool for the set service | ||
24 | * @author Florian Dold | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_common.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_testbed_service.h" | ||
30 | #include "gnunet_set_service.h" | ||
31 | |||
32 | |||
33 | static struct GNUNET_PeerIdentity local_id; | ||
34 | |||
35 | static struct GNUNET_HashCode app_id; | ||
36 | static struct GNUNET_SET_Handle *set1; | ||
37 | static struct GNUNET_SET_Handle *set2; | ||
38 | static struct GNUNET_SET_ListenHandle *listen_handle; | ||
39 | const static struct GNUNET_CONFIGURATION_Handle *config; | ||
40 | |||
41 | int num_done; | ||
42 | |||
43 | |||
44 | static void | ||
45 | result_cb_set1 (void *cls, const struct GNUNET_SET_Element *element, | ||
46 | enum GNUNET_SET_Status status) | ||
47 | { | ||
48 | switch (status) | ||
49 | { | ||
50 | case GNUNET_SET_STATUS_OK: | ||
51 | printf ("set 1: got element\n"); | ||
52 | break; | ||
53 | case GNUNET_SET_STATUS_FAILURE: | ||
54 | printf ("set 1: failure\n"); | ||
55 | break; | ||
56 | case GNUNET_SET_STATUS_DONE: | ||
57 | printf ("set 1: done\n"); | ||
58 | GNUNET_SET_destroy (set1); | ||
59 | break; | ||
60 | default: | ||
61 | GNUNET_assert (0); | ||
62 | } | ||
63 | } | ||
64 | |||
65 | |||
66 | static void | ||
67 | result_cb_set2 (void *cls, const struct GNUNET_SET_Element *element, | ||
68 | enum GNUNET_SET_Status status) | ||
69 | { | ||
70 | switch (status) | ||
71 | { | ||
72 | case GNUNET_SET_STATUS_OK: | ||
73 | printf ("set 2: got element\n"); | ||
74 | break; | ||
75 | case GNUNET_SET_STATUS_FAILURE: | ||
76 | printf ("set 2: failure\n"); | ||
77 | break; | ||
78 | case GNUNET_SET_STATUS_DONE: | ||
79 | printf ("set 2: done\n"); | ||
80 | GNUNET_SET_destroy (set2); | ||
81 | break; | ||
82 | default: | ||
83 | GNUNET_assert (0); | ||
84 | } | ||
85 | } | ||
86 | |||
87 | |||
88 | static void | ||
89 | listen_cb (void *cls, | ||
90 | const struct GNUNET_PeerIdentity *other_peer, | ||
91 | const struct GNUNET_MessageHeader *context_msg, | ||
92 | struct GNUNET_SET_Request *request) | ||
93 | { | ||
94 | struct GNUNET_SET_OperationHandle *oh; | ||
95 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "listen cb called\n"); | ||
96 | GNUNET_SET_listen_cancel (listen_handle); | ||
97 | |||
98 | oh = GNUNET_SET_accept (request, GNUNET_SET_RESULT_ADDED, result_cb_set2, NULL); | ||
99 | GNUNET_SET_conclude (oh, set2); | ||
100 | } | ||
101 | |||
102 | |||
103 | /** | ||
104 | * Start the set operation. | ||
105 | * | ||
106 | * @param cls closure, unused | ||
107 | */ | ||
108 | static void | ||
109 | start (void *cls) | ||
110 | { | ||
111 | struct GNUNET_SET_OperationHandle *oh; | ||
112 | |||
113 | listen_handle = GNUNET_SET_listen (config, GNUNET_SET_OPERATION_UNION, | ||
114 | &app_id, listen_cb, NULL); | ||
115 | oh = GNUNET_SET_evaluate (&local_id, &app_id, NULL, 42, | ||
116 | GNUNET_SET_RESULT_ADDED, | ||
117 | result_cb_set1, NULL); | ||
118 | GNUNET_SET_conclude (oh, set1); | ||
119 | } | ||
120 | |||
121 | |||
122 | /** | ||
123 | * Initialize the second set, continue | ||
124 | * | ||
125 | * @param cls closure, unused | ||
126 | */ | ||
127 | static void | ||
128 | init_set2 (void *cls) | ||
129 | { | ||
130 | struct GNUNET_SET_Element element; | ||
131 | |||
132 | |||
133 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initializing set 2\n"); | ||
134 | |||
135 | element.data = "hello"; | ||
136 | element.size = strlen(element.data); | ||
137 | GNUNET_SET_add_element (set2, &element, NULL, NULL); | ||
138 | element.data = "quux"; | ||
139 | element.size = strlen(element.data); | ||
140 | GNUNET_SET_add_element (set2, &element, start, NULL); | ||
141 | } | ||
142 | |||
143 | |||
144 | /** | ||
145 | * Initialize the first set, continue. | ||
146 | */ | ||
147 | static void | ||
148 | init_set1 (void) | ||
149 | { | ||
150 | struct GNUNET_SET_Element element; | ||
151 | |||
152 | element.data = "hello"; | ||
153 | element.size = strlen(element.data); | ||
154 | GNUNET_SET_add_element (set1, &element, NULL, NULL); | ||
155 | element.data = "bar"; | ||
156 | element.size = strlen(element.data); | ||
157 | GNUNET_SET_add_element (set1, &element, init_set2, NULL); | ||
158 | |||
159 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initialized set 1\n"); | ||
160 | } | ||
161 | |||
162 | |||
163 | /** | ||
164 | * Main function that will be run. | ||
165 | * | ||
166 | * @param cls closure | ||
167 | * @param args remaining command-line arguments | ||
168 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
169 | * @param cfg configuration | ||
170 | */ | ||
171 | static void | ||
172 | run (void *cls, char *const *args, | ||
173 | const char *cfgfile, | ||
174 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
175 | { | ||
176 | static const char* app_str = "gnunet-set"; | ||
177 | |||
178 | config = cfg; | ||
179 | |||
180 | GNUNET_CRYPTO_hash (app_str, strlen (app_str), &app_id); | ||
181 | |||
182 | GNUNET_CRYPTO_get_host_identity (cfg, &local_id); | ||
183 | |||
184 | set1 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_UNION); | ||
185 | set2 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_UNION); | ||
186 | |||
187 | init_set1 (); | ||
188 | } | ||
189 | |||
190 | |||
191 | |||
192 | int | ||
193 | main (int argc, char **argv) | ||
194 | { | ||
195 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
196 | GNUNET_GETOPT_OPTION_END | ||
197 | }; | ||
198 | GNUNET_PROGRAM_run2 (argc, argv, "gnunet-set", | ||
199 | "help", | ||
200 | options, &run, NULL, GNUNET_NO); | ||
201 | return 0; | ||
202 | } | ||
203 | |||
diff --git a/src/set/ibf.c b/src/set/ibf.c index 383ce3daf..e3c5be59a 100644 --- a/src/set/ibf.c +++ b/src/set/ibf.c | |||
@@ -19,7 +19,7 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file consensus/ibf.c | 22 | * @file set/ibf.c |
23 | * @brief implementation of the invertible bloom filter | 23 | * @brief implementation of the invertible bloom filter |
24 | * @author Florian Dold | 24 | * @author Florian Dold |
25 | */ | 25 | */ |
@@ -27,6 +27,12 @@ | |||
27 | #include "ibf.h" | 27 | #include "ibf.h" |
28 | 28 | ||
29 | /** | 29 | /** |
30 | * Compute the key's hash from the key. | ||
31 | * Redefine to use a different hash function. | ||
32 | */ | ||
33 | #define IBF_KEY_HASH_VAL(k) (GNUNET_CRYPTO_crc32_n (&(k), sizeof (struct IBF_KeyHash))) | ||
34 | |||
35 | /** | ||
30 | * Create a key from a hashcode. | 36 | * Create a key from a hashcode. |
31 | * | 37 | * |
32 | * @param hash the hashcode | 38 | * @param hash the hashcode |
@@ -89,23 +95,21 @@ static inline void | |||
89 | ibf_get_indices (const struct InvertibleBloomFilter *ibf, | 95 | ibf_get_indices (const struct InvertibleBloomFilter *ibf, |
90 | struct IBF_Key key, int *dst) | 96 | struct IBF_Key key, int *dst) |
91 | { | 97 | { |
92 | struct GNUNET_HashCode bucket_indices; | 98 | uint32_t filled; |
93 | unsigned int filled; | 99 | uint32_t i; |
94 | int i; | 100 | uint32_t bucket = key.key_val & 0xFFFFFFFF; |
95 | GNUNET_CRYPTO_hash (&key, sizeof key, &bucket_indices); | 101 | |
96 | filled = 0; | 102 | for (i = 0, filled=0; filled < ibf->hash_num; i++) |
97 | for (i = 0; filled < ibf->hash_num; i++) | ||
98 | { | 103 | { |
99 | unsigned int bucket; | ||
100 | unsigned int j; | 104 | unsigned int j; |
101 | if ( (0 != i) && (0 == (i % 16)) ) | 105 | uint64_t x; |
102 | GNUNET_CRYPTO_hash (&bucket_indices, sizeof (struct GNUNET_HashCode), &bucket_indices); | ||
103 | bucket = bucket_indices.bits[i % 16] % ibf->size; | ||
104 | for (j = 0; j < filled; j++) | 106 | for (j = 0; j < filled; j++) |
105 | if (dst[j] == bucket) | 107 | if (dst[j] == bucket) |
106 | goto try_next; | 108 | goto try_next; |
107 | dst[filled++] = bucket; | 109 | dst[filled++] = bucket % ibf->size; |
108 | try_next: ; | 110 | try_next: ; |
111 | x = ((uint64_t) bucket << 32) | i; | ||
112 | bucket = GNUNET_CRYPTO_crc32_n (&x, sizeof x); | ||
109 | } | 113 | } |
110 | } | 114 | } |
111 | 115 | ||
@@ -116,16 +120,14 @@ ibf_insert_into (struct InvertibleBloomFilter *ibf, | |||
116 | const int *buckets, int side) | 120 | const int *buckets, int side) |
117 | { | 121 | { |
118 | int i; | 122 | int i; |
119 | struct GNUNET_HashCode key_hash_sha; | 123 | |
120 | struct IBF_KeyHash key_hash; | ||
121 | GNUNET_CRYPTO_hash (&key, sizeof key, &key_hash_sha); | ||
122 | key_hash.key_hash_val = key_hash_sha.bits[0]; | ||
123 | for (i = 0; i < ibf->hash_num; i++) | 124 | for (i = 0; i < ibf->hash_num; i++) |
124 | { | 125 | { |
125 | const int bucket = buckets[i]; | 126 | const int bucket = buckets[i]; |
126 | ibf->count[bucket].count_val += side; | 127 | ibf->count[bucket].count_val += side; |
127 | ibf->key_sum[bucket].key_val ^= key.key_val; | 128 | ibf->key_sum[bucket].key_val ^= key.key_val; |
128 | ibf->key_hash_sum[bucket].key_hash_val ^= key_hash.key_hash_val; | 129 | ibf->key_hash_sum[bucket].key_hash_val |
130 | ^= IBF_KEY_HASH_VAL (key); | ||
129 | } | 131 | } |
130 | } | 132 | } |
131 | 133 | ||
@@ -183,7 +185,6 @@ ibf_decode (struct InvertibleBloomFilter *ibf, | |||
183 | { | 185 | { |
184 | struct IBF_KeyHash hash; | 186 | struct IBF_KeyHash hash; |
185 | int i; | 187 | int i; |
186 | struct GNUNET_HashCode key_hash_sha; | ||
187 | int buckets[ibf->hash_num]; | 188 | int buckets[ibf->hash_num]; |
188 | 189 | ||
189 | GNUNET_assert (NULL != ibf); | 190 | GNUNET_assert (NULL != ibf); |
@@ -197,8 +198,7 @@ ibf_decode (struct InvertibleBloomFilter *ibf, | |||
197 | if ((1 != ibf->count[i].count_val) && (-1 != ibf->count[i].count_val)) | 198 | if ((1 != ibf->count[i].count_val) && (-1 != ibf->count[i].count_val)) |
198 | continue; | 199 | continue; |
199 | 200 | ||
200 | GNUNET_CRYPTO_hash (&ibf->key_sum[i], sizeof (struct IBF_Key), &key_hash_sha); | 201 | hash.key_hash_val = IBF_KEY_HASH_VAL (ibf->key_sum[i]); |
201 | hash.key_hash_val = key_hash_sha.bits[0]; | ||
202 | 202 | ||
203 | /* test if the hash matches the key */ | 203 | /* test if the hash matches the key */ |
204 | if (hash.key_hash_val != ibf->key_hash_sum[i].key_hash_val) | 204 | if (hash.key_hash_val != ibf->key_hash_sum[i].key_hash_val) |
diff --git a/src/set/ibf.h b/src/set/ibf.h index 2bf3ef7c7..90ea231c0 100644 --- a/src/set/ibf.h +++ b/src/set/ibf.h | |||
@@ -19,7 +19,7 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file consensus/ibf.h | 22 | * @file set/ibf.h |
23 | * @brief invertible bloom filter | 23 | * @brief invertible bloom filter |
24 | * @author Florian Dold | 24 | * @author Florian Dold |
25 | */ | 25 | */ |
diff --git a/src/set/set_api.c b/src/set/set_api.c index c74933aa0..e1b6132cb 100644 --- a/src/set/set_api.c +++ b/src/set/set_api.c | |||
@@ -40,7 +40,7 @@ | |||
40 | struct GNUNET_SET_Handle | 40 | struct GNUNET_SET_Handle |
41 | { | 41 | { |
42 | struct GNUNET_CLIENT_Connection *client; | 42 | struct GNUNET_CLIENT_Connection *client; |
43 | struct GNUNET_MQ_MessageQueue *mq; | 43 | struct GNUNET_MQ_Handle *mq; |
44 | unsigned int messages_since_ack; | 44 | unsigned int messages_since_ack; |
45 | }; | 45 | }; |
46 | 46 | ||
@@ -73,7 +73,7 @@ struct GNUNET_SET_OperationHandle | |||
73 | * Message sent to the server on calling conclude, | 73 | * Message sent to the server on calling conclude, |
74 | * NULL if conclude has been called. | 74 | * NULL if conclude has been called. |
75 | */ | 75 | */ |
76 | struct GNUNET_MQ_Message *conclude_mqm; | 76 | struct GNUNET_MQ_Envelope *conclude_mqm; |
77 | 77 | ||
78 | /** | 78 | /** |
79 | * Address of the request if in the conclude message, | 79 | * Address of the request if in the conclude message, |
@@ -89,7 +89,7 @@ struct GNUNET_SET_OperationHandle | |||
89 | struct GNUNET_SET_ListenHandle | 89 | struct GNUNET_SET_ListenHandle |
90 | { | 90 | { |
91 | struct GNUNET_CLIENT_Connection *client; | 91 | struct GNUNET_CLIENT_Connection *client; |
92 | struct GNUNET_MQ_MessageQueue* mq; | 92 | struct GNUNET_MQ_Handle* mq; |
93 | GNUNET_SET_ListenCallback listen_cb; | 93 | GNUNET_SET_ListenCallback listen_cb; |
94 | void *listen_cls; | 94 | void *listen_cls; |
95 | }; | 95 | }; |
@@ -115,7 +115,7 @@ handle_result (void *cls, const struct GNUNET_MessageHeader *mh) | |||
115 | 115 | ||
116 | if (set->messages_since_ack >= GNUNET_SET_ACK_WINDOW/2) | 116 | if (set->messages_since_ack >= GNUNET_SET_ACK_WINDOW/2) |
117 | { | 117 | { |
118 | struct GNUNET_MQ_Message *mqm; | 118 | struct GNUNET_MQ_Envelope *mqm; |
119 | mqm = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_ACK); | 119 | mqm = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_ACK); |
120 | GNUNET_MQ_send (set->mq, mqm); | 120 | GNUNET_MQ_send (set->mq, mqm); |
121 | } | 121 | } |
@@ -162,7 +162,7 @@ handle_request (void *cls, const struct GNUNET_MessageHeader *mh) | |||
162 | 162 | ||
163 | if (GNUNET_NO == req->accepted) | 163 | if (GNUNET_NO == req->accepted) |
164 | { | 164 | { |
165 | struct GNUNET_MQ_Message *mqm; | 165 | struct GNUNET_MQ_Envelope *mqm; |
166 | struct GNUNET_SET_AcceptRejectMessage *amsg; | 166 | struct GNUNET_SET_AcceptRejectMessage *amsg; |
167 | 167 | ||
168 | mqm = GNUNET_MQ_msg (amsg, GNUNET_MESSAGE_TYPE_SET_REJECT); | 168 | mqm = GNUNET_MQ_msg (amsg, GNUNET_MESSAGE_TYPE_SET_REJECT); |
@@ -197,9 +197,9 @@ GNUNET_SET_create (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
197 | enum GNUNET_SET_OperationType op) | 197 | enum GNUNET_SET_OperationType op) |
198 | { | 198 | { |
199 | struct GNUNET_SET_Handle *set; | 199 | struct GNUNET_SET_Handle *set; |
200 | struct GNUNET_MQ_Message *mqm; | 200 | struct GNUNET_MQ_Envelope *mqm; |
201 | struct GNUNET_SET_CreateMessage *msg; | 201 | struct GNUNET_SET_CreateMessage *msg; |
202 | static const struct GNUNET_MQ_Handler mq_handlers[] = { | 202 | static const struct GNUNET_MQ_MessageHandler mq_handlers[] = { |
203 | {handle_result, GNUNET_MESSAGE_TYPE_SET_RESULT}, | 203 | {handle_result, GNUNET_MESSAGE_TYPE_SET_RESULT}, |
204 | GNUNET_MQ_HANDLERS_END | 204 | GNUNET_MQ_HANDLERS_END |
205 | }; | 205 | }; |
@@ -234,7 +234,7 @@ GNUNET_SET_add_element (struct GNUNET_SET_Handle *set, | |||
234 | GNUNET_SET_Continuation cont, | 234 | GNUNET_SET_Continuation cont, |
235 | void *cont_cls) | 235 | void *cont_cls) |
236 | { | 236 | { |
237 | struct GNUNET_MQ_Message *mqm; | 237 | struct GNUNET_MQ_Envelope *mqm; |
238 | struct GNUNET_SET_ElementMessage *msg; | 238 | struct GNUNET_SET_ElementMessage *msg; |
239 | 239 | ||
240 | mqm = GNUNET_MQ_msg_extra (msg, element->size, GNUNET_MESSAGE_TYPE_SET_ADD); | 240 | mqm = GNUNET_MQ_msg_extra (msg, element->size, GNUNET_MESSAGE_TYPE_SET_ADD); |
@@ -262,7 +262,7 @@ GNUNET_SET_remove_element (struct GNUNET_SET_Handle *set, | |||
262 | GNUNET_SET_Continuation cont, | 262 | GNUNET_SET_Continuation cont, |
263 | void *cont_cls) | 263 | void *cont_cls) |
264 | { | 264 | { |
265 | struct GNUNET_MQ_Message *mqm; | 265 | struct GNUNET_MQ_Envelope *mqm; |
266 | struct GNUNET_SET_ElementMessage *msg; | 266 | struct GNUNET_SET_ElementMessage *msg; |
267 | 267 | ||
268 | mqm = GNUNET_MQ_msg_extra (msg, element->size, GNUNET_MESSAGE_TYPE_SET_REMOVE); | 268 | mqm = GNUNET_MQ_msg_extra (msg, element->size, GNUNET_MESSAGE_TYPE_SET_REMOVE); |
@@ -287,9 +287,9 @@ GNUNET_SET_destroy (struct GNUNET_SET_Handle *set) | |||
287 | 287 | ||
288 | 288 | ||
289 | /** | 289 | /** |
290 | * Create a set operation for evaluation with another peer. | 290 | * Prepare a set operation to be evaluated with another peer. |
291 | * The evaluation will not start until the client provides | 291 | * The evaluation will not start until the client provides |
292 | * a local set with GNUNET_SET_conclude. | 292 | * a local set with GNUNET_SET_commit. |
293 | * | 293 | * |
294 | * @param other_peer peer with the other set | 294 | * @param other_peer peer with the other set |
295 | * @param app_id hash for the application using the set | 295 | * @param app_id hash for the application using the set |
@@ -304,15 +304,15 @@ GNUNET_SET_destroy (struct GNUNET_SET_Handle *set) | |||
304 | * @return a handle to cancel the operation | 304 | * @return a handle to cancel the operation |
305 | */ | 305 | */ |
306 | struct GNUNET_SET_OperationHandle * | 306 | struct GNUNET_SET_OperationHandle * |
307 | GNUNET_SET_evaluate (const struct GNUNET_PeerIdentity *other_peer, | 307 | GNUNET_SET_prepare (const struct GNUNET_PeerIdentity *other_peer, |
308 | const struct GNUNET_HashCode *app_id, | 308 | const struct GNUNET_HashCode *app_id, |
309 | const struct GNUNET_MessageHeader *context_msg, | 309 | const struct GNUNET_MessageHeader *context_msg, |
310 | uint16_t salt, | 310 | uint16_t salt, |
311 | enum GNUNET_SET_ResultMode result_mode, | 311 | enum GNUNET_SET_ResultMode result_mode, |
312 | GNUNET_SET_ResultIterator result_cb, | 312 | GNUNET_SET_ResultIterator result_cb, |
313 | void *result_cls) | 313 | void *result_cls) |
314 | { | 314 | { |
315 | struct GNUNET_MQ_Message *mqm; | 315 | struct GNUNET_MQ_Envelope *mqm; |
316 | struct GNUNET_SET_OperationHandle *oh; | 316 | struct GNUNET_SET_OperationHandle *oh; |
317 | struct GNUNET_SET_EvaluateMessage *msg; | 317 | struct GNUNET_SET_EvaluateMessage *msg; |
318 | 318 | ||
@@ -322,9 +322,6 @@ GNUNET_SET_evaluate (const struct GNUNET_PeerIdentity *other_peer, | |||
322 | 322 | ||
323 | mqm = GNUNET_MQ_msg_nested_mh (msg, GNUNET_MESSAGE_TYPE_SET_EVALUATE, context_msg); | 323 | mqm = GNUNET_MQ_msg_nested_mh (msg, GNUNET_MESSAGE_TYPE_SET_EVALUATE, context_msg); |
324 | 324 | ||
325 | if (NULL != context_msg) | ||
326 | LOG (GNUNET_ERROR_TYPE_INFO, "passed context msg\n"); | ||
327 | |||
328 | msg->app_id = *app_id; | 325 | msg->app_id = *app_id; |
329 | msg->target_peer = *other_peer; | 326 | msg->target_peer = *other_peer; |
330 | msg->salt = salt; | 327 | msg->salt = salt; |
@@ -356,9 +353,9 @@ GNUNET_SET_listen (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
356 | void *listen_cls) | 353 | void *listen_cls) |
357 | { | 354 | { |
358 | struct GNUNET_SET_ListenHandle *lh; | 355 | struct GNUNET_SET_ListenHandle *lh; |
359 | struct GNUNET_MQ_Message *mqm; | 356 | struct GNUNET_MQ_Envelope *mqm; |
360 | struct GNUNET_SET_ListenMessage *msg; | 357 | struct GNUNET_SET_ListenMessage *msg; |
361 | static const struct GNUNET_MQ_Handler mq_handlers[] = { | 358 | static const struct GNUNET_MQ_MessageHandler mq_handlers[] = { |
362 | {handle_request, GNUNET_MESSAGE_TYPE_SET_REQUEST}, | 359 | {handle_request, GNUNET_MESSAGE_TYPE_SET_REQUEST}, |
363 | GNUNET_MQ_HANDLERS_END | 360 | GNUNET_MQ_HANDLERS_END |
364 | }; | 361 | }; |
@@ -403,7 +400,7 @@ GNUNET_SET_listen_cancel (struct GNUNET_SET_ListenHandle *lh) | |||
403 | * @param result_mode specified how results will be returned, | 400 | * @param result_mode specified how results will be returned, |
404 | * see 'GNUNET_SET_ResultMode'. | 401 | * see 'GNUNET_SET_ResultMode'. |
405 | * @param result_cb callback for the results | 402 | * @param result_cb callback for the results |
406 | * @param result_cls closure for result_cb | 403 | * @param cls closure for result_cb |
407 | * @return a handle to cancel the operation | 404 | * @return a handle to cancel the operation |
408 | */ | 405 | */ |
409 | struct GNUNET_SET_OperationHandle * | 406 | struct GNUNET_SET_OperationHandle * |
@@ -412,7 +409,7 @@ GNUNET_SET_accept (struct GNUNET_SET_Request *request, | |||
412 | GNUNET_SET_ResultIterator result_cb, | 409 | GNUNET_SET_ResultIterator result_cb, |
413 | void *cls) | 410 | void *cls) |
414 | { | 411 | { |
415 | struct GNUNET_MQ_Message *mqm; | 412 | struct GNUNET_MQ_Envelope *mqm; |
416 | struct GNUNET_SET_OperationHandle *oh; | 413 | struct GNUNET_SET_OperationHandle *oh; |
417 | struct GNUNET_SET_AcceptRejectMessage *msg; | 414 | struct GNUNET_SET_AcceptRejectMessage *msg; |
418 | 415 | ||
@@ -441,7 +438,7 @@ GNUNET_SET_accept (struct GNUNET_SET_Request *request, | |||
441 | void | 438 | void |
442 | GNUNET_SET_operation_cancel (struct GNUNET_SET_OperationHandle *oh) | 439 | GNUNET_SET_operation_cancel (struct GNUNET_SET_OperationHandle *oh) |
443 | { | 440 | { |
444 | struct GNUNET_MQ_Message *mqm; | 441 | struct GNUNET_MQ_Envelope *mqm; |
445 | struct GNUNET_SET_OperationHandle *h_assoc; | 442 | struct GNUNET_SET_OperationHandle *h_assoc; |
446 | 443 | ||
447 | if (NULL != oh->set) | 444 | if (NULL != oh->set) |
@@ -460,7 +457,7 @@ GNUNET_SET_operation_cancel (struct GNUNET_SET_OperationHandle *oh) | |||
460 | 457 | ||
461 | 458 | ||
462 | /** | 459 | /** |
463 | * Conclude the given set operation using the given set. | 460 | * Commit a set to be used with a set operation. |
464 | * This function is called once we have fully constructed | 461 | * This function is called once we have fully constructed |
465 | * the set that we want to use for the operation. At this | 462 | * the set that we want to use for the operation. At this |
466 | * time, the P2P protocol can then begin to exchange the | 463 | * time, the P2P protocol can then begin to exchange the |
@@ -471,13 +468,13 @@ GNUNET_SET_operation_cancel (struct GNUNET_SET_OperationHandle *oh) | |||
471 | * @param set the set to use for the operation | 468 | * @param set the set to use for the operation |
472 | */ | 469 | */ |
473 | void | 470 | void |
474 | GNUNET_SET_conclude (struct GNUNET_SET_OperationHandle *oh, | 471 | GNUNET_SET_commit (struct GNUNET_SET_OperationHandle *oh, |
475 | struct GNUNET_SET_Handle *set) | 472 | struct GNUNET_SET_Handle *set) |
476 | { | 473 | { |
477 | GNUNET_assert (NULL == oh->set); | 474 | GNUNET_assert (NULL == oh->set); |
478 | GNUNET_assert (NULL != oh->conclude_mqm); | 475 | GNUNET_assert (NULL != oh->conclude_mqm); |
479 | oh->set = set; | 476 | oh->set = set; |
480 | oh->request_id = GNUNET_MQ_assoc_add (oh->set->mq, NULL, oh); | 477 | oh->request_id = GNUNET_MQ_assoc_add (oh->set->mq, oh); |
481 | *oh->request_id_addr = htonl (oh->request_id); | 478 | *oh->request_id_addr = htonl (oh->request_id); |
482 | GNUNET_MQ_send (oh->set->mq, oh->conclude_mqm); | 479 | GNUNET_MQ_send (oh->set->mq, oh->conclude_mqm); |
483 | oh->conclude_mqm = NULL; | 480 | oh->conclude_mqm = NULL; |
diff --git a/src/set/strata_estimator.c b/src/set/strata_estimator.c index 024bb99c6..18c127cd6 100644 --- a/src/set/strata_estimator.c +++ b/src/set/strata_estimator.c | |||
@@ -19,7 +19,7 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file consensus/ibf.h | 22 | * @file set/ibf.h |
23 | * @brief invertible bloom filter | 23 | * @brief invertible bloom filter |
24 | * @author Florian Dold | 24 | * @author Florian Dold |
25 | */ | 25 | */ |
diff --git a/src/set/strata_estimator.h b/src/set/strata_estimator.h index b3f050743..718c996d0 100644 --- a/src/set/strata_estimator.h +++ b/src/set/strata_estimator.h | |||
@@ -19,7 +19,7 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file consensus/strata_estimator.h | 22 | * @file set/strata_estimator.h |
23 | * @brief estimator of set difference | 23 | * @brief estimator of set difference |
24 | * @author Florian Dold | 24 | * @author Florian Dold |
25 | */ | 25 | */ |
diff --git a/src/set/test_set_api.c b/src/set/test_set_api.c index f773cebdf..db82b83b4 100644 --- a/src/set/test_set_api.c +++ b/src/set/test_set_api.c | |||
@@ -95,7 +95,7 @@ listen_cb (void *cls, | |||
95 | GNUNET_SET_listen_cancel (listen_handle); | 95 | GNUNET_SET_listen_cancel (listen_handle); |
96 | 96 | ||
97 | oh = GNUNET_SET_accept (request, GNUNET_SET_RESULT_ADDED, result_cb_set2, NULL); | 97 | oh = GNUNET_SET_accept (request, GNUNET_SET_RESULT_ADDED, result_cb_set2, NULL); |
98 | GNUNET_SET_conclude (oh, set2); | 98 | GNUNET_SET_commit (oh, set2); |
99 | } | 99 | } |
100 | 100 | ||
101 | 101 | ||
@@ -111,10 +111,10 @@ start (void *cls) | |||
111 | 111 | ||
112 | listen_handle = GNUNET_SET_listen (config, GNUNET_SET_OPERATION_UNION, | 112 | listen_handle = GNUNET_SET_listen (config, GNUNET_SET_OPERATION_UNION, |
113 | &app_id, listen_cb, NULL); | 113 | &app_id, listen_cb, NULL); |
114 | oh = GNUNET_SET_evaluate (&local_id, &app_id, NULL, 42, | 114 | oh = GNUNET_SET_prepare (&local_id, &app_id, NULL, 42, |
115 | GNUNET_SET_RESULT_ADDED, | 115 | GNUNET_SET_RESULT_ADDED, |
116 | result_cb_set1, NULL); | 116 | result_cb_set1, NULL); |
117 | GNUNET_SET_conclude (oh, set1); | 117 | GNUNET_SET_commit (oh, set1); |
118 | } | 118 | } |
119 | 119 | ||
120 | 120 | ||