34#define LOG(kind, ...) GNUNET_log_from (kind, "scalarproduct-api", __VA_ARGS__)
130 if (NULL !=
h->cont_status)
131 h->cont_status (
h->cont_cls,
168 uint32_t element_count)
176 for (uint32_t i = 0; i < element_count; i++)
184 _ (
"Keys given to SCALARPRODUCT not unique!\n"));
206 "Disconnected from SCALARPRODUCT service.\n");
218 uint32_t element_count,
237 uint32_t element_count_transfered;
243 h->cont_status = cont;
244 h->cont_cls = cont_cls;
269 msg->element_count_total = htonl (element_count);
270 msg->element_count_contained = htonl (todo);
275 element_count_transfered = todo;
280 while (element_count_transfered < element_count)
283 element_count - element_count_transfered);
290 &elements[element_count_transfered],
292 element_count_transfered += todo;
314 uint32_t product_len;
322 result = gcry_mpi_new (0);
324 product_len = ntohl (
msg->product_length);
328 if (0 != (rc = gcry_mpi_scan (&num, GCRYMPI_FMT_STD,
336 gcry_mpi_release (
result);
342 if (0 < (int32_t) ntohl (
msg->range))
346 gcry_mpi_release (num);
350 if (NULL !=
h->cont_datum)
351 h->cont_datum (
h->cont_cls,
355 gcry_mpi_release (
result);
366 uint32_t element_count,
385 uint32_t element_count_transfered;
391 "scalarproduct-alice",
402 h->cont_datum = cont;
403 h->cont_cls = cont_cls;
417 msg->element_count_total = htonl (element_count);
418 msg->element_count_contained = htonl (todo);
419 msg->reserved = htonl (0);
427 element_count_transfered = todo;
430 while (element_count_transfered < element_count)
433 element_count - element_count_transfered);
440 &elements[element_count_transfered],
442 element_count_transfered += todo;
struct GNUNET_MQ_MessageHandlers handlers[]
struct GNUNET_MessageHeader * msg
struct GNUNET_MQ_Envelope * env
static struct GNUNET_ARM_Handle * h
Connection with ARM.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static struct MHD_Response * response
Our canonical response.
struct GNUNET_HashCode key
The key used in the DHT.
static int status
The program status; 0 for success.
static int result
Global testing status.
static struct GNUNET_HashCode session_key
the session key identifying this computation
Constants for network protocols.
API to create, modify and access statistics.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_MQ_Error
Error codes for the queue.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
#define GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT
Alice/Bob -> Client Result.
#define GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_BOB
Client -> Bob.
#define GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE
Client -> Alice multipart.
#define GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_BOB
Client -> Bob multipart.
#define GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE
Client -> Alice.
void(* GNUNET_SCALARPRODUCT_DatumProcessor)(void *cls, enum GNUNET_SCALARPRODUCT_ResponseStatus status, gcry_mpi_t result)
Process a datum that was stored in the scalarproduct.
GNUNET_SCALARPRODUCT_ResponseStatus
Result status values for the computation.
struct GNUNET_SCALARPRODUCT_ComputationHandle * GNUNET_SCALARPRODUCT_start_computation(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_HashCode *session_key, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_SCALARPRODUCT_Element *elements, uint32_t element_count, GNUNET_SCALARPRODUCT_DatumProcessor cont, void *cont_cls)
Request by Alice's client for computing a scalar product.
void GNUNET_SCALARPRODUCT_cancel(struct GNUNET_SCALARPRODUCT_ComputationHandle *h)
Cancel an ongoing computation or revoke our collaboration offer.
GNUNET_NETWORK_STRUCT_END typedef void(* GNUNET_SCALARPRODUCT_ContinuationWithStatus)(void *cls, enum GNUNET_SCALARPRODUCT_ResponseStatus status)
Continuation called to notify client about result of the operation.
struct GNUNET_SCALARPRODUCT_ComputationHandle * GNUNET_SCALARPRODUCT_accept_computation(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_HashCode *session_key, const struct GNUNET_SCALARPRODUCT_Element *elements, uint32_t element_count, GNUNET_SCALARPRODUCT_ContinuationWithStatus cont, void *cont_cls)
Used by Bob's client to cooperate with Alice,.
@ GNUNET_SCALARPRODUCT_STATUS_SUCCESS
The computation was successful.
@ GNUNET_SCALARPRODUCT_STATUS_DISCONNECTED
We got disconnected from the SCALARPRODUCT service.
@ GNUNET_SCALARPRODUCT_STATUS_INVALID_RESPONSE
We got an invalid response.
static struct GNUNET_CONTAINER_MultiPeerMap * map
Peermap of PeerIdentities to "struct PeerEntry" (for fast lookup).
static unsigned int size
Size of the "table".
Scalar Product API Message Types.
#define LOG_GCRY(level, cmd, rc)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
static void process_result_message(struct GNUNET_SCALARPRODUCT_ComputationHandle *h, const struct ClientResponseMessage *msg, enum GNUNET_SCALARPRODUCT_ResponseStatus status)
Handles the RESULT received from the service for a request, should contain a result MPI value.
static int check_unique(const struct GNUNET_SCALARPRODUCT_Element *elements, uint32_t element_count)
Check if the keys for all given elements are unique.
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
We encountered an error communicating with the set service while performing a set operation.
static void process_status_message(struct GNUNET_SCALARPRODUCT_ComputationHandle *h, const struct ClientResponseMessage *msg, enum GNUNET_SCALARPRODUCT_ResponseStatus status)
Handles the STATUS received from the service for a response, does not contain a payload.
static void handle_response(void *cls, const struct ClientResponseMessage *message)
Called when a response is received from the service.
void(* GNUNET_SCALARPRODUCT_ResponseMessageHandler)(struct GNUNET_SCALARPRODUCT_ComputationHandle *h, const struct ClientResponseMessage *msg, enum GNUNET_SCALARPRODUCT_ResponseStatus status)
The abstraction function for our internal callback.
static int check_response(void *cls, const struct ClientResponseMessage *message)
Called when a response is received from the service.
Message type passed from client to service to initiate a request or responder role.
Message type passed from client to service to initiate a request or responder role.
Message type passed from service client to finalize a session as requester or responder.
uint32_t product_length
0 if no product attached
struct GNUNET_MessageHeader header
GNUNET message header.
uint32_t status
Status information about the outcome of this session, An enum GNUNET_SCALARPRODUCT_ResponseStatus (in...
multipart messages following struct ComputationMessage
uint32_t element_count_contained
contained elements the vector in payload contains
struct GNUNET_MQ_Handle * mq
Our connection to the ARM service.
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
Internal representation of the hash map.
Handle to a message queue.
Message handler for a specific message type.
The identity of the host (wraps the signing key of the peer).
A handle returned for each computation.
GNUNET_SCALARPRODUCT_ResponseMessageHandler response_proc
API internal callback for results and failures to be forwarded to the client.
struct GNUNET_MQ_Handle * mq
Current connection to the scalarproduct service.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
struct GNUNET_HashCode key
The shared session key identifying this computation.
void * cont_cls
Closure for cont_status or cont_datum.
GNUNET_SCALARPRODUCT_ContinuationWithStatus cont_status
Function to call after transmission of the request (Bob).
GNUNET_SCALARPRODUCT_DatumProcessor cont_datum
Function to call after transmission of the request (Alice).
An element key-value pair for scalarproduct.