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