summaryrefslogtreecommitdiff
path: root/src/messenger
diff options
context:
space:
mode:
Diffstat (limited to 'src/messenger')
-rw-r--r--src/messenger/gnunet-service-messenger.c4
-rw-r--r--src/messenger/gnunet-service-messenger_ego_store.c253
-rw-r--r--src/messenger/gnunet-service-messenger_ego_store.h57
-rw-r--r--src/messenger/gnunet-service-messenger_handle.c56
-rw-r--r--src/messenger/gnunet-service-messenger_member_session.c8
-rw-r--r--src/messenger/gnunet-service-messenger_room.c28
-rw-r--r--src/messenger/gnunet-service-messenger_room.h15
-rw-r--r--src/messenger/gnunet-service-messenger_service.c8
-rw-r--r--src/messenger/messenger.conf.in6
-rw-r--r--src/messenger/messenger_api.c4
-rw-r--r--src/messenger/messenger_api_message.c12
-rw-r--r--src/messenger/plugin_gnsrecord_messenger.c59
12 files changed, 410 insertions, 100 deletions
diff --git a/src/messenger/gnunet-service-messenger.c b/src/messenger/gnunet-service-messenger.c
index 546f4c0d2..31bffec18 100644
--- a/src/messenger/gnunet-service-messenger.c
+++ b/src/messenger/gnunet-service-messenger.c
@@ -170,9 +170,7 @@ handle_room_close (void *cls,
if (GNUNET_YES == close_handle_room (msg_client->handle, &(msg->key)))
{
- const struct GNUNET_ShortHashCode *member_id = get_handle_member_id (msg_client->handle, &(msg->key));
-
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Closing room with member id: %s\n", GNUNET_sh2s (member_id));
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Closing room succeeded: %s\n", GNUNET_h2s (&(msg->key)));
struct GNUNET_MESSENGER_RoomMessage *response;
struct GNUNET_MQ_Envelope *env;
diff --git a/src/messenger/gnunet-service-messenger_ego_store.c b/src/messenger/gnunet-service-messenger_ego_store.c
index c460ac1c7..60a4d7bfc 100644
--- a/src/messenger/gnunet-service-messenger_ego_store.c
+++ b/src/messenger/gnunet-service-messenger_ego_store.c
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- Copyright (C) 2020--2021 GNUnet e.V.
+ Copyright (C) 2020--2022 GNUnet e.V.
GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
@@ -33,14 +33,21 @@ callback_update_ego (void *cls,
void **ctx,
const char *identifier)
{
- if ((!ego) || (!identifier))
+ if ((!ctx) || (!identifier))
return;
struct GNUNET_MESSENGER_EgoStore *store = cls;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "New ego in use: '%s'\n", identifier);
-
- update_store_ego (store, identifier, GNUNET_IDENTITY_ego_get_private_key (ego));
+ if (ego)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New ego in use: '%s'\n", identifier);
+ update_store_ego (store, identifier, GNUNET_IDENTITY_ego_get_private_key (ego));
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego got deleted: '%s'\n", identifier);
+ delete_store_ego (store, identifier);
+ }
}
void
@@ -52,6 +59,7 @@ init_ego_store(struct GNUNET_MESSENGER_EgoStore *store,
store->cfg = config;
store->identity = GNUNET_IDENTITY_connect (config, &callback_update_ego, store);
store->egos = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO);
+ store->handles = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO);
store->lu_start = NULL;
store->lu_end = NULL;
@@ -60,7 +68,6 @@ init_ego_store(struct GNUNET_MESSENGER_EgoStore *store,
store->op_end = NULL;
}
-
static int
iterate_destroy_egos (void *cls,
const struct GNUNET_HashCode *key,
@@ -109,6 +116,8 @@ clear_ego_store(struct GNUNET_MESSENGER_EgoStore *store)
GNUNET_CONTAINER_multihashmap_iterate (store->egos, iterate_destroy_egos, NULL);
GNUNET_CONTAINER_multihashmap_destroy (store->egos);
+ GNUNET_CONTAINER_multihashmap_destroy (store->handles);
+
if (store->identity)
{
GNUNET_IDENTITY_disconnect (store->identity);
@@ -117,6 +126,16 @@ clear_ego_store(struct GNUNET_MESSENGER_EgoStore *store)
}
}
+static int
+iterate_create_ego (void *cls,
+ const struct GNUNET_HashCode *key,
+ void *value)
+{
+ struct GNUNET_MESSENGER_SrvHandle *handle = value;
+ set_handle_ego (handle, (struct GNUNET_MESSENGER_Ego*) cls);
+ return GNUNET_YES;
+}
+
static void
callback_ego_create (void *cls,
const struct GNUNET_IDENTITY_PrivateKey *key,
@@ -125,21 +144,22 @@ callback_ego_create (void *cls,
struct GNUNET_MESSENGER_EgoOperation *element = cls;
struct GNUNET_MESSENGER_EgoStore *store = element->store;
- GNUNET_assert(element->identifier);
+ GNUNET_assert (element->identifier);
if (emsg)
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s\n", emsg);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s\n", emsg);
if (key)
{
- struct GNUNET_MESSENGER_SrvHandle *handle = element->handle;
-
struct GNUNET_MESSENGER_Ego *msg_ego = update_store_ego (store, element->identifier, key);
- set_handle_ego (handle, msg_ego);
+ struct GNUNET_HashCode hash;
+ GNUNET_CRYPTO_hash (element->identifier, strlen (element->identifier), &hash);
+
+ GNUNET_CONTAINER_multihashmap_get_multiple (store->handles, &hash, iterate_create_ego, msg_ego);
}
else
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Creating ego failed!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Creating ego failed!\n");
GNUNET_CONTAINER_DLL_remove (store->op_start, store->op_end, element);
GNUNET_free (element->identifier);
@@ -148,24 +168,70 @@ callback_ego_create (void *cls,
void
create_store_ego (struct GNUNET_MESSENGER_EgoStore *store,
- const char *identifier,
- void *handle)
+ const char *identifier)
{
GNUNET_assert ((store) && (identifier));
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Store create ego: %s\n", identifier);
+
struct GNUNET_MESSENGER_EgoOperation *element = GNUNET_new (struct GNUNET_MESSENGER_EgoOperation);
element->store = store;
- element->handle = handle;
+ element->cls = NULL;
element->identifier = GNUNET_strdup (identifier);
- element->operation = GNUNET_IDENTITY_create (store->identity, identifier, NULL,
- GNUNET_IDENTITY_TYPE_ECDSA, callback_ego_create, element);
+ element->operation = GNUNET_IDENTITY_create (
+ store->identity,
+ identifier,
+ NULL,
+ GNUNET_IDENTITY_TYPE_ECDSA,
+ callback_ego_create,
+ element
+ );
GNUNET_CONTAINER_DLL_insert (store->op_start, store->op_end, element);
}
+void
+bind_store_ego (struct GNUNET_MESSENGER_EgoStore *store,
+ const char *identifier,
+ void *handle)
+{
+ GNUNET_assert ((store) && (identifier) && (handle));
+
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Store bind ego: %s\n", identifier);
+
+ struct GNUNET_HashCode hash;
+ GNUNET_CRYPTO_hash (identifier, strlen (identifier), &hash);
+
+ if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains_value(store->handles, &hash, handle))
+ return;
+
+ if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put(store->handles, &hash, handle,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE))
+ GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Putting handle binding to ego store failed!\n");
+}
+
+void
+unbind_store_ego (struct GNUNET_MESSENGER_EgoStore *store,
+ const char *identifier,
+ void *handle)
+{
+ GNUNET_assert ((store) && (identifier) && (handle));
+
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Store unbind ego: %s\n", identifier);
+
+ struct GNUNET_HashCode hash;
+ GNUNET_CRYPTO_hash (identifier, strlen (identifier), &hash);
+
+ if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_contains_value(store->handles, &hash, handle))
+ return;
+
+ if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove(store->handles, &hash, handle))
+ GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Removing handle binding from ego store failed!\n");
+}
+
static void
callback_ego_lookup (void *cls,
struct GNUNET_IDENTITY_Ego *ego)
@@ -173,16 +239,30 @@ callback_ego_lookup (void *cls,
struct GNUNET_MESSENGER_EgoLookup *element = cls;
struct GNUNET_MESSENGER_EgoStore *store = element->store;
- GNUNET_assert(element->identifier);
+ GNUNET_assert (element->identifier);
- struct GNUNET_MESSENGER_Ego *msg_ego;
+ struct GNUNET_MESSENGER_Ego *msg_ego = NULL;
if (ego)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New ego looked up: '%s'\n", element->identifier);
msg_ego = update_store_ego (
- store, element->identifier, GNUNET_IDENTITY_ego_get_private_key(ego)
+ store,
+ element->identifier,
+ GNUNET_IDENTITY_ego_get_private_key(ego)
);
+ }
else
- msg_ego = NULL;
+ {
+ struct GNUNET_HashCode hash;
+ GNUNET_CRYPTO_hash (element->identifier, strlen (element->identifier), &hash);
+
+ if (GNUNET_CONTAINER_multihashmap_get (store->egos, &hash))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looked up ego got deleted: '%s'\n", element->identifier);
+ delete_store_ego(store, element->identifier);
+ }
+ }
if (element->cb)
element->cb(element->cls, element->identifier, msg_ego);
@@ -200,43 +280,37 @@ lookup_store_ego(struct GNUNET_MESSENGER_EgoStore *store,
{
GNUNET_assert (store);
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Store lookup ego: %s\n", identifier);
+
if (!identifier)
{
lookup(cls, identifier, NULL);
return;
}
- struct GNUNET_HashCode hash;
- GNUNET_CRYPTO_hash (identifier, strlen (identifier), &hash);
-
- struct GNUNET_MESSENGER_Ego *ego = GNUNET_CONTAINER_multihashmap_get (store->egos, &hash);
-
- if (ego)
- lookup(cls, identifier, ego);
- else
- {
- struct GNUNET_MESSENGER_EgoLookup *element = GNUNET_new (struct GNUNET_MESSENGER_EgoLookup);
+ struct GNUNET_MESSENGER_EgoLookup *element = GNUNET_new (struct GNUNET_MESSENGER_EgoLookup);
- element->store = store;
+ element->store = store;
- element->cb = lookup;
- element->cls = cls;
+ element->cb = lookup;
+ element->cls = cls;
- element->identifier = GNUNET_strdup (identifier);
+ element->identifier = GNUNET_strdup (identifier);
- element->lookup = GNUNET_IDENTITY_ego_lookup(store->cfg, identifier, callback_ego_lookup, element);
+ element->lookup = GNUNET_IDENTITY_ego_lookup(store->cfg, identifier, callback_ego_lookup, element);
- GNUNET_CONTAINER_DLL_insert (store->lu_start, store->lu_end, element);
- }
+ GNUNET_CONTAINER_DLL_insert (store->lu_start, store->lu_end, element);
}
struct GNUNET_MESSENGER_Ego*
-update_store_ego(struct GNUNET_MESSENGER_EgoStore *store,
- const char *identifier,
- const struct GNUNET_IDENTITY_PrivateKey *key)
+update_store_ego (struct GNUNET_MESSENGER_EgoStore *store,
+ const char *identifier,
+ const struct GNUNET_IDENTITY_PrivateKey *key)
{
GNUNET_assert ((store) && (identifier) && (key));
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Store update ego: %s\n", identifier);
+
struct GNUNET_HashCode hash;
GNUNET_CRYPTO_hash (identifier, strlen (identifier), &hash);
@@ -256,6 +330,34 @@ update_store_ego(struct GNUNET_MESSENGER_EgoStore *store,
return ego;
}
+void
+delete_store_ego (struct GNUNET_MESSENGER_EgoStore *store,
+ const char *identifier)
+{
+ GNUNET_assert ((store) && (identifier));
+
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Store delete ego: %s\n", identifier);
+
+ struct GNUNET_HashCode hash;
+ GNUNET_CRYPTO_hash (identifier, strlen (identifier), &hash);
+
+ struct GNUNET_MESSENGER_Ego *ego = GNUNET_CONTAINER_multihashmap_get (store->egos, &hash);
+
+ if (ego)
+ {
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Ego is not stored!\n");
+ return;
+ }
+
+ if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (store->egos, &hash, ego))
+ {
+ GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Removing ego from store failed!\n");
+ return;
+ }
+
+ GNUNET_free(ego);
+}
+
static void
callback_ego_rename (void *cls,
const char *emsg)
@@ -263,19 +365,24 @@ callback_ego_rename (void *cls,
struct GNUNET_MESSENGER_EgoOperation *element = cls;
struct GNUNET_MESSENGER_EgoStore *store = element->store;
- GNUNET_assert(element->identifier);
+ GNUNET_assert (element->identifier);
if (emsg)
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s\n", emsg);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s\n", emsg);
struct GNUNET_HashCode hash;
GNUNET_CRYPTO_hash (element->identifier, strlen (element->identifier), &hash);
struct GNUNET_MESSENGER_Ego *ego = GNUNET_CONTAINER_multihashmap_get (store->egos, &hash);
+ if (!ego)
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Ego is not stored!\n");
+
+ char *identifier = (char*) element->cls;
+
if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (store->egos, &hash, ego))
{
- GNUNET_CRYPTO_hash ((char*) element->handle, strlen ((char*) element->handle), &hash);
+ GNUNET_CRYPTO_hash (identifier, strlen (identifier), &hash);
GNUNET_CONTAINER_multihashmap_put (store->egos, &hash, ego,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
@@ -283,7 +390,7 @@ callback_ego_rename (void *cls,
else
GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Renaming ego failed!\n");
- GNUNET_free (element->handle);
+ GNUNET_free (identifier);
GNUNET_CONTAINER_DLL_remove (store->op_start, store->op_end, element);
GNUNET_free (element->identifier);
@@ -297,14 +404,66 @@ rename_store_ego (struct GNUNET_MESSENGER_EgoStore *store,
{
GNUNET_assert ((store) && (old_identifier) && (new_identifier));
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Store rename ego: %s -> %s\n", old_identifier, new_identifier);
+
struct GNUNET_MESSENGER_EgoOperation *element = GNUNET_new (struct GNUNET_MESSENGER_EgoOperation);
element->store = store;
- element->handle = GNUNET_strdup (new_identifier);
+ element->cls = GNUNET_strdup (new_identifier);
element->identifier = GNUNET_strdup (old_identifier);
- element->operation = GNUNET_IDENTITY_rename (store->identity, old_identifier, new_identifier, callback_ego_rename, element);
+ element->operation = GNUNET_IDENTITY_rename (
+ store->identity,
+ old_identifier,
+ new_identifier,
+ callback_ego_rename,
+ element
+ );
+
+ GNUNET_CONTAINER_DLL_insert (store->op_start, store->op_end, element);
+}
+
+static void
+callback_ego_delete (void *cls,
+ const char *emsg)
+{
+ struct GNUNET_MESSENGER_EgoOperation *element = cls;
+ struct GNUNET_MESSENGER_EgoStore *store = element->store;
+
+ GNUNET_assert (element->identifier);
+
+ if (emsg)
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s\n", emsg);
+
+ create_store_ego (store, element->identifier);
+
+ GNUNET_CONTAINER_DLL_remove (store->op_start, store->op_end, element);
+ GNUNET_free (element->identifier);
+ GNUNET_free (element);
+}
+
+void
+renew_store_ego (struct GNUNET_MESSENGER_EgoStore *store,
+ const char *identifier)
+{
+ GNUNET_assert ((store) && (identifier));
+
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Store renew ego: %s\n", identifier);
+
+ struct GNUNET_MESSENGER_EgoOperation *element = GNUNET_new (struct GNUNET_MESSENGER_EgoOperation);
+
+ element->store = store;
+ element->cls = NULL;
+
+ element->identifier = GNUNET_strdup (identifier);
+
+ element->operation = GNUNET_IDENTITY_delete(
+ store->identity,
+ identifier,
+ callback_ego_delete,
+ element
+ );
GNUNET_CONTAINER_DLL_insert (store->op_start, store->op_end, element);
}
diff --git a/src/messenger/gnunet-service-messenger_ego_store.h b/src/messenger/gnunet-service-messenger_ego_store.h
index 4222a4e91..4ed2bbf6d 100644
--- a/src/messenger/gnunet-service-messenger_ego_store.h
+++ b/src/messenger/gnunet-service-messenger_ego_store.h
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- Copyright (C) 2020--2021 GNUnet e.V.
+ Copyright (C) 2020--2022 GNUnet e.V.
GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
@@ -62,7 +62,8 @@ struct GNUNET_MESSENGER_EgoOperation
struct GNUNET_IDENTITY_Operation *operation;
struct GNUNET_MESSENGER_EgoStore *store;
- void *handle;
+
+ void *cls;
char *identifier;
};
@@ -73,6 +74,7 @@ struct GNUNET_MESSENGER_EgoStore
struct GNUNET_IDENTITY_Handle *identity;
struct GNUNET_CONTAINER_MultiHashMap *egos;
+ struct GNUNET_CONTAINER_MultiHashMap *handles;
struct GNUNET_MESSENGER_EgoLookup *lu_start;
struct GNUNET_MESSENGER_EgoLookup *lu_end;
@@ -101,15 +103,38 @@ clear_ego_store (struct GNUNET_MESSENGER_EgoStore *store);
/**
* Creates a new EGO which will be registered to a <i>store</i> under
- * a specific <i>identifier</i>. A given <i>handle</i> will be informed
- * about the creation and changes its EGO accordingly.
+ * a specific <i>identifier</i>.
*
* @param[in/out] store EGO-store
* @param[in] identifier Identifier string
- * @param[in/out] handle Handle or NULL
*/
void
create_store_ego (struct GNUNET_MESSENGER_EgoStore *store,
+ const char *identifier);
+
+/**
+ * Binds an EGO which was registered to a <i>store</i> under
+ * a specific <i>identifier</i> to a given <i>handle</i>
+ *
+ * @param[in/out] store EGO-store
+ * @param[in] identifier Identifier string
+ * @param[in/out] handle Handle
+ */
+void
+bind_store_ego (struct GNUNET_MESSENGER_EgoStore *store,
+ const char *identifier,
+ void *handle);
+
+/**
+ * Binds an EGO which was registered to a <i>store</i> under
+ * a specific <i>identifier</i> to a given <i>handle</i>
+ *
+ * @param[in/out] store EGO-store
+ * @param[in] identifier Identifier string
+ * @param[in/out] handle Handle
+ */
+void
+unbind_store_ego (struct GNUNET_MESSENGER_EgoStore *store,
const char *identifier,
void *handle);
@@ -143,6 +168,17 @@ update_store_ego (struct GNUNET_MESSENGER_EgoStore *store,
const struct GNUNET_IDENTITY_PrivateKey *key);
/**
+ * Deletes the registration of an EGO in a <i>store</i> under
+ * a specific <i>identifier</i>.
+ *
+ * @param[in/out] store EGO-store
+ * @param[in] identifier Identifier string
+ */
+void
+delete_store_ego (struct GNUNET_MESSENGER_EgoStore *store,
+ const char *identifier);
+
+/**
* Updates the location of a registered EGO in a <i>store</i> to
* a different one under a specific <i>new_identifier<i> replacing
* its old one.
@@ -156,4 +192,15 @@ rename_store_ego (struct GNUNET_MESSENGER_EgoStore *store,
const char *old_identifier,
const char *new_identifier);
+/**
+ * Replaces the registered EGO in a <i>store</i> under a specific
+ * <i>identifier</i> with a newly created one.
+ *
+ * @param[in/out] store EGO-store
+ * @param[in] identifier Identifier string
+ */
+void
+renew_store_ego (struct GNUNET_MESSENGER_EgoStore *store,
+ const char *identifier);
+
#endif //GNUNET_SERVICE_MESSENGER_EGO_STORE_H
diff --git a/src/messenger/gnunet-service-messenger_handle.c b/src/messenger/gnunet-service-messenger_handle.c
index 341bb7251..218482e45 100644
--- a/src/messenger/gnunet-service-messenger_handle.c
+++ b/src/messenger/gnunet-service-messenger_handle.c
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- Copyright (C) 2020--2021 GNUnet e.V.
+ Copyright (C) 2020--2022 GNUnet e.V.
GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
@@ -68,7 +68,13 @@ destroy_handle (struct GNUNET_MESSENGER_SrvHandle *handle)
save_handle_configuration (handle);
if (handle->name)
+ {
+ struct GNUNET_MESSENGER_EgoStore *store = get_service_ego_store(handle->service);
+
+ unbind_store_ego(store, handle->name, handle);
+
GNUNET_free(handle->name);
+ }
GNUNET_CONTAINER_multihashmap_iterate (handle->member_ids, iterate_free_member_ids, NULL);
GNUNET_CONTAINER_multihashmap_destroy (handle->member_ids);
@@ -317,24 +323,26 @@ callback_update_handle (void *cls,
{
struct GNUNET_MESSENGER_SrvHandle *handle = cls;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Updating handle...\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating handle...\n");
struct GNUNET_MESSENGER_EgoStore *store = get_service_ego_store(handle->service);
+ bind_store_ego(store, handle->name, handle);
+
if (!ego)
- create_store_ego(store, handle->name, handle);
+ create_store_ego (store, handle->name);
else
- change_handle_ego (handle, ego);
+ renew_store_ego (store, handle->name);
}
void
update_handle (struct GNUNET_MESSENGER_SrvHandle *handle)
{
- GNUNET_assert(handle);
+ GNUNET_assert (handle);
if (!handle->name)
{
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Updating handle failed: Name is required!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Updating handle failed: Name is required!\n");
return;
}
@@ -360,46 +368,38 @@ callback_set_handle_name (void *cls,
struct GNUNET_MESSENGER_EgoStore *store = get_service_ego_store(handle->service);
- int rename_ego_in_store = handle->ego? GNUNET_YES : GNUNET_NO;
-
char *old_dir;
get_handle_data_subdir (handle, handle->name, &old_dir);
char *new_dir;
get_handle_data_subdir (handle, name, &new_dir);
- int result = 0;
+ if ((GNUNET_YES == GNUNET_DISK_directory_test (new_dir, GNUNET_NO)) &&
+ (GNUNET_OK != GNUNET_DISK_directory_remove(new_dir)))
+ goto free_dirs;
if (GNUNET_YES == GNUNET_DISK_directory_test (old_dir, GNUNET_YES))
{
GNUNET_DISK_directory_create_for_file (new_dir);
- result = rename (old_dir, new_dir);
+ if (0 != rename (old_dir, new_dir))
+ goto free_dirs;
}
- else if (GNUNET_YES == GNUNET_DISK_directory_test (new_dir, GNUNET_NO))
- result = -1;
-
- if (0 == result)
- {
- struct GNUNET_MESSENGER_MessageHandle msg_handle;
- msg_handle.handle = handle;
- msg_handle.message = create_message_name (name);
-
- GNUNET_CONTAINER_multihashmap_iterate (handle->member_ids, iterate_send_message, &msg_handle);
+ if (handle->ego)
+ rename_store_ego(store, handle->name, name);
- destroy_message (msg_handle.message);
+ struct GNUNET_MESSENGER_MessageHandle msg_handle;
+ msg_handle.handle = handle;
+ msg_handle.message = create_message_name (name);
- change_handle_name (handle, name);
- }
- else
- rename_ego_in_store = GNUNET_NO;
+ GNUNET_CONTAINER_multihashmap_iterate (handle->member_ids, iterate_send_message, &msg_handle);
+ destroy_message (msg_handle.message);
+ change_handle_name (handle, name);
+free_dirs:
GNUNET_free(old_dir);
GNUNET_free(new_dir);
-
- if (GNUNET_YES == rename_ego_in_store)
- rename_store_ego(store, handle->name, name);
}
void
diff --git a/src/messenger/gnunet-service-messenger_member_session.c b/src/messenger/gnunet-service-messenger_member_session.c
index 846dbbe2b..6bd1d24b8 100644
--- a/src/messenger/gnunet-service-messenger_member_session.c
+++ b/src/messenger/gnunet-service-messenger_member_session.c
@@ -84,6 +84,9 @@ check_member_session_completion (struct GNUNET_MESSENGER_MemberSession *session)
{
GNUNET_assert (session);
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Check session history (%s) for completion.\n",
+ GNUNET_sh2s(get_member_session_id(session)));
+
if (!session->messages.tail)
{
session->completed = GNUNET_YES;
@@ -142,7 +145,10 @@ check_member_session_completion (struct GNUNET_MESSENGER_MemberSession *session)
completion:
if (GNUNET_YES == is_member_session_completed(session))
{
- GNUNET_CONTAINER_multihashmap_destroy (session->history);
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Completed session history (%s)\n",
+ GNUNET_sh2s(get_member_session_id(session)));
+
+ GNUNET_CONTAINER_multihashmap_clear (session->history);
struct GNUNET_MESSENGER_ContactStore *store = get_member_contact_store(session->member->store);
diff --git a/src/messenger/gnunet-service-messenger_room.c b/src/messenger/gnunet-service-messenger_room.c
index 7f2fd0ca6..7a20d2191 100644
--- a/src/messenger/gnunet-service-messenger_room.c
+++ b/src/messenger/gnunet-service-messenger_room.c
@@ -92,14 +92,14 @@ static void
handle_room_messages (struct GNUNET_MESSENGER_SrvRoom *room);
void
-destroy_room (struct GNUNET_MESSENGER_SrvRoom *room)
+destroy_room (struct GNUNET_MESSENGER_SrvRoom *room,
+ int deletion)
{
GNUNET_assert(room);
if (room->idle)
{
GNUNET_SCHEDULER_cancel (room->idle);
-
room->idle = NULL;
}
@@ -107,18 +107,22 @@ destroy_room (struct GNUNET_MESSENGER_SrvRoom *room)
GNUNET_CADET_close_port (room->port);
GNUNET_CONTAINER_multipeermap_iterate (room->tunnels, iterate_destroy_tunnels, NULL);
-
handle_room_messages (room);
- if (room->service->dir)
+ if (!(room->service->dir))
+ goto skip_saving;
+
+ if (GNUNET_YES == deletion)
+ remove_room (room);
+ else
save_room (room);
+skip_saving:
clear_member_store (get_room_member_store(room));
clear_message_store (get_room_message_store(room));
clear_operation_store(get_room_operation_store(room));
GNUNET_CONTAINER_multipeermap_destroy (room->tunnels);
-
clear_list_tunnels (&(room->basement));
clear_message_state(&(room->state));
@@ -1221,6 +1225,20 @@ save_room (struct GNUNET_MESSENGER_SrvRoom *room)
GNUNET_free(room_dir);
}
+void
+remove_room (struct GNUNET_MESSENGER_SrvRoom *room)
+{
+ GNUNET_assert(room);
+
+ char *room_dir;
+ get_room_data_subdir (room, &room_dir);
+
+ if (GNUNET_YES == GNUNET_DISK_directory_test (room_dir, GNUNET_YES))
+ GNUNET_DISK_directory_remove(room_dir);
+
+ GNUNET_free(room_dir);
+}
+
static void
remove_room_member_session (struct GNUNET_MESSENGER_SrvRoom *room,
struct GNUNET_MESSENGER_MemberSession *session)
diff --git a/src/messenger/gnunet-service-messenger_room.h b/src/messenger/gnunet-service-messenger_room.h
index 4b3811104..58edc4121 100644
--- a/src/messenger/gnunet-service-messenger_room.h
+++ b/src/messenger/gnunet-service-messenger_room.h
@@ -95,10 +95,15 @@ create_room (struct GNUNET_MESSENGER_SrvHandle *handle,
/**
* Destroys a room and frees its memory fully.
*
+ * The <i>deletion</i> flag should only be set to #GNUNET_YES if the
+ * room gets dropped by the service, otherwise #GNUNET_NO.
+ *
* @param[in/out] room Room
+ * @param[in] deletion Flag to indicate context of destruction
*/
void
-destroy_room (struct GNUNET_MESSENGER_SrvRoom *room);
+destroy_room (struct GNUNET_MESSENGER_SrvRoom *room,
+ int deletion);
/**
* Returns the used member store of a given <i>room</i>.
@@ -364,4 +369,12 @@ load_room (struct GNUNET_MESSENGER_SrvRoom *room);
void
save_room (struct GNUNET_MESSENGER_SrvRoom *room);
+/**
+ * Removes the configuration for a given <i>room</i> of a service.
+ *
+ * @param[in] room Room
+ */
+void
+remove_room (struct GNUNET_MESSENGER_SrvRoom *room);
+
#endif //GNUNET_SERVICE_MESSENGER_ROOM_H
diff --git a/src/messenger/gnunet-service-messenger_service.c b/src/messenger/gnunet-service-messenger_service.c
index b53b72af8..83d7632d8 100644
--- a/src/messenger/gnunet-service-messenger_service.c
+++ b/src/messenger/gnunet-service-messenger_service.c
@@ -94,7 +94,7 @@ iterate_destroy_rooms (void *cls,
void *value)
{
struct GNUNET_MESSENGER_SrvRoom *room = value;
- destroy_room (room);
+ destroy_room (room, GNUNET_NO);
return GNUNET_YES;
}
@@ -220,7 +220,7 @@ open_service_room (struct GNUNET_MESSENGER_Service *service,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)))
return GNUNET_YES;
- destroy_room (room);
+ destroy_room (room, GNUNET_YES);
return GNUNET_NO;
}
@@ -253,7 +253,7 @@ entry_service_room (struct GNUNET_MESSENGER_Service *service,
}
else
{
- destroy_room (room);
+ destroy_room (room, GNUNET_YES);
return GNUNET_NO;
}
@@ -287,7 +287,7 @@ close_service_room (struct GNUNET_MESSENGER_Service *service,
{
if (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove (service->rooms, key, room))
{
- destroy_room (room);
+ destroy_room (room, GNUNET_YES);
return GNUNET_YES;
}
else
diff --git a/src/messenger/messenger.conf.in b/src/messenger/messenger.conf.in
index 6b54550ea..ef0544681 100644
--- a/src/messenger/messenger.conf.in
+++ b/src/messenger/messenger.conf.in
@@ -1,12 +1,12 @@
[messenger]
-START_ON_DEMAND = YES
+START_ON_DEMAND = @START_ON_DEMAND@
RUN_PER_USER = YES
-PORT = 2097
+@JAVAPORT@PORT = 2125
HOSTNAME = localhost
BINARY = gnunet-service-messenger
ACCEPT_FROM = 127.0.0.1;
ACCEPT_FROM6 = ::1;
-UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-messenger.sock
+UNIXPATH = $GNUNET_USER_RUNTIME_DIR/gnunet-service-messenger.sock
UNIX_MATCH_UID = NO
UNIX_MATCH_GID = YES
diff --git a/src/messenger/messenger_api.c b/src/messenger/messenger_api.c
index a37b1b10b..8cbe26549 100644
--- a/src/messenger/messenger_api.c
+++ b/src/messenger/messenger_api.c
@@ -64,6 +64,8 @@ GNUNET_MESSENGER_name_of_kind (enum GNUNET_MESSENGER_MessageKind kind)
return "FILE";
case GNUNET_MESSENGER_KIND_PRIVATE:
return "PRIVATE";
+ case GNUNET_MESSENGER_KIND_DELETE:
+ return "DELETE";
default:
return "UNKNOWN";
}
@@ -253,7 +255,7 @@ handle_recv_message (void *cls,
store, context, sender
);
- handle_room_message (room, contact, &message, hash);
+ contact = handle_room_message (room, contact, &message, hash);
const struct GNUNET_MESSENGER_Message *stored_message = get_room_message(room, hash);
diff --git a/src/messenger/messenger_api_message.c b/src/messenger/messenger_api_message.c
index 496c98dbf..3814def70 100644
--- a/src/messenger/messenger_api_message.c
+++ b/src/messenger/messenger_api_message.c
@@ -219,6 +219,10 @@ get_message_body_kind_size (enum GNUNET_MESSENGER_MessageKind kind)
case GNUNET_MESSENGER_KIND_PRIVATE:
length += member_size(struct GNUNET_MESSENGER_Message, body.privacy.key);
break;
+ case GNUNET_MESSENGER_KIND_DELETE:
+ length += member_size(struct GNUNET_MESSENGER_Message, body.deletion.hash);
+ length += member_size(struct GNUNET_MESSENGER_Message, body.deletion.delay);
+ break;
default:
break;
}
@@ -445,6 +449,10 @@ encode_message_body (enum GNUNET_MESSENGER_MessageKind kind,
encode_step(buffer, offset, &(body->privacy.key));
encode_step_ext(buffer, offset, body->privacy.data, min(length - offset, body->privacy.length));
break;
+ case GNUNET_MESSENGER_KIND_DELETE:
+ encode_step(buffer, offset, &(body->deletion.hash));
+ encode_step(buffer, offset, &(body->deletion.delay));
+ break;
default:
break;
}
@@ -616,6 +624,10 @@ decode_message_body (enum GNUNET_MESSENGER_MessageKind *kind,
body->privacy.length = (length - offset);
decode_step_malloc(buffer, offset, body->privacy.data, length - offset, 0);
break;
+ case GNUNET_MESSENGER_KIND_DELETE:
+ decode_step(buffer, offset, &(body->deletion.hash));
+ decode_step(buffer, offset, &(body->deletion.delay));
+ break;
default:
*kind = GNUNET_MESSENGER_KIND_UNKNOWN;
break;
diff --git a/src/messenger/plugin_gnsrecord_messenger.c b/src/messenger/plugin_gnsrecord_messenger.c
index 2219f0bde..e09a0330d 100644
--- a/src/messenger/plugin_gnsrecord_messenger.c
+++ b/src/messenger/plugin_gnsrecord_messenger.c
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- Copyright (C) 2021 GNUnet e.V.
+ Copyright (C) 2021--2022 GNUnet e.V.
GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
@@ -63,12 +63,30 @@ messenger_value_to_string (void *cls,
char *key = GNUNET_STRINGS_data_to_string_alloc (&(record->key), sizeof(struct GNUNET_HashCode));
char *ret;
- GNUNET_asprintf (&ret, "%s-%s", door, key);
+ GNUNET_asprintf (&ret, "%s-%s", key, door);
GNUNET_free (key);
GNUNET_free (door);
return ret;
}
+ case GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_DETAILS:
+ {
+ if (data_size != sizeof(struct GNUNET_MESSENGER_RoomDetailsRecord))
+ {
+ GNUNET_break_op (0);
+ return NULL;
+ }
+
+ const struct GNUNET_MESSENGER_RoomDetailsRecord *record = data;
+ char *name = GNUNET_strndup(record->name, 256);
+ char *flags = GNUNET_STRINGS_data_to_string_alloc (&(record->flags), sizeof(uint32_t));
+
+ char *ret;
+ GNUNET_asprintf (&ret, "%s-%s", flags, name);
+ GNUNET_free (flags);
+ GNUNET_free (name);
+ return ret;
+ }
default:
return NULL;
}
@@ -141,7 +159,43 @@ messenger_string_to_value (void *cls,
*data_size = sizeof(struct GNUNET_MESSENGER_RoomEntryRecord);
return GNUNET_OK;
}
+ case GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_DETAILS:
+ {
+ char flags [7];
+ const char *dash;
+
+ if ((NULL == (dash = strchr (s, '-'))) ||
+ (1 != sscanf (s, "%7s-", flags)) ||
+ (strlen (dash + 1) > 256))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Unable to parse MESSENGER_ROOM_DETAILS record `%s'\n"),
+ s);
+ return GNUNET_SYSERR;
+ }
+
+ struct GNUNET_MESSENGER_RoomDetailsRecord *record = GNUNET_new (
+ struct GNUNET_MESSENGER_RoomDetailsRecord
+ );
+
+ if (GNUNET_OK != GNUNET_STRINGS_string_to_data (flags,
+ strlen (flags),
+ &(record->flags),
+ sizeof(uint32_t)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Unable to parse MESSENGER_ROOM_DETAILS record `%s'\n"),
+ s);
+ GNUNET_free (record);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_memcpy(record->name, dash + 1, strlen(dash + 1));
+
+ *data = record;
+ *data_size = sizeof(struct GNUNET_MESSENGER_RoomDetailsRecord);
+ return GNUNET_OK;
+ }
default:
return GNUNET_SYSERR;
}
@@ -158,6 +212,7 @@ static struct
uint32_t number;
} name_map[] = {
{ "MESSENGER_ROOM_ENTRY", GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY },
+ { "MESSENGER_ROOM_DETAILS", GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_DETAILS },
{ NULL, UINT32_MAX }
};