GNUnet 0.22.2
scalarproduct_api.c File Reference

API for the scalarproduct. More...

Include dependency graph for scalarproduct_api.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_SCALARPRODUCT_ComputationHandle
 A handle returned for each computation. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "scalarproduct-api", __VA_ARGS__)
 

Typedefs

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

Functions

static int check_response (void *cls, const struct ClientResponseMessage *message)
 Called when a response is received from the service. More...
 
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. More...
 
static void handle_response (void *cls, const struct ClientResponseMessage *message)
 Called when a response is received from the service. More...
 
static int check_unique (const struct GNUNET_SCALARPRODUCT_Element *elements, uint32_t element_count)
 Check if the keys for all given elements are unique. More...
 
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. 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...
 
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. More...
 
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...
 
void GNUNET_SCALARPRODUCT_cancel (struct GNUNET_SCALARPRODUCT_ComputationHandle *h)
 Cancel an ongoing computation or revoke our collaboration offer. More...
 

Detailed Description

API for the scalarproduct.

Author
Christian Fuchs
Gaurav Kukreja
Christian Grothoff

Definition in file scalarproduct_api.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "scalarproduct-api", __VA_ARGS__)

Definition at line 34 of file scalarproduct_api.c.

Typedef Documentation

◆ GNUNET_SCALARPRODUCT_ResponseMessageHandler

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

Parameters
hcomputation handle
msgresponse we got, NULL on errors
statusprocessing status code

Definition at line 44 of file scalarproduct_api.c.

Function Documentation

◆ check_response()

static int check_response ( void *  cls,
const struct ClientResponseMessage message 
)
static

Called when a response is received from the service.

Perform basic check that the message is well-formed.

Parameters
clsPointer to the Master Context
messagePointer to the data received in response
Returns
GNUNET_OK if message is well-formed

Definition at line 103 of file scalarproduct_api.c.

105{
106 if (ntohs (message->header.size) !=
107 ntohl (message->product_length) + sizeof(struct ClientResponseMessage))
108 {
109 GNUNET_break (0);
110 return GNUNET_SYSERR;
111 }
112 return GNUNET_OK;
113}
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_OK
@ GNUNET_SYSERR
#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 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.

References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, ClientResponseMessage::header, ClientResponseMessage::product_length, and GNUNET_MessageHeader::size.

◆ process_status_message()

static void process_status_message ( struct GNUNET_SCALARPRODUCT_ComputationHandle h,
const struct ClientResponseMessage msg,
enum GNUNET_SCALARPRODUCT_ResponseStatus  status 
)
static

Handles the STATUS received from the service for a response, does not contain a payload.

Called when we participate as "Bob" via GNUNET_SCALARPRODUCT_accept_computation().

Parameters
hour Handle
msgthe response received
statusthe condition the request was terminated with (eg: disconnect)

Definition at line 126 of file scalarproduct_api.c.

129{
130 if (NULL != h->cont_status)
131 h->cont_status (h->cont_cls,
132 status);
134}
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:98
static int status
The program status; 0 for success.
Definition: gnunet-nse.c:39
void GNUNET_SCALARPRODUCT_cancel(struct GNUNET_SCALARPRODUCT_ComputationHandle *h)
Cancel an ongoing computation or revoke our collaboration offer.

References GNUNET_SCALARPRODUCT_cancel(), h, and status.

Referenced by GNUNET_SCALARPRODUCT_accept_computation().

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

◆ handle_response()

static void handle_response ( void *  cls,
const struct ClientResponseMessage message 
)
static

Called when a response is received from the service.

After basic check, the handler in h->response_proc is called. This functions handles the response to the client which used the API.

Parameters
clsPointer to the Master Context
messagePointer to the data received in response

Definition at line 146 of file scalarproduct_api.c.

