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 311 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().

312 {
317  handle),
321  handle),
322  GNUNET_MQ_hd_var_size (intermediate,
325  handle),
327  struct GNUNET_ABD_Request *vr;
328 
329  GNUNET_assert (NULL == handle->mq);
330  LOG (GNUNET_ERROR_TYPE_DEBUG, "Trying to connect to ABD\n");
331  handle->mq = GNUNET_CLIENT_connect (handle->cfg,
332  "abd",
333  handlers,
335  handle);
336  if (NULL == handle->mq)
337  return;
338  for (vr = handle->request_head; NULL != vr; vr = vr->next)
339  GNUNET_MQ_send_copy (handle->mq, vr->env);
340 }
#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:1058
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:311
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 202 of file abd_api.c.

References GNUNET_OK.

203 {
204  //TODO
205  return GNUNET_OK;
206 }
#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 216 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.

217 {
218  struct GNUNET_ABD_Handle *handle = cls;
219  uint32_t r_id = ntohl (vr_msg->id);
220  struct GNUNET_ABD_Request *vr;
221  size_t mlen = ntohs (vr_msg->header.size) - sizeof (*vr_msg);
222  uint32_t d_count = ntohl (vr_msg->d_count);
223  uint32_t c_count = ntohl (vr_msg->c_count);
224  struct GNUNET_ABD_Delegation d_chain[d_count];
225  struct GNUNET_ABD_Delegate dels[c_count];
227  void *proc_cls;
228 
230  "Received verify reply from ABD service\n");
231  for (vr = handle->request_head; NULL != vr; vr = vr->next)
232  if (vr->r_id == r_id)
233  break;
234  if (NULL == vr)
235  return;
236  proc = vr->verify_proc;
237  proc_cls = vr->proc_cls;
239  GNUNET_MQ_discard (vr->env);
240  GNUNET_free (vr);
241  GNUNET_assert (
242  GNUNET_OK ==
244  (const char *) &vr_msg[1],
245  d_count,
246  d_chain,
247  c_count,
248  dels));
249  if (GNUNET_NO == ntohl (vr_msg->del_found))
250  {
251  proc (proc_cls, 0, NULL, 0,
252  NULL);
253  }
254  else
255  {
256  proc (proc_cls, d_count, d_chain, c_count, dels);
257  }
258 }
#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 261 of file abd_api.c.

References GNUNET_OK.

262 {
263  //TODO
264  return GNUNET_OK;
265 }
#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 268 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.

269 {
270  struct GNUNET_ABD_Handle *handle = cls;
271  uint32_t r_id = ntohl (vr_msg->id);
272  uint32_t size = ntohl (vr_msg->size);
273  bool is_bw = ntohs(vr_msg->is_bw);
274  struct GNUNET_ABD_Request *vr;
276  void *proc_cls;
277  struct GNUNET_ABD_Delegation *dd;
278 
279 
280  LOG (GNUNET_ERROR_TYPE_DEBUG, "Received intermediate reply from ABD service\n");
281 
282  for (vr = handle->request_head; NULL != vr; vr = vr->next)
283  if (vr->r_id == r_id)
284  break;
285  if (NULL == vr)
286  return;
287 
288  proc = vr->int_proc;
289  proc_cls = vr->proc2_cls;
290 
291  dd = GNUNET_new (struct GNUNET_ABD_Delegation);
292  GNUNET_assert (
293  GNUNET_OK ==
295  (const char *) &vr_msg[1],
296  1,
297  dd,
298  0,
299  NULL));
300  proc (proc_cls, dd, is_bw);
301 }
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: