struct GNUNET_SERVER_TransmitHandle * client_transmit_handle;
/**
- * tunnel-handle associated with our mesh handle
+ * channel-handle associated with our mesh handle
*/
- struct GNUNET_MESH_Tunnel * tunnel;
+ struct GNUNET_MESH_Channel * channel;
/**
* Handle to a task that sends a msg to the our client
* Send a multi part chunk of a service request from alice to bob.
* This element only contains a part of the elements-vector (session->a[]),
* mask and public key set have to be contained within the first message
- *
+ *
* This allows a ~32kbit key length while using 32000 elements or 62000 elements per request.
- *
+ *
* @param cls the associated service session
*/
static void
/**
* Send a multi part chunk of a service response from bob to alice.
* This element only contains the two permutations of R, R'.
- *
+ *
* @param cls the associated service session
*/
static void
my_lambda = gcry_mpi_new (0);
// calculate lambda
- // lambda = \frac{(p-1)*(q-1)}{gcd(p-1,q-1)}
+ // lambda = frac{(p-1)*(q-1)}{gcd(p-1,q-1)}
gcry_mpi_sub_ui (tmp1, p, 1);
gcry_mpi_sub_ui (tmp2, q, 1);
gcry_mpi_gcd (gcd, tmp1, tmp2);
}
-/**
- * Encrypts an element using the paillier crypto system
- *
- * @param c ciphertext (output)
- * @param m plaintext
- * @param g the public base
- * @param n the module from which which r is chosen (Z*_n)
- * @param n_square the module for encryption, for performance reasons.
- */
-static void
-encrypt_element (gcry_mpi_t c, gcry_mpi_t m, gcry_mpi_t g, gcry_mpi_t n, gcry_mpi_t n_square)
-{
- gcry_mpi_t tmp;
-
- GNUNET_assert (tmp = gcry_mpi_new (0));
-
- while (0 >= gcry_mpi_cmp_ui (tmp, 1)) {
- gcry_mpi_randomize (tmp, KEYBITS / 3, GCRY_WEAK_RANDOM);
- // r must be 1 < r < n
- }
-
- gcry_mpi_powm (c, g, m, n_square);
- gcry_mpi_powm (tmp, tmp, n, n_square);
- gcry_mpi_mulm (c, tmp, c, n_square);
-
- gcry_mpi_release (tmp);
-}
-
-
/**
* decrypts an element using the paillier crypto system
*
/**
* Finds a not terminated client/service session in the
* given DLL based on session key, element count and state.
- *
+ *
* @param tail - the tail of the DLL
* @param key - the key we want to search for
* @param element_count - the total element count of the dataset (session->total)
return NULL;
}
-
/**
* Safely frees ALL memory areas referenced by a session.
- *
+ *
* @param session - the session to free elements from
*/
static void
for (i = 0; i < session->used; i++)
if (session->a[i]) gcry_mpi_release (session->a[i]);
GNUNET_free (session->a);
+ session->a = NULL;
+ }
+ if (session->mask) {
+ GNUNET_free (session->mask);
+ session->mask = NULL;
}
- GNUNET_free_non_null (session->mask);
if (session->r) {
for (i = 0; i < session->used; i++)
if (session->r[i]) gcry_mpi_release (session->r[i]);
GNUNET_free (session->r);
+ session->r = NULL;
}
if (session->r_prime) {
for (i = 0; i < session->used; i++)
if (session->r_prime[i]) gcry_mpi_release (session->r_prime[i]);
GNUNET_free (session->r_prime);
+ session->r_prime = NULL;
}
- if (session->s)
+ if (session->s) {
gcry_mpi_release (session->s);
- if (session->s_prime)
+ session->s = NULL;
+ }
+
+ if (session->s_prime) {
gcry_mpi_release (session->s_prime);
- if (session->product)
+ session->s_prime = NULL;
+ }
+
+ if (session->product) {
gcry_mpi_release (session->product);
+ session->product = NULL;
+ }
- if (session->remote_pubkey)
+ if (session->remote_pubkey) {
gcry_sexp_release (session->remote_pubkey);
+ session->remote_pubkey = NULL;
+ }
- GNUNET_free_non_null (session->vector);
+ if (session->vector) {
+ GNUNET_free_non_null (session->vector);
+ session->s = NULL;
+ }
}
///////////////////////////////////////////////////////////////////////////////
// Event and Message Handlers
{
struct ServiceSession *session;
- if (client == NULL)
+ if (NULL != client)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _ ("Client (%p) disconnected from us.\n"), client);
+ else
return;
+
session = GNUNET_SERVER_client_get_user_context (client, struct ServiceSession);
if (NULL == session)
return;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _ ("Client (%p) disconnected from us.\n"), client);
GNUNET_CONTAINER_DLL_remove (from_client_head, from_client_tail, session);
if (!(session->role == BOB && session->state == FINALIZED)) {
//we MUST terminate any client message underway
- if (session->service_transmit_handle && session->tunnel)
+ if (session->service_transmit_handle && session->channel)
GNUNET_MESH_notify_transmit_ready_cancel (session->service_transmit_handle);
- if (session->tunnel && session->state == WAITING_FOR_SERVICE_RESPONSE)
- GNUNET_MESH_tunnel_destroy (session->tunnel);
+ if (session->channel && session->state == WAITING_FOR_SERVICE_RESPONSE)
+ GNUNET_MESH_channel_destroy (session->channel);
}
if (GNUNET_SCHEDULER_NO_TASK != session->client_notification_task) {
GNUNET_SCHEDULER_cancel (session->client_notification_task);
else
GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Sending session-end notification to client (%p) for session %s\n"), &session->client, GNUNET_h2s (&session->key));
+ free_session_variables (session);
}
msg_length = sizeof (struct GNUNET_SCALARPRODUCT_client_response) +product_length;
msg = GNUNET_malloc (msg_length);
- memcpy (&msg->key, &session->key, sizeof (struct GNUNET_HashCode));
- memcpy (&msg->peer, &session->peer, sizeof ( struct GNUNET_PeerIdentity));
- if (product_exported != NULL) {
+ msg->key = session->key;
+ msg->peer = session->peer;
+ if (product_exported != NULL)
+ {
memcpy (&msg[1], product_exported, product_length);
GNUNET_free (product_exported);
}
_ ("Sent result to client (%p), this session (%s) has ended!\n"),
session->client,
GNUNET_h2s (&session->key));
+ free_session_variables (session);
}
/**
* Send a multipart chunk of a service response from bob to alice.
* This element only contains the two permutations of R, R'.
- *
+ *
* @param cls the associated service session
*/
static void
GNUNET_free (element_exported);
for (i = session->transferred; i < session->transferred; i++) {
gcry_mpi_release (session->r_prime[i]);
+ session->r_prime[i] = NULL;
gcry_mpi_release (session->r[i]);
+ session->r[i] = NULL;
}
session->transferred += todo_count;
session->msg = (struct GNUNET_MessageHeader *) msg;
session->service_transmit_handle =
- GNUNET_MESH_notify_transmit_ready (session->tunnel,
+ GNUNET_MESH_notify_transmit_ready (session->channel,
GNUNET_YES,
GNUNET_TIME_UNIT_FOREVER_REL,
msg_length,
return;
}
if (session->transferred != session->used)
- // multipart
+ // more multiparts
session->state = WAITING_FOR_MULTIPART_TRANSMISSION;
- else
- //singlepart
+ else{
+ // final part
session->state = FINALIZED;
+ GNUNET_free(session->r);
+ GNUNET_free(session->r_prime);
+ session->r_prime = NULL;
+ session->r = NULL;
+ }
}
msg->header.type = htons (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_TO_ALICE);
msg->header.size = htons (msg_length);
msg->total_element_count = htonl (session->total);
- msg->contained_element_count = htonl (session->used);
+ msg->used_element_count = htonl (session->used);
msg->contained_element_count = htonl (session->transferred);
memcpy (&msg->key, &session->key, sizeof (struct GNUNET_HashCode));
current = (unsigned char *) &msg[1];
GNUNET_free (element_exported);
for (i = 0; i < session->transferred; i++) {
gcry_mpi_release (session->r_prime[i]);
+ session->r_prime[i] = NULL;
gcry_mpi_release (session->r[i]);
+ session->r[i] = NULL;
}
gcry_mpi_release (s);
+ session->s = NULL;
gcry_mpi_release (s_prime);
+ session->s_prime = NULL;
session->msg = (struct GNUNET_MessageHeader *) msg;
session->service_transmit_handle =
- GNUNET_MESH_notify_transmit_ready (session->tunnel,
+ GNUNET_MESH_notify_transmit_ready (session->channel,
GNUNET_YES,
GNUNET_TIME_UNIT_FOREVER_REL,
msg_length,
if (session->transferred != session->used)
// multipart
session->state = WAITING_FOR_MULTIPART_TRANSMISSION;
- else
+ else{
//singlepart
session->state = FINALIZED;
+ GNUNET_free(session->r);
+ GNUNET_free(session->r_prime);
+ session->r_prime = NULL;
+ session->r = NULL;
+ }
return GNUNET_OK;
}
/**
* executed by bob:
* compute the values
- * (1)[]: $E_A(a_{\pi(i)}) \otimes E_A(- r_{\pi(i)} - b_{\pi(i)}) &= E_A(a_{\pi(i)} - r_{\pi(i)} - b_{\pi(i)})$
- * (2)[]: $E_A(a_{\pi'(i)}) \otimes E_A(- r_{\pi'(i)}) &= E_A(a_{\pi'(i)} - r_{\pi'(i)})$
- * S: $S := E_A(\sum (r_i + b_i)^2)$
- * S': $S' := E_A(\sum r_i^2)$
+ * (1)[]: $E_A(a_{pi(i)}) otimes E_A(- r_{pi(i)} - b_{pi(i)}) &= E_A(a_{pi(i)} - r_{pi(i)} - b_{pi(i)})$
+ * (2)[]: $E_A(a_{pi'(i)}) otimes E_A(- r_{pi'(i)}) &= E_A(a_{pi'(i)} - r_{pi'(i)})$
+ * S: $S := E_A(sum (r_i + b_i)^2)$
+ * S': $S' := E_A(sum r_i^2)$
*
* @param request the requesting session + bob's requesting peer
* @param response the responding session + bob's client handle
uint32_t count;
gcry_mpi_t * rand = NULL;
gcry_mpi_t * r = NULL;
+ struct GNUNET_CRYPTO_PaillierCiphertext * R;
gcry_mpi_t * r_prime = NULL;
+ struct GNUNET_CRYPTO_PaillierCiphertext * R_prime;
gcry_mpi_t * b;
gcry_mpi_t * a_pi;
gcry_mpi_t * a_pi_prime;
gcry_mpi_t * rand_pi;
gcry_mpi_t * rand_pi_prime;
gcry_mpi_t s = NULL;
+ struct GNUNET_CRYPTO_PaillierCiphertext * S;
gcry_mpi_t s_prime = NULL;
- gcry_mpi_t remote_n = NULL;
- gcry_mpi_t remote_nsquare;
- gcry_mpi_t remote_g = NULL;
- gcry_sexp_t tmp_exp;
+ struct GNUNET_CRYPTO_PaillierCiphertext * S_prime;
+
uint32_t value;
count = request->used;
rand_pi_prime = GNUNET_malloc (sizeof (gcry_mpi_t) * count);
// convert responder session to from long to mpi
- for (i = 0, j = 0; i < response->total && j < count; i++) {
- if (request->mask[i / 8] & (1 << (i % 8))) {
+ for (i = 0, j = 0; i < response->total && j < count; i++)
+ {
+ if (request->mask[i / 8] & (1 << (i % 8)))
+ {
value = response->vector[i] >= 0 ? response->vector[i] : -response->vector[i];
// long to gcry_mpi_t
- if (0 > response->vector[i]) {
+ if (0 > response->vector[i])
+ {
b[j] = gcry_mpi_new (0);
gcry_mpi_sub_ui (b[j], b[j], value);
}
}
GNUNET_free (response->vector);
response->vector = NULL;
-
- tmp_exp = gcry_sexp_find_token (request->remote_pubkey, "n", 0);
- if (!tmp_exp) {
- GNUNET_break_op (0);
- gcry_sexp_release (request->remote_pubkey);
- request->remote_pubkey = NULL;
- goto except;
- }
- remote_n = gcry_sexp_nth_mpi (tmp_exp, 1, GCRYMPI_FMT_USG);
- if (!remote_n) {
- GNUNET_break (0);
- gcry_sexp_release (tmp_exp);
- goto except;
- }
- remote_nsquare = gcry_mpi_new (KEYBITS + 1);
- gcry_mpi_mul (remote_nsquare, remote_n, remote_n);
- gcry_sexp_release (tmp_exp);
- tmp_exp = gcry_sexp_find_token (request->remote_pubkey, "g", 0);
- gcry_sexp_release (request->remote_pubkey);
- request->remote_pubkey = NULL;
- if (!tmp_exp) {
- GNUNET_break_op (0);
- gcry_mpi_release (remote_n);
- goto except;
- }
- remote_g = gcry_sexp_nth_mpi (tmp_exp, 1, GCRYMPI_FMT_USG);
- if (!remote_g) {
- GNUNET_break (0);
- gcry_mpi_release (remote_n);
- gcry_sexp_release (tmp_exp);
- goto except;
- }
- gcry_sexp_release (tmp_exp);
+ q = NULL;
+ p = NULL;
// generate r, p and q
rand = initialize_mpi_vector (count);
- for (i = 0; i < count; i++) {
- value = (int32_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
+ for (i = 0; i < count; i++)
+ {
+ int32_t svalue;
+
+ svalue = (int32_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
// long to gcry_mpi_t
- if (value < 0)
+ if (svalue < 0)
gcry_mpi_sub_ui (rand[i],
rand[i],
- -value);
+ -svalue);
else
- rand[i] = gcry_mpi_set_ui (rand[i], value);
+ rand[i] = gcry_mpi_set_ui (rand[i], svalue);
}
p = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, count);
q = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, count);
memcpy (b_pi, b, sizeof (gcry_mpi_t) * count);
memcpy (rand_pi, rand, sizeof (gcry_mpi_t) * count);
memcpy (rand_pi_prime, rand, sizeof (gcry_mpi_t) * count);
+
+ //todo get API-cryptoblocks, instead of MPI values
// generate p and q permutations for a, b and r
+ // TODO: APIify
GNUNET_assert (permute_vector (a_pi, p, count));
GNUNET_assert (permute_vector (b_pi, p, count));
GNUNET_assert (permute_vector (rand_pi, p, count));
// vectors, which get rid of all the lookups in p/q.
// however, ap/aq are not absolutely necessary but are just abstraction
// Calculate Kp = E(S + a_pi) (+) E(S - r_pi - b_pi)
- for (i = 0; i < count; i++) {
+ for (i = 0; i < count; i++)
+ {
// E(S - r_pi - b_pi)
gcry_mpi_sub (r[i], my_offset, rand_pi[i]);
gcry_mpi_sub (r[i], r[i], b_pi[i]);
- encrypt_element (r[i], r[i], remote_g, remote_n, remote_nsquare);
-
+ GNUNET_CRYPTO_paillier_encrypt (&request->remote_pubkey,
+ r[i],
+ &R[i]);
+
// E(S - r_pi - b_pi) * E(S + a_pi) == E(2*S + a - r - b)
- gcry_mpi_mulm (r[i], r[i], a_pi[i], remote_nsquare);
+ GNUNET_CRYPTO_paillier_hom_add (&request->remote_pubkey,
+ &R[i],
+ &A_pi[i],
+ &R[i]);
}
GNUNET_free (a_pi);
GNUNET_free (b_pi);
GNUNET_free (rand_pi);
// Calculate Kq = E(S + a_qi) (+) E(S - r_qi)
- for (i = 0; i < count; i++) {
+ for (i = 0; i < count; i++)
+ {
// E(S - r_qi)
gcry_mpi_sub (r_prime[i], my_offset, rand_pi_prime[i]);
- encrypt_element (r_prime[i], r_prime[i], remote_g, remote_n, remote_nsquare);
+ GNUNET_CRYPTO_paillier_encrypt (&request->remote_pubkey,
+ r_prime[i],
+ &R_prime[i]);
// E(S - r_qi) * E(S + a_qi) == E(2*S + a_qi - r_qi)
- gcry_mpi_mulm (r_prime[i], r_prime[i], a_pi_prime[i], remote_nsquare);
+ GNUNET_CRYPTO_paillier_hom_add (&request->remote_pubkey,
+ &R_prime[i],
+ &A_pi_prime[i],
+ &R_prime[i]);
}
GNUNET_free (a_pi_prime);
GNUNET_free (rand_pi_prime);
// Calculate S' = E(SUM( r_i^2 ))
s_prime = compute_square_sum (rand, count);
- encrypt_element (s_prime, s_prime, remote_g, remote_n, remote_nsquare);
+ GNUNET_CRYPTO_paillier_encrypt (&request->remote_pubkey,
+ s_prime,
+ &S_prime);
// Calculate S = E(SUM( (r_i + b_i)^2 ))
for (i = 0; i < count; i++) {
gcry_mpi_add (rand[i], rand[i], b[i]);
}
s = compute_square_sum (rand, count);
- encrypt_element (s, s, remote_g, remote_n, remote_nsquare);
- gcry_mpi_release (remote_n);
- gcry_mpi_release (remote_g);
- gcry_mpi_release (remote_nsquare);
+ GNUNET_CRYPTO_paillier_encrypt (&request->remote_pubkey,
+ s[i],
+ &S);
// release r and tmp
for (i = 0; i < count; i++)
gcry_mpi_release (rand[i]);
// copy the r[], r_prime[], S and Stick into a new message, prepare_service_response frees these
- if (GNUNET_YES != prepare_service_response (s, s_prime, request))
+ if (GNUNET_YES != prepare_service_response (S, S_prime, request))
GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Failed to communicate with `%s', scalar product calculation aborted.\n"),
GNUNET_i2s (&request->peer));
else
ret = GNUNET_OK;
except:
- for (i = 0; i < count; i++) {
+ for (i = 0; i < count; i++)
+ {
gcry_mpi_release (b[i]);
gcry_mpi_release (request->a[i]);
}
GNUNET_free (b);
GNUNET_free (request->a);
request->a = NULL;
-
+ GNUNET_free_non_null (p);
+ GNUNET_free_non_null (q);
+ GNUNET_free (rand);
return ret;
}
* Send a multi part chunk of a service request from alice to bob.
* This element only contains a part of the elements-vector (session->a[]),
* mask and public key set have to be contained within the first message
- *
+ *
* This allows a ~32kbit key length while using 32000 elements or 62000 elements per request.
- *
+ *
* @param cls the associated service session
*/
static void
a = gcry_mpi_new (KEYBITS * 2);
current = (unsigned char *) &msg[1];
// encrypt our vector and generate string representations
- for (i = session->last_processed, j = 0; i < session->total; i++) {
+ for (i = session->last_processed, j = 0; i < session->total; i++)
+ {
// is this a used element?
if (session->mask[i / 8] & 1 << (i % 8)) {
if (todo_count <= j)
GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Transmitting service request.\n"));
//transmit via mesh messaging
- session->service_transmit_handle = GNUNET_MESH_notify_transmit_ready (session->tunnel, GNUNET_YES,
+ session->service_transmit_handle = GNUNET_MESH_notify_transmit_ready (session->channel, GNUNET_YES,
GNUNET_TIME_UNIT_FOREVER_REL,
msg_length,
&do_send_message,
session);
if (!session->service_transmit_handle) {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Could not send service-request multipart message to tunnel!\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Could not send service-request multipart message to channel!\n"));
GNUNET_free (msg);
session->msg = NULL;
session->client_notification_task =
session->service_request_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Successfully created new tunnel to peer (%s)!\n"), GNUNET_i2s (&session->peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Successfully created new channel to peer (%s)!\n"), GNUNET_i2s (&session->peer));
msg_length = sizeof (struct GNUNET_SCALARPRODUCT_service_request)
+session->mask_length
GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Transmitting service request.\n"));
//transmit via mesh messaging
- session->service_transmit_handle = GNUNET_MESH_notify_transmit_ready (session->tunnel, GNUNET_YES,
+ session->service_transmit_handle = GNUNET_MESH_notify_transmit_ready (session->channel, GNUNET_YES,
GNUNET_TIME_UNIT_FOREVER_REL,
msg_length,
&do_send_message,
session);
if (!session->service_transmit_handle) {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Could not send message to tunnel!\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Could not send message to channel!\n"));
GNUNET_free (msg);
session->msg = NULL;
session->client_notification_task =
if ((ntohs (msg->header.size) != (sizeof (struct GNUNET_SCALARPRODUCT_client_request) +element_count * sizeof (int32_t) + mask_length))
|| (0 == element_count)) {
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _ ("Invalid message received from client, session information incorrect!\n"));
+ _("Invalid message received from client, session information incorrect!\n"));
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
element_count,
NULL, NULL)) {
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _ ("Duplicate session information received, cannot create new session with key `%s'\n"),
+ _("Duplicate session information received, cannot create new session with key `%s'\n"),
GNUNET_h2s (&msg->key));
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
session->vector = GNUNET_malloc (sizeof (int32_t) * element_count);
vector = (int32_t *) & msg[1];
- if (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE == msg_type) {
+ if (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE == msg_type)
+ {
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _ ("Got client-request-session with key %s, preparing tunnel to remote service.\n"),
+ _("Got client-request-session with key %s, preparing channel to remote service.\n"),
GNUNET_h2s (&session->key));
session->role = ALICE;
// copy over the elements
session->used = 0;
- for (i = 0; i < element_count; i++) {
+ for (i = 0; i < element_count; i++)
+ {
session->vector[i] = ntohl (vector[i]);
if (session->vector[i] == 0)
session->mask[i / 8] &= ~(1 << (i % 8));
session->used++;
}
- if (0 == session->used) {
+ if (0 == session->used)
+ {
GNUNET_break_op (0);
GNUNET_free (session->vector);
GNUNET_free (session);
return;
}
//session with ourself makes no sense!
- if (!memcmp (&msg->peer, &me, sizeof (struct GNUNET_PeerIdentity))) {
+ if (!memcmp (&msg->peer, &me, sizeof (struct GNUNET_PeerIdentity)))
+ {
GNUNET_break (0);
GNUNET_free (session->vector);
GNUNET_free (session);
// get our peer ID
memcpy (&session->peer, &msg->peer, sizeof (struct GNUNET_PeerIdentity));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _ ("Creating new tunnel to for session with key %s.\n"),
+ _ ("Creating new channel for session with key %s.\n"),
GNUNET_h2s (&session->key));
- session->tunnel = GNUNET_MESH_tunnel_create (my_mesh, session,
+ session->channel = GNUNET_MESH_channel_create (my_mesh, session,
&session->peer,
GNUNET_APPLICATION_TYPE_SCALARPRODUCT,
- GNUNET_NO,
- GNUNET_YES);
- //prepare_service_request, tunnel_peer_disconnect_handler,
- if (!session->tunnel) {
+ GNUNET_MESH_OPTION_RELIABLE);
+ //prepare_service_request, channel_peer_disconnect_handler,
+ if (!session->channel) {
GNUNET_break (0);
GNUNET_free (session->vector);
GNUNET_free (session);
session);
}
- else {
+ else
+ {
struct ServiceSession * requesting_session;
enum SessionState needed_state = SERVICE_REQUEST_RECEIVED;
&session->key,
session->total,
&needed_state, NULL);
- if (NULL != requesting_session) {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Got client-responder-session with key %s and a matching service-request-session set, processing.\n"), GNUNET_h2s (&session->key));
+ if (NULL != requesting_session)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Got client-responder-session with key %s and a matching service-request-session set, processing.\n"),
+ GNUNET_h2s (&session->key));
if (GNUNET_OK != compute_service_response (requesting_session, session))
session->client_notification_task =
GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
session);
}
- else {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Got client-responder-session with key %s but NO matching service-request-session set, queuing element for later use.\n"), GNUNET_h2s (&session->key));
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Got client-responder-session with key %s but NO matching service-request-session set, queuing element for later use.\n"),
+ GNUNET_h2s (&session->key));
// no matching session exists yet, store the response
// for later processing by handle_service_request()
}
/**
- * Function called for inbound tunnels.
+ * Function called for inbound channels.
*
* @param cls closure
- * @param tunnel new handle to the tunnel
- * @param initiator peer that started the tunnel
+ * @param channel new handle to the channel
+ * @param initiator peer that started the channel
* @param port unused
- * @return session associated with the tunnel
+ * @param options unused
+ *
+ * @return session associated with the channel
*/
static void *
-tunnel_incoming_handler (void *cls,
- struct GNUNET_MESH_Tunnel *tunnel,
+channel_incoming_handler (void *cls,
+ struct GNUNET_MESH_Channel *channel,
const struct GNUNET_PeerIdentity *initiator,
- uint32_t port)
+ uint32_t port, enum GNUNET_MESH_ChannelOption options)
{
struct ServiceSession * c = GNUNET_new (struct ServiceSession);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ _("New incoming channel from peer %s.\n"),
+ GNUNET_i2s (initiator));
+
c->peer = *initiator;
- c->tunnel = tunnel;
+ c->channel = channel;
c->role = BOB;
c->state = WAITING_FOR_SERVICE_REQUEST;
return c;
/**
- * Function called whenever a tunnel is destroyed. Should clean up
+ * Function called whenever a channel is destroyed. Should clean up
* any associated state.
*
- * It must NOT call GNUNET_MESH_tunnel_destroy on the tunnel.
+ * It must NOT call GNUNET_MESH_channel_destroy on the channel.
*
* @param cls closure (set from GNUNET_MESH_connect)
- * @param tunnel connection to the other end (henceforth invalid)
- * @param tunnel_ctx place where local state associated
- * with the tunnel is stored
+ * @param channel connection to the other end (henceforth invalid)
+ * @param channel_ctx place where local state associated
+ * with the channel is stored
*/
static void
-tunnel_destruction_handler (void *cls,
- const struct GNUNET_MESH_Tunnel *tunnel,
- void *tunnel_ctx)
+channel_destruction_handler (void *cls,
+ const struct GNUNET_MESH_Channel *channel,
+ void *channel_ctx)
{
- struct ServiceSession * session = tunnel_ctx;
+ struct ServiceSession * session = channel_ctx;
struct ServiceSession * client_session;
struct ServiceSession * curr;
// as we have only one peer connected in each session, just remove the session
if ((SERVICE_RESPONSE_RECEIVED > session->state) && (!do_shutdown)) {
- session->tunnel = NULL;
+ session->channel = NULL;
// if this happened before we received the answer, we must terminate the session
session->client_notification_task =
GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
uint32_t count;
gcry_mpi_t t;
gcry_mpi_t u;
- gcry_mpi_t utick;
+ gcry_mpi_t u_prime;
gcry_mpi_t p;
- gcry_mpi_t ptick;
+ gcry_mpi_t p_prime;
gcry_mpi_t tmp;
unsigned int i;
count = session->used;
- tmp = gcry_mpi_new (KEYBITS);
// due to the introduced static offset S, we now also have to remove this
// from the E(a_pi)(+)E(-b_pi-r_pi) and E(a_qi)(+)E(-r_qi) twice each,
// the result is E((S + a_pi) + (S -b_pi-r_pi)) and E(S + a_qi + S - r_qi)
- for (i = 0; i < count; i++) {
+ for (i = 0; i < count; i++)
+ {
decrypt_element (session->r[i], session->r[i], my_mu, my_lambda, my_n, my_nsquare);
gcry_mpi_sub (session->r[i], session->r[i], my_offset);
gcry_mpi_sub (session->r[i], session->r[i], my_offset);
gcry_mpi_release (tmp);
//calculate U'
- utick = gcry_mpi_new (0);
+ u_prime = gcry_mpi_new (0);
tmp = compute_square_sum (session->r_prime, count);
- gcry_mpi_sub (utick, utick, tmp);
+ gcry_mpi_sub (u_prime, u_prime, tmp);
GNUNET_assert (p = gcry_mpi_new (0));
- GNUNET_assert (ptick = gcry_mpi_new (0));
+ GNUNET_assert (p_prime = gcry_mpi_new (0));
// compute P
decrypt_element (session->s, session->s, my_mu, my_lambda, my_n, my_nsquare);
gcry_mpi_add (p, p, u);
// compute P'
- gcry_mpi_add (ptick, session->s_prime, t);
- gcry_mpi_add (ptick, ptick, utick);
+ gcry_mpi_add (p_prime, session->s_prime, t);
+ gcry_mpi_add (p_prime, p_prime, u_prime);
gcry_mpi_release (t);
gcry_mpi_release (u);
- gcry_mpi_release (utick);
+ gcry_mpi_release (u_prime);
// compute product
- gcry_mpi_sub (p, p, ptick);
- gcry_mpi_release (ptick);
+ gcry_mpi_sub (p, p, p_prime);
+ gcry_mpi_release (p_prime);
tmp = gcry_mpi_set_ui (tmp, 2);
gcry_mpi_div (p, NULL, p, tmp, 0);
* Handle a multipart-chunk of a request from another service to calculate a scalarproduct with us.
*
* @param cls closure (set from #GNUNET_MESH_connect)
- * @param tunnel connection to the other end
- * @param tunnel_ctx place to store local state associated with the tunnel
+ * @param channel connection to the other end
+ * @param channel_ctx place to store local state associated with the channel
* @param message the actual message
* @return #GNUNET_OK to keep the connection open,
* #GNUNET_SYSERR to close it (signal serious error)
*/
static int
handle_service_request_multipart (void *cls,
- struct GNUNET_MESH_Tunnel * tunnel,
- void **tunnel_ctx,
+ struct GNUNET_MESH_Channel * channel,
+ void **channel_ctx,
const struct GNUNET_MessageHeader * message)
{
struct ServiceSession * session;
int32_t i = -1;
// are we in the correct state?
- session = (struct ServiceSession *) * tunnel_ctx;
+ session = (struct ServiceSession *) * channel_ctx;
if ((BOB != session->role) || (WAITING_FOR_MULTIPART_TRANSMISSION != session->state)) {
goto except;
}
}
session->transferred += contained_elements;
- if (session->transferred == used_elements) {
+ if (session->transferred == used_elements)
+ {
// single part finished
session->state = SERVICE_REQUEST_RECEIVED;
- if (session->response) {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Got session with key %s and a matching element set, processing.\n"), GNUNET_h2s (&session->key));
+ if (session->response)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _ ("Got session with key %s and a matching element set, processing.\n"),
+ GNUNET_h2s (&session->key));
if (GNUNET_OK != compute_service_response (session, session->response)) {
//something went wrong, remove it again...
goto except;
}
}
else
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Got session with key %s without a matching element set, queueing.\n"), GNUNET_h2s (&session->key));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("Got session with key %s without a matching element set, queueing.\n"),
+ GNUNET_h2s (&session->key));
}
- else {
+ else
+ {
// multipart message
}
}
* Handle a request from another service to calculate a scalarproduct with us.
*
* @param cls closure (set from #GNUNET_MESH_connect)
- * @param tunnel connection to the other end
- * @param tunnel_ctx place to store local state associated with the tunnel
+ * @param channel connection to the other end
+ * @param channel_ctx place to store local state associated with the channel
* @param message the actual message
* @return #GNUNET_OK to keep the connection open,
* #GNUNET_SYSERR to close it (signal serious error)
*/
static int
handle_service_request (void *cls,
- struct GNUNET_MESH_Tunnel * tunnel,
- void **tunnel_ctx,
+ struct GNUNET_MESH_Channel * channel,
+ void **channel_ctx,
const struct GNUNET_MessageHeader * message)
{
struct ServiceSession * session;
int32_t i = -1;
enum SessionState needed_state;
- session = (struct ServiceSession *) * tunnel_ctx;
+ session = (struct ServiceSession *) * channel_ctx;
if (WAITING_FOR_SERVICE_REQUEST != session->state) {
goto invalid_msg;
}
+mask_length + pk_length + contained_elements * PAILLIER_ELEMENT_LENGTH;
//sanity check: is the message as long as the message_count fields suggests?
- if ((ntohs (msg->header.size) != msg_length) || (element_count < used_elements) || (used_elements < contained_elements)
- || (used_elements == 0) || (mask_length != (element_count / 8 + (element_count % 8 ? 1 : 0)))
- ) {
+ if ( (ntohs (msg->header.size) != msg_length) ||
+ (element_count < used_elements) ||
+ (used_elements < contained_elements) ||
+ (0 == used_elements) ||
+ (mask_length != (element_count / 8 + ((element_count % 8) ? 1 : 0))) )
+ {
GNUNET_free (session);
GNUNET_break_op (0);
return GNUNET_SYSERR;
&msg->key,
element_count,
NULL,
- NULL)) {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Got message with duplicate session key (`%s'), ignoring service request.\n"), (const char *) &(msg->key));
+ NULL))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Got message with duplicate session key (`%s'), ignoring service request.\n"),
+ (const char *) &(msg->key));
GNUNET_free (session);
return GNUNET_SYSERR;
}
- memcpy (&session->peer, &session->peer, sizeof (struct GNUNET_PeerIdentity));
session->total = element_count;
session->used = used_elements;
session->transferred = contained_elements;
- session->tunnel = tunnel;
+ session->channel = channel;
// session key
memcpy (&session->key, &msg->key, sizeof (struct GNUNET_HashCode));
* Handle a multipart chunk of a response we got from another service we wanted to calculate a scalarproduct with.
*
* @param cls closure (set from #GNUNET_MESH_connect)
- * @param tunnel connection to the other end
- * @param tunnel_ctx place to store local state associated with the tunnel
+ * @param channel connection to the other end
+ * @param channel_ctx place to store local state associated with the channel
* @param message the actual message
* @return #GNUNET_OK to keep the connection open,
* #GNUNET_SYSERR to close it (signal serious error)
*/
static int
handle_service_response_multipart (void *cls,
- struct GNUNET_MESH_Tunnel * tunnel,
- void **tunnel_ctx,
+ struct GNUNET_MESH_Channel * channel,
+ void **channel_ctx,
const struct GNUNET_MessageHeader * message)
{
struct ServiceSession * session;
size_t i;
uint32_t contained = 0;
size_t msg_size;
+ size_t required_size;
int rc;
GNUNET_assert (NULL != message);
// are we in the correct state?
- session = (struct ServiceSession *) * tunnel_ctx;
+ session = (struct ServiceSession *) * channel_ctx;
if ((ALICE != session->role) || (WAITING_FOR_MULTIPART_TRANSMISSION != session->state)) {
goto invalid_msg;
}
+ msg_size = ntohs (msg->header.size);
+ required_size = sizeof (struct GNUNET_SCALARPRODUCT_multipart_message) + 2 * PAILLIER_ELEMENT_LENGTH;
// shorter than minimum?
- if (ntohs (msg->header.size) <= sizeof (struct GNUNET_SCALARPRODUCT_multipart_message)) {
+ if (required_size > msg_size) {
goto invalid_msg;
}
contained = ntohl (msg->multipart_element_count);
- msg_size = sizeof (struct GNUNET_SCALARPRODUCT_multipart_message)
+ required_size = sizeof (struct GNUNET_SCALARPRODUCT_multipart_message)
+ 2 * contained * PAILLIER_ELEMENT_LENGTH;
//sanity check: is the message as long as the message_count fields suggests?
- if ((ntohs (msg->header.size) != msg_size) || (session->used < contained)) {
+ if ((required_size != msg_size) || (session->used < session->transferred + contained)) {
goto invalid_msg;
}
current = (unsigned char *) &msg[1];
if (session->transferred != session->used)
return GNUNET_OK;
session->state = SERVICE_RESPONSE_RECEIVED;
- session->product = compute_scalar_product (session);
- return GNUNET_SYSERR; // terminate the tunnel right away, we are done here!
+ session->product = compute_scalar_product (session); //never NULL
invalid_msg:
- GNUNET_break_op (0);
- free_session_variables (session);
- session->state = FINALIZED;
- session->tunnel = NULL;
+ GNUNET_break_op (NULL != session->product);
+
// send message with product to client
- if (ALICE == session->role)
+ if (ALICE == session->role){
+ session->state = FINALIZED;
+ session->channel = NULL;
session->client_notification_task =
GNUNET_SCHEDULER_add_now (&prepare_client_response,
session);
- // the tunnel has done its job, terminate our connection and the tunnel
- // the peer will be notified that the tunnel was destroyed via tunnel_destruction_handler
+ }
+ // the channel has done its job, terminate our connection and the channel
+ // the peer will be notified that the channel was destroyed via channel_destruction_handler
// just close the connection, as recommended by Christian
return GNUNET_SYSERR;
}
* Handle a response we got from another service we wanted to calculate a scalarproduct with.
*
* @param cls closure (set from #GNUNET_MESH_connect)
- * @param tunnel connection to the other end
- * @param tunnel_ctx place to store local state associated with the tunnel
+ * @param channel connection to the other end
+ * @param channel_ctx place to store local state associated with the channel
* @param message the actual message
* @return #GNUNET_OK to keep the connection open,
* #GNUNET_SYSERR to close it (we are done)
*/
static int
handle_service_response (void *cls,
- struct GNUNET_MESH_Tunnel * tunnel,
- void **tunnel_ctx,
+ struct GNUNET_MESH_Channel * channel,
+ void **channel_ctx,
const struct GNUNET_MessageHeader * message)
{
struct ServiceSession * session;
size_t i;
uint32_t contained = 0;
size_t msg_size;
+ size_t required_size;
int rc;
GNUNET_assert (NULL != message);
- session = (struct ServiceSession *) * tunnel_ctx;
+ session = (struct ServiceSession *) * channel_ctx;
// are we in the correct state?
- if (session->state != WAITING_FOR_SERVICE_REQUEST) {
+ if (WAITING_FOR_SERVICE_RESPONSE != session->state) {
goto invalid_msg;
}
//we need at least a full message without elements attached
- if (sizeof (struct GNUNET_SCALARPRODUCT_service_response) + 2 * PAILLIER_ELEMENT_LENGTH > ntohs (msg->header.size)) {
+ msg_size = ntohs (msg->header.size);
+ required_size = sizeof (struct GNUNET_SCALARPRODUCT_service_response) + 2 * PAILLIER_ELEMENT_LENGTH;
+
+ if (required_size > msg_size) {
goto invalid_msg;
}
contained = ntohl (msg->contained_element_count);
- msg_size = sizeof (struct GNUNET_SCALARPRODUCT_service_response)
+ required_size = sizeof (struct GNUNET_SCALARPRODUCT_service_response)
+ 2 * contained * PAILLIER_ELEMENT_LENGTH
+ 2 * PAILLIER_ELEMENT_LENGTH;
//sanity check: is the message as long as the message_count fields suggests?
- if ((ntohs (msg->header.size) != msg_size) || (session->used < contained)) {
+ if ((msg_size != required_size) || (session->used < contained)) {
goto invalid_msg;
}
session->state = WAITING_FOR_MULTIPART_TRANSMISSION;
return GNUNET_OK; //wait for the other multipart chunks
session->state = SERVICE_RESPONSE_RECEIVED;
- session->product = compute_scalar_product (session);
- return GNUNET_SYSERR; // terminate the tunnel right away, we are done here!
+ session->product = compute_scalar_product (session); //never NULL
invalid_msg:
- GNUNET_break_op (0);
- free_session_variables (session);
- session->state = FINALIZED;
- session->tunnel = NULL;
+ GNUNET_break_op (NULL != session->product);
// send message with product to client
- if (ALICE == session->role)
+ if (ALICE == session->role){
+ session->state = FINALIZED;
+ session->channel = NULL;
session->client_notification_task =
GNUNET_SCHEDULER_add_now (&prepare_client_response,
session);
- // the tunnel has done its job, terminate our connection and the tunnel
- // the peer will be notified that the tunnel was destroyed via tunnel_destruction_handler
+ }
+ // the channel has done its job, terminate our connection and the channel
+ // the peer will be notified that the channel was destroyed via channel_destruction_handler
// just close the connection, as recommended by Christian
return GNUNET_SYSERR;
}
do_shutdown = GNUNET_YES;
- // terminate all owned open tunnels.
+ // terminate all owned open channels.
for (session = from_client_head; NULL != session; session = session->next) {
- if ((FINALIZED != session->state) && (NULL != session->tunnel)) {
- GNUNET_MESH_tunnel_destroy (session->tunnel);
- session->tunnel = NULL;
+ if ((FINALIZED != session->state) && (NULL != session->channel)) {
+ GNUNET_MESH_channel_destroy (session->channel);
+ session->channel = NULL;
}
if (GNUNET_SCHEDULER_NO_TASK != session->client_notification_task) {
GNUNET_SCHEDULER_cancel (session->client_notification_task);
}
}
for (session = from_service_head; NULL != session; session = session->next)
- if (NULL != session->tunnel) {
- GNUNET_MESH_tunnel_destroy (session->tunnel);
- session->tunnel = NULL;
+ if (NULL != session->channel) {
+ GNUNET_MESH_channel_destroy (session->channel);
+ session->channel = NULL;
}
if (my_mesh) {
GNUNET_CRYPTO_get_peer_identity (c,
&me));
my_mesh = GNUNET_MESH_connect (c, NULL,
- &tunnel_incoming_handler,
- &tunnel_destruction_handler,
+ &channel_incoming_handler,
+ &channel_destruction_handler,
mesh_handlers, ports);
if (!my_mesh) {
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Connect to MESH failed\n"));
&run, NULL)) ? 0 : 1;
}
-/* end of gnunet-service-ext.c */
+/* end of gnunet-service-scalarproduct.c */