[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] 03/04: MESSENGER: Fix handle id initialization and add local co
From: |
gnunet |
Subject: |
[gnunet] 03/04: MESSENGER: Fix handle id initialization and add local contact id |
Date: |
Fri, 17 Nov 2023 00:59:48 +0100 |
This is an automated email from the git hooks/post-receive script.
thejackimonster pushed a commit to branch master
in repository gnunet.
commit 70de9fb2ce39ac74ed7e59a6c448ecb98c830073
Author: TheJackiMonster <thejackimonster@gmail.com>
AuthorDate: Fri Nov 17 00:55:56 2023 +0100
MESSENGER: Fix handle id initialization and add local contact id
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
---
src/include/gnunet_messenger_service.h | 9 +++
src/service/messenger/gnunet-service-messenger.c | 2 +-
.../messenger/gnunet-service-messenger_handle.c | 74 ----------------------
.../messenger/gnunet-service-messenger_service.c | 73 +++++++++++++++++++++
src/service/messenger/messenger_api.c | 11 ++++
src/service/messenger/messenger_api_contact.c | 13 +++-
src/service/messenger/messenger_api_contact.h | 14 +++-
.../messenger/messenger_api_contact_store.c | 4 +-
.../messenger/messenger_api_contact_store.h | 2 +
9 files changed, 124 insertions(+), 78 deletions(-)
diff --git a/src/include/gnunet_messenger_service.h
b/src/include/gnunet_messenger_service.h
index 9e389350a..dbe2d6ced 100644
--- a/src/include/gnunet_messenger_service.h
+++ b/src/include/gnunet_messenger_service.h
@@ -783,6 +783,15 @@ GNUNET_MESSENGER_contact_get_name (const struct
const struct GNUNET_CRYPTO_PublicKey*
GNUNET_MESSENGER_contact_get_key (const struct GNUNET_MESSENGER_Contact
*contact);
+/**
+ * Get the locally unique id of the <i>contact</i>.
+ *
+ * @param[in] contact Contact handle
+ * @return Locally unique contact id or zero
+ */
+size_t
+GNUNET_MESSENGER_contact_get_id (const struct GNUNET_MESSENGER_Contact
*contact);
+
/**
* Send a <i>message</i> into a <i>room</i>. If you opened the <i>room</i> all
entered members will receive the
* <i>message</i>. If you entered the <i>room</i> through a <b>door</b> all so
entered <b>doors</b> will receive the
diff --git a/src/service/messenger/gnunet-service-messenger.c
b/src/service/messenger/gnunet-service-messenger.c
index 8e9805ff0..2d10c60e2 100644
--- a/src/service/messenger/gnunet-service-messenger.c
+++ b/src/service/messenger/gnunet-service-messenger.c
@@ -114,7 +114,7 @@ initialize_handle_via_key (struct
GNUNET_MESSENGER_SrvHandle *handle,
"Initialization failed while reading invalid key!\n");
}
else
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Initialization is missing key!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Initialization is missing key!\n");
}
diff --git a/src/service/messenger/gnunet-service-messenger_handle.c
b/src/service/messenger/gnunet-service-messenger_handle.c
index f5d918636..5a50c9c22 100644
--- a/src/service/messenger/gnunet-service-messenger_handle.c
+++ b/src/service/messenger/gnunet-service-messenger_handle.c
@@ -213,84 +213,12 @@ change_srv_handle_member_id (struct
GNUNET_MESSENGER_SrvHandle *handle,
}
-struct RoomInitializationClosure
-{
- struct GNUNET_MESSENGER_SrvHandle *handle;
- const struct GNUNET_HashCode *key;
- const struct GNUNET_CRYPTO_PublicKey *pubkey;
-};
-
-static int
-find_member_session_in_room (void *cls,
- const struct GNUNET_CRYPTO_PublicKey *public_key,
- struct GNUNET_MESSENGER_MemberSession *session)
-{
- struct RoomInitializationClosure *init = cls;
-
- if (! public_key)
- return GNUNET_YES;
-
- const struct GNUNET_CRYPTO_PublicKey *pubkey = get_srv_handle_key (
- init->handle);
-
- if (0 != GNUNET_memcmp (pubkey, public_key))
- return GNUNET_YES;
-
- const struct GNUNET_ShortHashCode *id = get_member_session_id (session);
-
- if (! id)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initialitation: Missing member id!");
- return GNUNET_NO;
- }
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Initialitation: Matching member found (%s)!\n",
- GNUNET_sh2s (id));
-
- change_srv_handle_member_id (init->handle, init->key, id);
- return GNUNET_NO;
-}
-
-
-static void
-initialize_srv_handle_via_matching_member (struct
- GNUNET_MESSENGER_SrvHandle *handle,
- const struct GNUNET_HashCode *key)
-{
- struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (handle->service,
- key);
- if (! room)
- return;
-
- struct GNUNET_MESSENGER_MemberStore *store = get_srv_room_member_store
(room);
- if (! store)
- return;
-
- const struct GNUNET_CRYPTO_PublicKey *pubkey = get_srv_handle_key (handle);
- if ((! pubkey) || (0 == GNUNET_memcmp (pubkey, get_anonymous_public_key ())))
- return;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Initialize member id of handle via matching member in room!\n");
-
- struct RoomInitializationClosure init;
- init.handle = handle;
- init.key = key;
- init.pubkey = pubkey;
-
- iterate_store_members (store, find_member_session_in_room, &init);
-}
-
-
int
open_srv_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle,
const struct GNUNET_HashCode *key)
{
GNUNET_assert ((handle) && (key));
- initialize_srv_handle_via_matching_member (handle, key);
-
if ((! get_srv_handle_member_id (handle, key)) && (GNUNET_YES !=
create_handle_member_id (
handle, key)))
@@ -307,8 +235,6 @@ entry_srv_handle_room (struct GNUNET_MESSENGER_SrvHandle
*handle,
{
GNUNET_assert ((handle) && (door) && (key));
- initialize_srv_handle_via_matching_member (handle, key);
-
if ((! get_srv_handle_member_id (handle, key)) && (GNUNET_YES !=
create_handle_member_id (
handle, key)))
diff --git a/src/service/messenger/gnunet-service-messenger_service.c
b/src/service/messenger/gnunet-service-messenger_service.c
index 63d487db9..981223be5 100644
--- a/src/service/messenger/gnunet-service-messenger_service.c
+++ b/src/service/messenger/gnunet-service-messenger_service.c
@@ -228,6 +228,72 @@ get_service_room (const struct GNUNET_MESSENGER_Service
*service,
}
+struct HandleInitializationClosure
+{
+ struct GNUNET_MESSENGER_SrvHandle *handle;
+ struct GNUNET_MESSENGER_SrvRoom *room;
+ const struct GNUNET_CRYPTO_PublicKey *pubkey;
+};
+
+static int
+find_member_session_in_room (void *cls,
+ const struct GNUNET_CRYPTO_PublicKey *public_key,
+ struct GNUNET_MESSENGER_MemberSession *session)
+{
+ struct HandleInitializationClosure *init = cls;
+
+ if (! public_key)
+ return GNUNET_YES;
+
+ const struct GNUNET_CRYPTO_PublicKey *pubkey = get_srv_handle_key (
+ init->handle);
+
+ if (0 != GNUNET_memcmp (pubkey, public_key))
+ return GNUNET_YES;
+
+ const struct GNUNET_ShortHashCode *id = get_member_session_id (session);
+
+ if (! id)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initialitation: Missing member id!");
+ return GNUNET_NO;
+ }
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Initialitation: Matching member found (%s)!\n",
+ GNUNET_sh2s (id));
+
+ change_srv_handle_member_id (init->handle, get_srv_room_key(init->room), id);
+ return GNUNET_NO;
+}
+
+
+static void
+initialize_service_handle (struct GNUNET_MESSENGER_SrvHandle *handle,
+ struct GNUNET_MESSENGER_SrvRoom *room)
+{
+ GNUNET_assert ((handle) && (room));
+
+ struct GNUNET_MESSENGER_MemberStore *store = get_srv_room_member_store
(room);
+ if (! store)
+ return;
+
+ const struct GNUNET_CRYPTO_PublicKey *pubkey = get_srv_handle_key (handle);
+ if ((! pubkey) || (0 == GNUNET_memcmp (pubkey, get_anonymous_public_key ())))
+ return;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Initialize member id of handle via matching member in room!\n");
+
+ struct HandleInitializationClosure init;
+ init.handle = handle;
+ init.room = room;
+ init.pubkey = pubkey;
+
+ iterate_store_members (store, find_member_session_in_room, &init);
+}
+
+
int
open_service_room (struct GNUNET_MESSENGER_Service *service,
struct GNUNET_MESSENGER_SrvHandle *handle,
@@ -238,9 +304,13 @@ open_service_room (struct GNUNET_MESSENGER_Service
*service,
struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (service, key);
if (room)
+ {
+ initialize_service_handle (handle, room);
return open_srv_room (room, handle);
+ }
room = create_srv_room (handle, key);
+ initialize_service_handle (handle, room);
if ((GNUNET_YES == open_srv_room (room, handle)) &&
(GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (service->rooms,
@@ -265,6 +335,8 @@ entry_service_room (struct GNUNET_MESSENGER_Service
*service,
if (room)
{
+ initialize_service_handle (handle, room);
+
if (GNUNET_YES == enter_srv_room_at (room, handle, door))
return GNUNET_YES;
else
@@ -272,6 +344,7 @@ entry_service_room (struct GNUNET_MESSENGER_Service
*service,
}
room = create_srv_room (handle, key);
+ initialize_service_handle (handle, room);
if ((GNUNET_YES == enter_srv_room_at (room, handle, door)) &&
(GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (service->rooms,
diff --git a/src/service/messenger/messenger_api.c
b/src/service/messenger/messenger_api.c
index e796e4bad..d7cca918a 100644
--- a/src/service/messenger/messenger_api.c
+++ b/src/service/messenger/messenger_api.c
@@ -1027,6 +1027,17 @@ GNUNET_MESSENGER_contact_get_key (const struct
}
+size_t
+GNUNET_MESSENGER_contact_get_id (const struct
+ GNUNET_MESSENGER_Contact *contact)
+{
+ if (! contact)
+ return 0;
+
+ return get_contact_id(contact);
+}
+
+
void
GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room,
struct GNUNET_MESSENGER_Message *message,
diff --git a/src/service/messenger/messenger_api_contact.c
b/src/service/messenger/messenger_api_contact.c
index 848a27b8f..47733fe07 100644
--- a/src/service/messenger/messenger_api_contact.c
+++ b/src/service/messenger/messenger_api_contact.c
@@ -27,7 +27,8 @@
#include "messenger_api_contact.h"
struct GNUNET_MESSENGER_Contact*
-create_contact (const struct GNUNET_CRYPTO_PublicKey *key)
+create_contact (const struct GNUNET_CRYPTO_PublicKey *key,
+ size_t unique_id)
{
GNUNET_assert (key);
@@ -36,6 +37,7 @@ create_contact (const struct GNUNET_CRYPTO_PublicKey *key)
contact->name = NULL;
contact->rc = 0;
+ contact->id = unique_id;
GNUNET_memcpy (&(contact->public_key), key, sizeof(contact->public_key));
@@ -107,6 +109,15 @@ decrease_contact_rc (struct GNUNET_MESSENGER_Contact
*contact)
}
+size_t
+get_contact_id (const struct GNUNET_MESSENGER_Contact *contact)
+{
+ GNUNET_assert (contact);
+
+ return contact->id;
+}
+
+
void
get_context_from_member (const struct GNUNET_HashCode *key,
const struct GNUNET_ShortHashCode *id,
diff --git a/src/service/messenger/messenger_api_contact.h
b/src/service/messenger/messenger_api_contact.h
index 4463aa746..b2e3fc364 100644
--- a/src/service/messenger/messenger_api_contact.h
+++ b/src/service/messenger/messenger_api_contact.h
@@ -34,6 +34,7 @@ struct GNUNET_MESSENGER_Contact
{
char *name;
size_t rc;
+ size_t id;
struct GNUNET_CRYPTO_PublicKey public_key;
};
@@ -42,10 +43,12 @@ struct GNUNET_MESSENGER_Contact
* Creates and allocates a new contact with a given public <i>key</i> from an
EGO.
*
* @param[in] key Public key
+ * @param[in] unique_id Locally unique identifier
* @return New contact
*/
struct GNUNET_MESSENGER_Contact*
-create_contact (const struct GNUNET_CRYPTO_PublicKey *key);
+create_contact (const struct GNUNET_CRYPTO_PublicKey *key,
+ size_t unique_id);
/**
* Destroys a contact and frees its memory fully.
@@ -101,6 +104,15 @@ increase_contact_rc (struct GNUNET_MESSENGER_Contact
*contact);
int
decrease_contact_rc (struct GNUNET_MESSENGER_Contact *contact);
+/**
+ * Returns the locally unique identifier of a given <i>contact</i>.
+ *
+ * @param[in] contact contact Contact
+ * @return Locally unique identifier of contact
+ */
+size_t
+get_contact_id (const struct GNUNET_MESSENGER_Contact *contact);
+
/**
* Calculates the context <i>hash</i> of a member in a room and returns it.
*
diff --git a/src/service/messenger/messenger_api_contact_store.c
b/src/service/messenger/messenger_api_contact_store.c
index 8bcfb24ff..60bd2974f 100644
--- a/src/service/messenger/messenger_api_contact_store.c
+++ b/src/service/messenger/messenger_api_contact_store.c
@@ -36,6 +36,8 @@ init_contact_store (struct GNUNET_MESSENGER_ContactStore
*store)
store->anonymous = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO);
store->contacts = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO);
+
+ store->counter = 0;
}
@@ -136,7 +138,7 @@ get_store_contact (struct GNUNET_MESSENGER_ContactStore
*store,
return contact;
}
- contact = create_contact (pubkey);
+ contact = create_contact (pubkey, ++(store->counter));
if (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (map, &hash, contact,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
diff --git a/src/service/messenger/messenger_api_contact_store.h
b/src/service/messenger/messenger_api_contact_store.h
index 03912e985..4520e0a47 100644
--- a/src/service/messenger/messenger_api_contact_store.h
+++ b/src/service/messenger/messenger_api_contact_store.h
@@ -36,6 +36,8 @@ struct GNUNET_MESSENGER_ContactStore
{
struct GNUNET_CONTAINER_MultiHashMap *anonymous;
struct GNUNET_CONTAINER_MultiHashMap *contacts;
+
+ size_t counter;
};
/**
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.