GNUnet 0.21.0
Scalar Product service

Data Structures

struct  GNUNET_SCALARPRODUCT_Element
 An element key-value pair for scalarproduct. More...
 

Macros

#define GCRYPT_NO_DEPRECATED
 
#define GNUNET_SCALARPRODUCT_VERSION   0x00000044
 Version of the scalarproduct API. More...
 

Typedefs

typedef void(* GNUNET_SCALARPRODUCT_DatumProcessor) (void *cls, enum GNUNET_SCALARPRODUCT_ResponseStatus status, gcry_mpi_t result)
 Process a datum that was stored in the scalarproduct. More...
 

Enumerations

enum  GNUNET_SCALARPRODUCT_ResponseStatus {
  GNUNET_SCALARPRODUCT_STATUS_INIT = 0 , GNUNET_SCALARPRODUCT_STATUS_ACTIVE = 1 , GNUNET_SCALARPRODUCT_STATUS_SUCCESS , GNUNET_SCALARPRODUCT_STATUS_FAILURE ,
  GNUNET_SCALARPRODUCT_STATUS_INVALID_RESPONSE , GNUNET_SCALARPRODUCT_STATUS_DISCONNECTED
}
 Result status values for the computation. More...
 

Functions

struct GNUNET_SCALARPRODUCT_ComputationHandleGNUNET_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. More...
 
struct GNUNET_SCALARPRODUCT_ComputationHandleGNUNET_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,. More...
 
void GNUNET_SCALARPRODUCT_cancel (struct GNUNET_SCALARPRODUCT_ComputationHandle *h)
 Cancel an ongoing computation or revoke our collaboration offer. More...
 

Variables

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. More...
 

Detailed Description

Macro Definition Documentation

◆ GCRYPT_NO_DEPRECATED

#define GCRYPT_NO_DEPRECATED

Definition at line 33 of file gnunet_scalarproduct_service.h.

◆ GNUNET_SCALARPRODUCT_VERSION

#define GNUNET_SCALARPRODUCT_VERSION   0x00000044

Version of the scalarproduct API.

Definition at line 47 of file gnunet_scalarproduct_service.h.

Typedef Documentation

◆ GNUNET_SCALARPRODUCT_DatumProcessor

typedef void(* GNUNET_SCALARPRODUCT_DatumProcessor) (void *cls, enum GNUNET_SCALARPRODUCT_ResponseStatus status, gcry_mpi_t result)

Process a datum that was stored in the scalarproduct.

Parameters
clsclosure
statusStatus of the request
resultresult of the computation

Definition at line 133 of file gnunet_scalarproduct_service.h.

Enumeration Type Documentation

◆ GNUNET_SCALARPRODUCT_ResponseStatus

Result status values for the computation.

Enumerator
GNUNET_SCALARPRODUCT_STATUS_INIT 

Operation is still active (never returned, used internally).

GNUNET_SCALARPRODUCT_STATUS_ACTIVE 

Operation is still active (never returned, used internally).

GNUNET_SCALARPRODUCT_STATUS_SUCCESS 

The computation was successful.

GNUNET_SCALARPRODUCT_STATUS_FAILURE 

We encountered some error.

GNUNET_SCALARPRODUCT_STATUS_INVALID_RESPONSE 

We got an invalid response.

GNUNET_SCALARPRODUCT_STATUS_DISCONNECTED 

We got disconnected from the SCALARPRODUCT service.

Definition at line 52 of file gnunet_scalarproduct_service.h.

53{
58
63
68
73
78
83};
@ GNUNET_SCALARPRODUCT_STATUS_INIT
Operation is still active (never returned, used internally).
@ GNUNET_SCALARPRODUCT_STATUS_SUCCESS
The computation was successful.
@ GNUNET_SCALARPRODUCT_STATUS_ACTIVE
Operation is still active (never returned, used internally).
@ GNUNET_SCALARPRODUCT_STATUS_FAILURE
We encountered some error.
@ GNUNET_SCALARPRODUCT_STATUS_DISCONNECTED
We got disconnected from the SCALARPRODUCT service.
@ GNUNET_SCALARPRODUCT_STATUS_INVALID_RESPONSE
We got an invalid response.

Function Documentation

◆ GNUNET_SCALARPRODUCT_start_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.

Parameters
cfgthe gnunet configuration handle
session_keySession key should be unique to the requesting client
peerPeerID of the other peer
elementsArray of elements of the vector
element_countNumber of elements in the elements vector
contCallback function
cont_clsClosure for the cont callback function
Returns
a new handle for this computation

Definition at line 361 of file scalarproduct_api.c.

369{
376 h),
378 };
379 struct GNUNET_MQ_Envelope *env;
382 uint32_t size;
383 uint16_t possible;
384 uint16_t todo;
385 uint32_t element_count_transfered;
386
387 if (GNUNET_SYSERR == check_unique (elements,
388 element_count))
389 return NULL;
391 "scalarproduct-alice",
392 handlers,
394 h);
395 if (NULL == h->mq)
396 {
397 /* misconfigured scalarproduct service */
398 GNUNET_break (0);
399 GNUNET_free (h);
400 return NULL;
401 }
402 h->cont_datum = cont;
403 h->cont_cls = cont_cls;
404 h->response_proc = &process_result_message;
405 h->cfg = cfg;
406 h->key = *session_key;
407
408 possible = (GNUNET_MAX_MESSAGE_SIZE - 1 - sizeof(struct
410 / sizeof(struct GNUNET_SCALARPRODUCT_Element);
411 todo = GNUNET_MIN (possible,
412 element_count);
413 size = todo * sizeof(struct GNUNET_SCALARPRODUCT_Element);
415 size,
417 msg->element_count_total = htonl (element_count);
418 msg->element_count_contained = htonl (todo);
419 msg->reserved = htonl (0);
420 msg->peer = *peer;
421 msg->session_key = *session_key;
422 GNUNET_memcpy (&msg[1],
423 elements,
424 size);
426 env);
427 element_count_transfered = todo;
428 possible = (GNUNET_MAX_MESSAGE_SIZE - 1 - sizeof(*mmsg))
429 / sizeof(struct GNUNET_SCALARPRODUCT_Element);
430 while (element_count_transfered < element_count)
431 {
432 todo = GNUNET_MIN (possible,
433 element_count - element_count_transfered);
434 size = todo * sizeof(struct GNUNET_SCALARPRODUCT_Element);
435 env = GNUNET_MQ_msg_extra (mmsg,
436 size,
438 mmsg->element_count_contained = htonl (todo);
439 GNUNET_memcpy (&mmsg[1],
440 &elements[element_count_transfered],
441 size);
442 element_count_transfered += todo;
444 env);
445 }
446 return h;
447}
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
static struct MHD_Response * response
Our canonical response.
static struct GNUNET_HashCode session_key
the session key identifying this computation
#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.
Definition: client.c:1057
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_MIN(a, b)
@ GNUNET_SYSERR
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:304
#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.
Definition: gnunet_mq_lib.h:63
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT
Alice/Bob -> Client Result.
#define GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE
Client -> Alice multipart.
#define GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE
Client -> Alice.
static unsigned int size
Size of the "table".
Definition: peer.c:68
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.
Message type passed from client to service to initiate a request or responder role.
Definition: scalarproduct.h:46
Message type passed from service client to finalize a session as requester or responder.
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.
Definition: arm_api.c:107
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
Definition: arm_api.c:112
Message handler for a specific message type.
A handle returned for each computation.
An element key-value pair for scalarproduct.

References cfg, GNUNET_ARM_Handle::cfg, check_unique(), ComputationBobCryptodataMultipartMessage::element_count_contained, env, GNUNET_break, GNUNET_CLIENT_connect(), GNUNET_free, GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT, GNUNET_MIN, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_new, GNUNET_SYSERR, h, handlers, GNUNET_ARM_Handle::mq, mq_error_handler(), msg, process_result_message(), response, session_key, and size.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SCALARPRODUCT_accept_computation()

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,.

Parameters
cfgthe gnunet configuration handle
session_keySession key unique to the requesting client
elementsArray of elements of the vector
element_countNumber of elements in the elements vector
contCallback function
cont_clsClosure for the cont callback function
Returns
a new handle for this computation

