commit c11052c64b020d3913014b6065c9b16a8cac4547
parent 937d01213ab94cd0f4697b81cecc860f36cc7bfb
Author: Jacki <jacki@thejackimonster.de>
Date: Thu, 4 Jan 2024 23:21:53 +0100
Manage tickets per contact internally when received
Signed-off-by: Jacki <jacki@thejackimonster.de>
Diffstat:
7 files changed, 187 insertions(+), 2 deletions(-)
diff --git a/src/gnunet_chat_contact.c b/src/gnunet_chat_contact.c
@@ -25,6 +25,7 @@
#include "gnunet_chat_contact.h"
#include "gnunet_chat_context.h"
#include "gnunet_chat_handle.h"
+#include "gnunet_chat_ticket.h"
#include "gnunet_chat_contact_intern.c"
@@ -104,6 +105,22 @@ contact_destroy (struct GNUNET_CHAT_Contact* contact)
{
GNUNET_assert(contact);
+ struct GNUNET_CHAT_InternalTickets *tickets;
+ while (contact->tickets_head)
+ {
+ tickets = contact->tickets_head;
+
+ GNUNET_CONTAINER_DLL_remove(
+ contact->tickets_head,
+ contact->tickets_tail,
+ tickets
+ );
+
+ ticket_destroy(tickets->ticket);
+
+ GNUNET_free(tickets);
+ }
+
if (contact->public_key)
GNUNET_free(contact->public_key);
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c
@@ -29,6 +29,7 @@
#include "gnunet_chat_handle.h"
#include "gnunet_chat_invitation.h"
#include "gnunet_chat_message.h"
+#include "gnunet_chat_ticket.h"
#include "gnunet_chat_util.h"
#include <gnunet/gnunet_common.h>
@@ -47,6 +48,7 @@ static const char gnunet_service_name_gns [] = "gns";
static const char gnunet_service_name_identity [] = "identity";
static const char gnunet_service_name_messenger [] = "messenger";
static const char gnunet_service_name_namestore [] = "namestore";
+static const char gnunet_service_name_reclaim [] = "reclaim";
void
on_handle_shutdown(void *cls)
@@ -97,6 +99,12 @@ on_handle_arm_connection(void *cls,
GNUNET_OS_INHERIT_STD_NONE,
NULL, NULL
);
+
+ GNUNET_ARM_request_service_start(
+ chat->arm, gnunet_service_name_reclaim,
+ GNUNET_OS_INHERIT_STD_NONE,
+ NULL, NULL
+ );
} else {
GNUNET_ARM_request_service_start(
chat->arm, gnunet_service_name_arm,
@@ -919,6 +927,32 @@ on_handle_message (void *cls,
);
break;
}
+ case GNUNET_MESSENGER_KIND_TICKET:
+ {
+ struct GNUNET_CHAT_InternalTickets *tickets = GNUNET_new(
+ struct GNUNET_CHAT_InternalTickets
+ );
+
+ if (!tickets)
+ break;
+
+ tickets->ticket = ticket_create_from_message(
+ handle, sender, &(msg->body.ticket)
+ );
+
+ if (!tickets->ticket)
+ {
+ GNUNET_free(tickets);
+ break;
+ }
+
+ GNUNET_CONTAINER_DLL_insert_tail(
+ contact->tickets_head,
+ contact->tickets_tail,
+ tickets
+ );
+ break;
+ }
default:
break;
}
diff --git a/src/gnunet_chat_invitation.h b/src/gnunet_chat_invitation.h
@@ -39,7 +39,7 @@ struct GNUNET_CHAT_Invitation
};
/**
- * Creates a chat invitation from a invite body in a
+ * Creates a chat invitation from an invite body in a
* <i>message</i> with a selected chat <i>context</i>.
*
* @param[in,out] context Chat context
diff --git a/src/gnunet_chat_ticket.c b/src/gnunet_chat_ticket.c
@@ -0,0 +1,64 @@
+/*
+ This file is part of GNUnet.
+ Copyright (C) 2024 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
+ by the Free Software Foundation, either version 3 of the License,
+ or (at your option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ SPDX-License-Identifier: AGPL3.0-or-later
+ */
+/*
+ * @author Tobias Frisch
+ * @file gnunet_chat_ticket.c
+ */
+
+#include "gnunet_chat_ticket.h"
+
+#include "gnunet_chat_handle.h"
+#include <gnunet/gnunet_messenger_service.h>
+
+struct GNUNET_CHAT_Ticket*
+ticket_create_from_message (struct GNUNET_CHAT_Handle *handle,
+ const struct GNUNET_MESSENGER_Contact *issuer,
+ const struct GNUNET_MESSENGER_MessageTicket *message)
+{
+ GNUNET_assert((handle) && (issuer) && (message));
+
+ const struct GNUNET_CRYPTO_PublicKey *identity;
+ const struct GNUNET_CRYPTO_PublicKey *audience;
+
+ identity = GNUNET_MESSENGER_contact_get_key(issuer);
+ audience = GNUNET_MESSENGER_get_key(handle->messenger);
+
+ if ((!identity) || (!audience))
+ return NULL;
+
+ struct GNUNET_CHAT_Ticket *ticket = GNUNET_new(struct GNUNET_CHAT_Ticket);
+
+ ticket->handle = handle;
+ ticket->issuer = issuer;
+
+ GNUNET_memcpy(&(ticket->ticket.identity), identity, sizeof(ticket->ticket.identity));
+ GNUNET_memcpy(&(ticket->ticket.audience), audience, sizeof(ticket->ticket.audience));
+ GNUNET_memcpy(&(ticket->ticket.rnd), &(message->identifier), sizeof(ticket->ticket.rnd));
+
+ return ticket;
+}
+
+void
+ticket_destroy (struct GNUNET_CHAT_Ticket *ticket)
+{
+ GNUNET_assert(ticket);
+
+ GNUNET_free(ticket);
+}
diff --git a/src/gnunet_chat_ticket.h b/src/gnunet_chat_ticket.h
@@ -0,0 +1,66 @@
+/*
+ This file is part of GNUnet.
+ Copyright (C) 2024 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
+ by the Free Software Foundation, either version 3 of the License,
+ or (at your option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ SPDX-License-Identifier: AGPL3.0-or-later
+ */
+/*
+ * @author Tobias Frisch
+ * @file gnunet_chat_ticket.h
+ */
+
+#ifndef GNUNET_CHAT_TICKET_H_
+#define GNUNET_CHAT_TICKET_H_
+
+#include <gnunet/gnunet_messenger_service.h>
+#include <gnunet/gnunet_reclaim_service.h>
+#include <gnunet/gnunet_util_lib.h>
+
+struct GNUNET_CHAT_Handle;
+
+struct GNUNET_CHAT_Ticket
+{
+ struct GNUNET_CHAT_Handle *handle;
+
+ const struct GNUNET_MESSENGER_Contact *issuer;
+
+ struct GNUNET_RECLAIM_Ticket ticket;
+};
+
+/**
+ * Creates a chat ticket from a ticket body in a
+ * <i>message</i> received by a chat <i>handle</i>
+ * from a given <i>issuer</i>.
+ *
+ * @param[in,out] handle Chat handle
+ * @param[in,out] issuer Messenger contact
+ * @param[in] message Ticket message body
+ * @return New chat ticket
+ */
+struct GNUNET_CHAT_Ticket*
+ticket_create_from_message (struct GNUNET_CHAT_Handle *handle,
+ const struct GNUNET_MESSENGER_Contact *issuer,
+ const struct GNUNET_MESSENGER_MessageTicket *message);
+
+/**
+ * Destroys a chat <i>ticket</i> and frees its memory.
+ *
+ * @param[in,out] ticket Chat ticket
+ */
+void
+ticket_destroy (struct GNUNET_CHAT_Ticket *ticket);
+
+#endif /* GNUNET_CHAT_TICKET_H_ */
diff --git a/src/gnunet_chat_util.c b/src/gnunet_chat_util.c
@@ -23,6 +23,7 @@
*/
#include "gnunet_chat_util.h"
+#include <gnunet/gnunet_messenger_service.h>
static const char label_prefix_of_contact [] = "contact";
static const char label_prefix_of_group [] = "group";
@@ -420,6 +421,8 @@ util_message_kind_from_kind (enum GNUNET_MESSENGER_MessageKind kind)
return GNUNET_CHAT_KIND_WHISPER;
case GNUNET_MESSENGER_KIND_DELETE:
return GNUNET_CHAT_KIND_DELETION;
+ case GNUNET_MESSENGER_KIND_TICKET:
+ return GNUNET_CHAT_KIND_CONTACT;
default:
return GNUNET_CHAT_KIND_UNKNOWN;
}
diff --git a/src/meson.build b/src/meson.build
@@ -1,6 +1,6 @@
#
# This file is part of GNUnet.
-# Copyright (C) 2023 GNUnet e.V.
+# Copyright (C) 2023--2024 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
@@ -28,6 +28,7 @@ gnunetchat_sources = files([
'gnunet_chat_invitation.c', 'gnunet_chat_invitation.h',
'gnunet_chat_lobby.c', 'gnunet_chat_lobby.h',
'gnunet_chat_message.c', 'gnunet_chat_message.h',
+ 'gnunet_chat_ticket.c', 'gnunet_chat_ticket.h',
'gnunet_chat_uri.c', 'gnunet_chat_uri.h',
'gnunet_chat_util.c', 'gnunet_chat_util.h',
'gnunet_chat_lib.c',