144 "Client %p disconnected\n",
187 subsystem_cfg = NULL;
192 while (NULL != (e = ego_head))
212 uint32_t result_code,
222 elen = strlen (emsg) + 1;
229 "Sending result %d (%s) to client\n",
268 const char *servicename)
274 name_len = (NULL == servicename) ? 0 : (strlen (servicename) + 1);
302 "Received START message from client\n");
307 for (
struct Ego *ego = ego_head; NULL != ego; ego = ego->
next)
362 "Received LOOKUP message from client\n");
363 name = (
const char *) &message[1];
364 for (ego = ego_head; NULL != ego; ego = ego->
next)
412 "Received LOOKUP_BY_SUFFIX message from client\n");
413 name = (
const char *) &message[1];
415 for (
struct Ego *ego = ego_head; NULL != ego; ego = ego->
next)
417 if ((strlen (ego->identifier) <= strlen (name)) &&
418 (0 == strcmp (ego->identifier,
419 &name[strlen (name) - strlen (ego->identifier)])) &&
420 ((strlen (name) == strlen (ego->identifier)) ||
421 (
'.' == name[strlen (name) - strlen (ego->identifier) - 1])) &&
422 ((NULL == lprefix) ||
423 (strlen (ego->identifier) > strlen (lprefix->
identifier))))
462 name = (
const char *) &msg[1];
465 (0 != ntohs (msg->
reserved)) || (
'\0' != name[name_len - 1]))
495 "Received GET_DEFAULT for service `%s' from client\n",
500 "DEFAULT_IDENTIFIER",
508 for (
struct Ego *ego = ego_head; NULL != ego; ego = ego->
next)
510 if (0 == strcmp (ego->identifier, identifier))
522 "Failed to find ego `%s'\n",
528 "default configured, but ego unknown (internal error)"));
576 str = (
const char *) &msg[1];
577 if (
'\0' != str[name_len - 1])
606 "Received SET_DEFAULT for service `%s' from client\n",
608 for (ego = ego_head; NULL != ego; ego = ego->
next)
615 "DEFAULT_IDENTIFIER",
621 _ (
"Failed to write subsystem default identifier map to `%s'.\n"),
631 _ (
"Unknown ego specified for service (internal error)"));
689 str = (
const char *) &msg[1];
690 if (
'\0' != str[name_len - 1])
718 for (ego = ego_head; NULL != ego; ego = ego->
next)
725 "identifier already in use for another ego"));
732 ego->
pk = crm->private_key;
784 "DEFAULT_IDENTIFIER",
794 "DEFAULT_IDENTIFIER",
811 uint16_t old_name_len;
812 uint16_t new_name_len;
824 old_name = (
const char *) &msg[1];
825 new_name = &old_name[old_name_len];
826 if ((old_name_len + new_name_len +
sizeof(
struct RenameMessage) != size) ||
827 (
'\0' != old_name[old_name_len - 1]) ||
828 (
'\0' != new_name[new_name_len - 1]))
849 uint16_t old_name_len;
857 const char *old_name_tmp;
861 old_name_tmp = (
const char *) &rm[1];
868 for (ego = ego_head; NULL != ego; ego = ego->
next)
881 for (ego = ego_head; NULL != ego; ego = ego->
next)
896 _ (
"Failed to write subsystem default identifier map to `%s'.\n"),
900 if (0 != rename (fn_old, fn_new))
936 "DEFAULT_IDENTIFIER",
939 if (0 != strcmp (
id, identifier))
946 "DEFAULT_IDENTIFIER",
972 name = (
const char *) &msg[1];
975 (0 != ntohs (msg->
reserved)) || (
'\0' != name[name_len - 1]))
1004 for (ego = ego_head; NULL != ego; ego = ego->
next)
1016 _ (
"Failed to write subsystem default identifier map to `%s'.\n"),
1019 if (0 != unlink (fn))
1047 fd = open (filename,
1068 if (sb.st_size != buf_size)
1071 "File `%s' has wrong size (%llu), expected %llu bytes\n",
1073 (
unsigned long long) sb.st_size,
1074 (
unsigned long long) buf_size);
1131 _ (
"Failed to parse ego information in `%s'\n"),
1136 "Loaded ego `%s'\n",
1180 "Loading subsystem configuration `%s'\n",
1189 "Failed to parse subsystem identity configuration file `%s'\n"),
1198 _ (
"Failed to create directory `%s' for storing egos\n"),
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
GNUNET_SERVICE_MAIN("identity", GNUNET_SERVICE_OPTION_NONE, &run, &client_connect_cb, &client_disconnect_cb, NULL, GNUNET_MQ_hd_fixed_size(start_message, GNUNET_MESSAGE_TYPE_IDENTITY_START, struct GNUNET_MessageHeader, NULL), GNUNET_MQ_hd_var_size(lookup_message, GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP, struct LookupMessage, NULL), GNUNET_MQ_hd_var_size(lookup_by_suffix_message, GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX, struct LookupMessage, NULL), GNUNET_MQ_hd_var_size(get_default_message, GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT, struct GetDefaultMessage, NULL), GNUNET_MQ_hd_var_size(set_default_message, GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT, struct SetDefaultMessage, NULL), GNUNET_MQ_hd_var_size(create_message, GNUNET_MESSAGE_TYPE_IDENTITY_CREATE, struct CreateRequestMessage, NULL), GNUNET_MQ_hd_var_size(rename_message, GNUNET_MESSAGE_TYPE_IDENTITY_RENAME, struct RenameMessage, NULL), GNUNET_MQ_hd_var_size(delete_message, GNUNET_MESSAGE_TYPE_IDENTITY_DELETE, struct DeleteMessage, NULL), GNUNET_MQ_handler_end())
Define "main" method using service macro.
uint16_t reserved
Always zero.
Message from client to GNS service to lookup records.
#define GNUNET_MESSAGE_TYPE_IDENTITY_START
First message send from identity client to service (to subscribe to updates).
struct Ego * prev
We keep egos in a DLL.
#define GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT
Client sets default identity; or service informs about default identity.
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
static int check_delete_message(void *cls, const struct DeleteMessage *msg)
Checks a GNUNET_MESSAGE_TYPE_IDENTITY_DELETE message.
The notification context is the key datastructure for a convenience API used for transmission of noti...
Used from service to client as a result to the GET_DEFAULT message, used from client to service to SE...
struct GNUNET_MessageHeader * msg
#define GNUNET_MESSAGE_TYPE_IDENTITY_DELETE
Delete identity (client->service).
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_IDENTITY_CREATE.
struct Ego * next
We keep egos in a DLL.
static int key_cmp(const struct GNUNET_IDENTITY_PrivateKey *pk1, const struct GNUNET_IDENTITY_PrivateKey *pk2)
Compare the given two private keys for equality.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
Common type definitions for the identity service and API.
static void * client_connect_cb(void *cls, struct GNUNET_SERVICE_Client *client, struct GNUNET_MQ_Handle *mq)
Add a client to our list of active clients.
uint16_t reserved
Always zero.
static char * get_ego_filename(struct Ego *ego)
Get the name of the file we use to store a given ego.
static void send_result_code(struct GNUNET_SERVICE_Client *client, uint32_t result_code, const char *emsg)
Send a result code back to the client.
static void handle_lookup_message(void *cls, const struct LookupMessage *message)
Handler for LOOKUP message from client, sends information about ONE identity to the client immediatel...
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Parse a configuration file, add all of the options in the file to the configuration environment...
struct GNUNET_MQ_Handle * GNUNET_SERVICE_client_get_mq(struct GNUNET_SERVICE_Client *c)
Obtain the message queue of c.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE.
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
static int check_create_message(void *cls, const struct CreateRequestMessage *msg)
Checks a GNUNET_MESSAGE_TYPE_IDENTITY_CREATE message.
uint16_t name_len
Number of bytes in service name string including 0-termination, in NBO.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void handle_set_default_message(void *cls, const struct SetDefaultMessage *sdm)
Handler for SET_DEFAULT message from client, updates default identity for some service.
uint16_t name_len
Number of bytes in service name string including 0-termination, in NBO.
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT.
uint16_t old_name_len
Number of characters in the old name including 0-termination, in NBO.
Client requests renaming of an identity.
A private key for an identity as per LSD0001.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
uint16_t reserved
Always zero.
static struct Experiment * e
static void handle_lookup_by_suffix_message(void *cls, const struct LookupMessage *message)
Handler for LOOKUP_BY_SUFFIX message from client, sends information about ONE identity to the client ...
#define GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE
Update about identity status from service to clients.
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
struct GNUNET_MESSENGER_Message * create_message(enum GNUNET_MESSENGER_MessageKind kind)
Creates and allocates a new message with a specific kind.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Write configuration file.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
uint16_t name_len
Number of bytes in identity name string including 0-termination, in NBO.
void GNUNET_notification_context_add(struct GNUNET_NotificationContext *nc, struct GNUNET_MQ_Handle *mq)
Add a subscriber to the notification context.
static int check_lookup_message(void *cls, const struct LookupMessage *message)
Handler for LOOKUP message from client, sends information about ONE identity to the client immediatel...
Closure for 'handle_ego_rename'.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static char * section
Name of the section.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Handle to our current configuration.
Handle to a client that is connected to a service.
uint16_t reserved
Always zero.
static void handle_create_message(void *cls, const struct CreateRequestMessage *crm)
Handler for CREATE message from client, creates new identity.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
static int check_set_default_message(void *cls, const struct SetDefaultMessage *msg)
Checks a GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT message.
#define GNUNET_MQ_check_zero_termination(m)
Insert code for a "check_" function that verifies that a given variable-length message received over ...
static void handle_ego_delete(void *cls, const char *section)
An ego was removed, remove it from all subsystems where it is currently set as the default...
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
static struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
static void client_disconnect_cb(void *cls, struct GNUNET_SERVICE_Client *client, void *app_ctx)
Called whenever a client is disconnected.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
static char * fn
Filename of the unique file.
static struct GNUNET_MQ_Envelope * create_set_default_message(struct Ego *ego, const char *servicename)
Create a set default message with information about the current state of an ego.
#define GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP
First message send from identity client to service to lookup a single ego.
Client requests creation of an identity.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
static int check_rename_message(void *cls, const struct RenameMessage *msg)
Checks a GNUNET_MESSAGE_TYPE_IDENTITY_RENAME message.
char * identifier
String identifier for the ego.
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create(const char *dir)
Implementation of "mkdir -p".
void GNUNET_SERVICE_client_mark_monitor(struct GNUNET_SERVICE_Client *c)
Set the 'monitor' flag on this client.
static void shutdown_task(void *cls)
Task run during shutdown.
static void run(void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *service)
Handle network size estimate clients.
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_IDENTITY_DELETE.
Client requests deletion of an identity.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
static void handle_rename_message(void *cls, const struct RenameMessage *rm)
Handler for RENAME message from client, creates new identity.
const char * new_name
New name.
#define GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX
First message send from identity client to service to lookup a single ego matching the given suffix (...
#define GNUNET_MESSAGE_TYPE_IDENTITY_CREATE
Create new identity (client->service).
static unsigned int size
Size of the "table".
static void handle_delete_message(void *cls, const struct DeleteMessage *dm)
Handler for DELETE message from client, creates new identity.
static struct GNUNET_NotificationContext * nc
Notification context, simplifies client broadcasts.
struct GNUNET_MQ_Envelope * env
static struct Ego * ego_head
Head of DLL of all egos.
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT.
static char * subsystem_cfg_file
Configuration file name where subsystem information is kept.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
enum GNUNET_GenericReturnValue GNUNET_DISK_fn_write(const char *fn, const void *buf, size_t buf_size, enum GNUNET_DISK_AccessPermissions mode)
Write a buffer to a file atomically.
struct GNUNET_NotificationContext * GNUNET_notification_context_create(unsigned int queue_length)
Create a new notification context.
Information we keep about each ego.
uint32_t result_code
Status code for the last operation, in NBO.
uint16_t name_len
Number of bytes in ego name string including 0-termination, in NBO; 0 if the ego was deleted...
Handle to a message queue.
static int check_lookup_by_suffix_message(void *cls, const struct LookupMessage *message)
Handler for LOOKUP message from client, sends information about ONE identity to the client immediatel...
uint16_t new_name_len
Number of characters in the new name including 0-termination, in NBO.
void GNUNET_notification_context_broadcast(struct GNUNET_NotificationContext *nc, const struct GNUNET_MessageHeader *msg, int can_drop)
Send a message to all subscribers of this context.
static void notify_listeners(struct Ego *ego)
Send an updated message for the given ego to all listeners.
static int read_from_file(const char *filename, void *buf, size_t buf_size)
uint16_t end_of_list
Usually GNUNET_NO, GNUNET_YES to signal end of list.
void GNUNET_CONFIGURATION_iterate_sections(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_Section_Iterator iter, void *iter_cls)
Iterate over all sections in the configuration.
struct GNUNET_MQ_Handle * mq
#define GNUNET_log(kind,...)
static void handle_start_message(void *cls, const struct GNUNET_MessageHeader *message)
Handler for START message from client, sends information about all identities to the client immediate...
#define GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT
Client requests to know default identity for a subsystem.
struct GNUNET_IDENTITY_PrivateKey pk
Private key of the ego.
#define GNUNET_MESSAGE_TYPE_IDENTITY_RENAME
Rename existing identity (client->service).
static char * ego_directory
Directory where we store the identities.
struct GNUNET_IDENTITY_PrivateKey private_key
The private key.
uint16_t name_len
Number of characters in the name including 0-termination, in NBO.
static void handle_get_default_message(void *cls, const struct GetDefaultMessage *gdm)
Handler for GET_DEFAULT message from client, returns default identity for some service.
static int check_get_default_message(void *cls, const struct GetDefaultMessage *msg)
Checks a GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT message.
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_IDENTITY_RENAME.
void GNUNET_notification_context_destroy(struct GNUNET_NotificationContext *nc)
Destroy the context, force disconnect for all subscribers.
#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.
const char * old_name
Old name.
Client requests knowledge about default identity for a subsystem from identity service.
static struct Ego * ego_tail
Tail of DLL of all egos.
struct GNUNET_IDENTITY_PrivateKey private_key
The private key.
static int process_ego_file(void *cls, const char *filename)
Process the given file from the "EGODIR".
static struct GNUNET_CONFIGURATION_Handle * subsystem_cfg
Handle to subsystem configuration which for each subsystem contains the name of the default ego...
void GNUNET_SERVICE_client_disable_continue_warning(struct GNUNET_SERVICE_Client *c)
Disable the warning the server issues if a message is not acknowledged in a timely fashion...
static void handle_ego_rename(void *cls, const char *section)
An ego was renamed; rename it in all subsystems where it is currently set as the default.
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
static struct GNUNET_MQ_Envelope * create_update_message(struct Ego *ego)
Create an update message with information about the current state of an ego.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory)...
#define GNUNET_malloc(size)
Wrapper around malloc.
Answer from service to client about last operation; GET_DEFAULT maybe answered with this message on f...
Service informs client about status of a pseudonym.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_STRINGS_utf8_tolower(const char *input, char *output)
Convert the utf-8 input string to lower case.
#define gettext_noop(String)