aboutsummaryrefslogtreecommitdiff
path: root/src/messenger/gnunet-service-messenger_message_recv.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/messenger/gnunet-service-messenger_message_recv.c')
-rw-r--r--src/messenger/gnunet-service-messenger_message_recv.c229
1 files changed, 0 insertions, 229 deletions
diff --git a/src/messenger/gnunet-service-messenger_message_recv.c b/src/messenger/gnunet-service-messenger_message_recv.c
deleted file mode 100644
index e445c4e79..000000000
--- a/src/messenger/gnunet-service-messenger_message_recv.c
+++ /dev/null
@@ -1,229 +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_recv.c
23 * @brief GNUnet MESSENGER service
24 */
25
26#include "platform.h"
27#include "gnunet-service-messenger_message_recv.h"
28
29#include "gnunet-service-messenger_message_kind.h"
30#include "gnunet-service-messenger_operation.h"
31
32static void
33forward_about_members (struct GNUNET_MESSENGER_SrvRoom *room,
34 struct GNUNET_MESSENGER_SrvTunnel *tunnel,
35 struct GNUNET_MESSENGER_MemberSession *session,
36 struct GNUNET_CONTAINER_MultiHashMap *map)
37{
38 if (session->prev)
39 forward_about_members (room, tunnel, session->prev, map);
40
41 struct GNUNET_MESSENGER_MessageStore *message_store =
42 get_srv_room_message_store (room);
43 struct GNUNET_MESSENGER_ListMessage *element;
44
45 for (element = session->messages.head; element; element = element->next)
46 {
47 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (map,
48 &(element->hash)))
49 continue;
50
51 if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (map, &(element->hash),
52 NULL,
53 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
54 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
55 "Forwarding of session message could be duplicated!\n");
56
57 const struct GNUNET_MESSENGER_Message *message = get_store_message (
58 message_store, &(element->hash));
59
60 if (message)
61 forward_tunnel_message (tunnel, message, &(element->hash));
62 }
63}
64
65
66static int
67iterate_forward_members (void *cls,
68 const struct GNUNET_IDENTITY_PublicKey *public_key,
69 struct GNUNET_MESSENGER_MemberSession *session)
70{
71 struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls;
72
73 if (GNUNET_YES == is_member_session_completed (session))
74 return GNUNET_YES;
75
76 struct GNUNET_CONTAINER_MultiHashMap *map =
77 GNUNET_CONTAINER_multihashmap_create (4, GNUNET_NO);
78
79 forward_about_members (tunnel->room, tunnel, session, map);
80
81 GNUNET_CONTAINER_multihashmap_destroy (map);
82 return GNUNET_YES;
83}
84
85
86int
87recv_message_info (struct GNUNET_MESSENGER_SrvRoom *room,
88 struct GNUNET_MESSENGER_SrvTunnel *tunnel,
89 const struct GNUNET_MESSENGER_Message *message,
90 const struct GNUNET_HashCode *hash)
91{
92 const uint32_t version = get_tunnel_messenger_version (tunnel);
93
94 if (GNUNET_OK != update_tunnel_messenger_version (tunnel,
95 message->body.info.
96 messenger_version))
97 {
98 disconnect_tunnel (tunnel);
99 return GNUNET_NO;
100 }
101
102 if (version == get_tunnel_messenger_version (tunnel))
103 return GNUNET_NO;
104
105 if (room->host)
106 send_tunnel_message (tunnel, room->host, create_message_info (
107 room->service));
108
109 struct GNUNET_PeerIdentity peer;
110 get_tunnel_peer_identity (tunnel, &peer);
111
112 if (GNUNET_YES != contains_list_tunnels (&(room->basement), &peer))
113 {
114 struct GNUNET_MESSENGER_MessageStore *message_store =
115 get_srv_room_message_store (room);
116
117 struct GNUNET_MESSENGER_ListTunnel *element;
118 for (element = room->basement.head; element; element = element->next)
119 {
120 if (! element->hash)
121 continue;
122
123 const struct GNUNET_MESSENGER_Message *message = get_store_message (
124 message_store, element->hash);
125
126 if (message)
127 forward_tunnel_message (tunnel, message, element->hash);
128 }
129 }
130
131 if (GNUNET_YES != contains_list_tunnels (&(room->basement), &peer))
132 {
133 struct GNUNET_MESSENGER_MemberStore *member_store =
134 get_srv_room_member_store (room);
135
136 iterate_store_members (member_store, iterate_forward_members, tunnel);
137 }
138
139 check_srv_room_peer_status (room, tunnel);
140 return GNUNET_NO;
141}
142
143
144int
145recv_message_peer (struct GNUNET_MESSENGER_SrvRoom *room,
146 struct GNUNET_MESSENGER_SrvTunnel *tunnel,
147 const struct GNUNET_MESSENGER_Message *message,
148 const struct GNUNET_HashCode *hash)
149{
150 struct GNUNET_PeerIdentity peer;
151 GNUNET_PEER_resolve (tunnel->peer, &peer);
152
153 if (0 == GNUNET_memcmp (&peer, &(message->body.peer.peer)))
154 {
155 if (! tunnel->peer_message)
156 tunnel->peer_message = GNUNET_new (struct GNUNET_HashCode);
157
158 GNUNET_memcpy (tunnel->peer_message, &hash, sizeof(hash));
159 }
160
161 update_to_list_tunnels (&(room->basement), &(message->body.peer.peer), hash);
162 return GNUNET_YES;
163}
164
165
166static void
167callback_found_message (void *cls,
168 struct GNUNET_MESSENGER_SrvRoom *room,
169 const struct GNUNET_MESSENGER_Message *message,
170 const struct GNUNET_HashCode *hash)
171{
172 struct GNUNET_MESSENGER_SrvTunnel *tunnel = tunnel;
173
174 if (! message)
175 {
176 struct GNUNET_MESSENGER_OperationStore *operation_store =
177 get_srv_room_operation_store (room);
178
179 use_store_operation (
180 operation_store,
181 hash,
182 GNUNET_MESSENGER_OP_REQUEST,
183 GNUNET_MESSENGER_REQUEST_DELAY
184 );
185 }
186 else
187 forward_tunnel_message (tunnel, message, hash);
188}
189
190
191/*
192 * Function returns GNUNET_NO to drop forwarding the request.
193 * It will only be forwarded if it can't be answered!
194 */
195int
196recv_message_request (struct GNUNET_MESSENGER_SrvRoom *room,
197 struct GNUNET_MESSENGER_SrvTunnel *tunnel,
198 const struct GNUNET_MESSENGER_Message *message,
199 const struct GNUNET_HashCode *hash)
200{
201 struct GNUNET_MESSENGER_MemberStore *member_store =
202 get_srv_room_member_store (room);
203 struct GNUNET_MESSENGER_Member *member = get_store_member_of (member_store,
204 message);
205
206 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Request for message (%s)\n",
207 GNUNET_h2s (hash));
208
209 if (! member)
210 return GNUNET_NO;
211
212 struct GNUNET_MESSENGER_MemberSession *session = get_member_session_of (
213 member, message, hash);
214
215 if ((! session) || (GNUNET_YES != check_member_session_history (session,
216 &(message->
217 body.request
218 .hash),
219 GNUNET_NO)))
220 return GNUNET_NO;
221
222 if (GNUNET_NO == request_srv_room_message (room,
223 &(message->body.request.hash),
224 session, callback_found_message,
225 tunnel))
226 return GNUNET_YES;
227
228 return GNUNET_NO;
229}