From 6d5959b29aa3ff47605aa91550d90fc28597d0de Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 10 Aug 2016 11:46:22 +0000 Subject: [PATCH] use non-constant ports for CADET with scalarproduct --- .../gnunet-service-scalarproduct-ecc_alice.c | 8 +++-- .../gnunet-service-scalarproduct-ecc_bob.c | 28 +++++++++++++--- .../gnunet-service-scalarproduct_alice.c | 2 +- .../gnunet-service-scalarproduct_bob.c | 33 ++++++++++++------- src/scalarproduct/scalarproduct.conf.in | 4 +-- 5 files changed, 54 insertions(+), 21 deletions(-) diff --git a/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c b/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c index 43a25a08d..fe27067e8 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c +++ b/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c @@ -850,7 +850,11 @@ client_request_complete_alice (struct AliceServiceSession *s) { struct EccServiceRequestMessage *msg; struct GNUNET_MQ_Envelope *e; + struct GNUNET_HashCode set_sid; + GNUNET_CRYPTO_hash (&s->session_id, + sizeof (struct GNUNET_HashCode), + &set_sid); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating new channel for session with key %s.\n", GNUNET_h2s (&s->session_id)); @@ -858,7 +862,7 @@ client_request_complete_alice (struct AliceServiceSession *s) = GNUNET_CADET_channel_create (my_cadet, s, &s->peer, - GC_u2h (GNUNET_APPLICATION_TYPE_SCALARPRODUCT_ECC), + &s->session_id, GNUNET_CADET_OPTION_RELIABLE); if (NULL == s->channel) { @@ -870,7 +874,7 @@ client_request_complete_alice (struct AliceServiceSession *s) s->intersection_listen = GNUNET_SET_listen (cfg, GNUNET_SET_OPERATION_INTERSECTION, - &s->session_id, + &set_sid, &cb_intersection_request_alice, s); if (NULL == s->intersection_listen) diff --git a/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c b/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c index 7246fa6a0..db656d39b 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c +++ b/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c @@ -103,6 +103,11 @@ struct BobServiceSession */ struct GNUNET_SET_OperationHandle *intersection_op; + /** + * Our open port. + */ + struct GNUNET_CADET_Port *port; + /** * b(Bob) */ @@ -362,6 +367,7 @@ destroy_service_session (struct BobServiceSession *s) gcry_mpi_point_release (s->prod_h_i_b_i); s->prod_h_i_b_i = NULL; } + GNUNET_CADET_close_port (s->port); GNUNET_free (s); } @@ -795,6 +801,11 @@ cb_intersection_element_removed (void *cls, static void start_intersection (struct BobServiceSession *s) { + struct GNUNET_HashCode set_sid; + + GNUNET_CRYPTO_hash (&s->session_id, + sizeof (struct GNUNET_HashCode), + &set_sid); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got session with key %s and %u elements, starting intersection.\n", GNUNET_h2s (&s->session_id), @@ -802,7 +813,7 @@ start_intersection (struct BobServiceSession *s) s->intersection_op = GNUNET_SET_prepare (&s->cadet->peer, - &s->session_id, + &set_sid, NULL, GNUNET_SET_RESULT_REMOVED, &cb_intersection_element_removed, @@ -1076,6 +1087,18 @@ GSS_handle_bob_client_message (void *cls, s->total = total_count; s->client_received_element_count = contained_count; s->session_id = msg->session_key; + s->port = GNUNET_CADET_open_port (my_cadet, + &msg->session_key, + &cb_channel_incoming, + s); + if (NULL == s->port) + { + GNUNET_break (0); + GNUNET_SERVER_receive_done (client, + GNUNET_SYSERR); + GNUNET_free (s); + return; + } GNUNET_break (GNUNET_YES == GNUNET_CONTAINER_multihashmap_put (client_sessions, &s->session_id, @@ -1246,9 +1269,6 @@ run (void *cls, GNUNET_SCHEDULER_shutdown (); return; } - GNUNET_CADET_open_port (my_cadet, - GC_u2h (GNUNET_APPLICATION_TYPE_SCALARPRODUCT_ECC), - &cb_channel_incoming, NULL); GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); } diff --git a/src/scalarproduct/gnunet-service-scalarproduct_alice.c b/src/scalarproduct/gnunet-service-scalarproduct_alice.c index 8c3b1ed24..0df7da00c 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct_alice.c +++ b/src/scalarproduct/gnunet-service-scalarproduct_alice.c @@ -1081,7 +1081,7 @@ client_request_complete_alice (struct AliceServiceSession *s) = GNUNET_CADET_channel_create (my_cadet, s, &s->peer, - GC_u2h (GNUNET_APPLICATION_TYPE_SCALARPRODUCT), + &s->session_id, GNUNET_CADET_OPTION_RELIABLE); if (NULL == s->channel) { diff --git a/src/scalarproduct/gnunet-service-scalarproduct_bob.c b/src/scalarproduct/gnunet-service-scalarproduct_bob.c index 84c831c82..1136f1e00 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct_bob.c +++ b/src/scalarproduct/gnunet-service-scalarproduct_bob.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2013, 2014 GNUnet e.V. + Copyright (C) 2013, 2014, 2016 GNUnet e.V. GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -103,6 +103,11 @@ struct BobServiceSession */ struct GNUNET_SET_OperationHandle *intersection_op; + /** + * CADET port we are listening on. + */ + struct GNUNET_CADET_Port *port; + /** * a(Alice) */ @@ -403,6 +408,7 @@ destroy_service_session (struct BobServiceSession *s) GNUNET_free (s->r_prime); s->r_prime = NULL; } + GNUNET_CADET_close_port (s->port); GNUNET_free (s); } @@ -1176,7 +1182,7 @@ handle_alices_computation_request (void *cls, * preliminary initialization, more happens after we get Alice's first * message. * - * @param cls closure + * @param cls closure with the `struct BobServiceSession` * @param channel new handle to the channel * @param initiator peer that started the channel * @param port unused @@ -1357,13 +1363,6 @@ GSS_handle_bob_client_message (void *cls, GNUNET_SYSERR); return; } - if (NULL != find_matching_client_session (&msg->session_key)) - { - GNUNET_break (0); - GNUNET_SERVER_receive_done (client, - GNUNET_SYSERR); - return; - } s = GNUNET_new (struct BobServiceSession); s->status = GNUNET_SCALARPRODUCT_STATUS_ACTIVE; @@ -1372,6 +1371,19 @@ GSS_handle_bob_client_message (void *cls, s->total = total_count; s->client_received_element_count = contained_count; s->session_id = msg->session_key; + s->port = GNUNET_CADET_open_port (my_cadet, + &msg->session_key, + &cb_channel_incoming, + s); + if (NULL == s->port) + { + GNUNET_break (0); + GNUNET_SERVER_receive_done (client, + GNUNET_SYSERR); + GNUNET_free (s); + return; + } + GNUNET_break (GNUNET_YES == GNUNET_CONTAINER_multihashmap_put (client_sessions, &s->session_id, @@ -1543,9 +1555,6 @@ run (void *cls, GNUNET_SCHEDULER_shutdown (); return; } - GNUNET_CADET_open_port (my_cadet, - GC_u2h (GNUNET_APPLICATION_TYPE_SCALARPRODUCT), - &cb_channel_incoming, NULL); GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); } diff --git a/src/scalarproduct/scalarproduct.conf.in b/src/scalarproduct/scalarproduct.conf.in index c5149eeaf..e2a0c7ad7 100644 --- a/src/scalarproduct/scalarproduct.conf.in +++ b/src/scalarproduct/scalarproduct.conf.in @@ -1,6 +1,6 @@ [scalarproduct-alice] AUTOSTART = @AUTOSTART@ -BINARY = gnunet-service-scalarproduct-alice +BINARY = gnunet-service-scalarproduct-ecc-alice UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-scalarproduct-alice.sock @UNIXONLY@ PORT = 2117 #ACCEPT_FROM = 127.0.0.1; @@ -14,7 +14,7 @@ UNIX_MATCH_GID = YES [scalarproduct-bob] AUTOSTART = @AUTOSTART@ HOSTNAME = localhost -BINARY = gnunet-service-scalarproduct-bob +BINARY = gnunet-service-scalarproduct-ecc-bob UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-scalarproduct-bob.sock @UNIXONLY@ PORT = 2118 -- 2.25.1