GNUnet  0.20.0
abd_api.c File Reference

library to access the ABD 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 "abd.h"
#include "abd_serialization.h"
#include "gnunet_abd_service.h"
#include "gnunet_identity_service.h"
Include dependency graph for abd_api.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_ABD_Request
 Handle to a verify request. More...
 
struct  GNUNET_ABD_Handle
 Connection to the ABD service. More...
 

Macros

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

Functions

static void reconnect (struct GNUNET_ABD_Handle *handle)
 Reconnect to ABD service. More...
 
static void reconnect_task (void *cls)
 Reconnect to ABD. More...
 
static void force_reconnect (struct GNUNET_ABD_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 ABD service. More...
 
static void handle_result (void *cls, const struct DelegationChainResultMessage *vr_msg)
 Handler for messages received from the ABD service. More...
 
static int check_intermediate (void *cls, const struct DelegationChainIntermediateMessage *vr_msg)
 
static void handle_intermediate (void *cls, const struct DelegationChainIntermediateMessage *vr_msg)
 
struct GNUNET_ABD_HandleGNUNET_ABD_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Initialize the connection with the ABD service. More...
 
void GNUNET_ABD_disconnect (struct GNUNET_ABD_Handle *handle)
 Shutdown connection with the ABD service. More...
 
void GNUNET_ABD_request_cancel (struct GNUNET_ABD_Request *lr)
 Cancel pending verify request. More...
 
struct GNUNET_ABD_RequestGNUNET_ABD_collect (struct GNUNET_ABD_Handle *handle, const struct GNUNET_IDENTITY_PublicKey *issuer_key, const char *issuer_attribute, const struct GNUNET_IDENTITY_PrivateKey *subject_key, enum GNUNET_ABD_AlgoDirectionFlags direction, GNUNET_ABD_CredentialResultProcessor proc, void *proc_cls, GNUNET_ABD_IntermediateResultProcessor proc2, void *proc2_cls)
 Performs attribute collection. More...
 
struct GNUNET_ABD_RequestGNUNET_ABD_verify (struct GNUNET_ABD_Handle *handle, const struct GNUNET_IDENTITY_PublicKey *issuer_key, const char *issuer_attribute, const struct GNUNET_IDENTITY_PublicKey *subject_key, uint32_t delegate_count, const struct GNUNET_ABD_Delegate *delegates, enum GNUNET_ABD_AlgoDirectionFlags direction, GNUNET_ABD_CredentialResultProcessor proc, void *proc_cls, GNUNET_ABD_IntermediateResultProcessor proc2, void *proc2_cls)
 Performs attribute verification. More...
 

Detailed Description

library to access the ABD service

Author
Martin Schanzenbach

Definition in file abd_api.c.

Macro Definition Documentation

◆ LOG

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

Definition at line 38 of file abd_api.c.

Function Documentation

◆ reconnect()

static void reconnect ( struct GNUNET_ABD_Handle handle)
static

Reconnect to ABD service.

Parameters
handlethe handle to the ABD service

Definition at line 316 of file abd_api.c.

317 {
322  handle),
326  handle),
327  GNUNET_MQ_hd_var_size (intermediate,
330  handle),
332  struct GNUNET_ABD_Request *vr;
333 
334  GNUNET_assert (NULL == handle->mq);
335  LOG (GNUNET_ERROR_TYPE_DEBUG, "Trying to connect to ABD\n");
337  "abd",
338  handlers,
340  handle);
341  if (NULL == handle->mq)
342  return;
343  for (vr = handle->request_head; NULL != vr; vr = vr->next)
345 }
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...
Definition: abd_api.c:188
#define LOG(kind,...)
Definition: abd_api.c:38
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static int result
Global testing status.
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_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_DEBUG
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:370
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_ABD_COLLECT_RESULT
#define GNUNET_MESSAGE_TYPE_ABD_VERIFY_RESULT
#define GNUNET_MESSAGE_TYPE_ABD_INTERMEDIATE_RESULT
Message from ABD service to client: new results.
Definition: abd.h:152
Message from ABD service to client: new results.
Definition: abd.h:119
Handle to a verify request.
Definition: abd_api.c:44
struct GNUNET_ABD_Request * next
DLL.
Definition: abd_api.c:49
struct GNUNET_MQ_Envelope * env
Envelope with the message for this queue entry.
Definition: abd_api.c:84
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition: dns_api.c:66
struct GNUNET_MQ_Handle * mq
Connection to DNS service, or NULL.
Definition: dns_api.c:61
Message handler for a specific message type.