148{
151
152 status = ntohl (message->status);
153 h->response_proc (h,
154 message,
155 status);
156}
GNUNET_SCALARPRODUCT_ResponseStatus
Result status values for the computation.
uint32_t status
Status information about the outcome of this session, An enum GNUNET_SCALARPRODUCT_ResponseStatus (in...
A handle returned for each computation.

References h, status, and ClientResponseMessage::status.

◆ check_unique()

static int check_unique ( const struct GNUNET_SCALARPRODUCT_Element elements,
uint32_t  element_count 
)
static

Check if the keys for all given elements are unique.

Parameters
elementselements to check
element_countsize of the elements array
Returns
GNUNET_OK if all keys are unique

Definition at line 167 of file scalarproduct_api.c.

169{
171 int ok;
172
173 ok = GNUNET_OK;
174 map = GNUNET_CONTAINER_multihashmap_create (2 * element_count,
175 GNUNET_YES);
176 for (uint32_t i = 0; i < element_count; i++)
177 if (GNUNET_OK !=
179 &elements[i].key,
180 map,
182 {
184 _ ("Keys given to SCALARPRODUCT not unique!\n"));
185 ok = GNUNET_SYSERR;
186 }
188 return ok;
189}
struct GNUNET_HashCode key
The key used in the DHT.
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,...)
@ GNUNET_YES
@ GNUNET_ERROR_TYPE_ERROR
static struct GNUNET_CONTAINER_MultiPeerMap * map
Peermap of PeerIdentities to "struct PeerEntry" (for fast lookup).
Definition: peer.c:63
#define _(String)
GNU gettext support macro.
Definition: platform.h:179
Internal representation of the hash map.

References _, GNUNET_CONTAINER_multihashmap_create(), GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, key, and map.

Referenced by GNUNET_SCALARPRODUCT_accept_computation(), and GNUNET_SCALARPRODUCT_start_computation().

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

◆ mq_error_handler()

static void mq_error_handler ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

We encountered an error communicating with the set service while performing a set operation.

Report to the application.

Parameters
clsthe struct GNUNET_SCALARPRODUCT_ComputationHandle
errorerror code

Definition at line 200 of file scalarproduct_api.c.

202{
204
206 "Disconnected from SCALARPRODUCT service.\n");
207 h->response_proc (h,
208 NULL,
210}
@ GNUNET_ERROR_TYPE_INFO
@ GNUNET_SCALARPRODUCT_STATUS_DISCONNECTED
We got disconnected from the SCALARPRODUCT service.
#define LOG(kind,...)

References GNUNET_ERROR_TYPE_INFO, GNUNET_SCALARPRODUCT_STATUS_DISCONNECTED, h, and LOG.

Referenced by GNUNET_SCALARPRODUCT_accept_computation(), and GNUNET_SCALARPRODUCT_start_computation().

Here is the caller graph for this function:

◆ process_result_message()

static void process_result_message ( struct GNUNET_SCALARPRODUCT_ComputationHandle h,
const struct ClientResponseMessage msg,
enum GNUNET_SCALARPRODUCT_ResponseStatus  status 
)
static

Handles the RESULT received from the service for a request, should contain a result MPI value.

Called when we participate as "Alice" via GNUNET_SCALARPRODUCT_start_computation().

Parameters
hour Handle
msgPointer to the response received
statusthe condition the request was terminated with (eg: disconnect)

Definition at line 310 of file scalarproduct_api.c.

313{
314 uint32_t product_len;
315 gcry_mpi_t result = NULL;
316 gcry_error_t rc;
317 gcry_mpi_t num;
318 size_t rsize;
319
321 {
322 result = gcry_mpi_new (0);
323
324 product_len = ntohl (msg->product_length);
325 if (0 < product_len)
326 {
327 rsize = 0;
328 if (0 != (rc = gcry_mpi_scan (&num, GCRYMPI_FMT_STD,
329 &msg[1],
330 product_len,
331 &rsize)))
332 {
334 "gcry_mpi_scan",
335 rc);
336 gcry_mpi_release (result);
337 result = NULL;
339 }
340 else
341 {
342 if (0 < (int32_t) ntohl (msg->range))
343 gcry_mpi_add (result, result, num);
344 else
345 gcry_mpi_sub (result, result, num);
346 gcry_mpi_release (num);
347 }
348 }
349 }
350 if (NULL != h->cont_datum)
351 h->cont_datum (h->cont_cls,
352 status,
353 result);
354 if (NULL != result)
355 gcry_mpi_release (result);
357}
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static int result
Global testing status.
@ GNUNET_SCALARPRODUCT_STATUS_SUCCESS
The computation was successful.
@ GNUNET_SCALARPRODUCT_STATUS_INVALID_RESPONSE
We got an invalid response.
#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...
Definition: scalarproduct.h:35

References GNUNET_ERROR_TYPE_ERROR, GNUNET_SCALARPRODUCT_cancel(), GNUNET_SCALARPRODUCT_STATUS_INVALID_RESPONSE, GNUNET_SCALARPRODUCT_STATUS_SUCCESS, h, LOG_GCRY, msg, result, and status.

Referenced by GNUNET_SCALARPRODUCT_start_computation().

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