#include <gcrypt.h>
#include "gnunet_util_lib.h"
#include "gnunet_core_service.h"
-#include "gnunet_mesh_service.h"
+#include "gnunet_cadet_service.h"
#include "gnunet_applications.h"
#include "gnunet_protocols.h"
#include "gnunet_scalarproduct_service.h"
BOB
};
-
+/**
+ * DLL for sorting elements
+ */
struct SortedValue
{
+ /**
+ * Sorted Values are kept in a DLL
+ */
struct SortedValue * next;
+
+ /**
+ * Sorted Values are kept in a DLL
+ */
struct SortedValue * prev;
+
+ /**
+ * The element's id+integer-value
+ */
struct GNUNET_SCALARPRODUCT_Element * elem;
+
+ /**
+ * the element's value converted to MPI
+ */
gcry_mpi_t val;
};
* Alice or Bob's peerID
*/
struct GNUNET_PeerIdentity peer;
-
+
/**
* the client this request is related to
*/
/**
* Public key of the remote service, only used by bob
*/
- struct GNUNET_CRYPTO_PaillierPublicKey remote_pubkey;
+ struct GNUNET_CRYPTO_PaillierPublicKey * remote_pubkey;
/**
* DLL for sorting elements after intersection
/**
* My transmit handle for the current message to a alice/bob
*/
- struct GNUNET_MESH_TransmitHandle * service_transmit_handle;
+ struct GNUNET_CADET_TransmitHandle * service_transmit_handle;
/**
* My transmit handle for the current message to the client
struct GNUNET_SERVER_TransmitHandle * client_transmit_handle;
/**
- * channel-handle associated with our mesh handle
+ * channel-handle associated with our cadet handle
*/
- struct GNUNET_MESH_Channel * channel;
+ struct GNUNET_CADET_Channel * channel;
/**
* Handle to a task that sends a msg to the our client
/**
* Handle to the core service (NULL until we've connected to it).
*/
-static struct GNUNET_MESH_Handle *my_mesh;
+static struct GNUNET_CADET_Handle *my_cadet;
/**
* The identity of this host.
static struct ServiceSession * from_service_tail;
/**
- * Certain events (callbacks for server & mesh operations) must not be queued after shutdown.
+ * Certain events (callbacks for server & cadet operations) must not be queued after shutdown.
*/
static int do_shutdown;
GNUNET_free (session->e_a);
session->e_a = NULL;
}
+ if (session->remote_pubkey){
+ GNUNET_free(session->remote_pubkey);
+ session->remote_pubkey=NULL;
+ }
if (session->sorted_elements) {
GNUNET_free (session->sorted_elements);
session->sorted_elements = NULL;
GNUNET_SET_destroy (session->intersection_set);
session->intersection_set = NULL;
}
+ if (session->channel){
+ GNUNET_CADET_channel_destroy(session->channel);
+ session->channel = NULL;
+ }
if (session->msg) {
GNUNET_free (session->msg);
session->msg = NULL;
if (!(session->role == BOB && 0/*//TODO: if session concluded*/)) {
//we MUST terminate any client message underway
if (session->service_transmit_handle && session->channel)
- GNUNET_MESH_notify_transmit_ready_cancel (session->service_transmit_handle);
+ GNUNET_CADET_notify_transmit_ready_cancel (session->service_transmit_handle);
if (session->channel && 0/* //TODO: waiting for service response */)
- GNUNET_MESH_channel_destroy (session->channel);
+ GNUNET_CADET_channel_destroy (session->channel);
}
if (GNUNET_SCHEDULER_NO_TASK != session->client_notification_task) {
GNUNET_SCHEDULER_cancel (session->client_notification_task);
session->msg = (struct GNUNET_MessageHeader *) msg;
GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Transmitting service request.\n"));
- //transmit via mesh messaging
- session->service_transmit_handle = GNUNET_MESH_notify_transmit_ready (session->channel, GNUNET_YES,
+ //transmit via cadet messaging
+ session->service_transmit_handle = GNUNET_CADET_notify_transmit_ready (session->channel, GNUNET_YES,
GNUNET_TIME_UNIT_FOREVER_REL,
msg_length,
&do_send_message,
session->transferred_element_count += todo_count;
session->msg = (struct GNUNET_MessageHeader *) msg;
session->service_transmit_handle =
- GNUNET_MESH_notify_transmit_ready (session->channel,
+ GNUNET_CADET_notify_transmit_ready (session->channel,
GNUNET_YES,
GNUNET_TIME_UNIT_FOREVER_REL,
msg_length,
session);
//disconnect our client
if (NULL == session->service_transmit_handle) {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Could not send service-response message via mesh!)\n"));
-
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Could not send service-response message via cadet!)\n"));
+
+ GNUNET_free (msg);
+ session->msg = NULL;
+ GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session);
+
session->response->client_notification_task =
GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
session->response);
+ free_session_variables(session);
+ GNUNET_free(session);
return;
}
if (session->transferred_element_count != session->used_elements_count) {
session->msg = (struct GNUNET_MessageHeader *) msg;
session->service_transmit_handle =
- GNUNET_MESH_notify_transmit_ready (session->channel,
+ GNUNET_CADET_notify_transmit_ready (session->channel,
GNUNET_YES,
GNUNET_TIME_UNIT_FOREVER_REL,
msg_length,
session);
//disconnect our client
if (NULL == session->service_transmit_handle) {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Could not send service-response message via mesh!)\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Could not send service-response message via cadet!)\n"));
+ GNUNET_free (msg);
+ session->msg = NULL;
+ GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session);
+
session->response->client_notification_task =
GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
session->response);
+ free_session_variables(session);
+ GNUNET_free(session);
+ return;
}
if (session->transferred_element_count != session->used_elements_count) {
// multipart
// E(S - r_pi - b_pi)
gcry_mpi_sub (tmp, my_offset, rand[p[i]]);
gcry_mpi_sub (tmp, tmp, b[p[i]]);
- GNUNET_CRYPTO_paillier_encrypt (&session->remote_pubkey,
+ GNUNET_CRYPTO_paillier_encrypt (session->remote_pubkey,
tmp,
2,
&r[i]);
// E(S - r_pi - b_pi) * E(S + a_pi) == E(2*S + a - r - b)
- GNUNET_CRYPTO_paillier_hom_add (&session->remote_pubkey,
+ GNUNET_CRYPTO_paillier_hom_add (session->remote_pubkey,
&r[i],
&a[p[i]],
&r[i]);
for (i = 0; i < count; i++) {
// E(S - r_qi)
gcry_mpi_sub (tmp, my_offset, rand[q[i]]);
- GNUNET_assert (2 == GNUNET_CRYPTO_paillier_encrypt (&session->remote_pubkey,
+ GNUNET_assert (2 == GNUNET_CRYPTO_paillier_encrypt (session->remote_pubkey,
tmp,
2,
&r_prime[i]));
// E(S - r_qi) * E(S + a_qi) == E(2*S + a_qi - r_qi)
- GNUNET_assert (1 == GNUNET_CRYPTO_paillier_hom_add (&session->remote_pubkey,
+ GNUNET_assert (1 == GNUNET_CRYPTO_paillier_hom_add (session->remote_pubkey,
&r_prime[i],
&a[q[i]],
&r_prime[i]));
// Calculate S' = E(SUM( r_i^2 ))
tmp = compute_square_sum (rand, count);
- GNUNET_CRYPTO_paillier_encrypt (&session->remote_pubkey,
+ GNUNET_CRYPTO_paillier_encrypt (session->remote_pubkey,
tmp,
1,
s_prime);
for (i = 0; i < count; i++)
gcry_mpi_add (rand[i], rand[i], b[i]);
tmp = compute_square_sum (rand, count);
- GNUNET_CRYPTO_paillier_encrypt (&session->remote_pubkey,
+ GNUNET_CRYPTO_paillier_encrypt (session->remote_pubkey,
tmp,
1,
s);
while (NULL != o);
// broken DLL
GNUNET_assert (0);
- return GNUNET_NO;
}
session->sorted_elements = GNUNET_malloc (session->used_elements_count * sizeof (gcry_mpi_t));
for (i = 0; NULL != session->a_head; i++) {
struct SortedValue* a = session->a_head;
- if (i > session->used_elements_count) {
- GNUNET_assert (0);
- return;
- }
+ GNUNET_assert (i < session->used_elements_count);
+
session->sorted_elements[i] = a->val;
GNUNET_CONTAINER_DLL_remove (session->a_head, session->a_tail, a);
GNUNET_free (a->elem);
}
- if (i != session->used_elements_count)
- GNUNET_assert (0);
+ GNUNET_assert (i == session->used_elements_count);
if (ALICE == session->role) {
prepare_alices_cyrptodata_message (session);
return;
}
- else {
- if (session->used_elements_count == session->transferred_element_count)
- compute_service_response (session);
-
+ else if (session->used_elements_count == session->transferred_element_count) {
+ compute_service_response (session);
return;
}
default:
}
//failed if we go here
+ GNUNET_break (0);
+
+ // and notify our client-session that we could not complete the session
if (ALICE == session->role) {
session->client_notification_task =
GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
session);
}
else {
- //TODO: Fail service session, exit tunnel
-
-
+ GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session);
+ free_session_variables (session);
session->response->client_notification_task =
GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
session->response);
-
+ GNUNET_free(session);
}
}
session->msg = (struct GNUNET_MessageHeader *) msg;
GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Transmitting service request.\n"));
- //transmit via mesh messaging
- session->service_transmit_handle = GNUNET_MESH_notify_transmit_ready (session->channel, GNUNET_YES,
+ //transmit via cadet messaging
+ session->service_transmit_handle = GNUNET_CADET_notify_transmit_ready (session->channel, GNUNET_YES,
GNUNET_TIME_UNIT_FOREVER_REL,
sizeof (struct GNUNET_SCALARPRODUCT_service_request),
&do_send_message,
session->msg = (struct GNUNET_MessageHeader *) msg;
GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Transmitting service request.\n"));
- //transmit via mesh messaging
- session->service_transmit_handle = GNUNET_MESH_notify_transmit_ready (session->channel, GNUNET_YES,
+ //transmit via cadet messaging
+ session->service_transmit_handle = GNUNET_CADET_notify_transmit_ready (session->channel, GNUNET_YES,
GNUNET_TIME_UNIT_FOREVER_REL,
msg_length,
&do_send_message,
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_ ("Creating new channel for session with key %s.\n"),
GNUNET_h2s (&session->session_id));
- session->channel = GNUNET_MESH_channel_create (my_mesh, session,
+ session->channel = GNUNET_CADET_channel_create (my_cadet, session,
&session->peer,
GNUNET_APPLICATION_TYPE_SCALARPRODUCT,
- GNUNET_MESH_OPTION_RELIABLE);
+ GNUNET_CADET_OPTION_RELIABLE);
if (NULL == session->channel) {
session->response->client_notification_task =
GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
*/
static void *
cb_channel_incoming (void *cls,
- struct GNUNET_MESH_Channel *channel,
+ struct GNUNET_CADET_Channel *channel,
const struct GNUNET_PeerIdentity *initiator,
- uint32_t port, enum GNUNET_MESH_ChannelOption options)
+ uint32_t port, enum GNUNET_CADET_ChannelOption options)
{
struct ServiceSession * c = GNUNET_new (struct ServiceSession);
* Function called whenever a channel is destroyed. Should clean up
* any associated state.
*
- * It must NOT call GNUNET_MESH_channel_destroy on the channel.
+ * It must NOT call GNUNET_CADET_channel_destroy on the channel.
*
- * @param cls closure (set from GNUNET_MESH_connect)
+ * @param cls closure (set from GNUNET_CADET_connect)
* @param channel connection to the other end (henceforth invalid)
* @param channel_ctx place where local state associated
* with the channel is stored
*/
static void
cb_channel_destruction (void *cls,
- const struct GNUNET_MESH_Channel *channel,
+ const struct GNUNET_CADET_Channel *channel,
void *channel_ctx)
{
struct ServiceSession * session = channel_ctx;
/**
* 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 cls closure (set from #GNUNET_CADET_connect)
* @param channel connection to the other end
* @param channel_ctx place to store local state associated with the channel
* @param message the actual message
*/
static int
handle_alices_cyrptodata_message_multipart (void *cls,
- struct GNUNET_MESH_Channel * channel,
+ struct GNUNET_CADET_Channel * channel,
void **channel_ctx,
const struct GNUNET_MessageHeader * message)
{
session = (struct ServiceSession *) * channel_ctx;
//we are not bob
if ((NULL == session->e_a) || //or we did not expect this message yet
- (session->used_elements_count == session->transferred_element_count)) { //we not expecting multipart messages
+ (session->used_elements_count == session->transferred_element_count)) { //we are not expecting multipart messages
goto except;
}
// shorter than minimum?
return GNUNET_OK;
except:
+ session->channel = NULL;
// and notify our client-session that we could not complete the session
- GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session);
- if (session->response)
- // we just found the responder session in this queue
+ free_session_variables (session);
+ if (NULL != session->client){
+ //Alice
+ session->client_notification_task =
+ GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
+ session);
+ }
+ else {
+ //Bob
+ if (NULL != session->response)
session->response->client_notification_task =
GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
session->response);
- free_session_variables (session);
- GNUNET_free (session);
+ GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session);
+ GNUNET_free(session);
+ }
return GNUNET_SYSERR;
}
/**
* Handle a request from another service to calculate a scalarproduct with us.
*
- * @param cls closure (set from #GNUNET_MESH_connect)
+ * @param cls closure (set from #GNUNET_CADET_connect)
* @param channel connection to the other end
* @param channel_ctx place to store local state associated with the channel
* @param message the actual message
*/
static int
handle_alices_cyrptodata_message (void *cls,
- struct GNUNET_MESH_Channel * channel,
+ struct GNUNET_CADET_Channel * channel,
void **channel_ctx,
const struct GNUNET_MessageHeader * message)
{
return GNUNET_OK;
invalid_msg:
GNUNET_break_op (0);
- if ((NULL != session->next) || (NULL != session->prev) || (from_service_head == session))
- GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session);
+ session->channel = NULL;
// and notify our client-session that we could not complete the session
- if (session->response)
- // we just found the responder session in this queue
+ free_session_variables (session);
+ if (NULL != session->client){
+ //Alice
+ session->client_notification_task =
+ GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
+ session);
+ }
+ else {
+ //Bob
+ if (NULL != session->response)
session->response->client_notification_task =
GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
session->response);
- free_session_variables (session);
+ GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session);
+ GNUNET_free(session);
+ }
return GNUNET_SYSERR;
}
/**
* Handle a request from another service to calculate a scalarproduct with us.
*
- * @param cls closure (set from #GNUNET_MESH_connect)
+ * @param cls closure (set from #GNUNET_CADET_connect)
* @param channel connection to the other end
* @param channel_ctx place to store local state associated with the channel
* @param message the actual message
*/
static int
handle_alices_computation_request (void *cls,
- struct GNUNET_MESH_Channel * channel,
+ struct GNUNET_CADET_Channel * channel,
void **channel_ctx,
const struct GNUNET_MessageHeader * message)
{
memcpy (&session->session_id, &msg->session_id, sizeof (struct GNUNET_HashCode));
// public key
- memcpy (&session->remote_pubkey, &msg->public_key, sizeof (struct GNUNET_CRYPTO_PaillierPublicKey));
+ session->remote_pubkey = GNUNET_new (struct GNUNET_CRYPTO_PaillierPublicKey);
+ memcpy (session->remote_pubkey, &msg->public_key, sizeof (struct GNUNET_CRYPTO_PaillierPublicKey));
//check if service queue contains a matching request
client_session = find_matching_session (from_client_tail,
return GNUNET_OK;
invalid_msg:
GNUNET_break_op (0);
- if ((NULL != session->next) || (NULL != session->prev) || (from_service_head == session))
- GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session);
+ session->channel = NULL;
// and notify our client-session that we could not complete the session
- if (session->response)
- // we just found the responder session in this queue
+ free_session_variables (session);
+ if (NULL != session->client){
+ //Alice
+ session->client_notification_task =
+ GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
+ session);
+ }
+ else {
+ //Bob
+ if (NULL != session->response)
session->response->client_notification_task =
GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
session->response);
- free_session_variables (session);
+ GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session);
+ GNUNET_free(session);
+ }
return GNUNET_SYSERR;
}
/**
* 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 cls closure (set from #GNUNET_CADET_connect)
* @param channel connection to the other end
* @param channel_ctx place to store local state associated with the channel
* @param message the actual message
*/
static int
handle_bobs_cryptodata_multipart (void *cls,
- struct GNUNET_MESH_Channel * channel,
+ struct GNUNET_CADET_Channel * channel,
void **channel_ctx,
const struct GNUNET_MessageHeader * message)
{
session->product = compute_scalar_product (session); //never NULL
invalid_msg:
- GNUNET_break_op (NULL != session->product); //NULL if we never tried to compute it...
-
+ GNUNET_break_op (NULL != session->product);
+ session->channel = NULL;
// send message with product to client
- if (ALICE == session->role) {
- session->channel = NULL;
+ if (NULL != session->client){
+ //Alice
session->client_notification_task =
- GNUNET_SCHEDULER_add_now (&prepare_client_response,
- session);
+ GNUNET_SCHEDULER_add_now (&prepare_client_response,
+ session);
+ }
+ else {
+ //Bob
+ if (NULL != session->response)
+ session->response->client_notification_task =
+ GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
+ session->response);
+ GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session);
+ free_session_variables (session);
+ GNUNET_free(session);
}
// 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
/**
* Handle a response we got from another service we wanted to calculate a scalarproduct with.
*
- * @param cls closure (set from #GNUNET_MESH_connect)
+ * @param cls closure (set from #GNUNET_CADET_connect)
* @param channel connection to the other end
* @param channel_ctx place to store local state associated with the channel
* @param message the actual message
*/
static int
handle_bobs_cryptodata_message (void *cls,
- struct GNUNET_MESH_Channel * channel,
+ struct GNUNET_CADET_Channel * channel,
void **channel_ctx,
const struct GNUNET_MessageHeader * message)
{
invalid_msg:
GNUNET_break_op (NULL != session->product);
+ session->channel = NULL;
// send message with product to client
- if (ALICE == session->role) {
- session->channel = NULL;
+ if (NULL != session->client){
+ //Alice
session->client_notification_task =
- GNUNET_SCHEDULER_add_now (&prepare_client_response,
- session);
+ GNUNET_SCHEDULER_add_now (&prepare_client_response,
+ session);
+ }
+ else {
+ //Bob
+ if (NULL != session->response)
+ session->response->client_notification_task =
+ GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
+ session->response);
+ GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, session);
+ free_session_variables (session);
+ GNUNET_free(session);
}
// 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
// terminate all owned open channels.
for (session = from_client_head; NULL != session; session = session->next) {
if ((0/*//TODO: not finalized*/) && (NULL != session->channel)) {
- GNUNET_MESH_channel_destroy (session->channel);
+ GNUNET_CADET_channel_destroy (session->channel);
session->channel = NULL;
}
if (GNUNET_SCHEDULER_NO_TASK != session->client_notification_task) {
}
for (session = from_service_head; NULL != session; session = session->next)
if (NULL != session->channel) {
- GNUNET_MESH_channel_destroy (session->channel);
+ GNUNET_CADET_channel_destroy (session->channel);
session->channel = NULL;
}
- if (my_mesh) {
- GNUNET_MESH_disconnect (my_mesh);
- my_mesh = NULL;
+ if (my_cadet) {
+ GNUNET_CADET_disconnect (my_cadet);
+ my_cadet = NULL;
}
}
{&handle_client_message_multipart, NULL, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MUTLIPART, 0},
{NULL, NULL, 0, 0}
};
- static const struct GNUNET_MESH_MessageHandler mesh_handlers[] = {
+ static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
{ &handle_alices_computation_request, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA, 0},
{ &handle_alices_cyrptodata_message, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA, 0},
{ &handle_alices_cyrptodata_message_multipart, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA_MULTIPART, 0},
GNUNET_break (GNUNET_OK ==
GNUNET_CRYPTO_get_peer_identity (c,
&me));
- my_mesh = GNUNET_MESH_connect (c, NULL,
+ my_cadet = GNUNET_CADET_connect (c, NULL,
&cb_channel_incoming,
&cb_channel_destruction,
- mesh_handlers, ports);
- if (!my_mesh) {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Connect to MESH failed\n"));
+ cadet_handlers, ports);
+ if (!my_cadet) {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Connect to CADET failed\n"));
GNUNET_SCHEDULER_shutdown ();
return;
}
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Mesh initialized\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("CADET initialized\n"));
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
&shutdown_task,
NULL);