References GNUNET_DNS_Handle::cfg, GNUNET_ABD_Request::env, GNUNET_assert, GNUNET_CLIENT_connect(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_ABD_COLLECT_RESULT, GNUNET_MESSAGE_TYPE_ABD_INTERMEDIATE_RESULT, GNUNET_MESSAGE_TYPE_ABD_VERIFY_RESULT, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_MQ_send_copy(), handle, handlers, LOG, GNUNET_DNS_Handle::mq, mq_error_handler(), GNUNET_ABD_Request::next, and result.

Referenced by GNUNET_ABD_connect(), and reconnect_task().

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

Parameters
clsthe handle

Definition at line 151 of file abd_api.c.

152 {
153  struct GNUNET_ABD_Handle *handle = cls;
154 
155  handle->reconnect_task = NULL;
156  reconnect (handle);
157 }
static void reconnect(struct GNUNET_ABD_Handle *handle)
Reconnect to ABD service.
Definition: abd_api.c:316
Connection to the ABD service.
Definition: abd_api.c:97
struct GNUNET_SCHEDULER_Task * reconnect_task
Task to reconnect to the service.
Definition: dns_api.c:81

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

Referenced by force_reconnect().

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

◆ force_reconnect()

static void force_reconnect ( struct GNUNET_ABD_Handle handle)
static

Disconnect from service and then reconnect.

Parameters
handleour handle

Definition at line 166 of file abd_api.c.

167 {
169  handle->mq = NULL;
170  handle->reconnect_backoff =
171  GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff);
173  GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff,
175  handle);
176 }
static void reconnect_task(void *cls)
Reconnect to ABD.
Definition: abd_api.c:151
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:683
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:1272
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...

References GNUNET_MQ_destroy(), GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_STD_BACKOFF, handle, GNUNET_DNS_Handle::mq, reconnect_task(), and GNUNET_DNS_Handle::reconnect_task.

Referenced by mq_error_handler().

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_ABD_Handle *
errorerror code

Definition at line 188 of file abd_api.c.

189 {
190  struct GNUNET_ABD_Handle *handle = cls;
191 
193 }
static void force_reconnect(struct GNUNET_ABD_Handle *handle)
Disconnect from service and then reconnect.
Definition: abd_api.c:166

References force_reconnect(), and handle.

Referenced by reconnect().

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 ABD service.

Parameters
clsthe struct GNUNET_ABD_Handle *
vr_msgthe incoming message

Definition at line 203 of file abd_api.c.

204 {
205  // TODO
206  return GNUNET_OK;
207 }
@ GNUNET_OK

References GNUNET_OK.

◆ handle_result()

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

Handler for messages received from the ABD service.

Parameters
clsthe struct GNUNET_ABD_Handle *
vr_msgthe incoming message

Definition at line 217 of file abd_api.c.

218 {
219  struct GNUNET_ABD_Handle *handle = cls;
220  uint32_t r_id = ntohl (vr_msg->id);
221  struct GNUNET_ABD_Request *vr;
222  size_t mlen = ntohs (vr_msg->header.size) - sizeof (*vr_msg);
223  uint32_t d_count = ntohl (vr_msg->d_count);
224  uint32_t c_count = ntohl (vr_msg->c_count);
225  struct GNUNET_ABD_Delegation d_chain[d_count];
226  struct GNUNET_ABD_Delegate dels[c_count];
228  void *proc_cls;
229 
231  "Received verify reply from ABD service\n");
232  for (vr = handle->request_head; NULL != vr; vr = vr->next)
233  if (vr->r_id == r_id)
234  break;
235  if (NULL == vr)
236  return;
237  proc = vr->verify_proc;
238  proc_cls = vr->proc_cls;
239  GNUNET_CONTAINER_DLL_remove (handle->request_head, handle->request_tail, vr);
240  GNUNET_MQ_discard (vr->env);
241  GNUNET_free (vr);
242  GNUNET_assert (
243  GNUNET_OK ==
245  (const char *) &vr_msg[1],
246  d_count,
247  d_chain,
248  c_count,
249  dels));
250  if (GNUNET_NO == ntohl (vr_msg->del_found))
251  {
252  proc (proc_cls, 0, NULL, 0,
253  NULL);
254  }
255  else
256  {
257  proc (proc_cls, d_count, d_chain, c_count, dels);
258  }
259 }
int GNUNET_ABD_delegation_chain_deserialize(size_t len, const char *src, unsigned int d_count, struct GNUNET_ABD_Delegation *dd, unsigned int c_count, struct GNUNET_ABD_Delegate *cd)
Deserialize the given destination.
void(* GNUNET_ABD_CredentialResultProcessor)(void *cls, unsigned int d_count, struct GNUNET_ABD_Delegation *delegation_chain, unsigned int c_count, struct GNUNET_ABD_Delegate *delegte)
Iterator called on obtained result for an attribute verification.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
@ GNUNET_NO
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
Definition: mq.c:285
uint32_t del_found
Indicates if credential has been found at all.
Definition: abd.h:133
struct GNUNET_MessageHeader header
Header of type GNUNET_MESSAGE_TYPE_ABD_VERIFY_RESULT.
Definition: abd.h:123
uint32_t d_count
The number of delegations in the response.
Definition: abd.h:138
uint32_t id
Unique identifier for this request (for key collisions).
Definition: abd.h:128
uint32_t c_count
The number of credentials in the response.
Definition: abd.h:143
void * proc_cls
verify_proc closure
Definition: abd_api.c:69
GNUNET_ABD_CredentialResultProcessor verify_proc
processor to call on verify result
Definition: abd_api.c:64
uint32_t r_id
request id
Definition: abd_api.c:89
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.

