/*
This file is part of GNUnet.
- (C) 2013, 2014 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2013, 2014, 2017 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
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
*/
/**
* @file scalarproduct/gnunet-service-scalarproduct_alice.c
/**
* The client this request is related to.
*/
- struct GNUNET_SERVER_Client *client;
+ struct GNUNET_SERVICE_Client *client;
/**
* The message queue for the client.
if (GNUNET_YES == s->in_destroy)
return;
s->in_destroy = GNUNET_YES;
- if (NULL != s->client_mq)
- {
- GNUNET_MQ_destroy (s->client_mq);
- s->client_mq = NULL;
- }
- if (NULL != s->cadet_mq)
- {
- GNUNET_MQ_destroy (s->cadet_mq);
- s->cadet_mq = NULL;
- }
if (NULL != s->client)
{
- GNUNET_SERVER_client_set_user_context (s->client,
- NULL);
- GNUNET_SERVER_client_disconnect (s->client);
+ struct GNUNET_SERVICE_Client *c = s->client;
+
s->client = NULL;
+ GNUNET_SERVICE_client_drop (c);
}
if (NULL != s->channel)
{
struct ClientResponseMessage *msg;
struct GNUNET_MQ_Envelope *e;
+ if (NULL == session->client_mq)
+ return; /* no client left to be notified */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sending session-end notification with status %d to client for session %s\n",
session->status,
msg->product_length = htonl (product_length);
if (NULL != product_exported)
{
- memcpy (&msg[1],
+ GNUNET_memcpy (&msg[1],
product_exported,
product_length);
GNUNET_free (product_exported);
*
* It must NOT call #GNUNET_CADET_channel_destroy() on the channel.
*
- * @param cls closure (set from #GNUNET_CADET_connect())
+ * @param cls our `struct AliceServiceSession`
* @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_CADET_Channel *channel,
- void *channel_ctx)
+ const struct GNUNET_CADET_Channel *channel)
{
- struct AliceServiceSession *s = channel_ctx;
+ struct AliceServiceSession *s = cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Peer disconnected, terminating session %s with peer %s\n",
GNUNET_h2s (&s->session_id),
GNUNET_i2s (&s->peer));
- if (NULL != s->cadet_mq)
- {
- GNUNET_MQ_destroy (s->cadet_mq);
- s->cadet_mq = NULL;
- }
- s->channel = NULL;
if (GNUNET_SCALARPRODUCT_STATUS_ACTIVE == s->status)
{
/* We didn't get an answer yet, fail with error */
s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
prepare_client_end_notification (s);
}
+ s->channel = NULL;
}
/**
- * Handle a multipart chunk of a response we got from another service
+ * Check a multipart chunk of a response we got from another service
* we wanted to calculate a scalarproduct with.
*
- * @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 @a channel
- * @param message the actual message
+ * @param cls the `struct AliceServiceSession`
+ * @param msg the actual message
* @return #GNUNET_OK to keep the connection open,
* #GNUNET_SYSERR to close it (signal serious error)
*/
static int
-handle_bobs_cryptodata_multipart (void *cls,
- struct GNUNET_CADET_Channel *channel,
- void **channel_ctx,
- const struct GNUNET_MessageHeader *message)
+check_bobs_cryptodata_multipart (void *cls,
+ const struct BobCryptodataMultipartMessage *msg)
{
- struct AliceServiceSession *s = *channel_ctx;
- const struct BobCryptodataMultipartMessage *msg;
- const struct GNUNET_CRYPTO_PaillierCiphertext *payload;
- size_t i;
+ struct AliceServiceSession *s = cls;
uint32_t contained;
size_t msg_size;
size_t required_size;
- if (NULL == s)
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- msg_size = ntohs (message->size);
- if (sizeof (struct BobCryptodataMultipartMessage) > msg_size)
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- msg = (const struct BobCryptodataMultipartMessage *) message;
+ msg_size = ntohs (msg->header.size);
contained = ntohl (msg->contained_element_count);
required_size = sizeof (struct BobCryptodataMultipartMessage)
+ 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext);
GNUNET_break (0);
return GNUNET_SYSERR;
}
+ return GNUNET_OK;
+}
+/**
+ * Handle a multipart chunk of a response we got from another service
+ * we wanted to calculate a scalarproduct with.
+ *
+ * @param cls the `struct AliceServiceSession`
+ * @param msg the actual message
+ */
+static void
+handle_bobs_cryptodata_multipart (void *cls,
+ const struct BobCryptodataMultipartMessage *msg)
+{
+ struct AliceServiceSession *s = cls;
+ const struct GNUNET_CRYPTO_PaillierCiphertext *payload;
+ size_t i;
+ uint32_t contained;
+
+ contained = ntohl (msg->contained_element_count);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received %u additional crypto values from Bob\n",
(unsigned int) contained);
/* Convert each k[][perm] to its MPI_value */
for (i = 0; i < contained; i++)
{
- memcpy (&s->r[s->cadet_received_element_count + i],
- &payload[2 * i],
- sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
- memcpy (&s->r_prime[s->cadet_received_element_count + i],
- &payload[2 * i],
- sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
+ GNUNET_memcpy (&s->r[s->cadet_received_element_count + i],
+ &payload[2 * i],
+ sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
+ GNUNET_memcpy (&s->r_prime[s->cadet_received_element_count + i],
+ &payload[2 * i],
+ sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
}
s->cadet_received_element_count += contained;
GNUNET_CADET_receive_done (s->channel);
if (s->cadet_received_element_count != s->used_element_count)
- return GNUNET_OK;
+ return; /* more to come */
s->product = compute_scalar_product (s);
transmit_client_response (s);
- return GNUNET_OK;
}
/**
- * Handle a response we got from another service we wanted to
+ * Check a response we got from another service we wanted to
* calculate a scalarproduct with.
*
- * @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 cls our `struct AliceServiceSession`
* @param message the actual message
* @return #GNUNET_OK to keep the connection open,
* #GNUNET_SYSERR to close it (we are done)
*/
static int
-handle_bobs_cryptodata_message (void *cls,
- struct GNUNET_CADET_Channel *channel,
- void **channel_ctx,
- const struct GNUNET_MessageHeader *message)
+check_bobs_cryptodata_message (void *cls,
+ const struct BobCryptodataMessage *msg)
{
- struct AliceServiceSession *s = *channel_ctx;
- const struct BobCryptodataMessage *msg;
- const struct GNUNET_CRYPTO_PaillierCiphertext *payload;
- uint32_t i;
+ struct AliceServiceSession *s = cls;
uint32_t contained;
uint16_t msg_size;
size_t required_size;
- if (NULL == s)
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- msg_size = ntohs (message->size);
- if (sizeof (struct BobCryptodataMessage) > msg_size)
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- msg = (const struct BobCryptodataMessage *) message;
+ msg_size = ntohs (msg->header.size);
contained = ntohl (msg->contained_element_count);
required_size = sizeof (struct BobCryptodataMessage)
+ 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
+ return GNUNET_OK;
+}
+
+
+/**
+ * Handle a response we got from another service we wanted to
+ * calculate a scalarproduct with.
+ *
+ * @param cls our `struct AliceServiceSession`
+ * @param msg the actual message
+ */
+static void
+handle_bobs_cryptodata_message (void *cls,
+ const struct BobCryptodataMessage *msg)
+{
+ struct AliceServiceSession *s = cls;
+ const struct GNUNET_CRYPTO_PaillierCiphertext *payload;
+ uint32_t i;
+ uint32_t contained;
+
+ contained = ntohl (msg->contained_element_count);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received %u crypto values from Bob\n",
(unsigned int) contained);
-
payload = (const struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1];
- memcpy (&s->s,
- &payload[0],
- sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
- memcpy (&s->s_prime,
- &payload[1],
- sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
+ GNUNET_memcpy (&s->s,
+ &payload[0],
+ sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
+ GNUNET_memcpy (&s->s_prime,
+ &payload[1],
+ sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
payload = &payload[2];
- s->r = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * s->used_element_count);
- s->r_prime = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * s->used_element_count);
+ s->r = GNUNET_new_array (s->used_element_count,
+ struct GNUNET_CRYPTO_PaillierCiphertext);
+ s->r_prime = GNUNET_new_array (s->used_element_count,
+ struct GNUNET_CRYPTO_PaillierCiphertext);
for (i = 0; i < contained; i++)
{
- memcpy (&s->r[i],
- &payload[2 * i],
- sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
- memcpy (&s->r_prime[i],
- &payload[2 * i + 1],
- sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
+ GNUNET_memcpy (&s->r[i],
+ &payload[2 * i],
+ sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
+ GNUNET_memcpy (&s->r_prime[i],
+ &payload[2 * i + 1],
+ sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
}
s->cadet_received_element_count = contained;
GNUNET_CADET_receive_done (s->channel);
if (s->cadet_received_element_count != s->used_element_count)
{
/* More to come */
- return GNUNET_OK;
+ return;
}
-
s->product = compute_scalar_product (s);
transmit_client_response (s);
- return GNUNET_OK;
}
if (todo_count > ELEMENT_CAPACITY)
todo_count = ELEMENT_CAPACITY;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending %u crypto values to Bob\n",
- (unsigned int) todo_count);
+ "Sending %u/%u crypto values to Bob\n",
+ (unsigned int) todo_count,
+ (unsigned int) s->used_element_count);
e = GNUNET_MQ_msg_extra (msg,
todo_count * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext),
*
* @param cls closure with the `struct AliceServiceSession`
* @param element a result element, only valid if status is #GNUNET_SET_STATUS_OK
+ * @param current_size current set size
* @param status what has happened with the set intersection?
*/
static void
cb_intersection_element_removed (void *cls,
const struct GNUNET_SET_Element *element,
+ uint64_t current_size,
enum GNUNET_SET_Status status)
{
struct AliceServiceSession *s = cls;
s->intersection_op
= GNUNET_SET_accept (request,
GNUNET_SET_RESULT_REMOVED,
+ (struct GNUNET_SET_Option[]) {{ 0 }},
&cb_intersection_element_removed,
s);
if (NULL == s->intersection_op)
static void
client_request_complete_alice (struct AliceServiceSession *s)
{
+ struct GNUNET_MQ_MessageHandler cadet_handlers[] = {
+ GNUNET_MQ_hd_var_size (bobs_cryptodata_message,
+ GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA,
+ struct BobCryptodataMessage,
+ s),
+ GNUNET_MQ_hd_var_size (bobs_cryptodata_multipart,
+ GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART,
+ struct BobCryptodataMultipartMessage,
+ s),
+ GNUNET_MQ_handler_end ()
+ };
struct ServiceRequestMessage *msg;
struct GNUNET_MQ_Envelope *e;
"Creating new channel for session with key %s.\n",
GNUNET_h2s (&s->session_id));
s->channel
- = GNUNET_CADET_channel_create (my_cadet,
+ = GNUNET_CADET_channel_creatE (my_cadet,
s,
&s->peer,
- GNUNET_APPLICATION_TYPE_SCALARPRODUCT,
- GNUNET_CADET_OPTION_RELIABLE);
+ &s->session_id,
+ GNUNET_CADET_OPTION_RELIABLE,
+ NULL,
+ &cb_channel_destruction,
+ cadet_handlers);
if (NULL == s->channel)
{
s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
prepare_client_end_notification (s);
return;
}
- s->cadet_mq = GNUNET_CADET_mq_create (s->channel);
+ s->cadet_mq = GNUNET_CADET_get_mq (s->channel);
s->intersection_listen
= GNUNET_SET_listen (cfg,
GNUNET_SET_OPERATION_INTERSECTION,
/**
- * We're receiving additional set data. Add it to our
- * set and if we are done, initiate the transaction.
+ * We're receiving additional set data. Check if
+ * @a msg is well-formed.
*
- * @param cls closure
- * @param client identification of the client
- * @param message the actual message
+ * @param cls client identification of the client
+ * @param msg the actual message
+ * @return #GNUNET_OK if @a msg is well-formed
*/
-static void
-GSS_handle_alice_client_message_multipart (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+static int
+check_alice_client_message_multipart (void *cls,
+ const struct ComputationBobCryptodataMultipartMessage *msg)
{
- const struct ComputationBobCryptodataMultipartMessage * msg;
- struct AliceServiceSession *s;
+ struct AliceServiceSession *s = cls;
uint32_t contained_count;
- const struct GNUNET_SCALARPRODUCT_Element *elements;
- uint32_t i;
uint16_t msize;
- struct GNUNET_SET_Element set_elem;
- struct GNUNET_SCALARPRODUCT_Element *elem;
- s = GNUNET_SERVER_client_get_user_context (client,
- struct AliceServiceSession);
- if (NULL == s)
- {
- /* session needs to already exist */
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client,
- GNUNET_SYSERR);
- return;
- }
- msize = ntohs (message->size);
- if (msize < sizeof (struct ComputationBobCryptodataMultipartMessage))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client,
- GNUNET_SYSERR);
- return;
- }
- msg = (const struct ComputationBobCryptodataMultipartMessage *) message;
+ msize = ntohs (msg->header.size);
contained_count = ntohl (msg->element_count_contained);
-
if ( (msize != (sizeof (struct ComputationBobCryptodataMultipartMessage) +
contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) ||
(0 == contained_count) ||
(s->total < s->client_received_element_count + contained_count) )
{
GNUNET_break_op (0);
- GNUNET_SERVER_receive_done (client,
- GNUNET_SYSERR);
- return;
+ return GNUNET_SYSERR;
}
+ return GNUNET_OK;
+}
+
+
+/**
+ * We're receiving additional set data. Add it to our
+ * set and if we are done, initiate the transaction.
+ *
+ * @param cls client identification of the client
+ * @param msg the actual message
+ */
+static void
+handle_alice_client_message_multipart (void *cls,
+ const struct ComputationBobCryptodataMultipartMessage *msg)
+{
+ struct AliceServiceSession *s = cls;
+ uint32_t contained_count;
+ const struct GNUNET_SCALARPRODUCT_Element *elements;
+ struct GNUNET_SET_Element set_elem;
+ struct GNUNET_SCALARPRODUCT_Element *elem;
+
+ contained_count = ntohl (msg->element_count_contained);
s->client_received_element_count += contained_count;
elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1];
- for (i = 0; i < contained_count; i++)
+ for (uint32_t i = 0; i < contained_count; i++)
{
- if (0 == GNUNET_ntohll (elements[i].value))
- continue;
elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element);
- memcpy (elem,
- &elements[i],
- sizeof (struct GNUNET_SCALARPRODUCT_Element));
+ GNUNET_memcpy (elem,
+ &elements[i],
+ sizeof (struct GNUNET_SCALARPRODUCT_Element));
if (GNUNET_SYSERR ==
GNUNET_CONTAINER_multihashmap_put (s->intersected_elements,
&elem->key,
NULL, NULL);
s->used_element_count++;
}
- GNUNET_SERVER_receive_done (client,
- GNUNET_OK);
+ GNUNET_SERVICE_client_continue (s->client);
if (s->total != s->client_received_element_count)
{
/* more to come */
/**
* Handler for Alice's client request message.
- * We are doing request-initiation to compute a scalar product with a peer.
+ * Check that @a msg is well-formed.
*
- * @param cls closure
- * @param client identification of the client
- * @param message the actual message
+ * @param cls identification of the client
+ * @param msg the actual message
+ * @return #GNUNET_OK if @a msg is well-formed
*/
-static void
-GSS_handle_alice_client_message (void *cls,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *message)
+static int
+check_alice_client_message (void *cls,
+ const struct AliceComputationMessage *msg)
{
- const struct AliceComputationMessage *msg;
- struct AliceServiceSession *s;
- uint32_t contained_count;
- uint32_t total_count;
- const struct GNUNET_SCALARPRODUCT_Element *elements;
- uint32_t i;
+ struct AliceServiceSession *s = cls;
uint16_t msize;
- struct GNUNET_SET_Element set_elem;
- struct GNUNET_SCALARPRODUCT_Element *elem;
+ uint32_t total_count;
+ uint32_t contained_count;
- s = GNUNET_SERVER_client_get_user_context (client,
- struct AliceServiceSession);
- if (NULL != s)
+ if (NULL != s->intersected_elements)
{
/* only one concurrent session per client connection allowed,
simplifies logic a lot... */
GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
- }
- msize = ntohs (message->size);
- if (msize < sizeof (struct AliceComputationMessage))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
+ return GNUNET_SYSERR;
}
- msg = (const struct AliceComputationMessage *) message;
+ msize = ntohs (msg->header.size);
total_count = ntohl (msg->element_count_total);
contained_count = ntohl (msg->element_count_contained);
if ( (0 == total_count) ||
contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) )
{
GNUNET_break_op (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
- return;
+ return GNUNET_SYSERR;
}
+ return GNUNET_OK;
+}
- s = GNUNET_new (struct AliceServiceSession);
+
+/**
+ * Handler for Alice's client request message.
+ * We are doing request-initiation to compute a scalar product with a peer.
+ *
+ * @param cls identification of the client
+ * @param msg the actual message
+ */
+static void
+handle_alice_client_message (void *cls,
+ const struct AliceComputationMessage *msg)
+{
+ struct AliceServiceSession *s = cls;
+ uint32_t contained_count;
+ uint32_t total_count;
+ const struct GNUNET_SCALARPRODUCT_Element *elements;
+ struct GNUNET_SET_Element set_elem;
+ struct GNUNET_SCALARPRODUCT_Element *elem;
+
+ total_count = ntohl (msg->element_count_total);
+ contained_count = ntohl (msg->element_count_contained);
s->peer = msg->peer;
s->status = GNUNET_SCALARPRODUCT_STATUS_ACTIVE;
- s->client = client;
- s->client_mq = GNUNET_MQ_queue_for_server_client (client);
s->total = total_count;
s->client_received_element_count = contained_count;
s->session_id = msg->session_key;
GNUNET_YES);
s->intersection_set = GNUNET_SET_create (cfg,
GNUNET_SET_OPERATION_INTERSECTION);
- for (i = 0; i < contained_count; i++)
+
+ for (uint32_t i = 0; i < contained_count; i++)
{
if (0 == GNUNET_ntohll (elements[i].value))
continue;
elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element);
- memcpy (elem,
+ GNUNET_memcpy (elem,
&elements[i],
sizeof (struct GNUNET_SCALARPRODUCT_Element));
if (GNUNET_SYSERR ==
NULL, NULL);
s->used_element_count++;
}
- GNUNET_SERVER_client_set_user_context (client,
- s);
- GNUNET_SERVER_receive_done (client,
- GNUNET_OK);
+ GNUNET_SERVICE_client_continue (s->client);
if (s->total != s->client_received_element_count)
{
/* wait for multipart msg */
* Task run during shutdown.
*
* @param cls unused
- * @param tc unused
*/
static void
-shutdown_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Shutting down, initiating cleanup.\n");
}
+/**
+ * A client connected.
+ *
+ * Setup the associated data structure.
+ *
+ * @param cls closure, NULL
+ * @param client identification of the client
+ * @param mq message queue to communicate with @a client
+ * @return our `struct AliceServiceSession`
+ */
+static void *
+client_connect_cb (void *cls,
+ struct GNUNET_SERVICE_Client *client,
+ struct GNUNET_MQ_Handle *mq)
+{
+ struct AliceServiceSession *s;
+
+ s = GNUNET_new (struct AliceServiceSession);
+ s->client = client;
+ s->client_mq = mq;
+ return s;
+}
+
+
/**
* A client disconnected.
*
*
* @param cls closure, NULL
* @param client identification of the client
+ * @param app_cls our `struct AliceServiceSession`
*/
static void
-handle_client_disconnect (void *cls,
- struct GNUNET_SERVER_Client *client)
+client_disconnect_cb (void *cls,
+ struct GNUNET_SERVICE_Client *client,
+ void *app_cls)
{
- struct AliceServiceSession *s;
+ struct AliceServiceSession *s = app_cls;
- if (NULL == client)
- return;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Client %p disconnected from us.\n",
client);
- s = GNUNET_SERVER_client_get_user_context (client,
- struct AliceServiceSession);
- if (NULL == s)
- return;
s->client = NULL;
- GNUNET_SERVER_client_set_user_context (client,
- NULL);
+ s->client_mq = NULL;
destroy_service_session (s);
}
* Initialization of the program and message handlers
*
* @param cls closure
- * @param server the initialized server
* @param c configuration to use
+ * @param service the initialized service
*/
static void
run (void *cls,
- struct GNUNET_SERVER_Handle *server,
- const struct GNUNET_CONFIGURATION_Handle *c)
+ const struct GNUNET_CONFIGURATION_Handle *c,
+ struct GNUNET_SERVICE_Handle *service)
{
- static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
- { &handle_bobs_cryptodata_message,
- GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA,
- 0},
- { &handle_bobs_cryptodata_multipart,
- GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART,
- 0},
- { NULL, 0, 0}
- };
- static const struct GNUNET_SERVER_MessageHandler server_handlers[] = {
- { &GSS_handle_alice_client_message, NULL,
- GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE,
- 0},
- { &GSS_handle_alice_client_message_multipart, NULL,
- GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MUTLIPART_ALICE,
- 0},
- { NULL, NULL, 0, 0}
- };
-
cfg = c;
/*
offset has to be sufficiently small to allow computation of:
my_offset = gcry_mpi_new (GNUNET_CRYPTO_PAILLIER_BITS / 3);
gcry_mpi_set_bit (my_offset,
GNUNET_CRYPTO_PAILLIER_BITS / 3);
-
GNUNET_CRYPTO_paillier_create (&my_pubkey,
&my_privkey);
- GNUNET_SERVER_add_handlers (server,
- server_handlers);
- GNUNET_SERVER_disconnect_notify (server,
- &handle_client_disconnect,
- NULL);
- my_cadet = GNUNET_CADET_connect (cfg, NULL,
- NULL /* no incoming supported */,
- &cb_channel_destruction,
- cadet_handlers,
- NULL);
+ my_cadet = GNUNET_CADET_connecT (cfg);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
if (NULL == my_cadet)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
GNUNET_SCHEDULER_shutdown ();
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
- NULL);
-
}
/**
- * The main function for the scalarproduct service.
- *
- * @param argc number of arguments from the command line
- * @param argv command line arguments
- * @return 0 ok, 1 on error
+ * Define "main" method using service macro.
*/
-int
-main (int argc,
- char *const *argv)
-{
- return (GNUNET_OK ==
- GNUNET_SERVICE_run (argc, argv,
- "scalarproduct-alice",
- GNUNET_SERVICE_OPTION_NONE,
- &run, NULL)) ? 0 : 1;
-}
+GNUNET_SERVICE_MAIN
+("scalarproduct-alice",
+ GNUNET_SERVICE_OPTION_NONE,
+ &run,
+ &client_connect_cb,
+ &client_disconnect_cb,
+ NULL,
+ GNUNET_MQ_hd_var_size (alice_client_message,
+ GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE,
+ struct AliceComputationMessage,
+ NULL),
+ GNUNET_MQ_hd_var_size (alice_client_message_multipart,
+ GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE,
+ struct ComputationBobCryptodataMultipartMessage,
+ NULL),
+ GNUNET_MQ_handler_end ());
+
/* end of gnunet-service-scalarproduct_alice.c */