GNUnet  0.10.x
Data Structures | Macros | Functions
credential_api.c File Reference

library to access the CREDENTIAL service More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_constants.h"
#include "gnunet_arm_service.h"
#include "gnunet_hello_lib.h"
#include "gnunet_protocols.h"
#include "gnunet_signatures.h"
#include "credential.h"
#include "credential_serialization.h"
#include "gnunet_credential_service.h"
#include "gnunet_identity_service.h"
Include dependency graph for credential_api.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_CREDENTIAL_Request
 Handle to a verify request. More...
 
struct  GNUNET_CREDENTIAL_Handle
 Connection to the CREDENTIAL service. More...
 

Macros

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

Functions

static void reconnect (struct GNUNET_CREDENTIAL_Handle *handle)
 Reconnect to CREDENTIAL service. More...
 
static void reconnect_task (void *cls)
 Reconnect to CREDENTIAL. More...
 
static void force_reconnect (struct GNUNET_CREDENTIAL_Handle *handle)
 Disconnect from service and then reconnect. More...
 
static void mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
 Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue. More...
 
static int check_result (void *cls, const struct DelegationChainResultMessage *vr_msg)
 Check validity of message received from the CREDENTIAL service. More...
 
static void handle_result (void *cls, const struct DelegationChainResultMessage *vr_msg)
 Handler for messages received from the CREDENTIAL service. More...
 
struct GNUNET_CREDENTIAL_HandleGNUNET_CREDENTIAL_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Initialize the connection with the CREDENTIAL service. More...
 
void GNUNET_CREDENTIAL_disconnect (struct GNUNET_CREDENTIAL_Handle *handle)
 Shutdown connection with the CREDENTIAL service. More...
 
void GNUNET_CREDENTIAL_request_cancel (struct GNUNET_CREDENTIAL_Request *lr)
 Cancel pending verify request. More...
 
struct GNUNET_CREDENTIAL_RequestGNUNET_CREDENTIAL_collect (struct GNUNET_CREDENTIAL_Handle *handle, const struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key, const char *issuer_attribute, const struct GNUNET_CRYPTO_EcdsaPrivateKey *subject_key, GNUNET_CREDENTIAL_CredentialResultProcessor proc, void *proc_cls)
 Performs attribute collection. More...
 
struct GNUNET_CREDENTIAL_RequestGNUNET_CREDENTIAL_verify (struct GNUNET_CREDENTIAL_Handle *handle, const struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key, const char *issuer_attribute, const struct GNUNET_CRYPTO_EcdsaPublicKey *subject_key, uint32_t credential_count, const struct GNUNET_CREDENTIAL_Credential *credentials, GNUNET_CREDENTIAL_CredentialResultProcessor proc, void *proc_cls)
 Performs attribute verification. More...
 

Detailed Description

library to access the CREDENTIAL service

Author
Martin Schanzenbach

Definition in file credential_api.c.

Macro Definition Documentation

◆ LOG

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

Function Documentation

◆ reconnect()

static void reconnect ( struct GNUNET_CREDENTIAL_Handle handle)
static

Reconnect to CREDENTIAL service.

Parameters
handlethe handle to the CREDENTIAL service

Definition at line 268 of file credential_api.c.

