scalarproduct service implementation More...
#include "platform.h"
#include <limits.h>
#include <gcrypt.h>
#include "gnunet_util_lib.h"
#include "gnunet_cadet_service.h"
#include "gnunet_protocols.h"
#include "gnunet_scalarproduct_service.h"
#include "gnunet_seti_service.h"
#include "scalarproduct.h"
#include "gnunet-service-scalarproduct-ecc.h"
#include "gnunet_constants.h"
Go to the source code of this file.
Data Structures | |
struct | MpiElement |
An encrypted element key-value pair. More... | |
struct | AliceServiceSession |
A scalarproduct session which tracks a request form the client to our final response. More... | |
Macros | |
#define | LOG(kind, ...) GNUNET_log_from (kind, "scalarproduct-alice", __VA_ARGS__) |
#define | MAX_RESULT (1024 * 1024) |
Maximum allowed result value for the scalarproduct computation. More... | |
#define | MAX_RAM (1024) |
How many values should DLOG store in memory (determines baseline RAM consumption, roughly 100 bytes times the value given here). More... | |
#define | ELEMENT_CAPACITY |
Maximum number of elements we can put into a single cryptodata message. More... | |
Functions | |
static int | free_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value) |
Iterator called to free elements. More... | |
static void | destroy_service_session (struct AliceServiceSession *s) |
Destroy session state, we are done with it. More... | |
static void | prepare_client_end_notification (struct AliceServiceSession *session) |
Notify the client that the session has failed. More... | |
static void | transmit_client_response (struct AliceServiceSession *s) |
Prepare the final (positive) response we will send to Alice's client. More... | |
static void | cb_channel_destruction (void *cls, const struct GNUNET_CADET_Channel *channel) |
Function called whenever a channel is destroyed. More... | |
static void | handle_bobs_cryptodata_message (void *cls, const struct EccBobCryptodataMessage *msg) |
Handle a response we got from another service we wanted to calculate a scalarproduct with. More... | |
static int | copy_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value) |
Iterator to copy over messages from the hash map into an array for sorting. More... | |
static int | element_cmp (const void *a, const void *b) |
Compare two struct MpiValue s by key for sorting. More... | |
static void | send_alices_cryptodata_message (struct AliceServiceSession *s) |
Send the cryptographic data from Alice to Bob. More... | |
static void | cb_intersection_element_removed (void *cls, const struct GNUNET_SETI_Element *element, uint64_t current_size, enum GNUNET_SETI_Status status) |
Callback for set operation results. More... | |
static void | cb_intersection_request_alice (void *cls, const struct GNUNET_PeerIdentity *other_peer, const struct GNUNET_MessageHeader *context_msg, struct GNUNET_SETI_Request *request) |
Called when another peer wants to do a set operation with the local peer. More... | |
static void | client_request_complete_alice (struct AliceServiceSession *s) |
Our client has finished sending us its multipart message. More... | |
static int | check_alice_client_message_multipart (void *cls, const struct ComputationBobCryptodataMultipartMessage *msg) |
We're receiving additional set data. More... | |
static void | handle_alice_client_message_multipart (void *cls, const struct ComputationBobCryptodataMultipartMessage *msg) |
We're receiving additional set data. More... | |
static int | check_alice_client_message (void *cls, const struct AliceComputationMessage *msg) |
Handler for Alice's client request message. More... | |
static void | handle_alice_client_message (void *cls, const struct AliceComputationMessage *msg) |
Handler for Alice's client request message. More... | |
static void | shutdown_task (void *cls) |
Task run during shutdown. More... | |
static void * | client_connect_cb (void *cls, struct GNUNET_SERVICE_Client *client, struct GNUNET_MQ_Handle *mq) |
A client connected. More... | |
static void | client_disconnect_cb (void *cls, struct GNUNET_SERVICE_Client *client, void *app_cls) |
A client disconnected. More... | |
static void | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *service) |
Initialization of the program and message handlers. More... | |
GNUNET_SERVICE_MAIN (GNUNET_OS_project_data_gnunet(), "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()) | |
Define "main" method using service macro. More... | |
Variables | |
static const struct GNUNET_CONFIGURATION_Handle * | cfg |
GNUnet configuration handle. More... | |
static struct GNUNET_CRYPTO_EccDlogContext * | edc |
Context for DLOG operations on a curve. More... | |
static struct GNUNET_CRYPTO_EccScalar | my_privkey |
Alice's private key ('a'). More... | |
static struct GNUNET_CRYPTO_EccScalar | my_privkey_inv |
Inverse of Alice's private key ('a_inv'). More... | |
static struct GNUNET_CADET_Handle * | my_cadet |
Handle to the CADET service. More... | |
scalarproduct service implementation
Definition in file gnunet-service-scalarproduct-ecc_alice.c.
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log_from (kind, "scalarproduct-alice", __VA_ARGS__) |
Definition at line 38 of file gnunet-service-scalarproduct-ecc_alice.c.
#define MAX_RESULT (1024 * 1024) |
Maximum allowed result value for the scalarproduct computation.
DLOG will fail if the result is bigger. At 1 million, the precomputation takes about 2s on a fast machine.
Definition at line 46 of file gnunet-service-scalarproduct-ecc_alice.c.
#define MAX_RAM (1024) |
How many values should DLOG store in memory (determines baseline RAM consumption, roughly 100 bytes times the value given here).
Should be about SQRT (MAX_RESULT), larger values will make the online computation faster.
Definition at line 54 of file gnunet-service-scalarproduct-ecc_alice.c.
#define ELEMENT_CAPACITY |
Maximum number of elements we can put into a single cryptodata message.
Definition at line 527 of file gnunet-service-scalarproduct-ecc_alice.c.
|
static |
Iterator called to free elements.
cls | the struct AliceServiceSession * (unused) |
key | the key (unused) |
value | value to free |
Definition at line 214 of file gnunet-service-scalarproduct-ecc_alice.c.
References GNUNET_free, GNUNET_OK, and value.
Referenced by destroy_service_session().
|
static |
Destroy session state, we are done with it.
s | the session to free elements from |
Definition at line 231 of file gnunet-service-scalarproduct-ecc_alice.c.
References AliceServiceSession::channel, AliceServiceSession::client, free_element_cb(), GNUNET_CADET_channel_destroy(), GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_SERVICE_client_drop(), GNUNET_SETI_destroy(), GNUNET_SETI_listen_cancel(), GNUNET_SETI_operation_cancel(), GNUNET_YES, AliceServiceSession::in_destroy, AliceServiceSession::intersected_elements, AliceServiceSession::intersection_listen, AliceServiceSession::intersection_op, AliceServiceSession::intersection_set, LOG, and AliceServiceSession::sorted_elements.
Referenced by client_disconnect_cb(), and handle_bobs_cryptodata_message().
|
static |
Notify the client that the session has failed.
A message gets sent to Alice's client if we encountered any error.
session | the associated client session to fail or succeed |
Definition at line 289 of file gnunet-service-scalarproduct-ecc_alice.c.
References AliceServiceSession::client_mq, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT, GNUNET_MQ_msg, GNUNET_MQ_send(), msg, AliceServiceSession::session_id, and AliceServiceSession::status.
Referenced by cb_channel_destruction(), cb_intersection_element_removed(), cb_intersection_request_alice(), client_request_complete_alice(), and transmit_client_response().
|
static |
Prepare the final (positive) response we will send to Alice's client.
s | the session associated with our client. |
Definition at line 317 of file gnunet-service-scalarproduct-ecc_alice.c.
References AliceServiceSession::client_mq, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_h2s(), GNUNET_log, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_SCALARPRODUCT_STATUS_SUCCESS, INT_MAX, LOG_GCRY, msg, prepare_client_end_notification(), AliceServiceSession::product, AliceServiceSession::session_id, and value.
Referenced by handle_bobs_cryptodata_message().
|
static |
Function called whenever a channel is destroyed.
Should clean up any associated state.
It must NOT call GNUNET_CADET_channel_destroy() on the channel.
cls | the struct AliceServiceSession |
channel | connection to the other end (henceforth invalid) |
Definition at line 395 of file gnunet-service-scalarproduct-ecc_alice.c.
References GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_SCALARPRODUCT_STATUS_ACTIVE, GNUNET_SCALARPRODUCT_STATUS_FAILURE, prepare_client_end_notification(), and AliceServiceSession::s.
Referenced by client_request_complete_alice().
|
static |
Handle a response we got from another service we wanted to calculate a scalarproduct with.
cls | the struct AliceServiceSession * |
msg | the actual message |
Definition at line 422 of file gnunet-service-scalarproduct-ecc_alice.c.
References destroy_service_session(), edc, GNUNET_assert, GNUNET_break_op, GNUNET_CADET_receive_done(), GNUNET_CRYPTO_ecc_add(), GNUNET_CRYPTO_ecc_dlog(), GNUNET_CRYPTO_ecc_pmul_mpi(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, INT_MAX, msg, my_privkey_inv, AliceServiceSession::product, AliceServiceSession::s, and transmit_client_response().
|
static |
Iterator to copy over messages from the hash map into an array for sorting.
cls | the struct AliceServiceSession * |
key | the key (unused) |
value | the struct GNUNET_SCALARPRODUCT_Element * |
Definition at line 489 of file gnunet-service-scalarproduct-ecc_alice.c.
References GNUNET_ntohll(), GNUNET_OK, MpiElement::key, GNUNET_SCALARPRODUCT_Element::key, AliceServiceSession::s, AliceServiceSession::sorted_elements, AliceServiceSession::used_element_count, value, MpiElement::value, and GNUNET_SCALARPRODUCT_Element::value.
Referenced by send_alices_cryptodata_message().
|
static |
Compare two struct MpiValue
s by key for sorting.
a | pointer to first struct MpiValue * |
b | pointer to first struct MpiValue * |
Definition at line 512 of file gnunet-service-scalarproduct-ecc_alice.c.
References GNUNET_CRYPTO_hash_cmp(), and MpiElement::key.
Referenced by send_alices_cryptodata_message().
|
static |
Send the cryptographic data from Alice to Bob.
Does nothing if we already transferred all elements.
s | the associated service session |
Definition at line 540 of file gnunet-service-scalarproduct-ecc_alice.c.
References AliceServiceSession::cadet_mq, copy_element_cb(), ELEMENT_CAPACITY, element_cmp(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_CONTAINER_multihashmap_size(), GNUNET_CRYPTO_ecc_dexp_mpi(), GNUNET_CRYPTO_ecc_random_mod_n(), GNUNET_CRYPTO_ecc_scalar_from_int(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_ALICE_CRYPTODATA, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_new_array, GNUNET_OK, AliceServiceSession::intersected_elements, LOG, msg, my_privkey, payload, AliceServiceSession::sorted_elements, AliceServiceSession::used_element_count, GNUNET_CRYPTO_EccScalar::v, and MpiElement::value.
Referenced by cb_intersection_element_removed().
|
static |
Callback for set operation results.
Called for each element that should be removed from the result set, and then once to indicate that the set intersection operation is done.
cls | closure with the struct AliceServiceSession |
element | a result element, only valid if status is #GNUNET_SETI_STATUS_OK |
current_size | current set size |
status | what has happened with the set intersection? |
Definition at line 644 of file gnunet-service-scalarproduct-ecc_alice.c.
References GNUNET_SETI_Element::data, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_multihashmap_get(), GNUNET_CONTAINER_multihashmap_remove(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_h2s(), GNUNET_ntohll(), GNUNET_SCALARPRODUCT_STATUS_FAILURE, GNUNET_SETI_destroy(), GNUNET_SETI_listen_cancel(), GNUNET_SETI_STATUS_DEL_LOCAL, GNUNET_SETI_STATUS_DONE, GNUNET_SETI_STATUS_FAILURE, GNUNET_YES, AliceServiceSession::intersected_elements, AliceServiceSession::intersection_listen, AliceServiceSession::intersection_op, AliceServiceSession::intersection_set, GNUNET_SCALARPRODUCT_Element::key, LOG, prepare_client_end_notification(), AliceServiceSession::s, send_alices_cryptodata_message(), status, AliceServiceSession::status, and GNUNET_SCALARPRODUCT_Element::value.
Referenced by cb_intersection_request_alice().
|
static |
Called when another peer wants to do a set operation with the local peer.
If a listen error occurs, the request is NULL.
cls | closure with the struct AliceServiceSession * |
other_peer | the other peer |
context_msg | message with application specific information from the other peer |
request | request from the other peer (never NULL), use GNUNET_SETI_accept() to accept it, otherwise the request will be refused Note that we can't just return value from the listen callback, as it is also necessary to specify the set we want to do the operation with, which sometimes can be derived from the context message. It's necessary to specify the timeout. |
Definition at line 720 of file gnunet-service-scalarproduct-ecc_alice.c.
References cb_intersection_element_removed(), GNUNET_break, GNUNET_break_op, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_memcmp, GNUNET_OK, GNUNET_SCALARPRODUCT_STATUS_FAILURE, GNUNET_SETI_accept(), GNUNET_SETI_commit(), prepare_client_end_notification(), request, and AliceServiceSession::s.
Referenced by client_request_complete_alice().
|
static |
Our client has finished sending us its multipart message.
s | the service session context |
Definition at line 766 of file gnunet-service-scalarproduct-ecc_alice.c.
References AliceServiceSession::cadet_mq, cb_channel_destruction(), cb_intersection_request_alice(), cfg, AliceServiceSession::channel, GNUNET_CADET_channel_create(), GNUNET_CADET_channel_destroy(), GNUNET_CADET_get_mq(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_BOB_CRYPTODATA, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_SESSION_INITIALIZATION, GNUNET_MQ_env_set_options(), GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_msg, GNUNET_MQ_PRIO_CRITICAL_CONTROL, GNUNET_MQ_send(), GNUNET_SCALARPRODUCT_STATUS_FAILURE, GNUNET_SETI_listen(), AliceServiceSession::intersection_listen, msg, my_cadet, AliceServiceSession::peer, prepare_client_end_notification(), AliceServiceSession::session_id, and AliceServiceSession::status.
Referenced by handle_alice_client_message(), and handle_alice_client_message_multipart().
|
static |
We're receiving additional set data.
Check if msg is well-formed.
cls | client identification of the client |
msg | the actual message |
Definition at line 830 of file gnunet-service-scalarproduct-ecc_alice.c.
References GNUNET_break_op, GNUNET_OK, GNUNET_SYSERR, msg, AliceServiceSession::s, and GNUNET_MessageHeader::size.
|
static |
We're receiving additional set data.
Add it to our set and if we are done, initiate the transaction.
cls | client identification of the client |
msg | the actual message |
Definition at line 862 of file gnunet-service-scalarproduct-ecc_alice.c.
References AliceServiceSession::client, AliceServiceSession::client_received_element_count, client_request_complete_alice(), GNUNET_SETI_Element::data, GNUNET_SETI_Element::element_type, GNUNET_break, GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_memcpy, GNUNET_new, GNUNET_SERVICE_client_continue(), GNUNET_SETI_add_element(), GNUNET_SYSERR, AliceServiceSession::intersected_elements, AliceServiceSession::intersection_set, GNUNET_SCALARPRODUCT_Element::key, msg, AliceServiceSession::s, GNUNET_SETI_Element::size, AliceServiceSession::total, and AliceServiceSession::used_element_count.
|
static |
Handler for Alice's client request message.
Check that msg is well-formed.
cls | identification of the client |
msg | the actual message |
Definition at line 919 of file gnunet-service-scalarproduct-ecc_alice.c.
References GNUNET_break, GNUNET_break_op, GNUNET_OK, GNUNET_SYSERR, msg, AliceServiceSession::s, and GNUNET_MessageHeader::size.
|
static |
Handler for Alice's client request message.
We are doing request-initiation to compute a scalar product with a peer.
cls | identification of the client |
msg | the actual message |
Definition at line 957 of file gnunet-service-scalarproduct-ecc_alice.c.
References cfg, AliceServiceSession::client, AliceServiceSession::client_received_element_count, client_request_complete_alice(), GNUNET_SETI_Element::data, GNUNET_SETI_Element::element_type, GNUNET_break, GNUNET_CONTAINER_multihashmap_create(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_new, GNUNET_ntohll(), GNUNET_SCALARPRODUCT_STATUS_ACTIVE, GNUNET_SERVICE_client_continue(), GNUNET_SETI_add_element(), GNUNET_SETI_create(), GNUNET_SYSERR, GNUNET_YES, AliceServiceSession::intersected_elements, AliceServiceSession::intersection_set, GNUNET_SCALARPRODUCT_Element::key, msg, AliceServiceSession::peer, AliceServiceSession::s, AliceServiceSession::session_id, GNUNET_SETI_Element::size, AliceServiceSession::status, AliceServiceSession::total, AliceServiceSession::used_element_count, and value.
|
static |
Task run during shutdown.
cls | unused |
tc | unused |
Definition at line 1027 of file gnunet-service-scalarproduct-ecc_alice.c.
References edc, GNUNET_CADET_disconnect(), GNUNET_CRYPTO_ecc_dlog_release(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, and my_cadet.
Referenced by run().
|
static |
A client connected.
Setup the associated data structure.
cls | closure, NULL |
client | identification of the client |
mq | message queue to communicate with client |
struct AliceServiceSession
Definition at line 1056 of file gnunet-service-scalarproduct-ecc_alice.c.
References AliceServiceSession::client, GNUNET_new, mq, and AliceServiceSession::s.
|
static |
A client disconnected.
Remove the associated session(s), release data structures and cancel pending outgoing transmissions to the client.
cls | closure, NULL |
client | identification of the client |
app_cls | our struct AliceServiceSession |
Definition at line 1080 of file gnunet-service-scalarproduct-ecc_alice.c.
References AliceServiceSession::client, destroy_service_session(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, and AliceServiceSession::s.
|
static |
Initialization of the program and message handlers.
cls | closure |
c | configuration to use |
service | the initialized service |
Definition at line 1103 of file gnunet-service-scalarproduct-ecc_alice.c.
References _, cfg, edc, GNUNET_CADET_connect(), GNUNET_CRYPTO_ecc_dlog_prepare(), GNUNET_CRYPTO_ecc_rnd_mpi(), GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), MAX_RAM, MAX_RESULT, my_cadet, my_privkey, my_privkey_inv, and shutdown_task().
GNUNET_SERVICE_MAIN | ( | GNUNET_OS_project_data_gnunet() | , |
"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() | |||
) |
Define "main" method using service macro.
|
static |
GNUnet configuration handle.
Definition at line 182 of file gnunet-service-scalarproduct-ecc_alice.c.
Referenced by client_request_complete_alice(), handle_alice_client_message(), and run().
|
static |
Context for DLOG operations on a curve.
Definition at line 187 of file gnunet-service-scalarproduct-ecc_alice.c.
Referenced by GNUNET_CRYPTO_ecc_dlog(), GNUNET_CRYPTO_ecc_dlog_prepare(), GNUNET_CRYPTO_ecc_dlog_release(), handle_bobs_cryptodata_message(), run(), and shutdown_task().
|
static |
Alice's private key ('a').
Definition at line 192 of file gnunet-service-scalarproduct-ecc_alice.c.
Referenced by run(), and send_alices_cryptodata_message().
|
static |
Inverse of Alice's private key ('a_inv').
Definition at line 197 of file gnunet-service-scalarproduct-ecc_alice.c.
Referenced by handle_bobs_cryptodata_message(), and run().
|
static |
Handle to the CADET service.
Definition at line 202 of file gnunet-service-scalarproduct-ecc_alice.c.
Referenced by client_request_complete_alice(), run(), and shutdown_task().