GNUnet  0.11.x
Data Structures | Macros | Functions
identity_api.c File Reference

api to interact with the identity service More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_constants.h"
#include "gnunet_protocols.h"
#include "gnunet_identity_service.h"
#include "identity.h"
Include dependency graph for identity_api.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_IDENTITY_Operation
 Handle for an operation with the identity service. More...
 
struct  GNUNET_IDENTITY_Handle
 Handle for the service. More...
 

Macros

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

Functions

const struct GNUNET_IDENTITY_EgoGNUNET_IDENTITY_ego_get_anonymous ()
 Obtain the ego representing 'anonymous' users. More...
 
static void reconnect (void *cls)
 Try again to connect to the identity service. More...
 
static int free_ego (void *cls, const struct GNUNET_HashCode *key, void *value)
 Free ego from hash map. More...
 
static void reschedule_connect (struct GNUNET_IDENTITY_Handle *h)
 Reschedule a connect attempt to the service. 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_identity_result_code (void *cls, const struct ResultCodeMessage *rcm)
 We received a result code from the service. More...
 
static void handle_identity_result_code (void *cls, const struct ResultCodeMessage *rcm)
 We received a result code from the service. More...
 
static int check_identity_update (void *cls, const struct UpdateMessage *um)
 Check validity of identity update message. More...
 
static void handle_identity_update (void *cls, const struct UpdateMessage *um)
 Handle identity update message. More...
 
static int check_identity_set_default (void *cls, const struct SetDefaultMessage *sdm)
 Function called when we receive a set default message from the service. More...
 
static void handle_identity_set_default (void *cls, const struct SetDefaultMessage *sdm)
 Type of a function to call when we receive a message from the service. More...
 
struct GNUNET_IDENTITY_HandleGNUNET_IDENTITY_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_IDENTITY_Callback cb, void *cb_cls)
 Connect to the identity service. More...
 
const struct GNUNET_CRYPTO_EcdsaPrivateKeyGNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego)
 Obtain the ECC key associated with a ego. More...
 
void GNUNET_IDENTITY_ego_get_public_key (const struct GNUNET_IDENTITY_Ego *ego, struct GNUNET_CRYPTO_EcdsaPublicKey *pk)
 Get the identifier (public key) of an ego. More...
 
struct GNUNET_IDENTITY_OperationGNUNET_IDENTITY_get (struct GNUNET_IDENTITY_Handle *h, const char *service_name, GNUNET_IDENTITY_Callback cb, void *cb_cls)
 Obtain the identity that is currently preferred/default for a service. More...
 
struct GNUNET_IDENTITY_OperationGNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *h, const char *service_name, struct GNUNET_IDENTITY_Ego *ego, GNUNET_IDENTITY_Continuation cont, void *cont_cls)
 Set the preferred/default identity for a service. More...
 
struct GNUNET_IDENTITY_OperationGNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h, const char *name, GNUNET_IDENTITY_CreateContinuation cont, void *cont_cls)
 Create a new identity with the given name. More...
 
struct GNUNET_IDENTITY_OperationGNUNET_IDENTITY_rename (struct GNUNET_IDENTITY_Handle *h, const char *old_name, const char *new_name, GNUNET_IDENTITY_Continuation cb, void *cb_cls)
 Renames an existing identity. More...
 
struct GNUNET_IDENTITY_OperationGNUNET_IDENTITY_delete (struct GNUNET_IDENTITY_Handle *h, const char *name, GNUNET_IDENTITY_Continuation cb, void *cb_cls)
 Delete an existing identity. More...
 
void GNUNET_IDENTITY_cancel (struct GNUNET_IDENTITY_Operation *op)
 Cancel an identity operation. More...
 
void GNUNET_IDENTITY_disconnect (struct GNUNET_IDENTITY_Handle *h)
 Disconnect from identity service. More...
 

Detailed Description

api to interact with the identity service

Author
Christian Grothoff

Definition in file identity_api.c.

Macro Definition Documentation

◆ LOG

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