References GNUNET_CREDENTIAL_Handle::cfg, GNUNET_CREDENTIAL_Request::env, GNUNET_assert, GNUNET_CLIENT_connect(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_CREDENTIAL_COLLECT_RESULT, GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_MQ_send_copy(), LOG, GNUNET_CREDENTIAL_Handle::mq, mq_error_handler(), GNUNET_CREDENTIAL_Request::next, GNUNET_CREDENTIAL_Handle::request_head, and result.

Referenced by GNUNET_CREDENTIAL_connect(), and reconnect_task().

269 {
274  handle),
278  handle),
280  };
281  struct GNUNET_CREDENTIAL_Request *vr;
282 
283  GNUNET_assert (NULL == handle->mq);
285  "Trying to connect to CREDENTIAL\n");
286  handle->mq = GNUNET_CLIENT_connect (handle->cfg,
287  "credential",
288  handlers,
290  handle);
291  if (NULL == handle->mq)
292  return;
293  for (vr = handle->request_head; NULL != vr; vr = vr->next)
294  GNUNET_MQ_send_copy (handle->mq,
295  vr->env);
296 }
struct GNUNET_CREDENTIAL_Request * request_head
Head of linked list of active verify requests.
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:901
struct GNUNET_CREDENTIAL_Request * next
DLL.
Message from CREDENTIAL service to client: new results.
Definition: credential.h:110
#define GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_MESSAGE_TYPE_CREDENTIAL_COLLECT_RESULT
#define LOG(kind,...)
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
static int result
Global testing status.
struct GNUNET_MQ_Handle * mq
Connection to service (if available).
Message handler for a specific message type.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Handle to a verify request.
void GNUNET_MQ_send_copy(struct GNUNET_MQ_Handle *mq, const struct GNUNET_MQ_Envelope *ev)
Send a copy of a message with the given message queue.
Definition: mq.c:432
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
struct GNUNET_MQ_Envelope * env
Envelope with the message for this queue entry.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reconnect_task()

static void reconnect_task ( void *  cls)
static

Reconnect to CREDENTIAL.

Parameters
clsthe handle

Definition at line 143 of file credential_api.c.

References handle, reconnect(), and GNUNET_CREDENTIAL_Handle::reconnect_task.

Referenced by force_reconnect().

144 {
145  struct GNUNET_CREDENTIAL_Handle *handle = cls;
146 
147  handle->reconnect_task = NULL;
148  reconnect (handle);
149 }
struct GNUNET_SCHEDULER_Task * reconnect_task
Reconnect task.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
Connection to the CREDENTIAL service.
static void reconnect(struct GNUNET_CREDENTIAL_Handle *handle)
Reconnect to CREDENTIAL service.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ force_reconnect()

static void force_reconnect ( struct GNUNET_CREDENTIAL_Handle handle)
static

Disconnect from service and then reconnect.

Parameters
handleour handle

Definition at line 158 of file credential_api.c.

References GNUNET_MQ_destroy(), GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_STD_BACKOFF, GNUNET_CREDENTIAL_Handle::mq, GNUNET_CREDENTIAL_Handle::reconnect_backoff, GNUNET_CREDENTIAL_Handle::reconnect_task, and reconnect_task().

Referenced by mq_error_handler().

159 {
160  GNUNET_MQ_destroy (handle->mq);
161  handle->mq = NULL;
162  handle->reconnect_backoff
164  handle->reconnect_task
167  handle);
168 }
struct GNUNET_SCHEDULER_Task * reconnect_task
Reconnect task.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1246
struct GNUNET_MQ_Handle * mq
Connection to service (if available).
static void reconnect_task(void *cls)
Reconnect to CREDENTIAL.
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
struct GNUNET_TIME_Relative reconnect_backoff
How long do we wait until we try to reconnect?
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
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

Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue.

Not every message queue implementation supports an error handler.

Parameters
clsclosure with the struct GNUNET_CREDENTIAL_Handle *
errorerror code

Definition at line 180 of file credential_api.c.

References force_reconnect(), and handle.

Referenced by reconnect().

182 {
183  struct GNUNET_CREDENTIAL_Handle *handle = cls;
184 
185  force_reconnect (handle);
186 }
static void force_reconnect(struct GNUNET_CREDENTIAL_Handle *handle)
Disconnect from service and then reconnect.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
Connection to the CREDENTIAL service.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_result()

static int check_result ( void *  cls,
const struct DelegationChainResultMessage vr_msg 
)
static

Check validity of message received from the CREDENTIAL service.

Parameters
clsthe struct GNUNET_CREDENTIAL_Handle *
vr_msgthe incoming message

Definition at line 195 of file credential_api.c.

References GNUNET_OK.

197 {
198  //TODO
199  return GNUNET_OK;
200 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78

◆ handle_result()

static void handle_result ( void *  cls,
const struct DelegationChainResultMessage vr_msg 
)
static

Handler for messages received from the CREDENTIAL service.

Parameters
clsthe struct GNUNET_CREDENTIAL_Handle *
vr_msgthe incoming message

Definition at line 210 of file credential_api.c.

References DelegationChainResultMessage::c_count, DelegationChainResultMessage::d_count, GNUNET_CREDENTIAL_Request::env, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_CREDENTIAL_delegation_chain_deserialize(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_MQ_discard(), GNUNET_NO, GNUNET_OK, handle, DelegationChainResultMessage::header, DelegationChainResultMessage::id, LOG, GNUNET_CREDENTIAL_Request::next, GNUNET_CREDENTIAL_Request::proc_cls, GNUNET_CREDENTIAL_Request::r_id, GNUNET_CREDENTIAL_Handle::request_head, GNUNET_CREDENTIAL_Handle::request_tail, GNUNET_MessageHeader::size, and GNUNET_CREDENTIAL_Request::verify_proc.

212 {
213  struct GNUNET_CREDENTIAL_Handle *handle = cls;
214  uint32_t r_id = ntohl (vr_msg->id);
215  struct GNUNET_CREDENTIAL_Request *vr;
216  size_t mlen = ntohs (vr_msg->header.size) - sizeof (*vr_msg);
217  uint32_t d_count = ntohl (vr_msg->d_count);
218  uint32_t c_count = ntohl (vr_msg->c_count);
219  struct GNUNET_CREDENTIAL_Delegation d_chain[d_count];
220  struct GNUNET_CREDENTIAL_Credential creds[c_count];
222  void *proc_cls;
223 
225  "Received verify reply from CREDENTIAL service\n");
226  for (vr = handle->request_head; NULL != vr; vr = vr->next)
227  if (vr->r_id == r_id)
228  break;
229  if (NULL == vr)
230  return;
231  proc = vr->verify_proc;
232  proc_cls = vr->proc_cls;
234  handle->request_tail,
235  vr);
236  GNUNET_MQ_discard (vr->env);
237  GNUNET_free (vr);
240  (const char*) &vr_msg[1],
241  d_count,
242  d_chain,
243  c_count,
244  creds));
245  if (GNUNET_NO == ntohl (vr_msg->cred_found))
246  {
247  proc (proc_cls,
248  0,
249  NULL,
250  0,
251  NULL); // TODO
252  } else {
253  proc (proc_cls,
254  d_count,
255  d_chain,
256  c_count,
257  creds);
258  }
259 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
uint32_t id
Unique identifier for this request (for key collisions).
Definition: credential.h:120
void(* GNUNET_CREDENTIAL_CredentialResultProcessor)(void *cls, unsigned int d_count, struct GNUNET_CREDENTIAL_Delegation *delegation_chain, unsigned int c_count, struct GNUNET_CREDENTIAL_Credential *credential)
Iterator called on obtained result for an attribute verification.
struct GNUNET_CREDENTIAL_Request * request_head
Head of linked list of active verify requests.
struct GNUNET_CREDENTIAL_Request * next
DLL.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_MessageHeader header
Header of type GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT.
Definition: credential.h:115
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
uint32_t r_id
request id
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#define LOG(kind,...)
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
Connection to the CREDENTIAL service.
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
Definition: mq.c:321
Handle to a verify request.
int GNUNET_CREDENTIAL_delegation_chain_deserialize(size_t len, const char *src, unsigned int d_count, struct GNUNET_CREDENTIAL_Delegation *dd, unsigned int c_count, struct GNUNET_CREDENTIAL_Credential *cd)
Deserialize the given destination.
uint32_t cred_found
Indicates if credential has been found at all.
Definition: credential.h:125
GNUNET_CREDENTIAL_CredentialResultProcessor verify_proc
processor to call on verify result
void * proc_cls
verify_proc closure
struct GNUNET_MQ_Envelope * env
Envelope with the message for this queue entry.
struct GNUNET_CREDENTIAL_Request * request_tail
Tail of linked list of active verify requests.
uint32_t d_count
The number of delegations in the response.
Definition: credential.h:130
uint32_t c_count
The number of credentials in the response.
Definition: credential.h:135
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function: