GNUnet 0.21.1
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_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_PublicKey *issuer_key, const char *issuer_attribute, const struct GNUNET_CRYPTO_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_CRYPTO_PublicKey *issuer_key, const char *issuer_attribute, const struct GNUNET_CRYPTO_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 37 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 315 of file abd_api.c.

316{
321 handle),
325 handle),
326 GNUNET_MQ_hd_var_size (intermediate,
329 handle),
331 struct GNUNET_ABD_Request *vr;
332
333 GNUNET_assert (NULL == handle->mq);
334 LOG (GNUNET_ERROR_TYPE_DEBUG, "Trying to connect to ABD\n");
336 "abd",
337 handlers,
339 handle);
340 if (NULL == handle->mq)
341 return;
342 for (vr = handle->request_head; NULL != vr; vr = vr->next)
344}
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
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:187
#define LOG(kind,...)
Definition: abd_api.c:37
static int result
Global testing status.
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Definition: gnunet-vpn.c:35
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:43
struct GNUNET_ABD_Request * next
DLL.
Definition: abd_api.c:48
struct GNUNET_MQ_Envelope * env
Envelope with the message for this queue entry.
Definition: abd_api.c:83
Message handler for a specific message type.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we use.
Definition: vpn_api.c:39
struct GNUNET_MQ_Handle * mq
Connection to VPN service.
Definition: vpn_api.c:44

References GNUNET_VPN_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_VPN_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 150 of file abd_api.c.

151{
152 struct GNUNET_ABD_Handle *handle = cls;
153
154 handle->reconnect_task = NULL;
156}
static void reconnect(struct GNUNET_ABD_Handle *handle)
Reconnect to ABD service.
Definition: abd_api.c:315
Connection to the ABD service.
Definition: abd_api.c:96

References handle, and reconnect().

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 165 of file abd_api.c.

166{
168 handle->mq = NULL;
169 handle->reconnect_backoff =
170 GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff);
171 handle->reconnect_task =
172 GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff,
174 handle);
175}
static void reconnect_task(void *cls)
Reconnect to ABD.
Definition: abd_api.c:150
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:1278
#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_VPN_Handle::mq, and 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 187 of file abd_api.c.

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

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 202 of file abd_api.c.

203{
204 // TODO
205 return GNUNET_OK;
206}
@ 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 216 of file abd_api.c.

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;
238 GNUNET_CONTAINER_DLL_remove (handle->request_head, handle->request_tail, vr);
240 GNUNET_free (vr);
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}
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.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ 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:68
GNUNET_ABD_CredentialResultProcessor verify_proc
processor to call on verify result
Definition: abd_api.c:63
uint32_t r_id
request id
Definition: abd_api.c:88

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 262 of file abd_api.c.

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

References GNUNET_OK.

◆ handle_intermediate()

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

Definition at line 271 of file abd_api.c.

273{
274 struct GNUNET_ABD_Handle *handle = cls;
275 uint32_t r_id = ntohl (vr_msg->id);
276 uint32_t size = ntohl (vr_msg->size);
277 bool is_bw = ntohs (vr_msg->is_bw);
278 struct GNUNET_ABD_Request *vr;
280 void *proc_cls;
281 struct GNUNET_ABD_Delegation *dd;
282
283
285 "Received intermediate reply from ABD service\n");
286
287 for (vr = handle->request_head; NULL != vr; vr = vr->next)
288 if (vr->r_id == r_id)
289 break;
290 if (NULL == vr)
291 return;
292
293 proc = vr->int_proc;
294 proc_cls = vr->proc2_cls;
295
296 dd = GNUNET_new (struct GNUNET_ABD_Delegation);
298 GNUNET_OK ==
300 (const char *) &vr_msg[1],
301 1,
302 dd,
303 0,
304 NULL));
305 proc (proc_cls, dd, is_bw);
306}
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:73
void * proc2_cls
verify_proc2 closure
Definition: abd_api.c:78

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: