GNUnet  0.11.x
Data Structures | Macros | Functions
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_CRYPTO_EcdsaPublicKey *issuer_key, const char *issuer_attribute, const struct GNUNET_CRYPTO_EcdsaPrivateKey *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_CRYPTO_EcdsaPublicKey *issuer_key, const char *issuer_attribute, const struct GNUNET_CRYPTO_EcdsaPublicKey *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.

Referenced by check_access(), client_disconnect_cb(), client_message_tokenizer_callback(), connect_error(), connect_fail_continuation(), connect_success_continuation(), create_macendpoint(), create_session(), detach_terminal(), GNUNET_ABD_collect(), GNUNET_ABD_verify(), GNUNET_CONNECTION_connect_socket(), GNUNET_CONNECTION_create_from_accept(), GNUNET_CONNECTION_destroy(), GNUNET_CONNECTION_notify_transmit_ready(), GNUNET_SERVER_client_disconnect(), GNUNET_SERVER_destroy(), GNUNET_SERVER_inject(), GNUNET_SERVER_mst_receive(), GNUNET_SERVER_receive_done(), GNUNET_SERVER_stop_listening(), GST_forwarded_operation_timeout(), GST_queue_host_registration(), handle_helper_message(), handle_intermediate(), handle_manage_peer_service(), handle_peer_create(), handle_peer_destroy(), handle_peer_reconfigure(), handle_peer_start(), handle_peer_stop(), handle_result(), hr_completion(), LEGACY_SERVICE_get_server_addresses(), LEGACY_SERVICE_run(), LIBGNUNET_PLUGIN_TRANSPORT_INIT(), open_listen_socket(), parse_shared_services(), process_acl4(), process_acl6(), process_data(), process_incoming(), process_listen_socket(), process_mst(), process_notify(), receive_ready(), reconnect(), register_next_host(), restart_processing(), send_ack(), send_hello_beacon(), service_task(), set_user_id(), setup_service(), signal_receive_error(), signal_receive_timeout(), signal_transmit_error(), transmit_fragment(), transmit_ready(), transmit_timeout(), try_connect_using_address(), warn_no_receive_done(), wlan_plugin_address_suggested(), wlan_plugin_get_session(), and wlan_plugin_send().

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.

References GNUNET_ABD_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(), LOG, GNUNET_ABD_Handle::mq, mq_error_handler(), GNUNET_ABD_Request::next, GNUNET_ABD_Handle::request_head, and result.

Referenced by GNUNET_ABD_connect(), iopen(), and reconnect_task().

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");
336  handle->mq = GNUNET_CLIENT_connect (handle->cfg,
337  "abd",
338  handlers,
340  handle);
341  if (NULL == handle->mq)
342  return;
343  for (vr = handle->request_head; NULL != vr; vr = vr->next)
344  GNUNET_MQ_send_copy (handle->mq, vr->env);
345 }
#define GNUNET_MESSAGE_TYPE_ABD_INTERMEDIATE_RESULT
struct GNUNET_ABD_Request * request_head
Head of linked list of active verify requests.
Definition: abd_api.c:112
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
Message from ABD service to client: new results.
Definition: abd.h:118
#define LOG(kind,...)
Definition: abd_api.c:38
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition: abd_api.c:102
Handle to a verify request.
Definition: abd_api.c:43
Message from ABD service to client: new results.
Definition: abd.h:151
struct GNUNET_MQ_Handle * mq
Connection to service (if available).
Definition: abd_api.c:107
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
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
static int result
Global testing status.
struct GNUNET_ABD_Request * next
DLL.
Definition: abd_api.c:49
Message handler for a specific message type.
#define GNUNET_MESSAGE_TYPE_ABD_VERIFY_RESULT
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
struct GNUNET_MQ_Envelope * env
Envelope with the message for this queue entry.
Definition: abd_api.c:84
#define GNUNET_MESSAGE_TYPE_ABD_COLLECT_RESULT
#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 ABD.

Parameters
clsthe handle

Definition at line 151 of file abd_api.c.

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

Referenced by force_reconnect().

152 {
153  struct GNUNET_ABD_Handle *handle = cls;
154 
155  handle->reconnect_task = NULL;
156  reconnect (handle);
157 }
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
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:96
struct GNUNET_SCHEDULER_Task * reconnect_task
Reconnect task.
Definition: abd_api.c:122
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.

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

Referenced by mq_error_handler().

167 {
168  GNUNET_MQ_destroy (handle->mq);
169  handle->mq = NULL;
170  handle->reconnect_backoff =
172  handle->reconnect_task =
175  handle);
176 }
struct GNUNET_TIME_Relative reconnect_backoff
How long do we wait until we try to reconnect?
Definition: abd_api.c:127
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:1253
struct GNUNET_MQ_Handle * mq
Connection to service (if available).
Definition: abd_api.c:107
static void reconnect_task(void *cls)
Reconnect to ABD.
Definition: abd_api.c:151
#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_SCHEDULER_Task * reconnect_task
Reconnect task.
Definition: abd_api.c:122
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_ABD_Handle *
errorerror code

Definition at line 188 of file abd_api.c.

References force_reconnect(), and handle.

Referenced by reconnect().

189 {
190  struct GNUNET_ABD_Handle *handle = cls;
191 
192  force_reconnect (handle);
193 }
static void force_reconnect(struct GNUNET_ABD_Handle *handle)
Disconnect from service and then reconnect.
Definition: abd_api.c:166
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
Connection to the ABD service.
Definition: abd_api.c:96
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.

References GNUNET_OK.

204 {
205  // TODO
206  return GNUNET_OK;
207 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75

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

References DelegationChainResultMessage::c_count, DelegationChainResultMessage::d_count, 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_ABD_Handle::request_head, GNUNET_ABD_Handle::request_tail, GNUNET_MessageHeader::size, and GNUNET_ABD_Request::verify_proc.

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;
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 }
#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: abd.h:128
struct GNUNET_ABD_Request * request_head
Head of linked list of active verify requests.
Definition: abd_api.c:112
#define LOG(kind,...)
Definition: abd_api.c:38
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_MessageHeader header
Header of type GNUNET_MESSAGE_TYPE_ABD_VERIFY_RESULT.
Definition: abd.h:123
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
Handle to a verify request.
Definition: abd_api.c:43
void * proc_cls
verify_proc closure
Definition: abd_api.c:69
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.
GNUNET_ABD_CredentialResultProcessor verify_proc
processor to call on verify result
Definition: abd_api.c:64
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
struct GNUNET_ABD_Request * next
DLL.
Definition: abd_api.c:49
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_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
Definition: mq.c:321
Connection to the ABD service.
Definition: abd_api.c:96
struct GNUNET_ABD_Request * request_tail
Tail of linked list of active verify requests.
Definition: abd_api.c:117
uint32_t del_found
Indicates if credential has been found at all.
Definition: abd.h:133
struct GNUNET_MQ_Envelope * env
Envelope with the message for this queue entry.
Definition: abd_api.c:84
uint32_t d_count
The number of delegations in the response.
Definition: abd.h:138
uint32_t c_count
The number of credentials in the response.
Definition: abd.h:143
uint32_t r_id
request id
Definition: abd_api.c:89
#define GNUNET_free(ptr)
Wrapper around free.
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.

References GNUNET_OK.

265 {
266  // TODO
267  return GNUNET_OK;
268 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75

◆ handle_intermediate()

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

Definition at line 272 of file abd_api.c.

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, GNUNET_ABD_Handle::request_head, size, and DelegationChainIntermediateMessage::size.

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 }
struct GNUNET_ABD_Request * request_head
Head of linked list of active verify requests.
Definition: abd_api.c:112
void(* GNUNET_ABD_IntermediateResultProcessor)(void *cls, struct GNUNET_ABD_Delegation *delegation, bool is_bw)
uint32_t id
Unique identifier for this request (for key collisions).
Definition: abd.h:161
#define LOG(kind,...)
Definition: abd_api.c:38
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void * proc2_cls
verify_proc2 closure
Definition: abd_api.c:79
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
GNUNET_ABD_IntermediateResultProcessor int_proc
processor to call on intermediate result
Definition: abd_api.c:74
Handle to a verify request.
Definition: abd_api.c:43
void * proc_cls
verify_proc closure
Definition: abd_api.c:69
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
struct GNUNET_ABD_Request * next
DLL.
Definition: abd_api.c:49
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.
Connection to the ABD service.
Definition: abd_api.c:96
static unsigned int size
Size of the "table".
Definition: peer.c:67
uint32_t r_id
request id
Definition: abd_api.c:89
Here is the call graph for this function: