GNUnet  0.10.x
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
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 *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 34 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 131 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.

52  {
57 
62 
67 
72 
77 
82 };
Operation is still active (never returned, used internally).
Operation is still active (never returned, used internally).
We got disconnected from the SCALARPRODUCT service.

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
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 cont
Returns
a new handle for this computation

Definition at line 381 of file scalarproduct_api.c.

References GNUNET_SCALARPRODUCT_ComputationHandle::cfg, check_unique(), GNUNET_SCALARPRODUCT_ComputationHandle::cont_cls, GNUNET_SCALARPRODUCT_ComputationHandle::cont_datum, AliceComputationMessage::element_count_contained, ComputationBobCryptodataMultipartMessage::element_count_contained, AliceComputationMessage::element_count_total, 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, GNUNET_SCALARPRODUCT_ComputationHandle::key, GNUNET_SCALARPRODUCT_ComputationHandle::mq, mq_error_handler(), msg, AliceComputationMessage::peer, peer, process_result_message(), AliceComputationMessage::reserved, response, GNUNET_SCALARPRODUCT_ComputationHandle::response_proc, AliceComputationMessage::session_key, session_key, and size.

Referenced by run().

388 {
394  struct ClientResponseMessage,
395  h),
397  };
398  struct GNUNET_MQ_Envelope *env;
401  uint32_t size;
402  uint16_t possible;
403  uint16_t todo;
404  uint32_t element_count_transfered;
405 
406  if (GNUNET_SYSERR == check_unique(elements,
407  element_count))
408  return NULL;
409  h->mq = GNUNET_CLIENT_connect(cfg,
410  "scalarproduct-alice",
411  handlers,
413  h);
414  if (NULL == h->mq)
415  {
416  /* missconfigured scalarproduct service */
417  GNUNET_break(0);
418  GNUNET_free(h);
419  return NULL;
420  }
421  h->cont_datum = cont;
422  h->cont_cls = cont_cls;
424  h->cfg = cfg;
425  h->key = *session_key;
426 
427  possible = (GNUNET_MAX_MESSAGE_SIZE - 1 - sizeof(struct AliceComputationMessage))
428  / sizeof(struct GNUNET_SCALARPRODUCT_Element);
429  todo = GNUNET_MIN(possible,
430  element_count);
431  size = todo * sizeof(struct GNUNET_SCALARPRODUCT_Element);
432  env = GNUNET_MQ_msg_extra(msg,
433  size,
435  msg->element_count_total = htonl(element_count);
436  msg->element_count_contained = htonl(todo);
437  msg->reserved = htonl(0);
438  msg->peer = *peer;
439  msg->session_key = *session_key;
440  GNUNET_memcpy(&msg[1],
441  elements,
442  size);
443  GNUNET_MQ_send(h->mq,
444  env);
445  element_count_transfered = todo;
446  possible = (GNUNET_MAX_MESSAGE_SIZE - 1 - sizeof(*mmsg))
447  / sizeof(struct GNUNET_SCALARPRODUCT_Element);
448  while (element_count_transfered < element_count)
449  {
450  todo = GNUNET_MIN(possible,
451  element_count - element_count_transfered);
452  size = todo * sizeof(struct GNUNET_SCALARPRODUCT_Element);
453  env = GNUNET_MQ_msg_extra(mmsg,
454  size,
456  mmsg->element_count_contained = htonl(todo);
457  GNUNET_memcpy(&mmsg[1],
458  &elements[element_count_transfered],
459  size);
460  element_count_transfered += todo;
461  GNUNET_MQ_send(h->mq,
462  env);
463  }
464  return h;
465 }
A handle returned for each computation.
Message type passed from service client to finalize a session as requester or responder.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
#define GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE
Client -> Alice multipart.
struct GNUNET_HashCode key
The shared session key identifying this computation.
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:900
GNUNET_SCALARPRODUCT_DatumProcessor cont_datum
Function to call after transmission of the request (Alice).
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...
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
uint32_t reserved
Always zero.
Definition: scalarproduct.h:62
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Message type passed from client to service to initiate a request or responder role.
Definition: scalarproduct.h:42
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
struct GNUNET_HashCode session_key
the transaction/session key used to identify a session
Definition: scalarproduct.h:67
#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:52
static struct GNUNET_HashCode session_key
the session key identifying this computation
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
struct GNUNET_PeerIdentity peer
the identity of a remote peer we want to communicate with
Definition: scalarproduct.h:72
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MIN(a, b)
Definition: gnunet_common.h:80
uint32_t element_count_total
how many elements the vector in payload contains
Definition: scalarproduct.h:52
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 handler for a specific message type.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
#define GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE
Client -> Alice.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static unsigned int size
Size of the "table".
Definition: peer.c:66
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
uint32_t element_count_contained
contained elements the vector in payload contains
Definition: scalarproduct.h:57
static struct MHD_Response * response
Our canonical response.
uint32_t element_count_contained
contained elements the vector in payload contains
multipart messages following struct ComputationMessage
void * cont_cls
Closure for cont_status or cont_datum.
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:351
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
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.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
static int check_unique(const struct GNUNET_SCALARPRODUCT_Element *elements, uint32_t element_count)
Check if the keys for all given elements are unique.
An element key-value pair for scalarproduct.
#define GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT
Alice/Bob -> Client Result.
#define GNUNET_free(ptr)
Wrapper around free.
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
Parameters
cfgthe gnunet configuration handle
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 cont
Returns
a new handle for this computation

Definition at line 224 of file scalarproduct_api.c.

References GNUNET_SCALARPRODUCT_ComputationHandle::cfg, check_unique(), GNUNET_SCALARPRODUCT_ComputationHandle::cont_cls, GNUNET_SCALARPRODUCT_ComputationHandle::cont_status, BobComputationMessage::element_count_contained, ComputationBobCryptodataMultipartMessage::element_count_contained, BobComputationMessage::element_count_total, 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, GNUNET_SCALARPRODUCT_ComputationHandle::key, GNUNET_SCALARPRODUCT_ComputationHandle::mq, mq_error_handler(), msg, process_status_message(), response, GNUNET_SCALARPRODUCT_ComputationHandle::response_proc, BobComputationMessage::session_key, session_key, and size.

Referenced by run().

230 {
236  struct ClientResponseMessage,
237  h),
239  };
240  struct GNUNET_MQ_Envelope *env;
241  struct BobComputationMessage *msg;
243  uint32_t size;
244  uint16_t possible;
245  uint16_t todo;
246  uint32_t element_count_transfered;
247 
248 
249  if (GNUNET_SYSERR == check_unique(elements,
250  element_count))
251  return NULL;
252  h->cont_status = cont;
253  h->cont_cls = cont_cls;
255  h->cfg = cfg;
256  h->key = *session_key;
257  h->mq = GNUNET_CLIENT_connect(cfg,
258  "scalarproduct-bob",
259  handlers,
261  h);
262  if (NULL == h->mq)
263  {
264  /* scalarproduct configuration error */
265  GNUNET_break(0);
266  GNUNET_free(h);
267  return NULL;
268  }
269  possible = (GNUNET_MAX_MESSAGE_SIZE - 1 - sizeof(struct BobComputationMessage))
270  / sizeof(struct GNUNET_SCALARPRODUCT_Element);
271  todo = GNUNET_MIN(possible,
272  element_count);
273  size = todo * sizeof(struct GNUNET_SCALARPRODUCT_Element);
274  env = GNUNET_MQ_msg_extra(msg,
275  size,
277  msg->element_count_total = htonl(element_count);
278  msg->element_count_contained = htonl(todo);
279  msg->session_key = *session_key;
280  GNUNET_memcpy(&msg[1],
281  elements,
282  size);
283  element_count_transfered = todo;
284  GNUNET_MQ_send(h->mq,
285  env);
286  possible = (GNUNET_MAX_MESSAGE_SIZE - 1 - sizeof(*mmsg))
287  / sizeof(struct GNUNET_SCALARPRODUCT_Element);
288  while (element_count_transfered < element_count)
289  {
290  todo = GNUNET_MIN(possible,
291  element_count - element_count_transfered);
292  size = todo * sizeof(struct GNUNET_SCALARPRODUCT_Element);
293  env = GNUNET_MQ_msg_extra(mmsg,
294  size,
296  mmsg->element_count_contained = htonl(todo);
297  GNUNET_memcpy(&mmsg[1],
298  &elements[element_count_transfered],
299  size);
300  element_count_transfered += todo;
301  GNUNET_MQ_send(h->mq,
302  env);
303  }
304  return h;
305 }
A handle returned for each computation.
Message type passed from service client to finalize a session as requester or responder.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_HashCode key
The shared session key identifying this computation.
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:900
uint32_t element_count_total
how many elements the vector in payload contains
Definition: scalarproduct.h:94
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_BOB
Client -> Bob.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
#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:52
static struct GNUNET_HashCode session_key
the session key identifying this computation
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MIN(a, b)
Definition: gnunet_common.h:80
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 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 handler for a specific message type.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static unsigned int size
Size of the "table".
Definition: peer.c:66
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
GNUNET_SCALARPRODUCT_ContinuationWithStatus cont_status
Function to call after transmission of the request (Bob).
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
uint32_t element_count_contained
contained elements the vector in payload contains
Definition: scalarproduct.h:99
#define GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_BOB
Client -> Bob multipart.
static struct MHD_Response * response
Our canonical response.
uint32_t element_count_contained
contained elements the vector in payload contains
multipart messages following struct ComputationMessage
Message type passed from client to service to initiate a request or responder role.
Definition: scalarproduct.h:84
void * cont_cls
Closure for cont_status or cont_datum.
struct GNUNET_HashCode session_key
the transaction/session key used to identify a session
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:351
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
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.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
static int check_unique(const struct GNUNET_SCALARPRODUCT_Element *elements, uint32_t element_count)
Check if the keys for all given elements are unique.
An element key-value pair for scalarproduct.
#define GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT
Alice/Bob -> Client Result.
#define GNUNET_free(ptr)
Wrapper around free.
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 475 of file scalarproduct_api.c.

References GNUNET_free, GNUNET_MQ_destroy(), and GNUNET_SCALARPRODUCT_ComputationHandle::mq.

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

476 {
477  if (NULL != h->mq)
478  {
479  GNUNET_MQ_destroy(h->mq);
480  h->mq = NULL;
481  }
482  GNUNET_free(h);
483 }
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:821
struct GNUNET_MQ_Handle * mq
Current connection to the scalarproduct service.
#define GNUNET_free(ptr)
Wrapper around free.
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)

Continuation called to notify client about result of the operation.

Parameters
clsclosure
statusStatus of the request

Definition at line 119 of file gnunet_scalarproduct_service.h.