* Test if we are finished yet.
*/
static void
-test_finished ()
+test_finished (void)
{
- if ((NULL == create_op) && (NULL == delete_op) && (NULL == set_op) &&
- (NULL == set_subsystem) && (! list) && (! monitor))
+ if ( (NULL == create_op) &&
+ (NULL == delete_op) &&
+ (NULL == set_op) &&
+ (NULL == set_subsystem) &&
+ (! list) &&
+ (! monitor))
{
if (TIMEOUT_STATUS_CODE == global_ret)
global_ret = 0;
* @param emsg NULL on success, otherwise an error message
*/
static void
-delete_finished (void *cls, const char *emsg)
+delete_finished (void *cls,
+ const char *emsg)
{
struct GNUNET_IDENTITY_Operation **op = cls;
*op = NULL;
if (NULL == pk)
{
- fprintf (stderr, _ ("Failed to create ego: %s\n"), emsg);
+ fprintf (stderr,
+ _ ("Failed to create ego: %s\n"),
+ emsg);
global_ret = 1;
}
else if (verbose)
char *s;
char *privs;
- if ((NULL != set_ego) && (NULL != set_subsystem) && (NULL != ego) &&
- (NULL != identifier) && (0 == strcmp (identifier, set_ego)))
+ if ( (NULL != set_ego) &&
+ (NULL != set_subsystem) &&
+ (NULL != ego) &&
+ (NULL != identifier) &&
+ (0 == strcmp (identifier, set_ego)))
{
- set_op = GNUNET_IDENTITY_set (sh, set_subsystem, ego, &set_done, NULL);
+ set_op = GNUNET_IDENTITY_set (sh,
+ set_subsystem,
+ ego,
+ &set_done,
+ NULL);
GNUNET_free (set_subsystem);
set_subsystem = NULL;
GNUNET_free (set_ego);
set_ego = NULL;
}
- if ((NULL == ego) && (NULL != set_ego) && (NULL != set_subsystem))
+ if ( (NULL == ego) &&
+ (NULL != set_ego) &&
+ (NULL != set_subsystem) )
{
fprintf (stderr,
"Could not set ego to `%s' for subsystem `%s', ego not known\n",
}
if (! (list | monitor))
return;
- if ((NULL == ego) || (NULL == identifier))
+ if ( (NULL == ego) ||
+ (NULL == identifier) )
return;
- if ((NULL != set_ego) && (0 != strcmp (identifier, set_ego)))
+ if ( (NULL != set_ego) &&
+ (0 != strcmp (identifier,
+ set_ego)) )
return;
GNUNET_IDENTITY_ego_get_public_key (ego, &pk);
s = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk);
return;
}
sh = GNUNET_IDENTITY_connect (cfg,
- (monitor | list) || (NULL != set_ego) ||
+ (monitor | list) ||
+ (NULL != set_ego) ||
(NULL != set_subsystem)
? &print_ego
: NULL,
NULL);
if (NULL != delete_ego)
delete_op =
- GNUNET_IDENTITY_delete (sh, delete_ego, &delete_finished, &delete_op);
+ GNUNET_IDENTITY_delete (sh,
+ delete_ego,
+ &delete_finished,
+ &delete_op);
if (NULL != create_ego)
create_op =
- GNUNET_IDENTITY_create (sh, create_ego, &create_finished, &create_op);
- GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
+ GNUNET_IDENTITY_create (sh,
+ create_ego,
+ &create_finished,
+ &create_op);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
test_finished ();
}
int
main (int argc, char *const *argv)
{
- struct GNUNET_GETOPT_CommandLineOption options[] =
- { GNUNET_GETOPT_option_string ('C',
+ struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_option_string ('C',
"create",
"NAME",
gettext_noop ("create ego NAME"),
"set default identity to EGO for a subsystem SUBSYSTEM (use together with -e)"),
&set_subsystem),
GNUNET_GETOPT_option_verbose (&verbose),
- GNUNET_GETOPT_OPTION_END };
+ GNUNET_GETOPT_OPTION_END
+ };
int res;
- if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_get_utf8_args (argc, argv,
+ &argc, &argv))
return 4;
global_ret = TIMEOUT_STATUS_CODE; /* timeout */
res = GNUNET_PROGRAM_run (argc,
struct GNUNET_SERVICE_Client *client,
void *app_ctx)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Client %p disconnected\n",
+ client);
}
ego_directory = NULL;
while (NULL != (e = ego_head))
{
- GNUNET_CONTAINER_DLL_remove (ego_head, ego_tail, e);
+ GNUNET_CONTAINER_DLL_remove (ego_head,
+ ego_tail,
+ e);
GNUNET_free (e->identifier);
GNUNET_free (e);
}
* @return corresponding set default message
*/
static struct GNUNET_MQ_Envelope *
-create_set_default_message (struct Ego *ego, const char *servicename)
+create_set_default_message (struct Ego *ego,
+ const char *servicename)
{
struct SetDefaultMessage *sdm;
struct GNUNET_MQ_Envelope *env;
* @param message the message received
*/
static void
-handle_start_message (void *cls, const struct GNUNET_MessageHeader *message)
+handle_start_message (void *cls,
+ const struct GNUNET_MessageHeader *message)
{
struct GNUNET_SERVICE_Client *client = cls;
- struct UpdateMessage *ume;
- struct GNUNET_MQ_Envelope *env;
- struct Ego *ego;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received START message from client\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received START message from client\n");
GNUNET_SERVICE_client_mark_monitor (client);
GNUNET_SERVICE_client_disable_continue_warning (client);
- GNUNET_notification_context_add (nc, GNUNET_SERVICE_client_get_mq (client));
- for (ego = ego_head; NULL != ego; ego = ego->next)
+ GNUNET_notification_context_add (nc,
+ GNUNET_SERVICE_client_get_mq (client));
+ for (struct Ego *ego = ego_head; NULL != ego; ego = ego->next)
{
- env = create_update_message (ego);
- GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
+ GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
+ create_update_message (ego));
+ }
+ {
+ struct UpdateMessage *ume;
+ struct GNUNET_MQ_Envelope *env;
+
+ env = GNUNET_MQ_msg_extra (ume,
+ 0,
+ GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
+ ume->end_of_list = htons (GNUNET_YES);
+ ume->name_len = htons (0);
+ GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
+ env);
}
- env = GNUNET_MQ_msg_extra (ume, 0, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
- ume->end_of_list = htons (GNUNET_YES);
- ume->name_len = htons (0);
- GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
GNUNET_SERVICE_client_continue (client);
}
* @return #GNUNET_SYSERR if message was ill-formed
*/
static int
-check_lookup_message (void *cls, const struct LookupMessage *message)
+check_lookup_message (void *cls,
+ const struct LookupMessage *message)
{
GNUNET_MQ_check_zero_termination (message);
return GNUNET_OK;
* @param message the message received
*/
static void
-handle_lookup_message (void *cls, const struct LookupMessage *message)
+handle_lookup_message (void *cls,
+ const struct LookupMessage *message)
{
struct GNUNET_SERVICE_Client *client = cls;
const char *name;
struct GNUNET_MQ_Envelope *env;
struct Ego *ego;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received LOOKUP message from client\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received LOOKUP message from client\n");
name = (const char *) &message[1];
for (ego = ego_head; NULL != ego; ego = ego->next)
{
* @return #GNUNET_SYSERR if message was ill-formed
*/
static int
-check_lookup_by_suffix_message (void *cls, const struct LookupMessage *message)
+check_lookup_by_suffix_message (void *cls,
+ const struct LookupMessage *message)
{
GNUNET_MQ_check_zero_termination (message);
return GNUNET_OK;
* @param message the message received
*/
static void
-handle_lookup_by_suffix_message (void *cls, const struct LookupMessage *message)
+handle_lookup_by_suffix_message (void *cls,
+ const struct LookupMessage *message)
{
struct GNUNET_SERVICE_Client *client = cls;
const char *name;
* @return #GNUNET_OK if @a msg is well-formed
*/
static int
-check_get_default_message (void *cls, const struct GetDefaultMessage *msg)
+check_get_default_message (void *cls,
+ const struct GetDefaultMessage *msg)
{
uint16_t size;
uint16_t name_len;
* @param message the message received
*/
static void
-handle_get_default_message (void *cls, const struct GetDefaultMessage *gdm)
+handle_get_default_message (void *cls,
+ const struct GetDefaultMessage *gdm)
{
struct GNUNET_MQ_Envelope *env;
struct GNUNET_SERVICE_Client *client = cls;
- struct Ego *ego;
char *name;
char *identifier;
-
name = GNUNET_strdup ((const char *) &gdm[1]);
- GNUNET_STRINGS_utf8_tolower ((const char *) &gdm[1], name);
+ GNUNET_STRINGS_utf8_tolower ((const char *) &gdm[1],
+ name);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received GET_DEFAULT for service `%s' from client\n",
name);
- if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
- name,
- "DEFAULT_IDENTIFIER",
- &identifier))
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
+ name,
+ "DEFAULT_IDENTIFIER",
+ &identifier))
{
send_result_code (client, 1, gettext_noop ("no default known"));
GNUNET_SERVICE_client_continue (client);
GNUNET_free (name);
return;
}
- for (ego = ego_head; NULL != ego; ego = ego->next)
+ for (struct Ego *ego = ego_head; NULL != ego; ego = ego->next)
{
if (0 == strcmp (ego->identifier, identifier))
{
}
}
GNUNET_free (identifier);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to find ego `%s'\n", name);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Failed to find ego `%s'\n",
+ name);
GNUNET_free (name);
send_result_code (client,
1,
* @return #GNUNET_OK if @a msg is well-formed
*/
static int
-check_set_default_message (void *cls, const struct SetDefaultMessage *msg)
+check_set_default_message (void *cls,
+ const struct SetDefaultMessage *msg)
{
uint16_t size;
uint16_t name_len;
* @param message the message received
*/
static void
-handle_set_default_message (void *cls, const struct SetDefaultMessage *sdm)
+handle_set_default_message (void *cls,
+ const struct SetDefaultMessage *sdm)
{
struct Ego *ego;
struct GNUNET_SERVICE_Client *client = cls;
* @return #GNUNET_OK if @a msg is well-formed
*/
static int
-check_create_message (void *cls, const struct CreateRequestMessage *msg)
+check_create_message (void *cls,
+ const struct CreateRequestMessage *msg)
{
uint16_t size;
uint16_t name_len;
* @param message the message received
*/
static void
-handle_create_message (void *cls, const struct CreateRequestMessage *crm)
+handle_create_message (void *cls,
+ const struct CreateRequestMessage *crm)
{
struct GNUNET_SERVICE_Client *client = cls;
struct Ego *ego;
ego = GNUNET_new (struct Ego);
ego->pk = crm->private_key;
ego->identifier = GNUNET_strdup (str);
- GNUNET_CONTAINER_DLL_insert (ego_head, ego_tail, ego);
+ GNUNET_CONTAINER_DLL_insert (ego_head,
+ ego_tail,
+ ego);
send_result_code (client, 0, NULL);
fn = get_ego_filename (ego);
(void) GNUNET_DISK_directory_create_for_file (fn);
*/
struct GNUNET_IDENTITY_Ego
{
+ /**
+ * Hash of the private key of this ego.
+ */
+ struct GNUNET_HashCode id;
+
/**
* Private key associated with this ego.
*/
struct GNUNET_CRYPTO_EcdsaPrivateKey pk;
+ /**
+ * Public key associated with this ego. Initialized on demand.
+ * Always use #GNUNET_IDENTITY_ego_get_public_key() to obtain.
+ */
+ struct GNUNET_CRYPTO_EcdsaPublicKey pub;
+
/**
* Current name associated with this ego.
*/
void *ctx;
/**
- * Hash of the public key of this ego.
+ * Set to true once @e pub was initialized
*/
- struct GNUNET_HashCode id;
+ bool pub_initialized;
};
struct GNUNET_MQ_Handle *mq;
/**
- * Hash map from the hash of the public key to the
+ * Hash map from the hash of the private key to the
* respective `GNUNET_IDENTITY_Ego` handle.
*/
struct GNUNET_CONTAINER_MultiHashMap *egos;
* @return #GNUNET_OK (continue to iterate)
*/
static int
-free_ego (void *cls, const struct GNUNET_HashCode *key, void *value)
+free_ego (void *cls,
+ const struct GNUNET_HashCode *key,
+ void *value)
{
struct GNUNET_IDENTITY_Handle *h = cls;
struct GNUNET_IDENTITY_Ego *ego = value;
if (NULL != h->cb)
- h->cb (h->cb_cls, ego, &ego->ctx, NULL);
+ h->cb (h->cb_cls, ego,
+ &ego->ctx,
+ NULL);
GNUNET_free (ego->name);
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (h->egos, key, value));
+ GNUNET_CONTAINER_multihashmap_remove (h->egos,
+ key,
+ value));
GNUNET_free (ego);
return GNUNET_OK;
}
}
while (NULL != (op = h->op_head))
{
- GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
+ GNUNET_CONTAINER_DLL_remove (h->op_head,
+ h->op_tail,
+ op);
if (NULL != op->cont)
- op->cont (op->cls, "Error in communication with the identity service");
+ op->cont (op->cls,
+ "Error in communication with the identity service");
else if (NULL != op->cb)
op->cb (op->cls, NULL, NULL, NULL);
else if (NULL != op->create_cont)
"Failed to communicate with the identity service");
GNUNET_free (op);
}
- GNUNET_CONTAINER_multihashmap_iterate (h->egos, &free_ego, h);
+ GNUNET_CONTAINER_multihashmap_iterate (h->egos,
+ &free_ego,
+ h);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Scheduling task to reconnect to identity service in %s.\n",
- GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, GNUNET_YES));
+ GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay,
+ GNUNET_YES));
h->reconnect_task =
- GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
+ GNUNET_SCHEDULER_add_delayed (h->reconnect_delay,
+ &reconnect,
+ h);
h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
}
* @param error error code
*/
static void
-mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
+mq_error_handler (void *cls,
+ enum GNUNET_MQ_Error error)
{
struct GNUNET_IDENTITY_Handle *h = cls;
* @return #GNUNET_OK if the message is well-formed
*/
static int
-check_identity_result_code (void *cls, const struct ResultCodeMessage *rcm)
+check_identity_result_code (void *cls,
+ const struct ResultCodeMessage *rcm)
{
if (sizeof(*rcm) != htons (rcm->header.size))
GNUNET_MQ_check_zero_termination (rcm);
* @param rcm result message received
*/
static void
-handle_identity_result_code (void *cls, const struct ResultCodeMessage *rcm)
+handle_identity_result_code (void *cls,
+ const struct ResultCodeMessage *rcm)
{
struct GNUNET_IDENTITY_Handle *h = cls;
struct GNUNET_IDENTITY_Operation *op;
* @return #GNUNET_OK if the message is well-formed
*/
static int
-check_identity_update (void *cls, const struct UpdateMessage *um)
+check_identity_update (void *cls,
+ const struct UpdateMessage *um)
{
uint16_t size = ntohs (um->header.size);
uint16_t name_len = ntohs (um->name_len);
* @param um message received
*/
static void
-handle_identity_update (void *cls, const struct UpdateMessage *um)
+handle_identity_update (void *cls,
+ const struct UpdateMessage *um)
{
struct GNUNET_IDENTITY_Handle *h = cls;
uint16_t name_len = ntohs (um->name_len);
const char *str = (0 == name_len) ? NULL : (const char *) &um[1];
- struct GNUNET_CRYPTO_EcdsaPublicKey pub;
struct GNUNET_HashCode id;
struct GNUNET_IDENTITY_Ego *ego;
h->cb (h->cb_cls, NULL, NULL, NULL);
return;
}
- GNUNET_CRYPTO_ecdsa_key_get_public (&um->private_key, &pub);
- GNUNET_CRYPTO_hash (&pub, sizeof(pub), &id);
- ego = GNUNET_CONTAINER_multihashmap_get (h->egos, &id);
+ GNUNET_CRYPTO_hash (&um->private_key,
+ sizeof (um->private_key),
+ &id);
+ ego = GNUNET_CONTAINER_multihashmap_get (h->egos,
+ &id);
if (NULL == ego)
{
/* ego was created */
if (NULL == str)
{
/* ego was deleted */
- GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (h->egos,
- &ego->id,
- ego));
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_remove (h->egos,
+ &ego->id,
+ ego));
}
else
{
}
/* inform application about change */
if (NULL != h->cb)
- h->cb (h->cb_cls, ego, &ego->ctx, str);
+ h->cb (h->cb_cls,
+ ego,
+ &ego->ctx,
+ str);
/* complete deletion */
if (NULL == str)
{
* @return #GNUNET_OK if the message is well-formed
*/
static int
-check_identity_set_default (void *cls, const struct SetDefaultMessage *sdm)
+check_identity_set_default (void *cls,
+ const struct SetDefaultMessage *sdm)
{
uint16_t size = ntohs (sdm->header.size) - sizeof(*sdm);
uint16_t name_len = ntohs (sdm->name_len);
* @param sdm message received
*/
static void
-handle_identity_set_default (void *cls, const struct SetDefaultMessage *sdm)
+handle_identity_set_default (void *cls,
+ const struct SetDefaultMessage *sdm)
{
struct GNUNET_IDENTITY_Handle *h = cls;
struct GNUNET_IDENTITY_Operation *op;
- struct GNUNET_CRYPTO_EcdsaPublicKey pub;
struct GNUNET_HashCode id;
struct GNUNET_IDENTITY_Ego *ego;
- GNUNET_CRYPTO_ecdsa_key_get_public (&sdm->private_key, &pub);
- GNUNET_CRYPTO_hash (&pub, sizeof(pub), &id);
- ego = GNUNET_CONTAINER_multihashmap_get (h->egos, &id);
+ GNUNET_CRYPTO_hash (&sdm->private_key,
+ sizeof(sdm->private_key),
+ &id);
+ ego = GNUNET_CONTAINER_multihashmap_get (h->egos,
+ &id);
if (NULL == ego)
{
GNUNET_break (0);
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received SET_DEFAULT message from identity service\n");
- GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
+ GNUNET_CONTAINER_DLL_remove (h->op_head,
+ h->op_tail,
+ op);
if (NULL != op->cb)
- op->cb (op->cls, ego, &ego->ctx, ego->name);
+ op->cb (op->cls,
+ ego,
+ &ego->ctx,
+ ego->name);
GNUNET_free (op);
}
reconnect (void *cls)
{
struct GNUNET_IDENTITY_Handle *h = cls;
- struct GNUNET_MQ_MessageHandler handlers[] =
- { GNUNET_MQ_hd_var_size (identity_result_code,
+ struct GNUNET_MQ_MessageHandler handlers[] = {
+ GNUNET_MQ_hd_var_size (identity_result_code,
GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE,
struct ResultCodeMessage,
h),
GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT,
struct SetDefaultMessage,
h),
- GNUNET_MQ_handler_end () };
+ GNUNET_MQ_handler_end ()
+ };
struct GNUNET_MQ_Envelope *env;
struct GNUNET_MessageHeader *msg;
h->reconnect_task = NULL;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to identity service.\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Connecting to identity service.\n");
GNUNET_assert (NULL == h->mq);
- h->mq =
- GNUNET_CLIENT_connect (h->cfg, "identity", handlers, &mq_error_handler, h);
+ h->mq = GNUNET_CLIENT_connect (h->cfg,
+ "identity",
+ handlers,
+ &mq_error_handler,
+ h);
if (NULL == h->mq)
return;
if (NULL != h->cb)
{
- env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_IDENTITY_START);
- GNUNET_MQ_send (h->mq, env);
+ env = GNUNET_MQ_msg (msg,
+ GNUNET_MESSAGE_TYPE_IDENTITY_START);
+ GNUNET_MQ_send (h->mq,
+ env);
}
}
h->cfg = cfg;
h->cb = cb;
h->cb_cls = cb_cls;
- h->egos = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_YES);
+ h->egos = GNUNET_CONTAINER_multihashmap_create (16,
+ GNUNET_YES);
reconnect (h);
if (NULL == h->mq)
{
* @param pk set to ego's public key
*/
void
-GNUNET_IDENTITY_ego_get_public_key (const struct GNUNET_IDENTITY_Ego *ego,
+GNUNET_IDENTITY_ego_get_public_key (struct GNUNET_IDENTITY_Ego *ego,
struct GNUNET_CRYPTO_EcdsaPublicKey *pk)
{
- GNUNET_CRYPTO_ecdsa_key_get_public (&ego->pk,
- pk);
+ if (! ego->pub_initialized)
+ {
+ GNUNET_CRYPTO_ecdsa_key_get_public (&ego->pk,
+ &ego->pub);
+ ego->pub_initialized = true;
+ }
+ *pk = ego->pub;
}
}
if (NULL != h->egos)
{
- GNUNET_CONTAINER_multihashmap_iterate (h->egos, &free_ego, h);
+ GNUNET_CONTAINER_multihashmap_iterate (h->egos,
+ &free_ego,
+ h);
GNUNET_CONTAINER_multihashmap_destroy (h->egos);
h->egos = NULL;
}
* @param pk set to ego's public key
*/
void
-GNUNET_IDENTITY_ego_get_public_key (const struct GNUNET_IDENTITY_Ego *ego,
+GNUNET_IDENTITY_ego_get_public_key (struct GNUNET_IDENTITY_Ego *ego,
struct GNUNET_CRYPTO_EcdsaPublicKey *pk);