gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet] 06/08: MESSENGER: Store recipient information for each message


From: gnunet
Subject: [gnunet] 06/08: MESSENGER: Store recipient information for each message locally
Date: Sat, 20 Jan 2024 10:08:35 +0100

This is an automated email from the git hooks/post-receive script.

thejackimonster pushed a commit to branch master
in repository gnunet.

commit f44e76ba4266f88422110e7c2cae03b3a757453c
Author: TheJackiMonster <thejackimonster@gmail.com>
AuthorDate: Sat Jan 20 07:58:57 2024 +0100

    MESSENGER: Store recipient information for each message locally
    
    Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
---
 src/include/gnunet_messenger_service.h     | 14 ++++++++++++++
 src/service/messenger/messenger_api.c      | 15 +++++++++++++--
 src/service/messenger/messenger_api_room.c | 17 +++++++++++++++++
 src/service/messenger/messenger_api_room.h | 15 +++++++++++++++
 4 files changed, 59 insertions(+), 2 deletions(-)

diff --git a/src/include/gnunet_messenger_service.h 
b/src/include/gnunet_messenger_service.h
index c0c724795..e0ccea27a 100644
--- a/src/include/gnunet_messenger_service.h
+++ b/src/include/gnunet_messenger_service.h
@@ -891,6 +891,20 @@ const struct GNUNET_MESSENGER_Contact*
 GNUNET_MESSENGER_get_sender (const struct GNUNET_MESSENGER_Room *room,
                              const struct GNUNET_HashCode *hash);
 
+/**
+ * Get the contact of a member in a <i>room</i> which has been targeted as 
recipient of a specific message identified 
+ * with a given <i>hash</i>.
+ *
+ * Notice that contacts are independent of rooms but will be removed if all 
rooms containing these contacts get closed.
+ *
+ * @param[in] room Room handle
+ * @param[in] hash Hash identifying a message
+ * @return Contact handle, NULL otherwise
+ */
+const struct GNUNET_MESSENGER_Contact*
+GNUNET_MESSENGER_get_recipient (const struct GNUNET_MESSENGER_Room *room,
+                                const struct GNUNET_HashCode *hash);
+
 /**
  * Get the name used by the <i>contact</i>.
  *
diff --git a/src/service/messenger/messenger_api.c 
b/src/service/messenger/messenger_api.c
index ea0d6bca5..4f8e7230c 100644
--- a/src/service/messenger/messenger_api.c
+++ b/src/service/messenger/messenger_api.c
@@ -350,8 +350,8 @@ handle_recv_message (void *cls,
   recipient = get_store_contact(store, context, recipient_key);
 
 skip_recipient:
-  contact = handle_room_message (room, contact, private_message ?
-                                  private_message : &message, hash, flags);
+  contact = handle_room_message (room, contact, recipient, private_message ?
+                                 private_message : &message, hash, flags);
 
   const struct GNUNET_MESSENGER_Message *stored_message = get_room_message (
     room, hash);
@@ -1070,6 +1070,17 @@ GNUNET_MESSENGER_get_sender (const struct 
GNUNET_MESSENGER_Room *room,
 }
 
 
+const struct GNUNET_MESSENGER_Contact*
+GNUNET_MESSENGER_get_recipient (const struct GNUNET_MESSENGER_Room *room,
+                                const struct GNUNET_HashCode *hash)
+{
+  if ((! room) || (! hash))
+    return NULL;
+
+  return get_room_recipient (room, hash);
+}
+
+
 const char*
 GNUNET_MESSENGER_contact_get_name (const struct
                                    GNUNET_MESSENGER_Contact *contact)
diff --git a/src/service/messenger/messenger_api_room.c 
b/src/service/messenger/messenger_api_room.c
index a3b8ae520..e7de430ae 100644
--- a/src/service/messenger/messenger_api_room.c
+++ b/src/service/messenger/messenger_api_room.c
@@ -178,6 +178,21 @@ get_room_sender (const struct GNUNET_MESSENGER_Room *room,
 }
 
 
+struct GNUNET_MESSENGER_Contact*
+get_room_recipient (const struct GNUNET_MESSENGER_Room *room,
+                    const struct GNUNET_HashCode *hash)
+{
+  GNUNET_assert ((room) && (hash));
+
+  struct GNUNET_MESSENGER_RoomMessageEntry *entry =
+    GNUNET_CONTAINER_multihashmap_get (
+      room->messages, hash
+      );
+
+  return (entry? entry->recipient : NULL);
+}
+
+
 static struct GNUNET_MESSENGER_Contact*
 handle_join_message (struct GNUNET_MESSENGER_Room *room,
                      struct GNUNET_MESSENGER_Contact *sender,
@@ -354,6 +369,7 @@ handle_delete_message (struct GNUNET_MESSENGER_Room *room,
 struct GNUNET_MESSENGER_Contact*
 handle_room_message (struct GNUNET_MESSENGER_Room *room,
                      struct GNUNET_MESSENGER_Contact *sender,
+                     struct GNUNET_MESSENGER_Contact *recipient,
                      const struct GNUNET_MESSENGER_Message *message,
                      const struct GNUNET_HashCode *hash,
                      enum GNUNET_MESSENGER_MessageFlags flags)
@@ -396,6 +412,7 @@ handle_room_message (struct GNUNET_MESSENGER_Room *room,
     return sender;
 
   entry->sender = sender;
+  entry->recipient = recipient;
   entry->message = copy_message (message);
 
   if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (room->messages, hash,
diff --git a/src/service/messenger/messenger_api_room.h 
b/src/service/messenger/messenger_api_room.h
index 56bfbbf5a..855405337 100644
--- a/src/service/messenger/messenger_api_room.h
+++ b/src/service/messenger/messenger_api_room.h
@@ -37,6 +37,7 @@
 struct GNUNET_MESSENGER_RoomMessageEntry
 {
   struct GNUNET_MESSENGER_Contact *sender;
+  struct GNUNET_MESSENGER_Contact *recipient;
   struct GNUNET_MESSENGER_Message *message;
 };
 
@@ -132,6 +133,18 @@ struct GNUNET_MESSENGER_Contact*
 get_room_sender (const struct GNUNET_MESSENGER_Room *room,
                  const struct GNUNET_HashCode *hash);
 
+/**
+ * Returns a messages recipient locally stored from a map for a given 
<i>hash</i> in a <i>room</i>. If no
+ * matching message is found or the message has not been privately received, 
NULL gets returned.
+ *
+ * @param[in] room Room
+ * @param[in] hash Hash of message
+ * @return Contact of recipient or NULL
+ */
+struct GNUNET_MESSENGER_Contact*
+get_room_recipient (const struct GNUNET_MESSENGER_Room *room,
+                    const struct GNUNET_HashCode *hash);
+
 /**
  * Handles a <i>message</i> with a given <i>hash</i> in a <i>room</i> for the 
client API to update
  * members and its information. The function also stores the message in map 
locally for access afterwards.
@@ -141,6 +154,7 @@ get_room_sender (const struct GNUNET_MESSENGER_Room *room,
  *
  * @param[in,out] room Room
  * @param[in,out] sender Contact of sender
+ * @param[in,out] recipient Contact of recipient
  * @param[in] message Message
  * @param[in] hash Hash of message
  * @param[in] flags Flags of message
@@ -149,6 +163,7 @@ get_room_sender (const struct GNUNET_MESSENGER_Room *room,
 struct GNUNET_MESSENGER_Contact*
 handle_room_message (struct GNUNET_MESSENGER_Room *room,
                      struct GNUNET_MESSENGER_Contact *sender,
+                     struct GNUNET_MESSENGER_Contact *recipient,
                      const struct GNUNET_MESSENGER_Message *message,
                      const struct GNUNET_HashCode *hash,
                      enum GNUNET_MESSENGER_MessageFlags flags);

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]