References DelegationChainResultMessage::c_count, DelegationChainResultMessage::d_count, DelegationChainResultMessage::del_found, GNUNET_ABD_Request::env, GNUNET_ABD_delegation_chain_deserialize(), GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_MQ_discard(), GNUNET_NO, GNUNET_OK, handle, DelegationChainResultMessage::header, DelegationChainResultMessage::id, LOG, GNUNET_ABD_Request::next, GNUNET_ABD_Request::proc_cls, GNUNET_ABD_Request::r_id, GNUNET_MessageHeader::size, and GNUNET_ABD_Request::verify_proc.

Here is the call graph for this function:

◆ check_intermediate()

static int check_intermediate ( void *  cls,
const struct DelegationChainIntermediateMessage vr_msg 
)
static

Definition at line 263 of file abd_api.c.

265 {
266  // TODO
267  return GNUNET_OK;
268 }

References GNUNET_OK.

◆ handle_intermediate()

static void handle_intermediate ( void *  cls,
const struct DelegationChainIntermediateMessage vr_msg 
)
static

Definition at line 272 of file abd_api.c.

274 {
275  struct GNUNET_ABD_Handle *handle = cls;
276  uint32_t r_id = ntohl (vr_msg->id);
277  uint32_t size = ntohl (vr_msg->size);
278  bool is_bw = ntohs (vr_msg->is_bw);
279  struct GNUNET_ABD_Request *vr;
281  void *proc_cls;
282  struct GNUNET_ABD_Delegation *dd;
283 
284 
286  "Received intermediate reply from ABD service\n");
287 
288  for (vr = handle->request_head; NULL != vr; vr = vr->next)
289  if (vr->r_id == r_id)
290  break;
291  if (NULL == vr)
292  return;
293 
294  proc = vr->int_proc;
295  proc_cls = vr->proc2_cls;
296 
297  dd = GNUNET_new (struct GNUNET_ABD_Delegation);
298  GNUNET_assert (
299  GNUNET_OK ==
301  (const char *) &vr_msg[1],
302  1,
303  dd,
304  0,
305  NULL));
306  proc (proc_cls, dd, is_bw);
307 }
void(* GNUNET_ABD_IntermediateResultProcessor)(void *cls, struct GNUNET_ABD_Delegation *delegation, bool is_bw)
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static unsigned int size
Size of the "table".
Definition: peer.c:68
uint32_t id
Unique identifier for this request (for key collisions).
Definition: abd.h:161
GNUNET_ABD_IntermediateResultProcessor int_proc
processor to call on intermediate result
Definition: abd_api.c:74
void * proc2_cls
verify_proc2 closure
Definition: abd_api.c:79

References GNUNET_ABD_delegation_chain_deserialize(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_new, GNUNET_OK, handle, DelegationChainIntermediateMessage::id, GNUNET_ABD_Request::int_proc, DelegationChainIntermediateMessage::is_bw, LOG, GNUNET_ABD_Request::next, GNUNET_ABD_Request::proc2_cls, GNUNET_ABD_Request::proc_cls, GNUNET_ABD_Request::r_id, DelegationChainIntermediateMessage::size, and size.

Here is the call graph for this function: