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.c185
1 files changed, 0 insertions, 185 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 4e96cf552..000000000
--- a/src/messenger/gnunet-service-messenger_message_recv.c
+++ /dev/null
@@ -1,185 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2020--2022 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 "gnunet-service-messenger_message_recv.h"
27
28#include "gnunet-service-messenger_operation.h"
29
30static void
31forward_about_members (struct GNUNET_MESSENGER_SrvRoom *room,
32 struct GNUNET_MESSENGER_SrvTunnel *tunnel,
33 struct GNUNET_MESSENGER_MemberSession *session,
34 struct GNUNET_CONTAINER_MultiHashMap *map)
35{
36 if (session->prev)
37 forward_about_members (room, tunnel, session->prev, map);
38
39 struct GNUNET_MESSENGER_MessageStore *message_store = get_srv_room_message_store(room);
40 struct GNUNET_MESSENGER_ListMessage *element;
41
42 for (element = session->messages.head; element; element = element->next)
43 {
44 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(map, &(element->hash)))
45 continue;
46
47 if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put(map, &(element->hash), NULL,
48 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
49 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Forwarding of session message could be duplicated!\n");
50
51 const struct GNUNET_MESSENGER_Message *message = get_store_message(message_store, &(element->hash));
52
53 if (message)
54 forward_tunnel_message(tunnel, message, &(element->hash));
55 }
56}
57
58static int
59iterate_forward_members (void *cls,
60 const struct GNUNET_IDENTITY_PublicKey *public_key,
61 struct GNUNET_MESSENGER_MemberSession *session)
62{
63 struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls;
64
65 if (GNUNET_YES == is_member_session_completed(session))
66 return GNUNET_YES;
67
68 struct GNUNET_CONTAINER_MultiHashMap *map = GNUNET_CONTAINER_multihashmap_create(4, GNUNET_NO);
69
70 forward_about_members (tunnel->room, tunnel, session, map);
71
72 GNUNET_CONTAINER_multihashmap_destroy(map);
73 return GNUNET_YES;
74}
75
76int
77recv_message_info (struct GNUNET_MESSENGER_SrvRoom *room,
78 struct GNUNET_MESSENGER_SrvTunnel *tunnel,
79 const struct GNUNET_MESSENGER_Message *message,
80 const struct GNUNET_HashCode *hash)
81{
82 const uint32_t version = get_tunnel_messenger_version(tunnel);
83
84 if (GNUNET_OK != update_tunnel_messenger_version(tunnel, message->body.info.messenger_version))
85 {
86 disconnect_tunnel(tunnel);
87 return GNUNET_NO;
88 }
89
90 if (version == get_tunnel_messenger_version(tunnel))
91 return GNUNET_NO;
92
93 if (room->host)
94 {
95 const struct GNUNET_MESSENGER_Ego *ego = get_srv_handle_ego(room->host);
96
97 send_tunnel_message (tunnel, room->host, create_message_info(ego));
98 }
99
100 struct GNUNET_PeerIdentity peer;
101 get_tunnel_peer_identity(tunnel, &peer);
102
103 if (GNUNET_YES != contains_list_tunnels(&(room->basement), &peer))
104 {
105 struct GNUNET_MESSENGER_MemberStore *member_store = get_srv_room_member_store(room);
106
107 iterate_store_members(member_store, iterate_forward_members, tunnel);
108 }
109
110 check_srv_room_peer_status(room, tunnel);
111
112 return GNUNET_NO;
113}
114
115int
116recv_message_peer (struct GNUNET_MESSENGER_SrvRoom *room,
117 struct GNUNET_MESSENGER_SrvTunnel *tunnel,
118 const struct GNUNET_MESSENGER_Message *message,
119 const struct GNUNET_HashCode *hash)
120{
121 struct GNUNET_PeerIdentity peer;
122 GNUNET_PEER_resolve (tunnel->peer, &peer);
123
124 if (0 == GNUNET_memcmp(&peer, &(message->body.peer.peer)))
125 {
126 if (!tunnel->peer_message)
127 tunnel->peer_message = GNUNET_new(struct GNUNET_HashCode);
128
129 GNUNET_memcpy(tunnel->peer_message, &hash, sizeof(hash));
130 }
131
132 return GNUNET_YES;
133}
134
135static void
136callback_found_message (void *cls,
137 struct GNUNET_MESSENGER_SrvRoom *room,
138 const struct GNUNET_MESSENGER_Message *message,
139 const struct GNUNET_HashCode *hash)
140{
141 struct GNUNET_MESSENGER_SrvTunnel *tunnel = tunnel;
142
143 if (!message)
144 {
145 struct GNUNET_MESSENGER_OperationStore *operation_store = get_srv_room_operation_store(room);
146
147 use_store_operation(
148 operation_store,
149 hash,
150 GNUNET_MESSENGER_OP_REQUEST,
151 GNUNET_MESSENGER_REQUEST_DELAY
152 );
153 }
154 else
155 forward_tunnel_message (tunnel, message, hash);
156}
157
158/*
159 * Function returns GNUNET_NO to drop forwarding the request.
160 * It will only be forwarded if it can't be answered!
161 */
162int
163recv_message_request (struct GNUNET_MESSENGER_SrvRoom *room,
164 struct GNUNET_MESSENGER_SrvTunnel *tunnel,
165 const struct GNUNET_MESSENGER_Message *message,
166 const struct GNUNET_HashCode *hash)
167{
168 struct GNUNET_MESSENGER_MemberStore *member_store = get_srv_room_member_store(room);
169 struct GNUNET_MESSENGER_Member *member = get_store_member_of(member_store, message);
170
171 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Request for message (%s)\n", GNUNET_h2s (hash));
172
173 if (!member)
174 return GNUNET_NO;
175
176 struct GNUNET_MESSENGER_MemberSession *session = get_member_session_of(member, message, hash);
177
178 if ((!session) || (GNUNET_YES != check_member_session_history(session, hash, GNUNET_NO)))
179 return GNUNET_NO;
180
181 if (GNUNET_NO == request_srv_room_message(room, &(message->body.request.hash), session, callback_found_message, tunnel))
182 return GNUNET_YES;
183
184 return GNUNET_NO;
185}