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