aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacki <jacki@thejackimonster.de>2024-01-04 23:21:53 +0100
committerJacki <jacki@thejackimonster.de>2024-01-04 23:21:53 +0100
commitc11052c64b020d3913014b6065c9b16a8cac4547 (patch)
treeab1c3aade96c1eb462e15ce7d3a8acaead9d782a
parent937d01213ab94cd0f4697b81cecc860f36cc7bfb (diff)
downloadlibgnunetchat-c11052c64b020d3913014b6065c9b16a8cac4547.tar.gz
libgnunetchat-c11052c64b020d3913014b6065c9b16a8cac4547.zip
Manage tickets per contact internally when received
Signed-off-by: Jacki <jacki@thejackimonster.de>
-rw-r--r--src/gnunet_chat_contact.c17
-rw-r--r--src/gnunet_chat_handle_intern.c34
-rw-r--r--src/gnunet_chat_invitation.h2
-rw-r--r--src/gnunet_chat_ticket.c64
-rw-r--r--src/gnunet_chat_ticket.h66
-rw-r--r--src/gnunet_chat_util.c3
-rw-r--r--src/meson.build3
7 files changed, 187 insertions, 2 deletions
diff --git a/src/gnunet_chat_contact.c b/src/gnunet_chat_contact.c
index c4c813f..bde6669 100644
--- a/src/gnunet_chat_contact.c
+++ b/src/gnunet_chat_contact.c
@@ -25,6 +25,7 @@
25#include "gnunet_chat_contact.h" 25#include "gnunet_chat_contact.h"
26#include "gnunet_chat_context.h" 26#include "gnunet_chat_context.h"
27#include "gnunet_chat_handle.h" 27#include "gnunet_chat_handle.h"
28#include "gnunet_chat_ticket.h"
28 29
29#include "gnunet_chat_contact_intern.c" 30#include "gnunet_chat_contact_intern.c"
30 31
@@ -104,6 +105,22 @@ contact_destroy (struct GNUNET_CHAT_Contact* contact)
104{ 105{
105 GNUNET_assert(contact); 106 GNUNET_assert(contact);
106 107
108 struct GNUNET_CHAT_InternalTickets *tickets;
109 while (contact->tickets_head)
110 {
111 tickets = contact->tickets_head;
112
113 GNUNET_CONTAINER_DLL_remove(
114 contact->tickets_head,
115 contact->tickets_tail,
116 tickets
117 );
118
119 ticket_destroy(tickets->ticket);
120
121 GNUNET_free(tickets);
122 }
123
107 if (contact->public_key) 124 if (contact->public_key)
108 GNUNET_free(contact->public_key); 125 GNUNET_free(contact->public_key);
109 126
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c
index f9bc0fe..46243f8 100644
--- a/src/gnunet_chat_handle_intern.c
+++ b/src/gnunet_chat_handle_intern.c
@@ -29,6 +29,7 @@
29#include "gnunet_chat_handle.h" 29#include "gnunet_chat_handle.h"
30#include "gnunet_chat_invitation.h" 30#include "gnunet_chat_invitation.h"
31#include "gnunet_chat_message.h" 31#include "gnunet_chat_message.h"
32#include "gnunet_chat_ticket.h"
32#include "gnunet_chat_util.h" 33#include "gnunet_chat_util.h"
33 34
34#include <gnunet/gnunet_common.h> 35#include <gnunet/gnunet_common.h>
@@ -47,6 +48,7 @@ static const char gnunet_service_name_gns [] = "gns";
47static const char gnunet_service_name_identity [] = "identity"; 48static const char gnunet_service_name_identity [] = "identity";
48static const char gnunet_service_name_messenger [] = "messenger"; 49static const char gnunet_service_name_messenger [] = "messenger";
49static const char gnunet_service_name_namestore [] = "namestore"; 50static const char gnunet_service_name_namestore [] = "namestore";
51static const char gnunet_service_name_reclaim [] = "reclaim";
50 52
51void 53void
52on_handle_shutdown(void *cls) 54on_handle_shutdown(void *cls)
@@ -97,6 +99,12 @@ on_handle_arm_connection(void *cls,
97 GNUNET_OS_INHERIT_STD_NONE, 99 GNUNET_OS_INHERIT_STD_NONE,
98 NULL, NULL 100 NULL, NULL
99 ); 101 );
102
103 GNUNET_ARM_request_service_start(
104 chat->arm, gnunet_service_name_reclaim,
105 GNUNET_OS_INHERIT_STD_NONE,
106 NULL, NULL
107 );
100 } else { 108 } else {
101 GNUNET_ARM_request_service_start( 109 GNUNET_ARM_request_service_start(
102 chat->arm, gnunet_service_name_arm, 110 chat->arm, gnunet_service_name_arm,
@@ -919,6 +927,32 @@ on_handle_message (void *cls,
919 ); 927 );
920 break; 928 break;
921 } 929 }
930 case GNUNET_MESSENGER_KIND_TICKET:
931 {
932 struct GNUNET_CHAT_InternalTickets *tickets = GNUNET_new(
933 struct GNUNET_CHAT_InternalTickets
934 );
935
936 if (!tickets)
937 break;
938
939 tickets->ticket = ticket_create_from_message(
940 handle, sender, &(msg->body.ticket)
941 );
942
943 if (!tickets->ticket)
944 {
945 GNUNET_free(tickets);
946 break;
947 }
948
949 GNUNET_CONTAINER_DLL_insert_tail(
950 contact->tickets_head,
951 contact->tickets_tail,
952 tickets
953 );
954 break;
955 }
922 default: 956 default:
923 break; 957 break;
924 } 958 }
diff --git a/src/gnunet_chat_invitation.h b/src/gnunet_chat_invitation.h
index ec1656c..0d54c07 100644
--- a/src/gnunet_chat_invitation.h
+++ b/src/gnunet_chat_invitation.h
@@ -39,7 +39,7 @@ struct GNUNET_CHAT_Invitation
39}; 39};
40 40
41/** 41/**
42 * Creates a chat invitation from a invite body in a 42 * Creates a chat invitation from an invite body in a
43 * <i>message</i> with a selected chat <i>context</i>. 43 * <i>message</i> with a selected chat <i>context</i>.
44 * 44 *
45 * @param[in,out] context Chat context 45 * @param[in,out] context Chat context
diff --git a/src/gnunet_chat_ticket.c b/src/gnunet_chat_ticket.c
new file mode 100644
index 0000000..332b4ae
--- /dev/null
+++ b/src/gnunet_chat_ticket.c
@@ -0,0 +1,64 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2024 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/*
21 * @author Tobias Frisch
22 * @file gnunet_chat_ticket.c
23 */
24
25#include "gnunet_chat_ticket.h"
26
27#include "gnunet_chat_handle.h"
28#include <gnunet/gnunet_messenger_service.h>
29
30struct GNUNET_CHAT_Ticket*
31ticket_create_from_message (struct GNUNET_CHAT_Handle *handle,
32 const struct GNUNET_MESSENGER_Contact *issuer,
33 const struct GNUNET_MESSENGER_MessageTicket *message)
34{
35 GNUNET_assert((handle) && (issuer) && (message));
36
37 const struct GNUNET_CRYPTO_PublicKey *identity;
38 const struct GNUNET_CRYPTO_PublicKey *audience;
39
40 identity = GNUNET_MESSENGER_contact_get_key(issuer);
41 audience = GNUNET_MESSENGER_get_key(handle->messenger);
42
43 if ((!identity) || (!audience))
44 return NULL;
45
46 struct GNUNET_CHAT_Ticket *ticket = GNUNET_new(struct GNUNET_CHAT_Ticket);
47
48 ticket->handle = handle;
49 ticket->issuer = issuer;
50
51 GNUNET_memcpy(&(ticket->ticket.identity), identity, sizeof(ticket->ticket.identity));
52 GNUNET_memcpy(&(ticket->ticket.audience), audience, sizeof(ticket->ticket.audience));
53 GNUNET_memcpy(&(ticket->ticket.rnd), &(message->identifier), sizeof(ticket->ticket.rnd));
54
55 return ticket;
56}
57
58void
59ticket_destroy (struct GNUNET_CHAT_Ticket *ticket)
60{
61 GNUNET_assert(ticket);
62
63 GNUNET_free(ticket);
64}
diff --git a/src/gnunet_chat_ticket.h b/src/gnunet_chat_ticket.h
new file mode 100644
index 0000000..a2827ed
--- /dev/null
+++ b/src/gnunet_chat_ticket.h
@@ -0,0 +1,66 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2024 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/*
21 * @author Tobias Frisch
22 * @file gnunet_chat_ticket.h
23 */
24
25#ifndef GNUNET_CHAT_TICKET_H_
26#define GNUNET_CHAT_TICKET_H_
27
28#include <gnunet/gnunet_messenger_service.h>
29#include <gnunet/gnunet_reclaim_service.h>
30#include <gnunet/gnunet_util_lib.h>
31
32struct GNUNET_CHAT_Handle;
33
34struct GNUNET_CHAT_Ticket
35{
36 struct GNUNET_CHAT_Handle *handle;
37
38 const struct GNUNET_MESSENGER_Contact *issuer;
39
40 struct GNUNET_RECLAIM_Ticket ticket;
41};
42
43/**
44 * Creates a chat ticket from a ticket body in a
45 * <i>message</i> received by a chat <i>handle</i>
46 * from a given <i>issuer</i>.
47 *
48 * @param[in,out] handle Chat handle
49 * @param[in,out] issuer Messenger contact
50 * @param[in] message Ticket message body
51 * @return New chat ticket
52 */
53struct GNUNET_CHAT_Ticket*
54ticket_create_from_message (struct GNUNET_CHAT_Handle *handle,
55 const struct GNUNET_MESSENGER_Contact *issuer,
56 const struct GNUNET_MESSENGER_MessageTicket *message);
57
58/**
59 * Destroys a chat <i>ticket</i> and frees its memory.
60 *
61 * @param[in,out] ticket Chat ticket
62 */
63void
64ticket_destroy (struct GNUNET_CHAT_Ticket *ticket);
65
66#endif /* GNUNET_CHAT_TICKET_H_ */
diff --git a/src/gnunet_chat_util.c b/src/gnunet_chat_util.c
index cbd45de..bce5dae 100644
--- a/src/gnunet_chat_util.c
+++ b/src/gnunet_chat_util.c
@@ -23,6 +23,7 @@
23 */ 23 */
24 24
25#include "gnunet_chat_util.h" 25#include "gnunet_chat_util.h"
26#include <gnunet/gnunet_messenger_service.h>
26 27
27static const char label_prefix_of_contact [] = "contact"; 28static const char label_prefix_of_contact [] = "contact";
28static const char label_prefix_of_group [] = "group"; 29static const char label_prefix_of_group [] = "group";
@@ -420,6 +421,8 @@ util_message_kind_from_kind (enum GNUNET_MESSENGER_MessageKind kind)
420 return GNUNET_CHAT_KIND_WHISPER; 421 return GNUNET_CHAT_KIND_WHISPER;
421 case GNUNET_MESSENGER_KIND_DELETE: 422 case GNUNET_MESSENGER_KIND_DELETE:
422 return GNUNET_CHAT_KIND_DELETION; 423 return GNUNET_CHAT_KIND_DELETION;
424 case GNUNET_MESSENGER_KIND_TICKET:
425 return GNUNET_CHAT_KIND_CONTACT;
423 default: 426 default:
424 return GNUNET_CHAT_KIND_UNKNOWN; 427 return GNUNET_CHAT_KIND_UNKNOWN;
425 } 428 }
diff --git a/src/meson.build b/src/meson.build
index 2c8420d..cbeb4d3 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -1,6 +1,6 @@
1# 1#
2# This file is part of GNUnet. 2# This file is part of GNUnet.
3# Copyright (C) 2023 GNUnet e.V. 3# Copyright (C) 2023--2024 GNUnet e.V.
4# 4#
5# GNUnet is free software: you can redistribute it and/or modify it 5# GNUnet is free software: you can redistribute it and/or modify it
6# under the terms of the GNU Affero General Public License as published 6# under the terms of the GNU Affero General Public License as published
@@ -28,6 +28,7 @@ gnunetchat_sources = files([
28 'gnunet_chat_invitation.c', 'gnunet_chat_invitation.h', 28 'gnunet_chat_invitation.c', 'gnunet_chat_invitation.h',
29 'gnunet_chat_lobby.c', 'gnunet_chat_lobby.h', 29 'gnunet_chat_lobby.c', 'gnunet_chat_lobby.h',
30 'gnunet_chat_message.c', 'gnunet_chat_message.h', 30 'gnunet_chat_message.c', 'gnunet_chat_message.h',
31 'gnunet_chat_ticket.c', 'gnunet_chat_ticket.h',
31 'gnunet_chat_uri.c', 'gnunet_chat_uri.h', 32 'gnunet_chat_uri.c', 'gnunet_chat_uri.h',
32 'gnunet_chat_util.c', 'gnunet_chat_util.h', 33 'gnunet_chat_util.c', 'gnunet_chat_util.h',
33 'gnunet_chat_lib.c', 34 'gnunet_chat_lib.c',