Definition at line 214 of file scalarproduct_api.c.

221{
228 h),
230 };
231 struct GNUNET_MQ_Envelope *env;
234 uint32_t size;
235 uint16_t possible;
236 uint16_t todo;
237 uint32_t element_count_transfered;
238
239
240 if (GNUNET_SYSERR == check_unique (elements,
241 element_count))
242 return NULL;
243 h->cont_status = cont;
244 h->cont_cls = cont_cls;
245 h->response_proc = &process_status_message;
246 h->cfg = cfg;
247 h->key = *session_key;
249 "scalarproduct-bob",
250 handlers,
252 h);
253 if (NULL == h->mq)
254 {
255 /* scalarproduct configuration error */
256 GNUNET_break (0);
257 GNUNET_free (h);
258 return NULL;
259 }
260 possible = (GNUNET_MAX_MESSAGE_SIZE - 1 - sizeof(struct
262 / sizeof(struct GNUNET_SCALARPRODUCT_Element);
263 todo = GNUNET_MIN (possible,
264 element_count);
265 size = todo * sizeof(struct GNUNET_SCALARPRODUCT_Element);
267 size,
269 msg->element_count_total = htonl (element_count);
270 msg->element_count_contained = htonl (todo);
271 msg->session_key = *session_key;
272 GNUNET_memcpy (&msg[1],
273 elements,
274 size);
275 element_count_transfered = todo;
277 env);
278 possible = (GNUNET_MAX_MESSAGE_SIZE - 1 - sizeof(*mmsg))
279 / sizeof(struct GNUNET_SCALARPRODUCT_Element);
280 while (element_count_transfered < element_count)
281 {
282 todo = GNUNET_MIN (possible,
283 element_count - element_count_transfered);
284 size = todo * sizeof(struct GNUNET_SCALARPRODUCT_Element);
285 env = GNUNET_MQ_msg_extra (mmsg,
286 size,
288 mmsg->element_count_contained = htonl (todo);
289 GNUNET_memcpy (&mmsg[1],
290 &elements[element_count_transfered],
291 size);
292 element_count_transfered += todo;
294 env);
295 }
296 return h;
297}
#define GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_BOB
Client -> Bob.
#define GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_BOB
Client -> Bob multipart.
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.
Message type passed from client to service to initiate a request or responder role.
Definition: scalarproduct.h:89

References cfg, GNUNET_ARM_Handle::cfg, check_unique(), ComputationBobCryptodataMultipartMessage::element_count_contained, env, GNUNET_break, GNUNET_CLIENT_connect(), GNUNET_free, GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_BOB, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_BOB, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT, GNUNET_MIN, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_new, GNUNET_SYSERR, h, handlers, GNUNET_ARM_Handle::mq, mq_error_handler(), msg, process_status_message(), response, session_key, and size.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SCALARPRODUCT_cancel()

void GNUNET_SCALARPRODUCT_cancel ( struct GNUNET_SCALARPRODUCT_ComputationHandle h)

Cancel an ongoing computation or revoke our collaboration offer.

Closes the connection to the service

Parameters
hcomputation handle to terminate

Definition at line 457 of file scalarproduct_api.c.

458{
459 if (NULL != h->mq)
460 {
462 h->mq = NULL;
463 }
464 GNUNET_free (h);
465}
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:683

References GNUNET_free, GNUNET_MQ_destroy(), h, and GNUNET_ARM_Handle::mq.

Referenced by process_result_message(), process_status_message(), and shutdown_task().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ GNUNET_SCALARPRODUCT_ContinuationWithStatus

GNUNET_NETWORK_STRUCT_END typedef void(* GNUNET_SCALARPRODUCT_ContinuationWithStatus) (void *cls, enum GNUNET_SCALARPRODUCT_ResponseStatus status) ( void *  cls,
enum GNUNET_SCALARPRODUCT_ResponseStatus  status 
)

Continuation called to notify client about result of the operation.

Parameters
clsclosure
statusStatus of the request

Definition at line 120 of file gnunet_scalarproduct_service.h.