aboutsummaryrefslogtreecommitdiff
path: root/src/messenger/gnunet-service-messenger_message_send.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/messenger/gnunet-service-messenger_message_send.c')
-rw-r--r--src/messenger/gnunet-service-messenger_message_send.c197
1 files changed, 0 insertions, 197 deletions
diff --git a/src/messenger/gnunet-service-messenger_message_send.c b/src/messenger/gnunet-service-messenger_message_send.c
deleted file mode 100644
index 5c3f9ecc5..000000000
--- a/src/messenger/gnunet-service-messenger_message_send.c
+++ /dev/null
@@ -1,197 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2020--2023 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 src/messenger/gnunet-service-messenger_message_send.c
23 * @brief GNUnet MESSENGER service
24 */
25
26#include "platform.h"
27#include "gnunet-service-messenger_message_send.h"
28
29#include "gnunet-service-messenger_handle.h"
30#include "gnunet-service-messenger_member.h"
31#include "gnunet-service-messenger_member_session.h"
32#include "gnunet-service-messenger_operation.h"
33#include "gnunet-service-messenger_room.h"
34
35struct GNUNET_MESSENGER_MemberNotify
36{
37 struct GNUNET_MESSENGER_SrvRoom *room;
38 struct GNUNET_MESSENGER_SrvHandle *handle;
39 struct GNUNET_MESSENGER_MemberSession *session;
40};
41
42static void
43notify_about_members (struct GNUNET_MESSENGER_MemberNotify *notify,
44 struct GNUNET_MESSENGER_MemberSession *session,
45 struct GNUNET_CONTAINER_MultiHashMap *map,
46 int check_permission)
47{
48 if (session->prev)
49 notify_about_members (notify, session->prev, map, GNUNET_YES);
50
51 struct GNUNET_MESSENGER_MessageStore *message_store =
52 get_srv_room_message_store (notify->room);
53 struct GNUNET_MESSENGER_ListMessage *element;
54
55 for (element = session->messages.head; element; element = element->next)
56 {
57 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (map,
58 &(element->hash)))
59 continue;
60
61 if ((GNUNET_YES == check_permission) &&
62 (GNUNET_YES != check_member_session_history (notify->session,
63 &(element->hash),
64 GNUNET_NO)))
65 continue;
66
67 if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (map, &(element->hash),
68 NULL,
69 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
70 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
71 "Notification of session message could be duplicated!\n");
72
73 const struct GNUNET_MESSENGER_Message *message = get_store_message (
74 message_store, &(element->hash));
75
76 if ((! message) || (GNUNET_YES == is_peer_message (message)))
77 continue;
78
79 struct GNUNET_MESSENGER_SenderSession sender;
80 sender.member = session;
81
82 notify_srv_handle_message (notify->handle, notify->room, &sender, message,
83 &(element->hash));
84 }
85}
86
87
88static int
89iterate_notify_about_members (void *cls,
90 const struct
91 GNUNET_IDENTITY_PublicKey *public_key,
92 struct GNUNET_MESSENGER_MemberSession *session)
93{
94 struct GNUNET_MESSENGER_MemberNotify *notify = cls;
95
96 if ((notify->session == session) || (GNUNET_YES ==
97 is_member_session_completed (session)))
98 return GNUNET_YES;
99
100 struct GNUNET_CONTAINER_MultiHashMap *map =
101 GNUNET_CONTAINER_multihashmap_create (4, GNUNET_NO);
102
103 notify_about_members (notify, session, map, GNUNET_NO);
104
105 GNUNET_CONTAINER_multihashmap_destroy (map);
106 return GNUNET_YES;
107}
108
109
110void
111send_message_join (struct GNUNET_MESSENGER_SrvRoom *room,
112 struct GNUNET_MESSENGER_SrvHandle *handle,
113 const struct GNUNET_MESSENGER_Message *message,
114 const struct GNUNET_HashCode *hash)
115{
116 set_srv_handle_key (handle, &(message->body.join.key));
117
118 struct GNUNET_MESSENGER_MemberStore *member_store =
119 get_srv_room_member_store (room);
120 struct GNUNET_MESSENGER_Member *member = add_store_member (member_store,
121 &(message->header.
122 sender_id));
123
124 struct GNUNET_MESSENGER_MemberSession *session = get_member_session_of (
125 member, message, hash);
126
127 if (! session)
128 {
129 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
130 "A valid session is required to join a room!\n");
131 goto skip_member_notification;
132 }
133
134 struct GNUNET_MESSENGER_MemberNotify notify;
135
136 notify.room = room;
137 notify.handle = handle;
138 notify.session = session;
139
140 iterate_store_members (get_srv_room_member_store (room),
141 iterate_notify_about_members, &notify);
142
143skip_member_notification:
144 check_srv_room_peer_status (room, NULL);
145}
146
147
148void
149send_message_key (struct GNUNET_MESSENGER_SrvRoom *room,
150 struct GNUNET_MESSENGER_SrvHandle *handle,
151 const struct GNUNET_MESSENGER_Message *message,
152 const struct GNUNET_HashCode *hash)
153{
154 set_srv_handle_key (handle, &(message->body.key.key));
155}
156
157
158void
159send_message_peer (struct GNUNET_MESSENGER_SrvRoom *room,
160 struct GNUNET_MESSENGER_SrvHandle *handle,
161 const struct GNUNET_MESSENGER_Message *message,
162 const struct GNUNET_HashCode *hash)
163{
164 if (! room->peer_message)
165 room->peer_message = GNUNET_new (struct GNUNET_HashCode);
166
167 GNUNET_memcpy (room->peer_message, hash, sizeof(struct GNUNET_HashCode));
168}
169
170
171void
172send_message_id (struct GNUNET_MESSENGER_SrvRoom *room,
173 struct GNUNET_MESSENGER_SrvHandle *handle,
174 const struct GNUNET_MESSENGER_Message *message,
175 const struct GNUNET_HashCode *hash)
176{
177 change_srv_handle_member_id (handle, get_srv_room_key (room),
178 &(message->body.id.id));
179}
180
181
182void
183send_message_request (struct GNUNET_MESSENGER_SrvRoom *room,
184 struct GNUNET_MESSENGER_SrvHandle *handle,
185 const struct GNUNET_MESSENGER_Message *message,
186 const struct GNUNET_HashCode *hash)
187{
188 struct GNUNET_MESSENGER_OperationStore *operation_store =
189 get_srv_room_operation_store (room);
190
191 use_store_operation (
192 operation_store,
193 &(message->body.request.hash),
194 GNUNET_MESSENGER_OP_REQUEST,
195 GNUNET_MESSENGER_REQUEST_DELAY
196 );
197}