Definition at line 33 of file identity_api.c.

Referenced by reconnect(), and reschedule_connect().

Function Documentation

◆ reconnect()

static void reconnect ( void *  cls)
static

Try again to connect to the identity service.

Parameters
clshandle to the identity service.

Definition at line 483 of file identity_api.c.

References GNUNET_IDENTITY_Handle::cb, GNUNET_IDENTITY_Handle::cfg, GNUNET_IDENTITY_Operation::cls, env, GNUNET_assert, GNUNET_CLIENT_connect(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE, GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT, GNUNET_MESSAGE_TYPE_IDENTITY_START, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_IDENTITY_Operation::h, LOG, GNUNET_IDENTITY_Handle::mq, mq_error_handler(), GNUNET_IDENTITY_Operation::msg, and GNUNET_IDENTITY_Handle::reconnect_task.

Referenced by GNUNET_IDENTITY_connect(), GNUNET_IDENTITY_ego_get_anonymous(), and reschedule_connect().

484 {
485  struct GNUNET_IDENTITY_Handle *h = cls;
487  { GNUNET_MQ_hd_var_size (identity_result_code,
489  struct ResultCodeMessage,
490  h),
491  GNUNET_MQ_hd_var_size (identity_update,
493  struct UpdateMessage,
494  h),
495  GNUNET_MQ_hd_var_size (identity_set_default,
497  struct SetDefaultMessage,
498  h),
500  struct GNUNET_MQ_Envelope *env;
501  struct GNUNET_MessageHeader *msg;
502 
503  h->reconnect_task = NULL;
504  LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to identity service.\n");
505  GNUNET_assert (NULL == h->mq);
506  h->mq =
507  GNUNET_CLIENT_connect (h->cfg, "identity", handlers, &mq_error_handler, h);
508  if (NULL == h->mq)
509  return;
510  if (NULL != h->cb)
511  {
513  GNUNET_MQ_send (h->mq, env);
514  }
515 }
#define GNUNET_MESSAGE_TYPE_IDENTITY_START
First message send from identity client to service (to subscribe to updates).
#define GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT
Client sets default identity; or service informs about default identity.
Used from service to client as a result to the GET_DEFAULT message, used from client to service to SE...
Definition: identity.h:134
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
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
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: identity_api.c:255
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
#define GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE
Update about identity status from service to clients.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
#define LOG(kind,...)
Definition: identity_api.c:33
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
Handle for the service.
Definition: identity_api.c:95
struct GNUNET_SCHEDULER_Task * reconnect_task
Task doing exponential back-off trying to reconnect.
Definition: identity_api.c:136
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition: identity_api.c:100
Message handler for a specific message type.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
Header for all communications.
#define GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE
Generic response from identity service with success and/or error message.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:353
struct GNUNET_MQ_Handle * mq
Connection to service.
Definition: identity_api.c:105
GNUNET_IDENTITY_Callback cb
Function to call when we receive updates.
Definition: identity_api.c:116
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
Answer from service to client about last operation; GET_DEFAULT maybe answered with this message on f...
Definition: identity.h:42
Service informs client about status of a pseudonym.
Definition: identity.h:77
Here is the call graph for this function:
Here is the caller graph for this function:

◆ free_ego()

static int free_ego ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Free ego from hash map.

Parameters
clsidentity service handle
keyunused
valueego to free
Returns
GNUNET_OK (continue to iterate)

Definition at line 189 of file identity_api.c.

References GNUNET_IDENTITY_Handle::cb, GNUNET_IDENTITY_Handle::cb_cls, GNUNET_IDENTITY_Operation::cls, GNUNET_IDENTITY_Ego::ctx, GNUNET_IDENTITY_Handle::egos, GNUNET_assert, GNUNET_CONTAINER_multihashmap_remove(), GNUNET_free, GNUNET_OK, GNUNET_YES, GNUNET_IDENTITY_Operation::h, GNUNET_IDENTITY_Ego::name, GNUNET_IDENTITY_Ego::pk, and value.

Referenced by GNUNET_IDENTITY_disconnect(), and reschedule_connect().

190 {
191  struct GNUNET_IDENTITY_Handle *h = cls;
192  struct GNUNET_IDENTITY_Ego *ego = value;
193 
194  if (NULL != h->cb)
195  h->cb (h->cb_cls, ego, &ego->ctx, NULL);
196  GNUNET_free (ego->pk);
197  GNUNET_free (ego->name);
200  GNUNET_free (ego);
201  return GNUNET_OK;
202 }
struct GNUNET_CONTAINER_MultiHashMap * egos
Hash map from the hash of the public key to the respective GNUNET_IDENTITY_Ego handle.
Definition: identity_api.c:111
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
char * name
Current name associated with this ego.
Definition: identity.h:255
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
Handle for an ego.
Definition: identity.h:245
static char * value
Value of the record to add/remove.
Handle for the service.
Definition: identity_api.c:95
int GNUNET_CONTAINER_multihashmap_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.
void * ctx
Client context associated with this ego.
Definition: identity.h:260
#define GNUNET_YES
Definition: gnunet_common.h:77
void * cb_cls
Closure for cb.
Definition: identity_api.c:121
GNUNET_IDENTITY_Callback cb
Function to call when we receive updates.
Definition: identity_api.c:116
struct GNUNET_CRYPTO_EcdsaPrivateKey * pk
Private key associated with this ego.
Definition: identity.h:250
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reschedule_connect()

static void reschedule_connect ( struct GNUNET_IDENTITY_Handle h)
static

Reschedule a connect attempt to the service.

Parameters
htransport service to reconnect

Definition at line 211 of file identity_api.c.

References GNUNET_IDENTITY_Operation::cb, GNUNET_IDENTITY_Operation::cls, GNUNET_IDENTITY_Operation::cont, GNUNET_IDENTITY_Operation::create_cont, GNUNET_IDENTITY_Handle::egos, free_ego(), GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_free_non_null, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_add_delayed(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_STD_BACKOFF, GNUNET_YES, LOG, GNUNET_IDENTITY_Handle::mq, op, GNUNET_IDENTITY_Handle::op_head, GNUNET_IDENTITY_Handle::op_tail, GNUNET_IDENTITY_Operation::pk, reconnect(), GNUNET_IDENTITY_Handle::reconnect_delay, and GNUNET_IDENTITY_Handle::reconnect_task.

Referenced by handle_identity_result_code(), handle_identity_set_default(), handle_identity_update(), and mq_error_handler().

212 {
214 
215  GNUNET_assert (NULL == h->reconnect_task);
216 
217  if (NULL != h->mq)
218  {
219  GNUNET_MQ_destroy (h->mq);
220  h->mq = NULL;
221  }
222  while (NULL != (op = h->op_head))
223  {
225  if (NULL != op->cont)
226  op->cont (op->cls, "Error in communication with the identity service");
227  else if (NULL != op->cb)
228  op->cb (op->cls, NULL, NULL, NULL);
229  else if (NULL != op->create_cont)
230  op->create_cont (op->cls,
231  NULL,
232  "Failed to communicate with the identity service");
233  GNUNET_free_non_null (op->pk);
234  GNUNET_free (op);
235  }
238  "Scheduling task to reconnect to identity service in %s.\n",
240  h->reconnect_task =
243 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_CONTAINER_MultiHashMap * egos
Hash map from the hash of the public key to the respective GNUNET_IDENTITY_Ego handle.
Definition: identity_api.c:111
struct GNUNET_TIME_Relative reconnect_delay
Time for next connect retry.
Definition: identity_api.c:141
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_IDENTITY_Operation * op_tail
Tail of active operations.
Definition: identity_api.c:131
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
Handle for an operation with the identity service.
Definition: identity_api.c:39
static void reconnect(void *cls)
Try again to connect to the identity service.
Definition: identity_api.c:483
#define LOG(kind,...)
Definition: identity_api.c:33
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
GNUNET_IDENTITY_CreateContinuation create_cont
Continuation to invoke with the result of the transmission; cb and cb will be NULL in this case...
Definition: identity_api.c:72
struct GNUNET_SCHEDULER_Task * reconnect_task
Task doing exponential back-off trying to reconnect.
Definition: identity_api.c:136
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:687
struct GNUNET_CRYPTO_EcdsaPrivateKey * pk
Private key to return to create_cont, or NULL.
Definition: identity_api.c:77
GNUNET_IDENTITY_Continuation cont
Continuation to invoke with the result of the transmission; cb and create_cont will be NULL in this c...
Definition: identity_api.c:66
struct GNUNET_IDENTITY_Operation * op_head
Head of active operations.
Definition: identity_api.c:126
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
static int free_ego(void *cls, const struct GNUNET_HashCode *key, void *value)
Free ego from hash map.
Definition: identity_api.c:189
void * cls
Closure for cont or cb.
Definition: identity_api.c:88
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
#define GNUNET_YES
Definition: gnunet_common.h:77
struct GNUNET_MQ_Handle * mq
Connection to service.
Definition: identity_api.c:105
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:144
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
GNUNET_IDENTITY_Callback cb
Continuation to invoke with the result of the transmission for 'get' operations (cont and create_cont...
Definition: identity_api.c:83
#define GNUNET_free(ptr)
Wrapper around free.
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_IDENTITY_Handle *
errorerror code

Definition at line 255 of file identity_api.c.

References GNUNET_IDENTITY_Operation::cls, GNUNET_IDENTITY_Operation::h, and reschedule_connect().

Referenced by reconnect().

256 {
257  struct GNUNET_IDENTITY_Handle *h = cls;
258 
259  reschedule_connect (h);
260 }
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
Handle for the service.
Definition: identity_api.c:95
static void reschedule_connect(struct GNUNET_IDENTITY_Handle *h)
Reschedule a connect attempt to the service.
Definition: identity_api.c:211
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_identity_result_code()

static int check_identity_result_code ( void *  cls,
const struct ResultCodeMessage rcm 
)
static

We received a result code from the service.

Check the message is well-formed.

Parameters
clsclosure
rcmresult message received
Returns
GNUNET_OK if the message is well-formed

Definition at line 272 of file identity_api.c.

References GNUNET_MQ_check_zero_termination, GNUNET_OK, ResultCodeMessage::header, and GNUNET_MessageHeader::size.

273 {
274  if (sizeof(*rcm) != htons (rcm->header.size))
276  return GNUNET_OK;
277 }
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE.
Definition: identity.h:47
#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...
#define GNUNET_MQ_check_zero_termination(m)
Insert code for a "check_" function that verifies that a given variable-length message received over ...

◆ handle_identity_result_code()

static void handle_identity_result_code ( void *  cls,
const struct ResultCodeMessage rcm 
)
static

We received a result code from the service.

Parameters
clsclosure
rcmresult message received

Definition at line 287 of file identity_api.c.

References GNUNET_IDENTITY_Operation::cb, GNUNET_IDENTITY_Operation::cls, GNUNET_IDENTITY_Operation::cont, GNUNET_IDENTITY_Operation::create_cont, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_free_non_null, GNUNET_IDENTITY_Operation::h, ResultCodeMessage::header, op, GNUNET_IDENTITY_Handle::op_head, GNUNET_IDENTITY_Handle::op_tail, GNUNET_IDENTITY_Operation::pk, reschedule_connect(), size, and GNUNET_MessageHeader::size.

288 {
289  struct GNUNET_IDENTITY_Handle *h = cls;
291  uint16_t size = ntohs (rcm->header.size) - sizeof(*rcm);
292  const char *str = (0 == size) ? NULL : (const char *) &rcm[1];
293 
294  op = h->op_head;
295  if (NULL == op)
296  {
297  GNUNET_break (0);
298  reschedule_connect (h);
299  return;
300  }
302  if (NULL != op->cont)
303  op->cont (op->cls, str);
304  else if (NULL != op->cb)
305  op->cb (op->cls, NULL, NULL, NULL);
306  else if (NULL != op->create_cont)
307  op->create_cont (op->cls, (NULL == str) ? op->pk : NULL, str);
308  GNUNET_free_non_null (op->pk);
309  GNUNET_free (op);
310 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE.
Definition: identity.h:47
struct GNUNET_IDENTITY_Operation * op_tail
Tail of active operations.
Definition: identity_api.c:131
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Handle for an operation with the identity service.
Definition: identity_api.c:39
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
GNUNET_IDENTITY_CreateContinuation create_cont
Continuation to invoke with the result of the transmission; cb and cb will be NULL in this case...
Definition: identity_api.c:72
Handle for the service.
Definition: identity_api.c:95
struct GNUNET_CRYPTO_EcdsaPrivateKey * pk
Private key to return to create_cont, or NULL.
Definition: identity_api.c:77
GNUNET_IDENTITY_Continuation cont
Continuation to invoke with the result of the transmission; cb and create_cont will be NULL in this c...
Definition: identity_api.c:66
struct GNUNET_IDENTITY_Operation * op_head
Head of active operations.
Definition: identity_api.c:126
static void reschedule_connect(struct GNUNET_IDENTITY_Handle *h)
Reschedule a connect attempt to the service.
Definition: identity_api.c:211
static unsigned int size
Size of the "table".
Definition: peer.c:67
void * cls
Closure for cont or cb.
Definition: identity_api.c:88
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:144
GNUNET_IDENTITY_Callback cb
Continuation to invoke with the result of the transmission for 'get' operations (cont and create_cont...
Definition: identity_api.c:83
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

◆ check_identity_update()

static int check_identity_update ( void *  cls,
const struct UpdateMessage um 
)
static

Check validity of identity update message.

Parameters
clsclosure
ummessage received
Returns
GNUNET_OK if the message is well-formed

Definition at line 321 of file identity_api.c.

References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, UpdateMessage::header, UpdateMessage::name_len, size, and GNUNET_MessageHeader::size.

322 {
323  uint16_t size = ntohs (um->header.size);
324  uint16_t name_len = ntohs (um->name_len);
325  const char *str = (const char *) &um[1];
326 
327  if ((size != name_len + sizeof(struct UpdateMessage)) ||
328  ((0 != name_len) && ('\0' != str[name_len - 1])))
329  {
330  GNUNET_break (0);
331  return GNUNET_SYSERR;
332  }
333  return GNUNET_OK;
334 }
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE.
Definition: identity.h:82
#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...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static unsigned int size
Size of the "table".
Definition: peer.c:67
uint16_t name_len
Number of bytes in ego name string including 0-termination, in NBO; 0 if the ego was deleted...
Definition: identity.h:88
Service informs client about status of a pseudonym.
Definition: identity.h:77

◆ handle_identity_update()

static void handle_identity_update ( void *  cls,
const struct UpdateMessage um 
)
static

Handle identity update message.

Parameters
clsclosure
ummessage received

Definition at line 344 of file identity_api.c.

References GNUNET_IDENTITY_Handle::cb, GNUNET_IDENTITY_Handle::cb_cls, GNUNET_IDENTITY_Operation::cls, GNUNET_IDENTITY_Ego::ctx, GNUNET_IDENTITY_Handle::egos, UpdateMessage::end_of_list, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_multihashmap_get(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_multihashmap_remove(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CRYPTO_ecdsa_key_get_public(), GNUNET_CRYPTO_hash(), GNUNET_free, GNUNET_new, GNUNET_strdup, GNUNET_YES, GNUNET_IDENTITY_Operation::h, id, GNUNET_IDENTITY_Ego::id, GNUNET_IDENTITY_Ego::name, UpdateMessage::name_len, GNUNET_IDENTITY_Ego::pk, UpdateMessage::private_key, and reschedule_connect().

345 {
346  struct GNUNET_IDENTITY_Handle *h = cls;
347  uint16_t name_len = ntohs (um->name_len);
348  const char *str = (0 == name_len) ? NULL : (const char *) &um[1];
350  struct GNUNET_HashCode id;
351  struct GNUNET_IDENTITY_Ego *ego;
352 
353  if (GNUNET_YES == ntohs (um->end_of_list))
354  {
355  /* end of initial list of data */
356  if (NULL != h->cb)
357  h->cb (h->cb_cls, NULL, NULL, NULL);
358  return;
359  }
361  GNUNET_CRYPTO_hash (&pub, sizeof(pub), &id);
362  ego = GNUNET_CONTAINER_multihashmap_get (h->egos, &id);
363  if (NULL == ego)
364  {
365  /* ego was created */
366  if (NULL == str)
367  {
368  /* deletion of unknown ego? not allowed */
369  GNUNET_break (0);
370  reschedule_connect (h);
371  return;
372  }
373  ego = GNUNET_new (struct GNUNET_IDENTITY_Ego);
375  *ego->pk = um->private_key;
376  ego->name = GNUNET_strdup (str);
377  ego->id = id;
380  h->egos,
381  &ego->id,
382  ego,
384  }
385  if (NULL == str)
386  {
387  /* ego was deleted */
389  &ego->id,
390  ego));
391  }
392  else
393  {
394  /* ego changed name */
395  GNUNET_free (ego->name);
396  ego->name = GNUNET_strdup (str);
397  }
398  /* inform application about change */
399  if (NULL != h->cb)
400  h->cb (h->cb_cls, ego, &ego->ctx, str);
401  /* complete deletion */
402  if (NULL == str)
403  {
404  GNUNET_free (ego->pk);
405  GNUNET_free (ego->name);
406  GNUNET_free (ego);
407  }
408 }
struct GNUNET_CONTAINER_MultiHashMap * egos
Hash map from the hash of the public key to the respective GNUNET_IDENTITY_Ego handle.
Definition: identity_api.c:111
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CRYPTO_EcdsaPrivateKey private_key
The private key.
Definition: identity.h:98
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Private ECC key encoded for transmission.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
char * name
Current name associated with this ego.
Definition: identity.h:255
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
Handle for an ego.
Definition: identity.h:245
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:48
Handle for the service.
Definition: identity_api.c:95
int GNUNET_CONTAINER_multihashmap_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.
static void reschedule_connect(struct GNUNET_IDENTITY_Handle *h)
Reschedule a connect attempt to the service.
Definition: identity_api.c:211
A 512-bit hashcode.
struct GNUNET_HashCode id
Hash of the public key of this ego.
Definition: identity.h:265
There must only be one value per key; storing a value should fail if a value under the same key alrea...
void * ctx
Client context associated with this ego.
Definition: identity.h:260
void GNUNET_CRYPTO_ecdsa_key_get_public(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:239
int GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
uint16_t name_len
Number of bytes in ego name string including 0-termination, in NBO; 0 if the ego was deleted...
Definition: identity.h:88
static struct GNUNET_CRYPTO_EddsaPublicKey pub
Definition: gnunet-scrypt.c:39
uint16_t end_of_list
Usually GNUNET_NO, GNUNET_YES to signal end of list.
Definition: identity.h:93
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
#define GNUNET_YES
Definition: gnunet_common.h:77
void * cb_cls
Closure for cb.
Definition: identity_api.c:121
GNUNET_IDENTITY_Callback cb
Function to call when we receive updates.
Definition: identity_api.c:116
struct GNUNET_CRYPTO_EcdsaPrivateKey * pk
Private key associated with this ego.
Definition: identity.h:250
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

◆ check_identity_set_default()

static int check_identity_set_default ( void *  cls,
const struct SetDefaultMessage sdm 
)
static

Function called when we receive a set default message from the service.

Parameters
clsclosure
sdmmessage received
Returns
GNUNET_OK if the message is well-formed

Definition at line 420 of file identity_api.c.

References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, SetDefaultMessage::header, SetDefaultMessage::name_len, SetDefaultMessage::reserved, size, and GNUNET_MessageHeader::size.

421 {
422  uint16_t size = ntohs (sdm->header.size) - sizeof(*sdm);
423  uint16_t name_len = ntohs (sdm->name_len);
424  const char *str = (const char *) &sdm[1];
425 
426  if ((size != name_len) || ((0 != name_len) && ('\0' != str[name_len - 1])))
427  {
428  GNUNET_break (0);
429  return GNUNET_SYSERR;
430  }
431  GNUNET_break (0 == ntohs (sdm->reserved));
432  return GNUNET_OK;
433 }
uint16_t name_len
Number of bytes in service name string including 0-termination, in NBO.
Definition: identity.h:144
#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...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
uint16_t reserved
Always zero.
Definition: identity.h:149
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static unsigned int size
Size of the "table".
Definition: peer.c:67
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT.
Definition: identity.h:139

◆ handle_identity_set_default()

static void handle_identity_set_default ( void *  cls,
const struct SetDefaultMessage sdm 
)
static

Type of a function to call when we receive a message from the service.

Parameters
clsclosure
sdmmessage received

Definition at line 444 of file identity_api.c.

References GNUNET_IDENTITY_Operation::cb, GNUNET_IDENTITY_Operation::cls, GNUNET_IDENTITY_Ego::ctx, GNUNET_IDENTITY_Handle::egos, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multihashmap_get(), GNUNET_CRYPTO_ecdsa_key_get_public(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_IDENTITY_Operation::h, GNUNET_IDENTITY_Ego::name, op, GNUNET_IDENTITY_Handle::op_head, GNUNET_IDENTITY_Handle::op_tail, SetDefaultMessage::private_key, and reschedule_connect().

445 {
446  struct GNUNET_IDENTITY_Handle *h = cls;
449  struct GNUNET_HashCode id;
450  struct GNUNET_IDENTITY_Ego *ego;
451 
453  GNUNET_CRYPTO_hash (&pub, sizeof(pub), &id);
454  ego = GNUNET_CONTAINER_multihashmap_get (h->egos, &id);
455  if (NULL == ego)
456  {
457  GNUNET_break (0);
458  reschedule_connect (h);
459  return;
460  }
461  op = h->op_head;
462  if (NULL == op)
463  {
464  GNUNET_break (0);
465  reschedule_connect (h);
466  return;
467  }
469  "Received SET_DEFAULT message from identity service\n");
471  if (NULL != op->cb)
472  op->cb (op->cls, ego, &ego->ctx, ego->name);
473  GNUNET_free (op);
474 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_CONTAINER_MultiHashMap * egos
Hash map from the hash of the public key to the respective GNUNET_IDENTITY_Ego handle.
Definition: identity_api.c:111
struct GNUNET_CRYPTO_EcdsaPrivateKey private_key
The private key.
Definition: identity.h:154
struct GNUNET_IDENTITY_Operation * op_tail
Tail of active operations.
Definition: identity_api.c:131
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Handle for an operation with the identity service.
Definition: identity_api.c:39
char * name
Current name associated with this ego.
Definition: identity.h:255
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
Handle for an ego.
Definition: identity.h:245
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:48
Handle for the service.
Definition: identity_api.c:95
struct GNUNET_IDENTITY_Operation * op_head
Head of active operations.
Definition: identity_api.c:126
static void reschedule_connect(struct GNUNET_IDENTITY_Handle *h)
Reschedule a connect attempt to the service.
Definition: identity_api.c:211
A 512-bit hashcode.
void * ctx
Client context associated with this ego.
Definition: identity.h:260
void GNUNET_CRYPTO_ecdsa_key_get_public(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:239
static struct GNUNET_CRYPTO_EddsaPublicKey pub
Definition: gnunet-scrypt.c:39
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
void * cls
Closure for cont or cb.
Definition: identity_api.c:88
#define GNUNET_log(kind,...)
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:144
GNUNET_IDENTITY_Callback cb
Continuation to invoke with the result of the transmission for 'get' operations (cont and create_cont...
Definition: identity_api.c:83
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function: