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