gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet] branch master updated: MESSENGER: Implement function to send ti


From: gnunet
Subject: [gnunet] branch master updated: MESSENGER: Implement function to send ticket
Date: Wed, 03 Jan 2024 05:07:52 +0100

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

thejackimonster pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new 61fac3162 MESSENGER: Implement function to send ticket
61fac3162 is described below

commit 61fac3162ec489060f5f3c15a37ec0c65856996e
Author: TheJackiMonster <thejackimonster@gmail.com>
AuthorDate: Wed Jan 3 05:07:41 2024 +0100

    MESSENGER: Implement function to send ticket
    
    Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
---
 src/include/gnunet_messenger_service.h |  17 ++++
 src/service/messenger/messenger_api.c  | 159 ++++++++++++++++++++++++++-------
 2 files changed, 144 insertions(+), 32 deletions(-)

diff --git a/src/include/gnunet_messenger_service.h 
b/src/include/gnunet_messenger_service.h
index ad4151aed..5457e8ddb 100644
--- a/src/include/gnunet_messenger_service.h
+++ b/src/include/gnunet_messenger_service.h
@@ -43,6 +43,7 @@ extern "C" {
 #include "gnunet_configuration_lib.h"
 #include "gnunet_identity_service.h"
 #include "gnunet_reclaim_lib.h"
+#include "gnunet_reclaim_service.h"
 #include "gnunet_scheduler_lib.h"
 #include "gnunet_time_lib.h"
 #include "gnunet_util_lib.h"
@@ -904,6 +905,22 @@ GNUNET_MESSENGER_iterate_members (struct 
GNUNET_MESSENGER_Room *room,
                                   GNUNET_MESSENGER_MemberCallback callback,
                                   void *cls);
 
+/**
+ * Send a <i>ticket</i> into a <i>room</i>. The ticket will automatically be 
converted
+ * into a message to be sent only to its audience as a private message.
+ *
+ * A ticket can only be sent with this function if its issuer's public key is 
the one
+ * being used by the messenger. The audience's public key is not allowed to be 
the
+ * anonymous public key. The room needs to contain a member using the 
audience's public
+ * key.
+ *
+ * @param[in,out] room Room handle
+ * @param[in] ticket Ticket to send
+ */
+void
+GNUNET_MESSENGER_send_ticket (struct GNUNET_MESSENGER_Room *room,
+                              const struct GNUNET_RECLAIM_Ticket *ticket);
+
 #if 0 /* keep Emacsens' auto-indent happy */
 {
 #endif
diff --git a/src/service/messenger/messenger_api.c 
b/src/service/messenger/messenger_api.c
index 6d87a051d..7fd873211 100644
--- a/src/service/messenger/messenger_api.c
+++ b/src/service/messenger/messenger_api.c
@@ -23,11 +23,14 @@
  * @brief messenger api: client implementation of GNUnet MESSENGER service
  */
 
+#include "gnunet_common.h"
 #include "gnunet_identity_service.h"
 #include "gnunet_messenger_service.h"
 
 #include "gnunet-service-messenger.h"
 
+#include "gnunet_reclaim_service.h"
+#include "messenger_api_contact.h"
 #include "messenger_api_handle.h"
 #include "messenger_api_message.h"
 #include "messenger_api_message_kind.h"
@@ -1041,28 +1044,11 @@ GNUNET_MESSENGER_contact_get_id (const struct
 }
 
 
-void
-GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room,
+static void
+send_message_to_room_with_key (struct GNUNET_MESSENGER_Room *room,
                                struct GNUNET_MESSENGER_Message *message,
-                               const struct GNUNET_MESSENGER_Contact *contact)
+                               const struct GNUNET_CRYPTO_PublicKey 
*public_key)
 {
-  if ((! room) || (! message))
-    return;
-
-  switch (filter_message_sending (message))
-  {
-  case GNUNET_SYSERR:
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Sending message aborted: This kind of message is reserved for 
the service!\n");
-    return;
-  case GNUNET_NO:
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "Sending message aborted: This kind of message could cause 
issues!\n");
-    return;
-  default:
-    break;
-  }
-
   char *original_name;
   char *changed_name = NULL;
 
@@ -1084,19 +1070,8 @@ GNUNET_MESSENGER_send_message (struct 
GNUNET_MESSENGER_Room *room,
   }
 
 skip_naming:
-  if (contact)
+  if (public_key)
   {
-    const struct GNUNET_CRYPTO_PublicKey *public_key = get_non_anonymous_key (
-      get_contact_key (contact)
-      );
-
-    if (! public_key)
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                  "Sending message aborted: Invalid key!\n");
-      goto reset_naming;
-    }
-
     struct GNUNET_MESSENGER_Message *original = message;
     message = copy_message (original);
 
@@ -1125,6 +1100,50 @@ reset_naming:
 }
 
 
