diff options
Diffstat (limited to 'src/service/messenger/gnunet-service-messenger_room.c')
-rw-r--r-- | src/service/messenger/gnunet-service-messenger_room.c | 856 |
1 files changed, 490 insertions, 366 deletions
diff --git a/src/service/messenger/gnunet-service-messenger_room.c b/src/service/messenger/gnunet-service-messenger_room.c index f2f841c20..49e202a5a 100644 --- a/src/service/messenger/gnunet-service-messenger_room.c +++ b/src/service/messenger/gnunet-service-messenger_room.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 |
@@ -27,7 +27,7 @@ | |||
27 | #include "gnunet-service-messenger_room.h" | 27 | #include "gnunet-service-messenger_room.h" |
28 | 28 | ||
29 | #include "gnunet-service-messenger_member.h" | 29 | #include "gnunet-service-messenger_member.h" |
30 | #include "gnunet-service-messenger_member_session.h" | 30 | #include "gnunet-service-messenger_sender_session.h" |
31 | 31 | ||
32 | #include "gnunet-service-messenger_message_kind.h" | 32 | #include "gnunet-service-messenger_message_kind.h" |
33 | #include "gnunet-service-messenger_message_handle.h" | 33 | #include "gnunet-service-messenger_message_handle.h" |
@@ -38,6 +38,8 @@ | |||
38 | #include "gnunet-service-messenger.h" | 38 | #include "gnunet-service-messenger.h" |
39 | #include "gnunet-service-messenger_service.h" | 39 | #include "gnunet-service-messenger_service.h" |
40 | #include "gnunet-service-messenger_tunnel.h" | 40 | #include "gnunet-service-messenger_tunnel.h" |
41 | |||
42 | #include "messenger_api_message.h" | ||
41 | #include "messenger_api_util.h" | 43 | #include "messenger_api_util.h" |
42 | 44 | ||
43 | static void | 45 | static void |
@@ -47,24 +49,26 @@ struct GNUNET_MESSENGER_SrvRoom* | |||
47 | create_srv_room (struct GNUNET_MESSENGER_SrvHandle *handle, | 49 | create_srv_room (struct GNUNET_MESSENGER_SrvHandle *handle, |
48 | const struct GNUNET_HashCode *key) | 50 | const struct GNUNET_HashCode *key) |
49 | { | 51 | { |
50 | GNUNET_assert((handle) && (key)); | 52 | GNUNET_assert ((handle) && (key)); |
51 | 53 | ||
52 | struct GNUNET_MESSENGER_SrvRoom *room = GNUNET_new(struct GNUNET_MESSENGER_SrvRoom); | 54 | struct GNUNET_MESSENGER_SrvRoom *room = GNUNET_new (struct |
55 | GNUNET_MESSENGER_SrvRoom); | ||
53 | 56 | ||
54 | room->service = handle->service; | 57 | room->service = handle->service; |
55 | room->host = handle; | 58 | room->host = handle; |
56 | room->port = NULL; | 59 | room->port = NULL; |
57 | 60 | ||
58 | GNUNET_memcpy(&(room->key), key, sizeof(struct GNUNET_HashCode)); | 61 | GNUNET_memcpy (&(room->key), key, sizeof(struct GNUNET_HashCode)); |
59 | 62 | ||
60 | room->tunnels = GNUNET_CONTAINER_multipeermap_create (8, GNUNET_NO); | 63 | room->tunnels = GNUNET_CONTAINER_multipeermap_create (8, GNUNET_NO); |
61 | 64 | ||
62 | init_member_store(get_srv_room_member_store(room), room); | 65 | init_peer_store (get_srv_room_peer_store (room)); |
63 | init_message_store (get_srv_room_message_store(room)); | 66 | init_member_store (get_srv_room_member_store (room), room); |
64 | init_operation_store(get_srv_room_operation_store(room), room); | 67 | init_message_store (get_srv_room_message_store (room)); |
68 | init_operation_store (get_srv_room_operation_store (room), room); | ||
65 | 69 | ||
66 | init_list_tunnels (&(room->basement)); | 70 | init_list_tunnels (&(room->basement)); |
67 | init_message_state(&(room->state)); | 71 | init_message_state (&(room->state)); |
68 | 72 | ||
69 | room->peer_message = NULL; | 73 | room->peer_message = NULL; |
70 | 74 | ||
@@ -74,11 +78,13 @@ create_srv_room (struct GNUNET_MESSENGER_SrvHandle *handle, | |||
74 | if (room->service->dir) | 78 | if (room->service->dir) |
75 | load_srv_room (room); | 79 | load_srv_room (room); |
76 | 80 | ||
77 | room->idle = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, idle_request_room_messages, room); | 81 | room->idle = GNUNET_SCHEDULER_add_with_priority ( |
82 | GNUNET_SCHEDULER_PRIORITY_IDLE, idle_request_room_messages, room); | ||
78 | 83 | ||
79 | return room; | 84 | return room; |
80 | } | 85 | } |
81 | 86 | ||
87 | |||
82 | static int | 88 | static int |
83 | iterate_destroy_tunnels (void *cls, | 89 | iterate_destroy_tunnels (void *cls, |
84 | const struct GNUNET_PeerIdentity *key, | 90 | const struct GNUNET_PeerIdentity *key, |
@@ -89,6 +95,7 @@ iterate_destroy_tunnels (void *cls, | |||
89 | return GNUNET_YES; | 95 | return GNUNET_YES; |
90 | } | 96 | } |
91 | 97 | ||
98 | |||
92 | static void | 99 | static void |
93 | handle_room_messages (struct GNUNET_MESSENGER_SrvRoom *room); | 100 | handle_room_messages (struct GNUNET_MESSENGER_SrvRoom *room); |
94 | 101 | ||
@@ -96,7 +103,7 @@ void | |||
96 | destroy_srv_room (struct GNUNET_MESSENGER_SrvRoom *room, | 103 | destroy_srv_room (struct GNUNET_MESSENGER_SrvRoom *room, |
97 | int deletion) | 104 | int deletion) |
98 | { | 105 | { |
99 | GNUNET_assert(room); | 106 | GNUNET_assert (room); |
100 | 107 | ||
101 | if (room->idle) | 108 | if (room->idle) |
102 | { | 109 | { |
@@ -107,10 +114,11 @@ destroy_srv_room (struct GNUNET_MESSENGER_SrvRoom *room, | |||
107 | if (room->port) | 114 | if (room->port) |
108 | GNUNET_CADET_close_port (room->port); | 115 | GNUNET_CADET_close_port (room->port); |
109 | 116 | ||
110 | GNUNET_CONTAINER_multipeermap_iterate (room->tunnels, iterate_destroy_tunnels, NULL); | 117 | GNUNET_CONTAINER_multipeermap_iterate (room->tunnels, iterate_destroy_tunnels, |
118 | NULL); | ||
111 | handle_room_messages (room); | 119 | handle_room_messages (room); |
112 | 120 | ||
113 | if (!(room->service->dir)) | 121 | if (! (room->service->dir)) |
114 | goto skip_saving; | 122 | goto skip_saving; |
115 | 123 | ||
116 | if (GNUNET_YES == deletion) | 124 | if (GNUNET_YES == deletion) |
@@ -119,55 +127,71 @@ destroy_srv_room (struct GNUNET_MESSENGER_SrvRoom *room, | |||
119 | save_srv_room (room); | 127 | save_srv_room (room); |
120 | 128 | ||
121 | skip_saving: | 129 | skip_saving: |
122 | clear_member_store (get_srv_room_member_store(room)); | 130 | clear_peer_store (get_srv_room_peer_store (room)); |
123 | clear_message_store (get_srv_room_message_store(room)); | 131 | clear_member_store (get_srv_room_member_store (room)); |
124 | clear_operation_store(get_srv_room_operation_store(room)); | 132 | clear_message_store (get_srv_room_message_store (room)); |
133 | clear_operation_store (get_srv_room_operation_store (room)); | ||
125 | 134 | ||
126 | GNUNET_CONTAINER_multipeermap_destroy (room->tunnels); | 135 | GNUNET_CONTAINER_multipeermap_destroy (room->tunnels); |
127 | clear_list_tunnels (&(room->basement)); | 136 | clear_list_tunnels (&(room->basement)); |
128 | clear_message_state(&(room->state)); | 137 | clear_message_state (&(room->state)); |
129 | 138 | ||
130 | if (room->peer_message) | 139 | if (room->peer_message) |
131 | GNUNET_free(room->peer_message); | 140 | GNUNET_free (room->peer_message); |
141 | |||
142 | GNUNET_free (room); | ||
143 | } | ||
132 | 144 | ||
133 | GNUNET_free(room); | 145 | |
146 | struct GNUNET_MESSENGER_PeerStore* | ||
147 | get_srv_room_peer_store (struct GNUNET_MESSENGER_SrvRoom *room) | ||
148 | { | ||
149 | GNUNET_assert (room); | ||
150 | |||
151 | return &(room->peer_store); | ||
134 | } | 152 | } |
135 | 153 | ||
154 | |||
136 | struct GNUNET_MESSENGER_MemberStore* | 155 | struct GNUNET_MESSENGER_MemberStore* |
137 | get_srv_room_member_store (struct GNUNET_MESSENGER_SrvRoom *room) | 156 | get_srv_room_member_store (struct GNUNET_MESSENGER_SrvRoom *room) |
138 | { | 157 | { |
139 | GNUNET_assert(room); | 158 | GNUNET_assert (room); |
140 | 159 | ||
141 | return &(room->member_store); | 160 | return &(room->member_store); |
142 | } | 161 | } |
143 | 162 | ||
163 | |||
144 | struct GNUNET_MESSENGER_MessageStore* | 164 | struct GNUNET_MESSENGER_MessageStore* |
145 | get_srv_room_message_store (struct GNUNET_MESSENGER_SrvRoom *room) | 165 | get_srv_room_message_store (struct GNUNET_MESSENGER_SrvRoom *room) |
146 | { | 166 | { |
147 | GNUNET_assert(room); | 167 | GNUNET_assert (room); |
148 | 168 | ||
149 | return &(room->message_store); | 169 | return &(room->message_store); |
150 | } | 170 | } |
151 | 171 | ||
172 | |||
152 | struct GNUNET_MESSENGER_OperationStore* | 173 | struct GNUNET_MESSENGER_OperationStore* |
153 | get_srv_room_operation_store (struct GNUNET_MESSENGER_SrvRoom *room) | 174 | get_srv_room_operation_store (struct GNUNET_MESSENGER_SrvRoom *room) |
154 | { | 175 | { |
155 | GNUNET_assert(room); | 176 | GNUNET_assert (room); |
156 | 177 | ||
157 | return &(room->operation_store); | 178 | return &(room->operation_store); |
158 | } | 179 | } |
159 | 180 | ||
181 | |||
160 | static int | 182 | static int |
161 | send_room_info (struct GNUNET_MESSENGER_SrvRoom *room, | 183 | send_room_info (struct GNUNET_MESSENGER_SrvRoom *room, |
162 | struct GNUNET_MESSENGER_SrvHandle *handle, | 184 | struct GNUNET_MESSENGER_SrvHandle *handle, |
163 | struct GNUNET_MESSENGER_SrvTunnel *tunnel) | 185 | struct GNUNET_MESSENGER_SrvTunnel *tunnel) |
164 | { | 186 | { |
165 | if ((!handle) || (!is_tunnel_connected (tunnel))) | 187 | if ((! handle) || (! is_tunnel_connected (tunnel))) |
166 | return GNUNET_NO; | 188 | return GNUNET_NO; |
167 | 189 | ||
168 | return send_tunnel_message (tunnel, handle, create_message_info (get_srv_handle_ego (handle))); | 190 | return send_tunnel_message (tunnel, handle, create_message_info ( |
191 | room->service)); | ||
169 | } | 192 | } |
170 | 193 | ||
194 | |||
171 | static void* | 195 | static void* |
172 | callback_room_connect (void *cls, | 196 | callback_room_connect (void *cls, |
173 | struct GNUNET_CADET_Channel *channel, | 197 | struct GNUNET_CADET_Channel *channel, |
@@ -178,152 +202,87 @@ callback_room_connect (void *cls, | |||
178 | struct GNUNET_MESSENGER_SrvTunnel *tunnel = create_tunnel (room, source); | 202 | struct GNUNET_MESSENGER_SrvTunnel *tunnel = create_tunnel (room, source); |
179 | 203 | ||
180 | if ((tunnel) && | 204 | if ((tunnel) && |
181 | (GNUNET_OK != GNUNET_CONTAINER_multipeermap_put (room->tunnels, source, tunnel, | 205 | (GNUNET_OK != GNUNET_CONTAINER_multipeermap_put (room->tunnels, source, |
206 | tunnel, | ||
182 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE))) | 207 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE))) |
183 | { | 208 | { |
184 | destroy_tunnel (tunnel); | 209 | destroy_tunnel (tunnel); |
185 | tunnel = NULL; | 210 | tunnel = NULL; |
186 | } | 211 | } |
187 | 212 | ||
188 | if (!tunnel) | 213 | if (! tunnel) |
189 | { | 214 | { |
190 | delayed_disconnect_channel (channel); | 215 | delayed_disconnect_channel (channel); |
191 | return NULL; | 216 | return NULL; |
192 | } | 217 | } |
193 | 218 | ||
194 | bind_tunnel(tunnel, channel); | 219 | bind_tunnel (tunnel, channel); |
195 | 220 | ||
196 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "New tunnel in room (%s) established to peer: %s\n", | 221 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
197 | GNUNET_h2s(get_srv_room_key(room)), GNUNET_i2s (source)); | 222 | "New tunnel in room (%s) established to peer: %s\n", |
223 | GNUNET_h2s (get_srv_room_key (room)), GNUNET_i2s (source)); | ||
198 | 224 | ||
199 | if (GNUNET_YES == send_room_info (room, room->host, tunnel)) | 225 | if (GNUNET_YES == send_room_info (room, room->host, tunnel)) |
200 | return tunnel; | 226 | return tunnel; |
201 | 227 | ||
202 | disconnect_tunnel (tunnel); | 228 | disconnect_tunnel (tunnel); |
203 | 229 | ||
204 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (room->tunnels, source, tunnel)) | 230 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (room->tunnels, source, |
231 | tunnel)) | ||
205 | destroy_tunnel (tunnel); | 232 | destroy_tunnel (tunnel); |
206 | 233 | ||
207 | return NULL; | 234 | return NULL; |
208 | } | 235 | } |
209 | 236 | ||
237 | |||
210 | static int | 238 | static int |
211 | join_room (struct GNUNET_MESSENGER_SrvRoom *room, | 239 | join_room (struct GNUNET_MESSENGER_SrvRoom *room, |
212 | struct GNUNET_MESSENGER_SrvHandle *handle, | 240 | struct GNUNET_MESSENGER_SrvHandle *handle, |
213 | struct GNUNET_MESSENGER_Member *member) | 241 | struct GNUNET_MESSENGER_Member *member, |
242 | const struct GNUNET_ShortHashCode *id) | ||
214 | { | 243 | { |
215 | GNUNET_assert((room) && (handle) && (member)); | 244 | GNUNET_assert ((room) && (handle) && (member)); |
216 | |||
217 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Joining room: %s (%s)\n", GNUNET_h2s (get_srv_room_key (room)), | ||
218 | GNUNET_sh2s (get_member_id(member))); | ||
219 | 245 | ||
220 | const struct GNUNET_ShortHashCode *member_id = get_member_id(member); | 246 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Joining room: %s (%s)\n", GNUNET_h2s ( |
247 | get_srv_room_key (room)), | ||
248 | GNUNET_sh2s (get_member_id (member))); | ||
221 | 249 | ||
222 | if (GNUNET_OK != change_srv_handle_member_id (handle, get_srv_room_key(room), member_id)) | 250 | const struct GNUNET_ShortHashCode *member_id = get_member_id (member); |
223 | return GNUNET_NO; | ||
224 | |||
225 | struct GNUNET_MESSENGER_Message *message = create_message_join (get_srv_handle_ego (handle)); | ||
226 | |||
227 | if (!message) | ||
228 | { | ||
229 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Your join message could not be created!\n"); | ||
230 | 251 | ||
252 | if (GNUNET_OK != change_srv_handle_member_id (handle, get_srv_room_key (room), | ||
253 | member_id)) | ||
231 | return GNUNET_NO; | 254 | return GNUNET_NO; |
232 | } | ||
233 | |||
234 | GNUNET_memcpy(&(message->header.sender_id), member_id, sizeof(*member_id)); | ||
235 | return send_srv_room_message (room, handle, message); | ||
236 | } | ||
237 | |||
238 | struct GNUNET_MESSENGER_MemberNotify | ||
239 | { | ||
240 | struct GNUNET_MESSENGER_SrvRoom *room; | ||
241 | struct GNUNET_MESSENGER_SrvHandle *handle; | ||
242 | struct GNUNET_MESSENGER_MemberSession *session; | ||
243 | }; | ||
244 | |||
245 | static void | ||
246 | notify_about_members (struct GNUNET_MESSENGER_MemberNotify *notify, | ||
247 | struct GNUNET_MESSENGER_MemberSession *session, | ||
248 | struct GNUNET_CONTAINER_MultiHashMap *map, | ||
249 | int check_permission) | ||
250 | { | ||
251 | if (session->prev) | ||
252 | notify_about_members (notify, session->prev, map, GNUNET_YES); | ||
253 | |||
254 | struct GNUNET_MESSENGER_MessageStore *message_store = get_srv_room_message_store(notify->room); | ||
255 | struct GNUNET_MESSENGER_ListMessage *element; | ||
256 | |||
257 | for (element = session->messages.head; element; element = element->next) | ||
258 | { | ||
259 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(map, &(element->hash))) | ||
260 | continue; | ||
261 | |||
262 | if ((GNUNET_YES == check_permission) && | ||
263 | (GNUNET_YES != check_member_session_history(notify->session, &(element->hash), GNUNET_NO))) | ||
264 | continue; | ||
265 | 255 | ||
266 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put(map, &(element->hash), NULL, | 256 | enum GNUNET_GenericReturnValue reset; |
267 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | 257 | if ((! id) || (0 != GNUNET_memcmp (id, member_id))) |
268 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Notification of session message could be duplicated!\n"); | 258 | reset = GNUNET_YES; |
269 | 259 | else | |
270 | const struct GNUNET_MESSENGER_Message *message = get_store_message(message_store, &(element->hash)); | 260 | reset = GNUNET_NO; |
271 | |||
272 | if (message) | ||
273 | notify_srv_handle_message (notify->handle, notify->room, session, message, &(element->hash)); | ||
274 | } | ||
275 | } | ||
276 | |||
277 | static int | ||
278 | iterate_notify_about_members (void *cls, | ||
279 | const struct GNUNET_CRYPTO_PublicKey *public_key, | ||
280 | struct GNUNET_MESSENGER_MemberSession *session) | ||
281 | { | ||
282 | struct GNUNET_MESSENGER_MemberNotify *notify = cls; | ||
283 | |||
284 | if ((notify->session == session) || (GNUNET_YES == is_member_session_completed(session))) | ||
285 | return GNUNET_YES; | ||
286 | |||
287 | struct GNUNET_CONTAINER_MultiHashMap *map = GNUNET_CONTAINER_multihashmap_create(4, GNUNET_NO); | ||
288 | |||
289 | notify_about_members (notify, session, map, GNUNET_NO); | ||
290 | 261 | ||
291 | GNUNET_CONTAINER_multihashmap_destroy(map); | 262 | notify_srv_handle_member_id (handle, room, member_id, reset); |
292 | return GNUNET_YES; | 263 | return GNUNET_YES; |
293 | } | 264 | } |
294 | 265 | ||
266 | |||
295 | static int | 267 | static int |
296 | join_room_locally (struct GNUNET_MESSENGER_SrvRoom *room, | 268 | join_room_locally (struct GNUNET_MESSENGER_SrvRoom *room, |
297 | struct GNUNET_MESSENGER_SrvHandle *handle) | 269 | struct GNUNET_MESSENGER_SrvHandle *handle) |
298 | { | 270 | { |
299 | const struct GNUNET_ShortHashCode *member_id = get_srv_handle_member_id (handle, get_srv_room_key(room)); | 271 | const struct GNUNET_ShortHashCode *member_id = get_srv_handle_member_id ( |
272 | handle, get_srv_room_key (room)); | ||
300 | 273 | ||
301 | struct GNUNET_MESSENGER_MemberStore *member_store = get_srv_room_member_store(room); | 274 | struct GNUNET_MESSENGER_MemberStore *member_store = |
302 | struct GNUNET_MESSENGER_Member *member = add_store_member(member_store, member_id); | 275 | get_srv_room_member_store (room); |
276 | struct GNUNET_MESSENGER_Member *member = add_store_member (member_store, | ||
277 | member_id); | ||
303 | 278 | ||
304 | if (GNUNET_NO == join_room (room, handle, member)) | 279 | if (GNUNET_NO == join_room (room, handle, member, member_id)) |
305 | return GNUNET_NO; | 280 | return GNUNET_NO; |
306 | 281 | ||
307 | const struct GNUNET_MESSENGER_Ego *ego = get_srv_handle_ego(handle); | ||
308 | struct GNUNET_MESSENGER_MemberSession *session = get_member_session (member, &(ego->pub)); | ||
309 | |||
310 | if (!session) | ||
311 | { | ||
312 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "A valid session is required to join a room!\n"); | ||
313 | return GNUNET_NO; | ||
314 | } | ||
315 | |||
316 | struct GNUNET_MESSENGER_MemberNotify notify; | ||
317 | |||
318 | notify.room = room; | ||
319 | notify.handle = handle; | ||
320 | notify.session = session; | ||
321 | |||
322 | iterate_store_members(get_srv_room_member_store(room), iterate_notify_about_members, ¬ify); | ||
323 | |||
324 | return GNUNET_YES; | 282 | return GNUNET_YES; |
325 | } | 283 | } |
326 | 284 | ||
285 | |||
327 | extern int | 286 | extern int |
328 | check_tunnel_message (void *cls, | 287 | check_tunnel_message (void *cls, |
329 | const struct GNUNET_MessageHeader *header); | 288 | const struct GNUNET_MessageHeader *header); |
@@ -340,7 +299,7 @@ int | |||
340 | open_srv_room (struct GNUNET_MESSENGER_SrvRoom *room, | 299 | open_srv_room (struct GNUNET_MESSENGER_SrvRoom *room, |
341 | struct GNUNET_MESSENGER_SrvHandle *handle) | 300 | struct GNUNET_MESSENGER_SrvHandle *handle) |
342 | { | 301 | { |
343 | GNUNET_assert((room) && (handle)); | 302 | GNUNET_assert ((room) && (handle)); |
344 | 303 | ||
345 | if (room->port) | 304 | if (room->port) |
346 | return join_room_locally (room, handle); | 305 | return join_room_locally (room, handle); |
@@ -348,30 +307,40 @@ open_srv_room (struct GNUNET_MESSENGER_SrvRoom *room, | |||
348 | struct GNUNET_CADET_Handle *cadet = get_srv_room_cadet (room); | 307 | struct GNUNET_CADET_Handle *cadet = get_srv_room_cadet (room); |
349 | const struct GNUNET_HashCode *key = get_srv_room_key (room); | 308 | const struct GNUNET_HashCode *key = get_srv_room_key (room); |
350 | 309 | ||
351 | struct GNUNET_MQ_MessageHandler handlers[] = { GNUNET_MQ_hd_var_size(tunnel_message, GNUNET_MESSAGE_TYPE_CADET_CLI, | 310 | struct GNUNET_MQ_MessageHandler handlers[] = { GNUNET_MQ_hd_var_size ( |
352 | struct GNUNET_MessageHeader, NULL), | 311 | tunnel_message, |
353 | GNUNET_MQ_handler_end() }; | 312 | GNUNET_MESSAGE_TYPE_CADET_CLI, |
313 | struct | ||
314 | GNUNET_MessageHeader, NULL), | ||
315 | GNUNET_MQ_handler_end () }; | ||
354 | 316 | ||
355 | struct GNUNET_HashCode port; | 317 | struct GNUNET_HashCode port; |
356 | convert_messenger_key_to_port(key, &port); | 318 | convert_messenger_key_to_port (key, &port); |
357 | room->port = GNUNET_CADET_open_port (cadet, &port, callback_room_connect, room, NULL, callback_tunnel_disconnect, | 319 | room->port = GNUNET_CADET_open_port (cadet, &port, callback_room_connect, |
320 | room, NULL, callback_tunnel_disconnect, | ||
358 | handlers); | 321 | handlers); |
359 | 322 | ||
360 | if (room->port) | 323 | if (room->port) |
361 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Port of room (%s) was opened!\n", | 324 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Port of room (%s) was opened!\n", |
362 | GNUNET_h2s(get_srv_room_key(room))); | 325 | GNUNET_h2s (get_srv_room_key (room))); |
363 | else | 326 | else |
364 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Port of room (%s) could not be opened!\n", | 327 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
365 | GNUNET_h2s(get_srv_room_key(room))); | 328 | "Port of room (%s) could not be opened!\n", |
329 | GNUNET_h2s (get_srv_room_key (room))); | ||
366 | 330 | ||
367 | const struct GNUNET_ShortHashCode *member_id = get_srv_handle_member_id (handle, get_srv_room_key(room)); | 331 | const struct GNUNET_ShortHashCode *member_id = get_srv_handle_member_id ( |
332 | handle, get_srv_room_key (room)); | ||
368 | 333 | ||
369 | struct GNUNET_MESSENGER_MemberStore *member_store = get_srv_room_member_store(room); | 334 | struct GNUNET_MESSENGER_MemberStore *member_store = |
370 | struct GNUNET_MESSENGER_Member *member = add_store_member(member_store, member_id); | 335 | get_srv_room_member_store (room); |
336 | struct GNUNET_MESSENGER_Member *member = add_store_member (member_store, | ||
337 | member_id); | ||
371 | 338 | ||
372 | if ((GNUNET_NO == join_room (room, handle, member)) && (room->port)) | 339 | if ((GNUNET_NO == join_room (room, handle, member, member_id)) && |
340 | (room->port)) | ||
373 | { | 341 | { |
374 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "You could not join the room, therefore it keeps closed!\n"); | 342 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
343 | "You could not join the room, therefore it keeps closed!\n"); | ||
375 | 344 | ||
376 | GNUNET_CADET_close_port (room->port); | 345 | GNUNET_CADET_close_port (room->port); |
377 | room->port = NULL; | 346 | room->port = NULL; |
@@ -379,34 +348,40 @@ open_srv_room (struct GNUNET_MESSENGER_SrvRoom *room, | |||
379 | return GNUNET_NO; | 348 | return GNUNET_NO; |
380 | } | 349 | } |
381 | 350 | ||
382 | struct GNUNET_MESSENGER_Message *peer_msg = create_message_peer (room->service); | 351 | if (! room->port) |
383 | GNUNET_memcpy(&(peer_msg->header.sender_id), member_id, sizeof(*member_id)); | 352 | return GNUNET_NO; |
384 | return (room->port ? send_srv_room_message (room, handle, peer_msg) : GNUNET_NO); | 353 | |
354 | return send_srv_room_message (room, handle, create_message_peer ( | ||
355 | room->service)); | ||
385 | } | 356 | } |
386 | 357 | ||
358 | |||
387 | int | 359 | int |
388 | enter_srv_room_at (struct GNUNET_MESSENGER_SrvRoom *room, | 360 | enter_srv_room_at (struct GNUNET_MESSENGER_SrvRoom *room, |
389 | struct GNUNET_MESSENGER_SrvHandle *handle, | 361 | struct GNUNET_MESSENGER_SrvHandle *handle, |
390 | const struct GNUNET_PeerIdentity *door) | 362 | const struct GNUNET_PeerIdentity *door) |
391 | { | 363 | { |
392 | GNUNET_assert((room) && (handle) && (door)); | 364 | GNUNET_assert ((room) && (handle) && (door)); |
393 | 365 | ||
394 | struct GNUNET_PeerIdentity peer; | 366 | struct GNUNET_PeerIdentity peer; |
395 | 367 | ||
396 | if ((GNUNET_OK == get_service_peer_identity (room->service, &peer)) && | 368 | if ((GNUNET_OK == get_service_peer_identity (room->service, &peer)) && |
397 | (0 == GNUNET_memcmp(&peer, door))) | 369 | (0 == GNUNET_memcmp (&peer, door))) |
398 | return join_room_locally (room, handle); | 370 | return join_room_locally (room, handle); |
399 | 371 | ||
400 | struct GNUNET_MESSENGER_SrvTunnel *tunnel = GNUNET_CONTAINER_multipeermap_get (room->tunnels, door); | 372 | struct GNUNET_MESSENGER_SrvTunnel *tunnel = |
373 | GNUNET_CONTAINER_multipeermap_get (room->tunnels, door); | ||
401 | 374 | ||
402 | if (!tunnel) | 375 | if (! tunnel) |
403 | { | 376 | { |
404 | tunnel = create_tunnel (room, door); | 377 | tunnel = create_tunnel (room, door); |
405 | 378 | ||
406 | if (GNUNET_OK != GNUNET_CONTAINER_multipeermap_put (room->tunnels, door, tunnel, | 379 | if (GNUNET_OK != GNUNET_CONTAINER_multipeermap_put (room->tunnels, door, |
380 | tunnel, | ||
407 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)) | 381 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)) |
408 | { | 382 | { |
409 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "You could not connect to that door!\n"); | 383 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
384 | "You could not connect to that door!\n"); | ||
410 | destroy_tunnel (tunnel); | 385 | destroy_tunnel (tunnel); |
411 | return GNUNET_NO; | 386 | return GNUNET_NO; |
412 | } | 387 | } |
@@ -414,7 +389,8 @@ enter_srv_room_at (struct GNUNET_MESSENGER_SrvRoom *room, | |||
414 | 389 | ||
415 | if (GNUNET_SYSERR == connect_tunnel (tunnel)) | 390 | if (GNUNET_SYSERR == connect_tunnel (tunnel)) |
416 | { | 391 | { |
417 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Connection failure during entrance!\n"); | 392 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
393 | "Connection failure during entrance!\n"); | ||
418 | GNUNET_CONTAINER_multipeermap_remove (room->tunnels, door, tunnel); | 394 | GNUNET_CONTAINER_multipeermap_remove (room->tunnels, door, tunnel); |
419 | destroy_tunnel (tunnel); | 395 | destroy_tunnel (tunnel); |
420 | return GNUNET_NO; | 396 | return GNUNET_NO; |
@@ -423,6 +399,22 @@ enter_srv_room_at (struct GNUNET_MESSENGER_SrvRoom *room, | |||
423 | return join_room_locally (room, handle); | 399 | return join_room_locally (room, handle); |
424 | } | 400 | } |
425 | 401 | ||
402 | |||
403 | static void | ||
404 | sign_srv_room_message_by_peer (const void *cls, | ||
405 | struct GNUNET_MESSENGER_Message *message, | ||
406 | uint16_t length, | ||
407 | char *buffer, | ||
408 | const struct GNUNET_HashCode *hash) | ||
409 | { | ||
410 | const struct GNUNET_MESSENGER_SrvHandle *handle = cls; | ||
411 | |||
412 | GNUNET_assert ((handle) && (handle->service)); | ||
413 | |||
414 | sign_message_by_peer (message, length, buffer, hash, handle->service->config); | ||
415 | } | ||
416 | |||
417 | |||
426 | struct GNUNET_MQ_Envelope* | 418 | struct GNUNET_MQ_Envelope* |
427 | pack_srv_room_message (const struct GNUNET_MESSENGER_SrvRoom *room, | 419 | pack_srv_room_message (const struct GNUNET_MESSENGER_SrvRoom *room, |
428 | const struct GNUNET_MESSENGER_SrvHandle *handle, | 420 | const struct GNUNET_MESSENGER_SrvHandle *handle, |
@@ -430,20 +422,31 @@ pack_srv_room_message (const struct GNUNET_MESSENGER_SrvRoom *room, | |||
430 | struct GNUNET_HashCode *hash, | 422 | struct GNUNET_HashCode *hash, |
431 | int mode) | 423 | int mode) |
432 | { | 424 | { |
433 | GNUNET_assert((room) && (handle) && (message) && (hash)); | 425 | GNUNET_assert ((room) && (handle) && (message) && (hash)); |
434 | 426 | ||
435 | message->header.timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); | 427 | if (GNUNET_YES != is_peer_message (message)) |
428 | return pack_message (message, hash, NULL, mode, NULL); | ||
436 | 429 | ||
437 | const struct GNUNET_ShortHashCode *id = get_srv_handle_member_id (handle, get_srv_room_key(room)); | 430 | message->header.timestamp = GNUNET_TIME_absolute_hton ( |
431 | GNUNET_TIME_absolute_get ()); | ||
438 | 432 | ||
439 | GNUNET_assert(id); | 433 | struct GNUNET_PeerIdentity peer; |
434 | if (GNUNET_OK != get_service_peer_identity (handle->service, &peer)) | ||
435 | return NULL; | ||
440 | 436 | ||
441 | GNUNET_memcpy(&(message->header.sender_id), id, sizeof(struct GNUNET_ShortHashCode)); | 437 | convert_peer_identity_to_id (&peer, &(message->header.sender_id)); |
442 | get_message_state_chain_hash (&(room->state), &(message->header.previous)); | 438 | get_message_state_chain_hash (&(room->state), &(message->header.previous)); |
443 | 439 | ||
444 | return pack_message (message, hash, get_srv_handle_ego (handle), mode); | 440 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
441 | "Packing message with peer signature: %s\n", | ||
442 | GNUNET_sh2s (&(message->header.sender_id))); | ||
443 | |||
444 | message->header.signature.type = htonl (GNUNET_PUBLIC_KEY_TYPE_EDDSA); | ||
445 | return pack_message (message, hash, sign_srv_room_message_by_peer, mode, | ||
446 | handle); | ||
445 | } | 447 | } |
446 | 448 | ||
449 | |||
447 | struct GNUNET_MESSENGER_ClosureSendRoom | 450 | struct GNUNET_MESSENGER_ClosureSendRoom |
448 | { | 451 | { |
449 | struct GNUNET_MESSENGER_SrvRoom *room; | 452 | struct GNUNET_MESSENGER_SrvRoom *room; |
@@ -461,8 +464,8 @@ iterate_send_room_message (void *cls, | |||
461 | { | 464 | { |
462 | struct GNUNET_MESSENGER_SrvTunnel *tunnel = value; | 465 | struct GNUNET_MESSENGER_SrvTunnel *tunnel = value; |
463 | 466 | ||
464 | if ((!is_tunnel_connected (tunnel)) || | 467 | if ((! is_tunnel_connected (tunnel)) || |
465 | (get_tunnel_messenger_version(tunnel) < GNUNET_MESSENGER_VERSION)) | 468 | (get_tunnel_messenger_version (tunnel) < GNUNET_MESSENGER_VERSION)) |
466 | return GNUNET_YES; | 469 | return GNUNET_YES; |
467 | 470 | ||
468 | struct GNUNET_MESSENGER_ClosureSendRoom *closure = cls; | 471 | struct GNUNET_MESSENGER_ClosureSendRoom *closure = cls; |
@@ -474,14 +477,16 @@ iterate_send_room_message (void *cls, | |||
474 | 477 | ||
475 | if (closure->packed == GNUNET_NO) | 478 | if (closure->packed == GNUNET_NO) |
476 | { | 479 | { |
477 | env = pack_srv_room_message (closure->room, closure->handle, closure->message, closure->hash, | 480 | env = pack_srv_room_message (closure->room, closure->handle, |
478 | GNUNET_MESSENGER_PACK_MODE_ENVELOPE); | 481 | closure->message, closure->hash, |
482 | GNUNET_MESSENGER_PACK_MODE_ENVELOPE); | ||
479 | 483 | ||
480 | if (env) | 484 | if (env) |
481 | closure->packed = GNUNET_YES; | 485 | closure->packed = GNUNET_YES; |
482 | } | 486 | } |
483 | else | 487 | else |
484 | env = pack_message (closure->message, NULL, NULL, GNUNET_MESSENGER_PACK_MODE_ENVELOPE); | 488 | env = pack_message (closure->message, NULL, NULL, |
489 | GNUNET_MESSENGER_PACK_MODE_ENVELOPE, NULL); | ||
485 | 490 | ||
486 | if (env) | 491 | if (env) |
487 | send_tunnel_envelope (tunnel, env, closure->hash); | 492 | send_tunnel_envelope (tunnel, env, closure->hash); |
@@ -489,6 +494,7 @@ iterate_send_room_message (void *cls, | |||
489 | return GNUNET_YES; | 494 | return GNUNET_YES; |
490 | } | 495 | } |
491 | 496 | ||
497 | |||
492 | int | 498 | int |
493 | update_room_message (struct GNUNET_MESSENGER_SrvRoom *room, | 499 | update_room_message (struct GNUNET_MESSENGER_SrvRoom *room, |
494 | struct GNUNET_MESSENGER_Message *message, | 500 | struct GNUNET_MESSENGER_Message *message, |
@@ -496,7 +502,6 @@ update_room_message (struct GNUNET_MESSENGER_SrvRoom *room, | |||
496 | 502 | ||
497 | void | 503 | void |
498 | callback_room_handle_message (struct GNUNET_MESSENGER_SrvRoom *room, | 504 | callback_room_handle_message (struct GNUNET_MESSENGER_SrvRoom *room, |
499 | struct GNUNET_MESSENGER_SrvHandle *handle, | ||
500 | const struct GNUNET_MESSENGER_Message *message, | 505 | const struct GNUNET_MESSENGER_Message *message, |
501 | const struct GNUNET_HashCode *hash); | 506 | const struct GNUNET_HashCode *hash); |
502 | 507 | ||
@@ -505,16 +510,15 @@ send_srv_room_message (struct GNUNET_MESSENGER_SrvRoom *room, | |||
505 | struct GNUNET_MESSENGER_SrvHandle *handle, | 510 | struct GNUNET_MESSENGER_SrvHandle *handle, |
506 | struct GNUNET_MESSENGER_Message *message) | 511 | struct GNUNET_MESSENGER_Message *message) |
507 | { | 512 | { |
508 | GNUNET_assert((room) && (handle)); | 513 | GNUNET_assert ((room) && (handle)); |
509 | 514 | ||
510 | if (!message) | 515 | if (! message) |
511 | return GNUNET_NO; | 516 | return GNUNET_NO; |
512 | 517 | ||
513 | if (GNUNET_YES == is_message_session_bound(message)) | 518 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
514 | merge_srv_room_last_messages(room, handle); | 519 | "Sending message from handle in room: %s (%s)\n", |
515 | 520 | GNUNET_h2s (&(room->key)), | |
516 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Sending message from handle with member id: %s\n", | 521 | GNUNET_MESSENGER_name_of_kind (message->header.kind)); |
517 | GNUNET_sh2s(get_srv_handle_member_id(handle, get_srv_room_key(room)))); | ||
518 | 522 | ||
519 | struct GNUNET_HashCode hash; | 523 | struct GNUNET_HashCode hash; |
520 | struct GNUNET_MESSENGER_ClosureSendRoom closure; | 524 | struct GNUNET_MESSENGER_ClosureSendRoom closure; |
@@ -526,10 +530,12 @@ send_srv_room_message (struct GNUNET_MESSENGER_SrvRoom *room, | |||
526 | closure.hash = &hash; | 530 | closure.hash = &hash; |
527 | closure.packed = GNUNET_NO; | 531 | closure.packed = GNUNET_NO; |
528 | 532 | ||
529 | GNUNET_CONTAINER_multipeermap_iterate (room->tunnels, iterate_send_room_message, &closure); | 533 | GNUNET_CONTAINER_multipeermap_iterate (room->tunnels, |
534 | iterate_send_room_message, &closure); | ||
530 | 535 | ||
531 | if (GNUNET_NO == closure.packed) | 536 | if (GNUNET_NO == closure.packed) |
532 | pack_srv_room_message (room, handle, message, &hash, GNUNET_MESSENGER_PACK_MODE_UNKNOWN); | 537 | pack_srv_room_message (room, handle, message, &hash, |
538 | GNUNET_MESSENGER_PACK_MODE_UNKNOWN); | ||
533 | 539 | ||
534 | const int new_message = update_room_message (room, message, &hash); | 540 | const int new_message = update_room_message (room, message, &hash); |
535 | 541 | ||
@@ -541,6 +547,9 @@ send_srv_room_message (struct GNUNET_MESSENGER_SrvRoom *room, | |||
541 | case GNUNET_MESSENGER_KIND_JOIN: | 547 | case GNUNET_MESSENGER_KIND_JOIN: |
542 | send_message_join (room, handle, message, &hash); | 548 | send_message_join (room, handle, message, &hash); |
543 | break; | 549 | break; |
550 | case GNUNET_MESSENGER_KIND_KEY: | ||
551 | send_message_key (room, handle, message, &hash); | ||
552 | break; | ||
544 | case GNUNET_MESSENGER_KIND_PEER: | 553 | case GNUNET_MESSENGER_KIND_PEER: |
545 | send_message_peer (room, handle, message, &hash); | 554 | send_message_peer (room, handle, message, &hash); |
546 | break; | 555 | break; |
@@ -554,25 +563,26 @@ send_srv_room_message (struct GNUNET_MESSENGER_SrvRoom *room, | |||
554 | break; | 563 | break; |
555 | } | 564 | } |
556 | 565 | ||
557 | callback_room_handle_message (room, handle, message, &hash); | 566 | callback_room_handle_message (room, message, &hash); |
558 | return GNUNET_YES; | 567 | return GNUNET_YES; |
559 | } | 568 | } |
560 | 569 | ||
570 | |||
561 | void | 571 | void |
562 | forward_srv_room_message (struct GNUNET_MESSENGER_SrvRoom *room, | 572 | forward_srv_room_message (struct GNUNET_MESSENGER_SrvRoom *room, |
563 | struct GNUNET_MESSENGER_SrvTunnel *tunnel, | 573 | struct GNUNET_MESSENGER_SrvTunnel *tunnel, |
564 | struct GNUNET_MESSENGER_Message *message, | 574 | struct GNUNET_MESSENGER_Message *message, |
565 | const struct GNUNET_HashCode *hash) | 575 | const struct GNUNET_HashCode *hash) |
566 | { | 576 | { |
567 | GNUNET_assert((room) && (tunnel)); | 577 | GNUNET_assert ((room) && (tunnel)); |
568 | 578 | ||
569 | if (!message) | 579 | if (! message) |
570 | return; | 580 | return; |
571 | 581 | ||
572 | struct GNUNET_MESSENGER_ClosureSendRoom closure; | 582 | struct GNUNET_MESSENGER_ClosureSendRoom closure; |
573 | struct GNUNET_HashCode message_hash; | 583 | struct GNUNET_HashCode message_hash; |
574 | 584 | ||
575 | GNUNET_memcpy(&message_hash, hash, sizeof(struct GNUNET_HashCode)); | 585 | GNUNET_memcpy (&message_hash, hash, sizeof(struct GNUNET_HashCode)); |
576 | 586 | ||
577 | closure.room = room; | 587 | closure.room = room; |
578 | closure.handle = NULL; | 588 | closure.handle = NULL; |
@@ -581,188 +591,202 @@ forward_srv_room_message (struct GNUNET_MESSENGER_SrvRoom *room, | |||
581 | closure.hash = &message_hash; | 591 | closure.hash = &message_hash; |
582 | closure.packed = GNUNET_YES; | 592 | closure.packed = GNUNET_YES; |
583 | 593 | ||
584 | GNUNET_CONTAINER_multipeermap_iterate (room->tunnels, iterate_send_room_message, &closure); | 594 | GNUNET_CONTAINER_multipeermap_iterate (room->tunnels, |
595 | iterate_send_room_message, &closure); | ||
585 | } | 596 | } |
586 | 597 | ||
598 | |||
587 | void | 599 | void |
588 | check_srv_room_peer_status (struct GNUNET_MESSENGER_SrvRoom *room, | 600 | check_srv_room_peer_status (struct GNUNET_MESSENGER_SrvRoom *room, |
589 | struct GNUNET_MESSENGER_SrvTunnel *tunnel) | 601 | struct GNUNET_MESSENGER_SrvTunnel *tunnel) |
590 | { | 602 | { |
591 | if (!room->peer_message) | 603 | if (! room->peer_message) |
592 | return; | 604 | return; |
593 | 605 | ||
594 | struct GNUNET_MESSENGER_MessageStore *message_store = get_srv_room_message_store(room); | 606 | struct GNUNET_MESSENGER_MessageStore *message_store = |
607 | get_srv_room_message_store (room); | ||
595 | 608 | ||
596 | const struct GNUNET_MESSENGER_Message *message = get_store_message(message_store, room->peer_message); | 609 | const struct GNUNET_MESSENGER_Message *message = get_store_message ( |
610 | message_store, room->peer_message); | ||
597 | 611 | ||
598 | if (!message) | 612 | if (! message) |
599 | { | 613 | { |
600 | GNUNET_free(room->peer_message); | 614 | GNUNET_free (room->peer_message); |
601 | room->peer_message = NULL; | 615 | room->peer_message = NULL; |
602 | return; | 616 | return; |
603 | } | 617 | } |
604 | 618 | ||
605 | struct GNUNET_MESSENGER_MemberStore *member_store = get_srv_room_member_store(room); | ||
606 | struct GNUNET_MESSENGER_Member *member = get_store_member_of(member_store, message); | ||
607 | |||
608 | if (!member) | ||
609 | goto resend_peer_message; | ||
610 | |||
611 | struct GNUNET_MESSENGER_MemberSession *session = get_member_session_of(member, message, room->peer_message); | ||
612 | |||
613 | if (GNUNET_YES == is_member_session_closed(session)) | ||
614 | goto resend_peer_message; | ||
615 | |||
616 | if (tunnel) | 619 | if (tunnel) |
617 | forward_tunnel_message(tunnel, message, room->peer_message); | 620 | forward_tunnel_message (tunnel, message, room->peer_message); |
618 | |||
619 | return; | ||
620 | |||
621 | resend_peer_message: | ||
622 | if (room->host) | ||
623 | send_srv_room_message (room, room->host, create_message_peer (room->service)); | ||
624 | } | 621 | } |
625 | 622 | ||
623 | |||
626 | void | 624 | void |
627 | merge_srv_room_last_messages (struct GNUNET_MESSENGER_SrvRoom *room, | 625 | merge_srv_room_last_messages (struct GNUNET_MESSENGER_SrvRoom *room, |
628 | struct GNUNET_MESSENGER_SrvHandle *handle) | 626 | struct GNUNET_MESSENGER_SrvHandle *handle) |
629 | { | 627 | { |
630 | GNUNET_assert(room); | 628 | GNUNET_assert (room); |
631 | 629 | ||
632 | if (!handle) | 630 | if (! handle) |
633 | return; | 631 | return; |
634 | 632 | ||
633 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
634 | "Merging messages by handle in room: %s\n", | ||
635 | GNUNET_h2s (&(room->key))); | ||
636 | |||
635 | const struct GNUNET_HashCode *hash; | 637 | const struct GNUNET_HashCode *hash; |
636 | 638 | ||
637 | merge_next: | 639 | merge_next: |
638 | hash = get_message_state_merge_hash (&(room->state)); | 640 | hash = get_message_state_merge_hash (&(room->state)); |
639 | 641 | ||
640 | if (!hash) | 642 | if (! hash) |
641 | return; | 643 | return; |
642 | 644 | ||
643 | send_srv_room_message (room, handle, create_message_merge (hash)); | 645 | send_srv_room_message (room, handle, create_message_merge (hash)); |
644 | goto merge_next; | 646 | goto merge_next; |
645 | } | 647 | } |
646 | 648 | ||
649 | |||
647 | void | 650 | void |
648 | callback_room_deletion (struct GNUNET_MESSENGER_SrvRoom *room, | 651 | callback_room_deletion (struct GNUNET_MESSENGER_SrvRoom *room, |
649 | const struct GNUNET_HashCode *hash) | 652 | const struct GNUNET_HashCode *hash) |
650 | { | 653 | { |
651 | if (GNUNET_OK != delete_store_message (get_srv_room_message_store(room), hash)) | 654 | if (GNUNET_OK != delete_store_message (get_srv_room_message_store (room), |
655 | hash)) | ||
652 | { | 656 | { |
653 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Deletion of message failed! (%s)\n", GNUNET_h2s(hash)); | 657 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Deletion of message failed! (%s)\n", |
658 | GNUNET_h2s (hash)); | ||
654 | return; | 659 | return; |
655 | } | 660 | } |
656 | } | 661 | } |
657 | 662 | ||
663 | |||
658 | void | 664 | void |
659 | callback_room_merge (struct GNUNET_MESSENGER_SrvRoom *room, | 665 | callback_room_merge (struct GNUNET_MESSENGER_SrvRoom *room, |
660 | const struct GNUNET_HashCode *hash) | 666 | const struct GNUNET_HashCode *hash) |
661 | { | 667 | { |
662 | if (!room->host) | 668 | if (! room->host) |
663 | return; | 669 | return; |
664 | 670 | ||
665 | send_srv_room_message (room, room->host, create_message_merge (hash)); | 671 | send_srv_room_message (room, room->host, create_message_merge (hash)); |
666 | } | 672 | } |
667 | 673 | ||
674 | |||
668 | int | 675 | int |
669 | delete_srv_room_message (struct GNUNET_MESSENGER_SrvRoom *room, | 676 | delete_srv_room_message (struct GNUNET_MESSENGER_SrvRoom *room, |
670 | struct GNUNET_MESSENGER_MemberSession *session, | 677 | struct GNUNET_MESSENGER_MemberSession *session, |
671 | const struct GNUNET_HashCode *hash, | 678 | const struct GNUNET_HashCode *hash, |
672 | const struct GNUNET_TIME_Relative delay) | 679 | const struct GNUNET_TIME_Relative delay) |
673 | { | 680 | { |
674 | GNUNET_assert((room) && (session) && (hash)); | 681 | GNUNET_assert ((room) && (session) && (hash)); |
675 | 682 | ||
676 | const struct GNUNET_TIME_Relative forever = GNUNET_TIME_relative_get_forever_ (); | 683 | const struct GNUNET_TIME_Relative forever = |
684 | GNUNET_TIME_relative_get_forever_ (); | ||
677 | 685 | ||
678 | if (0 == GNUNET_memcmp(&forever, &delay)) | 686 | if (0 == GNUNET_memcmp (&forever, &delay)) |
679 | { | 687 | { |
680 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Deletion is delayed forever: operation is impossible!\n"); | 688 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
689 | "Deletion is delayed forever: operation is impossible!\n"); | ||
681 | return GNUNET_SYSERR; | 690 | return GNUNET_SYSERR; |
682 | } | 691 | } |
683 | 692 | ||
684 | struct GNUNET_MESSENGER_MessageStore *message_store = get_srv_room_message_store(room); | 693 | struct GNUNET_MESSENGER_MessageStore *message_store = |
694 | get_srv_room_message_store (room); | ||
685 | 695 | ||
686 | const struct GNUNET_MESSENGER_Message *message = get_store_message(message_store, hash); | 696 | const struct GNUNET_MESSENGER_Message *message = get_store_message ( |
697 | message_store, hash); | ||
687 | 698 | ||
688 | if (!message) | 699 | if (! message) |
689 | return GNUNET_YES; | 700 | return GNUNET_YES; |
690 | 701 | ||
691 | if (GNUNET_YES != check_member_session_history(session, hash, GNUNET_YES)) | 702 | if (GNUNET_YES != check_member_session_history (session, hash, GNUNET_YES)) |
692 | { | 703 | { |
693 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Unpermitted request for deletion by member (%s) of message (%s)!\n", | 704 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
694 | GNUNET_sh2s(get_member_session_id(session)), GNUNET_h2s(hash)); | 705 | "Unpermitted request for deletion by member (%s) of message (%s)!\n", |
706 | GNUNET_sh2s (get_member_session_id (session)), GNUNET_h2s ( | ||
707 | hash)); | ||
695 | 708 | ||
696 | return GNUNET_NO; | 709 | return GNUNET_NO; |
697 | } | 710 | } |
698 | 711 | ||
699 | struct GNUNET_MESSENGER_OperationStore *operation_store = get_srv_room_operation_store(room); | 712 | struct GNUNET_MESSENGER_OperationStore *operation_store = |
713 | get_srv_room_operation_store (room); | ||
700 | 714 | ||
701 | if (GNUNET_OK != use_store_operation(operation_store, hash, GNUNET_MESSENGER_OP_DELETE, delay)) | 715 | if (GNUNET_OK != use_store_operation (operation_store, hash, |
716 | GNUNET_MESSENGER_OP_DELETE, delay)) | ||
702 | { | 717 | { |
703 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Deletion has failed: operation denied!\n"); | 718 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
719 | "Deletion has failed: operation denied!\n"); | ||
704 | return GNUNET_SYSERR; | 720 | return GNUNET_SYSERR; |
705 | } | 721 | } |
706 | 722 | ||
707 | return GNUNET_YES; | 723 | return GNUNET_YES; |
708 | } | 724 | } |
709 | 725 | ||
726 | |||
710 | struct GNUNET_CADET_Handle* | 727 | struct GNUNET_CADET_Handle* |
711 | get_srv_room_cadet (struct GNUNET_MESSENGER_SrvRoom *room) | 728 | get_srv_room_cadet (struct GNUNET_MESSENGER_SrvRoom *room) |
712 | { | 729 | { |
713 | GNUNET_assert(room); | 730 | GNUNET_assert (room); |
714 | 731 | ||
715 | return room->service->cadet; | 732 | return room->service->cadet; |
716 | } | 733 | } |
717 | 734 | ||
735 | |||
718 | const struct GNUNET_HashCode* | 736 | const struct GNUNET_HashCode* |
719 | get_srv_room_key (const struct GNUNET_MESSENGER_SrvRoom *room) | 737 | get_srv_room_key (const struct GNUNET_MESSENGER_SrvRoom *room) |
720 | { | 738 | { |
721 | GNUNET_assert(room); | 739 | GNUNET_assert (room); |
722 | 740 | ||
723 | return &(room->key); | 741 | return &(room->key); |
724 | } | 742 | } |
725 | 743 | ||
744 | |||
726 | const struct GNUNET_MESSENGER_SrvTunnel* | 745 | const struct GNUNET_MESSENGER_SrvTunnel* |
727 | get_srv_room_tunnel (const struct GNUNET_MESSENGER_SrvRoom *room, | 746 | get_srv_room_tunnel (const struct GNUNET_MESSENGER_SrvRoom *room, |
728 | const struct GNUNET_PeerIdentity *peer) | 747 | const struct GNUNET_PeerIdentity *peer) |
729 | { | 748 | { |
730 | GNUNET_assert((room) && (peer)); | 749 | GNUNET_assert ((room) && (peer)); |
731 | 750 | ||
732 | return GNUNET_CONTAINER_multipeermap_get (room->tunnels, peer); | 751 | return GNUNET_CONTAINER_multipeermap_get (room->tunnels, peer); |
733 | } | 752 | } |
734 | 753 | ||
754 | |||
735 | static int | 755 | static int |
736 | request_room_message_step (struct GNUNET_MESSENGER_SrvRoom *room, | 756 | request_room_message_step (struct GNUNET_MESSENGER_SrvRoom *room, |
737 | const struct GNUNET_HashCode *hash, | 757 | const struct GNUNET_HashCode *hash, |
738 | const struct GNUNET_MESSENGER_MemberSession *session, | 758 | const struct GNUNET_MESSENGER_MemberSession *session, |
739 | GNUNET_MESSENGER_MessageRequestCallback callback, | 759 | GNUNET_MESSENGER_MessageRequestCallback callback, |
740 | void* cls) | 760 | void *cls) |
741 | { | 761 | { |
742 | struct GNUNET_MESSENGER_MessageStore *message_store = get_srv_room_message_store(room); | 762 | struct GNUNET_MESSENGER_MessageStore *message_store = |
763 | get_srv_room_message_store (room); | ||
743 | 764 | ||
744 | const struct GNUNET_MESSENGER_MessageLink *link = get_store_message_link( | 765 | const struct GNUNET_MESSENGER_MessageLink *link = get_store_message_link ( |
745 | message_store, hash, GNUNET_YES | 766 | message_store, hash, GNUNET_YES |
746 | ); | 767 | ); |
747 | 768 | ||
748 | if (!link) | 769 | if (! link) |
749 | goto forward; | 770 | goto forward; |
750 | 771 | ||
751 | int result = request_room_message_step(room, &(link->first), session, callback, cls); | 772 | int result = request_room_message_step (room, &(link->first), session, |
773 | callback, cls); | ||
752 | 774 | ||
753 | if ((GNUNET_YES == link->multiple) && | 775 | if ((GNUNET_YES == link->multiple) && |
754 | (GNUNET_YES == request_room_message_step(room, &(link->second), session, callback, cls))) | 776 | (GNUNET_YES == request_room_message_step (room, &(link->second), session, |
777 | callback, cls))) | ||
755 | return GNUNET_YES; | 778 | return GNUNET_YES; |
756 | else | 779 | else |
757 | return result; | 780 | return result; |
758 | 781 | ||
759 | forward: | 782 | forward: |
760 | if (GNUNET_YES != check_member_session_history(session, hash, GNUNET_NO)) | 783 | if (GNUNET_YES != check_member_session_history (session, hash, GNUNET_NO)) |
761 | return GNUNET_YES; | 784 | return GNUNET_YES; |
762 | 785 | ||
763 | const struct GNUNET_MESSENGER_Message *message = get_store_message(message_store, hash); | 786 | const struct GNUNET_MESSENGER_Message *message = get_store_message ( |
787 | message_store, hash); | ||
764 | 788 | ||
765 | if (!message) | 789 | if (! message) |
766 | return GNUNET_NO; | 790 | return GNUNET_NO; |
767 | 791 | ||
768 | if (callback) | 792 | if (callback) |
@@ -771,14 +795,15 @@ forward: | |||
771 | return GNUNET_YES; | 795 | return GNUNET_YES; |
772 | } | 796 | } |
773 | 797 | ||
798 | |||
774 | int | 799 | int |
775 | request_srv_room_message (struct GNUNET_MESSENGER_SrvRoom *room, | 800 | request_srv_room_message (struct GNUNET_MESSENGER_SrvRoom *room, |
776 | const struct GNUNET_HashCode *hash, | 801 | const struct GNUNET_HashCode *hash, |
777 | const struct GNUNET_MESSENGER_MemberSession *session, | 802 | const struct GNUNET_MESSENGER_MemberSession *session, |
778 | GNUNET_MESSENGER_MessageRequestCallback callback, | 803 | GNUNET_MESSENGER_MessageRequestCallback callback, |
779 | void* cls) | 804 | void *cls) |
780 | { | 805 | { |
781 | GNUNET_assert((room) && (hash)); | 806 | GNUNET_assert ((room) && (hash)); |
782 | 807 | ||
783 | int result = request_room_message_step (room, hash, session, callback, cls); | 808 | int result = request_room_message_step (room, hash, session, callback, cls); |
784 | 809 | ||
@@ -788,26 +813,31 @@ request_srv_room_message (struct GNUNET_MESSENGER_SrvRoom *room, | |||
788 | return result; | 813 | return result; |
789 | } | 814 | } |
790 | 815 | ||
816 | |||
791 | void | 817 | void |
792 | callback_room_disconnect (struct GNUNET_MESSENGER_SrvRoom *room, | 818 | callback_room_disconnect (struct GNUNET_MESSENGER_SrvRoom *room, |
793 | void *cls) | 819 | void *cls) |
794 | { | 820 | { |
795 | struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls; | 821 | struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls; |
796 | 822 | ||
797 | if (!room->host) | 823 | if (! room->host) |
798 | return; | 824 | return; |
799 | 825 | ||
800 | struct GNUNET_PeerIdentity identity; | 826 | struct GNUNET_PeerIdentity identity; |
801 | get_tunnel_peer_identity(tunnel, &identity); | 827 | get_tunnel_peer_identity (tunnel, &identity); |
802 | 828 | ||
803 | if ((GNUNET_YES != GNUNET_CONTAINER_multipeermap_remove (room->tunnels, &identity, tunnel)) || | 829 | if ((GNUNET_YES != GNUNET_CONTAINER_multipeermap_remove (room->tunnels, |
804 | (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains(room->tunnels, &identity))) | 830 | &identity, |
831 | tunnel)) || | ||
832 | (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (room->tunnels, | ||
833 | &identity))) | ||
805 | return; | 834 | return; |
806 | 835 | ||
807 | if (GNUNET_YES == contains_list_tunnels (&(room->basement), &identity)) | 836 | if (GNUNET_YES == contains_list_tunnels (&(room->basement), &identity)) |
808 | send_srv_room_message (room, room->host, create_message_miss (&identity)); | 837 | send_srv_room_message (room, room->host, create_message_miss (&identity)); |
809 | } | 838 | } |
810 | 839 | ||
840 | |||
811 | int | 841 | int |
812 | callback_verify_room_message (struct GNUNET_MESSENGER_SrvRoom *room, | 842 | callback_verify_room_message (struct GNUNET_MESSENGER_SrvRoom *room, |
813 | void *cls, | 843 | void *cls, |
@@ -816,33 +846,40 @@ callback_verify_room_message (struct GNUNET_MESSENGER_SrvRoom *room, | |||
816 | { | 846 | { |
817 | if (GNUNET_MESSENGER_KIND_UNKNOWN == message->header.kind) | 847 | if (GNUNET_MESSENGER_KIND_UNKNOWN == message->header.kind) |
818 | { | 848 | { |
819 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Message error: Kind is unknown! (%d)\n", message->header.kind); | 849 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
850 | "Message error: Kind is unknown! (%d)\n", message->header.kind); | ||
820 | return GNUNET_SYSERR; | 851 | return GNUNET_SYSERR; |
821 | } | 852 | } |
822 | 853 | ||
823 | struct GNUNET_MESSENGER_MessageStore *message_store = get_srv_room_message_store(room); | 854 | struct GNUNET_MESSENGER_MessageStore *message_store = |
855 | get_srv_room_message_store (room); | ||
824 | 856 | ||
825 | const struct GNUNET_MESSENGER_Message *previous = get_store_message(message_store, &(message->header.previous)); | 857 | const struct GNUNET_MESSENGER_Message *previous = get_store_message ( |
858 | message_store, &(message->header.previous)); | ||
826 | 859 | ||
827 | if (!previous) | 860 | if (! previous) |
828 | goto skip_time_comparison; | 861 | goto skip_time_comparison; |
829 | 862 | ||
830 | struct GNUNET_TIME_Absolute timestamp = GNUNET_TIME_absolute_ntoh(message->header.timestamp); | 863 | struct GNUNET_TIME_Absolute timestamp = GNUNET_TIME_absolute_ntoh ( |
831 | struct GNUNET_TIME_Absolute last = GNUNET_TIME_absolute_ntoh(previous->header.timestamp); | 864 | message->header.timestamp); |
865 | struct GNUNET_TIME_Absolute last = GNUNET_TIME_absolute_ntoh ( | ||
866 | previous->header.timestamp); | ||
832 | 867 | ||
833 | if (GNUNET_TIME_relative_get_zero_().rel_value_us != GNUNET_TIME_absolute_get_difference(timestamp, last).rel_value_us) | 868 | if (GNUNET_TIME_relative_get_zero_ ().rel_value_us != |
869 | GNUNET_TIME_absolute_get_difference (timestamp, last).rel_value_us) | ||
834 | { | 870 | { |
835 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Message error: Timestamp does not check out!\n"); | 871 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
836 | return GNUNET_SYSERR; | 872 | "Message warning: Timestamp does not check out!\n"); |
837 | } | 873 | } |
838 | 874 | ||
839 | skip_time_comparison: | 875 | skip_time_comparison: |
840 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Receiving message of kind: %s!\n", | 876 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving message of kind: %s!\n", |
841 | GNUNET_MESSENGER_name_of_kind(message->header.kind)); | 877 | GNUNET_MESSENGER_name_of_kind (message->header.kind)); |
842 | 878 | ||
843 | return GNUNET_OK; | 879 | return GNUNET_OK; |
844 | } | 880 | } |
845 | 881 | ||
882 | |||
846 | static void | 883 | static void |
847 | idle_request_room_messages (void *cls) | 884 | idle_request_room_messages (void *cls) |
848 | { | 885 | { |
@@ -850,78 +887,94 @@ idle_request_room_messages (void *cls) | |||
850 | 887 | ||
851 | room->idle = NULL; | 888 | room->idle = NULL; |
852 | 889 | ||
853 | struct GNUNET_MESSENGER_OperationStore *operation_store = get_srv_room_operation_store(room); | 890 | struct GNUNET_MESSENGER_OperationStore *operation_store = |
854 | const struct GNUNET_HashCode *hash = get_message_state_merge_hash(&(room->state)); | 891 | get_srv_room_operation_store (room); |
892 | const struct GNUNET_HashCode *hash = get_message_state_merge_hash ( | ||
893 | &(room->state)); | ||
855 | 894 | ||
856 | if ((hash) && | 895 | if ((hash) && |
857 | (GNUNET_MESSENGER_OP_UNKNOWN == get_store_operation_type(operation_store, hash))) | 896 | (GNUNET_MESSENGER_OP_UNKNOWN == get_store_operation_type (operation_store, |
858 | use_store_operation( | 897 | hash))) |
859 | operation_store, | 898 | use_store_operation ( |
860 | hash, | 899 | operation_store, |
861 | GNUNET_MESSENGER_OP_MERGE, | 900 | hash, |
862 | GNUNET_MESSENGER_MERGE_DELAY | 901 | GNUNET_MESSENGER_OP_MERGE, |
863 | ); | 902 | GNUNET_MESSENGER_MERGE_DELAY |
903 | ); | ||
864 | 904 | ||
865 | room->idle = GNUNET_SCHEDULER_add_delayed_with_priority ( | 905 | room->idle = GNUNET_SCHEDULER_add_delayed_with_priority ( |
866 | GNUNET_MESSENGER_IDLE_DELAY, | 906 | GNUNET_MESSENGER_IDLE_DELAY, |
867 | GNUNET_SCHEDULER_PRIORITY_IDLE, | 907 | GNUNET_SCHEDULER_PRIORITY_IDLE, |
868 | idle_request_room_messages, | 908 | idle_request_room_messages, |
869 | cls | 909 | cls |
870 | ); | 910 | ); |
871 | } | 911 | } |
872 | 912 | ||
913 | |||
873 | void | 914 | void |
874 | solve_srv_room_member_collisions (struct GNUNET_MESSENGER_SrvRoom *room, | 915 | solve_srv_room_member_collisions (struct GNUNET_MESSENGER_SrvRoom *room, |
875 | const struct GNUNET_CRYPTO_PublicKey *public_key, | 916 | const struct |
917 | GNUNET_CRYPTO_PublicKey *public_key, | ||
876 | const struct GNUNET_ShortHashCode *member_id, | 918 | const struct GNUNET_ShortHashCode *member_id, |
877 | struct GNUNET_TIME_Absolute timestamp) | 919 | struct GNUNET_TIME_Absolute timestamp) |
878 | { | 920 | { |
879 | GNUNET_assert ((room) && (public_key) && (member_id)); | 921 | GNUNET_assert ((room) && (public_key) && (member_id)); |
880 | 922 | ||
881 | struct GNUNET_MESSENGER_MemberStore *member_store = get_srv_room_member_store(room); | 923 | struct GNUNET_MESSENGER_MemberStore *member_store = |
882 | struct GNUNET_MESSENGER_Member *member = get_store_member(member_store, member_id); | 924 | get_srv_room_member_store (room); |
925 | struct GNUNET_MESSENGER_Member *member = get_store_member (member_store, | ||
926 | member_id); | ||
883 | 927 | ||
884 | if ((!member) || (1 >= GNUNET_CONTAINER_multihashmap_size(member->sessions))) | 928 | if ((! member) || (1 >= GNUNET_CONTAINER_multihashmap_size ( |
929 | member->sessions))) | ||
885 | return; | 930 | return; |
886 | 931 | ||
887 | struct GNUNET_MESSENGER_ListHandles *handles = &(room->service->handles); | 932 | struct GNUNET_MESSENGER_ListHandles *handles = &(room->service->handles); |
888 | struct GNUNET_MESSENGER_ListHandle* element; | 933 | struct GNUNET_MESSENGER_ListHandle *element; |
934 | |||
935 | const struct GNUNET_CRYPTO_PublicKey *pubkey; | ||
889 | 936 | ||
890 | for (element = handles->head; element; element = element->next) | 937 | for (element = handles->head; element; element = element->next) |
891 | { | 938 | { |
892 | if (0 != GNUNET_memcmp(member_id, get_srv_handle_member_id(element->handle, get_srv_room_key(room)))) | 939 | if (0 != GNUNET_memcmp (member_id, get_srv_handle_member_id ( |
940 | element->handle, get_srv_room_key (room)))) | ||
893 | continue; | 941 | continue; |
894 | 942 | ||
895 | if (0 == GNUNET_memcmp(public_key, &(get_srv_handle_ego(element->handle)->pub))) | 943 | pubkey = get_srv_handle_key (element->handle); |
944 | |||
945 | if (0 == GNUNET_memcmp (public_key, pubkey)) | ||
896 | continue; | 946 | continue; |
897 | 947 | ||
898 | struct GNUNET_MESSENGER_MemberSession *session = get_member_session(member, &(get_srv_handle_ego(element->handle)->pub)); | 948 | struct GNUNET_MESSENGER_MemberSession *session = get_member_session (member, |
949 | pubkey); | ||
899 | 950 | ||
900 | if (!session) | 951 | if (! session) |
901 | continue; | 952 | continue; |
902 | 953 | ||
903 | struct GNUNET_TIME_Absolute start = get_member_session_start(session); | 954 | struct GNUNET_TIME_Absolute start = get_member_session_start (session); |
904 | 955 | ||
905 | if (GNUNET_TIME_relative_get_zero_().rel_value_us != GNUNET_TIME_absolute_get_difference(start, timestamp).rel_value_us) | 956 | if (GNUNET_TIME_relative_get_zero_ ().rel_value_us != |
957 | GNUNET_TIME_absolute_get_difference (start, timestamp).rel_value_us) | ||
906 | continue; | 958 | continue; |
907 | 959 | ||
908 | struct GNUNET_ShortHashCode random_id; | 960 | struct GNUNET_ShortHashCode random_id; |
909 | generate_free_member_id (&random_id, member_store->members); | 961 | generate_free_member_id (&random_id, member_store->members); |
910 | 962 | ||
911 | send_srv_room_message(room, element->handle, create_message_id(&random_id)); | 963 | notify_srv_handle_member_id (element->handle, room, &random_id, GNUNET_NO); |
912 | } | 964 | } |
913 | } | 965 | } |
914 | 966 | ||
967 | |||
915 | void | 968 | void |
916 | rebuild_srv_room_basement_structure (struct GNUNET_MESSENGER_SrvRoom *room) | 969 | rebuild_srv_room_basement_structure (struct GNUNET_MESSENGER_SrvRoom *room) |
917 | { | 970 | { |
918 | GNUNET_assert(room); | 971 | GNUNET_assert (room); |
919 | 972 | ||
920 | struct GNUNET_PeerIdentity peer; | 973 | struct GNUNET_PeerIdentity peer; |
921 | size_t src; | 974 | size_t src; |
922 | 975 | ||
923 | if ((GNUNET_OK != get_service_peer_identity (room->service, &peer)) || | 976 | if ((GNUNET_OK != get_service_peer_identity (room->service, &peer)) || |
924 | (!find_list_tunnels (&(room->basement), &peer, &src))) | 977 | (! find_list_tunnels (&(room->basement), &peer, &src))) |
925 | return; | 978 | return; |
926 | 979 | ||
927 | size_t count = count_of_tunnels (&(room->basement)); | 980 | size_t count = count_of_tunnels (&(room->basement)); |
@@ -937,7 +990,7 @@ rebuild_srv_room_basement_structure (struct GNUNET_MESSENGER_SrvRoom *room) | |||
937 | 990 | ||
938 | tunnel = GNUNET_CONTAINER_multipeermap_get (room->tunnels, &peer); | 991 | tunnel = GNUNET_CONTAINER_multipeermap_get (room->tunnels, &peer); |
939 | 992 | ||
940 | if (!tunnel) | 993 | if (! tunnel) |
941 | { | 994 | { |
942 | element = remove_from_list_tunnels (&(room->basement), element); | 995 | element = remove_from_list_tunnels (&(room->basement), element); |
943 | continue; | 996 | continue; |
@@ -959,69 +1012,100 @@ rebuild_srv_room_basement_structure (struct GNUNET_MESSENGER_SrvRoom *room) | |||
959 | } | 1012 | } |
960 | } | 1013 | } |
961 | 1014 | ||
1015 | |||
962 | static void | 1016 | static void |
963 | handle_room_messages (struct GNUNET_MESSENGER_SrvRoom *room) | 1017 | handle_room_messages (struct GNUNET_MESSENGER_SrvRoom *room) |
964 | { | 1018 | { |
965 | struct GNUNET_MESSENGER_MessageStore *message_store = get_srv_room_message_store(room); | 1019 | struct GNUNET_MESSENGER_MessageStore *message_store = |
966 | struct GNUNET_MESSENGER_MemberStore *member_store = get_srv_room_member_store(room); | 1020 | get_srv_room_message_store (room); |
1021 | struct GNUNET_MESSENGER_MemberStore *member_store = | ||
1022 | get_srv_room_member_store (room); | ||
1023 | struct GNUNET_MESSENGER_PeerStore *peer_store = get_srv_room_peer_store ( | ||
1024 | room); | ||
967 | 1025 | ||
968 | while (room->handling.head) | 1026 | while (room->handling.head) |
969 | { | 1027 | { |
970 | struct GNUNET_MESSENGER_ListMessage *element = room->handling.head; | 1028 | struct GNUNET_MESSENGER_ListMessage *element = room->handling.head; |
971 | 1029 | ||
972 | const struct GNUNET_MESSENGER_Message *message = get_store_message (message_store, &(element->hash)); | 1030 | const struct GNUNET_MESSENGER_Message *message = get_store_message ( |
1031 | message_store, &(element->hash)); | ||
973 | 1032 | ||
974 | if (!message) | 1033 | if (! message) |
975 | goto finish_handling; | 1034 | goto finish_handling; |
976 | 1035 | ||
977 | struct GNUNET_MESSENGER_Member *member = get_store_member_of(member_store, message); | 1036 | struct GNUNET_MESSENGER_SenderSession session; |
978 | 1037 | ||
979 | if (!member) | 1038 | if (GNUNET_YES == is_peer_message (message)) |
980 | goto finish_handling; | 1039 | { |
1040 | session.peer = get_store_peer_of (peer_store, message, &(element->hash)); | ||
981 | 1041 | ||
982 | struct GNUNET_MESSENGER_MemberSession *session = get_member_session_of(member, message, &(element->hash)); | 1042 | if (! session.peer) |
1043 | goto finish_handling; | ||
1044 | } | ||
1045 | else | ||
1046 | { | ||
1047 | struct GNUNET_MESSENGER_Member *member = get_store_member_of ( | ||
1048 | member_store, message); | ||
983 | 1049 | ||
984 | if (session) | 1050 | if (! member) |
985 | handle_service_message (room->service, room, session, message, &(element->hash)); | 1051 | goto finish_handling; |
1052 | |||
1053 | session.member = get_member_session_of (member, message, | ||
1054 | &(element->hash)); | ||
1055 | |||
1056 | if (! session.member) | ||
1057 | goto finish_handling; | ||
1058 | } | ||
1059 | |||
1060 | handle_service_message (room->service, room, &session, message, | ||
1061 | &(element->hash)); | ||
986 | 1062 | ||
987 | finish_handling: | 1063 | finish_handling: |
988 | GNUNET_CONTAINER_DLL_remove(room->handling.head, room->handling.tail, element); | 1064 | GNUNET_CONTAINER_DLL_remove (room->handling.head, room->handling.tail, |
989 | GNUNET_free(element); | 1065 | element); |
1066 | GNUNET_free (element); | ||
990 | } | 1067 | } |
991 | } | 1068 | } |
992 | 1069 | ||
1070 | |||
993 | int | 1071 | int |
994 | update_room_message (struct GNUNET_MESSENGER_SrvRoom *room, | 1072 | update_room_message (struct GNUNET_MESSENGER_SrvRoom *room, |
995 | struct GNUNET_MESSENGER_Message *message, | 1073 | struct GNUNET_MESSENGER_Message *message, |
996 | const struct GNUNET_HashCode *hash) | 1074 | const struct GNUNET_HashCode *hash) |
997 | { | 1075 | { |
998 | GNUNET_assert((room) && (message) && (hash)); | 1076 | GNUNET_assert ((room) && (message) && (hash)); |
999 | 1077 | ||
1000 | struct GNUNET_MESSENGER_OperationStore *operation_store = get_srv_room_operation_store(room); | 1078 | struct GNUNET_MESSENGER_OperationStore *operation_store = |
1079 | get_srv_room_operation_store (room); | ||
1001 | 1080 | ||
1002 | const int requested = (GNUNET_MESSENGER_OP_REQUEST == get_store_operation_type(operation_store, hash)? | 1081 | const int requested = (GNUNET_MESSENGER_OP_REQUEST == |
1003 | GNUNET_YES : GNUNET_NO | 1082 | get_store_operation_type (operation_store, hash)? |
1004 | ); | 1083 | GNUNET_YES : GNUNET_NO |
1084 | ); | ||
1005 | 1085 | ||
1006 | if (GNUNET_YES == requested) | 1086 | if (GNUNET_YES == requested) |
1007 | cancel_store_operation(operation_store, hash); | 1087 | cancel_store_operation (operation_store, hash); |
1008 | 1088 | ||
1009 | struct GNUNET_MESSENGER_MessageStore *message_store = get_srv_room_message_store(room); | 1089 | struct GNUNET_MESSENGER_MessageStore *message_store = |
1090 | get_srv_room_message_store (room); | ||
1010 | 1091 | ||
1011 | const struct GNUNET_MESSENGER_Message *old_message = get_store_message (message_store, hash); | 1092 | const struct GNUNET_MESSENGER_Message *old_message = get_store_message ( |
1093 | message_store, hash); | ||
1012 | 1094 | ||
1013 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Handle a message in room (%s).\n", GNUNET_h2s (get_srv_room_key(room))); | 1095 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Handle a message in room (%s).\n", |
1096 | GNUNET_h2s (get_srv_room_key (room))); | ||
1014 | 1097 | ||
1015 | if ((old_message) || (GNUNET_OK != put_store_message (message_store, hash, message))) | 1098 | if ((old_message) || (GNUNET_OK != put_store_message (message_store, hash, |
1099 | message))) | ||
1016 | { | 1100 | { |
1017 | if (old_message != message) | 1101 | if (old_message != message) |
1018 | destroy_message(message); | 1102 | destroy_message (message); |
1019 | 1103 | ||
1020 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Duplicate message got dropped!\n"); | 1104 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Duplicate message got dropped!\n"); |
1021 | return GNUNET_NO; | 1105 | return GNUNET_NO; |
1022 | } | 1106 | } |
1023 | 1107 | ||
1024 | update_message_state(&(room->state), requested, message, hash); | 1108 | update_message_state (&(room->state), requested, message, hash); |
1025 | 1109 | ||
1026 | if ((GNUNET_YES == requested) || | 1110 | if ((GNUNET_YES == requested) || |
1027 | (GNUNET_MESSENGER_KIND_INFO == message->header.kind) || | 1111 | (GNUNET_MESSENGER_KIND_INFO == message->header.kind) || |
@@ -1029,15 +1113,20 @@ update_room_message (struct GNUNET_MESSENGER_SrvRoom *room, | |||
1029 | return GNUNET_YES; | 1113 | return GNUNET_YES; |
1030 | 1114 | ||
1031 | if ((GNUNET_MESSENGER_KIND_MERGE == message->header.kind) && | 1115 | if ((GNUNET_MESSENGER_KIND_MERGE == message->header.kind) && |
1032 | (GNUNET_MESSENGER_OP_MERGE == get_store_operation_type(operation_store, &(message->body.merge.previous)))) | 1116 | (GNUNET_MESSENGER_OP_MERGE == get_store_operation_type (operation_store, |
1033 | cancel_store_operation(operation_store, &(message->body.merge.previous)); | 1117 | &(message->body. |
1118 | merge.previous)))) | ||
1119 | cancel_store_operation (operation_store, &(message->body.merge.previous)); | ||
1034 | 1120 | ||
1035 | if (GNUNET_MESSENGER_OP_MERGE == get_store_operation_type(operation_store, &(message->header.previous))) | 1121 | if (GNUNET_MESSENGER_OP_MERGE == get_store_operation_type (operation_store, |
1036 | cancel_store_operation(operation_store, &(message->header.previous)); | 1122 | &(message->header. |
1123 | previous))) | ||
1124 | cancel_store_operation (operation_store, &(message->header.previous)); | ||
1037 | 1125 | ||
1038 | return GNUNET_YES; | 1126 | return GNUNET_YES; |
1039 | } | 1127 | } |
1040 | 1128 | ||
1129 | |||
1041 | struct GNUNET_MESSENGER_MemberSessionCompletion | 1130 | struct GNUNET_MESSENGER_MemberSessionCompletion |
1042 | { | 1131 | { |
1043 | struct GNUNET_MESSENGER_MemberSessionCompletion *prev; | 1132 | struct GNUNET_MESSENGER_MemberSessionCompletion *prev; |
@@ -1057,54 +1146,81 @@ struct GNUNET_MESSENGER_MemberUpdate | |||
1057 | 1146 | ||
1058 | static int | 1147 | static int |
1059 | iterate_update_member_sessions (void *cls, | 1148 | iterate_update_member_sessions (void *cls, |
1060 | const struct GNUNET_CRYPTO_PublicKey *public_key, | 1149 | const struct |
1150 | GNUNET_CRYPTO_PublicKey *public_key, | ||
1061 | struct GNUNET_MESSENGER_MemberSession *session) | 1151 | struct GNUNET_MESSENGER_MemberSession *session) |
1062 | { | 1152 | { |
1063 | struct GNUNET_MESSENGER_MemberUpdate *update = cls; | 1153 | struct GNUNET_MESSENGER_MemberUpdate *update = cls; |
1064 | 1154 | ||
1065 | update_member_session_history(session, update->message, update->hash); | 1155 | update_member_session_history (session, update->message, update->hash); |
1066 | 1156 | ||
1067 | if (GNUNET_YES == is_member_session_completed(session)) | 1157 | if (GNUNET_YES == is_member_session_completed (session)) |
1068 | { | 1158 | { |
1069 | struct GNUNET_MESSENGER_MemberSessionCompletion *element = GNUNET_new( | 1159 | struct GNUNET_MESSENGER_MemberSessionCompletion *element = GNUNET_new ( |
1070 | struct GNUNET_MESSENGER_MemberSessionCompletion | 1160 | struct GNUNET_MESSENGER_MemberSessionCompletion |
1071 | ); | 1161 | ); |
1072 | 1162 | ||
1073 | element->session = session; | 1163 | element->session = session; |
1074 | 1164 | ||
1075 | GNUNET_CONTAINER_DLL_insert_tail(update->head, update->tail, element); | 1165 | GNUNET_CONTAINER_DLL_insert_tail (update->head, update->tail, element); |
1076 | } | 1166 | } |
1077 | 1167 | ||
1078 | return GNUNET_YES; | 1168 | return GNUNET_YES; |
1079 | } | 1169 | } |
1080 | 1170 | ||
1171 | |||
1081 | static void | 1172 | static void |
1082 | remove_room_member_session (struct GNUNET_MESSENGER_SrvRoom *room, | 1173 | remove_room_member_session (struct GNUNET_MESSENGER_SrvRoom *room, |
1083 | struct GNUNET_MESSENGER_MemberSession *session); | 1174 | struct GNUNET_MESSENGER_MemberSession *session); |
1084 | 1175 | ||
1085 | void | 1176 | void |
1086 | callback_room_handle_message (struct GNUNET_MESSENGER_SrvRoom *room, | 1177 | callback_room_handle_message (struct GNUNET_MESSENGER_SrvRoom *room, |
1087 | struct GNUNET_MESSENGER_SrvHandle *handle, | ||
1088 | const struct GNUNET_MESSENGER_Message *message, | 1178 | const struct GNUNET_MESSENGER_Message *message, |
1089 | const struct GNUNET_HashCode *hash) | 1179 | const struct GNUNET_HashCode *hash) |
1090 | { | 1180 | { |
1091 | struct GNUNET_MESSENGER_MemberStore *member_store = get_srv_room_member_store(room); | 1181 | GNUNET_assert ((room) && (message) && (hash)); |
1092 | struct GNUNET_MESSENGER_Member *member = get_store_member_of(member_store, message); | ||
1093 | 1182 | ||
1094 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Callback for message (%s)\n", GNUNET_h2s (hash)); | 1183 | struct GNUNET_MESSENGER_PeerStore *peer_store = get_srv_room_peer_store ( |
1184 | room); | ||
1185 | struct GNUNET_MESSENGER_MemberStore *member_store = | ||
1186 | get_srv_room_member_store (room); | ||
1095 | 1187 | ||
1096 | if (!member) | 1188 | struct GNUNET_MESSENGER_SenderSession session; |
1189 | |||
1190 | if (GNUNET_YES == is_peer_message (message)) | ||
1097 | { | 1191 | { |
1098 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Message handling dropped: Member is missing!\n"); | 1192 | session.peer = get_store_peer_of (peer_store, message, hash); |
1099 | return; | 1193 | |
1194 | if (! session.peer) | ||
1195 | { | ||
1196 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1197 | "Message handling dropped: Peer is missing!\n"); | ||
1198 | return; | ||
1199 | } | ||
1100 | } | 1200 | } |
1201 | else | ||
1202 | { | ||
1203 | struct GNUNET_MESSENGER_Member *member = get_store_member_of (member_store, | ||
1204 | message); | ||
1101 | 1205 | ||
1102 | struct GNUNET_MESSENGER_MemberSession *session = get_member_session_of(member, message, hash); | 1206 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for message (%s)\n", |
1207 | GNUNET_h2s (hash)); | ||
1103 | 1208 | ||
1104 | if (!session) | 1209 | if (! member) |
1105 | { | 1210 | { |
1106 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Message handling dropped: Session is missing!\n"); | 1211 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1107 | return; | 1212 | "Message handling dropped: Member is missing!\n"); |
1213 | return; | ||
1214 | } | ||
1215 | |||
1216 | session.member = get_member_session_of (member, message, hash); | ||
1217 | |||
1218 | if (! session.member) | ||
1219 | { | ||
1220 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1221 | "Message handling dropped: Session is missing!\n"); | ||
1222 | return; | ||
1223 | } | ||
1108 | } | 1224 | } |
1109 | 1225 | ||
1110 | struct GNUNET_MESSENGER_MemberUpdate update; | 1226 | struct GNUNET_MESSENGER_MemberUpdate update; |
@@ -1114,7 +1230,7 @@ callback_room_handle_message (struct GNUNET_MESSENGER_SrvRoom *room, | |||
1114 | update.head = NULL; | 1230 | update.head = NULL; |
1115 | update.tail = NULL; | 1231 | update.tail = NULL; |
1116 | 1232 | ||
1117 | iterate_store_members(member_store, iterate_update_member_sessions, &update); | 1233 | iterate_store_members (member_store, iterate_update_member_sessions, &update); |
1118 | 1234 | ||
1119 | while (update.head) | 1235 | while (update.head) |
1120 | { | 1236 | { |
@@ -1122,7 +1238,7 @@ callback_room_handle_message (struct GNUNET_MESSENGER_SrvRoom *room, | |||
1122 | 1238 | ||
1123 | remove_room_member_session (room, element->session); | 1239 | remove_room_member_session (room, element->session); |
1124 | 1240 | ||
1125 | GNUNET_CONTAINER_DLL_remove(update.head, update.tail, element); | 1241 | GNUNET_CONTAINER_DLL_remove (update.head, update.tail, element); |
1126 | GNUNET_free (element); | 1242 | GNUNET_free (element); |
1127 | } | 1243 | } |
1128 | 1244 | ||
@@ -1133,28 +1249,28 @@ callback_room_handle_message (struct GNUNET_MESSENGER_SrvRoom *room, | |||
1133 | switch (message->header.kind) | 1249 | switch (message->header.kind) |
1134 | { | 1250 | { |
1135 | case GNUNET_MESSENGER_KIND_JOIN: | 1251 | case GNUNET_MESSENGER_KIND_JOIN: |
1136 | handle_message_join (room, session, message, hash); | 1252 | handle_message_join (room, &session, message, hash); |
1137 | break; | 1253 | break; |
1138 | case GNUNET_MESSENGER_KIND_LEAVE: | 1254 | case GNUNET_MESSENGER_KIND_LEAVE: |
1139 | handle_message_leave (room, session, message, hash); | 1255 | handle_message_leave (room, &session, message, hash); |
1140 | break; | 1256 | break; |
1141 | case GNUNET_MESSENGER_KIND_NAME: | 1257 | case GNUNET_MESSENGER_KIND_NAME: |
1142 | handle_message_name (room, session, message, hash); | 1258 | handle_message_name (room, &session, message, hash); |
1143 | break; | 1259 | break; |
1144 | case GNUNET_MESSENGER_KIND_KEY: | 1260 | case GNUNET_MESSENGER_KIND_KEY: |
1145 | handle_message_key (room, session, message, hash); | 1261 | handle_message_key (room, &session, message, hash); |
1146 | break; | 1262 | break; |
1147 | case GNUNET_MESSENGER_KIND_PEER: | 1263 | case GNUNET_MESSENGER_KIND_PEER: |
1148 | handle_message_peer (room, session, message, hash); | 1264 | handle_message_peer (room, &session, message, hash); |
1149 | break; | 1265 | break; |
1150 | case GNUNET_MESSENGER_KIND_ID: | 1266 | case GNUNET_MESSENGER_KIND_ID: |
1151 | handle_message_id (room, session, message, hash); | 1267 | handle_message_id (room, &session, message, hash); |
1152 | break; | 1268 | break; |
1153 | case GNUNET_MESSENGER_KIND_MISS: | 1269 | case GNUNET_MESSENGER_KIND_MISS: |
1154 | handle_message_miss (room, session, message, hash); | 1270 | handle_message_miss (room, &session, message, hash); |
1155 | break; | 1271 | break; |
1156 | case GNUNET_MESSENGER_KIND_DELETE: | 1272 | case GNUNET_MESSENGER_KIND_DELETE: |
1157 | handle_message_delete (room, session, message, hash); | 1273 | handle_message_delete (room, &session, message, hash); |
1158 | break; | 1274 | break; |
1159 | default: | 1275 | default: |
1160 | break; | 1276 | break; |
@@ -1164,45 +1280,50 @@ callback_room_handle_message (struct GNUNET_MESSENGER_SrvRoom *room, | |||
1164 | handle_room_messages (room); | 1280 | handle_room_messages (room); |
1165 | } | 1281 | } |
1166 | 1282 | ||
1283 | |||
1167 | static void | 1284 | static void |
1168 | get_room_data_subdir (struct GNUNET_MESSENGER_SrvRoom *room, | 1285 | get_room_data_subdir (struct GNUNET_MESSENGER_SrvRoom *room, |
1169 | char **dir) | 1286 | char **dir) |
1170 | { | 1287 | { |
1171 | GNUNET_assert((room) && (dir)); | 1288 | GNUNET_assert ((room) && (dir)); |
1172 | 1289 | ||
1173 | GNUNET_asprintf (dir, "%s%s%c%s%c", room->service->dir, "rooms", DIR_SEPARATOR, GNUNET_h2s (get_srv_room_key(room)), DIR_SEPARATOR); | 1290 | GNUNET_asprintf (dir, "%s%s%c%s%c", room->service->dir, "rooms", |
1291 | DIR_SEPARATOR, GNUNET_h2s (get_srv_room_key (room)), | ||
1292 | DIR_SEPARATOR); | ||
1174 | } | 1293 | } |
1175 | 1294 | ||
1295 | |||
1176 | void | 1296 | void |
1177 | load_srv_room (struct GNUNET_MESSENGER_SrvRoom *room) | 1297 | load_srv_room (struct GNUNET_MESSENGER_SrvRoom *room) |
1178 | { | 1298 | { |
1179 | GNUNET_assert(room); | 1299 | GNUNET_assert (room); |
1180 | 1300 | ||
1181 | char *room_dir; | 1301 | char *room_dir; |
1182 | get_room_data_subdir (room, &room_dir); | 1302 | get_room_data_subdir (room, &room_dir); |
1183 | 1303 | ||
1184 | if (GNUNET_YES == GNUNET_DISK_directory_test (room_dir, GNUNET_YES)) | 1304 | if (GNUNET_YES == GNUNET_DISK_directory_test (room_dir, GNUNET_YES)) |
1185 | { | 1305 | { |
1186 | load_member_store (get_srv_room_member_store(room), room_dir); | 1306 | load_member_store (get_srv_room_member_store (room), room_dir); |
1187 | load_message_store (get_srv_room_message_store(room), room_dir); | 1307 | load_message_store (get_srv_room_message_store (room), room_dir); |
1188 | load_operation_store(get_srv_room_operation_store(room), room_dir); | 1308 | load_operation_store (get_srv_room_operation_store (room), room_dir); |
1189 | 1309 | ||
1190 | char *basement_file; | 1310 | char *basement_file; |
1191 | GNUNET_asprintf (&basement_file, "%s%s", room_dir, "basement.list"); | 1311 | GNUNET_asprintf (&basement_file, "%s%s", room_dir, "basement.list"); |
1192 | 1312 | ||
1193 | load_list_tunnels(&(room->basement), basement_file); | 1313 | load_list_tunnels (&(room->basement), basement_file); |
1194 | GNUNET_free(basement_file); | 1314 | GNUNET_free (basement_file); |
1195 | 1315 | ||
1196 | load_message_state(&(room->state), room_dir); | 1316 | load_message_state (&(room->state), room_dir); |
1197 | } | 1317 | } |
1198 | 1318 | ||
1199 | GNUNET_free(room_dir); | 1319 | GNUNET_free (room_dir); |
1200 | } | 1320 | } |
1201 | 1321 | ||
1322 | |||
1202 | void | 1323 | void |
1203 | save_srv_room (struct GNUNET_MESSENGER_SrvRoom *room) | 1324 | save_srv_room (struct GNUNET_MESSENGER_SrvRoom *room) |
1204 | { | 1325 | { |
1205 | GNUNET_assert(room); | 1326 | GNUNET_assert (room); |
1206 | 1327 | ||
1207 | char *room_dir; | 1328 | char *room_dir; |
1208 | get_room_data_subdir (room, &room_dir); | 1329 | get_room_data_subdir (room, &room_dir); |
@@ -1210,36 +1331,38 @@ save_srv_room (struct GNUNET_MESSENGER_SrvRoom *room) | |||
1210 | if ((GNUNET_YES == GNUNET_DISK_directory_test (room_dir, GNUNET_NO)) || | 1331 | if ((GNUNET_YES == GNUNET_DISK_directory_test (room_dir, GNUNET_NO)) || |
1211 | (GNUNET_OK == GNUNET_DISK_directory_create (room_dir))) | 1332 | (GNUNET_OK == GNUNET_DISK_directory_create (room_dir))) |
1212 | { | 1333 | { |
1213 | save_member_store(get_srv_room_member_store(room), room_dir); | 1334 | save_member_store (get_srv_room_member_store (room), room_dir); |
1214 | save_message_store (get_srv_room_message_store(room), room_dir); | 1335 | save_message_store (get_srv_room_message_store (room), room_dir); |
1215 | save_operation_store(get_srv_room_operation_store(room), room_dir); | 1336 | save_operation_store (get_srv_room_operation_store (room), room_dir); |
1216 | 1337 | ||
1217 | char *basement_file; | 1338 | char *basement_file; |
1218 | GNUNET_asprintf (&basement_file, "%s%s", room_dir, "basement.list"); | 1339 | GNUNET_asprintf (&basement_file, "%s%s", room_dir, "basement.list"); |
1219 | 1340 | ||
1220 | save_list_tunnels(&(room->basement), basement_file); | 1341 | save_list_tunnels (&(room->basement), basement_file); |
1221 | GNUNET_free(basement_file); | 1342 | GNUNET_free (basement_file); |
1222 | 1343 | ||
1223 | save_message_state(&(room->state), room_dir); | 1344 | save_message_state (&(room->state), room_dir); |
1224 | } | 1345 | } |
1225 | 1346 | ||
1226 | GNUNET_free(room_dir); | 1347 | GNUNET_free (room_dir); |
1227 | } | 1348 | } |
1228 | 1349 | ||
1350 | |||
1229 | void | 1351 | void |
1230 | remove_srv_room (struct GNUNET_MESSENGER_SrvRoom *room) | 1352 | remove_srv_room (struct GNUNET_MESSENGER_SrvRoom *room) |
1231 | { | 1353 | { |
1232 | GNUNET_assert(room); | 1354 | GNUNET_assert (room); |
1233 | 1355 | ||
1234 | char *room_dir; | 1356 | char *room_dir; |
1235 | get_room_data_subdir (room, &room_dir); | 1357 | get_room_data_subdir (room, &room_dir); |
1236 | 1358 | ||
1237 | if (GNUNET_YES == GNUNET_DISK_directory_test (room_dir, GNUNET_YES)) | 1359 | if (GNUNET_YES == GNUNET_DISK_directory_test (room_dir, GNUNET_YES)) |
1238 | GNUNET_DISK_directory_remove(room_dir); | 1360 | GNUNET_DISK_directory_remove (room_dir); |
1239 | 1361 | ||
1240 | GNUNET_free(room_dir); | 1362 | GNUNET_free (room_dir); |
1241 | } | 1363 | } |
1242 | 1364 | ||
1365 | |||
1243 | static void | 1366 | static void |
1244 | remove_room_member_session (struct GNUNET_MESSENGER_SrvRoom *room, | 1367 | remove_room_member_session (struct GNUNET_MESSENGER_SrvRoom *room, |
1245 | struct GNUNET_MESSENGER_MemberSession *session) | 1368 | struct GNUNET_MESSENGER_MemberSession *session) |
@@ -1248,27 +1371,28 @@ remove_room_member_session (struct GNUNET_MESSENGER_SrvRoom *room, | |||
1248 | 1371 | ||
1249 | remove_member_session (session->member, session); | 1372 | remove_member_session (session->member, session); |
1250 | 1373 | ||
1251 | const struct GNUNET_CRYPTO_PublicKey *public_key = get_member_session_public_key(session); | 1374 | const struct GNUNET_CRYPTO_PublicKey *public_key = |
1375 | get_member_session_public_key (session); | ||
1252 | 1376 | ||
1253 | struct GNUNET_HashCode hash; | 1377 | struct GNUNET_HashCode hash; |
1254 | GNUNET_CRYPTO_hash(public_key, sizeof(*public_key), &hash); | 1378 | GNUNET_CRYPTO_hash (public_key, sizeof(*public_key), &hash); |
1255 | 1379 | ||
1256 | char *room_dir; | 1380 | char *room_dir; |
1257 | get_room_data_subdir (room, &room_dir); | 1381 | get_room_data_subdir (room, &room_dir); |
1258 | 1382 | ||
1259 | char* session_dir; | 1383 | char *session_dir; |
1260 | GNUNET_asprintf ( | 1384 | GNUNET_asprintf ( |
1261 | &session_dir, "%s%s%c%s%c%s%c%s%c", room_dir, | 1385 | &session_dir, "%s%s%c%s%c%s%c%s%c", room_dir, |
1262 | "members", DIR_SEPARATOR, | 1386 | "members", DIR_SEPARATOR, |
1263 | GNUNET_sh2s(get_member_session_id(session)), DIR_SEPARATOR, | 1387 | GNUNET_sh2s (get_member_session_id (session)), DIR_SEPARATOR, |
1264 | "sessions", DIR_SEPARATOR, | 1388 | "sessions", DIR_SEPARATOR, |
1265 | GNUNET_h2s(&hash), DIR_SEPARATOR | 1389 | GNUNET_h2s (&hash), DIR_SEPARATOR |
1266 | ); | 1390 | ); |
1267 | 1391 | ||
1268 | GNUNET_free (room_dir); | 1392 | GNUNET_free (room_dir); |
1269 | 1393 | ||
1270 | GNUNET_DISK_directory_remove(session_dir); | 1394 | GNUNET_DISK_directory_remove (session_dir); |
1271 | GNUNET_free (session_dir); | 1395 | GNUNET_free (session_dir); |
1272 | 1396 | ||
1273 | destroy_member_session(session); | 1397 | destroy_member_session (session); |
1274 | } | 1398 | } |