scalarproduct service implementation More...
#include "platform.h"
#include <limits.h>
#include <gcrypt.h>
#include "gnunet_util_lib.h"
#include "gnunet_core_service.h"
#include "gnunet_cadet_service.h"
#include "gnunet_applications.h"
#include "gnunet_protocols.h"
#include "gnunet_scalarproduct_service.h"
#include "gnunet_seti_service.h"
#include "scalarproduct.h"
#include "gnunet-service-scalarproduct-ecc.h"
Go to the source code of this file.
Data Structures | |
struct | MpiElement |
An encrypted element key-value pair. More... | |
struct | BobServiceSession |
A scalarproduct session which tracks an offer for a multiplication service by a local client. More... | |
Macros | |
#define | LOG(kind, ...) GNUNET_log_from (kind, "scalarproduct-bob", __VA_ARGS__) |
Functions | |
static int | free_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value) |
Callback used to free the elements in the map. More... | |
static void | destroy_service_session (struct BobServiceSession *s) |
Destroy session state, we are done with it. More... | |
static void | prepare_client_end_notification (struct BobServiceSession *session) |
Notify the client that the session has succeeded or failed. More... | |
static void | cb_channel_destruction (void *cls, const struct GNUNET_CADET_Channel *channel) |
Function called whenever a channel is destroyed. More... | |
static void | bob_cadet_done_cb (void *cls) |
MQ finished giving our last message to CADET, now notify the client that we are finished. More... | |
static void | transmit_bobs_cryptodata_message (struct BobServiceSession *s) |
Bob generates the response message to be sent to Alice. 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 int | check_alices_cryptodata_message (void *cls, const struct EccAliceCryptodataMessage *msg) |
Check a multipart-chunk of a request from another service to calculate a scalarproduct with us. More... | |
static void | handle_alices_cryptodata_message (void *cls, const struct EccAliceCryptodataMessage *msg) |
Handle a multipart-chunk of a request from another service to calculate a scalarproduct with us. 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 | start_intersection (struct BobServiceSession *s) |
We've paired up a client session with an incoming CADET request. More... | |
static void | handle_alices_computation_request (void *cls, const struct EccServiceRequestMessage *msg) |
Handle a request from Alice to calculate a scalarproduct with us (Bob). More... | |
static void * | cb_channel_incoming (void *cls, struct GNUNET_CADET_Channel *channel, const struct GNUNET_PeerIdentity *initiator) |
Function called for inbound channels on Bob's end. More... | |
static int | check_bob_client_message_multipart (void *cls, const struct ComputationBobCryptodataMultipartMessage *msg) |
We're receiving additional set data. More... | |
static void | handle_bob_client_message_multipart (void *cls, const struct ComputationBobCryptodataMultipartMessage *msg) |
We're receiving additional set data. More... | |
static int | check_bob_client_message (void *cls, const struct BobComputationMessage *msg) |
Handler for Bob's a client request message. More... | |
static void | handle_bob_client_message (void *cls, const struct BobComputationMessage *msg) |
Handler for Bob's a 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 ("scalarproduct-bob", GNUNET_SERVICE_OPTION_NONE, &run, &client_connect_cb, &client_disconnect_cb, NULL, GNUNET_MQ_hd_var_size(bob_client_message, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_BOB, struct BobComputationMessage, NULL), GNUNET_MQ_hd_var_size(bob_client_message_multipart, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_BOB, 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_CADET_Handle * | my_cadet |
Handle to the CADET service. More... | |
static struct GNUNET_CRYPTO_EccDlogContext * | edc |
Context for DLOG operations on a curve. More... | |
scalarproduct service implementation
Definition in file gnunet-service-scalarproduct-ecc_bob.c.
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log_from (kind, "scalarproduct-bob", __VA_ARGS__) |
Definition at line 39 of file gnunet-service-scalarproduct-ecc_bob.c.
|
static |
Callback used to free the elements in the map.
cls | NULL |
key | key of the element |
value | the value to free |
Definition at line 197 of file gnunet-service-scalarproduct-ecc_bob.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 214 of file gnunet-service-scalarproduct-ecc_bob.c.
References BobServiceSession::channel, BobServiceSession::client, free_element_cb(), GNUNET_CADET_channel_destroy(), GNUNET_CADET_close_port(), GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_free, GNUNET_SERVICE_client_drop(), GNUNET_SETI_destroy(), GNUNET_SETI_operation_cancel(), GNUNET_YES, BobServiceSession::in_destroy, BobServiceSession::intersected_elements, BobServiceSession::intersection_op, BobServiceSession::intersection_set, BobServiceSession::port, and BobServiceSession::sorted_elements.
Referenced by cb_channel_destruction(), and client_disconnect_cb().
|
static |
Notify the client that the session has succeeded or failed.
This message gets sent to Bob's client if the operation completed or Alice disconnected.
session | the associated client session to fail or succeed |
Definition at line 271 of file gnunet-service-scalarproduct-ecc_bob.c.
References BobServiceSession::client_mq, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT, GNUNET_MQ_msg, GNUNET_MQ_send(), msg, BobServiceSession::session_id, and BobServiceSession::status.
Referenced by bob_cadet_done_cb(), cb_channel_destruction(), and cb_intersection_element_removed().
|
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 BobServiceSession |
channel | connection to the other end (henceforth invalid) |
Definition at line 302 of file gnunet-service-scalarproduct-ecc_bob.c.
References destroy_service_session(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_SCALARPRODUCT_STATUS_ACTIVE, GNUNET_SCALARPRODUCT_STATUS_FAILURE, prepare_client_end_notification(), and BobServiceSession::s.
Referenced by handle_bob_client_message().
|
static |
MQ finished giving our last message to CADET, now notify the client that we are finished.
Definition at line 326 of file gnunet-service-scalarproduct-ecc_bob.c.
References GNUNET_SCALARPRODUCT_STATUS_SUCCESS, prepare_client_end_notification(), and BobServiceSession::status.
Referenced by transmit_bobs_cryptodata_message().
|
static |
Bob generates the response message to be sent to Alice.
s | the associated requesting session with Alice |
Definition at line 341 of file gnunet-service-scalarproduct-ecc_bob.c.
References bob_cadet_done_cb(), BobServiceSession::cadet_mq, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_BOB_CRYPTODATA, GNUNET_MQ_msg, GNUNET_MQ_notify_sent(), GNUNET_MQ_send(), msg, BobServiceSession::prod_g_i_b_i, and BobServiceSession::prod_h_i_b_i.
Referenced by cb_intersection_element_removed(), and handle_alices_cryptodata_message().
|
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 370 of file gnunet-service-scalarproduct-ecc_bob.c.
References GNUNET_ntohll(), GNUNET_OK, MpiElement::key, GNUNET_SCALARPRODUCT_Element::key, BobServiceSession::s, BobServiceSession::sorted_elements, BobServiceSession::used_element_count, value, MpiElement::value, and GNUNET_SCALARPRODUCT_Element::value.
Referenced by handle_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 394 of file gnunet-service-scalarproduct-ecc_bob.c.
References GNUNET_CRYPTO_hash_cmp(), and MpiElement::key.
Referenced by handle_alices_cryptodata_message().
|
static |
Check a multipart-chunk of a request from another service to calculate a scalarproduct with us.
cls | closure (set from GNUNET_CADET_connect) |
msg | the actual message |
Definition at line 415 of file gnunet-service-scalarproduct-ecc_bob.c.
References GNUNET_break_op, GNUNET_CONTAINER_multihashmap_size(), GNUNET_OK, GNUNET_SYSERR, max, msg, BobServiceSession::s, and GNUNET_MessageHeader::size.
|
static |
Handle a multipart-chunk of a request from another service to calculate a scalarproduct with us.
cls | closure (set from GNUNET_CADET_connect) |
msg | the actual message |
Definition at line 456 of file gnunet-service-scalarproduct-ecc_bob.c.
References BobServiceSession::cadet_received_element_count, BobServiceSession::channel, copy_element_cb(), element_cmp(), GNUNET_assert, GNUNET_CADET_receive_done(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_CONTAINER_multihashmap_size(), GNUNET_CRYPTO_ecc_add(), GNUNET_CRYPTO_ecc_pmul_mpi(), GNUNET_CRYPTO_ecc_scalar_from_int(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_new_array, GNUNET_OK, BobServiceSession::intersected_elements, BobServiceSession::intersection_op, max, msg, payload, BobServiceSession::prod_g_i_b_i, BobServiceSession::prod_h_i_b_i, BobServiceSession::s, BobServiceSession::sorted_elements, transmit_bobs_cryptodata_message(), BobServiceSession::used_element_count, GNUNET_CRYPTO_EccScalar::v, and MpiElement::value.
|
static |
Callback for set operation results.
Called for each element that needs to be removed from the result set.
cls | closure with the struct BobServiceSession |
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 557 of file gnunet-service-scalarproduct-ecc_bob.c.
References BobServiceSession::channel, BobServiceSession::client_received_element_count, GNUNET_SETI_Element::data, GNUNET_assert, GNUNET_break, GNUNET_CADET_receive_done(), GNUNET_CONTAINER_multihashmap_get(), GNUNET_CONTAINER_multihashmap_remove(), GNUNET_CONTAINER_multihashmap_size(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_h2s(), GNUNET_ntohll(), GNUNET_SCALARPRODUCT_STATUS_FAILURE, GNUNET_SETI_destroy(), GNUNET_SETI_STATUS_DEL_LOCAL, GNUNET_SETI_STATUS_DONE, GNUNET_SETI_STATUS_FAILURE, GNUNET_YES, BobServiceSession::intersected_elements, BobServiceSession::intersection_op, BobServiceSession::intersection_set, GNUNET_SCALARPRODUCT_Element::key, LOG, prepare_client_end_notification(), BobServiceSession::s, status, BobServiceSession::status, transmit_bobs_cryptodata_message(), and GNUNET_SCALARPRODUCT_Element::value.
|
static |
We've paired up a client session with an incoming CADET request.
Initiate set intersection work.
s | client session to start intersection for |
Definition at line 626 of file gnunet-service-scalarproduct-ecc_bob.c.
References GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_SETI_prepare(), BobServiceSession::intersection_op, BobServiceSession::peer, BobServiceSession::session_id, and BobServiceSession::total.
Referenced by handle_alices_computation_request(), and handle_bob_client_message_multipart().
|
static |
Handle a request from Alice to calculate a scalarproduct with us (Bob).
cls | closure (set from GNUNET_CADET_connect) |
msg | the actual message |
Definition at line 666 of file gnunet-service-scalarproduct-ecc_bob.c.
References GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, msg, BobServiceSession::s, and start_intersection().
|
static |
Function called for inbound channels on Bob's end.
Does some preliminary initialization, more happens after we get Alice's first message.
cls | our struct BobServiceSession |
channel | new handle to the channel |
initiator | peer that started the channel |
Definition at line 695 of file gnunet-service-scalarproduct-ecc_bob.c.
References BobServiceSession::channel, GNUNET_CADET_close_port(), GNUNET_CADET_get_mq(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, and BobServiceSession::s.
Referenced by handle_bob_client_message().
|
static |
We're receiving additional set data.
Check it is well-formed.
cls | identification of the client |
msg | the actual message |
Definition at line 721 of file gnunet-service-scalarproduct-ecc_bob.c.
References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, msg, BobServiceSession::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 | identification of the client |
msg | the actual message |
Definition at line 754 of file gnunet-service-scalarproduct-ecc_bob.c.
References BobServiceSession::channel, BobServiceSession::client, BobServiceSession::client_received_element_count, 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, BobServiceSession::intersected_elements, BobServiceSession::intersection_set, GNUNET_SCALARPRODUCT_Element::key, msg, BobServiceSession::s, GNUNET_SETI_Element::size, start_intersection(), and BobServiceSession::total.
|
static |
Handler for Bob's a client request message.
Check msg is well-formed.
cls | identification of the client |
msg | the actual message |
Definition at line 820 of file gnunet-service-scalarproduct-ecc_bob.c.
References GNUNET_break, GNUNET_break_op, GNUNET_OK, GNUNET_SCALARPRODUCT_STATUS_INIT, GNUNET_SYSERR, msg, BobServiceSession::s, and GNUNET_MessageHeader::size.
|
static |
Handler for Bob's a client request message.
Bob is in the response role, keep the values + session and waiting for a matching session or process a waiting request from Alice.
cls | identification of the client |
msg | the actual message |
Definition at line 859 of file gnunet-service-scalarproduct-ecc_bob.c.
References cb_channel_destruction(), cb_channel_incoming(), cfg, BobServiceSession::client, BobServiceSession::client_received_element_count, GNUNET_SETI_Element::data, GNUNET_SETI_Element::element_type, GNUNET_break, GNUNET_CADET_open_port(), GNUNET_CONTAINER_multihashmap_create(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_h2s(), GNUNET_log, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_ALICE_CRYPTODATA, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_SESSION_INITIALIZATION, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_new, GNUNET_ntohll(), GNUNET_SCALARPRODUCT_STATUS_ACTIVE, GNUNET_SERVICE_client_continue(), GNUNET_SERVICE_client_drop(), GNUNET_SETI_add_element(), GNUNET_SETI_create(), GNUNET_SYSERR, GNUNET_YES, BobServiceSession::intersected_elements, BobServiceSession::intersection_set, GNUNET_SCALARPRODUCT_Element::key, msg, my_cadet, BobServiceSession::port, BobServiceSession::s, BobServiceSession::session_id, GNUNET_SETI_Element::size, BobServiceSession::status, BobServiceSession::total, BobServiceSession::used_element_count, and value.
|
static |
Task run during shutdown.
cls | unused |
Definition at line 944 of file gnunet-service-scalarproduct-ecc_bob.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 BobServiceSession
Definition at line 973 of file gnunet-service-scalarproduct-ecc_bob.c.
References BobServiceSession::client, GNUNET_new, mq, and BobServiceSession::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 BobServiceSession |
Definition at line 997 of file gnunet-service-scalarproduct-ecc_bob.c.
References destroy_service_session(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, and BobServiceSession::s.
|
static |
Initialization of the program and message handlers.
cls | closure |
c | configuration to use |
service | the initialized service |
Definition at line 1018 of file gnunet-service-scalarproduct-ecc_bob.c.
References _, cfg, edc, GNUNET_CADET_connect(), GNUNET_CRYPTO_ecc_dlog_prepare(), GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), my_cadet, and shutdown_task().
GNUNET_SERVICE_MAIN | ( | "scalarproduct-bob" | , |
GNUNET_SERVICE_OPTION_NONE | , | ||
& | run, | ||
& | client_connect_cb, | ||
& | client_disconnect_cb, | ||
NULL | , | ||
GNUNET_MQ_hd_var_size(bob_client_message, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_BOB, struct BobComputationMessage, NULL) | , | ||
GNUNET_MQ_hd_var_size(bob_client_message_multipart, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_BOB, struct ComputationBobCryptodataMultipartMessage, NULL) | , | ||
GNUNET_MQ_handler_end() | |||
) |
Define "main" method using service macro.
|
static |
GNUnet configuration handle.
Definition at line 176 of file gnunet-service-scalarproduct-ecc_bob.c.
Referenced by handle_bob_client_message(), and run().
|
static |
Handle to the CADET service.
Definition at line 181 of file gnunet-service-scalarproduct-ecc_bob.c.
Referenced by handle_bob_client_message(), run(), and shutdown_task().
|
static |
Context for DLOG operations on a curve.
Definition at line 186 of file gnunet-service-scalarproduct-ecc_bob.c.
Referenced by run(), and shutdown_task().