+void
+GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room,
+                               struct GNUNET_MESSENGER_Message *message,
+                               const struct GNUNET_MESSENGER_Contact *contact)
+{
+  if ((! room) || (! message))
+    return;
+
+  switch (filter_message_sending (message))
+  {
+  case GNUNET_SYSERR:
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Sending message aborted: This kind of message is reserved for 
the service!\n");
+    return;
+  case GNUNET_NO:
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Sending message aborted: This kind of message could cause 
issues!\n");
+    return;
+  default:
+    break;
+  }
+
+  const struct GNUNET_CRYPTO_PublicKey *public_key;
+
+  if (contact)
+  {
+    public_key = get_non_anonymous_key (
+      get_contact_key (contact)
+      );
+
+    if (! public_key)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                  "Sending message aborted: Invalid key!\n");
+      return;
+    }
+  }
+  else
+    public_key = NULL;
+
+  send_message_to_room_with_key (room, message, public_key);
+}
+
+
 const struct GNUNET_MESSENGER_Message*
 GNUNET_MESSENGER_get_message (const struct GNUNET_MESSENGER_Room *room,
                               const struct GNUNET_HashCode *hash)
@@ -1160,3 +1179,79 @@ GNUNET_MESSENGER_iterate_members (struct 
GNUNET_MESSENGER_Room *room,
 
   return iterate_room_members (room, callback, cls);
 }
+
+
+struct GNUNET_MESSENGER_CheckTicket
+{
+  const struct GNUNET_CRYPTO_PublicKey *audience;
+  enum GNUNET_GenericReturnValue result;
+};
+
+
+static enum GNUNET_GenericReturnValue
+check_ticket_audience (void *cls,
+                       struct GNUNET_MESSENGER_Room *room,
+                       const struct GNUNET_MESSENGER_Contact *contact)
+{
+  struct GNUNET_MESSENGER_CheckTicket *check = cls;
+
+  const struct GNUNET_CRYPTO_PublicKey *key;
+  key = get_contact_key(contact);
+
+  if (0 == GNUNET_memcmp(key, check->audience))
+  {
+    check->result = GNUNET_YES;
+    return GNUNET_NO;
+  }
+
+  return GNUNET_YES;
+}
+
+
+void
+GNUNET_MESSENGER_send_ticket (struct GNUNET_MESSENGER_Room *room,
+                              const struct GNUNET_RECLAIM_Ticket *ticket)
+{
+  if ((! room) || (! ticket))
+    return;
+
+  const struct GNUNET_CRYPTO_PublicKey *pubkey;
+  pubkey = get_handle_pubkey(room->handle);
+
+  if (0 != GNUNET_memcmp(pubkey, &(ticket->identity)))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Sending ticket aborted: Invalid identity!\n");
+    return;
+  }
+
+  struct GNUNET_MESSENGER_CheckTicket check;
+  check.audience = &(ticket->audience);
+  check.result = GNUNET_NO;
+
+  const int members = iterate_room_members (
+    room, 
+    check_ticket_audience, 
+    &check);
+  
+  if ((! members) || (GNUNET_YES != check.result))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Sending ticket aborted: Audience not found!\n");
+    return;
+  }
+
+  struct GNUNET_MESSENGER_Message *message = create_message_ticket(
+    &(ticket->rnd)
+  );
+
+  if (! message)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Sending ticket aborted: Message creation failed!\n");
+    return;
+  }
+
+  send_message_to_room_with_key (room, message, &(ticket->audience));
+  destroy_message (message);
+}

-- 
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]