diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2023-11-10 23:23:45 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2023-11-10 23:23:45 +0100 |
commit | e60834efb1e50717351e683142d0e57d6b537ee2 (patch) | |
tree | 332eb6d80ccb296d3e1e7380d3b8d91a2b036624 | |
parent | a37db0db76a3b5b5580974062b5ea13850221539 (diff) | |
download | gnunet-e60834efb1e50717351e683142d0e57d6b537ee2.tar.gz gnunet-e60834efb1e50717351e683142d0e57d6b537ee2.zip |
MESSENGER: Uncrustify code
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
51 files changed, 3285 insertions, 2112 deletions
diff --git a/src/messenger/gnunet-messenger.c b/src/messenger/gnunet-messenger.c index 0fa706319..79c0d0b1e 100644 --- a/src/messenger/gnunet-messenger.c +++ b/src/messenger/gnunet-messenger.c | |||
@@ -52,12 +52,12 @@ on_message (void *cls, | |||
52 | { | 52 | { |
53 | const char *sender_name = GNUNET_MESSENGER_contact_get_name (sender); | 53 | const char *sender_name = GNUNET_MESSENGER_contact_get_name (sender); |
54 | 54 | ||
55 | if (!sender_name) | 55 | if (! sender_name) |
56 | sender_name = "anonymous"; | 56 | sender_name = "anonymous"; |
57 | 57 | ||
58 | printf ("[%s ->", GNUNET_h2s(&(message->header.previous))); | 58 | printf ("[%s ->", GNUNET_h2s (&(message->header.previous))); |
59 | printf (" %s]", GNUNET_h2s(hash)); | 59 | printf (" %s]", GNUNET_h2s (hash)); |
60 | printf ("[%s] ", GNUNET_sh2s(&(message->header.sender_id))); | 60 | printf ("[%s] ", GNUNET_sh2s (&(message->header.sender_id))); |
61 | 61 | ||
62 | if (flags & GNUNET_MESSENGER_FLAG_PRIVATE) | 62 | if (flags & GNUNET_MESSENGER_FLAG_PRIVATE) |
63 | printf ("*"); | 63 | printf ("*"); |
@@ -71,7 +71,8 @@ on_message (void *cls, | |||
71 | } | 71 | } |
72 | case GNUNET_MESSENGER_KIND_NAME: | 72 | case GNUNET_MESSENGER_KIND_NAME: |
73 | { | 73 | { |
74 | printf ("* '%s' gets renamed to '%s'\n", sender_name, message->body.name.name); | 74 | printf ("* '%s' gets renamed to '%s'\n", sender_name, |
75 | message->body.name.name); | ||
75 | break; | 76 | break; |
76 | } | 77 | } |
77 | case GNUNET_MESSENGER_KIND_LEAVE: | 78 | case GNUNET_MESSENGER_KIND_LEAVE: |
@@ -81,7 +82,8 @@ on_message (void *cls, | |||
81 | } | 82 | } |
82 | case GNUNET_MESSENGER_KIND_PEER: | 83 | case GNUNET_MESSENGER_KIND_PEER: |
83 | { | 84 | { |
84 | printf ("* '%s' opened the room on: %s\n", sender_name, GNUNET_i2s_full (&(message->body.peer.peer))); | 85 | printf ("* '%s' opened the room on: %s\n", sender_name, |
86 | GNUNET_i2s_full (&(message->body.peer.peer))); | ||
85 | break; | 87 | break; |
86 | } | 88 | } |
87 | case GNUNET_MESSENGER_KIND_TEXT: | 89 | case GNUNET_MESSENGER_KIND_TEXT: |
@@ -96,16 +98,18 @@ on_message (void *cls, | |||
96 | } | 98 | } |
97 | default: | 99 | default: |
98 | { | 100 | { |
99 | printf ("~ message: %s\n", GNUNET_MESSENGER_name_of_kind(message->header.kind)); | 101 | printf ("~ message: %s\n", |
102 | GNUNET_MESSENGER_name_of_kind (message->header.kind)); | ||
100 | break; | 103 | break; |
101 | } | 104 | } |
102 | } | 105 | } |
103 | 106 | ||
104 | if ((GNUNET_MESSENGER_KIND_JOIN == message->header.kind) && (flags & GNUNET_MESSENGER_FLAG_SENT)) | 107 | if ((GNUNET_MESSENGER_KIND_JOIN == message->header.kind) && |
108 | (flags & GNUNET_MESSENGER_FLAG_SENT)) | ||
105 | { | 109 | { |
106 | const char* name = GNUNET_MESSENGER_get_name (messenger); | 110 | const char *name = GNUNET_MESSENGER_get_name (messenger); |
107 | 111 | ||
108 | if (!name) | 112 | if (! name) |
109 | return; | 113 | return; |
110 | 114 | ||
111 | struct GNUNET_MESSENGER_Message response; | 115 | struct GNUNET_MESSENGER_Message response; |
@@ -118,6 +122,7 @@ on_message (void *cls, | |||
118 | } | 122 | } |
119 | } | 123 | } |
120 | 124 | ||
125 | |||
121 | struct GNUNET_SCHEDULER_Task *read_task; | 126 | struct GNUNET_SCHEDULER_Task *read_task; |
122 | struct GNUNET_IDENTITY_EgoLookup *ego_lookup; | 127 | struct GNUNET_IDENTITY_EgoLookup *ego_lookup; |
123 | 128 | ||
@@ -139,11 +144,12 @@ shutdown_hook (void *cls) | |||
139 | 144 | ||
140 | if (messenger) | 145 | if (messenger) |
141 | GNUNET_MESSENGER_disconnect (messenger); | 146 | GNUNET_MESSENGER_disconnect (messenger); |
142 | 147 | ||
143 | if (ego_lookup) | 148 | if (ego_lookup) |
144 | GNUNET_IDENTITY_ego_lookup_cancel (ego_lookup); | 149 | GNUNET_IDENTITY_ego_lookup_cancel (ego_lookup); |
145 | } | 150 | } |
146 | 151 | ||
152 | |||
147 | static void | 153 | static void |
148 | listen_stdio (void *cls); | 154 | listen_stdio (void *cls); |
149 | 155 | ||
@@ -156,12 +162,13 @@ iterate_send_private_message (void *cls, | |||
156 | { | 162 | { |
157 | struct GNUNET_MESSENGER_Message *message = cls; | 163 | struct GNUNET_MESSENGER_Message *message = cls; |
158 | 164 | ||
159 | if (GNUNET_MESSENGER_contact_get_key(contact)) | 165 | if (GNUNET_MESSENGER_contact_get_key (contact)) |
160 | GNUNET_MESSENGER_send_message (room, message, contact); | 166 | GNUNET_MESSENGER_send_message (room, message, contact); |
161 | 167 | ||
162 | return GNUNET_YES; | 168 | return GNUNET_YES; |
163 | } | 169 | } |
164 | 170 | ||
171 | |||
165 | int private_mode; | 172 | int private_mode; |
166 | 173 | ||
167 | /** | 174 | /** |
@@ -197,13 +204,15 @@ read_stdio (void *cls) | |||
197 | message.body.text.text = buffer; | 204 | message.body.text.text = buffer; |
198 | 205 | ||
199 | if (GNUNET_YES == private_mode) | 206 | if (GNUNET_YES == private_mode) |
200 | GNUNET_MESSENGER_iterate_members(room, iterate_send_private_message, &message); | 207 | GNUNET_MESSENGER_iterate_members (room, iterate_send_private_message, |
208 | &message); | ||
201 | else | 209 | else |
202 | GNUNET_MESSENGER_send_message (room, &message, NULL); | 210 | GNUNET_MESSENGER_send_message (room, &message, NULL); |
203 | 211 | ||
204 | read_task = GNUNET_SCHEDULER_add_now (listen_stdio, cls); | 212 | read_task = GNUNET_SCHEDULER_add_now (listen_stdio, cls); |
205 | } | 213 | } |
206 | 214 | ||
215 | |||
207 | /** | 216 | /** |
208 | * Wait for input on STDIO and send it out over the #ch. | 217 | * Wait for input on STDIO and send it out over the #ch. |
209 | * | 218 | * |
@@ -225,6 +234,7 @@ listen_stdio (void *cls) | |||
225 | GNUNET_NETWORK_fdset_destroy (rs); | 234 | GNUNET_NETWORK_fdset_destroy (rs); |
226 | } | 235 | } |
227 | 236 | ||
237 | |||
228 | /** | 238 | /** |
229 | * Initial task to startup application. | 239 | * Initial task to startup application. |
230 | * | 240 | * |
@@ -240,6 +250,7 @@ idle (void *cls) | |||
240 | read_task = GNUNET_SCHEDULER_add_now (listen_stdio, room); | 250 | read_task = GNUNET_SCHEDULER_add_now (listen_stdio, room); |
241 | } | 251 | } |
242 | 252 | ||
253 | |||
243 | char *door_id; | 254 | char *door_id; |
244 | char *ego_name; | 255 | char *ego_name; |
245 | char *room_key; | 256 | char *room_key; |
@@ -266,12 +277,16 @@ on_identity (void *cls, | |||
266 | struct GNUNET_PeerIdentity *door = NULL; | 277 | struct GNUNET_PeerIdentity *door = NULL; |
267 | 278 | ||
268 | if ((door_id) && | 279 | if ((door_id) && |
269 | (GNUNET_OK == GNUNET_CRYPTO_eddsa_public_key_from_string (door_id, strlen (door_id), &(door_peer.public_key)))) | 280 | (GNUNET_OK == GNUNET_CRYPTO_eddsa_public_key_from_string (door_id, |
281 | strlen ( | ||
282 | door_id), | ||
283 | &(door_peer. | ||
284 | public_key)))) | ||
270 | door = &door_peer; | 285 | door = &door_peer; |
271 | 286 | ||
272 | const char *name = GNUNET_MESSENGER_get_name (handle); | 287 | const char *name = GNUNET_MESSENGER_get_name (handle); |
273 | 288 | ||
274 | if (!name) | 289 | if (! name) |
275 | name = "anonymous"; | 290 | name = "anonymous"; |
276 | 291 | ||
277 | printf ("* Welcome to the messenger, '%s'!\n", name); | 292 | printf ("* Welcome to the messenger, '%s'!\n", name); |
@@ -295,15 +310,18 @@ on_identity (void *cls, | |||
295 | 310 | ||
296 | shutdown_task = GNUNET_SCHEDULER_add_shutdown (shutdown_hook, room); | 311 | shutdown_task = GNUNET_SCHEDULER_add_shutdown (shutdown_hook, room); |
297 | 312 | ||
298 | if (!room) | 313 | if (! room) |
299 | GNUNET_SCHEDULER_shutdown (); | 314 | GNUNET_SCHEDULER_shutdown (); |
300 | else | 315 | else |
301 | { | 316 | { |
302 | GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_relative_get_zero_ (), GNUNET_SCHEDULER_PRIORITY_IDLE, idle, | 317 | GNUNET_SCHEDULER_add_delayed_with_priority ( |
303 | room); | 318 | GNUNET_TIME_relative_get_zero_ (), |
319 | GNUNET_SCHEDULER_PRIORITY_IDLE, | ||
320 | idle, room); | ||
304 | } | 321 | } |
305 | } | 322 | } |
306 | 323 | ||
324 | |||
307 | static void | 325 | static void |
308 | on_ego_lookup (void *cls, | 326 | on_ego_lookup (void *cls, |
309 | struct GNUNET_IDENTITY_Ego *ego) | 327 | struct GNUNET_IDENTITY_Ego *ego) |
@@ -313,7 +331,8 @@ on_ego_lookup (void *cls, | |||
313 | const struct GNUNET_IDENTITY_PrivateKey *key; | 331 | const struct GNUNET_IDENTITY_PrivateKey *key; |
314 | key = ego ? GNUNET_IDENTITY_ego_get_private_key (ego) : NULL; | 332 | key = ego ? GNUNET_IDENTITY_ego_get_private_key (ego) : NULL; |
315 | 333 | ||
316 | messenger = GNUNET_MESSENGER_connect (config, ego_name, key, &on_message, NULL); | 334 | messenger = GNUNET_MESSENGER_connect (config, ego_name, key, &on_message, |
335 | NULL); | ||
317 | 336 | ||
318 | on_identity (NULL, messenger); | 337 | on_identity (NULL, messenger); |
319 | } | 338 | } |
@@ -329,7 +348,7 @@ on_ego_lookup (void *cls, | |||
329 | */ | 348 | */ |
330 | static void | 349 | static void |
331 | run (void *cls, | 350 | run (void *cls, |
332 | char *const*args, | 351 | char *const *args, |
333 | const char *cfgfile, | 352 | const char *cfgfile, |
334 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 353 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
335 | { | 354 | { |
@@ -337,7 +356,8 @@ run (void *cls, | |||
337 | 356 | ||
338 | if (ego_name) | 357 | if (ego_name) |
339 | { | 358 | { |
340 | ego_lookup = GNUNET_IDENTITY_ego_lookup (cfg, ego_name, &on_ego_lookup, NULL); | 359 | ego_lookup = GNUNET_IDENTITY_ego_lookup (cfg, ego_name, &on_ego_lookup, |
360 | NULL); | ||
341 | messenger = NULL; | 361 | messenger = NULL; |
342 | } | 362 | } |
343 | else | 363 | else |
@@ -352,6 +372,7 @@ run (void *cls, | |||
352 | on_identity (NULL, messenger); | 372 | on_identity (NULL, messenger); |
353 | } | 373 | } |
354 | 374 | ||
375 | |||
355 | /** | 376 | /** |
356 | * The main function to obtain messenger information. | 377 | * The main function to obtain messenger information. |
357 | * | 378 | * |
@@ -363,17 +384,26 @@ int | |||
363 | main (int argc, | 384 | main (int argc, |
364 | char **argv) | 385 | char **argv) |
365 | { | 386 | { |
366 | const char *description = "Open and connect to rooms using the MESSENGER to chat."; | 387 | const char *description = |
367 | 388 | "Open and connect to rooms using the MESSENGER to chat."; | |
368 | struct GNUNET_GETOPT_CommandLineOption options[] = | 389 | |
369 | { | 390 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
370 | GNUNET_GETOPT_option_string ('d', "door", "PEERIDENTITY", "peer identity to entry into the room", &door_id), | 391 | GNUNET_GETOPT_option_string ('d', "door", "PEERIDENTITY", |
371 | GNUNET_GETOPT_option_string ('e', "ego", "IDENTITY", "identity to use for messaging", &ego_name), | 392 | "peer identity to entry into the room", |
372 | GNUNET_GETOPT_option_string ('r', "room", "ROOMKEY", "key of the room to connect to", &room_key), | 393 | &door_id), |
373 | GNUNET_GETOPT_option_flag ('p', "private", "flag to enable private mode", &private_mode), | 394 | GNUNET_GETOPT_option_string ('e', "ego", "IDENTITY", |
395 | "identity to use for messaging", | ||
396 | &ego_name), | ||
397 | GNUNET_GETOPT_option_string ('r', "room", "ROOMKEY", | ||
398 | "key of the room to connect to", | ||
399 | &room_key), | ||
400 | GNUNET_GETOPT_option_flag ('p', "private", "flag to enable private mode", | ||
401 | &private_mode), | ||
374 | GNUNET_GETOPT_OPTION_END | 402 | GNUNET_GETOPT_OPTION_END |
375 | }; | 403 | }; |
376 | 404 | ||
377 | return (GNUNET_OK == GNUNET_PROGRAM_run (argc, argv, "gnunet-messenger\0", gettext_noop(description), options, &run, | 405 | return (GNUNET_OK == GNUNET_PROGRAM_run (argc, argv, "gnunet-messenger\0", |
378 | NULL) ? EXIT_SUCCESS : EXIT_FAILURE); | 406 | gettext_noop (description), options, |
407 | &run, | ||
408 | NULL) ? EXIT_SUCCESS : EXIT_FAILURE); | ||
379 | } | 409 | } |
diff --git a/src/messenger/gnunet-service-messenger.c b/src/messenger/gnunet-service-messenger.c index 0b447f3cf..bebadb943 100644 --- a/src/messenger/gnunet-service-messenger.c +++ b/src/messenger/gnunet-service-messenger.c | |||
@@ -50,6 +50,7 @@ handle_create (void *cls, | |||
50 | GNUNET_SERVICE_client_continue (msg_client->client); | 50 | GNUNET_SERVICE_client_continue (msg_client->client); |
51 | } | 51 | } |
52 | 52 | ||
53 | |||
53 | static void | 54 | static void |
54 | handle_destroy (void *cls, | 55 | handle_destroy (void *cls, |
55 | const struct GNUNET_MESSENGER_DestroyMessage *msg) | 56 | const struct GNUNET_MESSENGER_DestroyMessage *msg) |
@@ -61,6 +62,7 @@ handle_destroy (void *cls, | |||
61 | GNUNET_SERVICE_client_drop (msg_client->client); | 62 | GNUNET_SERVICE_client_drop (msg_client->client); |
62 | } | 63 | } |
63 | 64 | ||
65 | |||
64 | static int | 66 | static int |
65 | check_room_initial_key (const struct GNUNET_MESSENGER_RoomMessage *msg) | 67 | check_room_initial_key (const struct GNUNET_MESSENGER_RoomMessage *msg) |
66 | { | 68 | { |
@@ -78,12 +80,15 @@ check_room_initial_key (const struct GNUNET_MESSENGER_RoomMessage *msg) | |||
78 | struct GNUNET_IDENTITY_PublicKey key; | 80 | struct GNUNET_IDENTITY_PublicKey key; |
79 | size_t key_len; | 81 | size_t key_len; |
80 | 82 | ||
81 | if (GNUNET_OK != GNUNET_IDENTITY_read_public_key_from_buffer(msg_buffer, msg_length, &key, &key_len)) | 83 | if (GNUNET_OK != GNUNET_IDENTITY_read_public_key_from_buffer (msg_buffer, |
84 | msg_length, | ||
85 | &key, &key_len)) | ||
82 | return GNUNET_NO; | 86 | return GNUNET_NO; |
83 | 87 | ||
84 | return key_len == msg_length ? GNUNET_OK : GNUNET_NO; | 88 | return key_len == msg_length ? GNUNET_OK : GNUNET_NO; |
85 | } | 89 | } |
86 | 90 | ||
91 | |||
87 | static void | 92 | static void |
88 | initialize_handle_via_key (struct GNUNET_MESSENGER_SrvHandle *handle, | 93 | initialize_handle_via_key (struct GNUNET_MESSENGER_SrvHandle *handle, |
89 | const struct GNUNET_MESSENGER_RoomMessage *msg) | 94 | const struct GNUNET_MESSENGER_RoomMessage *msg) |
@@ -99,15 +104,20 @@ initialize_handle_via_key (struct GNUNET_MESSENGER_SrvHandle *handle, | |||
99 | struct GNUNET_IDENTITY_PublicKey key; | 104 | struct GNUNET_IDENTITY_PublicKey key; |
100 | size_t key_len; | 105 | size_t key_len; |
101 | 106 | ||
102 | if (GNUNET_OK == GNUNET_IDENTITY_read_public_key_from_buffer(msg_buffer, msg_length, &key, &key_len)) | 107 | if (GNUNET_OK == GNUNET_IDENTITY_read_public_key_from_buffer (msg_buffer, |
103 | set_srv_handle_key(handle, &key); | 108 | msg_length, |
109 | &key, | ||
110 | &key_len)) | ||
111 | set_srv_handle_key (handle, &key); | ||
104 | else | 112 | else |
105 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Initialization failed while reading invalid key!\n"); | 113 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
114 | "Initialization failed while reading invalid key!\n"); | ||
106 | } | 115 | } |
107 | else | 116 | else |
108 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Initialization is missing key!\n"); | 117 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Initialization is missing key!\n"); |
109 | } | 118 | } |
110 | 119 | ||
120 | |||
111 | static int | 121 | static int |
112 | check_room_open (void *cls, | 122 | check_room_open (void *cls, |
113 | const struct GNUNET_MESSENGER_RoomMessage *msg) | 123 | const struct GNUNET_MESSENGER_RoomMessage *msg) |
@@ -115,6 +125,7 @@ check_room_open (void *cls, | |||
115 | return check_room_initial_key (msg); | 125 | return check_room_initial_key (msg); |
116 | } | 126 | } |
117 | 127 | ||
128 | |||
118 | static void | 129 | static void |
119 | handle_room_open (void *cls, | 130 | handle_room_open (void *cls, |
120 | const struct GNUNET_MESSENGER_RoomMessage *msg) | 131 | const struct GNUNET_MESSENGER_RoomMessage *msg) |
@@ -148,6 +159,7 @@ handle_room_open (void *cls, | |||
148 | GNUNET_SERVICE_client_continue (msg_client->client); | 159 | GNUNET_SERVICE_client_continue (msg_client->client); |
149 | } | 160 | } |
150 | 161 | ||
162 | |||
151 | static int | 163 | static int |
152 | check_room_entry (void *cls, | 164 | check_room_entry (void *cls, |
153 | const struct GNUNET_MESSENGER_RoomMessage *msg) | 165 | const struct GNUNET_MESSENGER_RoomMessage *msg) |
@@ -155,6 +167,7 @@ check_room_entry (void *cls, | |||
155 | return check_room_initial_key (msg); | 167 | return check_room_initial_key (msg); |
156 | } | 168 | } |
157 | 169 | ||
170 | |||
158 | static void | 171 | static void |
159 | handle_room_entry (void *cls, | 172 | handle_room_entry (void *cls, |
160 | const struct GNUNET_MESSENGER_RoomMessage *msg) | 173 | const struct GNUNET_MESSENGER_RoomMessage *msg) |
@@ -191,6 +204,7 @@ handle_room_entry (void *cls, | |||
191 | GNUNET_SERVICE_client_continue (msg_client->client); | 204 | GNUNET_SERVICE_client_continue (msg_client->client); |
192 | } | 205 | } |
193 | 206 | ||
207 | |||
194 | static void | 208 | static void |
195 | handle_room_close (void *cls, | 209 | handle_room_close (void *cls, |
196 | const struct GNUNET_MESSENGER_RoomMessage *msg) | 210 | const struct GNUNET_MESSENGER_RoomMessage *msg) |
@@ -219,6 +233,7 @@ handle_room_close (void *cls, | |||
219 | GNUNET_SERVICE_client_continue (msg_client->client); | 233 | GNUNET_SERVICE_client_continue (msg_client->client); |
220 | } | 234 | } |
221 | 235 | ||
236 | |||
222 | static int | 237 | static int |
223 | check_send_message (void *cls, | 238 | check_send_message (void *cls, |
224 | const struct GNUNET_MESSENGER_SendMessage *msg) | 239 | const struct GNUNET_MESSENGER_SendMessage *msg) |
@@ -233,10 +248,12 @@ check_send_message (void *cls, | |||
233 | 248 | ||
234 | struct GNUNET_MESSENGER_Message message; | 249 | struct GNUNET_MESSENGER_Message message; |
235 | 250 | ||
236 | if (msg_length < get_message_kind_size (GNUNET_MESSENGER_KIND_UNKNOWN, GNUNET_YES)) | 251 | if (msg_length < get_message_kind_size (GNUNET_MESSENGER_KIND_UNKNOWN, |
252 | GNUNET_YES)) | ||
237 | return GNUNET_NO; | 253 | return GNUNET_NO; |
238 | 254 | ||
239 | if (GNUNET_YES != decode_message (&message, msg_length, msg_buffer, GNUNET_YES, | 255 | if (GNUNET_YES != decode_message (&message, msg_length, msg_buffer, |
256 | GNUNET_YES, | ||
240 | NULL)) | 257 | NULL)) |
241 | return GNUNET_NO; | 258 | return GNUNET_NO; |
242 | 259 | ||
@@ -246,6 +263,7 @@ check_send_message (void *cls, | |||
246 | return GNUNET_SYSERR != allowed? GNUNET_OK : GNUNET_NO; | 263 | return GNUNET_SYSERR != allowed? GNUNET_OK : GNUNET_NO; |
247 | } | 264 | } |
248 | 265 | ||
266 | |||
249 | static void | 267 | static void |
250 | handle_send_message (void *cls, | 268 | handle_send_message (void *cls, |
251 | const struct GNUNET_MESSENGER_SendMessage *msg) | 269 | const struct GNUNET_MESSENGER_SendMessage *msg) |
@@ -269,12 +287,13 @@ handle_send_message (void *cls, | |||
269 | GNUNET_MESSENGER_name_of_kind (message.header.kind), | 287 | GNUNET_MESSENGER_name_of_kind (message.header.kind), |
270 | GNUNET_h2s (key)); | 288 | GNUNET_h2s (key)); |
271 | 289 | ||
272 | end_handling: | 290 | end_handling: |
273 | cleanup_message (&message); | 291 | cleanup_message (&message); |
274 | 292 | ||
275 | GNUNET_SERVICE_client_continue (msg_client->client); | 293 | GNUNET_SERVICE_client_continue (msg_client->client); |
276 | } | 294 | } |
277 | 295 | ||
296 | |||
278 | static void | 297 | static void |
279 | callback_found_message (void *cls, | 298 | callback_found_message (void *cls, |
280 | struct GNUNET_MESSENGER_SrvRoom *room, | 299 | struct GNUNET_MESSENGER_SrvRoom *room, |
@@ -283,14 +302,15 @@ callback_found_message (void *cls, | |||
283 | { | 302 | { |
284 | struct GNUNET_MESSENGER_Client *msg_client = cls; | 303 | struct GNUNET_MESSENGER_Client *msg_client = cls; |
285 | 304 | ||
286 | if (!message) | 305 | if (! message) |
287 | { | 306 | { |
288 | struct GNUNET_MESSENGER_GetMessage *response; | 307 | struct GNUNET_MESSENGER_GetMessage *response; |
289 | struct GNUNET_MQ_Envelope *env; | 308 | struct GNUNET_MQ_Envelope *env; |
290 | 309 | ||
291 | env = GNUNET_MQ_msg (response, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE); | 310 | env = GNUNET_MQ_msg (response, |
292 | GNUNET_memcpy(&(response->key), &(room->key), sizeof(room->key)); | 311 | GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE); |
293 | GNUNET_memcpy(&(response->hash), hash, sizeof(*hash)); | 312 | GNUNET_memcpy (&(response->key), &(room->key), sizeof(room->key)); |
313 | GNUNET_memcpy (&(response->hash), hash, sizeof(*hash)); | ||
294 | GNUNET_MQ_send (msg_client->handle->mq, env); | 314 | GNUNET_MQ_send (msg_client->handle->mq, env); |
295 | return; | 315 | return; |
296 | } | 316 | } |
@@ -303,15 +323,17 @@ callback_found_message (void *cls, | |||
303 | 323 | ||
304 | session.peer = get_store_peer_of (store, message, hash); | 324 | session.peer = get_store_peer_of (store, message, hash); |
305 | 325 | ||
306 | if (!session.peer) | 326 | if (! session.peer) |
307 | return; | 327 | return; |
308 | } | 328 | } |
309 | else | 329 | else |
310 | { | 330 | { |
311 | struct GNUNET_MESSENGER_MemberStore *store = get_srv_room_member_store (room); | 331 | struct GNUNET_MESSENGER_MemberStore *store = get_srv_room_member_store ( |
312 | struct GNUNET_MESSENGER_Member *member = get_store_member_of (store, message); | 332 | room); |
333 | struct GNUNET_MESSENGER_Member *member = get_store_member_of (store, | ||
334 | message); | ||
313 | 335 | ||
314 | if (!member) | 336 | if (! member) |
315 | { | 337 | { |
316 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Sender of message (%s) unknown!\n", | 338 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Sender of message (%s) unknown!\n", |
317 | GNUNET_h2s (hash)); | 339 | GNUNET_h2s (hash)); |
@@ -320,7 +342,7 @@ callback_found_message (void *cls, | |||
320 | 342 | ||
321 | session.member = get_member_session_of (member, message, hash); | 343 | session.member = get_member_session_of (member, message, hash); |
322 | 344 | ||
323 | if (!session.member) | 345 | if (! session.member) |
324 | return; | 346 | return; |
325 | } | 347 | } |
326 | 348 | ||
@@ -328,6 +350,7 @@ callback_found_message (void *cls, | |||
328 | hash); | 350 | hash); |
329 | } | 351 | } |
330 | 352 | ||
353 | |||
331 | static void | 354 | static void |
332 | handle_get_message (void *cls, | 355 | handle_get_message (void *cls, |
333 | const struct GNUNET_MESSENGER_GetMessage *msg) | 356 | const struct GNUNET_MESSENGER_GetMessage *msg) |
@@ -364,7 +387,8 @@ handle_get_message (void *cls, | |||
364 | goto end_handling; | 387 | goto end_handling; |
365 | } | 388 | } |
366 | 389 | ||
367 | const struct GNUNET_IDENTITY_PublicKey* pubkey = get_srv_handle_key(msg_client->handle); | 390 | const struct GNUNET_IDENTITY_PublicKey *pubkey = get_srv_handle_key ( |
391 | msg_client->handle); | ||
368 | 392 | ||
369 | if (! pubkey) | 393 | if (! pubkey) |
370 | { | 394 | { |
@@ -386,10 +410,11 @@ handle_get_message (void *cls, | |||
386 | request_srv_room_message (room, &(msg->hash), session, callback_found_message, | 410 | request_srv_room_message (room, &(msg->hash), session, callback_found_message, |
387 | msg_client); | 411 | msg_client); |
388 | 412 | ||
389 | end_handling: | 413 | end_handling: |
390 | GNUNET_SERVICE_client_continue (msg_client->client); | 414 | GNUNET_SERVICE_client_continue (msg_client->client); |
391 | } | 415 | } |
392 | 416 | ||
417 | |||
393 | static void* | 418 | static void* |
394 | callback_client_connect (void *cls, | 419 | callback_client_connect (void *cls, |
395 | struct GNUNET_SERVICE_Client *client, | 420 | struct GNUNET_SERVICE_Client *client, |
@@ -404,6 +429,7 @@ callback_client_connect (void *cls, | |||
404 | return msg_client; | 429 | return msg_client; |
405 | } | 430 | } |
406 | 431 | ||
432 | |||
407 | static void | 433 | static void |
408 | callback_client_disconnect (void *cls, | 434 | callback_client_disconnect (void *cls, |
409 | struct GNUNET_SERVICE_Client *client, | 435 | struct GNUNET_SERVICE_Client *client, |
@@ -416,6 +442,7 @@ callback_client_disconnect (void *cls, | |||
416 | GNUNET_free (msg_client); | 442 | GNUNET_free (msg_client); |
417 | } | 443 | } |
418 | 444 | ||
445 | |||
419 | /** | 446 | /** |
420 | * Setup MESSENGER internals. | 447 | * Setup MESSENGER internals. |
421 | * | 448 | * |
@@ -434,6 +461,7 @@ run (void *cls, | |||
434 | GNUNET_SCHEDULER_shutdown (); | 461 | GNUNET_SCHEDULER_shutdown (); |
435 | } | 462 | } |
436 | 463 | ||
464 | |||
437 | /** | 465 | /** |
438 | * Define "main" method using service macro. | 466 | * Define "main" method using service macro. |
439 | */ | 467 | */ |
@@ -445,16 +473,17 @@ GNUNET_SERVICE_MAIN ( | |||
445 | &callback_client_disconnect, | 473 | &callback_client_disconnect, |
446 | NULL, | 474 | NULL, |
447 | GNUNET_MQ_hd_fixed_size (create, | 475 | GNUNET_MQ_hd_fixed_size (create, |
448 | GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_CREATE, struct | 476 | GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_CREATE, |
477 | struct | ||
449 | GNUNET_MESSENGER_CreateMessage, NULL), | 478 | GNUNET_MESSENGER_CreateMessage, NULL), |
450 | GNUNET_MQ_hd_fixed_size (destroy, | 479 | GNUNET_MQ_hd_fixed_size (destroy, |
451 | GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_DESTROY, | 480 | GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_DESTROY, |
452 | struct | 481 | struct |
453 | GNUNET_MESSENGER_DestroyMessage, NULL), | 482 | GNUNET_MESSENGER_DestroyMessage, NULL), |
454 | GNUNET_MQ_hd_var_size (room_open, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN, | 483 | GNUNET_MQ_hd_var_size (room_open, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN, |
455 | struct GNUNET_MESSENGER_RoomMessage, NULL), | 484 | struct GNUNET_MESSENGER_RoomMessage, NULL), |
456 | GNUNET_MQ_hd_var_size (room_entry, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY, | 485 | GNUNET_MQ_hd_var_size (room_entry, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY, |
457 | struct GNUNET_MESSENGER_RoomMessage, NULL), | 486 | struct GNUNET_MESSENGER_RoomMessage, NULL), |
458 | GNUNET_MQ_hd_fixed_size (room_close, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_CLOSE, | 487 | GNUNET_MQ_hd_fixed_size (room_close, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_CLOSE, |
459 | struct GNUNET_MESSENGER_RoomMessage, NULL), | 488 | struct GNUNET_MESSENGER_RoomMessage, NULL), |
460 | GNUNET_MQ_hd_var_size (send_message, | 489 | GNUNET_MQ_hd_var_size (send_message, |
diff --git a/src/messenger/gnunet-service-messenger_basement.c b/src/messenger/gnunet-service-messenger_basement.c index ae0dcaa62..d4de28c4c 100644 --- a/src/messenger/gnunet-service-messenger_basement.c +++ b/src/messenger/gnunet-service-messenger_basement.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--2021 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 |
@@ -29,7 +29,7 @@ | |||
29 | size_t | 29 | size_t |
30 | count_of_tunnels (const struct GNUNET_MESSENGER_ListTunnels *tunnels) | 30 | count_of_tunnels (const struct GNUNET_MESSENGER_ListTunnels *tunnels) |
31 | { | 31 | { |
32 | GNUNET_assert(tunnels); | 32 | GNUNET_assert (tunnels); |
33 | 33 | ||
34 | const struct GNUNET_MESSENGER_ListTunnel *element; | 34 | const struct GNUNET_MESSENGER_ListTunnel *element; |
35 | size_t count = 0; | 35 | size_t count = 0; |
@@ -40,6 +40,7 @@ count_of_tunnels (const struct GNUNET_MESSENGER_ListTunnels *tunnels) | |||
40 | return count; | 40 | return count; |
41 | } | 41 | } |
42 | 42 | ||
43 | |||
43 | int | 44 | int |
44 | should_connect_tunnel_to (size_t count, | 45 | should_connect_tunnel_to (size_t count, |
45 | size_t src, | 46 | size_t src, |
@@ -51,6 +52,7 @@ should_connect_tunnel_to (size_t count, | |||
51 | return GNUNET_NO; | 52 | return GNUNET_NO; |
52 | } | 53 | } |
53 | 54 | ||
55 | |||
54 | int | 56 | int |
55 | required_connection_between (size_t count, | 57 | required_connection_between (size_t count, |
56 | size_t src, | 58 | size_t src, |
diff --git a/src/messenger/gnunet-service-messenger_ego_store.c b/src/messenger/gnunet-service-messenger_ego_store.c index 3eb313b08..eb094cfd7 100644 --- a/src/messenger/gnunet-service-messenger_ego_store.c +++ b/src/messenger/gnunet-service-messenger_ego_store.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 |
@@ -34,7 +34,7 @@ callback_update_ego (void *cls, | |||
34 | void **ctx, | 34 | void **ctx, |
35 | const char *identifier) | 35 | const char *identifier) |
36 | { | 36 | { |
37 | if ((!ctx) || (!identifier)) | 37 | if ((! ctx) || (! identifier)) |
38 | return; | 38 | return; |
39 | 39 | ||
40 | struct GNUNET_MESSENGER_EgoStore *store = cls; | 40 | struct GNUNET_MESSENGER_EgoStore *store = cls; |
@@ -42,7 +42,8 @@ callback_update_ego (void *cls, | |||
42 | if (ego) | 42 | if (ego) |
43 | { | 43 | { |
44 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New ego in use: '%s'\n", identifier); | 44 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New ego in use: '%s'\n", identifier); |
45 | update_store_ego (store, identifier, GNUNET_IDENTITY_ego_get_private_key (ego)); | 45 | update_store_ego (store, identifier, |
46 | GNUNET_IDENTITY_ego_get_private_key (ego)); | ||
46 | } | 47 | } |
47 | else | 48 | else |
48 | { | 49 | { |
@@ -51,14 +52,16 @@ callback_update_ego (void *cls, | |||
51 | } | 52 | } |
52 | } | 53 | } |
53 | 54 | ||
55 | |||
54 | void | 56 | void |
55 | init_ego_store(struct GNUNET_MESSENGER_EgoStore *store, | 57 | init_ego_store (struct GNUNET_MESSENGER_EgoStore *store, |
56 | const struct GNUNET_CONFIGURATION_Handle *config) | 58 | const struct GNUNET_CONFIGURATION_Handle *config) |
57 | { | 59 | { |
58 | GNUNET_assert ((store) && (config)); | 60 | GNUNET_assert ((store) && (config)); |
59 | 61 | ||
60 | store->cfg = config; | 62 | store->cfg = config; |
61 | store->identity = GNUNET_IDENTITY_connect (config, &callback_update_ego, store); | 63 | store->identity = GNUNET_IDENTITY_connect (config, &callback_update_ego, |
64 | store); | ||
62 | store->egos = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); | 65 | store->egos = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); |
63 | store->handles = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); | 66 | store->handles = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); |
64 | 67 | ||
@@ -69,18 +72,20 @@ init_ego_store(struct GNUNET_MESSENGER_EgoStore *store, | |||
69 | store->op_end = NULL; | 72 | store->op_end = NULL; |
70 | } | 73 | } |
71 | 74 | ||
75 | |||
72 | static int | 76 | static int |
73 | iterate_destroy_egos (void *cls, | 77 | iterate_destroy_egos (void *cls, |
74 | const struct GNUNET_HashCode *key, | 78 | const struct GNUNET_HashCode *key, |
75 | void *value) | 79 | void *value) |
76 | { | 80 | { |
77 | struct GNUNET_MESSENGER_Ego *ego = value; | 81 | struct GNUNET_MESSENGER_Ego *ego = value; |
78 | GNUNET_free(ego); | 82 | GNUNET_free (ego); |
79 | return GNUNET_YES; | 83 | return GNUNET_YES; |
80 | } | 84 | } |
81 | 85 | ||
86 | |||
82 | void | 87 | void |
83 | clear_ego_store(struct GNUNET_MESSENGER_EgoStore *store) | 88 | clear_ego_store (struct GNUNET_MESSENGER_EgoStore *store) |
84 | { | 89 | { |
85 | GNUNET_assert (store); | 90 | GNUNET_assert (store); |
86 | 91 | ||
@@ -105,18 +110,19 @@ clear_ego_store(struct GNUNET_MESSENGER_EgoStore *store) | |||
105 | { | 110 | { |
106 | lu = store->lu_start; | 111 | lu = store->lu_start; |
107 | 112 | ||
108 | GNUNET_IDENTITY_ego_lookup_cancel(lu->lookup); | 113 | GNUNET_IDENTITY_ego_lookup_cancel (lu->lookup); |
109 | GNUNET_CONTAINER_DLL_remove (store->lu_start, store->lu_end, lu); | 114 | GNUNET_CONTAINER_DLL_remove (store->lu_start, store->lu_end, lu); |
110 | 115 | ||
111 | if (lu->identifier) | 116 | if (lu->identifier) |
112 | GNUNET_free(lu->identifier); | 117 | GNUNET_free (lu->identifier); |
113 | 118 | ||
114 | GNUNET_free (lu); | 119 | GNUNET_free (lu); |
115 | } | 120 | } |
116 | 121 | ||
117 | GNUNET_CONTAINER_multihashmap_iterate (store->egos, iterate_destroy_egos, NULL); | 122 | GNUNET_CONTAINER_multihashmap_iterate (store->egos, |
123 | iterate_destroy_egos, | ||
124 | NULL); | ||
118 | GNUNET_CONTAINER_multihashmap_destroy (store->egos); | 125 | GNUNET_CONTAINER_multihashmap_destroy (store->egos); |
119 | |||
120 | GNUNET_CONTAINER_multihashmap_destroy (store->handles); | 126 | GNUNET_CONTAINER_multihashmap_destroy (store->handles); |
121 | 127 | ||
122 | if (store->identity) | 128 | if (store->identity) |
@@ -127,6 +133,7 @@ clear_ego_store(struct GNUNET_MESSENGER_EgoStore *store) | |||
127 | } | 133 | } |
128 | } | 134 | } |
129 | 135 | ||
136 | |||
130 | static int | 137 | static int |
131 | iterate_create_ego (void *cls, | 138 | iterate_create_ego (void *cls, |
132 | const struct GNUNET_HashCode *key, | 139 | const struct GNUNET_HashCode *key, |
@@ -137,6 +144,7 @@ iterate_create_ego (void *cls, | |||
137 | return GNUNET_YES; | 144 | return GNUNET_YES; |
138 | } | 145 | } |
139 | 146 | ||
147 | |||
140 | static void | 148 | static void |
141 | callback_ego_create (void *cls, | 149 | callback_ego_create (void *cls, |
142 | const struct GNUNET_IDENTITY_PrivateKey *key, | 150 | const struct GNUNET_IDENTITY_PrivateKey *key, |
@@ -156,12 +164,16 @@ callback_ego_create (void *cls, | |||
156 | 164 | ||
157 | if (key) | 165 | if (key) |
158 | { | 166 | { |
159 | struct GNUNET_MESSENGER_Ego *msg_ego = update_store_ego (store, element->identifier, key); | 167 | struct GNUNET_MESSENGER_Ego *msg_ego = update_store_ego (store, |
168 | element->identifier, | ||
169 | key); | ||
160 | 170 | ||
161 | struct GNUNET_HashCode hash; | 171 | struct GNUNET_HashCode hash; |
162 | GNUNET_CRYPTO_hash (element->identifier, strlen (element->identifier), &hash); | 172 | GNUNET_CRYPTO_hash (element->identifier, strlen (element->identifier), |
173 | &hash); | ||
163 | 174 | ||
164 | GNUNET_CONTAINER_multihashmap_get_multiple (store->handles, &hash, iterate_create_ego, msg_ego); | 175 | GNUNET_CONTAINER_multihashmap_get_multiple (store->handles, &hash, |
176 | iterate_create_ego, msg_ego); | ||
165 | } | 177 | } |
166 | else | 178 | else |
167 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Creating ego failed!\n"); | 179 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Creating ego failed!\n"); |
@@ -171,15 +183,17 @@ callback_ego_create (void *cls, | |||
171 | GNUNET_free (element); | 183 | GNUNET_free (element); |
172 | } | 184 | } |
173 | 185 | ||
186 | |||
174 | void | 187 | void |
175 | create_store_ego (struct GNUNET_MESSENGER_EgoStore *store, | 188 | create_store_ego (struct GNUNET_MESSENGER_EgoStore *store, |
176 | const char *identifier) | 189 | const char *identifier) |
177 | { | 190 | { |
178 | GNUNET_assert ((store) && (identifier)); | 191 | GNUNET_assert ((store) && (identifier)); |
179 | 192 | ||
180 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Store create ego: %s\n", identifier); | 193 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Store create ego: %s\n", identifier); |
181 | 194 | ||
182 | struct GNUNET_MESSENGER_EgoOperation *element = GNUNET_new (struct GNUNET_MESSENGER_EgoOperation); | 195 | struct GNUNET_MESSENGER_EgoOperation *element = GNUNET_new (struct |
196 | GNUNET_MESSENGER_EgoOperation); | ||
183 | 197 | ||
184 | element->store = store; | 198 | element->store = store; |
185 | element->cls = NULL; | 199 | element->cls = NULL; |
@@ -187,17 +201,18 @@ create_store_ego (struct GNUNET_MESSENGER_EgoStore *store, | |||
187 | element->identifier = GNUNET_strdup (identifier); | 201 | element->identifier = GNUNET_strdup (identifier); |
188 | 202 | ||
189 | element->operation = GNUNET_IDENTITY_create ( | 203 | element->operation = GNUNET_IDENTITY_create ( |
190 | store->identity, | 204 | store->identity, |
191 | identifier, | 205 | identifier, |
192 | NULL, | 206 | NULL, |
193 | GNUNET_IDENTITY_TYPE_ECDSA, | 207 | GNUNET_IDENTITY_TYPE_ECDSA, |
194 | callback_ego_create, | 208 | callback_ego_create, |
195 | element | 209 | element |
196 | ); | 210 | ); |
197 | 211 | ||
198 | GNUNET_CONTAINER_DLL_insert (store->op_start, store->op_end, element); | 212 | GNUNET_CONTAINER_DLL_insert (store->op_start, store->op_end, element); |
199 | } | 213 | } |
200 | 214 | ||
215 | |||
201 | void | 216 | void |
202 | bind_store_ego (struct GNUNET_MESSENGER_EgoStore *store, | 217 | bind_store_ego (struct GNUNET_MESSENGER_EgoStore *store, |
203 | const char *identifier, | 218 | const char *identifier, |
@@ -205,19 +220,23 @@ bind_store_ego (struct GNUNET_MESSENGER_EgoStore *store, | |||
205 | { | 220 | { |
206 | GNUNET_assert ((store) && (identifier) && (handle)); | 221 | GNUNET_assert ((store) && (identifier) && (handle)); |
207 | 222 | ||
208 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Store bind ego: %s\n", identifier); | 223 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Store bind ego: %s\n", identifier); |
209 | 224 | ||
210 | struct GNUNET_HashCode hash; | 225 | struct GNUNET_HashCode hash; |
211 | GNUNET_CRYPTO_hash (identifier, strlen (identifier), &hash); | 226 | GNUNET_CRYPTO_hash (identifier, strlen (identifier), &hash); |
212 | 227 | ||
213 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains_value(store->handles, &hash, handle)) | 228 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains_value ( |
229 | store->handles, &hash, handle)) | ||
214 | return; | 230 | return; |
215 | 231 | ||
216 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put(store->handles, &hash, handle, | 232 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (store->handles, &hash, |
217 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)) | 233 | handle, |
218 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Putting handle binding to ego store failed!\n"); | 234 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)) |
235 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
236 | "Putting handle binding to ego store failed!\n"); | ||
219 | } | 237 | } |
220 | 238 | ||
239 | |||
221 | void | 240 | void |
222 | unbind_store_ego (struct GNUNET_MESSENGER_EgoStore *store, | 241 | unbind_store_ego (struct GNUNET_MESSENGER_EgoStore *store, |
223 | const char *identifier, | 242 | const char *identifier, |
@@ -225,18 +244,22 @@ unbind_store_ego (struct GNUNET_MESSENGER_EgoStore *store, | |||
225 | { | 244 | { |
226 | GNUNET_assert ((store) && (identifier) && (handle)); | 245 | GNUNET_assert ((store) && (identifier) && (handle)); |
227 | 246 | ||
228 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Store unbind ego: %s\n", identifier); | 247 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Store unbind ego: %s\n", identifier); |
229 | 248 | ||
230 | struct GNUNET_HashCode hash; | 249 | struct GNUNET_HashCode hash; |
231 | GNUNET_CRYPTO_hash (identifier, strlen (identifier), &hash); | 250 | GNUNET_CRYPTO_hash (identifier, strlen (identifier), &hash); |
232 | 251 | ||
233 | if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_contains_value(store->handles, &hash, handle)) | 252 | if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_contains_value ( |
253 | store->handles, &hash, handle)) | ||
234 | return; | 254 | return; |
235 | 255 | ||
236 | if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove(store->handles, &hash, handle)) | 256 | if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (store->handles, &hash, |
237 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Removing handle binding from ego store failed!\n"); | 257 | handle)) |
258 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
259 | "Removing handle binding from ego store failed!\n"); | ||
238 | } | 260 | } |
239 | 261 | ||
262 | |||
240 | static void | 263 | static void |
241 | callback_ego_lookup (void *cls, | 264 | callback_ego_lookup (void *cls, |
242 | struct GNUNET_IDENTITY_Ego *ego) | 265 | struct GNUNET_IDENTITY_Ego *ego) |
@@ -250,50 +273,55 @@ callback_ego_lookup (void *cls, | |||
250 | 273 | ||
251 | if (ego) | 274 | if (ego) |
252 | { | 275 | { |
253 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New ego looked up: '%s'\n", element->identifier); | 276 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New ego looked up: '%s'\n", |
277 | element->identifier); | ||
254 | msg_ego = update_store_ego ( | 278 | msg_ego = update_store_ego ( |
255 | store, | 279 | store, |
256 | element->identifier, | 280 | element->identifier, |
257 | GNUNET_IDENTITY_ego_get_private_key(ego) | 281 | GNUNET_IDENTITY_ego_get_private_key (ego) |
258 | ); | 282 | ); |
259 | } | 283 | } |
260 | else | 284 | else |
261 | { | 285 | { |
262 | struct GNUNET_HashCode hash; | 286 | struct GNUNET_HashCode hash; |
263 | GNUNET_CRYPTO_hash (element->identifier, strlen (element->identifier), &hash); | 287 | GNUNET_CRYPTO_hash (element->identifier, strlen (element->identifier), |
288 | &hash); | ||
264 | 289 | ||
265 | if (GNUNET_CONTAINER_multihashmap_get (store->egos, &hash)) | 290 | if (GNUNET_CONTAINER_multihashmap_get (store->egos, &hash)) |
266 | { | 291 | { |
267 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looked up ego got deleted: '%s'\n", element->identifier); | 292 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looked up ego got deleted: '%s'\n", |
268 | delete_store_ego(store, element->identifier); | 293 | element->identifier); |
294 | delete_store_ego (store, element->identifier); | ||
269 | } | 295 | } |
270 | } | 296 | } |
271 | 297 | ||
272 | if (element->cb) | 298 | if (element->cb) |
273 | element->cb(element->cls, element->identifier, msg_ego); | 299 | element->cb (element->cls, element->identifier, msg_ego); |
274 | 300 | ||
275 | GNUNET_CONTAINER_DLL_remove (store->lu_start, store->lu_end, element); | 301 | GNUNET_CONTAINER_DLL_remove (store->lu_start, store->lu_end, element); |
276 | GNUNET_free (element->identifier); | 302 | GNUNET_free (element->identifier); |
277 | GNUNET_free (element); | 303 | GNUNET_free (element); |
278 | } | 304 | } |
279 | 305 | ||
306 | |||
280 | void | 307 | void |
281 | lookup_store_ego(struct GNUNET_MESSENGER_EgoStore *store, | 308 | lookup_store_ego (struct GNUNET_MESSENGER_EgoStore *store, |
282 | const char *identifier, | 309 | const char *identifier, |
283 | GNUNET_MESSENGER_EgoLookupCallback lookup, | 310 | GNUNET_MESSENGER_EgoLookupCallback lookup, |
284 | void *cls) | 311 | void *cls) |
285 | { | 312 | { |
286 | GNUNET_assert (store); | 313 | GNUNET_assert (store); |
287 | 314 | ||
288 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Store lookup ego: %s\n", identifier); | 315 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Store lookup ego: %s\n", identifier); |
289 | 316 | ||
290 | if (!identifier) | 317 | if (! identifier) |
291 | { | 318 | { |
292 | lookup(cls, identifier, NULL); | 319 | lookup (cls, identifier, NULL); |
293 | return; | 320 | return; |
294 | } | 321 | } |
295 | 322 | ||
296 | struct GNUNET_MESSENGER_EgoLookup *element = GNUNET_new (struct GNUNET_MESSENGER_EgoLookup); | 323 | struct GNUNET_MESSENGER_EgoLookup *element = GNUNET_new (struct |
324 | GNUNET_MESSENGER_EgoLookup); | ||
297 | 325 | ||
298 | element->store = store; | 326 | element->store = store; |
299 | 327 | ||
@@ -302,11 +330,13 @@ lookup_store_ego(struct GNUNET_MESSENGER_EgoStore *store, | |||
302 | 330 | ||
303 | element->identifier = GNUNET_strdup (identifier); | 331 | element->identifier = GNUNET_strdup (identifier); |
304 | 332 | ||
305 | element->lookup = GNUNET_IDENTITY_ego_lookup(store->cfg, identifier, callback_ego_lookup, element); | 333 | element->lookup = GNUNET_IDENTITY_ego_lookup (store->cfg, identifier, |
334 | callback_ego_lookup, element); | ||
306 | 335 | ||
307 | GNUNET_CONTAINER_DLL_insert (store->lu_start, store->lu_end, element); | 336 | GNUNET_CONTAINER_DLL_insert (store->lu_start, store->lu_end, element); |
308 | } | 337 | } |
309 | 338 | ||
339 | |||
310 | struct GNUNET_MESSENGER_Ego* | 340 | struct GNUNET_MESSENGER_Ego* |
311 | update_store_ego (struct GNUNET_MESSENGER_EgoStore *store, | 341 | update_store_ego (struct GNUNET_MESSENGER_EgoStore *store, |
312 | const char *identifier, | 342 | const char *identifier, |
@@ -314,55 +344,62 @@ update_store_ego (struct GNUNET_MESSENGER_EgoStore *store, | |||
314 | { | 344 | { |
315 | GNUNET_assert ((store) && (identifier) && (key)); | 345 | GNUNET_assert ((store) && (identifier) && (key)); |
316 | 346 | ||
317 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Store update ego: %s\n", identifier); | 347 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Store update ego: %s\n", identifier); |
318 | 348 | ||
319 | struct GNUNET_HashCode hash; | 349 | struct GNUNET_HashCode hash; |
320 | GNUNET_CRYPTO_hash (identifier, strlen (identifier), &hash); | 350 | GNUNET_CRYPTO_hash (identifier, strlen (identifier), &hash); |
321 | 351 | ||
322 | struct GNUNET_MESSENGER_Ego *ego = GNUNET_CONTAINER_multihashmap_get (store->egos, &hash); | 352 | struct GNUNET_MESSENGER_Ego *ego = GNUNET_CONTAINER_multihashmap_get ( |
353 | store->egos, &hash); | ||
323 | 354 | ||
324 | if (!ego) | 355 | if (! ego) |
325 | { | 356 | { |
326 | ego = GNUNET_new(struct GNUNET_MESSENGER_Ego); | 357 | ego = GNUNET_new (struct GNUNET_MESSENGER_Ego); |
327 | GNUNET_CONTAINER_multihashmap_put (store->egos, &hash, ego, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 358 | GNUNET_CONTAINER_multihashmap_put (store->egos, &hash, ego, |
359 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | ||
328 | } | 360 | } |
329 | 361 | ||
330 | GNUNET_memcpy(&(ego->priv), key, sizeof(*key)); | 362 | GNUNET_memcpy (&(ego->priv), key, sizeof(*key)); |
331 | 363 | ||
332 | if (GNUNET_OK != GNUNET_IDENTITY_key_get_public (key, &(ego->pub))) | 364 | if (GNUNET_OK != GNUNET_IDENTITY_key_get_public (key, &(ego->pub))) |
333 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Updating invalid ego key failed!\n"); | 365 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
366 | "Updating invalid ego key failed!\n"); | ||
334 | 367 | ||
335 | return ego; | 368 | return ego; |
336 | } | 369 | } |
337 | 370 | ||
371 | |||
338 | void | 372 | void |
339 | delete_store_ego (struct GNUNET_MESSENGER_EgoStore *store, | 373 | delete_store_ego (struct GNUNET_MESSENGER_EgoStore *store, |
340 | const char *identifier) | 374 | const char *identifier) |
341 | { | 375 | { |
342 | GNUNET_assert ((store) && (identifier)); | 376 | GNUNET_assert ((store) && (identifier)); |
343 | 377 | ||
344 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Store delete ego: %s\n", identifier); | 378 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Store delete ego: %s\n", identifier); |
345 | 379 | ||
346 | struct GNUNET_HashCode hash; | 380 | struct GNUNET_HashCode hash; |
347 | GNUNET_CRYPTO_hash (identifier, strlen (identifier), &hash); | 381 | GNUNET_CRYPTO_hash (identifier, strlen (identifier), &hash); |
348 | 382 | ||
349 | struct GNUNET_MESSENGER_Ego *ego = GNUNET_CONTAINER_multihashmap_get (store->egos, &hash); | 383 | struct GNUNET_MESSENGER_Ego *ego = GNUNET_CONTAINER_multihashmap_get ( |
384 | store->egos, &hash); | ||
350 | 385 | ||
351 | if (ego) | 386 | if (ego) |
352 | { | 387 | { |
353 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Ego is not stored!\n"); | 388 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Ego is not stored!\n"); |
354 | return; | 389 | return; |
355 | } | 390 | } |
356 | 391 | ||
357 | if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (store->egos, &hash, ego)) | 392 | if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (store->egos, &hash, |
393 | ego)) | ||
358 | { | 394 | { |
359 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Removing ego from store failed!\n"); | 395 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Removing ego from store failed!\n"); |
360 | return; | 396 | return; |
361 | } | 397 | } |
362 | 398 | ||
363 | GNUNET_free(ego); | 399 | GNUNET_free (ego); |
364 | } | 400 | } |
365 | 401 | ||
402 | |||
366 | static void | 403 | static void |
367 | callback_ego_rename (void *cls, | 404 | callback_ego_rename (void *cls, |
368 | enum GNUNET_ErrorCode ec) | 405 | enum GNUNET_ErrorCode ec) |
@@ -382,14 +419,16 @@ callback_ego_rename (void *cls, | |||
382 | struct GNUNET_HashCode hash; | 419 | struct GNUNET_HashCode hash; |
383 | GNUNET_CRYPTO_hash (element->identifier, strlen (element->identifier), &hash); | 420 | GNUNET_CRYPTO_hash (element->identifier, strlen (element->identifier), &hash); |
384 | 421 | ||
385 | struct GNUNET_MESSENGER_Ego *ego = GNUNET_CONTAINER_multihashmap_get (store->egos, &hash); | 422 | struct GNUNET_MESSENGER_Ego *ego = GNUNET_CONTAINER_multihashmap_get ( |
423 | store->egos, &hash); | ||
386 | 424 | ||
387 | if (!ego) | 425 | if (! ego) |
388 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Ego is not stored!\n"); | 426 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Ego is not stored!\n"); |
389 | 427 | ||
390 | char *identifier = (char*) element->cls; | 428 | char *identifier = (char*) element->cls; |
391 | 429 | ||
392 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (store->egos, &hash, ego)) | 430 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (store->egos, &hash, |
431 | ego)) | ||
393 | { | 432 | { |
394 | GNUNET_CRYPTO_hash (identifier, strlen (identifier), &hash); | 433 | GNUNET_CRYPTO_hash (identifier, strlen (identifier), &hash); |
395 | 434 | ||
@@ -397,7 +436,7 @@ callback_ego_rename (void *cls, | |||
397 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 436 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); |
398 | } | 437 | } |
399 | else | 438 | else |
400 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Renaming ego failed!\n"); | 439 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Renaming ego failed!\n"); |
401 | 440 | ||
402 | GNUNET_free (identifier); | 441 | GNUNET_free (identifier); |
403 | 442 | ||
@@ -406,6 +445,7 @@ callback_ego_rename (void *cls, | |||
406 | GNUNET_free (element); | 445 | GNUNET_free (element); |
407 | } | 446 | } |
408 | 447 | ||
448 | |||
409 | void | 449 | void |
410 | rename_store_ego (struct GNUNET_MESSENGER_EgoStore *store, | 450 | rename_store_ego (struct GNUNET_MESSENGER_EgoStore *store, |
411 | const char *old_identifier, | 451 | const char *old_identifier, |
@@ -413,9 +453,11 @@ rename_store_ego (struct GNUNET_MESSENGER_EgoStore *store, | |||
413 | { | 453 | { |
414 | GNUNET_assert ((store) && (old_identifier) && (new_identifier)); | 454 | GNUNET_assert ((store) && (old_identifier) && (new_identifier)); |
415 | 455 | ||
416 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Store rename ego: %s -> %s\n", old_identifier, new_identifier); | 456 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Store rename ego: %s -> %s\n", |
457 | old_identifier, new_identifier); | ||
417 | 458 | ||
418 | struct GNUNET_MESSENGER_EgoOperation *element = GNUNET_new (struct GNUNET_MESSENGER_EgoOperation); | 459 | struct GNUNET_MESSENGER_EgoOperation *element = GNUNET_new (struct |
460 | GNUNET_MESSENGER_EgoOperation); | ||
419 | 461 | ||
420 | element->store = store; | 462 | element->store = store; |
421 | element->cls = GNUNET_strdup (new_identifier); | 463 | element->cls = GNUNET_strdup (new_identifier); |
@@ -423,16 +465,17 @@ rename_store_ego (struct GNUNET_MESSENGER_EgoStore *store, | |||
423 | element->identifier = GNUNET_strdup (old_identifier); | 465 | element->identifier = GNUNET_strdup (old_identifier); |
424 | 466 | ||
425 | element->operation = GNUNET_IDENTITY_rename ( | 467 | element->operation = GNUNET_IDENTITY_rename ( |
426 | store->identity, | 468 | store->identity, |
427 | old_identifier, | 469 | old_identifier, |
428 | new_identifier, | 470 | new_identifier, |
429 | callback_ego_rename, | 471 | callback_ego_rename, |
430 | element | 472 | element |
431 | ); | 473 | ); |
432 | 474 | ||
433 | GNUNET_CONTAINER_DLL_insert (store->op_start, store->op_end, element); | 475 | GNUNET_CONTAINER_DLL_insert (store->op_start, store->op_end, element); |
434 | } | 476 | } |
435 | 477 | ||
478 | |||
436 | static void | 479 | static void |
437 | callback_ego_delete (void *cls, | 480 | callback_ego_delete (void *cls, |
438 | enum GNUNET_ErrorCode ec) | 481 | enum GNUNET_ErrorCode ec) |
@@ -456,27 +499,29 @@ callback_ego_delete (void *cls, | |||
456 | GNUNET_free (element); | 499 | GNUNET_free (element); |
457 | } | 500 | } |
458 | 501 | ||
502 | |||
459 | void | 503 | void |
460 | renew_store_ego (struct GNUNET_MESSENGER_EgoStore *store, | 504 | renew_store_ego (struct GNUNET_MESSENGER_EgoStore *store, |
461 | const char *identifier) | 505 | const char *identifier) |
462 | { | 506 | { |
463 | GNUNET_assert ((store) && (identifier)); | 507 | GNUNET_assert ((store) && (identifier)); |
464 | 508 | ||
465 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Store renew ego: %s\n", identifier); | 509 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Store renew ego: %s\n", identifier); |
466 | 510 | ||
467 | struct GNUNET_MESSENGER_EgoOperation *element = GNUNET_new (struct GNUNET_MESSENGER_EgoOperation); | 511 | struct GNUNET_MESSENGER_EgoOperation *element = GNUNET_new (struct |
512 | GNUNET_MESSENGER_EgoOperation); | ||
468 | 513 | ||
469 | element->store = store; | 514 | element->store = store; |
470 | element->cls = NULL; | 515 | element->cls = NULL; |
471 | 516 | ||
472 | element->identifier = GNUNET_strdup (identifier); | 517 | element->identifier = GNUNET_strdup (identifier); |
473 | 518 | ||
474 | element->operation = GNUNET_IDENTITY_delete( | 519 | element->operation = GNUNET_IDENTITY_delete ( |
475 | store->identity, | 520 | store->identity, |
476 | identifier, | 521 | identifier, |
477 | callback_ego_delete, | 522 | callback_ego_delete, |
478 | element | 523 | element |
479 | ); | 524 | ); |
480 | 525 | ||
481 | GNUNET_CONTAINER_DLL_insert (store->op_start, store->op_end, element); | 526 | GNUNET_CONTAINER_DLL_insert (store->op_start, store->op_end, element); |
482 | } | 527 | } |
diff --git a/src/messenger/gnunet-service-messenger_handle.c b/src/messenger/gnunet-service-messenger_handle.c index ddb437b7e..8d572013e 100644 --- a/src/messenger/gnunet-service-messenger_handle.c +++ b/src/messenger/gnunet-service-messenger_handle.c | |||
@@ -40,9 +40,10 @@ struct GNUNET_MESSENGER_SrvHandle* | |||
40 | create_srv_handle (struct GNUNET_MESSENGER_Service *service, | 40 | create_srv_handle (struct GNUNET_MESSENGER_Service *service, |
41 | struct GNUNET_MQ_Handle *mq) | 41 | struct GNUNET_MQ_Handle *mq) |
42 | { | 42 | { |
43 | GNUNET_assert((service) && (mq)); | 43 | GNUNET_assert ((service) && (mq)); |
44 | 44 | ||
45 | struct GNUNET_MESSENGER_SrvHandle *handle = GNUNET_new(struct GNUNET_MESSENGER_SrvHandle); | 45 | struct GNUNET_MESSENGER_SrvHandle *handle = GNUNET_new (struct |
46 | GNUNET_MESSENGER_SrvHandle); | ||
46 | 47 | ||
47 | handle->service = service; | 48 | handle->service = service; |
48 | handle->mq = mq; | 49 | handle->mq = mq; |
@@ -55,65 +56,72 @@ create_srv_handle (struct GNUNET_MESSENGER_Service *service, | |||
55 | return handle; | 56 | return handle; |
56 | } | 57 | } |
57 | 58 | ||
59 | |||
58 | int | 60 | int |
59 | iterate_free_member_ids (void *cls, | 61 | iterate_free_member_ids (void *cls, |
60 | const struct GNUNET_HashCode *key, | 62 | const struct GNUNET_HashCode *key, |
61 | void *value) | 63 | void *value) |
62 | { | 64 | { |
63 | GNUNET_free(value); | 65 | GNUNET_free (value); |
64 | 66 | ||
65 | return GNUNET_YES; | 67 | return GNUNET_YES; |
66 | } | 68 | } |
67 | 69 | ||
70 | |||
68 | void | 71 | void |
69 | destroy_srv_handle (struct GNUNET_MESSENGER_SrvHandle *handle) | 72 | destroy_srv_handle (struct GNUNET_MESSENGER_SrvHandle *handle) |
70 | { | 73 | { |
71 | GNUNET_assert(handle); | 74 | GNUNET_assert (handle); |
72 | 75 | ||
73 | if (handle->notify) | 76 | if (handle->notify) |
74 | GNUNET_SCHEDULER_cancel(handle->notify); | 77 | GNUNET_SCHEDULER_cancel (handle->notify); |
75 | 78 | ||
76 | GNUNET_CONTAINER_multihashmap_iterate (handle->next_ids, iterate_free_member_ids, NULL); | 79 | GNUNET_CONTAINER_multihashmap_iterate (handle->next_ids, |
77 | GNUNET_CONTAINER_multihashmap_iterate (handle->member_ids, iterate_free_member_ids, NULL); | 80 | iterate_free_member_ids, NULL); |
81 | GNUNET_CONTAINER_multihashmap_iterate (handle->member_ids, | ||
82 | iterate_free_member_ids, NULL); | ||
78 | 83 | ||
79 | GNUNET_CONTAINER_multihashmap_destroy (handle->next_ids); | 84 | GNUNET_CONTAINER_multihashmap_destroy (handle->next_ids); |
80 | GNUNET_CONTAINER_multihashmap_destroy (handle->member_ids); | 85 | GNUNET_CONTAINER_multihashmap_destroy (handle->member_ids); |
81 | 86 | ||
82 | GNUNET_free(handle); | 87 | GNUNET_free (handle); |
83 | } | 88 | } |
84 | 89 | ||
90 | |||
85 | void | 91 | void |
86 | set_srv_handle_key (struct GNUNET_MESSENGER_SrvHandle *handle, | 92 | set_srv_handle_key (struct GNUNET_MESSENGER_SrvHandle *handle, |
87 | const struct GNUNET_IDENTITY_PublicKey *key) | 93 | const struct GNUNET_IDENTITY_PublicKey *key) |
88 | { | 94 | { |
89 | GNUNET_assert(handle); | 95 | GNUNET_assert (handle); |
90 | 96 | ||
91 | if ((handle->key) && (!key)) | 97 | if ((handle->key) && (! key)) |
92 | { | 98 | { |
93 | GNUNET_free(handle->key); | 99 | GNUNET_free (handle->key); |
94 | handle->key = NULL; | 100 | handle->key = NULL; |
95 | } | 101 | } |
96 | else if (!handle->key) | 102 | else if (! handle->key) |
97 | handle->key = GNUNET_new(struct GNUNET_IDENTITY_PublicKey); | 103 | handle->key = GNUNET_new (struct GNUNET_IDENTITY_PublicKey); |
98 | 104 | ||
99 | if (key) | 105 | if (key) |
100 | memcpy(handle->key, key, sizeof(struct GNUNET_IDENTITY_PublicKey)); | 106 | memcpy (handle->key, key, sizeof(struct GNUNET_IDENTITY_PublicKey)); |
101 | } | 107 | } |
102 | 108 | ||
109 | |||
103 | const struct GNUNET_IDENTITY_PublicKey* | 110 | const struct GNUNET_IDENTITY_PublicKey* |
104 | get_srv_handle_key (const struct GNUNET_MESSENGER_SrvHandle *handle) | 111 | get_srv_handle_key (const struct GNUNET_MESSENGER_SrvHandle *handle) |
105 | { | 112 | { |
106 | GNUNET_assert(handle); | 113 | GNUNET_assert (handle); |
107 | 114 | ||
108 | return handle->key; | 115 | return handle->key; |
109 | } | 116 | } |
110 | 117 | ||
118 | |||
111 | void | 119 | void |
112 | get_srv_handle_data_subdir (const struct GNUNET_MESSENGER_SrvHandle *handle, | 120 | get_srv_handle_data_subdir (const struct GNUNET_MESSENGER_SrvHandle *handle, |
113 | const char *name, | 121 | const char *name, |
114 | char **dir) | 122 | char **dir) |
115 | { | 123 | { |
116 | GNUNET_assert((handle) && (dir)); | 124 | GNUNET_assert ((handle) && (dir)); |
117 | 125 | ||
118 | if (name) | 126 | if (name) |
119 | GNUNET_asprintf (dir, "%s%s%c%s%c", handle->service->dir, "identities", | 127 | GNUNET_asprintf (dir, "%s%s%c%s%c", handle->service->dir, "identities", |
@@ -123,75 +131,88 @@ get_srv_handle_data_subdir (const struct GNUNET_MESSENGER_SrvHandle *handle, | |||
123 | DIR_SEPARATOR); | 131 | DIR_SEPARATOR); |
124 | } | 132 | } |
125 | 133 | ||
134 | |||
126 | static int | 135 | static int |
127 | create_handle_member_id (const struct GNUNET_MESSENGER_SrvHandle *handle, | 136 | create_handle_member_id (const struct GNUNET_MESSENGER_SrvHandle *handle, |
128 | const struct GNUNET_HashCode *key) | 137 | const struct GNUNET_HashCode *key) |
129 | { | 138 | { |
130 | GNUNET_assert((handle) && (key)); | 139 | GNUNET_assert ((handle) && (key)); |
131 | 140 | ||
132 | struct GNUNET_ShortHashCode *random_id = GNUNET_new(struct GNUNET_ShortHashCode); | 141 | struct GNUNET_ShortHashCode *random_id = GNUNET_new (struct |
142 | GNUNET_ShortHashCode); | ||
133 | 143 | ||
134 | if (!random_id) | 144 | if (! random_id) |
135 | return GNUNET_NO; | 145 | return GNUNET_NO; |
136 | 146 | ||
137 | generate_free_member_id (random_id, NULL); | 147 | generate_free_member_id (random_id, NULL); |
138 | 148 | ||
139 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (handle->member_ids, key, random_id, | 149 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (handle->member_ids, key, |
150 | random_id, | ||
140 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | 151 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) |
141 | { | 152 | { |
142 | GNUNET_free(random_id); | 153 | GNUNET_free (random_id); |
143 | return GNUNET_NO; | 154 | return GNUNET_NO; |
144 | } | 155 | } |
145 | 156 | ||
146 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Created a new member id (%s) for room: %s\n", GNUNET_sh2s (random_id), | 157 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
147 | GNUNET_h2s (key)); | 158 | "Created a new member id (%s) for room: %s\n", GNUNET_sh2s ( |
159 | random_id), | ||
160 | GNUNET_h2s (key)); | ||
148 | 161 | ||
149 | return GNUNET_YES; | 162 | return GNUNET_YES; |
150 | } | 163 | } |
151 | 164 | ||
165 | |||
152 | const struct GNUNET_ShortHashCode* | 166 | const struct GNUNET_ShortHashCode* |
153 | get_srv_handle_member_id (const struct GNUNET_MESSENGER_SrvHandle *handle, | 167 | get_srv_handle_member_id (const struct GNUNET_MESSENGER_SrvHandle *handle, |
154 | const struct GNUNET_HashCode *key) | 168 | const struct GNUNET_HashCode *key) |
155 | { | 169 | { |
156 | GNUNET_assert((handle) && (key)); | 170 | GNUNET_assert ((handle) && (key)); |
157 | 171 | ||
158 | return GNUNET_CONTAINER_multihashmap_get (handle->member_ids, key); | 172 | return GNUNET_CONTAINER_multihashmap_get (handle->member_ids, key); |
159 | } | 173 | } |
160 | 174 | ||
175 | |||
161 | int | 176 | int |
162 | change_srv_handle_member_id (struct GNUNET_MESSENGER_SrvHandle *handle, | 177 | change_srv_handle_member_id (struct GNUNET_MESSENGER_SrvHandle *handle, |
163 | const struct GNUNET_HashCode *key, | 178 | const struct GNUNET_HashCode *key, |
164 | const struct GNUNET_ShortHashCode *unique_id) | 179 | const struct GNUNET_ShortHashCode *unique_id) |
165 | { | 180 | { |
166 | GNUNET_assert((handle) && (key) && (unique_id)); | 181 | GNUNET_assert ((handle) && (key) && (unique_id)); |
167 | 182 | ||
168 | struct GNUNET_ShortHashCode *member_id = GNUNET_CONTAINER_multihashmap_get (handle->member_ids, key); | 183 | struct GNUNET_ShortHashCode *member_id = GNUNET_CONTAINER_multihashmap_get ( |
184 | handle->member_ids, key); | ||
169 | 185 | ||
170 | if (!member_id) | 186 | if (! member_id) |
171 | { | 187 | { |
172 | member_id = GNUNET_new(struct GNUNET_ShortHashCode); | 188 | member_id = GNUNET_new (struct GNUNET_ShortHashCode); |
173 | GNUNET_memcpy(member_id, unique_id, sizeof(*member_id)); | 189 | GNUNET_memcpy (member_id, unique_id, sizeof(*member_id)); |
174 | 190 | ||
175 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (handle->member_ids, key, member_id, | 191 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (handle->member_ids, key, |
192 | member_id, | ||
176 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | 193 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) |
177 | { | 194 | { |
178 | GNUNET_free(member_id); | 195 | GNUNET_free (member_id); |
179 | return GNUNET_SYSERR; | 196 | return GNUNET_SYSERR; |
180 | } | 197 | } |
181 | } | 198 | } |
182 | 199 | ||
183 | if (0 == GNUNET_memcmp(unique_id, member_id)) | 200 | if (0 == GNUNET_memcmp (unique_id, member_id)) |
184 | return GNUNET_OK; | 201 | return GNUNET_OK; |
185 | 202 | ||
186 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Change a member id (%s) for room (%s).\n", GNUNET_sh2s (member_id), | 203 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
187 | GNUNET_h2s (key)); | 204 | "Change a member id (%s) for room (%s).\n", GNUNET_sh2s ( |
205 | member_id), | ||
206 | GNUNET_h2s (key)); | ||
188 | 207 | ||
189 | GNUNET_memcpy(member_id, unique_id, sizeof(*unique_id)); | 208 | GNUNET_memcpy (member_id, unique_id, sizeof(*unique_id)); |
190 | 209 | ||
191 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Member id changed to (%s).\n", GNUNET_sh2s (unique_id)); | 210 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Member id changed to (%s).\n", |
211 | GNUNET_sh2s (unique_id)); | ||
192 | return GNUNET_OK; | 212 | return GNUNET_OK; |
193 | } | 213 | } |
194 | 214 | ||
215 | |||
195 | struct RoomInitializationClosure | 216 | struct RoomInitializationClosure |
196 | { | 217 | { |
197 | struct GNUNET_MESSENGER_SrvHandle *handle; | 218 | struct GNUNET_MESSENGER_SrvHandle *handle; |
@@ -206,160 +227,185 @@ find_member_session_in_room (void *cls, | |||
206 | { | 227 | { |
207 | struct RoomInitializationClosure *init = cls; | 228 | struct RoomInitializationClosure *init = cls; |
208 | 229 | ||
209 | if (!public_key) | 230 | if (! public_key) |
210 | return GNUNET_YES; | 231 | return GNUNET_YES; |
211 | 232 | ||
212 | const struct GNUNET_IDENTITY_PublicKey *pubkey = get_srv_handle_key(init->handle); | 233 | const struct GNUNET_IDENTITY_PublicKey *pubkey = get_srv_handle_key ( |
234 | init->handle); | ||
213 | 235 | ||
214 | if (0 != GNUNET_memcmp(pubkey, public_key)) | 236 | if (0 != GNUNET_memcmp (pubkey, public_key)) |
215 | return GNUNET_YES; | 237 | return GNUNET_YES; |
216 | 238 | ||
217 | const struct GNUNET_ShortHashCode *id = get_member_session_id(session); | 239 | const struct GNUNET_ShortHashCode *id = get_member_session_id (session); |
218 | 240 | ||
219 | if (!id) | 241 | if (! id) |
220 | { | 242 | { |
221 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initialitation: Missing member id!"); | 243 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initialitation: Missing member id!"); |
222 | return GNUNET_NO; | 244 | return GNUNET_NO; |
223 | } | 245 | } |
224 | 246 | ||
225 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Initialitation: Matching member found (%s)!\n", | 247 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
226 | GNUNET_sh2s(id)); | 248 | "Initialitation: Matching member found (%s)!\n", |
249 | GNUNET_sh2s (id)); | ||
227 | 250 | ||
228 | change_srv_handle_member_id(init->handle, init->key, id); | 251 | change_srv_handle_member_id (init->handle, init->key, id); |
229 | return GNUNET_NO; | 252 | return GNUNET_NO; |
230 | } | 253 | } |
231 | 254 | ||
255 | |||
232 | static void | 256 | static void |
233 | initialize_srv_handle_via_matching_member (struct GNUNET_MESSENGER_SrvHandle *handle, | 257 | initialize_srv_handle_via_matching_member (struct |
258 | GNUNET_MESSENGER_SrvHandle *handle, | ||
234 | const struct GNUNET_HashCode *key) | 259 | const struct GNUNET_HashCode *key) |
235 | { | 260 | { |
236 | struct GNUNET_MESSENGER_SrvRoom *room = get_service_room(handle->service, key); | 261 | struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (handle->service, |
237 | if (!room) | 262 | key); |
263 | if (! room) | ||
238 | return; | 264 | return; |
239 | 265 | ||
240 | struct GNUNET_MESSENGER_MemberStore *store = get_srv_room_member_store(room); | 266 | struct GNUNET_MESSENGER_MemberStore *store = get_srv_room_member_store (room); |
241 | if (!store) | 267 | if (! store) |
242 | return; | 268 | return; |
243 | 269 | ||
244 | const struct GNUNET_IDENTITY_PublicKey *pubkey = get_srv_handle_key(handle); | 270 | const struct GNUNET_IDENTITY_PublicKey *pubkey = get_srv_handle_key (handle); |
245 | if ((!pubkey) || (0 == GNUNET_memcmp (pubkey, get_anonymous_public_key()))) | 271 | if ((! pubkey) || (0 == GNUNET_memcmp (pubkey, get_anonymous_public_key ()))) |
246 | return; | 272 | return; |
247 | 273 | ||
248 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initialize member id of handle via matching member in room!\n"); | 274 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
275 | "Initialize member id of handle via matching member in room!\n"); | ||
249 | 276 | ||
250 | struct RoomInitializationClosure init; | 277 | struct RoomInitializationClosure init; |
251 | init.handle = handle; | 278 | init.handle = handle; |
252 | init.key = key; | 279 | init.key = key; |
253 | init.pubkey = pubkey; | 280 | init.pubkey = pubkey; |
254 | 281 | ||
255 | iterate_store_members(store, find_member_session_in_room, &init); | 282 | iterate_store_members (store, find_member_session_in_room, &init); |
256 | } | 283 | } |
257 | 284 | ||
285 | |||
258 | int | 286 | int |
259 | open_srv_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, | 287 | open_srv_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, |
260 | const struct GNUNET_HashCode *key) | 288 | const struct GNUNET_HashCode *key) |
261 | { | 289 | { |
262 | GNUNET_assert((handle) && (key)); | 290 | GNUNET_assert ((handle) && (key)); |
263 | 291 | ||
264 | initialize_srv_handle_via_matching_member (handle, key); | 292 | initialize_srv_handle_via_matching_member (handle, key); |
265 | 293 | ||
266 | if ((!get_srv_handle_member_id (handle, key)) && (GNUNET_YES != create_handle_member_id (handle, key))) | 294 | if ((! get_srv_handle_member_id (handle, key)) && (GNUNET_YES != |
295 | create_handle_member_id ( | ||
296 | handle, key))) | ||
267 | return GNUNET_NO; | 297 | return GNUNET_NO; |
268 | 298 | ||
269 | return open_service_room (handle->service, handle, key); | 299 | return open_service_room (handle->service, handle, key); |
270 | } | 300 | } |
271 | 301 | ||
302 | |||
272 | int | 303 | int |
273 | entry_srv_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, | 304 | entry_srv_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, |
274 | const struct GNUNET_PeerIdentity *door, | 305 | const struct GNUNET_PeerIdentity *door, |
275 | const struct GNUNET_HashCode *key) | 306 | const struct GNUNET_HashCode *key) |
276 | { | 307 | { |
277 | GNUNET_assert((handle) && (door) && (key)); | 308 | GNUNET_assert ((handle) && (door) && (key)); |
278 | 309 | ||
279 | initialize_srv_handle_via_matching_member (handle, key); | 310 | initialize_srv_handle_via_matching_member (handle, key); |
280 | 311 | ||
281 | if ((!get_srv_handle_member_id (handle, key)) && (GNUNET_YES != create_handle_member_id (handle, key))) | 312 | if ((! get_srv_handle_member_id (handle, key)) && (GNUNET_YES != |
313 | create_handle_member_id ( | ||
314 | handle, key))) | ||
282 | return GNUNET_NO; | 315 | return GNUNET_NO; |
283 | 316 | ||
284 | return entry_service_room (handle->service, handle, door, key); | 317 | return entry_service_room (handle->service, handle, door, key); |
285 | } | 318 | } |
286 | 319 | ||
320 | |||
287 | int | 321 | int |
288 | close_srv_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, | 322 | close_srv_handle_room (struct GNUNET_MESSENGER_SrvHandle *handle, |
289 | const struct GNUNET_HashCode *key) | 323 | const struct GNUNET_HashCode *key) |
290 | { | 324 | { |
291 | GNUNET_assert((handle) && (key)); | 325 | GNUNET_assert ((handle) && (key)); |
292 | 326 | ||
293 | GNUNET_CONTAINER_multihashmap_get_multiple (handle->next_ids, key, iterate_free_member_ids, NULL); | 327 | GNUNET_CONTAINER_multihashmap_get_multiple (handle->next_ids, key, |
328 | iterate_free_member_ids, NULL); | ||
294 | GNUNET_CONTAINER_multihashmap_remove_all (handle->next_ids, key); | 329 | GNUNET_CONTAINER_multihashmap_remove_all (handle->next_ids, key); |
295 | 330 | ||
296 | if ((handle->notify) && (0 == GNUNET_CONTAINER_multihashmap_size (handle->next_ids))) | 331 | if ((handle->notify) && (0 == GNUNET_CONTAINER_multihashmap_size ( |
332 | handle->next_ids))) | ||
297 | { | 333 | { |
298 | GNUNET_SCHEDULER_cancel(handle->notify); | 334 | GNUNET_SCHEDULER_cancel (handle->notify); |
299 | handle->notify = NULL; | 335 | handle->notify = NULL; |
300 | } | 336 | } |
301 | 337 | ||
302 | if (!get_srv_handle_member_id (handle, key)) | 338 | if (! get_srv_handle_member_id (handle, key)) |
303 | return GNUNET_NO; | 339 | return GNUNET_NO; |
304 | 340 | ||
305 | return close_service_room (handle->service, handle, key); | 341 | return close_service_room (handle->service, handle, key); |
306 | } | 342 | } |
307 | 343 | ||
344 | |||
308 | int | 345 | int |
309 | send_srv_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, | 346 | send_srv_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, |
310 | const struct GNUNET_HashCode *key, | 347 | const struct GNUNET_HashCode *key, |
311 | const struct GNUNET_MESSENGER_Message *message) | 348 | const struct GNUNET_MESSENGER_Message *message) |
312 | { | 349 | { |
313 | GNUNET_assert((handle) && (key) && (message)); | 350 | GNUNET_assert ((handle) && (key) && (message)); |
314 | 351 | ||
315 | const struct GNUNET_ShortHashCode *id = get_srv_handle_member_id (handle, key); | 352 | const struct GNUNET_ShortHashCode *id = get_srv_handle_member_id (handle, |
353 | key); | ||
316 | 354 | ||
317 | if (!id) | 355 | if (! id) |
318 | { | 356 | { |
319 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "It is required to be a member of a room to send messages!\n"); | 357 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
358 | "It is required to be a member of a room to send messages!\n"); | ||
320 | return GNUNET_NO; | 359 | return GNUNET_NO; |
321 | } | 360 | } |
322 | 361 | ||
323 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message with member id: %s\n", | 362 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message with member id: %s\n", |
324 | GNUNET_sh2s (id)); | 363 | GNUNET_sh2s (id)); |
325 | 364 | ||
326 | if (0 != GNUNET_memcmp(id, &(message->header.sender_id))) | 365 | if (0 != GNUNET_memcmp (id, &(message->header.sender_id))) |
327 | { | 366 | { |
328 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Member id does not match with handle!\n"); | 367 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
368 | "Member id does not match with handle!\n"); | ||
329 | return GNUNET_NO; | 369 | return GNUNET_NO; |
330 | } | 370 | } |
331 | 371 | ||
332 | struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (handle->service, key); | 372 | struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (handle->service, |
373 | key); | ||
333 | 374 | ||
334 | if (!room) | 375 | if (! room) |
335 | { | 376 | { |
336 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "The room (%s) is unknown!\n", GNUNET_h2s (key)); | 377 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "The room (%s) is unknown!\n", |
378 | GNUNET_h2s (key)); | ||
337 | return GNUNET_NO; | 379 | return GNUNET_NO; |
338 | } | 380 | } |
339 | 381 | ||
340 | struct GNUNET_MESSENGER_Message *msg = copy_message(message); | 382 | struct GNUNET_MESSENGER_Message *msg = copy_message (message); |
341 | return send_srv_room_message (room, handle, msg); | 383 | return send_srv_room_message (room, handle, msg); |
342 | } | 384 | } |
343 | 385 | ||
386 | |||
344 | static const struct GNUNET_HashCode* | 387 | static const struct GNUNET_HashCode* |
345 | get_next_member_session_context(const struct GNUNET_MESSENGER_MemberSession *session) | 388 | get_next_member_session_context (const struct |
389 | GNUNET_MESSENGER_MemberSession *session) | ||
346 | { | 390 | { |
347 | if (session->next) | 391 | if (session->next) |
348 | return get_next_member_session_context (session->next); | 392 | return get_next_member_session_context (session->next); |
349 | else | 393 | else |
350 | return get_member_session_context(session); | 394 | return get_member_session_context (session); |
351 | } | 395 | } |
352 | 396 | ||
397 | |||
353 | static const struct GNUNET_MESSENGER_MemberSession* | 398 | static const struct GNUNET_MESSENGER_MemberSession* |
354 | get_handle_member_session (struct GNUNET_MESSENGER_SrvHandle *handle, | 399 | get_handle_member_session (struct GNUNET_MESSENGER_SrvHandle *handle, |
355 | struct GNUNET_MESSENGER_SrvRoom *room, | 400 | struct GNUNET_MESSENGER_SrvRoom *room, |
356 | const struct GNUNET_HashCode *key) | 401 | const struct GNUNET_HashCode *key) |
357 | { | 402 | { |
358 | GNUNET_assert((handle) && (room) && (key) && (handle->service)); | 403 | GNUNET_assert ((handle) && (room) && (key) && (handle->service)); |
359 | 404 | ||
360 | const struct GNUNET_ShortHashCode *id = get_srv_handle_member_id(handle, key); | 405 | const struct GNUNET_ShortHashCode *id = get_srv_handle_member_id (handle, |
406 | key); | ||
361 | 407 | ||
362 | if (!id) | 408 | if (! id) |
363 | { | 409 | { |
364 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 410 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
365 | "Handle is missing a member id for its member session! (%s)\n", | 411 | "Handle is missing a member id for its member session! (%s)\n", |
@@ -367,12 +413,12 @@ get_handle_member_session (struct GNUNET_MESSENGER_SrvHandle *handle, | |||
367 | return NULL; | 413 | return NULL; |
368 | } | 414 | } |
369 | 415 | ||
370 | struct GNUNET_MESSENGER_MemberStore *store = get_srv_room_member_store(room); | 416 | struct GNUNET_MESSENGER_MemberStore *store = get_srv_room_member_store (room); |
371 | struct GNUNET_MESSENGER_Member *member = get_store_member(store, id); | 417 | struct GNUNET_MESSENGER_Member *member = get_store_member (store, id); |
372 | 418 | ||
373 | const struct GNUNET_IDENTITY_PublicKey *pubkey = get_srv_handle_key(handle); | 419 | const struct GNUNET_IDENTITY_PublicKey *pubkey = get_srv_handle_key (handle); |
374 | 420 | ||
375 | if (!pubkey) | 421 | if (! pubkey) |
376 | { | 422 | { |
377 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 423 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
378 | "Handle is missing a public key for its member session! (%s)\n", | 424 | "Handle is missing a public key for its member session! (%s)\n", |
@@ -380,9 +426,10 @@ get_handle_member_session (struct GNUNET_MESSENGER_SrvHandle *handle, | |||
380 | return NULL; | 426 | return NULL; |
381 | } | 427 | } |
382 | 428 | ||
383 | return get_member_session(member, pubkey); | 429 | return get_member_session (member, pubkey); |
384 | } | 430 | } |
385 | 431 | ||
432 | |||
386 | void | 433 | void |
387 | notify_srv_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, | 434 | notify_srv_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, |
388 | struct GNUNET_MESSENGER_SrvRoom *room, | 435 | struct GNUNET_MESSENGER_SrvRoom *room, |
@@ -390,13 +437,14 @@ notify_srv_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, | |||
390 | const struct GNUNET_MESSENGER_Message *message, | 437 | const struct GNUNET_MESSENGER_Message *message, |
391 | const struct GNUNET_HashCode *hash) | 438 | const struct GNUNET_HashCode *hash) |
392 | { | 439 | { |
393 | GNUNET_assert((handle) && (room) && (session) && (message) && (hash)); | 440 | GNUNET_assert ((handle) && (room) && (session) && (message) && (hash)); |
394 | 441 | ||
395 | const struct GNUNET_HashCode *key = get_srv_room_key(room); | 442 | const struct GNUNET_HashCode *key = get_srv_room_key (room); |
396 | 443 | ||
397 | if ((!handle->mq) || (!get_srv_handle_member_id (handle, key))) | 444 | if ((! handle->mq) || (! get_srv_handle_member_id (handle, key))) |
398 | { | 445 | { |
399 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Notifying client about message requires membership!\n"); | 446 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
447 | "Notifying client about message requires membership!\n"); | ||
400 | return; | 448 | return; |
401 | } | 449 | } |
402 | 450 | ||
@@ -406,37 +454,40 @@ notify_srv_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, | |||
406 | if (GNUNET_YES == is_peer_message (message)) | 454 | if (GNUNET_YES == is_peer_message (message)) |
407 | { | 455 | { |
408 | const struct GNUNET_PeerIdentity *identity = session->peer; | 456 | const struct GNUNET_PeerIdentity *identity = session->peer; |
409 | GNUNET_CRYPTO_hash(identity, sizeof(*identity), &sender); | 457 | GNUNET_CRYPTO_hash (identity, sizeof(*identity), &sender); |
410 | 458 | ||
411 | context = &sender; | 459 | context = &sender; |
412 | } | 460 | } |
413 | else | 461 | else |
414 | { | 462 | { |
415 | const struct GNUNET_IDENTITY_PublicKey *pubkey = get_contact_key(session->member->contact); | 463 | const struct GNUNET_IDENTITY_PublicKey *pubkey = get_contact_key ( |
416 | GNUNET_CRYPTO_hash(pubkey, sizeof(*pubkey), &sender); | 464 | session->member->contact); |
465 | GNUNET_CRYPTO_hash (pubkey, sizeof(*pubkey), &sender); | ||
417 | 466 | ||
418 | context = get_next_member_session_context (session->member); | 467 | context = get_next_member_session_context (session->member); |
419 | } | 468 | } |
420 | 469 | ||
421 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Notifying client about message: %s\n", GNUNET_h2s (hash)); | 470 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Notifying client about message: %s\n", |
471 | GNUNET_h2s (hash)); | ||
422 | 472 | ||
423 | struct GNUNET_MESSENGER_RecvMessage *msg; | 473 | struct GNUNET_MESSENGER_RecvMessage *msg; |
424 | struct GNUNET_MQ_Envelope *env; | 474 | struct GNUNET_MQ_Envelope *env; |
425 | 475 | ||
426 | uint16_t length = get_message_size (message, GNUNET_YES); | 476 | uint16_t length = get_message_size (message, GNUNET_YES); |
427 | 477 | ||
428 | env = GNUNET_MQ_msg_extra(msg, length, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_RECV_MESSAGE); | 478 | env = GNUNET_MQ_msg_extra (msg, length, |
479 | GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_RECV_MESSAGE); | ||
429 | 480 | ||
430 | GNUNET_memcpy(&(msg->key), key, sizeof(msg->key)); | 481 | GNUNET_memcpy (&(msg->key), key, sizeof(msg->key)); |
431 | GNUNET_memcpy(&(msg->sender), &sender, sizeof(msg->sender)); | 482 | GNUNET_memcpy (&(msg->sender), &sender, sizeof(msg->sender)); |
432 | GNUNET_memcpy(&(msg->context), context, sizeof(msg->context)); | 483 | GNUNET_memcpy (&(msg->context), context, sizeof(msg->context)); |
433 | GNUNET_memcpy(&(msg->hash), hash, sizeof(msg->hash)); | 484 | GNUNET_memcpy (&(msg->hash), hash, sizeof(msg->hash)); |
434 | 485 | ||
435 | msg->flags = (uint32_t) GNUNET_MESSENGER_FLAG_NONE; | 486 | msg->flags = (uint32_t) GNUNET_MESSENGER_FLAG_NONE; |
436 | 487 | ||
437 | if (GNUNET_YES == is_peer_message (message)) | 488 | if (GNUNET_YES == is_peer_message (message)) |
438 | msg->flags |= (uint32_t) GNUNET_MESSENGER_FLAG_PEER; | 489 | msg->flags |= (uint32_t) GNUNET_MESSENGER_FLAG_PEER; |
439 | else if (get_handle_member_session(handle, room, key) == session->member) | 490 | else if (get_handle_member_session (handle, room, key) == session->member) |
440 | msg->flags |= (uint32_t) GNUNET_MESSENGER_FLAG_SENT; | 491 | msg->flags |= (uint32_t) GNUNET_MESSENGER_FLAG_SENT; |
441 | 492 | ||
442 | char *buffer = ((char*) msg) + sizeof(*msg); | 493 | char *buffer = ((char*) msg) + sizeof(*msg); |
@@ -445,6 +496,7 @@ notify_srv_handle_message (struct GNUNET_MESSENGER_SrvHandle *handle, | |||
445 | GNUNET_MQ_send (handle->mq, env); | 496 | GNUNET_MQ_send (handle->mq, env); |
446 | } | 497 | } |
447 | 498 | ||
499 | |||
448 | static int | 500 | static int |
449 | iterate_next_member_ids (void *cls, | 501 | iterate_next_member_ids (void *cls, |
450 | const struct GNUNET_HashCode *key, | 502 | const struct GNUNET_HashCode *key, |
@@ -456,10 +508,10 @@ iterate_next_member_ids (void *cls, | |||
456 | struct GNUNET_MESSENGER_MemberMessage *msg; | 508 | struct GNUNET_MESSENGER_MemberMessage *msg; |
457 | struct GNUNET_MQ_Envelope *env; | 509 | struct GNUNET_MQ_Envelope *env; |
458 | 510 | ||
459 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_MEMBER_ID); | 511 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_MEMBER_ID); |
460 | 512 | ||
461 | GNUNET_memcpy(&(msg->key), key, sizeof(*key)); | 513 | GNUNET_memcpy (&(msg->key), key, sizeof(*key)); |
462 | GNUNET_memcpy(&(msg->id), &(next->id), sizeof(next->id)); | 514 | GNUNET_memcpy (&(msg->id), &(next->id), sizeof(next->id)); |
463 | msg->reset = (uint32_t) next->reset; | 515 | msg->reset = (uint32_t) next->reset; |
464 | 516 | ||
465 | GNUNET_MQ_send (handle->mq, env); | 517 | GNUNET_MQ_send (handle->mq, env); |
@@ -468,26 +520,30 @@ iterate_next_member_ids (void *cls, | |||
468 | return GNUNET_YES; | 520 | return GNUNET_YES; |
469 | } | 521 | } |
470 | 522 | ||
523 | |||
471 | static void | 524 | static void |
472 | task_notify_srv_handle_member_id (void *cls) | 525 | task_notify_srv_handle_member_id (void *cls) |
473 | { | 526 | { |
474 | struct GNUNET_MESSENGER_SrvHandle *handle = cls; | 527 | struct GNUNET_MESSENGER_SrvHandle *handle = cls; |
475 | handle->notify = NULL; | 528 | handle->notify = NULL; |
476 | 529 | ||
477 | GNUNET_CONTAINER_multihashmap_iterate (handle->next_ids, iterate_next_member_ids, handle); | 530 | GNUNET_CONTAINER_multihashmap_iterate (handle->next_ids, |
531 | iterate_next_member_ids, handle); | ||
478 | GNUNET_CONTAINER_multihashmap_clear (handle->next_ids); | 532 | GNUNET_CONTAINER_multihashmap_clear (handle->next_ids); |
479 | } | 533 | } |
480 | 534 | ||
535 | |||
481 | void | 536 | void |
482 | notify_srv_handle_member_id (struct GNUNET_MESSENGER_SrvHandle *handle, | 537 | notify_srv_handle_member_id (struct GNUNET_MESSENGER_SrvHandle *handle, |
483 | struct GNUNET_MESSENGER_SrvRoom *room, | 538 | struct GNUNET_MESSENGER_SrvRoom *room, |
484 | const struct GNUNET_ShortHashCode *member_id, | 539 | const struct GNUNET_ShortHashCode *member_id, |
485 | enum GNUNET_GenericReturnValue reset) | 540 | enum GNUNET_GenericReturnValue reset) |
486 | { | 541 | { |
487 | GNUNET_assert((handle) && (room) && (member_id)); | 542 | GNUNET_assert ((handle) && (room) && (member_id)); |
488 | 543 | ||
489 | struct GNUNET_MESSENGER_NextMemberId *next = GNUNET_new (struct GNUNET_MESSENGER_NextMemberId); | 544 | struct GNUNET_MESSENGER_NextMemberId *next = GNUNET_new (struct |
490 | if (!next) | 545 | GNUNET_MESSENGER_NextMemberId); |
546 | if (! next) | ||
491 | { | 547 | { |
492 | return; | 548 | return; |
493 | } | 549 | } |
@@ -495,10 +551,13 @@ notify_srv_handle_member_id (struct GNUNET_MESSENGER_SrvHandle *handle, | |||
495 | GNUNET_memcpy (&(next->id), member_id, sizeof(next->id)); | 551 | GNUNET_memcpy (&(next->id), member_id, sizeof(next->id)); |
496 | next->reset = reset; | 552 | next->reset = reset; |
497 | 553 | ||
498 | const struct GNUNET_HashCode *key = get_srv_room_key(room); | 554 | const struct GNUNET_HashCode *key = get_srv_room_key (room); |
499 | 555 | ||
500 | struct GNUNET_MESSENGER_NextMemberId *prev = GNUNET_CONTAINER_multihashmap_get(handle->next_ids, key); | 556 | struct GNUNET_MESSENGER_NextMemberId *prev = |
501 | if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_put(handle->next_ids, key, next, GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE)) | 557 | GNUNET_CONTAINER_multihashmap_get (handle->next_ids, key); |
558 | if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_put (handle->next_ids, key, | ||
559 | next, | ||
560 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE)) | ||
502 | { | 561 | { |
503 | return; | 562 | return; |
504 | } | 563 | } |
@@ -506,6 +565,7 @@ notify_srv_handle_member_id (struct GNUNET_MESSENGER_SrvHandle *handle, | |||
506 | if (prev) | 565 | if (prev) |
507 | GNUNET_free (prev); | 566 | GNUNET_free (prev); |
508 | 567 | ||
509 | if (!handle->notify) | 568 | if (! handle->notify) |
510 | handle->notify = GNUNET_SCHEDULER_add_now (task_notify_srv_handle_member_id, handle); | 569 | handle->notify = GNUNET_SCHEDULER_add_now (task_notify_srv_handle_member_id, |
570 | handle); | ||
511 | } | 571 | } |
diff --git a/src/messenger/gnunet-service-messenger_handle.h b/src/messenger/gnunet-service-messenger_handle.h index 4a68ff276..ecd58afe6 100644 --- a/src/messenger/gnunet-service-messenger_handle.h +++ b/src/messenger/gnunet-service-messenger_handle.h | |||
@@ -97,8 +97,8 @@ get_srv_handle_key (const struct GNUNET_MESSENGER_SrvHandle *handle); | |||
97 | */ | 97 | */ |
98 | void | 98 | void |
99 | get_srv_handle_data_subdir (const struct GNUNET_MESSENGER_SrvHandle *handle, | 99 | get_srv_handle_data_subdir (const struct GNUNET_MESSENGER_SrvHandle *handle, |
100 | const char *name, | 100 | const char *name, |
101 | char **dir); | 101 | char **dir); |
102 | 102 | ||
103 | /** | 103 | /** |
104 | * Returns the member id of a given <i>handle</i> in a specific <i>room</i>. | 104 | * Returns the member id of a given <i>handle</i> in a specific <i>room</i>. |
diff --git a/src/messenger/gnunet-service-messenger_list_handles.c b/src/messenger/gnunet-service-messenger_list_handles.c index 0703c2de6..826e1f4ed 100644 --- a/src/messenger/gnunet-service-messenger_list_handles.c +++ b/src/messenger/gnunet-service-messenger_list_handles.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 |
@@ -31,48 +31,52 @@ | |||
31 | void | 31 | void |
32 | init_list_handles (struct GNUNET_MESSENGER_ListHandles *handles) | 32 | init_list_handles (struct GNUNET_MESSENGER_ListHandles *handles) |
33 | { | 33 | { |
34 | GNUNET_assert(handles); | 34 | GNUNET_assert (handles); |
35 | 35 | ||
36 | handles->head = NULL; | 36 | handles->head = NULL; |
37 | handles->tail = NULL; | 37 | handles->tail = NULL; |
38 | } | 38 | } |
39 | 39 | ||
40 | |||
40 | void | 41 | void |
41 | clear_list_handles (struct GNUNET_MESSENGER_ListHandles *handles) | 42 | clear_list_handles (struct GNUNET_MESSENGER_ListHandles *handles) |
42 | { | 43 | { |
43 | GNUNET_assert(handles); | 44 | GNUNET_assert (handles); |
44 | 45 | ||
45 | while (handles->head) | 46 | while (handles->head) |
46 | { | 47 | { |
47 | struct GNUNET_MESSENGER_ListHandle *element = handles->head; | 48 | struct GNUNET_MESSENGER_ListHandle *element = handles->head; |
48 | 49 | ||
49 | GNUNET_CONTAINER_DLL_remove(handles->head, handles->tail, element); | 50 | GNUNET_CONTAINER_DLL_remove (handles->head, handles->tail, element); |
50 | destroy_srv_handle (element->handle); | 51 | destroy_srv_handle (element->handle); |
51 | GNUNET_free(element); | 52 | GNUNET_free (element); |
52 | } | 53 | } |
53 | 54 | ||
54 | handles->head = NULL; | 55 | handles->head = NULL; |
55 | handles->tail = NULL; | 56 | handles->tail = NULL; |
56 | } | 57 | } |
57 | 58 | ||
59 | |||
58 | void | 60 | void |
59 | add_list_handle (struct GNUNET_MESSENGER_ListHandles *handles, | 61 | add_list_handle (struct GNUNET_MESSENGER_ListHandles *handles, |
60 | struct GNUNET_MESSENGER_SrvHandle *handle) | 62 | struct GNUNET_MESSENGER_SrvHandle *handle) |
61 | { | 63 | { |
62 | GNUNET_assert((handles) && (handle)); | 64 | GNUNET_assert ((handles) && (handle)); |
63 | 65 | ||
64 | struct GNUNET_MESSENGER_ListHandle *element = GNUNET_new(struct GNUNET_MESSENGER_ListHandle); | 66 | struct GNUNET_MESSENGER_ListHandle *element = GNUNET_new (struct |
67 | GNUNET_MESSENGER_ListHandle); | ||
65 | 68 | ||
66 | element->handle = handle; | 69 | element->handle = handle; |
67 | 70 | ||
68 | GNUNET_CONTAINER_DLL_insert_tail(handles->head, handles->tail, element); | 71 | GNUNET_CONTAINER_DLL_insert_tail (handles->head, handles->tail, element); |
69 | } | 72 | } |
70 | 73 | ||
74 | |||
71 | int | 75 | int |
72 | remove_list_handle (struct GNUNET_MESSENGER_ListHandles *handles, | 76 | remove_list_handle (struct GNUNET_MESSENGER_ListHandles *handles, |
73 | struct GNUNET_MESSENGER_SrvHandle *handle) | 77 | struct GNUNET_MESSENGER_SrvHandle *handle) |
74 | { | 78 | { |
75 | GNUNET_assert((handles) && (handle)); | 79 | GNUNET_assert ((handles) && (handle)); |
76 | 80 | ||
77 | struct GNUNET_MESSENGER_ListHandle *element; | 81 | struct GNUNET_MESSENGER_ListHandle *element; |
78 | 82 | ||
@@ -80,25 +84,28 @@ remove_list_handle (struct GNUNET_MESSENGER_ListHandles *handles, | |||
80 | if (element->handle == handle) | 84 | if (element->handle == handle) |
81 | break; | 85 | break; |
82 | 86 | ||
83 | if (!element) | 87 | if (! element) |
84 | return GNUNET_NO; | 88 | return GNUNET_NO; |
85 | 89 | ||
86 | GNUNET_CONTAINER_DLL_remove(handles->head, handles->tail, element); | 90 | GNUNET_CONTAINER_DLL_remove (handles->head, handles->tail, element); |
87 | GNUNET_free(element); | 91 | GNUNET_free (element); |
88 | 92 | ||
89 | return GNUNET_YES; | 93 | return GNUNET_YES; |
90 | } | 94 | } |
91 | 95 | ||
96 | |||
92 | struct GNUNET_MESSENGER_SrvHandle* | 97 | struct GNUNET_MESSENGER_SrvHandle* |
93 | find_list_handle_by_member (const struct GNUNET_MESSENGER_ListHandles *handles, | 98 | find_list_handle_by_member (const struct GNUNET_MESSENGER_ListHandles *handles, |
94 | const struct GNUNET_HashCode *key) | 99 | const struct GNUNET_HashCode *key) |
95 | { | 100 | { |
96 | GNUNET_assert((handles) && (key)); | 101 | GNUNET_assert ((handles) && (key)); |
97 | 102 | ||
98 | struct GNUNET_MESSENGER_ListHandle *element; | 103 | struct GNUNET_MESSENGER_ListHandle *element; |
99 | 104 | ||
100 | for (element = handles->head; element; element = element->next) | 105 | for (element = handles->head; element; element = element->next) |
101 | if (get_srv_handle_member_id ((struct GNUNET_MESSENGER_SrvHandle*) element->handle, key)) | 106 | if (get_srv_handle_member_id ((struct |
107 | GNUNET_MESSENGER_SrvHandle*) element->handle, | ||
108 | key)) | ||
102 | return element->handle; | 109 | return element->handle; |
103 | 110 | ||
104 | return NULL; | 111 | return NULL; |
diff --git a/src/messenger/gnunet-service-messenger_list_messages.c b/src/messenger/gnunet-service-messenger_list_messages.c index 5bab52806..063e1ebfc 100644 --- a/src/messenger/gnunet-service-messenger_list_messages.c +++ b/src/messenger/gnunet-service-messenger_list_messages.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--2021 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 |
@@ -29,47 +29,51 @@ | |||
29 | void | 29 | void |
30 | init_list_messages (struct GNUNET_MESSENGER_ListMessages *messages) | 30 | init_list_messages (struct GNUNET_MESSENGER_ListMessages *messages) |
31 | { | 31 | { |
32 | GNUNET_assert(messages); | 32 | GNUNET_assert (messages); |
33 | 33 | ||
34 | messages->head = NULL; | 34 | messages->head = NULL; |
35 | messages->tail = NULL; | 35 | messages->tail = NULL; |
36 | } | 36 | } |
37 | 37 | ||
38 | |||
38 | void | 39 | void |
39 | clear_list_messages (struct GNUNET_MESSENGER_ListMessages *messages) | 40 | clear_list_messages (struct GNUNET_MESSENGER_ListMessages *messages) |
40 | { | 41 | { |
41 | GNUNET_assert(messages); | 42 | GNUNET_assert (messages); |
42 | 43 | ||
43 | while (messages->head) | 44 | while (messages->head) |
44 | { | 45 | { |
45 | struct GNUNET_MESSENGER_ListMessage *element = messages->head; | 46 | struct GNUNET_MESSENGER_ListMessage *element = messages->head; |
46 | 47 | ||
47 | GNUNET_CONTAINER_DLL_remove(messages->head, messages->tail, element); | 48 | GNUNET_CONTAINER_DLL_remove (messages->head, messages->tail, element); |
48 | GNUNET_free(element); | 49 | GNUNET_free (element); |
49 | } | 50 | } |
50 | 51 | ||
51 | messages->head = NULL; | 52 | messages->head = NULL; |
52 | messages->tail = NULL; | 53 | messages->tail = NULL; |
53 | } | 54 | } |
54 | 55 | ||
56 | |||
55 | void | 57 | void |
56 | add_to_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, | 58 | add_to_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, |
57 | const struct GNUNET_HashCode *hash) | 59 | const struct GNUNET_HashCode *hash) |
58 | { | 60 | { |
59 | GNUNET_assert((messages) && (hash)); | 61 | GNUNET_assert ((messages) && (hash)); |
60 | 62 | ||
61 | struct GNUNET_MESSENGER_ListMessage *element = GNUNET_new(struct GNUNET_MESSENGER_ListMessage); | 63 | struct GNUNET_MESSENGER_ListMessage *element = GNUNET_new (struct |
64 | GNUNET_MESSENGER_ListMessage); | ||
62 | 65 | ||
63 | GNUNET_memcpy(&(element->hash), hash, sizeof(struct GNUNET_HashCode)); | 66 | GNUNET_memcpy (&(element->hash), hash, sizeof(struct GNUNET_HashCode)); |
64 | 67 | ||
65 | GNUNET_CONTAINER_DLL_insert_tail(messages->head, messages->tail, element); | 68 | GNUNET_CONTAINER_DLL_insert_tail (messages->head, messages->tail, element); |
66 | } | 69 | } |
67 | 70 | ||
71 | |||
68 | void | 72 | void |
69 | copy_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, | 73 | copy_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, |
70 | const struct GNUNET_MESSENGER_ListMessages *origin) | 74 | const struct GNUNET_MESSENGER_ListMessages *origin) |
71 | { | 75 | { |
72 | GNUNET_assert((messages) && (origin)); | 76 | GNUNET_assert ((messages) && (origin)); |
73 | 77 | ||
74 | struct GNUNET_MESSENGER_ListMessage *element; | 78 | struct GNUNET_MESSENGER_ListMessage *element; |
75 | 79 | ||
@@ -77,80 +81,85 @@ copy_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, | |||
77 | add_to_list_messages (messages, &(element->hash)); | 81 | add_to_list_messages (messages, &(element->hash)); |
78 | } | 82 | } |
79 | 83 | ||
84 | |||
80 | void | 85 | void |
81 | remove_from_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, | 86 | remove_from_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, |
82 | const struct GNUNET_HashCode *hash) | 87 | const struct GNUNET_HashCode *hash) |
83 | { | 88 | { |
84 | GNUNET_assert((messages) && (hash)); | 89 | GNUNET_assert ((messages) && (hash)); |
85 | 90 | ||
86 | struct GNUNET_MESSENGER_ListMessage *element; | 91 | struct GNUNET_MESSENGER_ListMessage *element; |
87 | 92 | ||
88 | for (element = messages->head; element; element = element->next) | 93 | for (element = messages->head; element; element = element->next) |
89 | if (0 == GNUNET_CRYPTO_hash_cmp (&(element->hash), hash)) | 94 | if (0 == GNUNET_CRYPTO_hash_cmp (&(element->hash), hash)) |
90 | { | 95 | { |
91 | GNUNET_CONTAINER_DLL_remove(messages->head, messages->tail, element); | 96 | GNUNET_CONTAINER_DLL_remove (messages->head, messages->tail, element); |
92 | GNUNET_free(element); | 97 | GNUNET_free (element); |
93 | break; | 98 | break; |
94 | } | 99 | } |
95 | } | 100 | } |
96 | 101 | ||
102 | |||
97 | void | 103 | void |
98 | load_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, | 104 | load_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, |
99 | const char *path) | 105 | const char *path) |
100 | { | 106 | { |
101 | GNUNET_assert((messages) && (path)); | 107 | GNUNET_assert ((messages) && (path)); |
102 | 108 | ||
103 | if (GNUNET_YES != GNUNET_DISK_file_test (path)) | 109 | if (GNUNET_YES != GNUNET_DISK_file_test (path)) |
104 | return; | 110 | return; |
105 | 111 | ||
106 | enum GNUNET_DISK_AccessPermissions permission = (GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); | 112 | enum GNUNET_DISK_AccessPermissions permission = (GNUNET_DISK_PERM_USER_READ |
113 | | GNUNET_DISK_PERM_USER_WRITE); | ||
107 | 114 | ||
108 | struct GNUNET_DISK_FileHandle *handle = GNUNET_DISK_file_open( | 115 | struct GNUNET_DISK_FileHandle *handle = GNUNET_DISK_file_open ( |
109 | path, GNUNET_DISK_OPEN_READ, permission | 116 | path, GNUNET_DISK_OPEN_READ, permission |
110 | ); | 117 | ); |
111 | 118 | ||
112 | if (!handle) | 119 | if (! handle) |
113 | return; | 120 | return; |
114 | 121 | ||
115 | GNUNET_DISK_file_seek(handle, 0, GNUNET_DISK_SEEK_SET); | 122 | GNUNET_DISK_file_seek (handle, 0, GNUNET_DISK_SEEK_SET); |
116 | 123 | ||
117 | struct GNUNET_HashCode hash; | 124 | struct GNUNET_HashCode hash; |
118 | ssize_t len; | 125 | ssize_t len; |
119 | 126 | ||
120 | do { | 127 | do { |
121 | len = GNUNET_DISK_file_read(handle, &hash, sizeof(hash)); | 128 | len = GNUNET_DISK_file_read (handle, &hash, sizeof(hash)); |
122 | 129 | ||
123 | if (len != sizeof(hash)) | 130 | if (len != sizeof(hash)) |
124 | break; | 131 | break; |
125 | 132 | ||
126 | add_to_list_messages(messages, &hash); | 133 | add_to_list_messages (messages, &hash); |
127 | } while (len == sizeof(hash)); | 134 | } while (len == sizeof(hash)); |
128 | 135 | ||
129 | GNUNET_DISK_file_close(handle); | 136 | GNUNET_DISK_file_close (handle); |
130 | } | 137 | } |
131 | 138 | ||
139 | |||
132 | void | 140 | void |
133 | save_list_messages (const struct GNUNET_MESSENGER_ListMessages *messages, | 141 | save_list_messages (const struct GNUNET_MESSENGER_ListMessages *messages, |
134 | const char *path) | 142 | const char *path) |
135 | { | 143 | { |
136 | GNUNET_assert((messages) && (path)); | 144 | GNUNET_assert ((messages) && (path)); |
137 | 145 | ||
138 | enum GNUNET_DISK_AccessPermissions permission = (GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); | 146 | enum GNUNET_DISK_AccessPermissions permission = (GNUNET_DISK_PERM_USER_READ |
147 | | GNUNET_DISK_PERM_USER_WRITE); | ||
139 | 148 | ||
140 | struct GNUNET_DISK_FileHandle *handle = GNUNET_DISK_file_open( | 149 | struct GNUNET_DISK_FileHandle *handle = GNUNET_DISK_file_open ( |
141 | path, GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_WRITE, permission | 150 | path, GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_WRITE, permission |
142 | ); | 151 | ); |
143 | 152 | ||
144 | if (!handle) | 153 | if (! handle) |
145 | return; | 154 | return; |
146 | 155 | ||
147 | GNUNET_DISK_file_seek(handle, 0, GNUNET_DISK_SEEK_SET); | 156 | GNUNET_DISK_file_seek (handle, 0, GNUNET_DISK_SEEK_SET); |
148 | 157 | ||
149 | struct GNUNET_MESSENGER_ListMessage *element; | 158 | struct GNUNET_MESSENGER_ListMessage *element; |
150 | 159 | ||
151 | for (element = messages->head; element; element = element->next) | 160 | for (element = messages->head; element; element = element->next) |
152 | GNUNET_DISK_file_write(handle, &(element->hash), sizeof(element->hash)); | 161 | GNUNET_DISK_file_write (handle, &(element->hash), sizeof(element->hash)); |
153 | 162 | ||
154 | GNUNET_DISK_file_sync(handle); | 163 | GNUNET_DISK_file_sync (handle); |
155 | GNUNET_DISK_file_close(handle); | 164 | GNUNET_DISK_file_close (handle); |
156 | } | 165 | } |
diff --git a/src/messenger/gnunet-service-messenger_member.c b/src/messenger/gnunet-service-messenger_member.c index b483f315b..1bb3a9969 100644 --- a/src/messenger/gnunet-service-messenger_member.c +++ b/src/messenger/gnunet-service-messenger_member.c | |||
@@ -34,44 +34,50 @@ create_member (struct GNUNET_MESSENGER_MemberStore *store, | |||
34 | { | 34 | { |
35 | GNUNET_assert (store); | 35 | GNUNET_assert (store); |
36 | 36 | ||
37 | struct GNUNET_MESSENGER_Member *member = GNUNET_new(struct GNUNET_MESSENGER_Member); | 37 | struct GNUNET_MESSENGER_Member *member = GNUNET_new (struct |
38 | GNUNET_MESSENGER_Member); | ||
38 | 39 | ||
39 | member->store = store; | 40 | member->store = store; |
40 | 41 | ||
41 | if (id) | 42 | if (id) |
42 | GNUNET_memcpy(&(member->id), id, sizeof(member->id)); | 43 | GNUNET_memcpy (&(member->id), id, sizeof(member->id)); |
43 | else if (GNUNET_YES != generate_free_member_id(&(member->id), store->members)) | 44 | else if (GNUNET_YES != generate_free_member_id (&(member->id), |
45 | store->members)) | ||
44 | { | 46 | { |
45 | GNUNET_free (member); | 47 | GNUNET_free (member); |
46 | return NULL; | 48 | return NULL; |
47 | } | 49 | } |
48 | 50 | ||
49 | member->sessions = GNUNET_CONTAINER_multihashmap_create(2, GNUNET_NO); | 51 | member->sessions = GNUNET_CONTAINER_multihashmap_create (2, GNUNET_NO); |
50 | 52 | ||
51 | return member; | 53 | return member; |
52 | } | 54 | } |
53 | 55 | ||
56 | |||
54 | static int | 57 | static int |
55 | iterate_destroy_session (void *cls, | 58 | iterate_destroy_session (void *cls, |
56 | const struct GNUNET_HashCode *key, | 59 | const struct GNUNET_HashCode *key, |
57 | void *value) | 60 | void *value) |
58 | { | 61 | { |
59 | struct GNUNET_MESSENGER_MemberSession *session = value; | 62 | struct GNUNET_MESSENGER_MemberSession *session = value; |
60 | destroy_member_session(session); | 63 | destroy_member_session (session); |
61 | return GNUNET_YES; | 64 | return GNUNET_YES; |
62 | } | 65 | } |
63 | 66 | ||
67 | |||
64 | void | 68 | void |
65 | destroy_member (struct GNUNET_MESSENGER_Member *member) | 69 | destroy_member (struct GNUNET_MESSENGER_Member *member) |
66 | { | 70 | { |
67 | GNUNET_assert((member) && (member->sessions)); | 71 | GNUNET_assert ((member) && (member->sessions)); |
68 | 72 | ||
69 | GNUNET_CONTAINER_multihashmap_iterate (member->sessions, iterate_destroy_session, NULL); | 73 | GNUNET_CONTAINER_multihashmap_iterate (member->sessions, |
74 | iterate_destroy_session, NULL); | ||
70 | GNUNET_CONTAINER_multihashmap_destroy (member->sessions); | 75 | GNUNET_CONTAINER_multihashmap_destroy (member->sessions); |
71 | 76 | ||
72 | GNUNET_free (member); | 77 | GNUNET_free (member); |
73 | } | 78 | } |
74 | 79 | ||
80 | |||
75 | const struct GNUNET_ShortHashCode* | 81 | const struct GNUNET_ShortHashCode* |
76 | get_member_id (const struct GNUNET_MESSENGER_Member *member) | 82 | get_member_id (const struct GNUNET_MESSENGER_Member *member) |
77 | { | 83 | { |
@@ -80,6 +86,7 @@ get_member_id (const struct GNUNET_MESSENGER_Member *member) | |||
80 | return &(member->id); | 86 | return &(member->id); |
81 | } | 87 | } |
82 | 88 | ||
89 | |||
83 | static int | 90 | static int |
84 | callback_scan_for_sessions (void *cls, | 91 | callback_scan_for_sessions (void *cls, |
85 | const char *filename) | 92 | const char *filename) |
@@ -92,13 +99,14 @@ callback_scan_for_sessions (void *cls, | |||
92 | 99 | ||
93 | GNUNET_asprintf (&directory, "%s%c", filename, DIR_SEPARATOR); | 100 | GNUNET_asprintf (&directory, "%s%c", filename, DIR_SEPARATOR); |
94 | 101 | ||
95 | load_member_session(member, directory); | 102 | load_member_session (member, directory); |
96 | GNUNET_free (directory); | 103 | GNUNET_free (directory); |
97 | } | 104 | } |
98 | 105 | ||
99 | return GNUNET_OK; | 106 | return GNUNET_OK; |
100 | } | 107 | } |
101 | 108 | ||
109 | |||
102 | void | 110 | void |
103 | load_member (struct GNUNET_MESSENGER_MemberStore *store, | 111 | load_member (struct GNUNET_MESSENGER_MemberStore *store, |
104 | const char *directory) | 112 | const char *directory) |
@@ -113,7 +121,8 @@ load_member (struct GNUNET_MESSENGER_MemberStore *store, | |||
113 | if (GNUNET_YES != GNUNET_DISK_file_test (config_file)) | 121 | if (GNUNET_YES != GNUNET_DISK_file_test (config_file)) |
114 | goto free_config; | 122 | goto free_config; |
115 | 123 | ||
116 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Load member configuration: %s\n", config_file); | 124 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Load member configuration: %s\n", |
125 | config_file); | ||
117 | 126 | ||
118 | struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create (); | 127 | struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create (); |
119 | 128 | ||
@@ -121,10 +130,11 @@ load_member (struct GNUNET_MESSENGER_MemberStore *store, | |||
121 | { | 130 | { |
122 | struct GNUNET_ShortHashCode id; | 131 | struct GNUNET_ShortHashCode id; |
123 | 132 | ||
124 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_data (cfg, "member", "id", &id, sizeof(id))) | 133 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_data (cfg, "member", "id", &id, |
134 | sizeof(id))) | ||
125 | goto destroy_config; | 135 | goto destroy_config; |
126 | 136 | ||
127 | member = add_store_member(store, &id); | 137 | member = add_store_member (store, &id); |
128 | } | 138 | } |
129 | 139 | ||
130 | destroy_config: | 140 | destroy_config: |
@@ -132,9 +142,9 @@ destroy_config: | |||
132 | GNUNET_CONFIGURATION_destroy (cfg); | 142 | GNUNET_CONFIGURATION_destroy (cfg); |
133 | 143 | ||
134 | free_config: | 144 | free_config: |
135 | GNUNET_free(config_file); | 145 | GNUNET_free (config_file); |
136 | 146 | ||
137 | if (!member) | 147 | if (! member) |
138 | return; | 148 | return; |
139 | 149 | ||
140 | char *scan_dir; | 150 | char *scan_dir; |
@@ -143,18 +153,20 @@ free_config: | |||
143 | if (GNUNET_OK == GNUNET_DISK_directory_test (scan_dir, GNUNET_YES)) | 153 | if (GNUNET_OK == GNUNET_DISK_directory_test (scan_dir, GNUNET_YES)) |
144 | GNUNET_DISK_directory_scan (scan_dir, callback_scan_for_sessions, member); | 154 | GNUNET_DISK_directory_scan (scan_dir, callback_scan_for_sessions, member); |
145 | 155 | ||
146 | GNUNET_free(scan_dir); | 156 | GNUNET_free (scan_dir); |
147 | } | 157 | } |
148 | 158 | ||
159 | |||
149 | static int | 160 | static int |
150 | iterate_load_next_session (void *cls, | 161 | iterate_load_next_session (void *cls, |
151 | const struct GNUNET_HashCode *key, | 162 | const struct GNUNET_HashCode *key, |
152 | void *value) | 163 | void *value) |
153 | { | 164 | { |
154 | const char* sessions_directory = cls; | 165 | const char *sessions_directory = cls; |
155 | 166 | ||
156 | char* load_dir; | 167 | char *load_dir; |
157 | GNUNET_asprintf (&load_dir, "%s%s%c", sessions_directory, GNUNET_h2s(key), DIR_SEPARATOR); | 168 | GNUNET_asprintf (&load_dir, "%s%s%c", sessions_directory, GNUNET_h2s (key), |
169 | DIR_SEPARATOR); | ||
158 | 170 | ||
159 | struct GNUNET_MESSENGER_MemberSession *session = value; | 171 | struct GNUNET_MESSENGER_MemberSession *session = value; |
160 | 172 | ||
@@ -165,29 +177,33 @@ iterate_load_next_session (void *cls, | |||
165 | return GNUNET_YES; | 177 | return GNUNET_YES; |
166 | } | 178 | } |
167 | 179 | ||
180 | |||
168 | void | 181 | void |
169 | load_member_next_sessions (const struct GNUNET_MESSENGER_Member *member, | 182 | load_member_next_sessions (const struct GNUNET_MESSENGER_Member *member, |
170 | const char *directory) | 183 | const char *directory) |
171 | { | 184 | { |
172 | GNUNET_assert ((member) && (directory)); | 185 | GNUNET_assert ((member) && (directory)); |
173 | 186 | ||
174 | char* load_dir; | 187 | char *load_dir; |
175 | GNUNET_asprintf (&load_dir, "%s%s%c", directory, "sessions", DIR_SEPARATOR); | 188 | GNUNET_asprintf (&load_dir, "%s%s%c", directory, "sessions", DIR_SEPARATOR); |
176 | 189 | ||
177 | GNUNET_CONTAINER_multihashmap_iterate (member->sessions, iterate_load_next_session, load_dir); | 190 | GNUNET_CONTAINER_multihashmap_iterate (member->sessions, |
191 | iterate_load_next_session, load_dir); | ||
178 | 192 | ||
179 | GNUNET_free(load_dir); | 193 | GNUNET_free (load_dir); |
180 | } | 194 | } |
181 | 195 | ||
196 | |||
182 | static int | 197 | static int |
183 | iterate_save_session (void *cls, | 198 | iterate_save_session (void *cls, |
184 | const struct GNUNET_HashCode *key, | 199 | const struct GNUNET_HashCode *key, |
185 | void *value) | 200 | void *value) |
186 | { | 201 | { |
187 | const char* sessions_directory = cls; | 202 | const char *sessions_directory = cls; |
188 | 203 | ||
189 | char* save_dir; | 204 | char *save_dir; |
190 | GNUNET_asprintf (&save_dir, "%s%s%c", sessions_directory, GNUNET_h2s(key), DIR_SEPARATOR); | 205 | GNUNET_asprintf (&save_dir, "%s%s%c", sessions_directory, GNUNET_h2s (key), |
206 | DIR_SEPARATOR); | ||
191 | 207 | ||
192 | struct GNUNET_MESSENGER_MemberSession *session = value; | 208 | struct GNUNET_MESSENGER_MemberSession *session = value; |
193 | 209 | ||
@@ -199,6 +215,7 @@ iterate_save_session (void *cls, | |||
199 | return GNUNET_YES; | 215 | return GNUNET_YES; |
200 | } | 216 | } |
201 | 217 | ||
218 | |||
202 | void | 219 | void |
203 | save_member (struct GNUNET_MESSENGER_Member *member, | 220 | save_member (struct GNUNET_MESSENGER_Member *member, |
204 | const char *directory) | 221 | const char *directory) |
@@ -208,39 +225,43 @@ save_member (struct GNUNET_MESSENGER_Member *member, | |||
208 | char *config_file; | 225 | char *config_file; |
209 | GNUNET_asprintf (&config_file, "%s%s", directory, "member.cfg"); | 226 | GNUNET_asprintf (&config_file, "%s%s", directory, "member.cfg"); |
210 | 227 | ||
211 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Save member configuration: %s\n", config_file); | 228 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Save member configuration: %s\n", |
229 | config_file); | ||
212 | 230 | ||
213 | struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create (); | 231 | struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create (); |
214 | 232 | ||
215 | char *id_data = GNUNET_STRINGS_data_to_string_alloc (&(member->id), sizeof(member->id)); | 233 | char *id_data = GNUNET_STRINGS_data_to_string_alloc (&(member->id), |
234 | sizeof(member->id)); | ||
216 | 235 | ||
217 | if (id_data) | 236 | if (id_data) |
218 | { | 237 | { |
219 | GNUNET_CONFIGURATION_set_value_string (cfg, "member", "id", id_data); | 238 | GNUNET_CONFIGURATION_set_value_string (cfg, "member", "id", id_data); |
220 | 239 | ||
221 | GNUNET_free(id_data); | 240 | GNUNET_free (id_data); |
222 | } | 241 | } |
223 | 242 | ||
224 | GNUNET_CONFIGURATION_write (cfg, config_file); | 243 | GNUNET_CONFIGURATION_write (cfg, config_file); |
225 | GNUNET_CONFIGURATION_destroy (cfg); | 244 | GNUNET_CONFIGURATION_destroy (cfg); |
226 | 245 | ||
227 | GNUNET_free(config_file); | 246 | GNUNET_free (config_file); |
228 | 247 | ||
229 | char* save_dir; | 248 | char *save_dir; |
230 | GNUNET_asprintf (&save_dir, "%s%s%c", directory, "sessions", DIR_SEPARATOR); | 249 | GNUNET_asprintf (&save_dir, "%s%s%c", directory, "sessions", DIR_SEPARATOR); |
231 | 250 | ||
232 | if ((GNUNET_YES == GNUNET_DISK_directory_test (save_dir, GNUNET_NO)) || | 251 | if ((GNUNET_YES == GNUNET_DISK_directory_test (save_dir, GNUNET_NO)) || |
233 | (GNUNET_OK == GNUNET_DISK_directory_create (save_dir))) | 252 | (GNUNET_OK == GNUNET_DISK_directory_create (save_dir))) |
234 | GNUNET_CONTAINER_multihashmap_iterate (member->sessions, iterate_save_session, save_dir); | 253 | GNUNET_CONTAINER_multihashmap_iterate (member->sessions, |
254 | iterate_save_session, save_dir); | ||
235 | 255 | ||
236 | GNUNET_free(save_dir); | 256 | GNUNET_free (save_dir); |
237 | } | 257 | } |
238 | 258 | ||
259 | |||
239 | static void | 260 | static void |
240 | sync_session_contact_from_next (struct GNUNET_MESSENGER_MemberSession *session, | 261 | sync_session_contact_from_next (struct GNUNET_MESSENGER_MemberSession *session, |
241 | struct GNUNET_MESSENGER_MemberSession *next) | 262 | struct GNUNET_MESSENGER_MemberSession *next) |
242 | { | 263 | { |
243 | GNUNET_assert((session) && (next)); | 264 | GNUNET_assert ((session) && (next)); |
244 | 265 | ||
245 | if (session == next) | 266 | if (session == next) |
246 | return; | 267 | return; |
@@ -251,6 +272,7 @@ sync_session_contact_from_next (struct GNUNET_MESSENGER_MemberSession *session, | |||
251 | session->contact = next->contact; | 272 | session->contact = next->contact; |
252 | } | 273 | } |
253 | 274 | ||
275 | |||
254 | static int | 276 | static int |
255 | iterate_sync_session_contact (void *cls, | 277 | iterate_sync_session_contact (void *cls, |
256 | const struct GNUNET_HashCode *key, | 278 | const struct GNUNET_HashCode *key, |
@@ -264,14 +286,17 @@ iterate_sync_session_contact (void *cls, | |||
264 | return GNUNET_YES; | 286 | return GNUNET_YES; |
265 | } | 287 | } |
266 | 288 | ||
289 | |||
267 | void | 290 | void |
268 | sync_member_contacts (struct GNUNET_MESSENGER_Member *member) | 291 | sync_member_contacts (struct GNUNET_MESSENGER_Member *member) |
269 | { | 292 | { |
270 | GNUNET_assert ((member) && (member->sessions)); | 293 | GNUNET_assert ((member) && (member->sessions)); |
271 | 294 | ||
272 | GNUNET_CONTAINER_multihashmap_iterate (member->sessions, iterate_sync_session_contact, NULL); | 295 | GNUNET_CONTAINER_multihashmap_iterate (member->sessions, |
296 | iterate_sync_session_contact, NULL); | ||
273 | } | 297 | } |
274 | 298 | ||
299 | |||
275 | struct GNUNET_MESSENGER_MemberSession* | 300 | struct GNUNET_MESSENGER_MemberSession* |
276 | get_member_session (const struct GNUNET_MESSENGER_Member *member, | 301 | get_member_session (const struct GNUNET_MESSENGER_Member *member, |
277 | const struct GNUNET_IDENTITY_PublicKey *public_key) | 302 | const struct GNUNET_IDENTITY_PublicKey *public_key) |
@@ -279,12 +304,14 @@ get_member_session (const struct GNUNET_MESSENGER_Member *member, | |||
279 | GNUNET_assert ((member) && (public_key)); | 304 | GNUNET_assert ((member) && (public_key)); |
280 | 305 | ||
281 | struct GNUNET_HashCode hash; | 306 | struct GNUNET_HashCode hash; |
282 | GNUNET_CRYPTO_hash(public_key, sizeof(*public_key), &hash); | 307 | GNUNET_CRYPTO_hash (public_key, sizeof(*public_key), &hash); |
283 | 308 | ||
284 | return GNUNET_CONTAINER_multihashmap_get(member->sessions, &hash); | 309 | return GNUNET_CONTAINER_multihashmap_get (member->sessions, &hash); |
285 | } | 310 | } |
286 | 311 | ||
287 | struct GNUNET_MESSENGER_ClosureSearchSession { | 312 | |
313 | struct GNUNET_MESSENGER_ClosureSearchSession | ||
314 | { | ||
288 | const struct GNUNET_MESSENGER_Message *message; | 315 | const struct GNUNET_MESSENGER_Message *message; |
289 | const struct GNUNET_HashCode *hash; | 316 | const struct GNUNET_HashCode *hash; |
290 | 317 | ||
@@ -296,43 +323,48 @@ iterate_search_session (void *cls, | |||
296 | const struct GNUNET_HashCode *key, | 323 | const struct GNUNET_HashCode *key, |
297 | void *value) | 324 | void *value) |
298 | { | 325 | { |
299 | struct GNUNET_MESSENGER_ClosureSearchSession* search = cls; | 326 | struct GNUNET_MESSENGER_ClosureSearchSession *search = cls; |
300 | struct GNUNET_MESSENGER_MemberSession *session = value; | 327 | struct GNUNET_MESSENGER_MemberSession *session = value; |
301 | 328 | ||
302 | if (GNUNET_OK != verify_member_session_as_sender(session, search->message, search->hash)) | 329 | if (GNUNET_OK != verify_member_session_as_sender (session, search->message, |
330 | search->hash)) | ||
303 | return GNUNET_YES; | 331 | return GNUNET_YES; |
304 | 332 | ||
305 | search->match = session; | 333 | search->match = session; |
306 | return GNUNET_NO; | 334 | return GNUNET_NO; |
307 | } | 335 | } |
308 | 336 | ||
337 | |||
309 | static struct GNUNET_MESSENGER_MemberSession* | 338 | static struct GNUNET_MESSENGER_MemberSession* |
310 | try_member_session (struct GNUNET_MESSENGER_Member *member, | 339 | try_member_session (struct GNUNET_MESSENGER_Member *member, |
311 | const struct GNUNET_IDENTITY_PublicKey *public_key) | 340 | const struct GNUNET_IDENTITY_PublicKey *public_key) |
312 | { | 341 | { |
313 | struct GNUNET_MESSENGER_MemberSession* session = get_member_session(member, public_key); | 342 | struct GNUNET_MESSENGER_MemberSession *session = get_member_session (member, |
343 | public_key); | ||
314 | 344 | ||
315 | if (session) | 345 | if (session) |
316 | return session; | 346 | return session; |
317 | 347 | ||
318 | session = create_member_session(member, public_key); | 348 | session = create_member_session (member, public_key); |
319 | 349 | ||
320 | if (session) | 350 | if (session) |
321 | add_member_session(member, session); | 351 | add_member_session (member, session); |
322 | 352 | ||
323 | return session; | 353 | return session; |
324 | } | 354 | } |
325 | 355 | ||
356 | |||
326 | struct GNUNET_MESSENGER_MemberSession* | 357 | struct GNUNET_MESSENGER_MemberSession* |
327 | get_member_session_of (struct GNUNET_MESSENGER_Member *member, | 358 | get_member_session_of (struct GNUNET_MESSENGER_Member *member, |
328 | const struct GNUNET_MESSENGER_Message *message, | 359 | const struct GNUNET_MESSENGER_Message *message, |
329 | const struct GNUNET_HashCode *hash) | 360 | const struct GNUNET_HashCode *hash) |
330 | { | 361 | { |
331 | GNUNET_assert ((member) && (message) && (hash) && | 362 | GNUNET_assert ((member) && (message) && (hash) && |
332 | (0 == GNUNET_memcmp(&(member->id), &(message->header.sender_id)))); | 363 | (0 == GNUNET_memcmp (&(member->id), |
364 | &(message->header.sender_id)))); | ||
333 | 365 | ||
334 | if (GNUNET_MESSENGER_KIND_JOIN == message->header.kind) | 366 | if (GNUNET_MESSENGER_KIND_JOIN == message->header.kind) |
335 | return try_member_session(member, &(message->body.join.key)); | 367 | return try_member_session (member, &(message->body.join.key)); |
336 | 368 | ||
337 | struct GNUNET_MESSENGER_ClosureSearchSession search; | 369 | struct GNUNET_MESSENGER_ClosureSearchSession search; |
338 | 370 | ||
@@ -340,49 +372,59 @@ get_member_session_of (struct GNUNET_MESSENGER_Member *member, | |||
340 | search.hash = hash; | 372 | search.hash = hash; |
341 | 373 | ||
342 | search.match = NULL; | 374 | search.match = NULL; |
343 | GNUNET_CONTAINER_multihashmap_iterate(member->sessions, iterate_search_session, &search); | 375 | GNUNET_CONTAINER_multihashmap_iterate (member->sessions, |
376 | iterate_search_session, &search); | ||
344 | 377 | ||
345 | return search.match; | 378 | return search.match; |
346 | } | 379 | } |
347 | 380 | ||
381 | |||
348 | void | 382 | void |
349 | add_member_session (struct GNUNET_MESSENGER_Member *member, | 383 | add_member_session (struct GNUNET_MESSENGER_Member *member, |
350 | struct GNUNET_MESSENGER_MemberSession *session) | 384 | struct GNUNET_MESSENGER_MemberSession *session) |
351 | { | 385 | { |
352 | if (!session) | 386 | if (! session) |
353 | return; | 387 | return; |
354 | 388 | ||
355 | GNUNET_assert((member) && (session->member == member)); | 389 | GNUNET_assert ((member) && (session->member == member)); |
356 | 390 | ||
357 | const struct GNUNET_IDENTITY_PublicKey *public_key = get_member_session_public_key(session); | 391 | const struct GNUNET_IDENTITY_PublicKey *public_key = |
392 | get_member_session_public_key (session); | ||
358 | 393 | ||
359 | struct GNUNET_HashCode hash; | 394 | struct GNUNET_HashCode hash; |
360 | GNUNET_CRYPTO_hash(public_key, sizeof(*public_key), &hash); | 395 | GNUNET_CRYPTO_hash (public_key, sizeof(*public_key), &hash); |
361 | 396 | ||
362 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put( | 397 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put ( |
363 | member->sessions, &hash, session, | 398 | member->sessions, &hash, session, |
364 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | 399 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) |
365 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Adding a member session failed: %s\n", | 400 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
366 | GNUNET_h2s(&hash)); | 401 | "Adding a member session failed: %s\n", |
402 | GNUNET_h2s (&hash)); | ||
367 | } | 403 | } |
368 | 404 | ||
405 | |||
369 | void | 406 | void |
370 | remove_member_session (struct GNUNET_MESSENGER_Member *member, | 407 | remove_member_session (struct GNUNET_MESSENGER_Member *member, |
371 | struct GNUNET_MESSENGER_MemberSession *session) | 408 | struct GNUNET_MESSENGER_MemberSession *session) |
372 | { | 409 | { |
373 | GNUNET_assert ((member) && (session) && (session->member == member)); | 410 | GNUNET_assert ((member) && (session) && (session->member == member)); |
374 | 411 | ||
375 | const struct GNUNET_IDENTITY_PublicKey *public_key = get_member_session_public_key(session); | 412 | const struct GNUNET_IDENTITY_PublicKey *public_key = |
413 | get_member_session_public_key (session); | ||
376 | 414 | ||
377 | struct GNUNET_HashCode hash; | 415 | struct GNUNET_HashCode hash; |
378 | GNUNET_CRYPTO_hash(public_key, sizeof(*public_key), &hash); | 416 | GNUNET_CRYPTO_hash (public_key, sizeof(*public_key), &hash); |
379 | 417 | ||
380 | if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove(member->sessions, &hash, session)) | 418 | if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (member->sessions, |
381 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Removing a member session failed: %s\n", | 419 | &hash, session)) |
382 | GNUNET_h2s(&hash)); | 420 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
421 | "Removing a member session failed: %s\n", | ||
422 | GNUNET_h2s (&hash)); | ||
383 | } | 423 | } |
384 | 424 | ||
385 | struct GNUNET_MESSENGER_ClosureIterateSessions { | 425 | |
426 | struct GNUNET_MESSENGER_ClosureIterateSessions | ||
427 | { | ||
386 | GNUNET_MESSENGER_MemberIteratorCallback it; | 428 | GNUNET_MESSENGER_MemberIteratorCallback it; |
387 | void *cls; | 429 | void *cls; |
388 | }; | 430 | }; |
@@ -395,9 +437,11 @@ iterate_member_sessions_it (void *cls, | |||
395 | struct GNUNET_MESSENGER_ClosureIterateSessions *iterate = cls; | 437 | struct GNUNET_MESSENGER_ClosureIterateSessions *iterate = cls; |
396 | struct GNUNET_MESSENGER_MemberSession *session = value; | 438 | struct GNUNET_MESSENGER_MemberSession *session = value; |
397 | 439 | ||
398 | return iterate->it (iterate->cls, get_member_session_public_key(session), session); | 440 | return iterate->it (iterate->cls, get_member_session_public_key (session), |
441 | session); | ||
399 | } | 442 | } |
400 | 443 | ||
444 | |||
401 | int | 445 | int |
402 | iterate_member_sessions (struct GNUNET_MESSENGER_Member *member, | 446 | iterate_member_sessions (struct GNUNET_MESSENGER_Member *member, |
403 | GNUNET_MESSENGER_MemberIteratorCallback it, | 447 | GNUNET_MESSENGER_MemberIteratorCallback it, |
@@ -410,5 +454,7 @@ iterate_member_sessions (struct GNUNET_MESSENGER_Member *member, | |||
410 | iterate.it = it; | 454 | iterate.it = it; |
411 | iterate.cls = cls; | 455 | iterate.cls = cls; |
412 | 456 | ||
413 | return GNUNET_CONTAINER_multihashmap_iterate(member->sessions, iterate_member_sessions_it, &iterate); | 457 | return GNUNET_CONTAINER_multihashmap_iterate (member->sessions, |
458 | iterate_member_sessions_it, | ||
459 | &iterate); | ||
414 | } | 460 | } |
diff --git a/src/messenger/gnunet-service-messenger_member.h b/src/messenger/gnunet-service-messenger_member.h index 0c5870fd3..dc3643727 100644 --- a/src/messenger/gnunet-service-messenger_member.h +++ b/src/messenger/gnunet-service-messenger_member.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2020--2021 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 |
@@ -175,6 +175,6 @@ remove_member_session (struct GNUNET_MESSENGER_Member *member, | |||
175 | int | 175 | int |
176 | iterate_member_sessions (struct GNUNET_MESSENGER_Member *member, | 176 | iterate_member_sessions (struct GNUNET_MESSENGER_Member *member, |
177 | GNUNET_MESSENGER_MemberIteratorCallback it, | 177 | GNUNET_MESSENGER_MemberIteratorCallback it, |
178 | void* cls); | 178 | void *cls); |
179 | 179 | ||
180 | #endif //GNUNET_SERVICE_MESSENGER_MEMBER_H | 180 | #endif //GNUNET_SERVICE_MESSENGER_MEMBER_H |
diff --git a/src/messenger/gnunet-service-messenger_member_session.c b/src/messenger/gnunet-service-messenger_member_session.c index 2e26fd228..361fb9966 100644 --- a/src/messenger/gnunet-service-messenger_member_session.c +++ b/src/messenger/gnunet-service-messenger_member_session.c | |||
@@ -35,44 +35,46 @@ struct GNUNET_MESSENGER_MemberSession* | |||
35 | create_member_session (struct GNUNET_MESSENGER_Member *member, | 35 | create_member_session (struct GNUNET_MESSENGER_Member *member, |
36 | const struct GNUNET_IDENTITY_PublicKey *pubkey) | 36 | const struct GNUNET_IDENTITY_PublicKey *pubkey) |
37 | { | 37 | { |
38 | if ((!member) || (!pubkey) || (!(member->store))) | 38 | if ((! member) || (! pubkey) || (! (member->store))) |
39 | return NULL; | 39 | return NULL; |
40 | 40 | ||
41 | struct GNUNET_MESSENGER_MemberSession *session = GNUNET_new(struct GNUNET_MESSENGER_MemberSession); | 41 | struct GNUNET_MESSENGER_MemberSession *session = GNUNET_new (struct |
42 | GNUNET_MESSENGER_MemberSession); | ||
42 | session->member = member; | 43 | session->member = member; |
43 | 44 | ||
44 | GNUNET_memcpy(&(session->public_key), pubkey, sizeof(session->public_key)); | 45 | GNUNET_memcpy (&(session->public_key), pubkey, sizeof(session->public_key)); |
45 | 46 | ||
46 | get_context_from_member ( | 47 | get_context_from_member ( |
47 | get_member_session_key (session), | 48 | get_member_session_key (session), |
48 | get_member_session_id (session), | 49 | get_member_session_id (session), |
49 | &(session->context) | 50 | &(session->context) |
50 | ); | 51 | ); |
51 | 52 | ||
52 | struct GNUNET_MESSENGER_ContactStore *store = get_member_contact_store(session->member->store); | 53 | struct GNUNET_MESSENGER_ContactStore *store = get_member_contact_store ( |
54 | session->member->store); | ||
53 | 55 | ||
54 | session->contact = get_store_contact( | 56 | session->contact = get_store_contact ( |
55 | store, | 57 | store, |
56 | get_member_session_context (session), | 58 | get_member_session_context (session), |
57 | get_member_session_public_key (session) | 59 | get_member_session_public_key (session) |
58 | ); | 60 | ); |
59 | 61 | ||
60 | if (!(session->contact)) | 62 | if (! (session->contact)) |
61 | { | 63 | { |
62 | GNUNET_free(session); | 64 | GNUNET_free (session); |
63 | return NULL; | 65 | return NULL; |
64 | } | 66 | } |
65 | 67 | ||
66 | increase_contact_rc (session->contact); | 68 | increase_contact_rc (session->contact); |
67 | 69 | ||
68 | session->history = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO); | 70 | session->history = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); |
69 | 71 | ||
70 | init_list_messages(&(session->messages)); | 72 | init_list_messages (&(session->messages)); |
71 | 73 | ||
72 | session->prev = NULL; | 74 | session->prev = NULL; |
73 | session->next = NULL; | 75 | session->next = NULL; |
74 | 76 | ||
75 | session->start = GNUNET_TIME_absolute_get(); | 77 | session->start = GNUNET_TIME_absolute_get (); |
76 | 78 | ||
77 | session->closed = GNUNET_NO; | 79 | session->closed = GNUNET_NO; |
78 | session->completed = GNUNET_NO; | 80 | session->completed = GNUNET_NO; |
@@ -80,32 +82,35 @@ create_member_session (struct GNUNET_MESSENGER_Member *member, | |||
80 | return session; | 82 | return session; |
81 | } | 83 | } |
82 | 84 | ||
85 | |||
83 | static void | 86 | static void |
84 | check_member_session_completion (struct GNUNET_MESSENGER_MemberSession *session) | 87 | check_member_session_completion (struct GNUNET_MESSENGER_MemberSession *session) |
85 | { | 88 | { |
86 | GNUNET_assert (session); | 89 | GNUNET_assert (session); |
87 | 90 | ||
88 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Check session history (%s) for completion.\n", | 91 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
89 | GNUNET_sh2s(get_member_session_id(session))); | 92 | "Check session history (%s) for completion.\n", |
93 | GNUNET_sh2s (get_member_session_id (session))); | ||
90 | 94 | ||
91 | if (!session->messages.tail) | 95 | if (! session->messages.tail) |
92 | { | 96 | { |
93 | session->completed = GNUNET_YES; | 97 | session->completed = GNUNET_YES; |
94 | goto completion; | 98 | goto completion; |
95 | } | 99 | } |
96 | 100 | ||
97 | const struct GNUNET_HashCode* start = &(session->messages.head->hash); | 101 | const struct GNUNET_HashCode *start = &(session->messages.head->hash); |
98 | const struct GNUNET_HashCode* end = &(session->messages.tail->hash); | 102 | const struct GNUNET_HashCode *end = &(session->messages.tail->hash); |
99 | 103 | ||
100 | struct GNUNET_MESSENGER_ListMessages level; | 104 | struct GNUNET_MESSENGER_ListMessages level; |
101 | init_list_messages(&level); | 105 | init_list_messages (&level); |
102 | 106 | ||
103 | add_to_list_messages(&level, end); | 107 | add_to_list_messages (&level, end); |
104 | 108 | ||
105 | struct GNUNET_MESSENGER_MessageStore *store = get_srv_room_message_store(session->member->store->room); | 109 | struct GNUNET_MESSENGER_MessageStore *store = get_srv_room_message_store ( |
110 | session->member->store->room); | ||
106 | 111 | ||
107 | struct GNUNET_MESSENGER_ListMessages list; | 112 | struct GNUNET_MESSENGER_ListMessages list; |
108 | init_list_messages(&list); | 113 | init_list_messages (&list); |
109 | 114 | ||
110 | while (level.head) | 115 | while (level.head) |
111 | { | 116 | { |
@@ -113,57 +118,61 @@ check_member_session_completion (struct GNUNET_MESSENGER_MemberSession *session) | |||
113 | 118 | ||
114 | for (element = level.head; element; element = element->next) | 119 | for (element = level.head; element; element = element->next) |
115 | { | 120 | { |
116 | const struct GNUNET_MESSENGER_MessageLink *link = get_store_message_link( | 121 | const struct GNUNET_MESSENGER_MessageLink *link = get_store_message_link ( |
117 | store, &(element->hash), GNUNET_NO | 122 | store, &(element->hash), GNUNET_NO |
118 | ); | 123 | ); |
119 | 124 | ||
120 | if (!link) | 125 | if (! link) |
121 | continue; | 126 | continue; |
122 | 127 | ||
123 | add_to_list_messages(&list, &(link->first)); | 128 | add_to_list_messages (&list, &(link->first)); |
124 | 129 | ||
125 | if (GNUNET_YES == link->multiple) | 130 | if (GNUNET_YES == link->multiple) |
126 | add_to_list_messages(&list, &(link->second)); | 131 | add_to_list_messages (&list, &(link->second)); |
127 | } | 132 | } |
128 | 133 | ||
129 | clear_list_messages(&level); | 134 | clear_list_messages (&level); |
130 | 135 | ||
131 | for (element = list.head; element; element = element->next) | 136 | for (element = list.head; element; element = element->next) |
132 | if (GNUNET_YES == check_member_session_history(session, &(element->hash), GNUNET_YES)) | 137 | if (GNUNET_YES == check_member_session_history (session, &(element->hash), |
138 | GNUNET_YES)) | ||
133 | break; | 139 | break; |
134 | 140 | ||
135 | if (element) | 141 | if (element) |
136 | if (0 != GNUNET_CRYPTO_hash_cmp(&(element->hash), start)) | 142 | if (0 != GNUNET_CRYPTO_hash_cmp (&(element->hash), start)) |
137 | add_to_list_messages(&level, &(element->hash)); | 143 | add_to_list_messages (&level, &(element->hash)); |
138 | else | 144 | else |
139 | session->completed = GNUNET_YES; | 145 | session->completed = GNUNET_YES; |
140 | else | 146 | else |
141 | copy_list_messages(&level, &list); | 147 | copy_list_messages (&level, &list); |
142 | 148 | ||
143 | clear_list_messages(&list); | 149 | clear_list_messages (&list); |
144 | } | 150 | } |
145 | 151 | ||
146 | completion: | 152 | completion: |
147 | if (GNUNET_YES == is_member_session_completed(session)) | 153 | if (GNUNET_YES == is_member_session_completed (session)) |
148 | { | 154 | { |
149 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Completed session history (%s)\n", | 155 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Completed session history (%s)\n", |
150 | GNUNET_sh2s(get_member_session_id(session))); | 156 | GNUNET_sh2s (get_member_session_id (session))); |
151 | 157 | ||
152 | GNUNET_CONTAINER_multihashmap_clear (session->history); | 158 | GNUNET_CONTAINER_multihashmap_clear (session->history); |
153 | 159 | ||
154 | struct GNUNET_MESSENGER_ContactStore *store = get_member_contact_store(session->member->store); | 160 | struct GNUNET_MESSENGER_ContactStore *store = get_member_contact_store ( |
161 | session->member->store); | ||
155 | 162 | ||
156 | if ((session->contact) && (GNUNET_YES == decrease_contact_rc (session->contact))) | 163 | if ((session->contact) && (GNUNET_YES == decrease_contact_rc ( |
164 | session->contact))) | ||
157 | remove_store_contact ( | 165 | remove_store_contact ( |
158 | store, | 166 | store, |
159 | session->contact, | 167 | session->contact, |
160 | get_member_session_context(session) | 168 | get_member_session_context (session) |
161 | ); | 169 | ); |
162 | 170 | ||
163 | session->contact = NULL; | 171 | session->contact = NULL; |
164 | } | 172 | } |
165 | } | 173 | } |
166 | 174 | ||
175 | |||
167 | static int | 176 | static int |
168 | iterate_copy_history (void *cls, | 177 | iterate_copy_history (void *cls, |
169 | const struct GNUNET_HashCode *key, | 178 | const struct GNUNET_HashCode *key, |
@@ -171,73 +180,79 @@ iterate_copy_history (void *cls, | |||
171 | { | 180 | { |
172 | struct GNUNET_MESSENGER_MemberSession *next = cls; | 181 | struct GNUNET_MESSENGER_MemberSession *next = cls; |
173 | 182 | ||
174 | GNUNET_CONTAINER_multihashmap_put(next->history, key, (value? next : NULL), | 183 | GNUNET_CONTAINER_multihashmap_put (next->history, key, (value? next : NULL), |
175 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 184 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); |
176 | 185 | ||
177 | return GNUNET_YES; | 186 | return GNUNET_YES; |
178 | } | 187 | } |
179 | 188 | ||
189 | |||
180 | struct GNUNET_MESSENGER_MemberSession* | 190 | struct GNUNET_MESSENGER_MemberSession* |
181 | switch_member_session (struct GNUNET_MESSENGER_MemberSession *session, | 191 | switch_member_session (struct GNUNET_MESSENGER_MemberSession *session, |
182 | const struct GNUNET_MESSENGER_Message *message, | 192 | const struct GNUNET_MESSENGER_Message *message, |
183 | const struct GNUNET_HashCode *hash) | 193 | const struct GNUNET_HashCode *hash) |
184 | { | 194 | { |
185 | if ((!session) || (!message) || (!hash)) | 195 | if ((! session) || (! message) || (! hash)) |
186 | return NULL; | 196 | return NULL; |
187 | 197 | ||
188 | GNUNET_assert((GNUNET_MESSENGER_KIND_ID == message->header.kind) || | 198 | GNUNET_assert ((GNUNET_MESSENGER_KIND_ID == message->header.kind) || |
189 | (GNUNET_MESSENGER_KIND_KEY == message->header.kind)); | 199 | (GNUNET_MESSENGER_KIND_KEY == message->header.kind)); |
190 | 200 | ||
191 | struct GNUNET_MESSENGER_MemberSession *next = GNUNET_new(struct GNUNET_MESSENGER_MemberSession); | 201 | struct GNUNET_MESSENGER_MemberSession *next = GNUNET_new (struct |
202 | GNUNET_MESSENGER_MemberSession); | ||
192 | 203 | ||
193 | if (GNUNET_MESSENGER_KIND_ID == message->header.kind) | 204 | if (GNUNET_MESSENGER_KIND_ID == message->header.kind) |
194 | next->member = add_store_member(session->member->store, &(message->body.id.id)); | 205 | next->member = add_store_member (session->member->store, |
206 | &(message->body.id.id)); | ||
195 | else | 207 | else |
196 | next->member = session->member; | 208 | next->member = session->member; |
197 | 209 | ||
198 | if (GNUNET_MESSENGER_KIND_KEY == message->header.kind) | 210 | if (GNUNET_MESSENGER_KIND_KEY == message->header.kind) |
199 | GNUNET_memcpy(&(next->public_key), &(message->body.key.key), sizeof(next->public_key)); | 211 | GNUNET_memcpy (&(next->public_key), &(message->body.key.key), |
212 | sizeof(next->public_key)); | ||
200 | else | 213 | else |
201 | GNUNET_memcpy(&(next->public_key), get_member_session_public_key(session), sizeof(next->public_key)); | 214 | GNUNET_memcpy (&(next->public_key), get_member_session_public_key (session), |
215 | sizeof(next->public_key)); | ||
202 | 216 | ||
203 | get_context_from_member ( | 217 | get_context_from_member ( |
204 | get_member_session_key (next), | 218 | get_member_session_key (next), |
205 | get_member_session_id (next), | 219 | get_member_session_id (next), |
206 | &(next->context) | 220 | &(next->context) |
207 | ); | 221 | ); |
208 | 222 | ||
209 | update_store_contact( | 223 | update_store_contact ( |
210 | get_member_contact_store(next->member->store), | 224 | get_member_contact_store (next->member->store), |
211 | get_member_session_contact(session), | 225 | get_member_session_contact (session), |
212 | get_member_session_context(session), | 226 | get_member_session_context (session), |
213 | get_member_session_context(next), | 227 | get_member_session_context (next), |
214 | get_member_session_public_key(next) | 228 | get_member_session_public_key (next) |
215 | ); | 229 | ); |
216 | 230 | ||
217 | next->contact = get_member_session_contact(session); | 231 | next->contact = get_member_session_contact (session); |
218 | 232 | ||
219 | if (!(next->contact)) | 233 | if (! (next->contact)) |
220 | { | 234 | { |
221 | GNUNET_free(next); | 235 | GNUNET_free (next); |
222 | return NULL; | 236 | return NULL; |
223 | } | 237 | } |
224 | 238 | ||
225 | increase_contact_rc (next->contact); | 239 | increase_contact_rc (next->contact); |
226 | 240 | ||
227 | next->history = GNUNET_CONTAINER_multihashmap_create( | 241 | next->history = GNUNET_CONTAINER_multihashmap_create ( |
228 | GNUNET_CONTAINER_multihashmap_size(session->history), GNUNET_NO | 242 | GNUNET_CONTAINER_multihashmap_size (session->history), GNUNET_NO |
229 | ); | 243 | ); |
230 | 244 | ||
231 | GNUNET_CONTAINER_multihashmap_iterate(session->history, iterate_copy_history, next); | 245 | GNUNET_CONTAINER_multihashmap_iterate (session->history, iterate_copy_history, |
246 | next); | ||
232 | 247 | ||
233 | init_list_messages(&(next->messages)); | 248 | init_list_messages (&(next->messages)); |
234 | copy_list_messages(&(next->messages), &(session->messages)); | 249 | copy_list_messages (&(next->messages), &(session->messages)); |
235 | 250 | ||
236 | session->next = next; | 251 | session->next = next; |
237 | next->prev = session; | 252 | next->prev = session; |
238 | next->next = NULL; | 253 | next->next = NULL; |
239 | 254 | ||
240 | next->start = GNUNET_TIME_absolute_get(); | 255 | next->start = GNUNET_TIME_absolute_get (); |
241 | 256 | ||
242 | session->closed = GNUNET_YES; | 257 | session->closed = GNUNET_YES; |
243 | next->closed = GNUNET_NO; | 258 | next->closed = GNUNET_NO; |
@@ -248,8 +263,9 @@ switch_member_session (struct GNUNET_MESSENGER_MemberSession *session, | |||
248 | return next; | 263 | return next; |
249 | } | 264 | } |
250 | 265 | ||
266 | |||
251 | void | 267 | void |
252 | destroy_member_session(struct GNUNET_MESSENGER_MemberSession* session) | 268 | destroy_member_session (struct GNUNET_MESSENGER_MemberSession *session) |
253 | { | 269 | { |
254 | GNUNET_assert (session); | 270 | GNUNET_assert (session); |
255 | 271 | ||
@@ -257,32 +273,35 @@ destroy_member_session(struct GNUNET_MESSENGER_MemberSession* session) | |||
257 | 273 | ||
258 | clear_list_messages (&(session->messages)); | 274 | clear_list_messages (&(session->messages)); |
259 | 275 | ||
260 | struct GNUNET_MESSENGER_Contact *contact = get_member_session_contact (session); | 276 | struct GNUNET_MESSENGER_Contact *contact = get_member_session_contact ( |
277 | session); | ||
261 | 278 | ||
262 | if ((contact) && (GNUNET_YES == decrease_contact_rc (contact))) | 279 | if ((contact) && (GNUNET_YES == decrease_contact_rc (contact))) |
263 | remove_store_contact ( | 280 | remove_store_contact ( |
264 | get_member_contact_store(session->member->store), | 281 | get_member_contact_store (session->member->store), |
265 | contact, | 282 | contact, |
266 | get_member_session_context(session) | 283 | get_member_session_context (session) |
267 | ); | 284 | ); |
268 | 285 | ||
269 | GNUNET_free(session); | 286 | GNUNET_free (session); |
270 | } | 287 | } |
271 | 288 | ||
289 | |||
272 | int | 290 | int |
273 | reset_member_session (struct GNUNET_MESSENGER_MemberSession* session, | 291 | reset_member_session (struct GNUNET_MESSENGER_MemberSession *session, |
274 | const struct GNUNET_HashCode *hash) | 292 | const struct GNUNET_HashCode *hash) |
275 | { | 293 | { |
276 | GNUNET_assert ((session) && (hash)); | 294 | GNUNET_assert ((session) && (hash)); |
277 | 295 | ||
278 | struct GNUNET_MESSENGER_ContactStore *store = get_member_contact_store(session->member->store); | 296 | struct GNUNET_MESSENGER_ContactStore *store = get_member_contact_store ( |
279 | struct GNUNET_MESSENGER_Contact *contact = get_store_contact( | 297 | session->member->store); |
280 | store, | 298 | struct GNUNET_MESSENGER_Contact *contact = get_store_contact ( |
281 | get_member_session_context (session), | 299 | store, |
282 | get_member_session_public_key (session) | 300 | get_member_session_context (session), |
283 | ); | 301 | get_member_session_public_key (session) |
302 | ); | ||
284 | 303 | ||
285 | if (!contact) | 304 | if (! contact) |
286 | return GNUNET_SYSERR; | 305 | return GNUNET_SYSERR; |
287 | 306 | ||
288 | if (contact == session->contact) | 307 | if (contact == session->contact) |
@@ -292,8 +311,8 @@ reset_member_session (struct GNUNET_MESSENGER_MemberSession* session, | |||
292 | increase_contact_rc (session->contact); | 311 | increase_contact_rc (session->contact); |
293 | 312 | ||
294 | clear_messages: | 313 | clear_messages: |
295 | clear_list_messages(&(session->messages)); | 314 | clear_list_messages (&(session->messages)); |
296 | add_to_list_messages(&(session->messages), hash); | 315 | add_to_list_messages (&(session->messages), hash); |
297 | 316 | ||
298 | session->next = NULL; | 317 | session->next = NULL; |
299 | session->closed = GNUNET_NO; | 318 | session->closed = GNUNET_NO; |
@@ -302,8 +321,9 @@ clear_messages: | |||
302 | return GNUNET_OK; | 321 | return GNUNET_OK; |
303 | } | 322 | } |
304 | 323 | ||
324 | |||
305 | void | 325 | void |
306 | close_member_session (struct GNUNET_MESSENGER_MemberSession* session) | 326 | close_member_session (struct GNUNET_MESSENGER_MemberSession *session) |
307 | { | 327 | { |
308 | GNUNET_assert (session); | 328 | GNUNET_assert (session); |
309 | 329 | ||
@@ -311,132 +331,158 @@ close_member_session (struct GNUNET_MESSENGER_MemberSession* session) | |||
311 | check_member_session_completion (session); | 331 | check_member_session_completion (session); |
312 | } | 332 | } |
313 | 333 | ||
334 | |||
314 | int | 335 | int |
315 | is_member_session_closed (const struct GNUNET_MESSENGER_MemberSession* session) | 336 | is_member_session_closed (const struct GNUNET_MESSENGER_MemberSession *session) |
316 | { | 337 | { |
317 | GNUNET_assert(session); | 338 | GNUNET_assert (session); |
318 | 339 | ||
319 | return session->closed; | 340 | return session->closed; |
320 | } | 341 | } |
321 | 342 | ||
343 | |||
322 | int | 344 | int |
323 | is_member_session_completed (const struct GNUNET_MESSENGER_MemberSession* session) | 345 | is_member_session_completed (const struct |
346 | GNUNET_MESSENGER_MemberSession *session) | ||
324 | { | 347 | { |
325 | GNUNET_assert(session); | 348 | GNUNET_assert (session); |
326 | 349 | ||
327 | return session->completed; | 350 | return session->completed; |
328 | } | 351 | } |
329 | 352 | ||
353 | |||
330 | struct GNUNET_TIME_Absolute | 354 | struct GNUNET_TIME_Absolute |
331 | get_member_session_start (const struct GNUNET_MESSENGER_MemberSession* session) | 355 | get_member_session_start (const struct GNUNET_MESSENGER_MemberSession *session) |
332 | { | 356 | { |
333 | GNUNET_assert(session); | 357 | GNUNET_assert (session); |
334 | 358 | ||
335 | if (session->prev) | 359 | if (session->prev) |
336 | return get_member_session_start(session->prev); | 360 | return get_member_session_start (session->prev); |
337 | 361 | ||
338 | return session->start; | 362 | return session->start; |
339 | } | 363 | } |
340 | 364 | ||
365 | |||
341 | const struct GNUNET_HashCode* | 366 | const struct GNUNET_HashCode* |
342 | get_member_session_key (const struct GNUNET_MESSENGER_MemberSession* session) | 367 | get_member_session_key (const struct GNUNET_MESSENGER_MemberSession *session) |
343 | { | 368 | { |
344 | GNUNET_assert((session) && (session->member)); | 369 | GNUNET_assert ((session) && (session->member)); |
345 | 370 | ||
346 | return get_member_store_key(session->member->store); | 371 | return get_member_store_key (session->member->store); |
347 | } | 372 | } |
348 | 373 | ||
374 | |||
349 | const struct GNUNET_ShortHashCode* | 375 | const struct GNUNET_ShortHashCode* |
350 | get_member_session_id (const struct GNUNET_MESSENGER_MemberSession* session) | 376 | get_member_session_id (const struct GNUNET_MESSENGER_MemberSession *session) |
351 | { | 377 | { |
352 | GNUNET_assert(session); | 378 | GNUNET_assert (session); |
353 | 379 | ||
354 | return get_member_id(session->member); | 380 | return get_member_id (session->member); |
355 | } | 381 | } |
356 | 382 | ||
383 | |||
357 | const struct GNUNET_IDENTITY_PublicKey* | 384 | const struct GNUNET_IDENTITY_PublicKey* |
358 | get_member_session_public_key (const struct GNUNET_MESSENGER_MemberSession* session) | 385 | get_member_session_public_key (const struct |
386 | GNUNET_MESSENGER_MemberSession *session) | ||
359 | { | 387 | { |
360 | GNUNET_assert(session); | 388 | GNUNET_assert (session); |
361 | 389 | ||
362 | return &(session->public_key); | 390 | return &(session->public_key); |
363 | } | 391 | } |
364 | 392 | ||
393 | |||
365 | const struct GNUNET_HashCode* | 394 | const struct GNUNET_HashCode* |
366 | get_member_session_context (const struct GNUNET_MESSENGER_MemberSession* session) | 395 | get_member_session_context (const struct |
396 | GNUNET_MESSENGER_MemberSession *session) | ||
367 | { | 397 | { |
368 | GNUNET_assert(session); | 398 | GNUNET_assert (session); |
369 | 399 | ||
370 | return &(session->context); | 400 | return &(session->context); |
371 | } | 401 | } |
372 | 402 | ||
403 | |||
373 | struct GNUNET_MESSENGER_Contact* | 404 | struct GNUNET_MESSENGER_Contact* |
374 | get_member_session_contact (struct GNUNET_MESSENGER_MemberSession* session) | 405 | get_member_session_contact (struct GNUNET_MESSENGER_MemberSession *session) |
375 | { | 406 | { |
376 | GNUNET_assert (session); | 407 | GNUNET_assert (session); |
377 | 408 | ||
378 | return session->contact; | 409 | return session->contact; |
379 | } | 410 | } |
380 | 411 | ||
381 | int verify_member_session_as_sender (const struct GNUNET_MESSENGER_MemberSession *session, | 412 | |
382 | const struct GNUNET_MESSENGER_Message *message, | 413 | int |
383 | const struct GNUNET_HashCode *hash) | 414 | verify_member_session_as_sender (const struct |
415 | GNUNET_MESSENGER_MemberSession *session, | ||
416 | const struct GNUNET_MESSENGER_Message *message, | ||
417 | const struct GNUNET_HashCode *hash) | ||
384 | { | 418 | { |
385 | GNUNET_assert((session) && (message) && (hash)); | 419 | GNUNET_assert ((session) && (message) && (hash)); |
386 | 420 | ||
387 | if (GNUNET_YES == is_member_session_completed (session)) | 421 | if (GNUNET_YES == is_member_session_completed (session)) |
388 | return GNUNET_SYSERR; | 422 | return GNUNET_SYSERR; |
389 | 423 | ||
390 | if (0 != GNUNET_memcmp (get_member_session_id (session), &(message->header.sender_id))) | 424 | if (0 != GNUNET_memcmp (get_member_session_id (session), |
425 | &(message->header.sender_id))) | ||
391 | return GNUNET_SYSERR; | 426 | return GNUNET_SYSERR; |
392 | 427 | ||
393 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Check message (%s) using key: %s\n", | 428 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Check message (%s) using key: %s\n", |
394 | GNUNET_h2s (hash), | 429 | GNUNET_h2s (hash), |
395 | GNUNET_IDENTITY_public_key_to_string (get_member_session_public_key (session))); | 430 | GNUNET_IDENTITY_public_key_to_string ( |
431 | get_member_session_public_key (session))); | ||
396 | 432 | ||
397 | return verify_message (message, hash, get_member_session_public_key (session)); | 433 | return verify_message (message, hash, get_member_session_public_key ( |
434 | session)); | ||
398 | } | 435 | } |
399 | 436 | ||
437 | |||
400 | int | 438 | int |
401 | check_member_session_history (const struct GNUNET_MESSENGER_MemberSession *session, | 439 | check_member_session_history (const struct |
440 | GNUNET_MESSENGER_MemberSession *session, | ||
402 | const struct GNUNET_HashCode *hash, int ownership) | 441 | const struct GNUNET_HashCode *hash, int ownership) |
403 | { | 442 | { |
404 | GNUNET_assert((session) && (hash)); | 443 | GNUNET_assert ((session) && (hash)); |
405 | 444 | ||
406 | if (GNUNET_YES == ownership) | 445 | if (GNUNET_YES == ownership) |
407 | return (NULL != GNUNET_CONTAINER_multihashmap_get(session->history, hash)? GNUNET_YES : GNUNET_NO); | 446 | return (NULL != GNUNET_CONTAINER_multihashmap_get (session->history, hash)? |
447 | GNUNET_YES : GNUNET_NO); | ||
408 | else | 448 | else |
409 | return GNUNET_CONTAINER_multihashmap_contains(session->history, hash); | 449 | return GNUNET_CONTAINER_multihashmap_contains (session->history, hash); |
410 | } | 450 | } |
411 | 451 | ||
452 | |||
412 | static void | 453 | static void |
413 | update_member_chain_history (struct GNUNET_MESSENGER_MemberSession *session, | 454 | update_member_chain_history (struct GNUNET_MESSENGER_MemberSession *session, |
414 | const struct GNUNET_HashCode *hash, int ownership) | 455 | const struct GNUNET_HashCode *hash, int ownership) |
415 | { | 456 | { |
416 | GNUNET_assert ((session) && (hash)); | 457 | GNUNET_assert ((session) && (hash)); |
417 | 458 | ||
418 | if ((GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(session->history, hash, (GNUNET_YES == ownership? session : NULL), | 459 | if ((GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (session->history, hash, |
419 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) && (session->next)) | 460 | (GNUNET_YES == ownership? |
461 | session : NULL), | ||
462 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | ||
463 | && (session->next)) | ||
420 | update_member_chain_history (session->next, hash, ownership); | 464 | update_member_chain_history (session->next, hash, ownership); |
421 | } | 465 | } |
422 | 466 | ||
467 | |||
423 | void | 468 | void |
424 | update_member_session_history (struct GNUNET_MESSENGER_MemberSession *session, | 469 | update_member_session_history (struct GNUNET_MESSENGER_MemberSession *session, |
425 | const struct GNUNET_MESSENGER_Message *message, | 470 | const struct GNUNET_MESSENGER_Message *message, |
426 | const struct GNUNET_HashCode *hash) | 471 | const struct GNUNET_HashCode *hash) |
427 | { | 472 | { |
428 | GNUNET_assert((session) && (message) && (hash)); | 473 | GNUNET_assert ((session) && (message) && (hash)); |
429 | 474 | ||
430 | if (GNUNET_YES == is_member_session_completed(session)) | 475 | if (GNUNET_YES == is_member_session_completed (session)) |
431 | return; | 476 | return; |
432 | 477 | ||
433 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Updating sessions history (%s) += (%s)\n", | 478 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
434 | GNUNET_sh2s(get_member_session_id(session)), GNUNET_h2s(hash)); | 479 | "Updating sessions history (%s) += (%s)\n", |
480 | GNUNET_sh2s (get_member_session_id (session)), GNUNET_h2s (hash)); | ||
435 | 481 | ||
436 | if (GNUNET_OK == verify_member_session_as_sender (session, message, hash)) | 482 | if (GNUNET_OK == verify_member_session_as_sender (session, message, hash)) |
437 | { | 483 | { |
438 | if (GNUNET_YES == is_message_session_bound (message)) | 484 | if (GNUNET_YES == is_message_session_bound (message)) |
439 | add_to_list_messages(&(session->messages), hash); | 485 | add_to_list_messages (&(session->messages), hash); |
440 | 486 | ||
441 | update_member_chain_history (session, hash, GNUNET_YES); | 487 | update_member_chain_history (session, hash, GNUNET_YES); |
442 | } | 488 | } |
@@ -444,28 +490,32 @@ update_member_session_history (struct GNUNET_MESSENGER_MemberSession *session, | |||
444 | update_member_chain_history (session, hash, GNUNET_NO); | 490 | update_member_chain_history (session, hash, GNUNET_NO); |
445 | 491 | ||
446 | if (GNUNET_YES == session->closed) | 492 | if (GNUNET_YES == session->closed) |
447 | check_member_session_completion(session); | 493 | check_member_session_completion (session); |
448 | } | 494 | } |
449 | 495 | ||
496 | |||
450 | static void | 497 | static void |
451 | clear_member_chain_history (struct GNUNET_MESSENGER_MemberSession *session, | 498 | clear_member_chain_history (struct GNUNET_MESSENGER_MemberSession *session, |
452 | const struct GNUNET_HashCode *hash) | 499 | const struct GNUNET_HashCode *hash) |
453 | { | 500 | { |
454 | GNUNET_assert ((session) && (hash)); | 501 | GNUNET_assert ((session) && (hash)); |
455 | 502 | ||
456 | if ((0 < GNUNET_CONTAINER_multihashmap_remove_all(session->history, hash)) && (session->next)) | 503 | if ((0 < GNUNET_CONTAINER_multihashmap_remove_all (session->history, hash)) && |
457 | clear_member_session_history(session->next, hash); | 504 | (session->next)) |
505 | clear_member_session_history (session->next, hash); | ||
458 | } | 506 | } |
459 | 507 | ||
508 | |||
460 | void | 509 | void |
461 | clear_member_session_history (struct GNUNET_MESSENGER_MemberSession *session, | 510 | clear_member_session_history (struct GNUNET_MESSENGER_MemberSession *session, |
462 | const struct GNUNET_HashCode *hash) | 511 | const struct GNUNET_HashCode *hash) |
463 | { | 512 | { |
464 | GNUNET_assert((session) && (hash)); | 513 | GNUNET_assert ((session) && (hash)); |
465 | 514 | ||
466 | clear_member_chain_history (session, hash); | 515 | clear_member_chain_history (session, hash); |
467 | } | 516 | } |
468 | 517 | ||
518 | |||
469 | struct GNUNET_MESSENGER_MemberSessionHistoryEntry | 519 | struct GNUNET_MESSENGER_MemberSessionHistoryEntry |
470 | { | 520 | { |
471 | struct GNUNET_HashCode hash; | 521 | struct GNUNET_HashCode hash; |
@@ -476,21 +526,22 @@ static void | |||
476 | load_member_session_history (struct GNUNET_MESSENGER_MemberSession *session, | 526 | load_member_session_history (struct GNUNET_MESSENGER_MemberSession *session, |
477 | const char *path) | 527 | const char *path) |
478 | { | 528 | { |
479 | GNUNET_assert((session) && (path)); | 529 | GNUNET_assert ((session) && (path)); |
480 | 530 | ||
481 | if (GNUNET_YES != GNUNET_DISK_file_test (path)) | 531 | if (GNUNET_YES != GNUNET_DISK_file_test (path)) |
482 | return; | 532 | return; |
483 | 533 | ||
484 | enum GNUNET_DISK_AccessPermissions permission = (GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); | 534 | enum GNUNET_DISK_AccessPermissions permission = (GNUNET_DISK_PERM_USER_READ |
535 | | GNUNET_DISK_PERM_USER_WRITE); | ||
485 | 536 | ||
486 | struct GNUNET_DISK_FileHandle *handle = GNUNET_DISK_file_open( | 537 | struct GNUNET_DISK_FileHandle *handle = GNUNET_DISK_file_open ( |
487 | path, GNUNET_DISK_OPEN_READ, permission | 538 | path, GNUNET_DISK_OPEN_READ, permission |
488 | ); | 539 | ); |
489 | 540 | ||
490 | if (!handle) | 541 | if (! handle) |
491 | return; | 542 | return; |
492 | 543 | ||
493 | GNUNET_DISK_file_seek(handle, 0, GNUNET_DISK_SEEK_SET); | 544 | GNUNET_DISK_file_seek (handle, 0, GNUNET_DISK_SEEK_SET); |
494 | 545 | ||
495 | struct GNUNET_MESSENGER_MemberSessionHistoryEntry entry; | 546 | struct GNUNET_MESSENGER_MemberSessionHistoryEntry entry; |
496 | ssize_t len; | 547 | ssize_t len; |
@@ -498,23 +549,27 @@ load_member_session_history (struct GNUNET_MESSENGER_MemberSession *session, | |||
498 | int status; | 549 | int status; |
499 | 550 | ||
500 | do { | 551 | do { |
501 | len = GNUNET_DISK_file_read(handle, &(entry.hash), sizeof(entry.hash)); | 552 | len = GNUNET_DISK_file_read (handle, &(entry.hash), sizeof(entry.hash)); |
502 | 553 | ||
503 | if (len != sizeof(entry.hash)) | 554 | if (len != sizeof(entry.hash)) |
504 | break; | 555 | break; |
505 | 556 | ||
506 | len = GNUNET_DISK_file_read(handle, &(entry.ownership), sizeof(entry.ownership)); | 557 | len = GNUNET_DISK_file_read (handle, &(entry.ownership), |
558 | sizeof(entry.ownership)); | ||
507 | 559 | ||
508 | if (len != sizeof(entry.ownership)) | 560 | if (len != sizeof(entry.ownership)) |
509 | break; | 561 | break; |
510 | 562 | ||
511 | status = GNUNET_CONTAINER_multihashmap_put(session->history, &(entry.hash), (entry.ownership? session : NULL), | 563 | status = GNUNET_CONTAINER_multihashmap_put (session->history, &(entry.hash), |
512 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 564 | (entry.ownership? session : |
565 | NULL), | ||
566 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | ||
513 | } while (status == GNUNET_OK); | 567 | } while (status == GNUNET_OK); |
514 | 568 | ||
515 | GNUNET_DISK_file_close(handle); | 569 | GNUNET_DISK_file_close (handle); |
516 | } | 570 | } |
517 | 571 | ||
572 | |||
518 | void | 573 | void |
519 | load_member_session (struct GNUNET_MESSENGER_Member *member, | 574 | load_member_session (struct GNUNET_MESSENGER_Member *member, |
520 | const char *directory) | 575 | const char *directory) |
@@ -529,7 +584,8 @@ load_member_session (struct GNUNET_MESSENGER_Member *member, | |||
529 | if (GNUNET_YES != GNUNET_DISK_file_test (config_file)) | 584 | if (GNUNET_YES != GNUNET_DISK_file_test (config_file)) |
530 | goto free_config; | 585 | goto free_config; |
531 | 586 | ||
532 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Load session configuration of member: %s\n", config_file); | 587 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
588 | "Load session configuration of member: %s\n", config_file); | ||
533 | 589 | ||
534 | struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create (); | 590 | struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create (); |
535 | 591 | ||
@@ -537,61 +593,71 @@ load_member_session (struct GNUNET_MESSENGER_Member *member, | |||
537 | { | 593 | { |
538 | char *key_data; | 594 | char *key_data; |
539 | 595 | ||
540 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, "session", "key", &key_data)) | 596 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "session", |
597 | "key", &key_data)) | ||
541 | goto destroy_config; | 598 | goto destroy_config; |
542 | 599 | ||
543 | struct GNUNET_IDENTITY_PublicKey key; | 600 | struct GNUNET_IDENTITY_PublicKey key; |
544 | 601 | ||
545 | enum GNUNET_GenericReturnValue key_return = GNUNET_IDENTITY_public_key_from_string(key_data, &key); | 602 | enum GNUNET_GenericReturnValue key_return = |
603 | GNUNET_IDENTITY_public_key_from_string (key_data, &key); | ||
546 | 604 | ||
547 | GNUNET_free(key_data); | 605 | GNUNET_free (key_data); |
548 | 606 | ||
549 | if (GNUNET_OK != key_return) | 607 | if (GNUNET_OK != key_return) |
550 | goto destroy_config; | 608 | goto destroy_config; |
551 | 609 | ||
552 | session = create_member_session(member, &key); | 610 | session = create_member_session (member, &key); |
553 | 611 | ||
554 | unsigned long long numeric_value; | 612 | unsigned long long numeric_value; |
555 | 613 | ||
556 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, "session", "start", &numeric_value)) | 614 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "session", |
615 | "start", | ||
616 | &numeric_value)) | ||
557 | session->start.abs_value_us = numeric_value; | 617 | session->start.abs_value_us = numeric_value; |
558 | 618 | ||
559 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, "session", "closed", &numeric_value)) | 619 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "session", |
620 | "closed", | ||
621 | &numeric_value)) | ||
560 | session->closed = (GNUNET_YES == numeric_value? GNUNET_YES : GNUNET_NO); | 622 | session->closed = (GNUNET_YES == numeric_value? GNUNET_YES : GNUNET_NO); |
561 | 623 | ||
562 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, "session", "completed", &numeric_value)) | 624 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "session", |
563 | session->completed = (GNUNET_YES == numeric_value? GNUNET_YES : GNUNET_NO); | 625 | "completed", |
626 | &numeric_value)) | ||
627 | session->completed = (GNUNET_YES == numeric_value? GNUNET_YES : | ||
628 | GNUNET_NO); | ||
564 | } | 629 | } |
565 | 630 | ||
566 | destroy_config: | 631 | destroy_config: |
567 | GNUNET_CONFIGURATION_destroy (cfg); | 632 | GNUNET_CONFIGURATION_destroy (cfg); |
568 | 633 | ||
569 | free_config: | 634 | free_config: |
570 | GNUNET_free(config_file); | 635 | GNUNET_free (config_file); |
571 | 636 | ||
572 | if (!session) | 637 | if (! session) |
573 | return; | 638 | return; |
574 | 639 | ||
575 | char *history_file; | 640 | char *history_file; |
576 | GNUNET_asprintf (&history_file, "%s%s", directory, "history.map"); | 641 | GNUNET_asprintf (&history_file, "%s%s", directory, "history.map"); |
577 | 642 | ||
578 | load_member_session_history (session, history_file); | 643 | load_member_session_history (session, history_file); |
579 | GNUNET_free(history_file); | 644 | GNUNET_free (history_file); |
580 | 645 | ||
581 | char *messages_file; | 646 | char *messages_file; |
582 | GNUNET_asprintf (&messages_file, "%s%s", directory, "messages.list"); | 647 | GNUNET_asprintf (&messages_file, "%s%s", directory, "messages.list"); |
583 | 648 | ||
584 | load_list_messages(&(session->messages), messages_file); | 649 | load_list_messages (&(session->messages), messages_file); |
585 | GNUNET_free(messages_file); | 650 | GNUNET_free (messages_file); |
586 | 651 | ||
587 | add_member_session(member, session); | 652 | add_member_session (member, session); |
588 | } | 653 | } |
589 | 654 | ||
655 | |||
590 | static struct GNUNET_MESSENGER_MemberSession* | 656 | static struct GNUNET_MESSENGER_MemberSession* |
591 | get_cycle_safe_next_session (struct GNUNET_MESSENGER_MemberSession *session, | 657 | get_cycle_safe_next_session (struct GNUNET_MESSENGER_MemberSession *session, |
592 | struct GNUNET_MESSENGER_MemberSession *next) | 658 | struct GNUNET_MESSENGER_MemberSession *next) |
593 | { | 659 | { |
594 | if (!next) | 660 | if (! next) |
595 | return NULL; | 661 | return NULL; |
596 | 662 | ||
597 | struct GNUNET_MESSENGER_MemberSession *check = next; | 663 | struct GNUNET_MESSENGER_MemberSession *check = next; |
@@ -606,6 +672,7 @@ get_cycle_safe_next_session (struct GNUNET_MESSENGER_MemberSession *session, | |||
606 | return next; | 672 | return next; |
607 | } | 673 | } |
608 | 674 | ||
675 | |||
609 | void | 676 | void |
610 | load_member_session_next (struct GNUNET_MESSENGER_MemberSession *session, | 677 | load_member_session_next (struct GNUNET_MESSENGER_MemberSession *session, |
611 | const char *directory) | 678 | const char *directory) |
@@ -618,7 +685,8 @@ load_member_session_next (struct GNUNET_MESSENGER_MemberSession *session, | |||
618 | if (GNUNET_YES != GNUNET_DISK_file_test (config_file)) | 685 | if (GNUNET_YES != GNUNET_DISK_file_test (config_file)) |
619 | goto free_config; | 686 | goto free_config; |
620 | 687 | ||
621 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Load next session configuration of member: %s\n", config_file); | 688 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
689 | "Load next session configuration of member: %s\n", config_file); | ||
622 | 690 | ||
623 | struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create (); | 691 | struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create (); |
624 | 692 | ||
@@ -626,28 +694,33 @@ load_member_session_next (struct GNUNET_MESSENGER_MemberSession *session, | |||
626 | { | 694 | { |
627 | char *key_data; | 695 | char *key_data; |
628 | 696 | ||
629 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, "session", "next_key", &key_data)) | 697 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "session", |
698 | "next_key", | ||
699 | &key_data)) | ||
630 | goto destroy_config; | 700 | goto destroy_config; |
631 | 701 | ||
632 | struct GNUNET_IDENTITY_PublicKey next_key; | 702 | struct GNUNET_IDENTITY_PublicKey next_key; |
633 | 703 | ||
634 | enum GNUNET_GenericReturnValue key_return = GNUNET_IDENTITY_public_key_from_string(key_data, &next_key); | 704 | enum GNUNET_GenericReturnValue key_return = |
705 | GNUNET_IDENTITY_public_key_from_string (key_data, &next_key); | ||
635 | 706 | ||
636 | GNUNET_free(key_data); | 707 | GNUNET_free (key_data); |
637 | 708 | ||
638 | if (GNUNET_OK != key_return) | 709 | if (GNUNET_OK != key_return) |
639 | goto destroy_config; | 710 | goto destroy_config; |
640 | 711 | ||
641 | struct GNUNET_ShortHashCode next_id; | 712 | struct GNUNET_ShortHashCode next_id; |
642 | 713 | ||
643 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_data (cfg, "session", "next_id", &next_id, sizeof(next_id))) | 714 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_data (cfg, "session", "next_id", |
715 | &next_id, sizeof(next_id))) | ||
644 | goto destroy_config; | 716 | goto destroy_config; |
645 | 717 | ||
646 | struct GNUNET_MESSENGER_Member *member = get_store_member(session->member->store, &next_id); | 718 | struct GNUNET_MESSENGER_Member *member = get_store_member ( |
719 | session->member->store, &next_id); | ||
647 | 720 | ||
648 | session->next = get_cycle_safe_next_session( | 721 | session->next = get_cycle_safe_next_session ( |
649 | session, member? get_member_session (member, &next_key) : NULL | 722 | session, member? get_member_session (member, &next_key) : NULL |
650 | ); | 723 | ); |
651 | 724 | ||
652 | if (session->next) | 725 | if (session->next) |
653 | session->next->prev = session; | 726 | session->next->prev = session; |
@@ -657,9 +730,10 @@ destroy_config: | |||
657 | GNUNET_CONFIGURATION_destroy (cfg); | 730 | GNUNET_CONFIGURATION_destroy (cfg); |
658 | 731 | ||
659 | free_config: | 732 | free_config: |
660 | GNUNET_free(config_file); | 733 | GNUNET_free (config_file); |
661 | } | 734 | } |
662 | 735 | ||
736 | |||
663 | static int | 737 | static int |
664 | iterate_save_member_session_history_hentries (void *cls, | 738 | iterate_save_member_session_history_hentries (void *cls, |
665 | const struct GNUNET_HashCode *key, | 739 | const struct GNUNET_HashCode *key, |
@@ -668,39 +742,42 @@ iterate_save_member_session_history_hentries (void *cls, | |||
668 | struct GNUNET_DISK_FileHandle *handle = cls; | 742 | struct GNUNET_DISK_FileHandle *handle = cls; |
669 | unsigned char ownership = value? GNUNET_YES : GNUNET_NO; | 743 | unsigned char ownership = value? GNUNET_YES : GNUNET_NO; |
670 | 744 | ||
671 | GNUNET_DISK_file_write(handle, key, sizeof(*key)); | 745 | GNUNET_DISK_file_write (handle, key, sizeof(*key)); |
672 | GNUNET_DISK_file_write(handle, &ownership, sizeof(ownership)); | 746 | GNUNET_DISK_file_write (handle, &ownership, sizeof(ownership)); |
673 | 747 | ||
674 | return GNUNET_YES; | 748 | return GNUNET_YES; |
675 | } | 749 | } |
676 | 750 | ||
751 | |||
677 | static void | 752 | static void |
678 | save_member_session_history (struct GNUNET_MESSENGER_MemberSession *session, | 753 | save_member_session_history (struct GNUNET_MESSENGER_MemberSession *session, |
679 | const char *path) | 754 | const char *path) |
680 | { | 755 | { |
681 | GNUNET_assert((session) && (path)); | 756 | GNUNET_assert ((session) && (path)); |
682 | 757 | ||
683 | enum GNUNET_DISK_AccessPermissions permission = (GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); | 758 | enum GNUNET_DISK_AccessPermissions permission = (GNUNET_DISK_PERM_USER_READ |
759 | | GNUNET_DISK_PERM_USER_WRITE); | ||
684 | 760 | ||
685 | struct GNUNET_DISK_FileHandle *handle = GNUNET_DISK_file_open( | 761 | struct GNUNET_DISK_FileHandle *handle = GNUNET_DISK_file_open ( |
686 | path, GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_WRITE, permission | 762 | path, GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_WRITE, permission |
687 | ); | 763 | ); |
688 | 764 | ||
689 | if (!handle) | 765 | if (! handle) |
690 | return; | 766 | return; |
691 | 767 | ||
692 | GNUNET_DISK_file_seek(handle, 0, GNUNET_DISK_SEEK_SET); | 768 | GNUNET_DISK_file_seek (handle, 0, GNUNET_DISK_SEEK_SET); |
693 | 769 | ||
694 | GNUNET_CONTAINER_multihashmap_iterate( | 770 | GNUNET_CONTAINER_multihashmap_iterate ( |
695 | session->history, | 771 | session->history, |
696 | iterate_save_member_session_history_hentries, | 772 | iterate_save_member_session_history_hentries, |
697 | handle | 773 | handle |
698 | ); | 774 | ); |
699 | 775 | ||
700 | GNUNET_DISK_file_sync(handle); | 776 | GNUNET_DISK_file_sync (handle); |
701 | GNUNET_DISK_file_close(handle); | 777 | GNUNET_DISK_file_close (handle); |
702 | } | 778 | } |
703 | 779 | ||
780 | |||
704 | void | 781 | void |
705 | save_member_session (struct GNUNET_MESSENGER_MemberSession *session, | 782 | save_member_session (struct GNUNET_MESSENGER_MemberSession *session, |
706 | const char *directory) | 783 | const char *directory) |
@@ -710,61 +787,71 @@ save_member_session (struct GNUNET_MESSENGER_MemberSession *session, | |||
710 | char *config_file; | 787 | char *config_file; |
711 | GNUNET_asprintf (&config_file, "%s%s", directory, "session.cfg"); | 788 | GNUNET_asprintf (&config_file, "%s%s", directory, "session.cfg"); |
712 | 789 | ||
713 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Save session configuration of member: %s\n", config_file); | 790 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
791 | "Save session configuration of member: %s\n", config_file); | ||
714 | 792 | ||
715 | struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create (); | 793 | struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create (); |
716 | 794 | ||
717 | char *key_data = GNUNET_IDENTITY_public_key_to_string(get_member_session_public_key(session)); | 795 | char *key_data = GNUNET_IDENTITY_public_key_to_string ( |
796 | get_member_session_public_key (session)); | ||
718 | 797 | ||
719 | if (key_data) | 798 | if (key_data) |
720 | { | 799 | { |
721 | GNUNET_CONFIGURATION_set_value_string (cfg, "session", "key", key_data); | 800 | GNUNET_CONFIGURATION_set_value_string (cfg, "session", "key", key_data); |
722 | 801 | ||
723 | GNUNET_free(key_data); | 802 | GNUNET_free (key_data); |
724 | } | 803 | } |
725 | 804 | ||
726 | if (session->next) | 805 | if (session->next) |
727 | { | 806 | { |
728 | const struct GNUNET_ShortHashCode *next_id = get_member_session_id(session->next); | 807 | const struct GNUNET_ShortHashCode *next_id = get_member_session_id ( |
808 | session->next); | ||
729 | 809 | ||
730 | char *next_id_data = GNUNET_STRINGS_data_to_string_alloc (next_id, sizeof(*next_id)); | 810 | char *next_id_data = GNUNET_STRINGS_data_to_string_alloc (next_id, |
811 | sizeof(*next_id)); | ||
731 | 812 | ||
732 | if (next_id_data) | 813 | if (next_id_data) |
733 | { | 814 | { |
734 | GNUNET_CONFIGURATION_set_value_string (cfg, "session", "next_id", next_id_data); | 815 | GNUNET_CONFIGURATION_set_value_string (cfg, "session", "next_id", |
816 | next_id_data); | ||
735 | 817 | ||
736 | GNUNET_free(next_id_data); | 818 | GNUNET_free (next_id_data); |
737 | } | 819 | } |
738 | 820 | ||
739 | key_data = GNUNET_IDENTITY_public_key_to_string(get_member_session_public_key(session->next)); | 821 | key_data = GNUNET_IDENTITY_public_key_to_string ( |
822 | get_member_session_public_key (session->next)); | ||
740 | 823 | ||
741 | if (key_data) | 824 | if (key_data) |
742 | { | 825 | { |
743 | GNUNET_CONFIGURATION_set_value_string (cfg, "session", "next_key", key_data); | 826 | GNUNET_CONFIGURATION_set_value_string (cfg, "session", "next_key", |
827 | key_data); | ||
744 | 828 | ||
745 | GNUNET_free(key_data); | 829 | GNUNET_free (key_data); |
746 | } | 830 | } |
747 | } | 831 | } |
748 | 832 | ||
749 | GNUNET_CONFIGURATION_set_value_number(cfg, "session", "start", session->start.abs_value_us); | 833 | GNUNET_CONFIGURATION_set_value_number (cfg, "session", "start", |
834 | session->start.abs_value_us); | ||
750 | 835 | ||
751 | GNUNET_CONFIGURATION_set_value_number (cfg, "session", "closed", session->closed); | 836 | GNUNET_CONFIGURATION_set_value_number (cfg, "session", "closed", |
752 | GNUNET_CONFIGURATION_set_value_number (cfg, "session", "completed", session->completed); | 837 | session->closed); |
838 | GNUNET_CONFIGURATION_set_value_number (cfg, "session", "completed", | ||
839 | session->completed); | ||
753 | 840 | ||
754 | GNUNET_CONFIGURATION_write (cfg, config_file); | 841 | GNUNET_CONFIGURATION_write (cfg, config_file); |
755 | GNUNET_CONFIGURATION_destroy (cfg); | 842 | GNUNET_CONFIGURATION_destroy (cfg); |
756 | 843 | ||
757 | GNUNET_free(config_file); | 844 | GNUNET_free (config_file); |
758 | 845 | ||
759 | char *history_file; | 846 | char *history_file; |
760 | GNUNET_asprintf (&history_file, "%s%s", directory, "history.map"); | 847 | GNUNET_asprintf (&history_file, "%s%s", directory, "history.map"); |
761 | 848 | ||
762 | save_member_session_history (session, history_file); | 849 | save_member_session_history (session, history_file); |
763 | GNUNET_free(history_file); | 850 | GNUNET_free (history_file); |
764 | 851 | ||
765 | char *messages_file; | 852 | char *messages_file; |
766 | GNUNET_asprintf (&messages_file, "%s%s", directory, "messages.list"); | 853 | GNUNET_asprintf (&messages_file, "%s%s", directory, "messages.list"); |
767 | 854 | ||
768 | save_list_messages(&(session->messages), messages_file); | 855 | save_list_messages (&(session->messages), messages_file); |
769 | GNUNET_free(messages_file); | 856 | GNUNET_free (messages_file); |
770 | } | 857 | } |
diff --git a/src/messenger/gnunet-service-messenger_member_session.h b/src/messenger/gnunet-service-messenger_member_session.h index 9b4065d05..8a4143058 100644 --- a/src/messenger/gnunet-service-messenger_member_session.h +++ b/src/messenger/gnunet-service-messenger_member_session.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2021 GNUnet e.V. | 3 | Copyright (C) 2021, 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 |
@@ -35,7 +35,8 @@ | |||
35 | 35 | ||
36 | #include "messenger_api_contact.h" | 36 | #include "messenger_api_contact.h" |
37 | 37 | ||
38 | struct GNUNET_MESSENGER_MemberSession { | 38 | struct GNUNET_MESSENGER_MemberSession |
39 | { | ||
39 | struct GNUNET_MESSENGER_Member *member; | 40 | struct GNUNET_MESSENGER_Member *member; |
40 | 41 | ||
41 | struct GNUNET_IDENTITY_PublicKey public_key; | 42 | struct GNUNET_IDENTITY_PublicKey public_key; |
@@ -46,8 +47,8 @@ struct GNUNET_MESSENGER_MemberSession { | |||
46 | struct GNUNET_CONTAINER_MultiHashMap *history; | 47 | struct GNUNET_CONTAINER_MultiHashMap *history; |
47 | struct GNUNET_MESSENGER_ListMessages messages; | 48 | struct GNUNET_MESSENGER_ListMessages messages; |
48 | 49 | ||
49 | struct GNUNET_MESSENGER_MemberSession* prev; | 50 | struct GNUNET_MESSENGER_MemberSession *prev; |
50 | struct GNUNET_MESSENGER_MemberSession* next; | 51 | struct GNUNET_MESSENGER_MemberSession *next; |
51 | 52 | ||
52 | struct GNUNET_TIME_Absolute start; | 53 | struct GNUNET_TIME_Absolute start; |
53 | 54 | ||
@@ -92,7 +93,7 @@ switch_member_session (struct GNUNET_MESSENGER_MemberSession *session, | |||
92 | * @param[in,out] session Member session | 93 | * @param[in,out] session Member session |
93 | */ | 94 | */ |
94 | void | 95 | void |
95 | destroy_member_session(struct GNUNET_MESSENGER_MemberSession* session); | 96 | destroy_member_session (struct GNUNET_MESSENGER_MemberSession *session); |
96 | 97 | ||
97 | /** | 98 | /** |
98 | * Resets a given member <i>session</i> which re-opens a member | 99 | * Resets a given member <i>session</i> which re-opens a member |
@@ -105,7 +106,7 @@ destroy_member_session(struct GNUNET_MESSENGER_MemberSession* session); | |||
105 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | 106 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
106 | */ | 107 | */ |
107 | int | 108 | int |
108 | reset_member_session (struct GNUNET_MESSENGER_MemberSession* session, | 109 | reset_member_session (struct GNUNET_MESSENGER_MemberSession *session, |
109 | const struct GNUNET_HashCode *hash); | 110 | const struct GNUNET_HashCode *hash); |
110 | 111 | ||
111 | /** | 112 | /** |
@@ -118,7 +119,7 @@ reset_member_session (struct GNUNET_MESSENGER_MemberSession* session, | |||
118 | * @param[in,out] session Member session | 119 | * @param[in,out] session Member session |
119 | */ | 120 | */ |
120 | void | 121 | void |
121 | close_member_session (struct GNUNET_MESSENGER_MemberSession* session); | 122 | close_member_session (struct GNUNET_MESSENGER_MemberSession *session); |
122 | 123 | ||
123 | /** | 124 | /** |
124 | * Returns if the given member <i>session</i> has been closed. | 125 | * Returns if the given member <i>session</i> has been closed. |
@@ -127,7 +128,7 @@ close_member_session (struct GNUNET_MESSENGER_MemberSession* session); | |||
127 | * @return #GNUNET_YES or #GNUNET_NO | 128 | * @return #GNUNET_YES or #GNUNET_NO |
128 | */ | 129 | */ |
129 | int | 130 | int |
130 | is_member_session_closed (const struct GNUNET_MESSENGER_MemberSession* session); | 131 | is_member_session_closed (const struct GNUNET_MESSENGER_MemberSession *session); |
131 | 132 | ||
132 | /** | 133 | /** |
133 | * Returns if the given member <i>session</i> has been completed. | 134 | * Returns if the given member <i>session</i> has been completed. |
@@ -139,7 +140,8 @@ is_member_session_closed (const struct GNUNET_MESSENGER_MemberSession* session); | |||
139 | * @return #GNUNET_YES or #GNUNET_NO | 140 | * @return #GNUNET_YES or #GNUNET_NO |
140 | */ | 141 | */ |
141 | int | 142 | int |
142 | is_member_session_completed (const struct GNUNET_MESSENGER_MemberSession* session); | 143 | is_member_session_completed (const struct |
144 | GNUNET_MESSENGER_MemberSession *session); | ||
143 | 145 | ||
144 | /** | 146 | /** |
145 | * Returns the timestamp of the member <i>session</i>'s start. | 147 | * Returns the timestamp of the member <i>session</i>'s start. |
@@ -148,7 +150,7 @@ is_member_session_completed (const struct GNUNET_MESSENGER_MemberSession* sessio | |||
148 | * @return Absolute timestamp | 150 | * @return Absolute timestamp |
149 | */ | 151 | */ |
150 | struct GNUNET_TIME_Absolute | 152 | struct GNUNET_TIME_Absolute |
151 | get_member_session_start (const struct GNUNET_MESSENGER_MemberSession* session); | 153 | get_member_session_start (const struct GNUNET_MESSENGER_MemberSession *session); |
152 | 154 | ||
153 | /** | 155 | /** |
154 | * Returns the key of the room a given member <i>session</i> belongs to. | 156 | * Returns the key of the room a given member <i>session</i> belongs to. |
@@ -157,7 +159,7 @@ get_member_session_start (const struct GNUNET_MESSENGER_MemberSession* session); | |||
157 | * @return Key of room | 159 | * @return Key of room |
158 | */ | 160 | */ |
159 | const struct GNUNET_HashCode* | 161 | const struct GNUNET_HashCode* |
160 | get_member_session_key (const struct GNUNET_MESSENGER_MemberSession* session); | 162 | get_member_session_key (const struct GNUNET_MESSENGER_MemberSession *session); |
161 | 163 | ||
162 | /** | 164 | /** |
163 | * Returns the member id of a given member <i>session</i>. | 165 | * Returns the member id of a given member <i>session</i>. |
@@ -166,7 +168,7 @@ get_member_session_key (const struct GNUNET_MESSENGER_MemberSession* session); | |||
166 | * @return Member id | 168 | * @return Member id |
167 | */ | 169 | */ |
168 | const struct GNUNET_ShortHashCode* | 170 | const struct GNUNET_ShortHashCode* |
169 | get_member_session_id (const struct GNUNET_MESSENGER_MemberSession* session); | 171 | get_member_session_id (const struct GNUNET_MESSENGER_MemberSession *session); |
170 | 172 | ||
171 | /** | 173 | /** |
172 | * Returns the public key from an EGO of a given member <i>session</i>. | 174 | * Returns the public key from an EGO of a given member <i>session</i>. |
@@ -175,7 +177,8 @@ get_member_session_id (const struct GNUNET_MESSENGER_MemberSession* session); | |||
175 | * @return Public key of EGO | 177 | * @return Public key of EGO |
176 | */ | 178 | */ |
177 | const struct GNUNET_IDENTITY_PublicKey* | 179 | const struct GNUNET_IDENTITY_PublicKey* |
178 | get_member_session_public_key (const struct GNUNET_MESSENGER_MemberSession* session); | 180 | get_member_session_public_key (const struct |
181 | GNUNET_MESSENGER_MemberSession *session); | ||
179 | 182 | ||
180 | /** | 183 | /** |
181 | * Returns the member context of a given member <i>session</i>. | 184 | * Returns the member context of a given member <i>session</i>. |
@@ -184,7 +187,8 @@ get_member_session_public_key (const struct GNUNET_MESSENGER_MemberSession* sess | |||
184 | * @return Member context as hash | 187 | * @return Member context as hash |
185 | */ | 188 | */ |
186 | const struct GNUNET_HashCode* | 189 | const struct GNUNET_HashCode* |
187 | get_member_session_context (const struct GNUNET_MESSENGER_MemberSession* session); | 190 | get_member_session_context (const struct |
191 | GNUNET_MESSENGER_MemberSession *session); | ||
188 | 192 | ||
189 | /** | 193 | /** |
190 | * Returns the contact which is connected to a given member <i>session</i>. | 194 | * Returns the contact which is connected to a given member <i>session</i>. |
@@ -193,7 +197,7 @@ get_member_session_context (const struct GNUNET_MESSENGER_MemberSession* session | |||
193 | * @return Contact | 197 | * @return Contact |
194 | */ | 198 | */ |
195 | struct GNUNET_MESSENGER_Contact* | 199 | struct GNUNET_MESSENGER_Contact* |
196 | get_member_session_contact (struct GNUNET_MESSENGER_MemberSession* session); | 200 | get_member_session_contact (struct GNUNET_MESSENGER_MemberSession *session); |
197 | 201 | ||
198 | /** | 202 | /** |
199 | * Verifies a given member <i>session</i> as sender of a selected <i>message</i> and | 203 | * Verifies a given member <i>session</i> as sender of a selected <i>message</i> and |
@@ -208,7 +212,8 @@ get_member_session_contact (struct GNUNET_MESSENGER_MemberSession* session); | |||
208 | * @return #GNUNET_OK on success, otherwise #GNUNET_SYSERR | 212 | * @return #GNUNET_OK on success, otherwise #GNUNET_SYSERR |
209 | */ | 213 | */ |
210 | int | 214 | int |
211 | verify_member_session_as_sender (const struct GNUNET_MESSENGER_MemberSession *session, | 215 | verify_member_session_as_sender (const struct |
216 | GNUNET_MESSENGER_MemberSession *session, | ||
212 | const struct GNUNET_MESSENGER_Message *message, | 217 | const struct GNUNET_MESSENGER_Message *message, |
213 | const struct GNUNET_HashCode *hash); | 218 | const struct GNUNET_HashCode *hash); |
214 | 219 | ||
@@ -223,7 +228,8 @@ verify_member_session_as_sender (const struct GNUNET_MESSENGER_MemberSession *se | |||
223 | * @return #GNUNET_YES if found, otherwise #GNUNET_NO | 228 | * @return #GNUNET_YES if found, otherwise #GNUNET_NO |
224 | */ | 229 | */ |
225 | int | 230 | int |
226 | check_member_session_history (const struct GNUNET_MESSENGER_MemberSession *session, | 231 | check_member_session_history (const struct |
232 | GNUNET_MESSENGER_MemberSession *session, | ||
227 | const struct GNUNET_HashCode *hash, | 233 | const struct GNUNET_HashCode *hash, |
228 | int ownership); | 234 | int ownership); |
229 | 235 | ||
diff --git a/src/messenger/gnunet-service-messenger_member_store.c b/src/messenger/gnunet-service-messenger_member_store.c index 8b2bd7ac8..e7876b382 100644 --- a/src/messenger/gnunet-service-messenger_member_store.c +++ b/src/messenger/gnunet-service-messenger_member_store.c | |||
@@ -37,25 +37,28 @@ init_member_store (struct GNUNET_MESSENGER_MemberStore *store, | |||
37 | GNUNET_assert ((store) && (room)); | 37 | GNUNET_assert ((store) && (room)); |
38 | 38 | ||
39 | store->room = room; | 39 | store->room = room; |
40 | store->members = GNUNET_CONTAINER_multishortmap_create(8, GNUNET_NO); | 40 | store->members = GNUNET_CONTAINER_multishortmap_create (8, GNUNET_NO); |
41 | } | 41 | } |
42 | 42 | ||
43 | |||
43 | static int | 44 | static int |
44 | iterate_destroy_members (void *cls, | 45 | iterate_destroy_members (void *cls, |
45 | const struct GNUNET_ShortHashCode *key, | 46 | const struct GNUNET_ShortHashCode *key, |
46 | void *value) | 47 | void *value) |
47 | { | 48 | { |
48 | struct GNUNET_MESSENGER_Member *member = value; | 49 | struct GNUNET_MESSENGER_Member *member = value; |
49 | destroy_member(member); | 50 | destroy_member (member); |
50 | return GNUNET_YES; | 51 | return GNUNET_YES; |
51 | } | 52 | } |
52 | 53 | ||
54 | |||
53 | void | 55 | void |
54 | clear_member_store (struct GNUNET_MESSENGER_MemberStore *store) | 56 | clear_member_store (struct GNUNET_MESSENGER_MemberStore *store) |
55 | { | 57 | { |
56 | GNUNET_assert ((store) && (store->members)); | 58 | GNUNET_assert ((store) && (store->members)); |
57 | 59 | ||
58 | GNUNET_CONTAINER_multishortmap_iterate (store->members, iterate_destroy_members, NULL); | 60 | GNUNET_CONTAINER_multishortmap_iterate (store->members, |
61 | iterate_destroy_members, NULL); | ||
59 | GNUNET_CONTAINER_multishortmap_destroy (store->members); | 62 | GNUNET_CONTAINER_multishortmap_destroy (store->members); |
60 | } | 63 | } |
61 | 64 | ||
@@ -67,17 +70,20 @@ get_member_contact_store (struct GNUNET_MESSENGER_MemberStore *store) | |||
67 | 70 | ||
68 | struct GNUNET_MESSENGER_SrvRoom *room = store->room; | 71 | struct GNUNET_MESSENGER_SrvRoom *room = store->room; |
69 | 72 | ||
70 | return get_service_contact_store(room->service); | 73 | return get_service_contact_store (room->service); |
71 | } | 74 | } |
72 | 75 | ||
76 | |||
73 | const struct GNUNET_HashCode* | 77 | const struct GNUNET_HashCode* |
74 | get_member_store_key (const struct GNUNET_MESSENGER_MemberStore *store) | 78 | get_member_store_key (const struct GNUNET_MESSENGER_MemberStore *store) |
75 | { | 79 | { |
76 | GNUNET_assert (store); | 80 | GNUNET_assert (store); |
77 | 81 | ||
78 | return get_srv_room_key((const struct GNUNET_MESSENGER_SrvRoom*) store->room); | 82 | return get_srv_room_key ((const struct |
83 | GNUNET_MESSENGER_SrvRoom*) store->room); | ||
79 | } | 84 | } |
80 | 85 | ||
86 | |||
81 | static int | 87 | static int |
82 | callback_scan_for_members (void *cls, | 88 | callback_scan_for_members (void *cls, |
83 | const char *filename) | 89 | const char *filename) |
@@ -90,14 +96,15 @@ callback_scan_for_members (void *cls, | |||
90 | 96 | ||
91 | GNUNET_asprintf (&directory, "%s%c", filename, DIR_SEPARATOR); | 97 | GNUNET_asprintf (&directory, "%s%c", filename, DIR_SEPARATOR); |
92 | 98 | ||
93 | load_member(store, directory); | 99 | load_member (store, directory); |
94 | 100 | ||
95 | GNUNET_free(directory); | 101 | GNUNET_free (directory); |
96 | } | 102 | } |
97 | 103 | ||
98 | return GNUNET_OK; | 104 | return GNUNET_OK; |
99 | } | 105 | } |
100 | 106 | ||
107 | |||
101 | static int | 108 | static int |
102 | iterate_load_next_member_sessions (void *cls, | 109 | iterate_load_next_member_sessions (void *cls, |
103 | const struct GNUNET_ShortHashCode *id, | 110 | const struct GNUNET_ShortHashCode *id, |
@@ -107,19 +114,21 @@ iterate_load_next_member_sessions (void *cls, | |||
107 | 114 | ||
108 | struct GNUNET_MESSENGER_Member *member = value; | 115 | struct GNUNET_MESSENGER_Member *member = value; |
109 | 116 | ||
110 | if (!member) | 117 | if (! member) |
111 | return GNUNET_YES; | 118 | return GNUNET_YES; |
112 | 119 | ||
113 | char *member_dir; | 120 | char *member_dir; |
114 | GNUNET_asprintf (&member_dir, "%s%s%c", sync_dir, GNUNET_sh2s(id), DIR_SEPARATOR); | 121 | GNUNET_asprintf (&member_dir, "%s%s%c", sync_dir, GNUNET_sh2s (id), |
122 | DIR_SEPARATOR); | ||
115 | 123 | ||
116 | if (GNUNET_YES == GNUNET_DISK_directory_test (member_dir, GNUNET_YES)) | 124 | if (GNUNET_YES == GNUNET_DISK_directory_test (member_dir, GNUNET_YES)) |
117 | load_member_next_sessions (member, member_dir); | 125 | load_member_next_sessions (member, member_dir); |
118 | 126 | ||
119 | GNUNET_free(member_dir); | 127 | GNUNET_free (member_dir); |
120 | return GNUNET_YES; | 128 | return GNUNET_YES; |
121 | } | 129 | } |
122 | 130 | ||
131 | |||
123 | static int | 132 | static int |
124 | iterate_sync_member_contacts (void *cls, | 133 | iterate_sync_member_contacts (void *cls, |
125 | const struct GNUNET_ShortHashCode *id, | 134 | const struct GNUNET_ShortHashCode *id, |
@@ -127,13 +136,14 @@ iterate_sync_member_contacts (void *cls, | |||
127 | { | 136 | { |
128 | struct GNUNET_MESSENGER_Member *member = value; | 137 | struct GNUNET_MESSENGER_Member *member = value; |
129 | 138 | ||
130 | if (!member) | 139 | if (! member) |
131 | return GNUNET_YES; | 140 | return GNUNET_YES; |
132 | 141 | ||
133 | sync_member_contacts (member); | 142 | sync_member_contacts (member); |
134 | return GNUNET_YES; | 143 | return GNUNET_YES; |
135 | } | 144 | } |
136 | 145 | ||
146 | |||
137 | void | 147 | void |
138 | load_member_store (struct GNUNET_MESSENGER_MemberStore *store, | 148 | load_member_store (struct GNUNET_MESSENGER_MemberStore *store, |
139 | const char *directory) | 149 | const char *directory) |
@@ -146,12 +156,16 @@ load_member_store (struct GNUNET_MESSENGER_MemberStore *store, | |||
146 | if (GNUNET_OK == GNUNET_DISK_directory_test (scan_dir, GNUNET_YES)) | 156 | if (GNUNET_OK == GNUNET_DISK_directory_test (scan_dir, GNUNET_YES)) |
147 | GNUNET_DISK_directory_scan (scan_dir, callback_scan_for_members, store); | 157 | GNUNET_DISK_directory_scan (scan_dir, callback_scan_for_members, store); |
148 | 158 | ||
149 | GNUNET_CONTAINER_multishortmap_iterate(store->members, iterate_load_next_member_sessions, scan_dir); | 159 | GNUNET_CONTAINER_multishortmap_iterate (store->members, |
150 | GNUNET_CONTAINER_multishortmap_iterate(store->members, iterate_sync_member_contacts, NULL); | 160 | iterate_load_next_member_sessions, |
161 | scan_dir); | ||
162 | GNUNET_CONTAINER_multishortmap_iterate (store->members, | ||
163 | iterate_sync_member_contacts, NULL); | ||
151 | 164 | ||
152 | GNUNET_free(scan_dir); | 165 | GNUNET_free (scan_dir); |
153 | } | 166 | } |
154 | 167 | ||
168 | |||
155 | static int | 169 | static int |
156 | iterate_save_members (void *cls, | 170 | iterate_save_members (void *cls, |
157 | const struct GNUNET_ShortHashCode *id, | 171 | const struct GNUNET_ShortHashCode *id, |
@@ -161,36 +175,40 @@ iterate_save_members (void *cls, | |||
161 | 175 | ||
162 | struct GNUNET_MESSENGER_Member *member = value; | 176 | struct GNUNET_MESSENGER_Member *member = value; |
163 | 177 | ||
164 | if (!member) | 178 | if (! member) |
165 | return GNUNET_YES; | 179 | return GNUNET_YES; |
166 | 180 | ||
167 | char *member_dir; | 181 | char *member_dir; |
168 | GNUNET_asprintf (&member_dir, "%s%s%c", save_dir, GNUNET_sh2s(id), DIR_SEPARATOR); | 182 | GNUNET_asprintf (&member_dir, "%s%s%c", save_dir, GNUNET_sh2s (id), |
183 | DIR_SEPARATOR); | ||
169 | 184 | ||
170 | if ((GNUNET_YES == GNUNET_DISK_directory_test (member_dir, GNUNET_NO)) || | 185 | if ((GNUNET_YES == GNUNET_DISK_directory_test (member_dir, GNUNET_NO)) || |
171 | (GNUNET_OK == GNUNET_DISK_directory_create (member_dir))) | 186 | (GNUNET_OK == GNUNET_DISK_directory_create (member_dir))) |
172 | save_member(member, member_dir); | 187 | save_member (member, member_dir); |
173 | 188 | ||
174 | GNUNET_free(member_dir); | 189 | GNUNET_free (member_dir); |
175 | return GNUNET_YES; | 190 | return GNUNET_YES; |
176 | } | 191 | } |
177 | 192 | ||
193 | |||
178 | void | 194 | void |
179 | save_member_store (struct GNUNET_MESSENGER_MemberStore *store, | 195 | save_member_store (struct GNUNET_MESSENGER_MemberStore *store, |
180 | const char *directory) | 196 | const char *directory) |
181 | { | 197 | { |
182 | GNUNET_assert ((store) && (directory)); | 198 | GNUNET_assert ((store) && (directory)); |
183 | 199 | ||
184 | char* save_dir; | 200 | char *save_dir; |
185 | GNUNET_asprintf (&save_dir, "%s%s%c", directory, "members", DIR_SEPARATOR); | 201 | GNUNET_asprintf (&save_dir, "%s%s%c", directory, "members", DIR_SEPARATOR); |
186 | 202 | ||
187 | if ((GNUNET_YES == GNUNET_DISK_directory_test (save_dir, GNUNET_NO)) || | 203 | if ((GNUNET_YES == GNUNET_DISK_directory_test (save_dir, GNUNET_NO)) || |
188 | (GNUNET_OK == GNUNET_DISK_directory_create (save_dir))) | 204 | (GNUNET_OK == GNUNET_DISK_directory_create (save_dir))) |
189 | GNUNET_CONTAINER_multishortmap_iterate(store->members, iterate_save_members, save_dir); | 205 | GNUNET_CONTAINER_multishortmap_iterate (store->members, |
206 | iterate_save_members, save_dir); | ||
190 | 207 | ||
191 | GNUNET_free(save_dir); | 208 | GNUNET_free (save_dir); |
192 | } | 209 | } |
193 | 210 | ||
211 | |||
194 | struct GNUNET_MESSENGER_Member* | 212 | struct GNUNET_MESSENGER_Member* |
195 | get_store_member (const struct GNUNET_MESSENGER_MemberStore *store, | 213 | get_store_member (const struct GNUNET_MESSENGER_MemberStore *store, |
196 | const struct GNUNET_ShortHashCode *id) | 214 | const struct GNUNET_ShortHashCode *id) |
@@ -200,48 +218,55 @@ get_store_member (const struct GNUNET_MESSENGER_MemberStore *store, | |||
200 | return GNUNET_CONTAINER_multishortmap_get (store->members, id); | 218 | return GNUNET_CONTAINER_multishortmap_get (store->members, id); |
201 | } | 219 | } |
202 | 220 | ||
221 | |||
203 | struct GNUNET_MESSENGER_Member* | 222 | struct GNUNET_MESSENGER_Member* |
204 | get_store_member_of (struct GNUNET_MESSENGER_MemberStore *store, | 223 | get_store_member_of (struct GNUNET_MESSENGER_MemberStore *store, |
205 | const struct GNUNET_MESSENGER_Message *message) | 224 | const struct GNUNET_MESSENGER_Message *message) |
206 | { | 225 | { |
207 | GNUNET_assert((store) && (message)); | 226 | GNUNET_assert ((store) && (message)); |
208 | 227 | ||
209 | if (GNUNET_YES == is_peer_message(message)) | 228 | if (GNUNET_YES == is_peer_message (message)) |
210 | return NULL; | 229 | return NULL; |
211 | 230 | ||
212 | if (GNUNET_MESSENGER_KIND_JOIN == message->header.kind) | 231 | if (GNUNET_MESSENGER_KIND_JOIN == message->header.kind) |
213 | return add_store_member(store, &(message->header.sender_id)); | 232 | return add_store_member (store, &(message->header.sender_id)); |
214 | else | 233 | else |
215 | return get_store_member(store, &(message->header.sender_id)); | 234 | return get_store_member (store, &(message->header.sender_id)); |
216 | } | 235 | } |
217 | 236 | ||
237 | |||
218 | struct GNUNET_MESSENGER_Member* | 238 | struct GNUNET_MESSENGER_Member* |
219 | add_store_member (struct GNUNET_MESSENGER_MemberStore *store, | 239 | add_store_member (struct GNUNET_MESSENGER_MemberStore *store, |
220 | const struct GNUNET_ShortHashCode *id) | 240 | const struct GNUNET_ShortHashCode *id) |
221 | { | 241 | { |
222 | GNUNET_assert ((store) && (store->members)); | 242 | GNUNET_assert ((store) && (store->members)); |
223 | 243 | ||
224 | struct GNUNET_MESSENGER_Member *member = id? get_store_member(store, id) : NULL; | 244 | struct GNUNET_MESSENGER_Member *member = id? get_store_member (store, id) : |
245 | NULL; | ||
225 | 246 | ||
226 | if (member) | 247 | if (member) |
227 | return member; | 248 | return member; |
228 | 249 | ||
229 | member = create_member(store, id); | 250 | member = create_member (store, id); |
230 | 251 | ||
231 | if (!member) | 252 | if (! member) |
232 | return NULL; | 253 | return NULL; |
233 | 254 | ||
234 | if (GNUNET_OK != GNUNET_CONTAINER_multishortmap_put (store->members, get_member_id(member), member, | 255 | if (GNUNET_OK != GNUNET_CONTAINER_multishortmap_put (store->members, |
256 | get_member_id (member), | ||
257 | member, | ||
235 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | 258 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) |
236 | { | 259 | { |
237 | destroy_member(member); | 260 | destroy_member (member); |
238 | return NULL; | 261 | return NULL; |
239 | } | 262 | } |
240 | 263 | ||
241 | return member; | 264 | return member; |
242 | } | 265 | } |
243 | 266 | ||
244 | struct GNUNET_MESSENGER_ClosureIterateMembers { | 267 | |
268 | struct GNUNET_MESSENGER_ClosureIterateMembers | ||
269 | { | ||
245 | GNUNET_MESSENGER_MemberIteratorCallback it; | 270 | GNUNET_MESSENGER_MemberIteratorCallback it; |
246 | void *cls; | 271 | void *cls; |
247 | }; | 272 | }; |
@@ -254,13 +279,14 @@ iterate_store_members_it (void *cls, | |||
254 | struct GNUNET_MESSENGER_ClosureIterateMembers *iterate = cls; | 279 | struct GNUNET_MESSENGER_ClosureIterateMembers *iterate = cls; |
255 | struct GNUNET_MESSENGER_Member *member = value; | 280 | struct GNUNET_MESSENGER_Member *member = value; |
256 | 281 | ||
257 | return iterate_member_sessions(member, iterate->it, iterate->cls); | 282 | return iterate_member_sessions (member, iterate->it, iterate->cls); |
258 | } | 283 | } |
259 | 284 | ||
285 | |||
260 | int | 286 | int |
261 | iterate_store_members (struct GNUNET_MESSENGER_MemberStore *store, | 287 | iterate_store_members (struct GNUNET_MESSENGER_MemberStore *store, |
262 | GNUNET_MESSENGER_MemberIteratorCallback it, | 288 | GNUNET_MESSENGER_MemberIteratorCallback it, |
263 | void* cls) | 289 | void *cls) |
264 | { | 290 | { |
265 | GNUNET_assert ((store) && (store->members) && (it)); | 291 | GNUNET_assert ((store) && (store->members) && (it)); |
266 | 292 | ||
@@ -269,5 +295,7 @@ iterate_store_members (struct GNUNET_MESSENGER_MemberStore *store, | |||
269 | iterate.it = it; | 295 | iterate.it = it; |
270 | iterate.cls = cls; | 296 | iterate.cls = cls; |
271 | 297 | ||
272 | return GNUNET_CONTAINER_multishortmap_iterate(store->members, iterate_store_members_it, &iterate); | 298 | return GNUNET_CONTAINER_multishortmap_iterate (store->members, |
299 | iterate_store_members_it, | ||
300 | &iterate); | ||
273 | } | 301 | } |
diff --git a/src/messenger/gnunet-service-messenger_member_store.h b/src/messenger/gnunet-service-messenger_member_store.h index 3dc39114b..54c5e4588 100644 --- a/src/messenger/gnunet-service-messenger_member_store.h +++ b/src/messenger/gnunet-service-messenger_member_store.h | |||
@@ -44,9 +44,9 @@ struct GNUNET_MESSENGER_MemberStore | |||
44 | }; | 44 | }; |
45 | 45 | ||
46 | typedef int (*GNUNET_MESSENGER_MemberIteratorCallback) ( | 46 | typedef int (*GNUNET_MESSENGER_MemberIteratorCallback) ( |
47 | void *cls, | 47 | void *cls, |
48 | const struct GNUNET_IDENTITY_PublicKey *public_key, | 48 | const struct GNUNET_IDENTITY_PublicKey *public_key, |
49 | struct GNUNET_MESSENGER_MemberSession *session); | 49 | struct GNUNET_MESSENGER_MemberSession *session); |
50 | 50 | ||
51 | /** | 51 | /** |
52 | * Initializes a member <i>store</i> as fully empty connected to a <i>room</i>. | 52 | * Initializes a member <i>store</i> as fully empty connected to a <i>room</i>. |
@@ -154,6 +154,6 @@ add_store_member (struct GNUNET_MESSENGER_MemberStore *store, | |||
154 | int | 154 | int |
155 | iterate_store_members (struct GNUNET_MESSENGER_MemberStore *store, | 155 | iterate_store_members (struct GNUNET_MESSENGER_MemberStore *store, |
156 | GNUNET_MESSENGER_MemberIteratorCallback it, | 156 | GNUNET_MESSENGER_MemberIteratorCallback it, |
157 | void* cls); | 157 | void *cls); |
158 | 158 | ||
159 | #endif //GNUNET_SERVICE_MESSENGER_MEMBER_STORE_H | 159 | #endif //GNUNET_SERVICE_MESSENGER_MEMBER_STORE_H |
diff --git a/src/messenger/gnunet-service-messenger_message_handle.c b/src/messenger/gnunet-service-messenger_message_handle.c index 57b758fa4..77466b599 100644 --- a/src/messenger/gnunet-service-messenger_message_handle.c +++ b/src/messenger/gnunet-service-messenger_message_handle.c | |||
@@ -31,58 +31,67 @@ handle_member_session_switch (struct GNUNET_MESSENGER_MemberSession *session, | |||
31 | const struct GNUNET_MESSENGER_Message *message, | 31 | const struct GNUNET_MESSENGER_Message *message, |
32 | const struct GNUNET_HashCode *hash) | 32 | const struct GNUNET_HashCode *hash) |
33 | { | 33 | { |
34 | struct GNUNET_MESSENGER_MemberSession *next = switch_member_session(session, message, hash); | 34 | struct GNUNET_MESSENGER_MemberSession *next = switch_member_session (session, |
35 | message, | ||
36 | hash); | ||
35 | 37 | ||
36 | if (next != session) | 38 | if (next != session) |
37 | add_member_session(next->member, next); | 39 | add_member_session (next->member, next); |
38 | } | 40 | } |
39 | 41 | ||
42 | |||
40 | void | 43 | void |
41 | handle_message_join (struct GNUNET_MESSENGER_SrvRoom *room, | 44 | handle_message_join (struct GNUNET_MESSENGER_SrvRoom *room, |
42 | struct GNUNET_MESSENGER_SenderSession *session, | 45 | struct GNUNET_MESSENGER_SenderSession *session, |
43 | const struct GNUNET_MESSENGER_Message *message, | 46 | const struct GNUNET_MESSENGER_Message *message, |
44 | const struct GNUNET_HashCode *hash) | 47 | const struct GNUNET_HashCode *hash) |
45 | { | 48 | { |
46 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Member (%s) joins room (%s).\n", | 49 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Member (%s) joins room (%s).\n", |
47 | GNUNET_sh2s (&(message->header.sender_id)), GNUNET_h2s(get_srv_room_key(room))); | 50 | GNUNET_sh2s (&(message->header.sender_id)), GNUNET_h2s ( |
51 | get_srv_room_key (room))); | ||
48 | 52 | ||
49 | if (GNUNET_OK != reset_member_session(session->member, hash)) | 53 | if (GNUNET_OK != reset_member_session (session->member, hash)) |
50 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Resetting member session failed!\n"); | 54 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Resetting member session failed!\n"); |
51 | 55 | ||
52 | solve_srv_room_member_collisions ( | 56 | solve_srv_room_member_collisions ( |
53 | room, | 57 | room, |
54 | &(message->body.join.key), | 58 | &(message->body.join.key), |
55 | &(message->header.sender_id), | 59 | &(message->header.sender_id), |
56 | GNUNET_TIME_absolute_ntoh(message->header.timestamp) | 60 | GNUNET_TIME_absolute_ntoh (message->header.timestamp) |
57 | ); | 61 | ); |
58 | } | 62 | } |
59 | 63 | ||
64 | |||
60 | void | 65 | void |
61 | handle_message_leave (struct GNUNET_MESSENGER_SrvRoom *room, | 66 | handle_message_leave (struct GNUNET_MESSENGER_SrvRoom *room, |
62 | struct GNUNET_MESSENGER_SenderSession *session, | 67 | struct GNUNET_MESSENGER_SenderSession *session, |
63 | const struct GNUNET_MESSENGER_Message *message, | 68 | const struct GNUNET_MESSENGER_Message *message, |
64 | const struct GNUNET_HashCode *hash) | 69 | const struct GNUNET_HashCode *hash) |
65 | { | 70 | { |
66 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Member (%s) leaves room (%s).\n", | 71 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Member (%s) leaves room (%s).\n", |
67 | GNUNET_sh2s (&(message->header.sender_id)), GNUNET_h2s(get_srv_room_key(room))); | 72 | GNUNET_sh2s (&(message->header.sender_id)), GNUNET_h2s ( |
73 | get_srv_room_key (room))); | ||
68 | 74 | ||
69 | close_member_session(session->member); | 75 | close_member_session (session->member); |
70 | } | 76 | } |
71 | 77 | ||
78 | |||
72 | void | 79 | void |
73 | handle_message_name (struct GNUNET_MESSENGER_SrvRoom *room, | 80 | handle_message_name (struct GNUNET_MESSENGER_SrvRoom *room, |
74 | struct GNUNET_MESSENGER_SenderSession *session, | 81 | struct GNUNET_MESSENGER_SenderSession *session, |
75 | const struct GNUNET_MESSENGER_Message *message, | 82 | const struct GNUNET_MESSENGER_Message *message, |
76 | const struct GNUNET_HashCode *hash) | 83 | const struct GNUNET_HashCode *hash) |
77 | { | 84 | { |
78 | struct GNUNET_MESSENGER_Contact *contact = get_member_session_contact(session->member); | 85 | struct GNUNET_MESSENGER_Contact *contact = get_member_session_contact ( |
86 | session->member); | ||
79 | 87 | ||
80 | if (!contact) | 88 | if (! contact) |
81 | return; | 89 | return; |
82 | 90 | ||
83 | set_contact_name (contact, message->body.name.name); | 91 | set_contact_name (contact, message->body.name.name); |
84 | } | 92 | } |
85 | 93 | ||
94 | |||
86 | void | 95 | void |
87 | handle_message_key (struct GNUNET_MESSENGER_SrvRoom *room, | 96 | handle_message_key (struct GNUNET_MESSENGER_SrvRoom *room, |
88 | struct GNUNET_MESSENGER_SenderSession *session, | 97 | struct GNUNET_MESSENGER_SenderSession *session, |
@@ -92,6 +101,7 @@ handle_message_key (struct GNUNET_MESSENGER_SrvRoom *room, | |||
92 | handle_member_session_switch (session->member, message, hash); | 101 | handle_member_session_switch (session->member, message, hash); |
93 | } | 102 | } |
94 | 103 | ||
104 | |||
95 | void | 105 | void |
96 | handle_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, | 106 | handle_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, |
97 | struct GNUNET_MESSENGER_SenderSession *session, | 107 | struct GNUNET_MESSENGER_SenderSession *session, |
@@ -100,16 +110,18 @@ handle_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, | |||
100 | { | 110 | { |
101 | struct GNUNET_MESSENGER_PeerStore *store = get_srv_room_peer_store (room); | 111 | struct GNUNET_MESSENGER_PeerStore *store = get_srv_room_peer_store (room); |
102 | 112 | ||
103 | if (0 == GNUNET_memcmp(session->peer, &(message->body.peer.peer))) | 113 | if (0 == GNUNET_memcmp (session->peer, &(message->body.peer.peer))) |
104 | update_store_peer(store, &(message->body.peer.peer)); | 114 | update_store_peer (store, &(message->body.peer.peer)); |
105 | 115 | ||
106 | if (GNUNET_NO == contains_list_tunnels (&(room->basement), &(message->body.peer.peer))) | 116 | if (GNUNET_NO == contains_list_tunnels (&(room->basement), |
117 | &(message->body.peer.peer))) | ||
107 | add_to_list_tunnels (&(room->basement), &(message->body.peer.peer), hash); | 118 | add_to_list_tunnels (&(room->basement), &(message->body.peer.peer), hash); |
108 | 119 | ||
109 | if (room->peer_message) | 120 | if (room->peer_message) |
110 | rebuild_srv_room_basement_structure (room); | 121 | rebuild_srv_room_basement_structure (room); |
111 | } | 122 | } |
112 | 123 | ||
124 | |||
113 | void | 125 | void |
114 | handle_message_id (struct GNUNET_MESSENGER_SrvRoom *room, | 126 | handle_message_id (struct GNUNET_MESSENGER_SrvRoom *room, |
115 | struct GNUNET_MESSENGER_SenderSession *session, | 127 | struct GNUNET_MESSENGER_SenderSession *session, |
@@ -119,13 +131,14 @@ handle_message_id (struct GNUNET_MESSENGER_SrvRoom *room, | |||
119 | handle_member_session_switch (session->member, message, hash); | 131 | handle_member_session_switch (session->member, message, hash); |
120 | 132 | ||
121 | solve_srv_room_member_collisions ( | 133 | solve_srv_room_member_collisions ( |
122 | room, | 134 | room, |
123 | get_member_session_public_key(session->member), | 135 | get_member_session_public_key (session->member), |
124 | &(message->body.id.id), | 136 | &(message->body.id.id), |
125 | GNUNET_TIME_absolute_ntoh(message->header.timestamp) | 137 | GNUNET_TIME_absolute_ntoh (message->header.timestamp) |
126 | ); | 138 | ); |
127 | } | 139 | } |
128 | 140 | ||
141 | |||
129 | void | 142 | void |
130 | handle_message_miss (struct GNUNET_MESSENGER_SrvRoom *room, | 143 | handle_message_miss (struct GNUNET_MESSENGER_SrvRoom *room, |
131 | struct GNUNET_MESSENGER_SenderSession *session, | 144 | struct GNUNET_MESSENGER_SenderSession *session, |
@@ -134,12 +147,13 @@ handle_message_miss (struct GNUNET_MESSENGER_SrvRoom *room, | |||
134 | { | 147 | { |
135 | struct GNUNET_MESSENGER_PeerStore *store = get_srv_room_peer_store (room); | 148 | struct GNUNET_MESSENGER_PeerStore *store = get_srv_room_peer_store (room); |
136 | 149 | ||
137 | if (0 == GNUNET_memcmp(session->peer, &(message->body.miss.peer))) | 150 | if (0 == GNUNET_memcmp (session->peer, &(message->body.miss.peer))) |
138 | remove_store_peer(store, &(message->body.miss.peer)); | 151 | remove_store_peer (store, &(message->body.miss.peer)); |
139 | 152 | ||
140 | struct GNUNET_MESSENGER_ListTunnel *element = find_list_tunnels (&(room->basement), &(message->body.miss.peer), NULL); | 153 | struct GNUNET_MESSENGER_ListTunnel *element = find_list_tunnels ( |
154 | &(room->basement), &(message->body.miss.peer), NULL); | ||
141 | 155 | ||
142 | if (!element) | 156 | if (! element) |
143 | return; | 157 | return; |
144 | 158 | ||
145 | remove_from_list_tunnels (&(room->basement), element); | 159 | remove_from_list_tunnels (&(room->basement), element); |
@@ -148,17 +162,22 @@ handle_message_miss (struct GNUNET_MESSENGER_SrvRoom *room, | |||
148 | rebuild_srv_room_basement_structure (room); | 162 | rebuild_srv_room_basement_structure (room); |
149 | } | 163 | } |
150 | 164 | ||
165 | |||
151 | void | 166 | void |
152 | handle_message_delete (struct GNUNET_MESSENGER_SrvRoom *room, | 167 | handle_message_delete (struct GNUNET_MESSENGER_SrvRoom *room, |
153 | struct GNUNET_MESSENGER_SenderSession *session, | 168 | struct GNUNET_MESSENGER_SenderSession *session, |
154 | const struct GNUNET_MESSENGER_Message *message, | 169 | const struct GNUNET_MESSENGER_Message *message, |
155 | const struct GNUNET_HashCode *hash) | 170 | const struct GNUNET_HashCode *hash) |
156 | { | 171 | { |
157 | struct GNUNET_TIME_Relative delay = GNUNET_TIME_relative_ntoh (message->body.deletion.delay); | 172 | struct GNUNET_TIME_Relative delay = GNUNET_TIME_relative_ntoh ( |
158 | struct GNUNET_TIME_Absolute action = GNUNET_TIME_absolute_ntoh (message->header.timestamp); | 173 | message->body.deletion.delay); |
174 | struct GNUNET_TIME_Absolute action = GNUNET_TIME_absolute_ntoh ( | ||
175 | message->header.timestamp); | ||
159 | 176 | ||
160 | action = GNUNET_TIME_absolute_add (action, delay); | 177 | action = GNUNET_TIME_absolute_add (action, delay); |
161 | delay = GNUNET_TIME_absolute_get_difference (GNUNET_TIME_absolute_get (), action); | 178 | delay = GNUNET_TIME_absolute_get_difference (GNUNET_TIME_absolute_get (), |
179 | action); | ||
162 | 180 | ||
163 | delete_srv_room_message (room, session->member, &(message->body.deletion.hash), delay); | 181 | delete_srv_room_message (room, session->member, |
182 | &(message->body.deletion.hash), delay); | ||
164 | } | 183 | } |
diff --git a/src/messenger/gnunet-service-messenger_message_kind.c b/src/messenger/gnunet-service-messenger_message_kind.c index 688dd2fd9..0cc3afeaf 100644 --- a/src/messenger/gnunet-service-messenger_message_kind.c +++ b/src/messenger/gnunet-service-messenger_message_kind.c | |||
@@ -31,12 +31,13 @@ | |||
31 | struct GNUNET_MESSENGER_Message* | 31 | struct GNUNET_MESSENGER_Message* |
32 | create_message_info (struct GNUNET_MESSENGER_Service *service) | 32 | create_message_info (struct GNUNET_MESSENGER_Service *service) |
33 | { | 33 | { |
34 | if (!service) | 34 | if (! service) |
35 | return NULL; | 35 | return NULL; |
36 | 36 | ||
37 | struct GNUNET_MESSENGER_Message *message = create_message (GNUNET_MESSENGER_KIND_INFO); | 37 | struct GNUNET_MESSENGER_Message *message = create_message ( |
38 | GNUNET_MESSENGER_KIND_INFO); | ||
38 | 39 | ||
39 | if (!message) | 40 | if (! message) |
40 | return NULL; | 41 | return NULL; |
41 | 42 | ||
42 | message->body.info.messenger_version = GNUNET_MESSENGER_VERSION; | 43 | message->body.info.messenger_version = GNUNET_MESSENGER_VERSION; |
@@ -44,18 +45,21 @@ create_message_info (struct GNUNET_MESSENGER_Service *service) | |||
44 | return message; | 45 | return message; |
45 | } | 46 | } |
46 | 47 | ||
48 | |||
47 | struct GNUNET_MESSENGER_Message* | 49 | struct GNUNET_MESSENGER_Message* |
48 | create_message_peer (struct GNUNET_MESSENGER_Service *service) | 50 | create_message_peer (struct GNUNET_MESSENGER_Service *service) |
49 | { | 51 | { |
50 | if (!service) | 52 | if (! service) |
51 | return NULL; | 53 | return NULL; |
52 | 54 | ||
53 | struct GNUNET_MESSENGER_Message *message = create_message (GNUNET_MESSENGER_KIND_PEER); | 55 | struct GNUNET_MESSENGER_Message *message = create_message ( |
56 | GNUNET_MESSENGER_KIND_PEER); | ||
54 | 57 | ||
55 | if (!message) | 58 | if (! message) |
56 | return NULL; | 59 | return NULL; |
57 | 60 | ||
58 | if (GNUNET_OK == get_service_peer_identity (service, &(message->body.peer.peer))) | 61 | if (GNUNET_OK == get_service_peer_identity (service, |
62 | &(message->body.peer.peer))) | ||
59 | return message; | 63 | return message; |
60 | else | 64 | else |
61 | { | 65 | { |
@@ -64,36 +68,42 @@ create_message_peer (struct GNUNET_MESSENGER_Service *service) | |||
64 | } | 68 | } |
65 | } | 69 | } |
66 | 70 | ||
71 | |||
67 | struct GNUNET_MESSENGER_Message* | 72 | struct GNUNET_MESSENGER_Message* |
68 | create_message_miss (const struct GNUNET_PeerIdentity *peer) | 73 | create_message_miss (const struct GNUNET_PeerIdentity *peer) |
69 | { | 74 | { |
70 | if (!peer) | 75 | if (! peer) |
71 | return NULL; | 76 | return NULL; |
72 | 77 | ||
73 | struct GNUNET_MESSENGER_Message *message = create_message (GNUNET_MESSENGER_KIND_MISS); | 78 | struct GNUNET_MESSENGER_Message *message = create_message ( |
79 | GNUNET_MESSENGER_KIND_MISS); | ||
74 | 80 | ||
75 | if (!message) | 81 | if (! message) |
76 | { | 82 | { |
77 | return NULL; | 83 | return NULL; |
78 | } | 84 | } |
79 | 85 | ||
80 | GNUNET_memcpy(&(message->body.miss.peer), peer, sizeof(struct GNUNET_PeerIdentity)); | 86 | GNUNET_memcpy (&(message->body.miss.peer), peer, sizeof(struct |
87 | GNUNET_PeerIdentity)); | ||
81 | 88 | ||
82 | return message; | 89 | return message; |
83 | } | 90 | } |
84 | 91 | ||
92 | |||
85 | struct GNUNET_MESSENGER_Message* | 93 | struct GNUNET_MESSENGER_Message* |
86 | create_message_merge (const struct GNUNET_HashCode *previous) | 94 | create_message_merge (const struct GNUNET_HashCode *previous) |
87 | { | 95 | { |
88 | if (!previous) | 96 | if (! previous) |
89 | return NULL; | 97 | return NULL; |
90 | 98 | ||
91 | struct GNUNET_MESSENGER_Message *message = create_message (GNUNET_MESSENGER_KIND_MERGE); | 99 | struct GNUNET_MESSENGER_Message *message = create_message ( |
100 | GNUNET_MESSENGER_KIND_MERGE); | ||
92 | 101 | ||
93 | if (!message) | 102 | if (! message) |
94 | return NULL; | 103 | return NULL; |
95 | 104 | ||
96 | GNUNET_memcpy(&(message->body.merge.previous), previous, sizeof(struct GNUNET_HashCode)); | 105 | GNUNET_memcpy (&(message->body.merge.previous), previous, sizeof(struct |
106 | GNUNET_HashCode)); | ||
97 | 107 | ||
98 | return message; | 108 | return message; |
99 | } | 109 | } |
diff --git a/src/messenger/gnunet-service-messenger_message_recv.c b/src/messenger/gnunet-service-messenger_message_recv.c index 3b545cfa4..e445c4e79 100644 --- a/src/messenger/gnunet-service-messenger_message_recv.c +++ b/src/messenger/gnunet-service-messenger_message_recv.c | |||
@@ -38,25 +38,31 @@ forward_about_members (struct GNUNET_MESSENGER_SrvRoom *room, | |||
38 | if (session->prev) | 38 | if (session->prev) |
39 | forward_about_members (room, tunnel, session->prev, map); | 39 | forward_about_members (room, tunnel, session->prev, map); |
40 | 40 | ||
41 | struct GNUNET_MESSENGER_MessageStore *message_store = get_srv_room_message_store(room); | 41 | struct GNUNET_MESSENGER_MessageStore *message_store = |
42 | get_srv_room_message_store (room); | ||
42 | struct GNUNET_MESSENGER_ListMessage *element; | 43 | struct GNUNET_MESSENGER_ListMessage *element; |
43 | 44 | ||
44 | for (element = session->messages.head; element; element = element->next) | 45 | for (element = session->messages.head; element; element = element->next) |
45 | { | 46 | { |
46 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(map, &(element->hash))) | 47 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (map, |
48 | &(element->hash))) | ||
47 | continue; | 49 | continue; |
48 | 50 | ||
49 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put(map, &(element->hash), NULL, | 51 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (map, &(element->hash), |
50 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | 52 | NULL, |
51 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Forwarding of session message could be duplicated!\n"); | 53 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) |
54 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
55 | "Forwarding of session message could be duplicated!\n"); | ||
52 | 56 | ||
53 | const struct GNUNET_MESSENGER_Message *message = get_store_message(message_store, &(element->hash)); | 57 | const struct GNUNET_MESSENGER_Message *message = get_store_message ( |
58 | message_store, &(element->hash)); | ||
54 | 59 | ||
55 | if (message) | 60 | if (message) |
56 | forward_tunnel_message(tunnel, message, &(element->hash)); | 61 | forward_tunnel_message (tunnel, message, &(element->hash)); |
57 | } | 62 | } |
58 | } | 63 | } |
59 | 64 | ||
65 | |||
60 | static int | 66 | static int |
61 | iterate_forward_members (void *cls, | 67 | iterate_forward_members (void *cls, |
62 | const struct GNUNET_IDENTITY_PublicKey *public_key, | 68 | const struct GNUNET_IDENTITY_PublicKey *public_key, |
@@ -64,68 +70,77 @@ iterate_forward_members (void *cls, | |||
64 | { | 70 | { |
65 | struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls; | 71 | struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls; |
66 | 72 | ||
67 | if (GNUNET_YES == is_member_session_completed(session)) | 73 | if (GNUNET_YES == is_member_session_completed (session)) |
68 | return GNUNET_YES; | 74 | return GNUNET_YES; |
69 | 75 | ||
70 | struct GNUNET_CONTAINER_MultiHashMap *map = GNUNET_CONTAINER_multihashmap_create(4, GNUNET_NO); | 76 | struct GNUNET_CONTAINER_MultiHashMap *map = |
77 | GNUNET_CONTAINER_multihashmap_create (4, GNUNET_NO); | ||
71 | 78 | ||
72 | forward_about_members (tunnel->room, tunnel, session, map); | 79 | forward_about_members (tunnel->room, tunnel, session, map); |
73 | 80 | ||
74 | GNUNET_CONTAINER_multihashmap_destroy(map); | 81 | GNUNET_CONTAINER_multihashmap_destroy (map); |
75 | return GNUNET_YES; | 82 | return GNUNET_YES; |
76 | } | 83 | } |
77 | 84 | ||
85 | |||
78 | int | 86 | int |
79 | recv_message_info (struct GNUNET_MESSENGER_SrvRoom *room, | 87 | recv_message_info (struct GNUNET_MESSENGER_SrvRoom *room, |
80 | struct GNUNET_MESSENGER_SrvTunnel *tunnel, | 88 | struct GNUNET_MESSENGER_SrvTunnel *tunnel, |
81 | const struct GNUNET_MESSENGER_Message *message, | 89 | const struct GNUNET_MESSENGER_Message *message, |
82 | const struct GNUNET_HashCode *hash) | 90 | const struct GNUNET_HashCode *hash) |
83 | { | 91 | { |
84 | const uint32_t version = get_tunnel_messenger_version(tunnel); | 92 | const uint32_t version = get_tunnel_messenger_version (tunnel); |
85 | 93 | ||
86 | if (GNUNET_OK != update_tunnel_messenger_version(tunnel, message->body.info.messenger_version)) | 94 | if (GNUNET_OK != update_tunnel_messenger_version (tunnel, |
95 | message->body.info. | ||
96 | messenger_version)) | ||
87 | { | 97 | { |
88 | disconnect_tunnel(tunnel); | 98 | disconnect_tunnel (tunnel); |
89 | return GNUNET_NO; | 99 | return GNUNET_NO; |
90 | } | 100 | } |
91 | 101 | ||
92 | if (version == get_tunnel_messenger_version(tunnel)) | 102 | if (version == get_tunnel_messenger_version (tunnel)) |
93 | return GNUNET_NO; | 103 | return GNUNET_NO; |
94 | 104 | ||
95 | if (room->host) | 105 | if (room->host) |
96 | send_tunnel_message (tunnel, room->host, create_message_info (room->service)); | 106 | send_tunnel_message (tunnel, room->host, create_message_info ( |
107 | room->service)); | ||
97 | 108 | ||
98 | struct GNUNET_PeerIdentity peer; | 109 | struct GNUNET_PeerIdentity peer; |
99 | get_tunnel_peer_identity(tunnel, &peer); | 110 | get_tunnel_peer_identity (tunnel, &peer); |
100 | 111 | ||
101 | if (GNUNET_YES != contains_list_tunnels(&(room->basement), &peer)) | 112 | if (GNUNET_YES != contains_list_tunnels (&(room->basement), &peer)) |
102 | { | 113 | { |
103 | struct GNUNET_MESSENGER_MessageStore *message_store = get_srv_room_message_store(room); | 114 | struct GNUNET_MESSENGER_MessageStore *message_store = |
115 | get_srv_room_message_store (room); | ||
104 | 116 | ||
105 | struct GNUNET_MESSENGER_ListTunnel *element; | 117 | struct GNUNET_MESSENGER_ListTunnel *element; |
106 | for (element = room->basement.head; element; element = element->next) | 118 | for (element = room->basement.head; element; element = element->next) |
107 | { | 119 | { |
108 | if (!element->hash) | 120 | if (! element->hash) |
109 | continue; | 121 | continue; |
110 | 122 | ||
111 | const struct GNUNET_MESSENGER_Message *message = get_store_message(message_store, element->hash); | 123 | const struct GNUNET_MESSENGER_Message *message = get_store_message ( |
124 | message_store, element->hash); | ||
112 | 125 | ||
113 | if (message) | 126 | if (message) |
114 | forward_tunnel_message(tunnel, message, element->hash); | 127 | forward_tunnel_message (tunnel, message, element->hash); |
115 | } | 128 | } |
116 | } | 129 | } |
117 | 130 | ||
118 | if (GNUNET_YES != contains_list_tunnels(&(room->basement), &peer)) | 131 | if (GNUNET_YES != contains_list_tunnels (&(room->basement), &peer)) |
119 | { | 132 | { |
120 | struct GNUNET_MESSENGER_MemberStore *member_store = get_srv_room_member_store(room); | 133 | struct GNUNET_MESSENGER_MemberStore *member_store = |
134 | get_srv_room_member_store (room); | ||
121 | 135 | ||
122 | iterate_store_members(member_store, iterate_forward_members, tunnel); | 136 | iterate_store_members (member_store, iterate_forward_members, tunnel); |
123 | } | 137 | } |
124 | 138 | ||
125 | check_srv_room_peer_status(room, tunnel); | 139 | check_srv_room_peer_status (room, tunnel); |
126 | return GNUNET_NO; | 140 | return GNUNET_NO; |
127 | } | 141 | } |
128 | 142 | ||
143 | |||
129 | int | 144 | int |
130 | recv_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, | 145 | recv_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, |
131 | struct GNUNET_MESSENGER_SrvTunnel *tunnel, | 146 | struct GNUNET_MESSENGER_SrvTunnel *tunnel, |
@@ -135,18 +150,19 @@ recv_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, | |||
135 | struct GNUNET_PeerIdentity peer; | 150 | struct GNUNET_PeerIdentity peer; |
136 | GNUNET_PEER_resolve (tunnel->peer, &peer); | 151 | GNUNET_PEER_resolve (tunnel->peer, &peer); |
137 | 152 | ||
138 | if (0 == GNUNET_memcmp(&peer, &(message->body.peer.peer))) | 153 | if (0 == GNUNET_memcmp (&peer, &(message->body.peer.peer))) |
139 | { | 154 | { |
140 | if (!tunnel->peer_message) | 155 | if (! tunnel->peer_message) |
141 | tunnel->peer_message = GNUNET_new(struct GNUNET_HashCode); | 156 | tunnel->peer_message = GNUNET_new (struct GNUNET_HashCode); |
142 | 157 | ||
143 | GNUNET_memcpy(tunnel->peer_message, &hash, sizeof(hash)); | 158 | GNUNET_memcpy (tunnel->peer_message, &hash, sizeof(hash)); |
144 | } | 159 | } |
145 | 160 | ||
146 | update_to_list_tunnels(&(room->basement), &(message->body.peer.peer), hash); | 161 | update_to_list_tunnels (&(room->basement), &(message->body.peer.peer), hash); |
147 | return GNUNET_YES; | 162 | return GNUNET_YES; |
148 | } | 163 | } |
149 | 164 | ||
165 | |||
150 | static void | 166 | static void |
151 | callback_found_message (void *cls, | 167 | callback_found_message (void *cls, |
152 | struct GNUNET_MESSENGER_SrvRoom *room, | 168 | struct GNUNET_MESSENGER_SrvRoom *room, |
@@ -155,21 +171,23 @@ callback_found_message (void *cls, | |||
155 | { | 171 | { |
156 | struct GNUNET_MESSENGER_SrvTunnel *tunnel = tunnel; | 172 | struct GNUNET_MESSENGER_SrvTunnel *tunnel = tunnel; |
157 | 173 | ||
158 | if (!message) | 174 | if (! message) |
159 | { | 175 | { |
160 | struct GNUNET_MESSENGER_OperationStore *operation_store = get_srv_room_operation_store(room); | 176 | struct GNUNET_MESSENGER_OperationStore *operation_store = |
161 | 177 | get_srv_room_operation_store (room); | |
162 | use_store_operation( | 178 | |
163 | operation_store, | 179 | use_store_operation ( |
164 | hash, | 180 | operation_store, |
165 | GNUNET_MESSENGER_OP_REQUEST, | 181 | hash, |
166 | GNUNET_MESSENGER_REQUEST_DELAY | 182 | GNUNET_MESSENGER_OP_REQUEST, |
167 | ); | 183 | GNUNET_MESSENGER_REQUEST_DELAY |
184 | ); | ||
168 | } | 185 | } |
169 | else | 186 | else |
170 | forward_tunnel_message (tunnel, message, hash); | 187 | forward_tunnel_message (tunnel, message, hash); |
171 | } | 188 | } |
172 | 189 | ||
190 | |||
173 | /* | 191 | /* |
174 | * Function returns GNUNET_NO to drop forwarding the request. | 192 | * Function returns GNUNET_NO to drop forwarding the request. |
175 | * It will only be forwarded if it can't be answered! | 193 | * It will only be forwarded if it can't be answered! |
@@ -180,20 +198,31 @@ recv_message_request (struct GNUNET_MESSENGER_SrvRoom *room, | |||
180 | const struct GNUNET_MESSENGER_Message *message, | 198 | const struct GNUNET_MESSENGER_Message *message, |
181 | const struct GNUNET_HashCode *hash) | 199 | const struct GNUNET_HashCode *hash) |
182 | { | 200 | { |
183 | struct GNUNET_MESSENGER_MemberStore *member_store = get_srv_room_member_store(room); | 201 | struct GNUNET_MESSENGER_MemberStore *member_store = |
184 | struct GNUNET_MESSENGER_Member *member = get_store_member_of(member_store, message); | 202 | get_srv_room_member_store (room); |
203 | struct GNUNET_MESSENGER_Member *member = get_store_member_of (member_store, | ||
204 | message); | ||
185 | 205 | ||
186 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Request for message (%s)\n", GNUNET_h2s (hash)); | 206 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Request for message (%s)\n", |
207 | GNUNET_h2s (hash)); | ||
187 | 208 | ||
188 | if (!member) | 209 | if (! member) |
189 | return GNUNET_NO; | 210 | return GNUNET_NO; |
190 | 211 | ||
191 | struct GNUNET_MESSENGER_MemberSession *session = get_member_session_of(member, message, hash); | 212 | struct GNUNET_MESSENGER_MemberSession *session = get_member_session_of ( |
213 | member, message, hash); | ||
192 | 214 | ||
193 | if ((!session) || (GNUNET_YES != check_member_session_history(session, &(message->body.request.hash), GNUNET_NO))) | 215 | if ((! session) || (GNUNET_YES != check_member_session_history (session, |
216 | &(message-> | ||
217 | body.request | ||
218 | .hash), | ||
219 | GNUNET_NO))) | ||
194 | return GNUNET_NO; | 220 | return GNUNET_NO; |
195 | 221 | ||
196 | if (GNUNET_NO == request_srv_room_message(room, &(message->body.request.hash), session, callback_found_message, tunnel)) | 222 | if (GNUNET_NO == request_srv_room_message (room, |
223 | &(message->body.request.hash), | ||
224 | session, callback_found_message, | ||
225 | tunnel)) | ||
197 | return GNUNET_YES; | 226 | return GNUNET_YES; |
198 | 227 | ||
199 | return GNUNET_NO; | 228 | return GNUNET_NO; |
diff --git a/src/messenger/gnunet-service-messenger_message_send.c b/src/messenger/gnunet-service-messenger_message_send.c index 40ff95cef..5c3f9ecc5 100644 --- a/src/messenger/gnunet-service-messenger_message_send.c +++ b/src/messenger/gnunet-service-messenger_message_send.c | |||
@@ -48,68 +48,86 @@ notify_about_members (struct GNUNET_MESSENGER_MemberNotify *notify, | |||
48 | if (session->prev) | 48 | if (session->prev) |
49 | notify_about_members (notify, session->prev, map, GNUNET_YES); | 49 | notify_about_members (notify, session->prev, map, GNUNET_YES); |
50 | 50 | ||
51 | struct GNUNET_MESSENGER_MessageStore *message_store = get_srv_room_message_store(notify->room); | 51 | struct GNUNET_MESSENGER_MessageStore *message_store = |
52 | get_srv_room_message_store (notify->room); | ||
52 | struct GNUNET_MESSENGER_ListMessage *element; | 53 | struct GNUNET_MESSENGER_ListMessage *element; |
53 | 54 | ||
54 | for (element = session->messages.head; element; element = element->next) | 55 | for (element = session->messages.head; element; element = element->next) |
55 | { | 56 | { |
56 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(map, &(element->hash))) | 57 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (map, |
58 | &(element->hash))) | ||
57 | continue; | 59 | continue; |
58 | 60 | ||
59 | if ((GNUNET_YES == check_permission) && | 61 | if ((GNUNET_YES == check_permission) && |
60 | (GNUNET_YES != check_member_session_history(notify->session, &(element->hash), GNUNET_NO))) | 62 | (GNUNET_YES != check_member_session_history (notify->session, |
63 | &(element->hash), | ||
64 | GNUNET_NO))) | ||
61 | continue; | 65 | continue; |
62 | 66 | ||
63 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put(map, &(element->hash), NULL, | 67 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (map, &(element->hash), |
64 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | 68 | NULL, |
65 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Notification of session message could be duplicated!\n"); | 69 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) |
70 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
71 | "Notification of session message could be duplicated!\n"); | ||
66 | 72 | ||
67 | const struct GNUNET_MESSENGER_Message *message = get_store_message(message_store, &(element->hash)); | 73 | const struct GNUNET_MESSENGER_Message *message = get_store_message ( |
74 | message_store, &(element->hash)); | ||
68 | 75 | ||
69 | if ((!message) || (GNUNET_YES == is_peer_message (message))) | 76 | if ((! message) || (GNUNET_YES == is_peer_message (message))) |
70 | continue; | 77 | continue; |
71 | 78 | ||
72 | struct GNUNET_MESSENGER_SenderSession sender; | 79 | struct GNUNET_MESSENGER_SenderSession sender; |
73 | sender.member = session; | 80 | sender.member = session; |
74 | 81 | ||
75 | notify_srv_handle_message (notify->handle, notify->room, &sender, message, &(element->hash)); | 82 | notify_srv_handle_message (notify->handle, notify->room, &sender, message, |
83 | &(element->hash)); | ||
76 | } | 84 | } |
77 | } | 85 | } |
78 | 86 | ||
87 | |||
79 | static int | 88 | static int |
80 | iterate_notify_about_members (void *cls, | 89 | iterate_notify_about_members (void *cls, |
81 | const struct GNUNET_IDENTITY_PublicKey *public_key, | 90 | const struct |
91 | GNUNET_IDENTITY_PublicKey *public_key, | ||
82 | struct GNUNET_MESSENGER_MemberSession *session) | 92 | struct GNUNET_MESSENGER_MemberSession *session) |
83 | { | 93 | { |
84 | struct GNUNET_MESSENGER_MemberNotify *notify = cls; | 94 | struct GNUNET_MESSENGER_MemberNotify *notify = cls; |
85 | 95 | ||
86 | if ((notify->session == session) || (GNUNET_YES == is_member_session_completed(session))) | 96 | if ((notify->session == session) || (GNUNET_YES == |
97 | is_member_session_completed (session))) | ||
87 | return GNUNET_YES; | 98 | return GNUNET_YES; |
88 | 99 | ||
89 | struct GNUNET_CONTAINER_MultiHashMap *map = GNUNET_CONTAINER_multihashmap_create(4, GNUNET_NO); | 100 | struct GNUNET_CONTAINER_MultiHashMap *map = |
101 | GNUNET_CONTAINER_multihashmap_create (4, GNUNET_NO); | ||
90 | 102 | ||
91 | notify_about_members (notify, session, map, GNUNET_NO); | 103 | notify_about_members (notify, session, map, GNUNET_NO); |
92 | 104 | ||
93 | GNUNET_CONTAINER_multihashmap_destroy(map); | 105 | GNUNET_CONTAINER_multihashmap_destroy (map); |
94 | return GNUNET_YES; | 106 | return GNUNET_YES; |
95 | } | 107 | } |
96 | 108 | ||
109 | |||
97 | void | 110 | void |
98 | send_message_join (struct GNUNET_MESSENGER_SrvRoom *room, | 111 | send_message_join (struct GNUNET_MESSENGER_SrvRoom *room, |
99 | struct GNUNET_MESSENGER_SrvHandle *handle, | 112 | struct GNUNET_MESSENGER_SrvHandle *handle, |
100 | const struct GNUNET_MESSENGER_Message *message, | 113 | const struct GNUNET_MESSENGER_Message *message, |
101 | const struct GNUNET_HashCode *hash) | 114 | const struct GNUNET_HashCode *hash) |
102 | { | 115 | { |
103 | set_srv_handle_key(handle, &(message->body.join.key)); | 116 | set_srv_handle_key (handle, &(message->body.join.key)); |
104 | 117 | ||
105 | struct GNUNET_MESSENGER_MemberStore *member_store = get_srv_room_member_store(room); | 118 | struct GNUNET_MESSENGER_MemberStore *member_store = |
106 | struct GNUNET_MESSENGER_Member *member = add_store_member(member_store, &(message->header.sender_id)); | 119 | get_srv_room_member_store (room); |
120 | struct GNUNET_MESSENGER_Member *member = add_store_member (member_store, | ||
121 | &(message->header. | ||
122 | sender_id)); | ||
107 | 123 | ||
108 | struct GNUNET_MESSENGER_MemberSession *session = get_member_session_of (member, message, hash); | 124 | struct GNUNET_MESSENGER_MemberSession *session = get_member_session_of ( |
125 | member, message, hash); | ||
109 | 126 | ||
110 | if (!session) | 127 | if (! session) |
111 | { | 128 | { |
112 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "A valid session is required to join a room!\n"); | 129 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
130 | "A valid session is required to join a room!\n"); | ||
113 | goto skip_member_notification; | 131 | goto skip_member_notification; |
114 | } | 132 | } |
115 | 133 | ||
@@ -119,54 +137,61 @@ send_message_join (struct GNUNET_MESSENGER_SrvRoom *room, | |||
119 | notify.handle = handle; | 137 | notify.handle = handle; |
120 | notify.session = session; | 138 | notify.session = session; |
121 | 139 | ||
122 | iterate_store_members(get_srv_room_member_store(room), iterate_notify_about_members, ¬ify); | 140 | iterate_store_members (get_srv_room_member_store (room), |
141 | iterate_notify_about_members, ¬ify); | ||
123 | 142 | ||
124 | skip_member_notification: | 143 | skip_member_notification: |
125 | check_srv_room_peer_status(room, NULL); | 144 | check_srv_room_peer_status (room, NULL); |
126 | } | 145 | } |
127 | 146 | ||
147 | |||
128 | void | 148 | void |
129 | send_message_key (struct GNUNET_MESSENGER_SrvRoom *room, | 149 | send_message_key (struct GNUNET_MESSENGER_SrvRoom *room, |
130 | struct GNUNET_MESSENGER_SrvHandle *handle, | 150 | struct GNUNET_MESSENGER_SrvHandle *handle, |
131 | const struct GNUNET_MESSENGER_Message *message, | 151 | const struct GNUNET_MESSENGER_Message *message, |
132 | const struct GNUNET_HashCode *hash) | 152 | const struct GNUNET_HashCode *hash) |
133 | { | 153 | { |
134 | set_srv_handle_key(handle, &(message->body.key.key)); | 154 | set_srv_handle_key (handle, &(message->body.key.key)); |
135 | } | 155 | } |
136 | 156 | ||
157 | |||
137 | void | 158 | void |
138 | send_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, | 159 | send_message_peer (struct GNUNET_MESSENGER_SrvRoom *room, |
139 | struct GNUNET_MESSENGER_SrvHandle *handle, | 160 | struct GNUNET_MESSENGER_SrvHandle *handle, |
140 | const struct GNUNET_MESSENGER_Message *message, | 161 | const struct GNUNET_MESSENGER_Message *message, |
141 | const struct GNUNET_HashCode *hash) | 162 | const struct GNUNET_HashCode *hash) |
142 | { | 163 | { |
143 | if (!room->peer_message) | 164 | if (! room->peer_message) |
144 | room->peer_message = GNUNET_new(struct GNUNET_HashCode); | 165 | room->peer_message = GNUNET_new (struct GNUNET_HashCode); |
145 | 166 | ||
146 | GNUNET_memcpy(room->peer_message, hash, sizeof(struct GNUNET_HashCode)); | 167 | GNUNET_memcpy (room->peer_message, hash, sizeof(struct GNUNET_HashCode)); |
147 | } | 168 | } |
148 | 169 | ||
170 | |||
149 | void | 171 | void |
150 | send_message_id (struct GNUNET_MESSENGER_SrvRoom *room, | 172 | send_message_id (struct GNUNET_MESSENGER_SrvRoom *room, |
151 | struct GNUNET_MESSENGER_SrvHandle *handle, | 173 | struct GNUNET_MESSENGER_SrvHandle *handle, |
152 | const struct GNUNET_MESSENGER_Message *message, | 174 | const struct GNUNET_MESSENGER_Message *message, |
153 | const struct GNUNET_HashCode *hash) | 175 | const struct GNUNET_HashCode *hash) |
154 | { | 176 | { |
155 | change_srv_handle_member_id (handle, get_srv_room_key(room), &(message->body.id.id)); | 177 | change_srv_handle_member_id (handle, get_srv_room_key (room), |
178 | &(message->body.id.id)); | ||
156 | } | 179 | } |
157 | 180 | ||
181 | |||
158 | void | 182 | void |
159 | send_message_request (struct GNUNET_MESSENGER_SrvRoom *room, | 183 | send_message_request (struct GNUNET_MESSENGER_SrvRoom *room, |
160 | struct GNUNET_MESSENGER_SrvHandle *handle, | 184 | struct GNUNET_MESSENGER_SrvHandle *handle, |
161 | const struct GNUNET_MESSENGER_Message *message, | 185 | const struct GNUNET_MESSENGER_Message *message, |
162 | const struct GNUNET_HashCode *hash) | 186 | const struct GNUNET_HashCode *hash) |
163 | { | 187 | { |
164 | struct GNUNET_MESSENGER_OperationStore *operation_store = get_srv_room_operation_store(room); | 188 | struct GNUNET_MESSENGER_OperationStore *operation_store = |
165 | 189 | get_srv_room_operation_store (room); | |
166 | use_store_operation( | 190 | |
167 | operation_store, | 191 | use_store_operation ( |
168 | &(message->body.request.hash), | 192 | operation_store, |
169 | GNUNET_MESSENGER_OP_REQUEST, | 193 | &(message->body.request.hash), |
170 | GNUNET_MESSENGER_REQUEST_DELAY | 194 | GNUNET_MESSENGER_OP_REQUEST, |
171 | ); | 195 | GNUNET_MESSENGER_REQUEST_DELAY |
196 | ); | ||
172 | } | 197 | } |
diff --git a/src/messenger/gnunet-service-messenger_message_state.c b/src/messenger/gnunet-service-messenger_message_state.c index b2328588e..112f03032 100644 --- a/src/messenger/gnunet-service-messenger_message_state.c +++ b/src/messenger/gnunet-service-messenger_message_state.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--2021 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 |
@@ -29,35 +29,38 @@ | |||
29 | void | 29 | void |
30 | init_message_state (struct GNUNET_MESSENGER_MessageState *state) | 30 | init_message_state (struct GNUNET_MESSENGER_MessageState *state) |
31 | { | 31 | { |
32 | GNUNET_assert(state); | 32 | GNUNET_assert (state); |
33 | 33 | ||
34 | init_list_messages (&(state->last_messages)); | 34 | init_list_messages (&(state->last_messages)); |
35 | } | 35 | } |
36 | 36 | ||
37 | |||
37 | void | 38 | void |
38 | clear_message_state (struct GNUNET_MESSENGER_MessageState *state) | 39 | clear_message_state (struct GNUNET_MESSENGER_MessageState *state) |
39 | { | 40 | { |
40 | GNUNET_assert(state); | 41 | GNUNET_assert (state); |
41 | 42 | ||
42 | clear_list_messages (&(state->last_messages)); | 43 | clear_list_messages (&(state->last_messages)); |
43 | } | 44 | } |
44 | 45 | ||
46 | |||
45 | void | 47 | void |
46 | get_message_state_chain_hash (const struct GNUNET_MESSENGER_MessageState *state, | 48 | get_message_state_chain_hash (const struct GNUNET_MESSENGER_MessageState *state, |
47 | struct GNUNET_HashCode *hash) | 49 | struct GNUNET_HashCode *hash) |
48 | { | 50 | { |
49 | GNUNET_assert((state) && (hash)); | 51 | GNUNET_assert ((state) && (hash)); |
50 | 52 | ||
51 | if (state->last_messages.head) | 53 | if (state->last_messages.head) |
52 | GNUNET_memcpy(hash, &(state->last_messages.head->hash), sizeof(*hash)); | 54 | GNUNET_memcpy (hash, &(state->last_messages.head->hash), sizeof(*hash)); |
53 | else | 55 | else |
54 | memset (hash, 0, sizeof(*hash)); | 56 | memset (hash, 0, sizeof(*hash)); |
55 | } | 57 | } |
56 | 58 | ||
59 | |||
57 | const struct GNUNET_HashCode* | 60 | const struct GNUNET_HashCode* |
58 | get_message_state_merge_hash (const struct GNUNET_MESSENGER_MessageState *state) | 61 | get_message_state_merge_hash (const struct GNUNET_MESSENGER_MessageState *state) |
59 | { | 62 | { |
60 | GNUNET_assert(state); | 63 | GNUNET_assert (state); |
61 | 64 | ||
62 | if (state->last_messages.head == state->last_messages.tail) | 65 | if (state->last_messages.head == state->last_messages.tail) |
63 | return NULL; | 66 | return NULL; |
@@ -65,13 +68,14 @@ get_message_state_merge_hash (const struct GNUNET_MESSENGER_MessageState *state) | |||
65 | return &(state->last_messages.tail->hash); | 68 | return &(state->last_messages.tail->hash); |
66 | } | 69 | } |
67 | 70 | ||
71 | |||
68 | void | 72 | void |
69 | update_message_state (struct GNUNET_MESSENGER_MessageState *state, | 73 | update_message_state (struct GNUNET_MESSENGER_MessageState *state, |
70 | int requested, | 74 | int requested, |
71 | const struct GNUNET_MESSENGER_Message *message, | 75 | const struct GNUNET_MESSENGER_Message *message, |
72 | const struct GNUNET_HashCode *hash) | 76 | const struct GNUNET_HashCode *hash) |
73 | { | 77 | { |
74 | GNUNET_assert((state) && (message) && (hash)); | 78 | GNUNET_assert ((state) && (message) && (hash)); |
75 | 79 | ||
76 | if ((GNUNET_YES == requested) || | 80 | if ((GNUNET_YES == requested) || |
77 | (GNUNET_MESSENGER_KIND_INFO == message->header.kind) || | 81 | (GNUNET_MESSENGER_KIND_INFO == message->header.kind) || |
@@ -79,36 +83,38 @@ update_message_state (struct GNUNET_MESSENGER_MessageState *state, | |||
79 | return; | 83 | return; |
80 | 84 | ||
81 | if (GNUNET_MESSENGER_KIND_MERGE == message->header.kind) | 85 | if (GNUNET_MESSENGER_KIND_MERGE == message->header.kind) |
82 | remove_from_list_messages(&(state->last_messages), &(message->body.merge.previous)); | 86 | remove_from_list_messages (&(state->last_messages), |
83 | remove_from_list_messages(&(state->last_messages), &(message->header.previous)); | 87 | &(message->body.merge.previous)); |
88 | remove_from_list_messages (&(state->last_messages), | ||
89 | &(message->header.previous)); | ||
84 | 90 | ||
85 | add_to_list_messages (&(state->last_messages), hash); | 91 | add_to_list_messages (&(state->last_messages), hash); |
86 | } | 92 | } |
87 | 93 | ||
94 | |||
88 | void | 95 | void |
89 | load_message_state (struct GNUNET_MESSENGER_MessageState *state, | 96 | load_message_state (struct GNUNET_MESSENGER_MessageState *state, |
90 | const char *path) | 97 | const char *path) |
91 | { | 98 | { |
92 | GNUNET_assert((state) && (path)); | 99 | GNUNET_assert ((state) && (path)); |
93 | 100 | ||
94 | char *last_messages_file; | 101 | char *last_messages_file; |
95 | GNUNET_asprintf (&last_messages_file, "%s%s", path, "last_messages.list"); | 102 | GNUNET_asprintf (&last_messages_file, "%s%s", path, "last_messages.list"); |
96 | 103 | ||
97 | load_list_messages(&(state->last_messages), last_messages_file); | 104 | load_list_messages (&(state->last_messages), last_messages_file); |
98 | GNUNET_free(last_messages_file); | 105 | GNUNET_free (last_messages_file); |
99 | } | 106 | } |
100 | 107 | ||
108 | |||
101 | void | 109 | void |
102 | save_message_state (const struct GNUNET_MESSENGER_MessageState *state, | 110 | save_message_state (const struct GNUNET_MESSENGER_MessageState *state, |
103 | const char *path) | 111 | const char *path) |
104 | { | 112 | { |
105 | GNUNET_assert((state) && (path)); | 113 | GNUNET_assert ((state) && (path)); |
106 | 114 | ||
107 | char *last_messages_file; | 115 | char *last_messages_file; |
108 | GNUNET_asprintf (&last_messages_file, "%s%s", path, "last_messages.list"); | 116 | GNUNET_asprintf (&last_messages_file, "%s%s", path, "last_messages.list"); |
109 | 117 | ||
110 | save_list_messages(&(state->last_messages), last_messages_file); | 118 | save_list_messages (&(state->last_messages), last_messages_file); |
111 | GNUNET_free(last_messages_file); | 119 | GNUNET_free (last_messages_file); |
112 | } | 120 | } |
113 | |||
114 | |||
diff --git a/src/messenger/gnunet-service-messenger_message_state.h b/src/messenger/gnunet-service-messenger_message_state.h index 10e6a2c46..f6a1a41b9 100644 --- a/src/messenger/gnunet-service-messenger_message_state.h +++ b/src/messenger/gnunet-service-messenger_message_state.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2020--2021 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 |
@@ -48,7 +48,8 @@ get_message_state_chain_hash (const struct GNUNET_MESSENGER_MessageState *state, | |||
48 | struct GNUNET_HashCode *hash); | 48 | struct GNUNET_HashCode *hash); |
49 | 49 | ||
50 | const struct GNUNET_HashCode* | 50 | const struct GNUNET_HashCode* |
51 | get_message_state_merge_hash (const struct GNUNET_MESSENGER_MessageState *state); | 51 | get_message_state_merge_hash (const struct |
52 | GNUNET_MESSENGER_MessageState *state); | ||
52 | 53 | ||
53 | void | 54 | void |
54 | update_message_state (struct GNUNET_MESSENGER_MessageState *state, | 55 | update_message_state (struct GNUNET_MESSENGER_MessageState *state, |
diff --git a/src/messenger/gnunet-service-messenger_message_store.c b/src/messenger/gnunet-service-messenger_message_store.c index e137e9d93..d4bccca5c 100644 --- a/src/messenger/gnunet-service-messenger_message_store.c +++ b/src/messenger/gnunet-service-messenger_message_store.c | |||
@@ -30,7 +30,7 @@ | |||
30 | void | 30 | void |
31 | init_message_store (struct GNUNET_MESSENGER_MessageStore *store) | 31 | init_message_store (struct GNUNET_MESSENGER_MessageStore *store) |
32 | { | 32 | { |
33 | GNUNET_assert(store); | 33 | GNUNET_assert (store); |
34 | 34 | ||
35 | store->storage_messages = NULL; | 35 | store->storage_messages = NULL; |
36 | 36 | ||
@@ -42,6 +42,7 @@ init_message_store (struct GNUNET_MESSENGER_MessageStore *store) | |||
42 | store->write_links = GNUNET_NO; | 42 | store->write_links = GNUNET_NO; |
43 | } | 43 | } |
44 | 44 | ||
45 | |||
45 | static int | 46 | static int |
46 | iterate_destroy_entries (void *cls, | 47 | iterate_destroy_entries (void *cls, |
47 | const struct GNUNET_HashCode *key, | 48 | const struct GNUNET_HashCode *key, |
@@ -49,11 +50,12 @@ iterate_destroy_entries (void *cls, | |||
49 | { | 50 | { |
50 | struct GNUNET_MESSENGER_MessageEntry *entry = value; | 51 | struct GNUNET_MESSENGER_MessageEntry *entry = value; |
51 | 52 | ||
52 | GNUNET_free(entry); | 53 | GNUNET_free (entry); |
53 | 54 | ||
54 | return GNUNET_YES; | 55 | return GNUNET_YES; |
55 | } | 56 | } |
56 | 57 | ||
58 | |||
57 | static int | 59 | static int |
58 | iterate_destroy_messages (void *cls, | 60 | iterate_destroy_messages (void *cls, |
59 | const struct GNUNET_HashCode *key, | 61 | const struct GNUNET_HashCode *key, |
@@ -66,6 +68,7 @@ iterate_destroy_messages (void *cls, | |||
66 | return GNUNET_YES; | 68 | return GNUNET_YES; |
67 | } | 69 | } |
68 | 70 | ||
71 | |||
69 | static int | 72 | static int |
70 | iterate_destroy_links (void *cls, | 73 | iterate_destroy_links (void *cls, |
71 | const struct GNUNET_HashCode *key, | 74 | const struct GNUNET_HashCode *key, |
@@ -73,15 +76,16 @@ iterate_destroy_links (void *cls, | |||
73 | { | 76 | { |
74 | struct GNUNET_HashCode *previous = value; | 77 | struct GNUNET_HashCode *previous = value; |
75 | 78 | ||
76 | GNUNET_free(previous); | 79 | GNUNET_free (previous); |
77 | 80 | ||
78 | return GNUNET_YES; | 81 | return GNUNET_YES; |
79 | } | 82 | } |
80 | 83 | ||
84 | |||
81 | void | 85 | void |
82 | clear_message_store (struct GNUNET_MESSENGER_MessageStore *store) | 86 | clear_message_store (struct GNUNET_MESSENGER_MessageStore *store) |
83 | { | 87 | { |
84 | GNUNET_assert(store); | 88 | GNUNET_assert (store); |
85 | 89 | ||
86 | if (store->storage_messages) | 90 | if (store->storage_messages) |
87 | { | 91 | { |
@@ -90,15 +94,19 @@ clear_message_store (struct GNUNET_MESSENGER_MessageStore *store) | |||
90 | store->storage_messages = NULL; | 94 | store->storage_messages = NULL; |
91 | } | 95 | } |
92 | 96 | ||
93 | GNUNET_CONTAINER_multihashmap_iterate (store->entries, iterate_destroy_entries, NULL); | 97 | GNUNET_CONTAINER_multihashmap_iterate (store->entries, |
94 | GNUNET_CONTAINER_multihashmap_iterate (store->messages, iterate_destroy_messages, NULL); | 98 | iterate_destroy_entries, NULL); |
95 | GNUNET_CONTAINER_multihashmap_iterate (store->links, iterate_destroy_links, NULL); | 99 | GNUNET_CONTAINER_multihashmap_iterate (store->messages, |
100 | iterate_destroy_messages, NULL); | ||
101 | GNUNET_CONTAINER_multihashmap_iterate (store->links, iterate_destroy_links, | ||
102 | NULL); | ||
96 | 103 | ||
97 | GNUNET_CONTAINER_multihashmap_destroy (store->entries); | 104 | GNUNET_CONTAINER_multihashmap_destroy (store->entries); |
98 | GNUNET_CONTAINER_multihashmap_destroy (store->messages); | 105 | GNUNET_CONTAINER_multihashmap_destroy (store->messages); |
99 | GNUNET_CONTAINER_multihashmap_destroy (store->links); | 106 | GNUNET_CONTAINER_multihashmap_destroy (store->links); |
100 | } | 107 | } |
101 | 108 | ||
109 | |||
102 | struct GNUNET_MESSENGER_MessageEntryStorage | 110 | struct GNUNET_MESSENGER_MessageEntryStorage |
103 | { | 111 | { |
104 | struct GNUNET_HashCode hash; | 112 | struct GNUNET_HashCode hash; |
@@ -106,10 +114,12 @@ struct GNUNET_MESSENGER_MessageEntryStorage | |||
106 | }; | 114 | }; |
107 | 115 | ||
108 | #define load_message_store_attribute_failed(file, attribute) \ | 116 | #define load_message_store_attribute_failed(file, attribute) \ |
109 | sizeof(attribute) != GNUNET_DISK_file_read(file, &(attribute), sizeof(attribute)) | 117 | sizeof(attribute) != GNUNET_DISK_file_read (file, &(attribute), \ |
118 | sizeof(attribute)) | ||
110 | 119 | ||
111 | #define save_message_store_attribute_failed(file, attribute) \ | 120 | #define save_message_store_attribute_failed(file, attribute) \ |
112 | sizeof(attribute) != GNUNET_DISK_file_write(file, &(attribute), sizeof(attribute)) | 121 | sizeof(attribute) != GNUNET_DISK_file_write (file, &(attribute), \ |
122 | sizeof(attribute)) | ||
113 | 123 | ||
114 | static void | 124 | static void |
115 | load_message_store_entries (struct GNUNET_MESSENGER_MessageStore *store, | 125 | load_message_store_entries (struct GNUNET_MESSENGER_MessageStore *store, |
@@ -117,31 +127,36 @@ load_message_store_entries (struct GNUNET_MESSENGER_MessageStore *store, | |||
117 | { | 127 | { |
118 | enum GNUNET_DISK_AccessPermissions permission = (GNUNET_DISK_PERM_USER_READ); | 128 | enum GNUNET_DISK_AccessPermissions permission = (GNUNET_DISK_PERM_USER_READ); |
119 | 129 | ||
120 | struct GNUNET_DISK_FileHandle *entries = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, permission); | 130 | struct GNUNET_DISK_FileHandle *entries = GNUNET_DISK_file_open (filename, |
131 | GNUNET_DISK_OPEN_READ, | ||
132 | permission); | ||
121 | 133 | ||
122 | if (!entries) | 134 | if (! entries) |
123 | return; | 135 | return; |
124 | 136 | ||
125 | struct GNUNET_MESSENGER_MessageEntryStorage storage; | 137 | struct GNUNET_MESSENGER_MessageEntryStorage storage; |
126 | struct GNUNET_MESSENGER_MessageEntry *entry; | 138 | struct GNUNET_MESSENGER_MessageEntry *entry; |
127 | 139 | ||
128 | memset(&storage, 0, sizeof(storage)); | 140 | memset (&storage, 0, sizeof(storage)); |
129 | 141 | ||
130 | do | 142 | do |
131 | { | 143 | { |
132 | entry = NULL; | 144 | entry = NULL; |
133 | 145 | ||
134 | if ((load_message_store_attribute_failed(entries, storage.hash)) || | 146 | if ((load_message_store_attribute_failed (entries, storage.hash)) || |
135 | (load_message_store_attribute_failed(entries, storage.entry.offset)) || | 147 | (load_message_store_attribute_failed (entries, storage.entry.offset)) || |
136 | (load_message_store_attribute_failed(entries, storage.entry.length))) | 148 | (load_message_store_attribute_failed (entries, storage.entry.length))) |
137 | break; | 149 | break; |
138 | 150 | ||
139 | entry = GNUNET_new(struct GNUNET_MESSENGER_MessageEntry); | 151 | entry = GNUNET_new (struct GNUNET_MESSENGER_MessageEntry); |
140 | 152 | ||
141 | GNUNET_memcpy(entry, &(storage.entry), sizeof(*entry)); | 153 | GNUNET_memcpy (entry, &(storage.entry), sizeof(*entry)); |
142 | 154 | ||
143 | if ((GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (store->entries, &(storage.hash))) || | 155 | if ((GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (store->entries, |
144 | (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (store->entries, &(storage.hash), entry, | 156 | &(storage.hash))) |
157 | || | ||
158 | (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (store->entries, | ||
159 | &(storage.hash), entry, | ||
145 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))) | 160 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))) |
146 | { | 161 | { |
147 | store->rewrite_entries = GNUNET_YES; | 162 | store->rewrite_entries = GNUNET_YES; |
@@ -151,11 +166,12 @@ load_message_store_entries (struct GNUNET_MESSENGER_MessageStore *store, | |||
151 | while (entry); | 166 | while (entry); |
152 | 167 | ||
153 | if (entry) | 168 | if (entry) |
154 | GNUNET_free(entry); | 169 | GNUNET_free (entry); |
155 | 170 | ||
156 | GNUNET_DISK_file_close (entries); | 171 | GNUNET_DISK_file_close (entries); |
157 | } | 172 | } |
158 | 173 | ||
174 | |||
159 | struct GNUNET_MESSENGER_MessageLinkStorage | 175 | struct GNUNET_MESSENGER_MessageLinkStorage |
160 | { | 176 | { |
161 | struct GNUNET_HashCode hash; | 177 | struct GNUNET_HashCode hash; |
@@ -168,51 +184,59 @@ load_message_store_links (struct GNUNET_MESSENGER_MessageStore *store, | |||
168 | { | 184 | { |
169 | enum GNUNET_DISK_AccessPermissions permission = (GNUNET_DISK_PERM_USER_READ); | 185 | enum GNUNET_DISK_AccessPermissions permission = (GNUNET_DISK_PERM_USER_READ); |
170 | 186 | ||
171 | struct GNUNET_DISK_FileHandle *entries = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, permission); | 187 | struct GNUNET_DISK_FileHandle *entries = GNUNET_DISK_file_open (filename, |
188 | GNUNET_DISK_OPEN_READ, | ||
189 | permission); | ||
172 | 190 | ||
173 | if (!entries) | 191 | if (! entries) |
174 | return; | 192 | return; |
175 | 193 | ||
176 | struct GNUNET_MESSENGER_MessageLinkStorage storage; | 194 | struct GNUNET_MESSENGER_MessageLinkStorage storage; |
177 | struct GNUNET_MESSENGER_MessageLink *link; | 195 | struct GNUNET_MESSENGER_MessageLink *link; |
178 | 196 | ||
179 | memset(&storage, 0, sizeof(storage)); | 197 | memset (&storage, 0, sizeof(storage)); |
180 | 198 | ||
181 | do | 199 | do |
182 | { | 200 | { |
183 | link = NULL; | 201 | link = NULL; |
184 | 202 | ||
185 | if ((load_message_store_attribute_failed(entries, storage.hash)) || | 203 | if ((load_message_store_attribute_failed (entries, storage.hash)) || |
186 | (load_message_store_attribute_failed(entries, storage.link.multiple)) || | 204 | (load_message_store_attribute_failed (entries, |
187 | (load_message_store_attribute_failed(entries, storage.link.first)) || | 205 | storage.link.multiple)) || |
206 | (load_message_store_attribute_failed (entries, storage.link.first)) || | ||
188 | ((GNUNET_YES == storage.link.multiple) && | 207 | ((GNUNET_YES == storage.link.multiple) && |
189 | (load_message_store_attribute_failed(entries, storage.link.second)))) | 208 | (load_message_store_attribute_failed (entries, storage.link.second)))) |
190 | break; | 209 | break; |
191 | 210 | ||
192 | link = GNUNET_new(struct GNUNET_MESSENGER_MessageLink); | 211 | link = GNUNET_new (struct GNUNET_MESSENGER_MessageLink); |
193 | 212 | ||
194 | GNUNET_memcpy(link, &(storage.link), sizeof(*link)); | 213 | GNUNET_memcpy (link, &(storage.link), sizeof(*link)); |
195 | 214 | ||
196 | if ((GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (store->links, &(storage.hash))) || | 215 | if ((GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (store->links, |
197 | (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (store->links, &(storage.hash), link, | 216 | &(storage.hash))) |
217 | || | ||
218 | (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (store->links, | ||
219 | &(storage.hash), link, | ||
198 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))) | 220 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))) |
199 | break; | 221 | break; |
200 | } | 222 | } |
201 | while (link); | 223 | while (link); |
202 | 224 | ||
203 | if (link) | 225 | if (link) |
204 | GNUNET_free(link); | 226 | GNUNET_free (link); |
205 | 227 | ||
206 | GNUNET_DISK_file_close (entries); | 228 | GNUNET_DISK_file_close (entries); |
207 | } | 229 | } |
208 | 230 | ||
231 | |||
209 | void | 232 | void |
210 | load_message_store (struct GNUNET_MESSENGER_MessageStore *store, | 233 | load_message_store (struct GNUNET_MESSENGER_MessageStore *store, |
211 | const char *directory) | 234 | const char *directory) |
212 | { | 235 | { |
213 | GNUNET_assert((store) && (directory)); | 236 | GNUNET_assert ((store) && (directory)); |
214 | 237 | ||
215 | enum GNUNET_DISK_AccessPermissions permission = (GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); | 238 | enum GNUNET_DISK_AccessPermissions permission = (GNUNET_DISK_PERM_USER_READ |
239 | | GNUNET_DISK_PERM_USER_WRITE); | ||
216 | 240 | ||
217 | if (store->storage_messages) | 241 | if (store->storage_messages) |
218 | GNUNET_DISK_file_close (store->storage_messages); | 242 | GNUNET_DISK_file_close (store->storage_messages); |
@@ -221,30 +245,33 @@ load_message_store (struct GNUNET_MESSENGER_MessageStore *store, | |||
221 | GNUNET_asprintf (&filename, "%s%s", directory, "messages.store"); | 245 | GNUNET_asprintf (&filename, "%s%s", directory, "messages.store"); |
222 | 246 | ||
223 | if (GNUNET_YES == GNUNET_DISK_file_test (filename)) | 247 | if (GNUNET_YES == GNUNET_DISK_file_test (filename)) |
224 | store->storage_messages = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READWRITE, permission); | 248 | store->storage_messages = GNUNET_DISK_file_open (filename, |
249 | GNUNET_DISK_OPEN_READWRITE, | ||
250 | permission); | ||
225 | else | 251 | else |
226 | store->storage_messages = NULL; | 252 | store->storage_messages = NULL; |
227 | 253 | ||
228 | GNUNET_free(filename); | 254 | GNUNET_free (filename); |
229 | 255 | ||
230 | if (!store->storage_messages) | 256 | if (! store->storage_messages) |
231 | return; | 257 | return; |
232 | 258 | ||
233 | GNUNET_asprintf (&filename, "%s%s", directory, "entries.store"); | 259 | GNUNET_asprintf (&filename, "%s%s", directory, "entries.store"); |
234 | 260 | ||
235 | if (GNUNET_YES == GNUNET_DISK_file_test (filename)) | 261 | if (GNUNET_YES == GNUNET_DISK_file_test (filename)) |
236 | load_message_store_entries(store, filename); | 262 | load_message_store_entries (store, filename); |
237 | 263 | ||
238 | GNUNET_free(filename); | 264 | GNUNET_free (filename); |
239 | 265 | ||
240 | GNUNET_asprintf (&filename, "%s%s", directory, "links.store"); | 266 | GNUNET_asprintf (&filename, "%s%s", directory, "links.store"); |
241 | 267 | ||
242 | if (GNUNET_YES == GNUNET_DISK_file_test (filename)) | 268 | if (GNUNET_YES == GNUNET_DISK_file_test (filename)) |
243 | load_message_store_links(store, filename); | 269 | load_message_store_links (store, filename); |
244 | 270 | ||
245 | GNUNET_free(filename); | 271 | GNUNET_free (filename); |
246 | } | 272 | } |
247 | 273 | ||
274 | |||
248 | struct GNUNET_MESSENGER_ClosureMessageSave | 275 | struct GNUNET_MESSENGER_ClosureMessageSave |
249 | { | 276 | { |
250 | struct GNUNET_MESSENGER_MessageStore *store; | 277 | struct GNUNET_MESSENGER_MessageStore *store; |
@@ -261,12 +288,15 @@ iterate_save_entries (void *cls, | |||
261 | struct GNUNET_MESSENGER_MessageEntry *entry = value; | 288 | struct GNUNET_MESSENGER_MessageEntry *entry = value; |
262 | 289 | ||
263 | GNUNET_DISK_file_write (save->storage, key, sizeof(*key)); | 290 | GNUNET_DISK_file_write (save->storage, key, sizeof(*key)); |
264 | GNUNET_DISK_file_write (save->storage, &(entry->offset), sizeof(entry->offset)); | 291 | GNUNET_DISK_file_write (save->storage, &(entry->offset), |
265 | GNUNET_DISK_file_write (save->storage, &(entry->length), sizeof(entry->length)); | 292 | sizeof(entry->offset)); |
293 | GNUNET_DISK_file_write (save->storage, &(entry->length), | ||
294 | sizeof(entry->length)); | ||
266 | 295 | ||
267 | return GNUNET_YES; | 296 | return GNUNET_YES; |
268 | } | 297 | } |
269 | 298 | ||
299 | |||
270 | static int | 300 | static int |
271 | iterate_save_messages (void *cls, | 301 | iterate_save_messages (void *cls, |
272 | const struct GNUNET_HashCode *key, | 302 | const struct GNUNET_HashCode *key, |
@@ -274,36 +304,42 @@ iterate_save_messages (void *cls, | |||
274 | { | 304 | { |
275 | struct GNUNET_MESSENGER_ClosureMessageSave *save = cls; | 305 | struct GNUNET_MESSENGER_ClosureMessageSave *save = cls; |
276 | 306 | ||
277 | if (GNUNET_NO != GNUNET_CONTAINER_multihashmap_contains (save->store->entries, key)) | 307 | if (GNUNET_NO != GNUNET_CONTAINER_multihashmap_contains (save->store->entries, |
308 | key)) | ||
278 | return GNUNET_YES; | 309 | return GNUNET_YES; |
279 | 310 | ||
280 | struct GNUNET_MESSENGER_Message *message = value; | 311 | struct GNUNET_MESSENGER_Message *message = value; |
281 | struct GNUNET_MESSENGER_MessageEntryStorage storage; | 312 | struct GNUNET_MESSENGER_MessageEntryStorage storage; |
282 | 313 | ||
283 | GNUNET_memcpy(&(storage.hash), key, sizeof(storage.hash)); | 314 | GNUNET_memcpy (&(storage.hash), key, sizeof(storage.hash)); |
284 | 315 | ||
285 | storage.entry.length = get_message_size (message, GNUNET_YES); | 316 | storage.entry.length = get_message_size (message, GNUNET_YES); |
286 | storage.entry.offset = GNUNET_DISK_file_seek (save->store->storage_messages, 0, GNUNET_DISK_SEEK_END); | 317 | storage.entry.offset = GNUNET_DISK_file_seek (save->store->storage_messages, |
318 | 0, GNUNET_DISK_SEEK_END); | ||
287 | 319 | ||
288 | if ((GNUNET_SYSERR == storage.entry.offset) || | 320 | if ((GNUNET_SYSERR == storage.entry.offset) || |
289 | (save_message_store_attribute_failed(save->storage, storage.hash)) || | 321 | (save_message_store_attribute_failed (save->storage, storage.hash)) || |
290 | (save_message_store_attribute_failed(save->storage, storage.entry.offset)) || | 322 | (save_message_store_attribute_failed (save->storage, |
291 | (save_message_store_attribute_failed(save->storage, storage.entry.length))) | 323 | storage.entry.offset)) || |
324 | (save_message_store_attribute_failed (save->storage, | ||
325 | storage.entry.length))) | ||
292 | return GNUNET_YES; | 326 | return GNUNET_YES; |
293 | 327 | ||
294 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Storing message with hash: %s\n", | 328 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Storing message with hash: %s\n", |
295 | GNUNET_h2s (&(storage.hash))); | 329 | GNUNET_h2s (&(storage.hash))); |
296 | 330 | ||
297 | char *buffer = GNUNET_malloc(storage.entry.length); | 331 | char *buffer = GNUNET_malloc (storage.entry.length); |
298 | 332 | ||
299 | encode_message (message, storage.entry.length, buffer, GNUNET_YES); | 333 | encode_message (message, storage.entry.length, buffer, GNUNET_YES); |
300 | 334 | ||
301 | GNUNET_DISK_file_write (save->store->storage_messages, buffer, storage.entry.length); | 335 | GNUNET_DISK_file_write (save->store->storage_messages, buffer, |
336 | storage.entry.length); | ||
302 | 337 | ||
303 | GNUNET_free(buffer); | 338 | GNUNET_free (buffer); |
304 | return GNUNET_YES; | 339 | return GNUNET_YES; |
305 | } | 340 | } |
306 | 341 | ||
342 | |||
307 | static int | 343 | static int |
308 | iterate_save_links (void *cls, | 344 | iterate_save_links (void *cls, |
309 | const struct GNUNET_HashCode *key, | 345 | const struct GNUNET_HashCode *key, |
@@ -313,24 +349,28 @@ iterate_save_links (void *cls, | |||
313 | struct GNUNET_MESSENGER_MessageLink *link = value; | 349 | struct GNUNET_MESSENGER_MessageLink *link = value; |
314 | 350 | ||
315 | GNUNET_DISK_file_write (save->storage, key, sizeof(*key)); | 351 | GNUNET_DISK_file_write (save->storage, key, sizeof(*key)); |
316 | GNUNET_DISK_file_write (save->storage, &(link->multiple), sizeof(link->multiple)); | 352 | GNUNET_DISK_file_write (save->storage, &(link->multiple), |
353 | sizeof(link->multiple)); | ||
317 | GNUNET_DISK_file_write (save->storage, &(link->first), sizeof(link->first)); | 354 | GNUNET_DISK_file_write (save->storage, &(link->first), sizeof(link->first)); |
318 | 355 | ||
319 | if (GNUNET_YES == link->multiple) | 356 | if (GNUNET_YES == link->multiple) |
320 | GNUNET_DISK_file_write (save->storage, &(link->second), sizeof(link->second)); | 357 | GNUNET_DISK_file_write (save->storage, &(link->second), |
358 | sizeof(link->second)); | ||
321 | 359 | ||
322 | return GNUNET_YES; | 360 | return GNUNET_YES; |
323 | } | 361 | } |
324 | 362 | ||
363 | |||
325 | void | 364 | void |
326 | save_message_store (struct GNUNET_MESSENGER_MessageStore *store, | 365 | save_message_store (struct GNUNET_MESSENGER_MessageStore *store, |
327 | const char *directory) | 366 | const char *directory) |
328 | { | 367 | { |
329 | GNUNET_assert((store) && (directory)); | 368 | GNUNET_assert ((store) && (directory)); |
330 | 369 | ||
331 | struct GNUNET_MESSENGER_ClosureMessageSave save; | 370 | struct GNUNET_MESSENGER_ClosureMessageSave save; |
332 | 371 | ||
333 | enum GNUNET_DISK_AccessPermissions permission = (GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); | 372 | enum GNUNET_DISK_AccessPermissions permission = (GNUNET_DISK_PERM_USER_READ |
373 | | GNUNET_DISK_PERM_USER_WRITE); | ||
334 | 374 | ||
335 | char *filename; | 375 | char *filename; |
336 | 376 | ||
@@ -340,17 +380,20 @@ save_message_store (struct GNUNET_MESSENGER_MessageStore *store, | |||
340 | GNUNET_asprintf (&filename, "%s%s", directory, "links.store"); | 380 | GNUNET_asprintf (&filename, "%s%s", directory, "links.store"); |
341 | 381 | ||
342 | save.store = store; | 382 | save.store = store; |
343 | save.storage = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, permission); | 383 | save.storage = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_WRITE |
384 | | GNUNET_DISK_OPEN_CREATE, permission); | ||
344 | 385 | ||
345 | GNUNET_free(filename); | 386 | GNUNET_free (filename); |
346 | 387 | ||
347 | if (!save.storage) | 388 | if (! save.storage) |
348 | goto save_entries; | 389 | goto save_entries; |
349 | 390 | ||
350 | if (GNUNET_SYSERR == GNUNET_DISK_file_seek (save.storage, 0, GNUNET_DISK_SEEK_SET)) | 391 | if (GNUNET_SYSERR == GNUNET_DISK_file_seek (save.storage, 0, |
392 | GNUNET_DISK_SEEK_SET)) | ||
351 | goto close_links; | 393 | goto close_links; |
352 | 394 | ||
353 | GNUNET_CONTAINER_multihashmap_iterate (store->links, iterate_save_links, &save); | 395 | GNUNET_CONTAINER_multihashmap_iterate (store->links, iterate_save_links, |
396 | &save); | ||
354 | store->write_links = GNUNET_NO; | 397 | store->write_links = GNUNET_NO; |
355 | 398 | ||
356 | close_links: | 399 | close_links: |
@@ -360,22 +403,26 @@ save_entries: | |||
360 | GNUNET_asprintf (&filename, "%s%s", directory, "entries.store"); | 403 | GNUNET_asprintf (&filename, "%s%s", directory, "entries.store"); |
361 | 404 | ||
362 | save.store = store; | 405 | save.store = store; |
363 | save.storage = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, permission); | 406 | save.storage = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_WRITE |
407 | | GNUNET_DISK_OPEN_CREATE, permission); | ||
364 | 408 | ||
365 | GNUNET_free(filename); | 409 | GNUNET_free (filename); |
366 | 410 | ||
367 | if (!save.storage) | 411 | if (! save.storage) |
368 | return; | 412 | return; |
369 | 413 | ||
370 | if (GNUNET_YES == store->rewrite_entries) | 414 | if (GNUNET_YES == store->rewrite_entries) |
371 | { | 415 | { |
372 | if (GNUNET_SYSERR == GNUNET_DISK_file_seek (save.storage, 0, GNUNET_DISK_SEEK_SET)) | 416 | if (GNUNET_SYSERR == GNUNET_DISK_file_seek (save.storage, 0, |
417 | GNUNET_DISK_SEEK_SET)) | ||
373 | goto close_entries; | 418 | goto close_entries; |
374 | 419 | ||
375 | GNUNET_CONTAINER_multihashmap_iterate (store->entries, iterate_save_entries, &save); | 420 | GNUNET_CONTAINER_multihashmap_iterate (store->entries, iterate_save_entries, |
421 | &save); | ||
376 | store->rewrite_entries = GNUNET_NO; | 422 | store->rewrite_entries = GNUNET_NO; |
377 | } | 423 | } |
378 | else if (GNUNET_SYSERR == GNUNET_DISK_file_seek (save.storage, 0, GNUNET_DISK_SEEK_END)) | 424 | else if (GNUNET_SYSERR == GNUNET_DISK_file_seek (save.storage, 0, |
425 | GNUNET_DISK_SEEK_END)) | ||
379 | goto close_entries; | 426 | goto close_entries; |
380 | 427 | ||
381 | if (store->storage_messages) | 428 | if (store->storage_messages) |
@@ -383,14 +430,17 @@ save_entries: | |||
383 | 430 | ||
384 | GNUNET_asprintf (&filename, "%s%s", directory, "messages.store"); | 431 | GNUNET_asprintf (&filename, "%s%s", directory, "messages.store"); |
385 | 432 | ||
386 | store->storage_messages = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READWRITE | GNUNET_DISK_OPEN_CREATE, | 433 | store->storage_messages = GNUNET_DISK_file_open (filename, |
434 | GNUNET_DISK_OPEN_READWRITE | ||
435 | | GNUNET_DISK_OPEN_CREATE, | ||
387 | permission); | 436 | permission); |
388 | 437 | ||
389 | GNUNET_free(filename); | 438 | GNUNET_free (filename); |
390 | 439 | ||
391 | if (store->storage_messages) | 440 | if (store->storage_messages) |
392 | { | 441 | { |
393 | GNUNET_CONTAINER_multihashmap_iterate (store->messages, iterate_save_messages, &save); | 442 | GNUNET_CONTAINER_multihashmap_iterate (store->messages, |
443 | iterate_save_messages, &save); | ||
394 | 444 | ||
395 | GNUNET_DISK_file_sync (store->storage_messages); | 445 | GNUNET_DISK_file_sync (store->storage_messages); |
396 | GNUNET_DISK_file_sync (save.storage); | 446 | GNUNET_DISK_file_sync (save.storage); |
@@ -400,80 +450,94 @@ close_entries: | |||
400 | GNUNET_DISK_file_close (save.storage); | 450 | GNUNET_DISK_file_close (save.storage); |
401 | } | 451 | } |
402 | 452 | ||
453 | |||
403 | int | 454 | int |
404 | contains_store_message (const struct GNUNET_MESSENGER_MessageStore *store, | 455 | contains_store_message (const struct GNUNET_MESSENGER_MessageStore *store, |
405 | const struct GNUNET_HashCode *hash) | 456 | const struct GNUNET_HashCode *hash) |
406 | { | 457 | { |
407 | GNUNET_assert((store) && (hash)); | 458 | GNUNET_assert ((store) && (hash)); |
408 | 459 | ||
409 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (store->messages, hash)) | 460 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (store->messages, |
461 | hash)) | ||
410 | return GNUNET_YES; | 462 | return GNUNET_YES; |
411 | 463 | ||
412 | return GNUNET_CONTAINER_multihashmap_contains (store->entries, hash); | 464 | return GNUNET_CONTAINER_multihashmap_contains (store->entries, hash); |
413 | } | 465 | } |
414 | 466 | ||
467 | |||
415 | const struct GNUNET_MESSENGER_Message* | 468 | const struct GNUNET_MESSENGER_Message* |
416 | get_store_message (struct GNUNET_MESSENGER_MessageStore *store, | 469 | get_store_message (struct GNUNET_MESSENGER_MessageStore *store, |
417 | const struct GNUNET_HashCode *hash) | 470 | const struct GNUNET_HashCode *hash) |
418 | { | 471 | { |
419 | GNUNET_assert((store) && (hash)); | 472 | GNUNET_assert ((store) && (hash)); |
420 | 473 | ||
421 | struct GNUNET_MESSENGER_Message *message = GNUNET_CONTAINER_multihashmap_get (store->messages, hash); | 474 | struct GNUNET_MESSENGER_Message *message = GNUNET_CONTAINER_multihashmap_get ( |
475 | store->messages, hash); | ||
422 | 476 | ||
423 | if (message) | 477 | if (message) |
424 | return message; | 478 | return message; |
425 | 479 | ||
426 | if (!store->storage_messages) | 480 | if (! store->storage_messages) |
427 | return NULL; | 481 | return NULL; |
428 | 482 | ||
429 | const struct GNUNET_MESSENGER_MessageEntry *entry = GNUNET_CONTAINER_multihashmap_get (store->entries, hash); | 483 | const struct GNUNET_MESSENGER_MessageEntry *entry = |
484 | GNUNET_CONTAINER_multihashmap_get (store->entries, hash); | ||
430 | 485 | ||
431 | if (!entry) | 486 | if (! entry) |
432 | return NULL; | 487 | return NULL; |
433 | 488 | ||
434 | if (entry->offset != GNUNET_DISK_file_seek (store->storage_messages, entry->offset, GNUNET_DISK_SEEK_SET)) | 489 | if (entry->offset != GNUNET_DISK_file_seek (store->storage_messages, |
490 | entry->offset, | ||
491 | GNUNET_DISK_SEEK_SET)) | ||
435 | return message; | 492 | return message; |
436 | 493 | ||
437 | char *buffer = GNUNET_malloc(entry->length); | 494 | char *buffer = GNUNET_malloc (entry->length); |
438 | 495 | ||
439 | if (!buffer) | 496 | if (! buffer) |
440 | return NULL; | 497 | return NULL; |
441 | 498 | ||
442 | if ((GNUNET_DISK_file_read (store->storage_messages, buffer, entry->length) != entry->length) || | 499 | if ((GNUNET_DISK_file_read (store->storage_messages, buffer, entry->length) != |
443 | (entry->length < get_message_kind_size(GNUNET_MESSENGER_KIND_UNKNOWN, GNUNET_YES))) | 500 | entry->length) || |
501 | (entry->length < get_message_kind_size (GNUNET_MESSENGER_KIND_UNKNOWN, | ||
502 | GNUNET_YES))) | ||
444 | goto free_buffer; | 503 | goto free_buffer; |
445 | 504 | ||
446 | message = create_message (GNUNET_MESSENGER_KIND_UNKNOWN); | 505 | message = create_message (GNUNET_MESSENGER_KIND_UNKNOWN); |
447 | 506 | ||
448 | const int decoding = decode_message (message, entry->length, buffer, GNUNET_YES, NULL); | 507 | const int decoding = decode_message (message, entry->length, buffer, |
508 | GNUNET_YES, NULL); | ||
449 | 509 | ||
450 | struct GNUNET_HashCode check; | 510 | struct GNUNET_HashCode check; |
451 | hash_message (message, entry->length, buffer, &check); | 511 | hash_message (message, entry->length, buffer, &check); |
452 | 512 | ||
453 | if ((GNUNET_YES != decoding) || (GNUNET_CRYPTO_hash_cmp (hash, &check) != 0)) | 513 | if ((GNUNET_YES != decoding) || (GNUNET_CRYPTO_hash_cmp (hash, &check) != 0)) |
454 | { | 514 | { |
455 | if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (store->entries, hash, entry)) | 515 | if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (store->entries, |
456 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Corrupted entry could not be removed from store: %s\n", | 516 | hash, entry)) |
457 | GNUNET_h2s(hash)); | 517 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
518 | "Corrupted entry could not be removed from store: %s\n", | ||
519 | GNUNET_h2s (hash)); | ||
458 | 520 | ||
459 | store->rewrite_entries = GNUNET_YES; | 521 | store->rewrite_entries = GNUNET_YES; |
460 | 522 | ||
461 | goto free_message; | 523 | goto free_message; |
462 | } | 524 | } |
463 | 525 | ||
464 | if (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (store->messages, hash, message, | 526 | if (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (store->messages, hash, |
527 | message, | ||
465 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | 528 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) |
466 | goto free_buffer; | 529 | goto free_buffer; |
467 | 530 | ||
468 | free_message: destroy_message (message); | 531 | free_message : destroy_message (message); |
469 | message = NULL; | 532 | message = NULL; |
470 | 533 | ||
471 | free_buffer: | 534 | free_buffer: |
472 | GNUNET_free(buffer); | 535 | GNUNET_free (buffer); |
473 | 536 | ||
474 | return message; | 537 | return message; |
475 | } | 538 | } |
476 | 539 | ||
540 | |||
477 | const struct GNUNET_MESSENGER_MessageLink* | 541 | const struct GNUNET_MESSENGER_MessageLink* |
478 | get_store_message_link (struct GNUNET_MESSENGER_MessageStore *store, | 542 | get_store_message_link (struct GNUNET_MESSENGER_MessageStore *store, |
479 | const struct GNUNET_HashCode *hash, | 543 | const struct GNUNET_HashCode *hash, |
@@ -482,21 +546,26 @@ get_store_message_link (struct GNUNET_MESSENGER_MessageStore *store, | |||
482 | if (deleted_only) | 546 | if (deleted_only) |
483 | goto get_link; | 547 | goto get_link; |
484 | 548 | ||
485 | const struct GNUNET_MESSENGER_Message *message = get_store_message(store, hash); | 549 | const struct GNUNET_MESSENGER_Message *message = get_store_message (store, |
550 | hash); | ||
486 | 551 | ||
487 | if (!message) | 552 | if (! message) |
488 | goto get_link; | 553 | goto get_link; |
489 | 554 | ||
490 | static struct GNUNET_MESSENGER_MessageLink link; | 555 | static struct GNUNET_MESSENGER_MessageLink link; |
491 | 556 | ||
492 | GNUNET_memcpy(&(link.first), &(message->header.previous), sizeof(link.first)); | 557 | GNUNET_memcpy (&(link.first), &(message->header.previous), |
558 | sizeof(link.first)); | ||
493 | 559 | ||
494 | link.multiple = GNUNET_MESSENGER_KIND_MERGE == message->header.kind? GNUNET_YES : GNUNET_NO; | 560 | link.multiple = GNUNET_MESSENGER_KIND_MERGE == message->header.kind? |
561 | GNUNET_YES : GNUNET_NO; | ||
495 | 562 | ||
496 | if (GNUNET_YES == link.multiple) | 563 | if (GNUNET_YES == link.multiple) |
497 | GNUNET_memcpy(&(link.second), &(message->body.merge.previous), sizeof(link.second)); | 564 | GNUNET_memcpy (&(link.second), &(message->body.merge.previous), |
565 | sizeof(link.second)); | ||
498 | else | 566 | else |
499 | GNUNET_memcpy(&(link.second), &(message->header.previous), sizeof(link.second)); | 567 | GNUNET_memcpy (&(link.second), &(message->header.previous), |
568 | sizeof(link.second)); | ||
500 | 569 | ||
501 | return &link; | 570 | return &link; |
502 | 571 | ||
@@ -504,78 +573,95 @@ get_link: | |||
504 | return GNUNET_CONTAINER_multihashmap_get (store->links, hash); | 573 | return GNUNET_CONTAINER_multihashmap_get (store->links, hash); |
505 | } | 574 | } |
506 | 575 | ||
576 | |||
507 | int | 577 | int |
508 | put_store_message (struct GNUNET_MESSENGER_MessageStore *store, | 578 | put_store_message (struct GNUNET_MESSENGER_MessageStore *store, |
509 | const struct GNUNET_HashCode *hash, | 579 | const struct GNUNET_HashCode *hash, |
510 | struct GNUNET_MESSENGER_Message *message) | 580 | struct GNUNET_MESSENGER_Message *message) |
511 | { | 581 | { |
512 | GNUNET_assert((store) && (hash) && (message)); | 582 | GNUNET_assert ((store) && (hash) && (message)); |
513 | 583 | ||
514 | return GNUNET_CONTAINER_multihashmap_put (store->messages, hash, message, | 584 | return GNUNET_CONTAINER_multihashmap_put (store->messages, hash, message, |
515 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 585 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); |
516 | } | 586 | } |
517 | 587 | ||
588 | |||
518 | static void | 589 | static void |
519 | add_link (struct GNUNET_MESSENGER_MessageStore *store, | 590 | add_link (struct GNUNET_MESSENGER_MessageStore *store, |
520 | const struct GNUNET_HashCode *hash, | 591 | const struct GNUNET_HashCode *hash, |
521 | const struct GNUNET_MESSENGER_Message *message) | 592 | const struct GNUNET_MESSENGER_Message *message) |
522 | { | 593 | { |
523 | struct GNUNET_MESSENGER_MessageLink *link = GNUNET_new(struct GNUNET_MESSENGER_MessageLink); | 594 | struct GNUNET_MESSENGER_MessageLink *link = GNUNET_new (struct |
595 | GNUNET_MESSENGER_MessageLink); | ||
524 | 596 | ||
525 | GNUNET_memcpy(&(link->first), &(message->header.previous), sizeof(link->first)); | 597 | GNUNET_memcpy (&(link->first), &(message->header.previous), |
598 | sizeof(link->first)); | ||
526 | 599 | ||
527 | link->multiple = GNUNET_MESSENGER_KIND_MERGE == message->header.kind? GNUNET_YES : GNUNET_NO; | 600 | link->multiple = GNUNET_MESSENGER_KIND_MERGE == message->header.kind? |
601 | GNUNET_YES : GNUNET_NO; | ||
528 | 602 | ||
529 | if (GNUNET_YES == link->multiple) | 603 | if (GNUNET_YES == link->multiple) |
530 | GNUNET_memcpy(&(link->second), &(message->body.merge.previous), sizeof(link->second)); | 604 | GNUNET_memcpy (&(link->second), &(message->body.merge.previous), |
605 | sizeof(link->second)); | ||
531 | else | 606 | else |
532 | GNUNET_memcpy(&(link->second), &(message->header.previous), sizeof(link->second)); | 607 | GNUNET_memcpy (&(link->second), &(message->header.previous), |
608 | sizeof(link->second)); | ||
533 | 609 | ||
534 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put(store->links, hash, link, | 610 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (store->links, hash, link, |
535 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | 611 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) |
536 | GNUNET_free(link); | 612 | GNUNET_free (link); |
537 | } | 613 | } |
538 | 614 | ||
615 | |||
539 | int | 616 | int |
540 | delete_store_message (struct GNUNET_MESSENGER_MessageStore *store, | 617 | delete_store_message (struct GNUNET_MESSENGER_MessageStore *store, |
541 | const struct GNUNET_HashCode *hash) | 618 | const struct GNUNET_HashCode *hash) |
542 | { | 619 | { |
543 | GNUNET_assert((store) && (hash)); | 620 | GNUNET_assert ((store) && (hash)); |
544 | 621 | ||
545 | const struct GNUNET_MESSENGER_MessageEntry *entry = GNUNET_CONTAINER_multihashmap_get (store->entries, hash); | 622 | const struct GNUNET_MESSENGER_MessageEntry *entry = |
623 | GNUNET_CONTAINER_multihashmap_get (store->entries, hash); | ||
546 | 624 | ||
547 | if (!entry) | 625 | if (! entry) |
548 | goto clear_memory; | 626 | goto clear_memory; |
549 | 627 | ||
550 | const struct GNUNET_MESSENGER_Message *message = get_store_message(store, hash); | 628 | const struct GNUNET_MESSENGER_Message *message = get_store_message (store, |
629 | hash); | ||
551 | 630 | ||
552 | if (message) | 631 | if (message) |
553 | add_link (store, hash, message); | 632 | add_link (store, hash, message); |
554 | 633 | ||
555 | if (!store->storage_messages) | 634 | if (! store->storage_messages) |
556 | goto clear_entry; | 635 | goto clear_entry; |
557 | 636 | ||
558 | if (entry->offset != GNUNET_DISK_file_seek (store->storage_messages, entry->offset, GNUNET_DISK_SEEK_SET)) | 637 | if (entry->offset != GNUNET_DISK_file_seek (store->storage_messages, |
638 | entry->offset, | ||
639 | GNUNET_DISK_SEEK_SET)) | ||
559 | return GNUNET_SYSERR; | 640 | return GNUNET_SYSERR; |
560 | 641 | ||
561 | char *clear_buffer = GNUNET_malloc(entry->length); | 642 | char *clear_buffer = GNUNET_malloc (entry->length); |
562 | 643 | ||
563 | if (!clear_buffer) | 644 | if (! clear_buffer) |
564 | return GNUNET_SYSERR; | 645 | return GNUNET_SYSERR; |
565 | 646 | ||
566 | GNUNET_CRYPTO_zero_keys (clear_buffer, entry->length); | 647 | GNUNET_CRYPTO_zero_keys (clear_buffer, entry->length); |
567 | 648 | ||
568 | if ((entry->length != GNUNET_DISK_file_write (store->storage_messages, clear_buffer, entry->length)) || (GNUNET_OK | 649 | if ((entry->length != GNUNET_DISK_file_write (store->storage_messages, |
569 | != GNUNET_DISK_file_sync (store->storage_messages))) | 650 | clear_buffer, entry->length)) || |
651 | (GNUNET_OK | ||
652 | != | ||
653 | GNUNET_DISK_file_sync ( | ||
654 | store->storage_messages))) | ||
570 | { | 655 | { |
571 | GNUNET_free(clear_buffer); | 656 | GNUNET_free (clear_buffer); |
572 | return GNUNET_SYSERR; | 657 | return GNUNET_SYSERR; |
573 | } | 658 | } |
574 | 659 | ||
575 | GNUNET_free(clear_buffer); | 660 | GNUNET_free (clear_buffer); |
576 | 661 | ||
577 | clear_entry: | 662 | clear_entry: |
578 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (store->entries, hash, entry)) | 663 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (store->entries, hash, |
664 | entry)) | ||
579 | store->rewrite_entries = GNUNET_YES; | 665 | store->rewrite_entries = GNUNET_YES; |
580 | 666 | ||
581 | clear_memory: | 667 | clear_memory: |
diff --git a/src/messenger/gnunet-service-messenger_operation.c b/src/messenger/gnunet-service-messenger_operation.c index 9c4201fdf..f13db7de0 100644 --- a/src/messenger/gnunet-service-messenger_operation.c +++ b/src/messenger/gnunet-service-messenger_operation.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2021 GNUnet e.V. | 3 | Copyright (C) 2021, 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 |
@@ -31,30 +31,33 @@ | |||
31 | struct GNUNET_MESSENGER_Operation* | 31 | struct GNUNET_MESSENGER_Operation* |
32 | create_operation (const struct GNUNET_HashCode *hash) | 32 | create_operation (const struct GNUNET_HashCode *hash) |
33 | { | 33 | { |
34 | GNUNET_assert(hash); | 34 | GNUNET_assert (hash); |
35 | 35 | ||
36 | struct GNUNET_MESSENGER_Operation *op = GNUNET_new(struct GNUNET_MESSENGER_Operation); | 36 | struct GNUNET_MESSENGER_Operation *op = GNUNET_new (struct |
37 | GNUNET_MESSENGER_Operation); | ||
37 | 38 | ||
38 | op->type = GNUNET_MESSENGER_OP_UNKNOWN; | 39 | op->type = GNUNET_MESSENGER_OP_UNKNOWN; |
39 | GNUNET_memcpy(&(op->hash), hash, sizeof(*hash)); | 40 | GNUNET_memcpy (&(op->hash), hash, sizeof(*hash)); |
40 | op->timestamp = GNUNET_TIME_absolute_get_zero_(); | 41 | op->timestamp = GNUNET_TIME_absolute_get_zero_ (); |
41 | op->store = NULL; | 42 | op->store = NULL; |
42 | op->task = NULL; | 43 | op->task = NULL; |
43 | 44 | ||
44 | return op; | 45 | return op; |
45 | } | 46 | } |
46 | 47 | ||
48 | |||
47 | void | 49 | void |
48 | destroy_operation (struct GNUNET_MESSENGER_Operation *op) | 50 | destroy_operation (struct GNUNET_MESSENGER_Operation *op) |
49 | { | 51 | { |
50 | GNUNET_assert(op); | 52 | GNUNET_assert (op); |
51 | 53 | ||
52 | if (op->task) | 54 | if (op->task) |
53 | GNUNET_SCHEDULER_cancel(op->task); | 55 | GNUNET_SCHEDULER_cancel (op->task); |
54 | 56 | ||
55 | GNUNET_free(op); | 57 | GNUNET_free (op); |
56 | } | 58 | } |
57 | 59 | ||
60 | |||
58 | static void | 61 | static void |
59 | callback_operation (void *cls); | 62 | callback_operation (void *cls); |
60 | 63 | ||
@@ -62,25 +65,28 @@ struct GNUNET_MESSENGER_Operation* | |||
62 | load_operation (struct GNUNET_MESSENGER_OperationStore *store, | 65 | load_operation (struct GNUNET_MESSENGER_OperationStore *store, |
63 | const char *path) | 66 | const char *path) |
64 | { | 67 | { |
65 | GNUNET_assert((store) && (path)); | 68 | GNUNET_assert ((store) && (path)); |
66 | 69 | ||
67 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Load operation configuration: %s\n", path); | 70 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Load operation configuration: %s\n", |
71 | path); | ||
68 | 72 | ||
69 | struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create (); | 73 | struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create (); |
70 | struct GNUNET_MESSENGER_Operation* op = NULL; | 74 | struct GNUNET_MESSENGER_Operation *op = NULL; |
71 | 75 | ||
72 | if (GNUNET_OK != GNUNET_CONFIGURATION_parse(cfg, path)) | 76 | if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, path)) |
73 | goto destroy_config; | 77 | goto destroy_config; |
74 | 78 | ||
75 | struct GNUNET_HashCode hash; | 79 | struct GNUNET_HashCode hash; |
76 | 80 | ||
77 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_data (cfg, "operation", "hash", &hash, sizeof(hash))) | 81 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_data (cfg, "operation", "hash", |
82 | &hash, sizeof(hash))) | ||
78 | goto destroy_config; | 83 | goto destroy_config; |
79 | 84 | ||
80 | op = create_operation(&hash); | 85 | op = create_operation (&hash); |
81 | 86 | ||
82 | unsigned long long type_number; | 87 | unsigned long long type_number; |
83 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(cfg, "operation", "type", &type_number)) | 88 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "operation", |
89 | "type", &type_number)) | ||
84 | switch (type_number) | 90 | switch (type_number) |
85 | { | 91 | { |
86 | case GNUNET_MESSENGER_OP_REQUEST: | 92 | case GNUNET_MESSENGER_OP_REQUEST: |
@@ -97,21 +103,25 @@ load_operation (struct GNUNET_MESSENGER_OperationStore *store, | |||
97 | } | 103 | } |
98 | 104 | ||
99 | if ((GNUNET_MESSENGER_OP_UNKNOWN == op->type) || | 105 | if ((GNUNET_MESSENGER_OP_UNKNOWN == op->type) || |
100 | (GNUNET_OK != GNUNET_CONFIGURATION_get_data (cfg, "operation", "timestamp", &(op->timestamp), sizeof(op->timestamp)))) | 106 | (GNUNET_OK != GNUNET_CONFIGURATION_get_data (cfg, "operation", |
107 | "timestamp", | ||
108 | &(op->timestamp), | ||
109 | sizeof(op->timestamp)))) | ||
101 | { | 110 | { |
102 | destroy_operation(op); | 111 | destroy_operation (op); |
103 | op = NULL; | 112 | op = NULL; |
104 | goto destroy_config; | 113 | goto destroy_config; |
105 | } | 114 | } |
106 | 115 | ||
107 | const struct GNUNET_TIME_Relative delay = GNUNET_TIME_absolute_get_remaining(op->timestamp); | 116 | const struct GNUNET_TIME_Relative delay = GNUNET_TIME_absolute_get_remaining ( |
117 | op->timestamp); | ||
108 | 118 | ||
109 | op->task = GNUNET_SCHEDULER_add_delayed_with_priority( | 119 | op->task = GNUNET_SCHEDULER_add_delayed_with_priority ( |
110 | delay, | 120 | delay, |
111 | GNUNET_SCHEDULER_PRIORITY_BACKGROUND, | 121 | GNUNET_SCHEDULER_PRIORITY_BACKGROUND, |
112 | callback_operation, | 122 | callback_operation, |
113 | op | 123 | op |
114 | ); | 124 | ); |
115 | 125 | ||
116 | op->store = store; | 126 | op->store = store; |
117 | 127 | ||
@@ -121,42 +131,48 @@ destroy_config: | |||
121 | return op; | 131 | return op; |
122 | } | 132 | } |
123 | 133 | ||
134 | |||
124 | void | 135 | void |
125 | save_operation (const struct GNUNET_MESSENGER_Operation *op, | 136 | save_operation (const struct GNUNET_MESSENGER_Operation *op, |
126 | const char *path) | 137 | const char *path) |
127 | { | 138 | { |
128 | GNUNET_assert((path) && (op)); | 139 | GNUNET_assert ((path) && (op)); |
129 | 140 | ||
130 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Save operation configuration: %s\n", path); | 141 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Save operation configuration: %s\n", |
142 | path); | ||
131 | 143 | ||
132 | struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create (); | 144 | struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create (); |
133 | 145 | ||
134 | char *hash_data; | 146 | char *hash_data; |
135 | hash_data = GNUNET_STRINGS_data_to_string_alloc (&(op->hash), sizeof(op->hash)); | 147 | hash_data = GNUNET_STRINGS_data_to_string_alloc (&(op->hash), |
148 | sizeof(op->hash)); | ||
136 | 149 | ||
137 | if (hash_data) | 150 | if (hash_data) |
138 | { | 151 | { |
139 | GNUNET_CONFIGURATION_set_value_string (cfg, "operation", "hash", hash_data); | 152 | GNUNET_CONFIGURATION_set_value_string (cfg, "operation", "hash", hash_data); |
140 | 153 | ||
141 | GNUNET_free(hash_data); | 154 | GNUNET_free (hash_data); |
142 | } | 155 | } |
143 | 156 | ||
144 | GNUNET_CONFIGURATION_set_value_number(cfg, "operation", "type", op->type); | 157 | GNUNET_CONFIGURATION_set_value_number (cfg, "operation", "type", op->type); |
145 | 158 | ||
146 | char *timestamp_data; | 159 | char *timestamp_data; |
147 | timestamp_data = GNUNET_STRINGS_data_to_string_alloc (&(op->timestamp), sizeof(op->timestamp)); | 160 | timestamp_data = GNUNET_STRINGS_data_to_string_alloc (&(op->timestamp), |
161 | sizeof(op->timestamp)); | ||
148 | 162 | ||
149 | if (timestamp_data) | 163 | if (timestamp_data) |
150 | { | 164 | { |
151 | GNUNET_CONFIGURATION_set_value_string (cfg, "operation", "timestamp", timestamp_data); | 165 | GNUNET_CONFIGURATION_set_value_string (cfg, "operation", "timestamp", |
166 | timestamp_data); | ||
152 | 167 | ||
153 | GNUNET_free(timestamp_data); | 168 | GNUNET_free (timestamp_data); |
154 | } | 169 | } |
155 | 170 | ||
156 | GNUNET_CONFIGURATION_write (cfg, path); | 171 | GNUNET_CONFIGURATION_write (cfg, path); |
157 | GNUNET_CONFIGURATION_destroy (cfg); | 172 | GNUNET_CONFIGURATION_destroy (cfg); |
158 | } | 173 | } |
159 | 174 | ||
175 | |||
160 | extern void | 176 | extern void |
161 | callback_store_operation (struct GNUNET_MESSENGER_OperationStore *store, | 177 | callback_store_operation (struct GNUNET_MESSENGER_OperationStore *store, |
162 | enum GNUNET_MESSENGER_OperationType type, | 178 | enum GNUNET_MESSENGER_OperationType type, |
@@ -172,28 +188,29 @@ callback_operation (void *cls) | |||
172 | callback_store_operation (op->store, op->type, &(op->hash)); | 188 | callback_store_operation (op->store, op->type, &(op->hash)); |
173 | } | 189 | } |
174 | 190 | ||
191 | |||
175 | int | 192 | int |
176 | start_operation (struct GNUNET_MESSENGER_Operation *op, | 193 | start_operation (struct GNUNET_MESSENGER_Operation *op, |
177 | enum GNUNET_MESSENGER_OperationType type, | 194 | enum GNUNET_MESSENGER_OperationType type, |
178 | struct GNUNET_MESSENGER_OperationStore *store, | 195 | struct GNUNET_MESSENGER_OperationStore *store, |
179 | struct GNUNET_TIME_Relative delay) | 196 | struct GNUNET_TIME_Relative delay) |
180 | { | 197 | { |
181 | GNUNET_assert((op) && (store)); | 198 | GNUNET_assert ((op) && (store)); |
182 | 199 | ||
183 | if (op->task) | 200 | if (op->task) |
184 | return GNUNET_SYSERR; | 201 | return GNUNET_SYSERR; |
185 | 202 | ||
186 | const struct GNUNET_TIME_Absolute timestamp = GNUNET_TIME_absolute_add( | 203 | const struct GNUNET_TIME_Absolute timestamp = GNUNET_TIME_absolute_add ( |
187 | GNUNET_TIME_absolute_get(), | 204 | GNUNET_TIME_absolute_get (), |
188 | delay | 205 | delay |
189 | ); | 206 | ); |
190 | 207 | ||
191 | op->task = GNUNET_SCHEDULER_add_delayed_with_priority( | 208 | op->task = GNUNET_SCHEDULER_add_delayed_with_priority ( |
192 | delay, | 209 | delay, |
193 | GNUNET_SCHEDULER_PRIORITY_BACKGROUND, | 210 | GNUNET_SCHEDULER_PRIORITY_BACKGROUND, |
194 | callback_operation, | 211 | callback_operation, |
195 | op | 212 | op |
196 | ); | 213 | ); |
197 | 214 | ||
198 | op->type = type; | 215 | op->type = type; |
199 | op->timestamp = timestamp; | 216 | op->timestamp = timestamp; |
@@ -202,19 +219,20 @@ start_operation (struct GNUNET_MESSENGER_Operation *op, | |||
202 | return GNUNET_OK; | 219 | return GNUNET_OK; |
203 | } | 220 | } |
204 | 221 | ||
222 | |||
205 | int | 223 | int |
206 | stop_operation (struct GNUNET_MESSENGER_Operation *op) | 224 | stop_operation (struct GNUNET_MESSENGER_Operation *op) |
207 | { | 225 | { |
208 | GNUNET_assert(op); | 226 | GNUNET_assert (op); |
209 | 227 | ||
210 | if (!op->task) | 228 | if (! op->task) |
211 | return GNUNET_SYSERR; | 229 | return GNUNET_SYSERR; |
212 | 230 | ||
213 | GNUNET_SCHEDULER_cancel(op->task); | 231 | GNUNET_SCHEDULER_cancel (op->task); |
214 | op->task = NULL; | 232 | op->task = NULL; |
215 | 233 | ||
216 | op->type = GNUNET_MESSENGER_OP_UNKNOWN; | 234 | op->type = GNUNET_MESSENGER_OP_UNKNOWN; |
217 | op->timestamp = GNUNET_TIME_absolute_get_zero_(); | 235 | op->timestamp = GNUNET_TIME_absolute_get_zero_ (); |
218 | op->store = NULL; | 236 | op->store = NULL; |
219 | 237 | ||
220 | return GNUNET_OK; | 238 | return GNUNET_OK; |
diff --git a/src/messenger/gnunet-service-messenger_operation.h b/src/messenger/gnunet-service-messenger_operation.h index b93282d24..6631693cf 100644 --- a/src/messenger/gnunet-service-messenger_operation.h +++ b/src/messenger/gnunet-service-messenger_operation.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2021 GNUnet e.V. | 3 | Copyright (C) 2021, 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 |
@@ -51,7 +51,7 @@ struct GNUNET_MESSENGER_Operation | |||
51 | struct GNUNET_TIME_Absolute timestamp; | 51 | struct GNUNET_TIME_Absolute timestamp; |
52 | 52 | ||
53 | struct GNUNET_MESSENGER_OperationStore *store; | 53 | struct GNUNET_MESSENGER_OperationStore *store; |
54 | struct GNUNET_SCHEDULER_Task* task; | 54 | struct GNUNET_SCHEDULER_Task *task; |
55 | }; | 55 | }; |
56 | 56 | ||
57 | /** | 57 | /** |
diff --git a/src/messenger/gnunet-service-messenger_operation_store.c b/src/messenger/gnunet-service-messenger_operation_store.c index 6a639d69e..670d5cdf5 100644 --- a/src/messenger/gnunet-service-messenger_operation_store.c +++ b/src/messenger/gnunet-service-messenger_operation_store.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2021 GNUnet e.V. | 3 | Copyright (C) 2021, 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 |
@@ -33,12 +33,13 @@ void | |||
33 | init_operation_store (struct GNUNET_MESSENGER_OperationStore *store, | 33 | init_operation_store (struct GNUNET_MESSENGER_OperationStore *store, |
34 | struct GNUNET_MESSENGER_SrvRoom *room) | 34 | struct GNUNET_MESSENGER_SrvRoom *room) |
35 | { | 35 | { |
36 | GNUNET_assert((store) && (room)); | 36 | GNUNET_assert ((store) && (room)); |
37 | 37 | ||
38 | store->room = room; | 38 | store->room = room; |
39 | store->operations = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO); | 39 | store->operations = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); |
40 | } | 40 | } |
41 | 41 | ||
42 | |||
42 | static int | 43 | static int |
43 | iterate_destroy_operations (void *cls, | 44 | iterate_destroy_operations (void *cls, |
44 | const struct GNUNET_HashCode *key, | 45 | const struct GNUNET_HashCode *key, |
@@ -46,20 +47,23 @@ iterate_destroy_operations (void *cls, | |||
46 | { | 47 | { |
47 | struct GNUNET_MESSENGER_Operation *op = value; | 48 | struct GNUNET_MESSENGER_Operation *op = value; |
48 | 49 | ||
49 | destroy_operation(op); | 50 | destroy_operation (op); |
50 | 51 | ||
51 | return GNUNET_YES; | 52 | return GNUNET_YES; |
52 | } | 53 | } |
53 | 54 | ||
55 | |||
54 | void | 56 | void |
55 | clear_operation_store (struct GNUNET_MESSENGER_OperationStore *store) | 57 | clear_operation_store (struct GNUNET_MESSENGER_OperationStore *store) |
56 | { | 58 | { |
57 | GNUNET_assert(store); | 59 | GNUNET_assert (store); |
58 | 60 | ||
59 | GNUNET_CONTAINER_multihashmap_iterate (store->operations, iterate_destroy_operations, NULL); | 61 | GNUNET_CONTAINER_multihashmap_iterate (store->operations, |
60 | GNUNET_CONTAINER_multihashmap_destroy(store->operations); | 62 | iterate_destroy_operations, NULL); |
63 | GNUNET_CONTAINER_multihashmap_destroy (store->operations); | ||
61 | } | 64 | } |
62 | 65 | ||
66 | |||
63 | static int | 67 | static int |
64 | callback_scan_for_operations (void *cls, | 68 | callback_scan_for_operations (void *cls, |
65 | const char *filename) | 69 | const char *filename) |
@@ -69,37 +73,40 @@ callback_scan_for_operations (void *cls, | |||
69 | if (GNUNET_YES != GNUNET_DISK_file_test (filename)) | 73 | if (GNUNET_YES != GNUNET_DISK_file_test (filename)) |
70 | return GNUNET_OK; | 74 | return GNUNET_OK; |
71 | 75 | ||
72 | if ((strlen(filename) <= 4) || (0 != strcmp(filename + strlen(filename) - 4, ".cfg"))) | 76 | if ((strlen (filename) <= 4) || (0 != strcmp (filename + strlen (filename) |
77 | - 4, ".cfg"))) | ||
73 | return GNUNET_OK; | 78 | return GNUNET_OK; |
74 | 79 | ||
75 | struct GNUNET_MESSENGER_Operation *op = load_operation(store, filename); | 80 | struct GNUNET_MESSENGER_Operation *op = load_operation (store, filename); |
76 | 81 | ||
77 | if ((op) && (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put( | 82 | if ((op) && (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put ( |
78 | store->operations, | 83 | store->operations, |
79 | &(op->hash), op, | 84 | &(op->hash), op, |
80 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))) | 85 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))) |
81 | { | 86 | { |
82 | destroy_operation(op); | 87 | destroy_operation (op); |
83 | } | 88 | } |
84 | 89 | ||
85 | return GNUNET_OK; | 90 | return GNUNET_OK; |
86 | } | 91 | } |
87 | 92 | ||
93 | |||
88 | void | 94 | void |
89 | load_operation_store (struct GNUNET_MESSENGER_OperationStore *store, | 95 | load_operation_store (struct GNUNET_MESSENGER_OperationStore *store, |
90 | const char *directory) | 96 | const char *directory) |
91 | { | 97 | { |
92 | GNUNET_assert ((store) && (directory)); | 98 | GNUNET_assert ((store) && (directory)); |
93 | 99 | ||
94 | char* load_dir; | 100 | char *load_dir; |
95 | GNUNET_asprintf (&load_dir, "%s%s%c", directory, "operations", DIR_SEPARATOR); | 101 | GNUNET_asprintf (&load_dir, "%s%s%c", directory, "operations", DIR_SEPARATOR); |
96 | 102 | ||
97 | if (GNUNET_OK == GNUNET_DISK_directory_test (load_dir, GNUNET_YES)) | 103 | if (GNUNET_OK == GNUNET_DISK_directory_test (load_dir, GNUNET_YES)) |
98 | GNUNET_DISK_directory_scan (load_dir, callback_scan_for_operations, store); | 104 | GNUNET_DISK_directory_scan (load_dir, callback_scan_for_operations, store); |
99 | 105 | ||
100 | GNUNET_free(load_dir); | 106 | GNUNET_free (load_dir); |
101 | } | 107 | } |
102 | 108 | ||
109 | |||
103 | static int | 110 | static int |
104 | iterate_save_operations (void *cls, | 111 | iterate_save_operations (void *cls, |
105 | const struct GNUNET_HashCode *key, | 112 | const struct GNUNET_HashCode *key, |
@@ -109,65 +116,73 @@ iterate_save_operations (void *cls, | |||
109 | 116 | ||
110 | struct GNUNET_MESSENGER_Operation *op = value; | 117 | struct GNUNET_MESSENGER_Operation *op = value; |
111 | 118 | ||
112 | if (!op) | 119 | if (! op) |
113 | return GNUNET_YES; | 120 | return GNUNET_YES; |
114 | 121 | ||
115 | char *op_dir; | 122 | char *op_dir; |
116 | GNUNET_asprintf (&op_dir, "%s%s.cfg", save_dir, GNUNET_h2s(key)); | 123 | GNUNET_asprintf (&op_dir, "%s%s.cfg", save_dir, GNUNET_h2s (key)); |
117 | save_operation(op, op_dir); | 124 | save_operation (op, op_dir); |
118 | 125 | ||
119 | GNUNET_free(op_dir); | 126 | GNUNET_free (op_dir); |
120 | return GNUNET_YES; | 127 | return GNUNET_YES; |
121 | } | 128 | } |
122 | 129 | ||
130 | |||
123 | void | 131 | void |
124 | save_operation_store (const struct GNUNET_MESSENGER_OperationStore *store, | 132 | save_operation_store (const struct GNUNET_MESSENGER_OperationStore *store, |
125 | const char *directory) | 133 | const char *directory) |
126 | { | 134 | { |
127 | GNUNET_assert ((store) && (directory)); | 135 | GNUNET_assert ((store) && (directory)); |
128 | 136 | ||
129 | char* save_dir; | 137 | char *save_dir; |
130 | GNUNET_asprintf (&save_dir, "%s%s%c", directory, "operations", DIR_SEPARATOR); | 138 | GNUNET_asprintf (&save_dir, "%s%s%c", directory, "operations", DIR_SEPARATOR); |
131 | 139 | ||
132 | if ((GNUNET_YES == GNUNET_DISK_directory_test (save_dir, GNUNET_NO)) || | 140 | if ((GNUNET_YES == GNUNET_DISK_directory_test (save_dir, GNUNET_NO)) || |
133 | (GNUNET_OK == GNUNET_DISK_directory_create (save_dir))) | 141 | (GNUNET_OK == GNUNET_DISK_directory_create (save_dir))) |
134 | GNUNET_CONTAINER_multihashmap_iterate (store->operations, iterate_save_operations, save_dir); | 142 | GNUNET_CONTAINER_multihashmap_iterate (store->operations, |
143 | iterate_save_operations, save_dir); | ||
135 | 144 | ||
136 | GNUNET_free(save_dir); | 145 | GNUNET_free (save_dir); |
137 | } | 146 | } |
138 | 147 | ||
148 | |||
139 | enum GNUNET_MESSENGER_OperationType | 149 | enum GNUNET_MESSENGER_OperationType |
140 | get_store_operation_type (const struct GNUNET_MESSENGER_OperationStore *store, | 150 | get_store_operation_type (const struct GNUNET_MESSENGER_OperationStore *store, |
141 | const struct GNUNET_HashCode *hash) | 151 | const struct GNUNET_HashCode *hash) |
142 | { | 152 | { |
143 | GNUNET_assert((store) && (hash)); | 153 | GNUNET_assert ((store) && (hash)); |
144 | 154 | ||
145 | struct GNUNET_MESSENGER_Operation *op = GNUNET_CONTAINER_multihashmap_get(store->operations, hash); | 155 | struct GNUNET_MESSENGER_Operation *op = GNUNET_CONTAINER_multihashmap_get ( |
156 | store->operations, hash); | ||
146 | 157 | ||
147 | if (!op) | 158 | if (! op) |
148 | return GNUNET_MESSENGER_OP_UNKNOWN; | 159 | return GNUNET_MESSENGER_OP_UNKNOWN; |
149 | 160 | ||
150 | return op->type; | 161 | return op->type; |
151 | } | 162 | } |
152 | 163 | ||
164 | |||
153 | int | 165 | int |
154 | use_store_operation (struct GNUNET_MESSENGER_OperationStore *store, | 166 | use_store_operation (struct GNUNET_MESSENGER_OperationStore *store, |
155 | const struct GNUNET_HashCode *hash, | 167 | const struct GNUNET_HashCode *hash, |
156 | enum GNUNET_MESSENGER_OperationType type, | 168 | enum GNUNET_MESSENGER_OperationType type, |
157 | struct GNUNET_TIME_Relative delay) | 169 | struct GNUNET_TIME_Relative delay) |
158 | { | 170 | { |
159 | GNUNET_assert((store) && (hash)); | 171 | GNUNET_assert ((store) && (hash)); |
160 | 172 | ||
161 | struct GNUNET_MESSENGER_Operation *op = GNUNET_CONTAINER_multihashmap_get(store->operations, hash); | 173 | struct GNUNET_MESSENGER_Operation *op = GNUNET_CONTAINER_multihashmap_get ( |
174 | store->operations, hash); | ||
162 | 175 | ||
163 | if (op) | 176 | if (op) |
164 | goto use_op; | 177 | goto use_op; |
165 | 178 | ||
166 | op = create_operation(hash); | 179 | op = create_operation (hash); |
167 | 180 | ||
168 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put(store->operations, hash, op, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | 181 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (store->operations, hash, |
182 | op, | ||
183 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | ||
169 | { | 184 | { |
170 | destroy_operation(op); | 185 | destroy_operation (op); |
171 | 186 | ||
172 | return GNUNET_SYSERR; | 187 | return GNUNET_SYSERR; |
173 | } | 188 | } |
@@ -177,29 +192,34 @@ use_op: | |||
177 | (type == GNUNET_MESSENGER_OP_DELETE)) | 192 | (type == GNUNET_MESSENGER_OP_DELETE)) |
178 | stop_operation (op); | 193 | stop_operation (op); |
179 | 194 | ||
180 | return start_operation(op, type, store, delay); | 195 | return start_operation (op, type, store, delay); |
181 | } | 196 | } |
182 | 197 | ||
198 | |||
183 | void | 199 | void |
184 | cancel_store_operation (struct GNUNET_MESSENGER_OperationStore *store, | 200 | cancel_store_operation (struct GNUNET_MESSENGER_OperationStore *store, |
185 | const struct GNUNET_HashCode *hash) | 201 | const struct GNUNET_HashCode *hash) |
186 | { | 202 | { |
187 | GNUNET_assert((store) && (hash)); | 203 | GNUNET_assert ((store) && (hash)); |
188 | 204 | ||
189 | struct GNUNET_MESSENGER_Operation *op = GNUNET_CONTAINER_multihashmap_get(store->operations, hash); | 205 | struct GNUNET_MESSENGER_Operation *op = GNUNET_CONTAINER_multihashmap_get ( |
206 | store->operations, hash); | ||
190 | 207 | ||
191 | if (!op) | 208 | if (! op) |
192 | return; | 209 | return; |
193 | 210 | ||
194 | stop_operation(op); | 211 | stop_operation (op); |
195 | 212 | ||
196 | if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove(store->operations, hash, op)) | 213 | if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (store->operations, |
197 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Canceled operation could not be removed: %s\n", | 214 | hash, op)) |
198 | GNUNET_h2s(hash)); | 215 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
216 | "Canceled operation could not be removed: %s\n", | ||
217 | GNUNET_h2s (hash)); | ||
199 | 218 | ||
200 | destroy_operation(op); | 219 | destroy_operation (op); |
201 | } | 220 | } |
202 | 221 | ||
222 | |||
203 | extern void | 223 | extern void |
204 | callback_room_deletion (struct GNUNET_MESSENGER_SrvRoom *room, | 224 | callback_room_deletion (struct GNUNET_MESSENGER_SrvRoom *room, |
205 | const struct GNUNET_HashCode *hash); | 225 | const struct GNUNET_HashCode *hash); |
@@ -213,10 +233,10 @@ callback_store_operation (struct GNUNET_MESSENGER_OperationStore *store, | |||
213 | enum GNUNET_MESSENGER_OperationType type, | 233 | enum GNUNET_MESSENGER_OperationType type, |
214 | const struct GNUNET_HashCode *hash) | 234 | const struct GNUNET_HashCode *hash) |
215 | { | 235 | { |
216 | GNUNET_assert((store) && (hash)); | 236 | GNUNET_assert ((store) && (hash)); |
217 | 237 | ||
218 | struct GNUNET_HashCode op_hash; | 238 | struct GNUNET_HashCode op_hash; |
219 | GNUNET_memcpy(&op_hash, hash, sizeof(op_hash)); | 239 | GNUNET_memcpy (&op_hash, hash, sizeof(op_hash)); |
220 | cancel_store_operation (store, &op_hash); | 240 | cancel_store_operation (store, &op_hash); |
221 | 241 | ||
222 | struct GNUNET_MESSENGER_SrvRoom *room = store->room; | 242 | struct GNUNET_MESSENGER_SrvRoom *room = store->room; |
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 | } |
diff --git a/src/messenger/gnunet-service-messenger_room.h b/src/messenger/gnunet-service-messenger_room.h index f0bb33f80..a4a76645d 100644 --- a/src/messenger/gnunet-service-messenger_room.h +++ b/src/messenger/gnunet-service-messenger_room.h | |||
@@ -45,13 +45,13 @@ | |||
45 | #include "gnunet-service-messenger_operation_store.h" | 45 | #include "gnunet-service-messenger_operation_store.h" |
46 | 46 | ||
47 | #define GNUNET_MESSENGER_IDLE_DELAY GNUNET_TIME_relative_multiply \ | 47 | #define GNUNET_MESSENGER_IDLE_DELAY GNUNET_TIME_relative_multiply \ |
48 | (GNUNET_TIME_relative_get_second_ (), 5) | 48 | (GNUNET_TIME_relative_get_second_ (), 5) |
49 | 49 | ||
50 | #define GNUNET_MESSENGER_REQUEST_DELAY GNUNET_TIME_relative_multiply \ | 50 | #define GNUNET_MESSENGER_REQUEST_DELAY GNUNET_TIME_relative_multiply \ |
51 | (GNUNET_TIME_relative_get_minute_ (), 5) | 51 | (GNUNET_TIME_relative_get_minute_ (), 5) |
52 | 52 | ||
53 | #define GNUNET_MESSENGER_MERGE_DELAY GNUNET_TIME_relative_multiply \ | 53 | #define GNUNET_MESSENGER_MERGE_DELAY GNUNET_TIME_relative_multiply \ |
54 | (GNUNET_TIME_relative_get_second_ (), 30) | 54 | (GNUNET_TIME_relative_get_second_ (), 30) |
55 | 55 | ||
56 | struct GNUNET_MESSENGER_SrvTunnel; | 56 | struct GNUNET_MESSENGER_SrvTunnel; |
57 | struct GNUNET_MESSENGER_MemberSession; | 57 | struct GNUNET_MESSENGER_MemberSession; |
@@ -89,7 +89,7 @@ struct GNUNET_MESSENGER_SrvRoom | |||
89 | */ | 89 | */ |
90 | struct GNUNET_MESSENGER_SrvRoom* | 90 | struct GNUNET_MESSENGER_SrvRoom* |
91 | create_srv_room (struct GNUNET_MESSENGER_SrvHandle *handle, | 91 | create_srv_room (struct GNUNET_MESSENGER_SrvHandle *handle, |
92 | const struct GNUNET_HashCode *key); | 92 | const struct GNUNET_HashCode *key); |
93 | 93 | ||
94 | /** | 94 | /** |
95 | * Destroys a room and frees its memory fully. | 95 | * Destroys a room and frees its memory fully. |
@@ -102,7 +102,7 @@ create_srv_room (struct GNUNET_MESSENGER_SrvHandle *handle, | |||
102 | */ | 102 | */ |
103 | void | 103 | void |
104 | destroy_srv_room (struct GNUNET_MESSENGER_SrvRoom *room, | 104 | destroy_srv_room (struct GNUNET_MESSENGER_SrvRoom *room, |
105 | int deletion); | 105 | int deletion); |
106 | 106 | ||
107 | /** | 107 | /** |
108 | * Returns the used peer store of a given <i>room</i>. | 108 | * Returns the used peer store of a given <i>room</i>. |
@@ -307,11 +307,11 @@ get_srv_room_tunnel (const struct GNUNET_MESSENGER_SrvRoom *room, | |||
307 | * @param[in] hash Hash of message | 307 | * @param[in] hash Hash of message |
308 | */ | 308 | */ |
309 | typedef void (GNUNET_MESSENGER_MessageRequestCallback) ( | 309 | typedef void (GNUNET_MESSENGER_MessageRequestCallback) ( |
310 | void *cls, | 310 | void *cls, |
311 | struct GNUNET_MESSENGER_SrvRoom *room, | 311 | struct GNUNET_MESSENGER_SrvRoom *room, |
312 | const struct GNUNET_MESSENGER_Message *message, | 312 | const struct GNUNET_MESSENGER_Message *message, |
313 | const struct GNUNET_HashCode *hash | 313 | const struct GNUNET_HashCode *hash |
314 | ); | 314 | ); |
315 | 315 | ||
316 | /** | 316 | /** |
317 | * Requests a message from a <i>room</i> identified by a given <i>hash</i>. If the message is found, | 317 | * Requests a message from a <i>room</i> identified by a given <i>hash</i>. If the message is found, |
@@ -333,7 +333,7 @@ request_srv_room_message (struct GNUNET_MESSENGER_SrvRoom *room, | |||
333 | const struct GNUNET_HashCode *hash, | 333 | const struct GNUNET_HashCode *hash, |
334 | const struct GNUNET_MESSENGER_MemberSession *session, | 334 | const struct GNUNET_MESSENGER_MemberSession *session, |
335 | GNUNET_MESSENGER_MessageRequestCallback callback, | 335 | GNUNET_MESSENGER_MessageRequestCallback callback, |
336 | void* cls); | 336 | void *cls); |
337 | 337 | ||
338 | /** | 338 | /** |
339 | * Checks for potential collisions with member ids and solves them changing active handles ids if they | 339 | * Checks for potential collisions with member ids and solves them changing active handles ids if they |
@@ -346,7 +346,8 @@ request_srv_room_message (struct GNUNET_MESSENGER_SrvRoom *room, | |||
346 | */ | 346 | */ |
347 | void | 347 | void |
348 | solve_srv_room_member_collisions (struct GNUNET_MESSENGER_SrvRoom *room, | 348 | solve_srv_room_member_collisions (struct GNUNET_MESSENGER_SrvRoom *room, |
349 | const struct GNUNET_IDENTITY_PublicKey *public_key, | 349 | const struct |
350 | GNUNET_IDENTITY_PublicKey *public_key, | ||
350 | const struct GNUNET_ShortHashCode *member_id, | 351 | const struct GNUNET_ShortHashCode *member_id, |
351 | struct GNUNET_TIME_Absolute timestamp); | 352 | struct GNUNET_TIME_Absolute timestamp); |
352 | 353 | ||
diff --git a/src/messenger/gnunet-service-messenger_sender_session.h b/src/messenger/gnunet-service-messenger_sender_session.h index b137da11a..6eb287607 100644 --- a/src/messenger/gnunet-service-messenger_sender_session.h +++ b/src/messenger/gnunet-service-messenger_sender_session.h | |||
@@ -31,8 +31,10 @@ | |||
31 | 31 | ||
32 | #include "gnunet-service-messenger_member_session.h" | 32 | #include "gnunet-service-messenger_member_session.h" |
33 | 33 | ||
34 | struct GNUNET_MESSENGER_SenderSession { | 34 | struct GNUNET_MESSENGER_SenderSession |
35 | union { | 35 | { |
36 | union | ||
37 | { | ||
36 | struct GNUNET_MESSENGER_MemberSession *member; | 38 | struct GNUNET_MESSENGER_MemberSession *member; |
37 | struct GNUNET_PeerIdentity *peer; | 39 | struct GNUNET_PeerIdentity *peer; |
38 | }; | 40 | }; |
diff --git a/src/messenger/gnunet-service-messenger_service.c b/src/messenger/gnunet-service-messenger_service.c index 2f4d7bf80..b72bbd201 100644 --- a/src/messenger/gnunet-service-messenger_service.c +++ b/src/messenger/gnunet-service-messenger_service.c | |||
@@ -41,37 +41,43 @@ callback_shutdown_service (void *cls) | |||
41 | } | 41 | } |
42 | } | 42 | } |
43 | 43 | ||
44 | |||
44 | struct GNUNET_MESSENGER_Service* | 45 | struct GNUNET_MESSENGER_Service* |
45 | create_service (const struct GNUNET_CONFIGURATION_Handle *config, | 46 | create_service (const struct GNUNET_CONFIGURATION_Handle *config, |
46 | struct GNUNET_SERVICE_Handle *service_handle) | 47 | struct GNUNET_SERVICE_Handle *service_handle) |
47 | { | 48 | { |
48 | GNUNET_assert((config) && (service_handle)); | 49 | GNUNET_assert ((config) && (service_handle)); |
49 | 50 | ||
50 | struct GNUNET_MESSENGER_Service *service = GNUNET_new(struct GNUNET_MESSENGER_Service); | 51 | struct GNUNET_MESSENGER_Service *service = GNUNET_new (struct |
52 | GNUNET_MESSENGER_Service); | ||
51 | 53 | ||
52 | service->config = config; | 54 | service->config = config; |
53 | service->service = service_handle; | 55 | service->service = service_handle; |
54 | 56 | ||
55 | service->shutdown = GNUNET_SCHEDULER_add_shutdown (&callback_shutdown_service, service); | 57 | service->shutdown = GNUNET_SCHEDULER_add_shutdown (&callback_shutdown_service, |
58 | service); | ||
56 | 59 | ||
57 | service->peer = NULL; | 60 | service->peer = NULL; |
58 | service->dir = NULL; | 61 | service->dir = NULL; |
59 | 62 | ||
60 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (service->config, | 63 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (service->config, |
61 | GNUNET_MESSENGER_SERVICE_NAME, | 64 | GNUNET_MESSENGER_SERVICE_NAME, |
62 | "MESSENGER_DIR", &(service->dir))) | 65 | "MESSENGER_DIR", |
66 | &(service->dir))) | ||
63 | { | 67 | { |
64 | if (service->dir) | 68 | if (service->dir) |
65 | GNUNET_free(service->dir); | 69 | GNUNET_free (service->dir); |
66 | 70 | ||
67 | service->dir = NULL; | 71 | service->dir = NULL; |
68 | } | 72 | } |
69 | else | 73 | else |
70 | { | 74 | { |
71 | if ((GNUNET_YES != GNUNET_DISK_directory_test (service->dir, GNUNET_YES)) && (GNUNET_OK | 75 | if ((GNUNET_YES != GNUNET_DISK_directory_test (service->dir, GNUNET_YES)) && |
72 | != GNUNET_DISK_directory_create (service->dir))) | 76 | (GNUNET_OK |
77 | != | ||
78 | GNUNET_DISK_directory_create (service->dir))) | ||
73 | { | 79 | { |
74 | GNUNET_free(service->dir); | 80 | GNUNET_free (service->dir); |
75 | 81 | ||
76 | service->dir = NULL; | 82 | service->dir = NULL; |
77 | } | 83 | } |
@@ -88,6 +94,7 @@ create_service (const struct GNUNET_CONFIGURATION_Handle *config, | |||
88 | return service; | 94 | return service; |
89 | } | 95 | } |
90 | 96 | ||
97 | |||
91 | static int | 98 | static int |
92 | iterate_destroy_rooms (void *cls, | 99 | iterate_destroy_rooms (void *cls, |
93 | const struct GNUNET_HashCode *key, | 100 | const struct GNUNET_HashCode *key, |
@@ -98,10 +105,11 @@ iterate_destroy_rooms (void *cls, | |||
98 | return GNUNET_YES; | 105 | return GNUNET_YES; |
99 | } | 106 | } |
100 | 107 | ||
108 | |||
101 | void | 109 | void |
102 | destroy_service (struct GNUNET_MESSENGER_Service *service) | 110 | destroy_service (struct GNUNET_MESSENGER_Service *service) |
103 | { | 111 | { |
104 | GNUNET_assert(service); | 112 | GNUNET_assert (service); |
105 | 113 | ||
106 | if (service->shutdown) | 114 | if (service->shutdown) |
107 | { | 115 | { |
@@ -112,7 +120,8 @@ destroy_service (struct GNUNET_MESSENGER_Service *service) | |||
112 | 120 | ||
113 | clear_list_handles (&(service->handles)); | 121 | clear_list_handles (&(service->handles)); |
114 | 122 | ||
115 | GNUNET_CONTAINER_multihashmap_iterate (service->rooms, iterate_destroy_rooms, NULL); | 123 | GNUNET_CONTAINER_multihashmap_iterate (service->rooms, iterate_destroy_rooms, |
124 | NULL); | ||
116 | GNUNET_CONTAINER_multihashmap_destroy (service->rooms); | 125 | GNUNET_CONTAINER_multihashmap_destroy (service->rooms); |
117 | 126 | ||
118 | clear_contact_store (get_service_contact_store (service)); | 127 | clear_contact_store (get_service_contact_store (service)); |
@@ -126,36 +135,38 @@ destroy_service (struct GNUNET_MESSENGER_Service *service) | |||
126 | 135 | ||
127 | if (service->dir) | 136 | if (service->dir) |
128 | { | 137 | { |
129 | GNUNET_free(service->dir); | 138 | GNUNET_free (service->dir); |
130 | 139 | ||
131 | service->dir = NULL; | 140 | service->dir = NULL; |
132 | } | 141 | } |
133 | 142 | ||
134 | if (service->peer) | 143 | if (service->peer) |
135 | { | 144 | { |
136 | GNUNET_free(service->peer); | 145 | GNUNET_free (service->peer); |
137 | 146 | ||
138 | service->peer = NULL; | 147 | service->peer = NULL; |
139 | } | 148 | } |
140 | 149 | ||
141 | GNUNET_SERVICE_shutdown (service->service); | 150 | GNUNET_SERVICE_shutdown (service->service); |
142 | 151 | ||
143 | GNUNET_free(service); | 152 | GNUNET_free (service); |
144 | } | 153 | } |
145 | 154 | ||
155 | |||
146 | struct GNUNET_MESSENGER_ContactStore* | 156 | struct GNUNET_MESSENGER_ContactStore* |
147 | get_service_contact_store (struct GNUNET_MESSENGER_Service *service) | 157 | get_service_contact_store (struct GNUNET_MESSENGER_Service *service) |
148 | { | 158 | { |
149 | GNUNET_assert(service); | 159 | GNUNET_assert (service); |
150 | 160 | ||
151 | return &(service->contact_store); | 161 | return &(service->contact_store); |
152 | } | 162 | } |
153 | 163 | ||
164 | |||
154 | struct GNUNET_MESSENGER_SrvHandle* | 165 | struct GNUNET_MESSENGER_SrvHandle* |
155 | add_service_handle (struct GNUNET_MESSENGER_Service *service, | 166 | add_service_handle (struct GNUNET_MESSENGER_Service *service, |
156 | struct GNUNET_MQ_Handle *mq) | 167 | struct GNUNET_MQ_Handle *mq) |
157 | { | 168 | { |
158 | GNUNET_assert((service) && (mq)); | 169 | GNUNET_assert ((service) && (mq)); |
159 | 170 | ||
160 | struct GNUNET_MESSENGER_SrvHandle *handle = create_srv_handle (service, mq); | 171 | struct GNUNET_MESSENGER_SrvHandle *handle = create_srv_handle (service, mq); |
161 | 172 | ||
@@ -167,58 +178,62 @@ add_service_handle (struct GNUNET_MESSENGER_Service *service, | |||
167 | return handle; | 178 | return handle; |
168 | } | 179 | } |
169 | 180 | ||
181 | |||
170 | void | 182 | void |
171 | remove_service_handle (struct GNUNET_MESSENGER_Service *service, | 183 | remove_service_handle (struct GNUNET_MESSENGER_Service *service, |
172 | struct GNUNET_MESSENGER_SrvHandle *handle) | 184 | struct GNUNET_MESSENGER_SrvHandle *handle) |
173 | { | 185 | { |
174 | GNUNET_assert((service) && (handle)); | 186 | GNUNET_assert ((service) && (handle)); |
175 | 187 | ||
176 | if (!handle) | 188 | if (! handle) |
177 | return; | 189 | return; |
178 | 190 | ||
179 | if (GNUNET_YES == remove_list_handle (&(service->handles), handle)) | 191 | if (GNUNET_YES == remove_list_handle (&(service->handles), handle)) |
180 | destroy_srv_handle (handle); | 192 | destroy_srv_handle (handle); |
181 | } | 193 | } |
182 | 194 | ||
195 | |||
183 | int | 196 | int |
184 | get_service_peer_identity (struct GNUNET_MESSENGER_Service *service, | 197 | get_service_peer_identity (struct GNUNET_MESSENGER_Service *service, |
185 | struct GNUNET_PeerIdentity *peer) | 198 | struct GNUNET_PeerIdentity *peer) |
186 | { | 199 | { |
187 | GNUNET_assert((service) && (peer)); | 200 | GNUNET_assert ((service) && (peer)); |
188 | 201 | ||
189 | if (service->peer) | 202 | if (service->peer) |
190 | { | 203 | { |
191 | GNUNET_memcpy(peer, service->peer, sizeof(struct GNUNET_PeerIdentity)); | 204 | GNUNET_memcpy (peer, service->peer, sizeof(struct GNUNET_PeerIdentity)); |
192 | return GNUNET_OK; | 205 | return GNUNET_OK; |
193 | } | 206 | } |
194 | 207 | ||
195 | int result = GNUNET_CRYPTO_get_peer_identity(service->config, peer); | 208 | int result = GNUNET_CRYPTO_get_peer_identity (service->config, peer); |
196 | 209 | ||
197 | if (GNUNET_OK != result) | 210 | if (GNUNET_OK != result) |
198 | return result; | 211 | return result; |
199 | 212 | ||
200 | if (!service->peer) | 213 | if (! service->peer) |
201 | service->peer = GNUNET_new(struct GNUNET_PeerIdentity); | 214 | service->peer = GNUNET_new (struct GNUNET_PeerIdentity); |
202 | 215 | ||
203 | GNUNET_memcpy(service->peer, peer, sizeof(struct GNUNET_PeerIdentity)); | 216 | GNUNET_memcpy (service->peer, peer, sizeof(struct GNUNET_PeerIdentity)); |
204 | return result; | 217 | return result; |
205 | } | 218 | } |
206 | 219 | ||
220 | |||
207 | struct GNUNET_MESSENGER_SrvRoom* | 221 | struct GNUNET_MESSENGER_SrvRoom* |
208 | get_service_room (const struct GNUNET_MESSENGER_Service *service, | 222 | get_service_room (const struct GNUNET_MESSENGER_Service *service, |
209 | const struct GNUNET_HashCode *key) | 223 | const struct GNUNET_HashCode *key) |
210 | { | 224 | { |
211 | GNUNET_assert((service) && (key)); | 225 | GNUNET_assert ((service) && (key)); |
212 | 226 | ||
213 | return GNUNET_CONTAINER_multihashmap_get (service->rooms, key); | 227 | return GNUNET_CONTAINER_multihashmap_get (service->rooms, key); |
214 | } | 228 | } |
215 | 229 | ||
230 | |||
216 | int | 231 | int |
217 | open_service_room (struct GNUNET_MESSENGER_Service *service, | 232 | open_service_room (struct GNUNET_MESSENGER_Service *service, |
218 | struct GNUNET_MESSENGER_SrvHandle *handle, | 233 | struct GNUNET_MESSENGER_SrvHandle *handle, |
219 | const struct GNUNET_HashCode *key) | 234 | const struct GNUNET_HashCode *key) |
220 | { | 235 | { |
221 | GNUNET_assert((service) && (handle) && (key)); | 236 | GNUNET_assert ((service) && (handle) && (key)); |
222 | 237 | ||
223 | struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (service, key); | 238 | struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (service, key); |
224 | 239 | ||
@@ -237,13 +252,14 @@ open_service_room (struct GNUNET_MESSENGER_Service *service, | |||
237 | return GNUNET_NO; | 252 | return GNUNET_NO; |
238 | } | 253 | } |
239 | 254 | ||
255 | |||
240 | int | 256 | int |
241 | entry_service_room (struct GNUNET_MESSENGER_Service *service, | 257 | entry_service_room (struct GNUNET_MESSENGER_Service *service, |
242 | struct GNUNET_MESSENGER_SrvHandle *handle, | 258 | struct GNUNET_MESSENGER_SrvHandle *handle, |
243 | const struct GNUNET_PeerIdentity *door, | 259 | const struct GNUNET_PeerIdentity *door, |
244 | const struct GNUNET_HashCode *key) | 260 | const struct GNUNET_HashCode *key) |
245 | { | 261 | { |
246 | GNUNET_assert((service) && (handle) && (door) && (key)); | 262 | GNUNET_assert ((service) && (handle) && (door) && (key)); |
247 | 263 | ||
248 | struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (service, key); | 264 | struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (service, key); |
249 | 265 | ||
@@ -272,31 +288,38 @@ entry_service_room (struct GNUNET_MESSENGER_Service *service, | |||
272 | 288 | ||
273 | } | 289 | } |
274 | 290 | ||
291 | |||
275 | int | 292 | int |
276 | close_service_room (struct GNUNET_MESSENGER_Service *service, | 293 | close_service_room (struct GNUNET_MESSENGER_Service *service, |
277 | struct GNUNET_MESSENGER_SrvHandle *handle, | 294 | struct GNUNET_MESSENGER_SrvHandle *handle, |
278 | const struct GNUNET_HashCode *key) | 295 | const struct GNUNET_HashCode *key) |
279 | { | 296 | { |
280 | GNUNET_assert((service) && (handle) && (key)); | 297 | GNUNET_assert ((service) && (handle) && (key)); |
281 | 298 | ||
282 | struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (service, key); | 299 | struct GNUNET_MESSENGER_SrvRoom *room = get_service_room (service, key); |
283 | 300 | ||
284 | if (!room) | 301 | if (! room) |
285 | return GNUNET_NO; | 302 | return GNUNET_NO; |
286 | 303 | ||
287 | const struct GNUNET_ShortHashCode *id = get_srv_handle_member_id (handle, key); | 304 | const struct GNUNET_ShortHashCode *id = get_srv_handle_member_id (handle, |
305 | key); | ||
288 | 306 | ||
289 | GNUNET_assert(id); | 307 | GNUNET_assert (id); |
290 | 308 | ||
291 | if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (handle->member_ids, key, id)) | 309 | if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (handle->member_ids, |
310 | key, id)) | ||
292 | return GNUNET_NO; | 311 | return GNUNET_NO; |
293 | 312 | ||
294 | struct GNUNET_MESSENGER_SrvHandle *member_handle = (struct GNUNET_MESSENGER_SrvHandle*) find_list_handle_by_member ( | 313 | struct GNUNET_MESSENGER_SrvHandle *member_handle = (struct |
295 | &(service->handles), key); | 314 | GNUNET_MESSENGER_SrvHandle |
315 | *) | ||
316 | find_list_handle_by_member ( | ||
317 | &(service->handles), key); | ||
296 | 318 | ||
297 | if (!member_handle) | 319 | if (! member_handle) |
298 | { | 320 | { |
299 | if (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove (service->rooms, key, room)) | 321 | if (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove (service->rooms, key, |
322 | room)) | ||
300 | { | 323 | { |
301 | destroy_srv_room (room, GNUNET_YES); | 324 | destroy_srv_room (room, GNUNET_YES); |
302 | return GNUNET_YES; | 325 | return GNUNET_YES; |
@@ -311,6 +334,7 @@ close_service_room (struct GNUNET_MESSENGER_Service *service, | |||
311 | return GNUNET_YES; | 334 | return GNUNET_YES; |
312 | } | 335 | } |
313 | 336 | ||
337 | |||
314 | void | 338 | void |
315 | handle_service_message (struct GNUNET_MESSENGER_Service *service, | 339 | handle_service_message (struct GNUNET_MESSENGER_Service *service, |
316 | struct GNUNET_MESSENGER_SrvRoom *room, | 340 | struct GNUNET_MESSENGER_SrvRoom *room, |
@@ -318,7 +342,7 @@ handle_service_message (struct GNUNET_MESSENGER_Service *service, | |||
318 | const struct GNUNET_MESSENGER_Message *message, | 342 | const struct GNUNET_MESSENGER_Message *message, |
319 | const struct GNUNET_HashCode *hash) | 343 | const struct GNUNET_HashCode *hash) |
320 | { | 344 | { |
321 | GNUNET_assert((service) && (room) && (session) && (message) && (hash)); | 345 | GNUNET_assert ((service) && (room) && (session) && (message) && (hash)); |
322 | 346 | ||
323 | struct GNUNET_MESSENGER_ListHandle *element = service->handles.head; | 347 | struct GNUNET_MESSENGER_ListHandle *element = service->handles.head; |
324 | 348 | ||
diff --git a/src/messenger/gnunet-service-messenger_tunnel.c b/src/messenger/gnunet-service-messenger_tunnel.c index c82a42cd0..5262ba79b 100644 --- a/src/messenger/gnunet-service-messenger_tunnel.c +++ b/src/messenger/gnunet-service-messenger_tunnel.c | |||
@@ -37,9 +37,10 @@ struct GNUNET_MESSENGER_SrvTunnel* | |||
37 | create_tunnel (struct GNUNET_MESSENGER_SrvRoom *room, | 37 | create_tunnel (struct GNUNET_MESSENGER_SrvRoom *room, |
38 | const struct GNUNET_PeerIdentity *door) | 38 | const struct GNUNET_PeerIdentity *door) |
39 | { | 39 | { |
40 | GNUNET_assert((room) && (door)); | 40 | GNUNET_assert ((room) && (door)); |
41 | 41 | ||
42 | struct GNUNET_MESSENGER_SrvTunnel *tunnel = GNUNET_new(struct GNUNET_MESSENGER_SrvTunnel); | 42 | struct GNUNET_MESSENGER_SrvTunnel *tunnel = GNUNET_new (struct |
43 | GNUNET_MESSENGER_SrvTunnel); | ||
43 | 44 | ||
44 | tunnel->room = room; | 45 | tunnel->room = room; |
45 | tunnel->channel = NULL; | 46 | tunnel->channel = NULL; |
@@ -50,15 +51,16 @@ create_tunnel (struct GNUNET_MESSENGER_SrvRoom *room, | |||
50 | 51 | ||
51 | tunnel->peer_message = NULL; | 52 | tunnel->peer_message = NULL; |
52 | 53 | ||
53 | init_message_state(&(tunnel->state)); | 54 | init_message_state (&(tunnel->state)); |
54 | 55 | ||
55 | return tunnel; | 56 | return tunnel; |
56 | } | 57 | } |
57 | 58 | ||
59 | |||
58 | void | 60 | void |
59 | destroy_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel) | 61 | destroy_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel) |
60 | { | 62 | { |
61 | GNUNET_assert(tunnel); | 63 | GNUNET_assert (tunnel); |
62 | 64 | ||
63 | if (tunnel->channel) | 65 | if (tunnel->channel) |
64 | GNUNET_CADET_channel_destroy (tunnel->channel); | 66 | GNUNET_CADET_channel_destroy (tunnel->channel); |
@@ -66,18 +68,19 @@ destroy_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel) | |||
66 | GNUNET_PEER_change_rc (tunnel->peer, -1); | 68 | GNUNET_PEER_change_rc (tunnel->peer, -1); |
67 | 69 | ||
68 | if (tunnel->peer_message) | 70 | if (tunnel->peer_message) |
69 | GNUNET_free(tunnel->peer_message); | 71 | GNUNET_free (tunnel->peer_message); |
70 | 72 | ||
71 | clear_message_state(&(tunnel->state)); | 73 | clear_message_state (&(tunnel->state)); |
72 | 74 | ||
73 | GNUNET_free(tunnel); | 75 | GNUNET_free (tunnel); |
74 | } | 76 | } |
75 | 77 | ||
78 | |||
76 | void | 79 | void |
77 | bind_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel, | 80 | bind_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel, |
78 | struct GNUNET_CADET_Channel *channel) | 81 | struct GNUNET_CADET_Channel *channel) |
79 | { | 82 | { |
80 | GNUNET_assert(tunnel); | 83 | GNUNET_assert (tunnel); |
81 | 84 | ||
82 | if (tunnel->channel) | 85 | if (tunnel->channel) |
83 | delayed_disconnect_channel (tunnel->channel); | 86 | delayed_disconnect_channel (tunnel->channel); |
@@ -85,6 +88,7 @@ bind_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel, | |||
85 | tunnel->channel = channel; | 88 | tunnel->channel = channel; |
86 | } | 89 | } |
87 | 90 | ||
91 | |||
88 | extern void | 92 | extern void |
89 | callback_room_disconnect (struct GNUNET_MESSENGER_SrvRoom *room, | 93 | callback_room_disconnect (struct GNUNET_MESSENGER_SrvRoom *room, |
90 | void *cls); | 94 | void *cls); |
@@ -103,6 +107,7 @@ callback_tunnel_disconnect (void *cls, | |||
103 | } | 107 | } |
104 | } | 108 | } |
105 | 109 | ||
110 | |||
106 | extern int | 111 | extern int |
107 | callback_verify_room_message (struct GNUNET_MESSENGER_SrvRoom *room, | 112 | callback_verify_room_message (struct GNUNET_MESSENGER_SrvRoom *room, |
108 | void *cls, | 113 | void *cls, |
@@ -115,7 +120,7 @@ check_tunnel_message (void *cls, | |||
115 | { | 120 | { |
116 | struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls; | 121 | struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls; |
117 | 122 | ||
118 | if (!tunnel) | 123 | if (! tunnel) |
119 | return GNUNET_SYSERR; | 124 | return GNUNET_SYSERR; |
120 | 125 | ||
121 | const uint16_t length = ntohs (header->size) - sizeof(*header); | 126 | const uint16_t length = ntohs (header->size) - sizeof(*header); |
@@ -123,17 +128,20 @@ check_tunnel_message (void *cls, | |||
123 | 128 | ||
124 | struct GNUNET_MESSENGER_Message message; | 129 | struct GNUNET_MESSENGER_Message message; |
125 | 130 | ||
126 | if (length < get_message_kind_size(GNUNET_MESSENGER_KIND_UNKNOWN, GNUNET_YES)) | 131 | if (length < get_message_kind_size (GNUNET_MESSENGER_KIND_UNKNOWN, |
132 | GNUNET_YES)) | ||
127 | { | 133 | { |
128 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Tunnel error: Message too short! (%d)\n", length); | 134 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
135 | "Tunnel error: Message too short! (%d)\n", length); | ||
129 | return GNUNET_SYSERR; | 136 | return GNUNET_SYSERR; |
130 | } | 137 | } |
131 | 138 | ||
132 | uint16_t padding = 0; | 139 | uint16_t padding = 0; |
133 | 140 | ||
134 | if (GNUNET_YES != decode_message (&message, length, buffer, GNUNET_YES, &padding)) | 141 | if (GNUNET_YES != decode_message (&message, length, buffer, GNUNET_YES, |
142 | &padding)) | ||
135 | { | 143 | { |
136 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Tunnel error: Decoding failed!\n"); | 144 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Tunnel error: Decoding failed!\n"); |
137 | return GNUNET_SYSERR; | 145 | return GNUNET_SYSERR; |
138 | } | 146 | } |
139 | 147 | ||
@@ -143,6 +151,7 @@ check_tunnel_message (void *cls, | |||
143 | return callback_verify_room_message (tunnel->room, cls, &message, &hash); | 151 | return callback_verify_room_message (tunnel->room, cls, &message, &hash); |
144 | } | 152 | } |
145 | 153 | ||
154 | |||
146 | extern int | 155 | extern int |
147 | update_room_message (struct GNUNET_MESSENGER_SrvRoom *room, | 156 | update_room_message (struct GNUNET_MESSENGER_SrvRoom *room, |
148 | struct GNUNET_MESSENGER_Message *message, | 157 | struct GNUNET_MESSENGER_Message *message, |
@@ -157,26 +166,31 @@ static void | |||
157 | update_tunnel_last_message (struct GNUNET_MESSENGER_SrvTunnel *tunnel, | 166 | update_tunnel_last_message (struct GNUNET_MESSENGER_SrvTunnel *tunnel, |
158 | const struct GNUNET_HashCode *hash) | 167 | const struct GNUNET_HashCode *hash) |
159 | { | 168 | { |
160 | struct GNUNET_MESSENGER_OperationStore *operation_store = get_srv_room_operation_store(tunnel->room); | 169 | struct GNUNET_MESSENGER_OperationStore *operation_store = |
170 | get_srv_room_operation_store (tunnel->room); | ||
161 | 171 | ||
162 | const int requested = (GNUNET_MESSENGER_OP_REQUEST == get_store_operation_type(operation_store, hash)? | 172 | const int requested = (GNUNET_MESSENGER_OP_REQUEST == |
163 | GNUNET_YES : GNUNET_NO | 173 | get_store_operation_type (operation_store, hash)? |
164 | ); | 174 | GNUNET_YES : GNUNET_NO |
175 | ); | ||
165 | 176 | ||
166 | struct GNUNET_MESSENGER_MessageStore *message_store = get_srv_room_message_store(tunnel->room); | 177 | struct GNUNET_MESSENGER_MessageStore *message_store = |
178 | get_srv_room_message_store (tunnel->room); | ||
167 | 179 | ||
168 | const struct GNUNET_MESSENGER_Message *message = get_store_message(message_store, hash); | 180 | const struct GNUNET_MESSENGER_Message *message = get_store_message ( |
181 | message_store, hash); | ||
169 | 182 | ||
170 | if (message) | 183 | if (message) |
171 | update_message_state(&(tunnel->state), requested, message, hash); | 184 | update_message_state (&(tunnel->state), requested, message, hash); |
172 | } | 185 | } |
173 | 186 | ||
187 | |||
174 | void | 188 | void |
175 | handle_tunnel_message (void *cls, const struct GNUNET_MessageHeader *header) | 189 | handle_tunnel_message (void *cls, const struct GNUNET_MessageHeader *header) |
176 | { | 190 | { |
177 | struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls; | 191 | struct GNUNET_MESSENGER_SrvTunnel *tunnel = cls; |
178 | 192 | ||
179 | if (!tunnel) | 193 | if (! tunnel) |
180 | return; | 194 | return; |
181 | 195 | ||
182 | const uint16_t length = ntohs (header->size) - sizeof(*header); | 196 | const uint16_t length = ntohs (header->size) - sizeof(*header); |
@@ -190,12 +204,12 @@ handle_tunnel_message (void *cls, const struct GNUNET_MessageHeader *header) | |||
190 | decode_message (&message, length, buffer, GNUNET_YES, &padding); | 204 | decode_message (&message, length, buffer, GNUNET_YES, &padding); |
191 | hash_message (&message, length - padding, buffer, &hash); | 205 | hash_message (&message, length - padding, buffer, &hash); |
192 | 206 | ||
193 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got message of kind: %s!\n", | 207 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got message of kind: %s!\n", |
194 | GNUNET_MESSENGER_name_of_kind(message.header.kind)); | 208 | GNUNET_MESSENGER_name_of_kind (message.header.kind)); |
195 | 209 | ||
196 | const int new_message = update_room_message ( | 210 | const int new_message = update_room_message ( |
197 | tunnel->room, copy_message (&message), &hash | 211 | tunnel->room, copy_message (&message), &hash |
198 | ); | 212 | ); |
199 | 213 | ||
200 | if (GNUNET_YES != new_message) | 214 | if (GNUNET_YES != new_message) |
201 | goto receive_done; | 215 | goto receive_done; |
@@ -213,7 +227,8 @@ handle_tunnel_message (void *cls, const struct GNUNET_MessageHeader *header) | |||
213 | forward_message = recv_message_peer (tunnel->room, tunnel, &message, &hash); | 227 | forward_message = recv_message_peer (tunnel->room, tunnel, &message, &hash); |
214 | break; | 228 | break; |
215 | case GNUNET_MESSENGER_KIND_REQUEST: | 229 | case GNUNET_MESSENGER_KIND_REQUEST: |
216 | forward_message = recv_message_request (tunnel->room, tunnel, &message, &hash); | 230 | forward_message = recv_message_request (tunnel->room, tunnel, &message, |
231 | &hash); | ||
217 | break; | 232 | break; |
218 | default: | 233 | default: |
219 | break; | 234 | break; |
@@ -226,15 +241,16 @@ handle_tunnel_message (void *cls, const struct GNUNET_MessageHeader *header) | |||
226 | } | 241 | } |
227 | 242 | ||
228 | receive_done: | 243 | receive_done: |
229 | cleanup_message(&message); | 244 | cleanup_message (&message); |
230 | 245 | ||
231 | GNUNET_CADET_receive_done (tunnel->channel); | 246 | GNUNET_CADET_receive_done (tunnel->channel); |
232 | } | 247 | } |
233 | 248 | ||
249 | |||
234 | int | 250 | int |
235 | connect_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel) | 251 | connect_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel) |
236 | { | 252 | { |
237 | GNUNET_assert(tunnel); | 253 | GNUNET_assert (tunnel); |
238 | 254 | ||
239 | if (tunnel->channel) | 255 | if (tunnel->channel) |
240 | return GNUNET_NO; | 256 | return GNUNET_NO; |
@@ -244,21 +260,28 @@ connect_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel) | |||
244 | struct GNUNET_CADET_Handle *cadet = get_srv_room_cadet (tunnel->room); | 260 | struct GNUNET_CADET_Handle *cadet = get_srv_room_cadet (tunnel->room); |
245 | const struct GNUNET_HashCode *key = get_srv_room_key (tunnel->room); | 261 | const struct GNUNET_HashCode *key = get_srv_room_key (tunnel->room); |
246 | 262 | ||
247 | struct GNUNET_MQ_MessageHandler handlers[] = { GNUNET_MQ_hd_var_size(tunnel_message, GNUNET_MESSAGE_TYPE_CADET_CLI, | 263 | struct GNUNET_MQ_MessageHandler handlers[] = { GNUNET_MQ_hd_var_size ( |
248 | struct GNUNET_MessageHeader, NULL), | 264 | tunnel_message, |
249 | GNUNET_MQ_handler_end() }; | 265 | GNUNET_MESSAGE_TYPE_CADET_CLI, |
266 | struct | ||
267 | GNUNET_MessageHeader, NULL), | ||
268 | GNUNET_MQ_handler_end () }; | ||
250 | 269 | ||
251 | struct GNUNET_HashCode port; | 270 | struct GNUNET_HashCode port; |
252 | convert_messenger_key_to_port(key, &port); | 271 | convert_messenger_key_to_port (key, &port); |
253 | tunnel->channel = GNUNET_CADET_channel_create (cadet, tunnel, door, &port, NULL, callback_tunnel_disconnect, handlers); | 272 | tunnel->channel = GNUNET_CADET_channel_create (cadet, tunnel, door, &port, |
273 | NULL, | ||
274 | callback_tunnel_disconnect, | ||
275 | handlers); | ||
254 | 276 | ||
255 | return GNUNET_YES; | 277 | return GNUNET_YES; |
256 | } | 278 | } |
257 | 279 | ||
280 | |||
258 | void | 281 | void |
259 | disconnect_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel) | 282 | disconnect_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel) |
260 | { | 283 | { |
261 | GNUNET_assert(tunnel); | 284 | GNUNET_assert (tunnel); |
262 | 285 | ||
263 | if (tunnel->channel) | 286 | if (tunnel->channel) |
264 | { | 287 | { |
@@ -268,14 +291,16 @@ disconnect_tunnel (struct GNUNET_MESSENGER_SrvTunnel *tunnel) | |||
268 | } | 291 | } |
269 | } | 292 | } |
270 | 293 | ||
294 | |||
271 | int | 295 | int |
272 | is_tunnel_connected (const struct GNUNET_MESSENGER_SrvTunnel *tunnel) | 296 | is_tunnel_connected (const struct GNUNET_MESSENGER_SrvTunnel *tunnel) |
273 | { | 297 | { |
274 | GNUNET_assert(tunnel); | 298 | GNUNET_assert (tunnel); |
275 | 299 | ||
276 | return (tunnel->channel ? GNUNET_YES : GNUNET_NO); | 300 | return (tunnel->channel ? GNUNET_YES : GNUNET_NO); |
277 | } | 301 | } |
278 | 302 | ||
303 | |||
279 | struct GNUNET_MESSENGER_MessageSent | 304 | struct GNUNET_MESSENGER_MessageSent |
280 | { | 305 | { |
281 | struct GNUNET_MESSENGER_SrvTunnel *tunnel; | 306 | struct GNUNET_MESSENGER_SrvTunnel *tunnel; |
@@ -290,21 +315,23 @@ callback_tunnel_sent (void *cls) | |||
290 | if (sent->tunnel) | 315 | if (sent->tunnel) |
291 | update_tunnel_last_message (sent->tunnel, &(sent->hash)); | 316 | update_tunnel_last_message (sent->tunnel, &(sent->hash)); |
292 | 317 | ||
293 | GNUNET_free(sent); | 318 | GNUNET_free (sent); |
294 | } | 319 | } |
295 | 320 | ||
321 | |||
296 | void | 322 | void |
297 | send_tunnel_envelope (struct GNUNET_MESSENGER_SrvTunnel *tunnel, | 323 | send_tunnel_envelope (struct GNUNET_MESSENGER_SrvTunnel *tunnel, |
298 | struct GNUNET_MQ_Envelope *env, | 324 | struct GNUNET_MQ_Envelope *env, |
299 | const struct GNUNET_HashCode *hash) | 325 | const struct GNUNET_HashCode *hash) |
300 | { | 326 | { |
301 | GNUNET_assert((tunnel) && (env) && (hash)); | 327 | GNUNET_assert ((tunnel) && (env) && (hash)); |
302 | 328 | ||
303 | struct GNUNET_MQ_Handle *mq = GNUNET_CADET_get_mq (tunnel->channel); | 329 | struct GNUNET_MQ_Handle *mq = GNUNET_CADET_get_mq (tunnel->channel); |
304 | 330 | ||
305 | struct GNUNET_MESSENGER_MessageSent *sent = GNUNET_new(struct GNUNET_MESSENGER_MessageSent); | 331 | struct GNUNET_MESSENGER_MessageSent *sent = GNUNET_new (struct |
332 | GNUNET_MESSENGER_MessageSent); | ||
306 | 333 | ||
307 | GNUNET_memcpy(&(sent->hash), hash, sizeof(struct GNUNET_HashCode)); | 334 | GNUNET_memcpy (&(sent->hash), hash, sizeof(struct GNUNET_HashCode)); |
308 | 335 | ||
309 | sent->tunnel = tunnel; | 336 | sent->tunnel = tunnel; |
310 | 337 | ||
@@ -312,85 +339,93 @@ send_tunnel_envelope (struct GNUNET_MESSENGER_SrvTunnel *tunnel, | |||
312 | GNUNET_MQ_send (mq, env); | 339 | GNUNET_MQ_send (mq, env); |
313 | } | 340 | } |
314 | 341 | ||
342 | |||
315 | int | 343 | int |
316 | send_tunnel_message (struct GNUNET_MESSENGER_SrvTunnel *tunnel, | 344 | send_tunnel_message (struct GNUNET_MESSENGER_SrvTunnel *tunnel, |
317 | void *handle, | 345 | void *handle, |
318 | struct GNUNET_MESSENGER_Message *message) | 346 | struct GNUNET_MESSENGER_Message *message) |
319 | { | 347 | { |
320 | GNUNET_assert((tunnel) && (handle)); | 348 | GNUNET_assert ((tunnel) && (handle)); |
321 | 349 | ||
322 | if (!message) | 350 | if (! message) |
323 | return GNUNET_NO; | 351 | return GNUNET_NO; |
324 | 352 | ||
325 | struct GNUNET_HashCode hash; | 353 | struct GNUNET_HashCode hash; |
326 | struct GNUNET_MQ_Envelope *env = pack_srv_room_message ( | 354 | struct GNUNET_MQ_Envelope *env = pack_srv_room_message ( |
327 | tunnel->room, (struct GNUNET_MESSENGER_SrvHandle*) handle, | 355 | tunnel->room, (struct GNUNET_MESSENGER_SrvHandle*) handle, |
328 | message, &hash, GNUNET_MESSENGER_PACK_MODE_ENVELOPE | 356 | message, &hash, GNUNET_MESSENGER_PACK_MODE_ENVELOPE |
329 | ); | 357 | ); |
330 | 358 | ||
331 | destroy_message(message); | 359 | destroy_message (message); |
332 | 360 | ||
333 | if (!env) | 361 | if (! env) |
334 | return GNUNET_NO; | 362 | return GNUNET_NO; |
335 | 363 | ||
336 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending tunnel message: %s\n", | 364 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending tunnel message: %s\n", |
337 | GNUNET_h2s(&hash)); | 365 | GNUNET_h2s (&hash)); |
338 | 366 | ||
339 | send_tunnel_envelope (tunnel, env, &hash); | 367 | send_tunnel_envelope (tunnel, env, &hash); |
340 | return GNUNET_YES; | 368 | return GNUNET_YES; |
341 | } | 369 | } |
342 | 370 | ||
371 | |||
343 | void | 372 | void |
344 | forward_tunnel_message (struct GNUNET_MESSENGER_SrvTunnel *tunnel, | 373 | forward_tunnel_message (struct GNUNET_MESSENGER_SrvTunnel *tunnel, |
345 | const struct GNUNET_MESSENGER_Message *message, | 374 | const struct GNUNET_MESSENGER_Message *message, |
346 | const struct GNUNET_HashCode *hash) | 375 | const struct GNUNET_HashCode *hash) |
347 | { | 376 | { |
348 | GNUNET_assert((tunnel) && (message) && (hash)); | 377 | GNUNET_assert ((tunnel) && (message) && (hash)); |
349 | 378 | ||
350 | struct GNUNET_MESSENGER_Message *copy = copy_message(message); | 379 | struct GNUNET_MESSENGER_Message *copy = copy_message (message); |
351 | struct GNUNET_MQ_Envelope *env = pack_message (copy, NULL, NULL, GNUNET_MESSENGER_PACK_MODE_ENVELOPE, NULL); | 380 | struct GNUNET_MQ_Envelope *env = pack_message (copy, NULL, NULL, |
381 | GNUNET_MESSENGER_PACK_MODE_ENVELOPE, | ||
382 | NULL); | ||
352 | 383 | ||
353 | destroy_message(copy); | 384 | destroy_message (copy); |
354 | 385 | ||
355 | if (!env) | 386 | if (! env) |
356 | return; | 387 | return; |
357 | 388 | ||
358 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Forwarding tunnel message: %s\n", | 389 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Forwarding tunnel message: %s\n", |
359 | GNUNET_h2s(hash)); | 390 | GNUNET_h2s (hash)); |
360 | 391 | ||
361 | send_tunnel_envelope (tunnel, env, hash); | 392 | send_tunnel_envelope (tunnel, env, hash); |
362 | } | 393 | } |
363 | 394 | ||
395 | |||
364 | const struct GNUNET_HashCode* | 396 | const struct GNUNET_HashCode* |
365 | get_tunnel_peer_message (const struct GNUNET_MESSENGER_SrvTunnel *tunnel) | 397 | get_tunnel_peer_message (const struct GNUNET_MESSENGER_SrvTunnel *tunnel) |
366 | { | 398 | { |
367 | GNUNET_assert(tunnel); | 399 | GNUNET_assert (tunnel); |
368 | 400 | ||
369 | return tunnel->peer_message; | 401 | return tunnel->peer_message; |
370 | } | 402 | } |
371 | 403 | ||
404 | |||
372 | void | 405 | void |
373 | get_tunnel_peer_identity (const struct GNUNET_MESSENGER_SrvTunnel *tunnel, | 406 | get_tunnel_peer_identity (const struct GNUNET_MESSENGER_SrvTunnel *tunnel, |
374 | struct GNUNET_PeerIdentity *peer) | 407 | struct GNUNET_PeerIdentity *peer) |
375 | { | 408 | { |
376 | GNUNET_assert(tunnel); | 409 | GNUNET_assert (tunnel); |
377 | 410 | ||
378 | GNUNET_PEER_resolve(tunnel->peer, peer); | 411 | GNUNET_PEER_resolve (tunnel->peer, peer); |
379 | } | 412 | } |
380 | 413 | ||
414 | |||
381 | uint32_t | 415 | uint32_t |
382 | get_tunnel_messenger_version (const struct GNUNET_MESSENGER_SrvTunnel *tunnel) | 416 | get_tunnel_messenger_version (const struct GNUNET_MESSENGER_SrvTunnel *tunnel) |
383 | { | 417 | { |
384 | GNUNET_assert(tunnel); | 418 | GNUNET_assert (tunnel); |
385 | 419 | ||
386 | return tunnel->messenger_version; | 420 | return tunnel->messenger_version; |
387 | } | 421 | } |
388 | 422 | ||
423 | |||
389 | int | 424 | int |
390 | update_tunnel_messenger_version (struct GNUNET_MESSENGER_SrvTunnel *tunnel, | 425 | update_tunnel_messenger_version (struct GNUNET_MESSENGER_SrvTunnel *tunnel, |
391 | uint32_t version) | 426 | uint32_t version) |
392 | { | 427 | { |
393 | GNUNET_assert(tunnel); | 428 | GNUNET_assert (tunnel); |
394 | 429 | ||
395 | if (version != GNUNET_MESSENGER_VERSION) | 430 | if (version != GNUNET_MESSENGER_VERSION) |
396 | return GNUNET_SYSERR; | 431 | return GNUNET_SYSERR; |
diff --git a/src/messenger/messenger_api.c b/src/messenger/messenger_api.c index 82fc0d1eb..fe99e0e8d 100644 --- a/src/messenger/messenger_api.c +++ b/src/messenger/messenger_api.c | |||
@@ -75,6 +75,7 @@ GNUNET_MESSENGER_name_of_kind (enum GNUNET_MESSENGER_MessageKind kind) | |||
75 | } | 75 | } |
76 | } | 76 | } |
77 | 77 | ||
78 | |||
78 | static enum GNUNET_GenericReturnValue | 79 | static enum GNUNET_GenericReturnValue |
79 | dequeue_messages_from_room (struct GNUNET_MESSENGER_Room *room); | 80 | dequeue_messages_from_room (struct GNUNET_MESSENGER_Room *room); |
80 | 81 | ||
@@ -86,7 +87,7 @@ handle_room_open (void *cls, | |||
86 | 87 | ||
87 | const struct GNUNET_HashCode *key = &(msg->key); | 88 | const struct GNUNET_HashCode *key = &(msg->key); |
88 | 89 | ||
89 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Opened room: %s\n", GNUNET_h2s (key)); | 90 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Opened room: %s\n", GNUNET_h2s (key)); |
90 | 91 | ||
91 | open_handle_room (handle, key); | 92 | open_handle_room (handle, key); |
92 | 93 | ||
@@ -96,6 +97,7 @@ handle_room_open (void *cls, | |||
96 | dequeue_messages_from_room (room); | 97 | dequeue_messages_from_room (room); |
97 | } | 98 | } |
98 | 99 | ||
100 | |||
99 | static void | 101 | static void |
100 | handle_room_entry (void *cls, | 102 | handle_room_entry (void *cls, |
101 | const struct GNUNET_MESSENGER_RoomMessage *msg) | 103 | const struct GNUNET_MESSENGER_RoomMessage *msg) |
@@ -115,6 +117,7 @@ handle_room_entry (void *cls, | |||
115 | dequeue_messages_from_room (room); | 117 | dequeue_messages_from_room (room); |
116 | } | 118 | } |
117 | 119 | ||
120 | |||
118 | static void | 121 | static void |
119 | handle_room_close (void *cls, | 122 | handle_room_close (void *cls, |
120 | const struct GNUNET_MESSENGER_RoomMessage *msg) | 123 | const struct GNUNET_MESSENGER_RoomMessage *msg) |
@@ -133,6 +136,7 @@ handle_room_close (void *cls, | |||
133 | close_handle_room (handle, key); | 136 | close_handle_room (handle, key); |
134 | } | 137 | } |
135 | 138 | ||
139 | |||
136 | static void | 140 | static void |
137 | enqueue_message_to_room (struct GNUNET_MESSENGER_Room *room, | 141 | enqueue_message_to_room (struct GNUNET_MESSENGER_Room *room, |
138 | struct GNUNET_MESSENGER_Message *message); | 142 | struct GNUNET_MESSENGER_Message *message); |
@@ -147,13 +151,15 @@ handle_member_id (void *cls, | |||
147 | const struct GNUNET_ShortHashCode *id = &(msg->id); | 151 | const struct GNUNET_ShortHashCode *id = &(msg->id); |
148 | const uint32_t reset = msg->reset; | 152 | const uint32_t reset = msg->reset; |
149 | 153 | ||
150 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Changed member id in room: %s\n", GNUNET_h2s (key)); | 154 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Changed member id in room: %s\n", |
155 | GNUNET_h2s (key)); | ||
151 | 156 | ||
152 | struct GNUNET_MESSENGER_Room *room = get_handle_room (handle, key); | 157 | struct GNUNET_MESSENGER_Room *room = get_handle_room (handle, key); |
153 | 158 | ||
154 | if (!room) | 159 | if (! room) |
155 | { | 160 | { |
156 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Room is unknown to handle: %s\n", GNUNET_h2s (key)); | 161 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Room is unknown to handle: %s\n", |
162 | GNUNET_h2s (key)); | ||
157 | return; | 163 | return; |
158 | } | 164 | } |
159 | 165 | ||
@@ -161,7 +167,7 @@ handle_member_id (void *cls, | |||
161 | switch (reset) | 167 | switch (reset) |
162 | { | 168 | { |
163 | case GNUNET_YES: | 169 | case GNUNET_YES: |
164 | set_room_sender_id(room, id); | 170 | set_room_sender_id (room, id); |
165 | message = create_message_join (get_handle_key (handle)); | 171 | message = create_message_join (get_handle_key (handle)); |
166 | break; | 172 | break; |
167 | case GNUNET_NO: | 173 | case GNUNET_NO: |
@@ -171,13 +177,14 @@ handle_member_id (void *cls, | |||
171 | break; | 177 | break; |
172 | } | 178 | } |
173 | 179 | ||
174 | if (!message) | 180 | if (! message) |
175 | return; | 181 | return; |
176 | 182 | ||
177 | enqueue_message_to_room (room, message); | 183 | enqueue_message_to_room (room, message); |
178 | destroy_message (message); | 184 | destroy_message (message); |
179 | } | 185 | } |
180 | 186 | ||
187 | |||
181 | static int | 188 | static int |
182 | check_recv_message (void *cls, | 189 | check_recv_message (void *cls, |
183 | const struct GNUNET_MESSENGER_RecvMessage *msg) | 190 | const struct GNUNET_MESSENGER_RecvMessage *msg) |
@@ -186,7 +193,8 @@ check_recv_message (void *cls, | |||
186 | 193 | ||
187 | if (full_length < sizeof(*msg)) | 194 | if (full_length < sizeof(*msg)) |
188 | { | 195 | { |
189 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Receiving failed: Message invalid!\n"); | 196 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
197 | "Receiving failed: Message invalid!\n"); | ||
190 | return GNUNET_NO; | 198 | return GNUNET_NO; |
191 | } | 199 | } |
192 | 200 | ||
@@ -195,22 +203,26 @@ check_recv_message (void *cls, | |||
195 | 203 | ||
196 | struct GNUNET_MESSENGER_Message message; | 204 | struct GNUNET_MESSENGER_Message message; |
197 | 205 | ||
198 | if (length < get_message_kind_size(GNUNET_MESSENGER_KIND_UNKNOWN, GNUNET_YES)) | 206 | if (length < get_message_kind_size (GNUNET_MESSENGER_KIND_UNKNOWN, |
207 | GNUNET_YES)) | ||
199 | { | 208 | { |
200 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Receiving failed: Message too short!\n"); | 209 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
210 | "Receiving failed: Message too short!\n"); | ||
201 | return GNUNET_NO; | 211 | return GNUNET_NO; |
202 | } | 212 | } |
203 | 213 | ||
204 | if (GNUNET_YES != decode_message (&message, length, buffer, GNUNET_YES, NULL)) | 214 | if (GNUNET_YES != decode_message (&message, length, buffer, GNUNET_YES, NULL)) |
205 | { | 215 | { |
206 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Receiving failed: Message decoding failed!\n"); | 216 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
217 | "Receiving failed: Message decoding failed!\n"); | ||
207 | return GNUNET_NO; | 218 | return GNUNET_NO; |
208 | } | 219 | } |
209 | 220 | ||
210 | cleanup_message(&message); | 221 | cleanup_message (&message); |
211 | return GNUNET_OK; | 222 | return GNUNET_OK; |
212 | } | 223 | } |
213 | 224 | ||
225 | |||
214 | static void | 226 | static void |
215 | handle_recv_message (void *cls, | 227 | handle_recv_message (void *cls, |
216 | const struct GNUNET_MESSENGER_RecvMessage *msg) | 228 | const struct GNUNET_MESSENGER_RecvMessage *msg) |
@@ -223,8 +235,8 @@ handle_recv_message (void *cls, | |||
223 | const struct GNUNET_HashCode *hash = &(msg->hash); | 235 | const struct GNUNET_HashCode *hash = &(msg->hash); |
224 | 236 | ||
225 | enum GNUNET_MESSENGER_MessageFlags flags = ( | 237 | enum GNUNET_MESSENGER_MessageFlags flags = ( |
226 | (enum GNUNET_MESSENGER_MessageFlags) (msg->flags) | 238 | (enum GNUNET_MESSENGER_MessageFlags) (msg->flags) |
227 | ); | 239 | ); |
228 | 240 | ||
229 | const uint16_t length = ntohs (msg->header.size) - sizeof(*msg); | 241 | const uint16_t length = ntohs (msg->header.size) - sizeof(*msg); |
230 | const char *buffer = ((const char*) msg) + sizeof(*msg); | 242 | const char *buffer = ((const char*) msg) + sizeof(*msg); |
@@ -235,11 +247,12 @@ handle_recv_message (void *cls, | |||
235 | struct GNUNET_MESSENGER_Message *private_message = NULL; | 247 | struct GNUNET_MESSENGER_Message *private_message = NULL; |
236 | if (GNUNET_MESSENGER_KIND_PRIVATE == message.header.kind) | 248 | if (GNUNET_MESSENGER_KIND_PRIVATE == message.header.kind) |
237 | { | 249 | { |
238 | private_message = copy_message(&message); | 250 | private_message = copy_message (&message); |
239 | 251 | ||
240 | if (GNUNET_YES != decrypt_message(private_message, get_handle_key(handle))) | 252 | if (GNUNET_YES != decrypt_message (private_message, get_handle_key ( |
253 | handle))) | ||
241 | { | 254 | { |
242 | destroy_message(private_message); | 255 | destroy_message (private_message); |
243 | private_message = NULL; | 256 | private_message = NULL; |
244 | } | 257 | } |
245 | } | 258 | } |
@@ -248,37 +261,46 @@ handle_recv_message (void *cls, | |||
248 | flags |= GNUNET_MESSENGER_FLAG_PRIVATE; | 261 | flags |= GNUNET_MESSENGER_FLAG_PRIVATE; |
249 | 262 | ||
250 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving message: %s\n", | 263 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving message: %s\n", |
251 | GNUNET_MESSENGER_name_of_kind (private_message ? private_message->header.kind : message.header.kind)); | 264 | GNUNET_MESSENGER_name_of_kind (private_message ? |
265 | private_message->header.kind : | ||
266 | message.header.kind)); | ||
252 | 267 | ||
253 | struct GNUNET_MESSENGER_Room *room = get_handle_room(handle, key); | 268 | struct GNUNET_MESSENGER_Room *room = get_handle_room (handle, key); |
254 | 269 | ||
255 | if (room) | 270 | if (room) |
256 | { | 271 | { |
257 | struct GNUNET_MESSENGER_ContactStore *store = get_handle_contact_store(handle); | 272 | struct GNUNET_MESSENGER_ContactStore *store = get_handle_contact_store ( |
273 | handle); | ||
258 | 274 | ||
259 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Raw contact from sender and context: (%s : %s)\n", | 275 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
260 | GNUNET_h2s(sender), GNUNET_h2s_full(context)); | 276 | "Raw contact from sender and context: (%s : %s)\n", |
277 | GNUNET_h2s (sender), GNUNET_h2s_full (context)); | ||
261 | 278 | ||
262 | struct GNUNET_MESSENGER_Contact *contact = get_store_contact_raw( | 279 | struct GNUNET_MESSENGER_Contact *contact = get_store_contact_raw ( |
263 | store, context, sender | 280 | store, context, sender |
264 | ); | 281 | ); |
265 | 282 | ||
266 | contact = handle_room_message (room, contact, private_message ? private_message : &message, hash, flags); | 283 | contact = handle_room_message (room, contact, private_message ? |
284 | private_message : &message, hash, flags); | ||
267 | 285 | ||
268 | const struct GNUNET_MESSENGER_Message *stored_message = get_room_message(room, hash); | 286 | const struct GNUNET_MESSENGER_Message *stored_message = get_room_message ( |
287 | room, hash); | ||
269 | 288 | ||
270 | if (handle->msg_callback) | 289 | if (handle->msg_callback) |
271 | handle->msg_callback (handle->msg_cls, room, contact, stored_message, hash, flags); | 290 | handle->msg_callback (handle->msg_cls, room, contact, stored_message, |
291 | hash, flags); | ||
272 | } | 292 | } |
273 | else | 293 | else |
274 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unknown room for this client: %s\n", GNUNET_h2s (key)); | 294 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unknown room for this client: %s\n", |
295 | GNUNET_h2s (key)); | ||
275 | 296 | ||
276 | cleanup_message(&message); | 297 | cleanup_message (&message); |
277 | 298 | ||
278 | if (private_message) | 299 | if (private_message) |
279 | destroy_message(private_message); | 300 | destroy_message (private_message); |
280 | } | 301 | } |
281 | 302 | ||
303 | |||
282 | static void | 304 | static void |
283 | handle_miss_message (void *cls, | 305 | handle_miss_message (void *cls, |
284 | const struct GNUNET_MESSENGER_GetMessage *msg) | 306 | const struct GNUNET_MESSENGER_GetMessage *msg) |
@@ -288,27 +310,30 @@ handle_miss_message (void *cls, | |||
288 | const struct GNUNET_HashCode *key = &(msg->key); | 310 | const struct GNUNET_HashCode *key = &(msg->key); |
289 | const struct GNUNET_HashCode *hash = &(msg->hash); | 311 | const struct GNUNET_HashCode *hash = &(msg->hash); |
290 | 312 | ||
291 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Missing message in room: %s\n", GNUNET_h2s (hash)); | 313 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Missing message in room: %s\n", |
314 | GNUNET_h2s (hash)); | ||
292 | 315 | ||
293 | struct GNUNET_MESSENGER_Room *room = get_handle_room(handle, key); | 316 | struct GNUNET_MESSENGER_Room *room = get_handle_room (handle, key); |
294 | 317 | ||
295 | if (!room) | 318 | if (! room) |
296 | { | 319 | { |
297 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Miss in unknown room for this client: %s\n", GNUNET_h2s (key)); | 320 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
321 | "Miss in unknown room for this client: %s\n", GNUNET_h2s (key)); | ||
298 | return; | 322 | return; |
299 | } | 323 | } |
300 | 324 | ||
301 | if (!get_room_sender_id(room)) | 325 | if (! get_room_sender_id (room)) |
302 | return; | 326 | return; |
303 | 327 | ||
304 | struct GNUNET_MESSENGER_Message *message = create_message_request (hash); | 328 | struct GNUNET_MESSENGER_Message *message = create_message_request (hash); |
305 | if (!message) | 329 | if (! message) |
306 | return; | 330 | return; |
307 | 331 | ||
308 | enqueue_message_to_room (room, message); | 332 | enqueue_message_to_room (room, message); |
309 | destroy_message (message); | 333 | destroy_message (message); |
310 | } | 334 | } |
311 | 335 | ||
336 | |||
312 | static void | 337 | static void |
313 | reconnect (struct GNUNET_MESSENGER_Handle *handle); | 338 | reconnect (struct GNUNET_MESSENGER_Handle *handle); |
314 | 339 | ||
@@ -316,34 +341,37 @@ static void | |||
316 | send_open_room (struct GNUNET_MESSENGER_Handle *handle, | 341 | send_open_room (struct GNUNET_MESSENGER_Handle *handle, |
317 | struct GNUNET_MESSENGER_Room *room) | 342 | struct GNUNET_MESSENGER_Room *room) |
318 | { | 343 | { |
319 | const struct GNUNET_IDENTITY_PublicKey *key = get_handle_pubkey(handle); | 344 | const struct GNUNET_IDENTITY_PublicKey *key = get_handle_pubkey (handle); |
320 | 345 | ||
321 | struct GNUNET_MESSENGER_RoomMessage *msg; | 346 | struct GNUNET_MESSENGER_RoomMessage *msg; |
322 | struct GNUNET_MQ_Envelope *env; | 347 | struct GNUNET_MQ_Envelope *env; |
323 | 348 | ||
324 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Open room (%s) by member using key: %s\n", | 349 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
350 | "Open room (%s) by member using key: %s\n", | ||
325 | GNUNET_h2s (&(room->key)), | 351 | GNUNET_h2s (&(room->key)), |
326 | GNUNET_IDENTITY_public_key_to_string (key)); | 352 | GNUNET_IDENTITY_public_key_to_string (key)); |
327 | 353 | ||
328 | const ssize_t len = GNUNET_IDENTITY_public_key_get_length(key); | 354 | const ssize_t len = GNUNET_IDENTITY_public_key_get_length (key); |
329 | 355 | ||
330 | env = GNUNET_MQ_msg_extra(msg, len > 0 ? len : 0, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN); | 356 | env = GNUNET_MQ_msg_extra (msg, len > 0 ? len : 0, |
331 | GNUNET_memcpy(&(msg->key), &(room->key), sizeof(msg->key)); | 357 | GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN); |
358 | GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key)); | ||
332 | 359 | ||
333 | char *msg_buffer = ((char*) msg) + sizeof(*msg); | 360 | char *msg_buffer = ((char*) msg) + sizeof(*msg); |
334 | 361 | ||
335 | if (len > 0) | 362 | if (len > 0) |
336 | GNUNET_IDENTITY_write_public_key_to_buffer(key, msg_buffer, len); | 363 | GNUNET_IDENTITY_write_public_key_to_buffer (key, msg_buffer, len); |
337 | 364 | ||
338 | GNUNET_MQ_send (handle->mq, env); | 365 | GNUNET_MQ_send (handle->mq, env); |
339 | } | 366 | } |
340 | 367 | ||
368 | |||
341 | static void | 369 | static void |
342 | send_enter_room (struct GNUNET_MESSENGER_Handle *handle, | 370 | send_enter_room (struct GNUNET_MESSENGER_Handle *handle, |
343 | struct GNUNET_MESSENGER_Room *room, | 371 | struct GNUNET_MESSENGER_Room *room, |
344 | const struct GNUNET_PeerIdentity *door) | 372 | const struct GNUNET_PeerIdentity *door) |
345 | { | 373 | { |
346 | const struct GNUNET_IDENTITY_PublicKey *key = get_handle_pubkey(handle); | 374 | const struct GNUNET_IDENTITY_PublicKey *key = get_handle_pubkey (handle); |
347 | 375 | ||
348 | struct GNUNET_MESSENGER_RoomMessage *msg; | 376 | struct GNUNET_MESSENGER_RoomMessage *msg; |
349 | struct GNUNET_MQ_Envelope *env; | 377 | struct GNUNET_MQ_Envelope *env; |
@@ -353,20 +381,22 @@ send_enter_room (struct GNUNET_MESSENGER_Handle *handle, | |||
353 | GNUNET_i2s (door), | 381 | GNUNET_i2s (door), |
354 | GNUNET_IDENTITY_public_key_to_string (key)); | 382 | GNUNET_IDENTITY_public_key_to_string (key)); |
355 | 383 | ||
356 | const ssize_t len = GNUNET_IDENTITY_public_key_get_length(key); | 384 | const ssize_t len = GNUNET_IDENTITY_public_key_get_length (key); |
357 | 385 | ||
358 | env = GNUNET_MQ_msg_extra(msg, len > 0 ? len : 0, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY); | 386 | env = GNUNET_MQ_msg_extra (msg, len > 0 ? len : 0, |
359 | GNUNET_memcpy(&(msg->door), door, sizeof(*door)); | 387 | GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY); |
360 | GNUNET_memcpy(&(msg->key), &(room->key), sizeof(msg->key)); | 388 | GNUNET_memcpy (&(msg->door), door, sizeof(*door)); |
389 | GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key)); | ||
361 | 390 | ||
362 | char *msg_buffer = ((char*) msg) + sizeof(*msg); | 391 | char *msg_buffer = ((char*) msg) + sizeof(*msg); |
363 | 392 | ||
364 | if (len > 0) | 393 | if (len > 0) |
365 | GNUNET_IDENTITY_write_public_key_to_buffer(key, msg_buffer, len); | 394 | GNUNET_IDENTITY_write_public_key_to_buffer (key, msg_buffer, len); |
366 | 395 | ||
367 | GNUNET_MQ_send (handle->mq, env); | 396 | GNUNET_MQ_send (handle->mq, env); |
368 | } | 397 | } |
369 | 398 | ||
399 | |||
370 | static void | 400 | static void |
371 | send_close_room (struct GNUNET_MESSENGER_Handle *handle, | 401 | send_close_room (struct GNUNET_MESSENGER_Handle *handle, |
372 | struct GNUNET_MESSENGER_Room *room) | 402 | struct GNUNET_MESSENGER_Room *room) |
@@ -377,11 +407,12 @@ send_close_room (struct GNUNET_MESSENGER_Handle *handle, | |||
377 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Close room (%s)!\n", | 407 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Close room (%s)!\n", |
378 | GNUNET_h2s (&(room->key))); | 408 | GNUNET_h2s (&(room->key))); |
379 | 409 | ||
380 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_CLOSE); | 410 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_CLOSE); |
381 | GNUNET_memcpy(&(msg->key), &(room->key), sizeof(msg->key)); | 411 | GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key)); |
382 | GNUNET_MQ_send (handle->mq, env); | 412 | GNUNET_MQ_send (handle->mq, env); |
383 | } | 413 | } |
384 | 414 | ||
415 | |||
385 | static int | 416 | static int |
386 | iterate_reset_room (void *cls, | 417 | iterate_reset_room (void *cls, |
387 | const struct GNUNET_HashCode *key, | 418 | const struct GNUNET_HashCode *key, |
@@ -409,21 +440,24 @@ iterate_reset_room (void *cls, | |||
409 | return GNUNET_YES; | 440 | return GNUNET_YES; |
410 | } | 441 | } |
411 | 442 | ||
443 | |||
412 | static void | 444 | static void |
413 | callback_reconnect (void *cls) | 445 | callback_reconnect (void *cls) |
414 | { | 446 | { |
415 | struct GNUNET_MESSENGER_Handle *handle = cls; | 447 | struct GNUNET_MESSENGER_Handle *handle = cls; |
416 | 448 | ||
417 | handle->reconnect_task = NULL; | 449 | handle->reconnect_task = NULL; |
418 | handle->reconnect_time = GNUNET_TIME_STD_BACKOFF(handle->reconnect_time); | 450 | handle->reconnect_time = GNUNET_TIME_STD_BACKOFF (handle->reconnect_time); |
419 | 451 | ||
420 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reconnect messenger!\n"); | 452 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reconnect messenger!\n"); |
421 | 453 | ||
422 | reconnect (handle); | 454 | reconnect (handle); |
423 | 455 | ||
424 | GNUNET_CONTAINER_multihashmap_iterate (handle->rooms, iterate_reset_room, handle); | 456 | GNUNET_CONTAINER_multihashmap_iterate (handle->rooms, iterate_reset_room, |
457 | handle); | ||
425 | } | 458 | } |
426 | 459 | ||
460 | |||
427 | static int | 461 | static int |
428 | iterate_close_room (void *cls, | 462 | iterate_close_room (void *cls, |
429 | const struct GNUNET_HashCode *key, | 463 | const struct GNUNET_HashCode *key, |
@@ -437,15 +471,17 @@ iterate_close_room (void *cls, | |||
437 | return GNUNET_YES; | 471 | return GNUNET_YES; |
438 | } | 472 | } |
439 | 473 | ||
474 | |||
440 | static void | 475 | static void |
441 | callback_mq_error (void *cls, | 476 | callback_mq_error (void *cls, |
442 | enum GNUNET_MQ_Error error) | 477 | enum GNUNET_MQ_Error error) |
443 | { | 478 | { |
444 | struct GNUNET_MESSENGER_Handle *handle = cls; | 479 | struct GNUNET_MESSENGER_Handle *handle = cls; |
445 | 480 | ||
446 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "MQ_Error: %u\n", error); | 481 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MQ_Error: %u\n", error); |
447 | 482 | ||
448 | GNUNET_CONTAINER_multihashmap_iterate (handle->rooms, iterate_close_room, handle); | 483 | GNUNET_CONTAINER_multihashmap_iterate (handle->rooms, iterate_close_room, |
484 | handle); | ||
449 | 485 | ||
450 | if (handle->mq) | 486 | if (handle->mq) |
451 | { | 487 | { |
@@ -453,50 +489,55 @@ callback_mq_error (void *cls, | |||
453 | handle->mq = NULL; | 489 | handle->mq = NULL; |
454 | } | 490 | } |
455 | 491 | ||
456 | handle->reconnect_task = GNUNET_SCHEDULER_add_delayed (handle->reconnect_time, &callback_reconnect, handle); | 492 | handle->reconnect_task = GNUNET_SCHEDULER_add_delayed (handle->reconnect_time, |
493 | &callback_reconnect, | ||
494 | handle); | ||
457 | } | 495 | } |
458 | 496 | ||
497 | |||
459 | static void | 498 | static void |
460 | reconnect (struct GNUNET_MESSENGER_Handle *handle) | 499 | reconnect (struct GNUNET_MESSENGER_Handle *handle) |
461 | { | 500 | { |
462 | const struct GNUNET_MQ_MessageHandler handlers[] = | 501 | const struct GNUNET_MQ_MessageHandler handlers[] = { |
463 | { | 502 | GNUNET_MQ_hd_fixed_size ( |
464 | GNUNET_MQ_hd_fixed_size( | 503 | member_id, |
465 | member_id, | 504 | GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_MEMBER_ID, |
466 | GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_MEMBER_ID, | 505 | struct GNUNET_MESSENGER_MemberMessage, handle |
467 | struct GNUNET_MESSENGER_MemberMessage, handle | 506 | ), |
468 | ), | 507 | GNUNET_MQ_hd_fixed_size ( |
469 | GNUNET_MQ_hd_fixed_size( | 508 | room_open, |
470 | room_open, | 509 | GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN, |
471 | GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN, | 510 | struct GNUNET_MESSENGER_RoomMessage, handle |
472 | struct GNUNET_MESSENGER_RoomMessage, handle | 511 | ), |
473 | ), | 512 | GNUNET_MQ_hd_fixed_size ( |
474 | GNUNET_MQ_hd_fixed_size( | 513 | room_entry, |
475 | room_entry, | 514 | GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY, |
476 | GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY, | 515 | struct GNUNET_MESSENGER_RoomMessage, handle |
477 | struct GNUNET_MESSENGER_RoomMessage, handle | 516 | ), |
478 | ), | 517 | GNUNET_MQ_hd_fixed_size ( |
479 | GNUNET_MQ_hd_fixed_size( | 518 | room_close, |
480 | room_close, | 519 | GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_CLOSE, |
481 | GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_CLOSE, | 520 | struct GNUNET_MESSENGER_RoomMessage, handle |
482 | struct GNUNET_MESSENGER_RoomMessage, handle | 521 | ), |
483 | ), | 522 | GNUNET_MQ_hd_var_size ( |
484 | GNUNET_MQ_hd_var_size( | 523 | recv_message, |
485 | recv_message, | 524 | GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_RECV_MESSAGE, |
486 | GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_RECV_MESSAGE, | 525 | struct GNUNET_MESSENGER_RecvMessage, handle |
487 | struct GNUNET_MESSENGER_RecvMessage, handle | 526 | ), |
488 | ), | 527 | GNUNET_MQ_hd_fixed_size ( |
489 | GNUNET_MQ_hd_fixed_size( | 528 | miss_message, |
490 | miss_message, | 529 | GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE, |
491 | GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE, | 530 | struct GNUNET_MESSENGER_GetMessage, handle |
492 | struct GNUNET_MESSENGER_GetMessage, handle | 531 | ), |
493 | ), | 532 | GNUNET_MQ_handler_end () |
494 | GNUNET_MQ_handler_end() | ||
495 | }; | 533 | }; |
496 | 534 | ||
497 | handle->mq = GNUNET_CLIENT_connect (handle->cfg, GNUNET_MESSENGER_SERVICE_NAME, handlers, &callback_mq_error, handle); | 535 | handle->mq = GNUNET_CLIENT_connect (handle->cfg, |
536 | GNUNET_MESSENGER_SERVICE_NAME, handlers, | ||
537 | &callback_mq_error, handle); | ||
498 | } | 538 | } |
499 | 539 | ||
540 | |||
500 | struct GNUNET_MESSENGER_Handle* | 541 | struct GNUNET_MESSENGER_Handle* |
501 | GNUNET_MESSENGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | 542 | GNUNET_MESSENGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, |
502 | const char *name, | 543 | const char *name, |
@@ -504,7 +545,8 @@ GNUNET_MESSENGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
504 | GNUNET_MESSENGER_MessageCallback msg_callback, | 545 | GNUNET_MESSENGER_MessageCallback msg_callback, |
505 | void *msg_cls) | 546 | void *msg_cls) |
506 | { | 547 | { |
507 | struct GNUNET_MESSENGER_Handle *handle = create_handle (cfg, msg_callback, msg_cls); | 548 | struct GNUNET_MESSENGER_Handle *handle = create_handle (cfg, msg_callback, |
549 | msg_cls); | ||
508 | 550 | ||
509 | reconnect (handle); | 551 | reconnect (handle); |
510 | 552 | ||
@@ -512,13 +554,13 @@ GNUNET_MESSENGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
512 | { | 554 | { |
513 | set_handle_name (handle, name); | 555 | set_handle_name (handle, name); |
514 | 556 | ||
515 | if ((!key) || (0 < GNUNET_IDENTITY_private_key_get_length (key))) | 557 | if ((! key) || (0 < GNUNET_IDENTITY_private_key_get_length (key))) |
516 | set_handle_key (handle, key); | 558 | set_handle_key (handle, key); |
517 | 559 | ||
518 | struct GNUNET_MESSENGER_CreateMessage *msg; | 560 | struct GNUNET_MESSENGER_CreateMessage *msg; |
519 | struct GNUNET_MQ_Envelope *env; | 561 | struct GNUNET_MQ_Envelope *env; |
520 | 562 | ||
521 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_CREATE); | 563 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_CREATE); |
522 | GNUNET_MQ_send (handle->mq, env); | 564 | GNUNET_MQ_send (handle->mq, env); |
523 | return handle; | 565 | return handle; |
524 | } | 566 | } |
@@ -529,21 +571,23 @@ GNUNET_MESSENGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
529 | } | 571 | } |
530 | } | 572 | } |
531 | 573 | ||
574 | |||
532 | void | 575 | void |
533 | GNUNET_MESSENGER_disconnect (struct GNUNET_MESSENGER_Handle *handle) | 576 | GNUNET_MESSENGER_disconnect (struct GNUNET_MESSENGER_Handle *handle) |
534 | { | 577 | { |
535 | if (!handle) | 578 | if (! handle) |
536 | return; | 579 | return; |
537 | 580 | ||
538 | struct GNUNET_MESSENGER_DestroyMessage *msg; | 581 | struct GNUNET_MESSENGER_DestroyMessage *msg; |
539 | struct GNUNET_MQ_Envelope *env; | 582 | struct GNUNET_MQ_Envelope *env; |
540 | 583 | ||
541 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_DESTROY); | 584 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_DESTROY); |
542 | GNUNET_MQ_send (handle->mq, env); | 585 | GNUNET_MQ_send (handle->mq, env); |
543 | 586 | ||
544 | destroy_handle (handle); | 587 | destroy_handle (handle); |
545 | } | 588 | } |
546 | 589 | ||
590 | |||
547 | static void | 591 | static void |
548 | send_message_to_room (struct GNUNET_MESSENGER_Room *room, | 592 | send_message_to_room (struct GNUNET_MESSENGER_Room *room, |
549 | struct GNUNET_MESSENGER_Message *message, | 593 | struct GNUNET_MESSENGER_Message *message, |
@@ -551,10 +595,13 @@ send_message_to_room (struct GNUNET_MESSENGER_Room *room, | |||
551 | { | 595 | { |
552 | const struct GNUNET_ShortHashCode *sender_id = get_room_sender_id (room); | 596 | const struct GNUNET_ShortHashCode *sender_id = get_room_sender_id (room); |
553 | 597 | ||
554 | message->header.timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); | 598 | message->header.timestamp = GNUNET_TIME_absolute_hton ( |
599 | GNUNET_TIME_absolute_get ()); | ||
555 | 600 | ||
556 | GNUNET_memcpy (&(message->header.sender_id), sender_id, sizeof(message->header.sender_id)); | 601 | GNUNET_memcpy (&(message->header.sender_id), sender_id, |
557 | GNUNET_memcpy (&(message->header.previous), &(room->last_message), sizeof(message->header.previous)); | 602 | sizeof(message->header.sender_id)); |
603 | GNUNET_memcpy (&(message->header.previous), &(room->last_message), | ||
604 | sizeof(message->header.previous)); | ||
558 | 605 | ||
559 | message->header.signature.type = key->type; | 606 | message->header.signature.type = key->type; |
560 | 607 | ||
@@ -563,12 +610,12 @@ send_message_to_room (struct GNUNET_MESSENGER_Room *room, | |||
563 | struct GNUNET_MESSENGER_SendMessage *msg; | 610 | struct GNUNET_MESSENGER_SendMessage *msg; |
564 | struct GNUNET_MQ_Envelope *env; | 611 | struct GNUNET_MQ_Envelope *env; |
565 | 612 | ||
566 | env = GNUNET_MQ_msg_extra( | 613 | env = GNUNET_MQ_msg_extra ( |
567 | msg, msg_length, | 614 | msg, msg_length, |
568 | GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_SEND_MESSAGE | 615 | GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_SEND_MESSAGE |
569 | ); | 616 | ); |
570 | 617 | ||
571 | GNUNET_memcpy(&(msg->key), &(room->key), sizeof(msg->key)); | 618 | GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key)); |
572 | 619 | ||
573 | char *msg_buffer = ((char*) msg) + sizeof(*msg); | 620 | char *msg_buffer = ((char*) msg) + sizeof(*msg); |
574 | encode_message (message, msg_length, msg_buffer, GNUNET_YES); | 621 | encode_message (message, msg_length, msg_buffer, GNUNET_YES); |
@@ -582,6 +629,7 @@ send_message_to_room (struct GNUNET_MESSENGER_Room *room, | |||
582 | GNUNET_MQ_send (room->handle->mq, env); | 629 | GNUNET_MQ_send (room->handle->mq, env); |
583 | } | 630 | } |
584 | 631 | ||
632 | |||
585 | static void | 633 | static void |
586 | enqueue_message_to_room (struct GNUNET_MESSENGER_Room *room, | 634 | enqueue_message_to_room (struct GNUNET_MESSENGER_Room *room, |
587 | struct GNUNET_MESSENGER_Message *message) | 635 | struct GNUNET_MESSENGER_Message *message) |
@@ -594,9 +642,10 @@ enqueue_message_to_room (struct GNUNET_MESSENGER_Room *room, | |||
594 | send_message_to_room (room, message, key); | 642 | send_message_to_room (room, message, key); |
595 | } | 643 | } |
596 | else | 644 | else |
597 | enqueue_to_messages(&(room->queue), key, message); | 645 | enqueue_to_messages (&(room->queue), key, message); |
598 | } | 646 | } |
599 | 647 | ||
648 | |||
600 | static enum GNUNET_GenericReturnValue | 649 | static enum GNUNET_GenericReturnValue |
601 | dequeue_messages_from_room (struct GNUNET_MESSENGER_Room *room) | 650 | dequeue_messages_from_room (struct GNUNET_MESSENGER_Room *room) |
602 | { | 651 | { |
@@ -608,28 +657,30 @@ dequeue_messages_from_room (struct GNUNET_MESSENGER_Room *room) | |||
608 | 657 | ||
609 | do { | 658 | do { |
610 | if (message) | 659 | if (message) |
611 | destroy_message(message); | 660 | destroy_message (message); |
612 | 661 | ||
613 | message = dequeue_from_messages(&(room->queue), &key); | 662 | message = dequeue_from_messages (&(room->queue), &key); |
614 | 663 | ||
615 | if (message) | 664 | if (message) |
616 | send_message_to_room(room, message, &key); | 665 | send_message_to_room (room, message, &key); |
617 | } while (message); | 666 | } while (message); |
618 | 667 | ||
619 | return GNUNET_YES; | 668 | return GNUNET_YES; |
620 | } | 669 | } |
621 | 670 | ||
671 | |||
622 | const char* | 672 | const char* |
623 | GNUNET_MESSENGER_get_name (const struct GNUNET_MESSENGER_Handle *handle) | 673 | GNUNET_MESSENGER_get_name (const struct GNUNET_MESSENGER_Handle *handle) |
624 | { | 674 | { |
625 | if (!handle) | 675 | if (! handle) |
626 | return NULL; | 676 | return NULL; |
627 | 677 | ||
628 | return get_handle_name (handle); | 678 | return get_handle_name (handle); |
629 | } | 679 | } |
630 | 680 | ||
681 | |||
631 | static int | 682 | static int |
632 | iterate_send_name_to_room (void* cls, | 683 | iterate_send_name_to_room (void *cls, |
633 | struct GNUNET_MESSENGER_Room *room, | 684 | struct GNUNET_MESSENGER_Room *room, |
634 | const struct GNUNET_MESSENGER_Contact *contact) | 685 | const struct GNUNET_MESSENGER_Contact *contact) |
635 | { | 686 | { |
@@ -638,14 +689,14 @@ iterate_send_name_to_room (void* cls, | |||
638 | if (GNUNET_YES != room->use_handle_name) | 689 | if (GNUNET_YES != room->use_handle_name) |
639 | return GNUNET_YES; | 690 | return GNUNET_YES; |
640 | 691 | ||
641 | const char *name = get_handle_name(handle); | 692 | const char *name = get_handle_name (handle); |
642 | 693 | ||
643 | if (!name) | 694 | if (! name) |
644 | return GNUNET_YES; | 695 | return GNUNET_YES; |
645 | 696 | ||
646 | struct GNUNET_MESSENGER_Message *message = create_message_name (name); | 697 | struct GNUNET_MESSENGER_Message *message = create_message_name (name); |
647 | 698 | ||
648 | if (!message) | 699 | if (! message) |
649 | return GNUNET_NO; | 700 | return GNUNET_NO; |
650 | 701 | ||
651 | enqueue_message_to_room (room, message); | 702 | enqueue_message_to_room (room, message); |
@@ -653,11 +704,12 @@ iterate_send_name_to_room (void* cls, | |||
653 | return GNUNET_YES; | 704 | return GNUNET_YES; |
654 | } | 705 | } |
655 | 706 | ||
707 | |||
656 | int | 708 | int |
657 | GNUNET_MESSENGER_set_name (struct GNUNET_MESSENGER_Handle *handle, | 709 | GNUNET_MESSENGER_set_name (struct GNUNET_MESSENGER_Handle *handle, |
658 | const char *name) | 710 | const char *name) |
659 | { | 711 | { |
660 | if (!handle) | 712 | if (! handle) |
661 | return GNUNET_SYSERR; | 713 | return GNUNET_SYSERR; |
662 | 714 | ||
663 | set_handle_name (handle, strlen (name) > 0 ? name : NULL); | 715 | set_handle_name (handle, strlen (name) > 0 ? name : NULL); |
@@ -665,26 +717,29 @@ GNUNET_MESSENGER_set_name (struct GNUNET_MESSENGER_Handle *handle, | |||
665 | return GNUNET_YES; | 717 | return GNUNET_YES; |
666 | } | 718 | } |
667 | 719 | ||
720 | |||
668 | static const struct GNUNET_IDENTITY_PublicKey* | 721 | static const struct GNUNET_IDENTITY_PublicKey* |
669 | get_non_anonymous_key (const struct GNUNET_IDENTITY_PublicKey* public_key) | 722 | get_non_anonymous_key (const struct GNUNET_IDENTITY_PublicKey *public_key) |
670 | { | 723 | { |
671 | if (0 == GNUNET_memcmp(public_key, get_anonymous_public_key ())) | 724 | if (0 == GNUNET_memcmp (public_key, get_anonymous_public_key ())) |
672 | return NULL; | 725 | return NULL; |
673 | 726 | ||
674 | return public_key; | 727 | return public_key; |
675 | } | 728 | } |
676 | 729 | ||
730 | |||
677 | const struct GNUNET_IDENTITY_PublicKey* | 731 | const struct GNUNET_IDENTITY_PublicKey* |
678 | GNUNET_MESSENGER_get_key (const struct GNUNET_MESSENGER_Handle *handle) | 732 | GNUNET_MESSENGER_get_key (const struct GNUNET_MESSENGER_Handle *handle) |
679 | { | 733 | { |
680 | if (!handle) | 734 | if (! handle) |
681 | return NULL; | 735 | return NULL; |
682 | 736 | ||
683 | return get_non_anonymous_key (get_handle_pubkey (handle)); | 737 | return get_non_anonymous_key (get_handle_pubkey (handle)); |
684 | } | 738 | } |
685 | 739 | ||
740 | |||
686 | static int | 741 | static int |
687 | iterate_send_key_to_room (void* cls, | 742 | iterate_send_key_to_room (void *cls, |
688 | struct GNUNET_MESSENGER_Room *room, | 743 | struct GNUNET_MESSENGER_Room *room, |
689 | const struct GNUNET_MESSENGER_Contact *contact) | 744 | const struct GNUNET_MESSENGER_Contact *contact) |
690 | { | 745 | { |
@@ -692,7 +747,7 @@ iterate_send_key_to_room (void* cls, | |||
692 | 747 | ||
693 | struct GNUNET_MESSENGER_Message *message = create_message_key (key); | 748 | struct GNUNET_MESSENGER_Message *message = create_message_key (key); |
694 | 749 | ||
695 | if (!message) | 750 | if (! message) |
696 | return GNUNET_NO; | 751 | return GNUNET_NO; |
697 | 752 | ||
698 | enqueue_message_to_room (room, message); | 753 | enqueue_message_to_room (room, message); |
@@ -700,14 +755,15 @@ iterate_send_key_to_room (void* cls, | |||
700 | return GNUNET_YES; | 755 | return GNUNET_YES; |
701 | } | 756 | } |
702 | 757 | ||
758 | |||
703 | int | 759 | int |
704 | GNUNET_MESSENGER_set_key (struct GNUNET_MESSENGER_Handle *handle, | 760 | GNUNET_MESSENGER_set_key (struct GNUNET_MESSENGER_Handle *handle, |
705 | const struct GNUNET_IDENTITY_PrivateKey *key) | 761 | const struct GNUNET_IDENTITY_PrivateKey *key) |
706 | { | 762 | { |
707 | if (!handle) | 763 | if (! handle) |
708 | return GNUNET_SYSERR; | 764 | return GNUNET_SYSERR; |
709 | 765 | ||
710 | if (!key) | 766 | if (! key) |
711 | { | 767 | { |
712 | GNUNET_MESSENGER_find_rooms (handle, NULL, iterate_send_key_to_room, NULL); | 768 | GNUNET_MESSENGER_find_rooms (handle, NULL, iterate_send_key_to_room, NULL); |
713 | set_handle_key (handle, NULL); | 769 | set_handle_key (handle, NULL); |
@@ -725,20 +781,23 @@ GNUNET_MESSENGER_set_key (struct GNUNET_MESSENGER_Handle *handle, | |||
725 | return GNUNET_YES; | 781 | return GNUNET_YES; |
726 | } | 782 | } |
727 | 783 | ||
784 | |||
728 | struct GNUNET_MESSENGER_Room* | 785 | struct GNUNET_MESSENGER_Room* |
729 | GNUNET_MESSENGER_open_room (struct GNUNET_MESSENGER_Handle *handle, | 786 | GNUNET_MESSENGER_open_room (struct GNUNET_MESSENGER_Handle *handle, |
730 | const struct GNUNET_HashCode *key) | 787 | const struct GNUNET_HashCode *key) |
731 | { | 788 | { |
732 | if ((!handle) || (!key)) | 789 | if ((! handle) || (! key)) |
733 | return NULL; | 790 | return NULL; |
734 | 791 | ||
735 | struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key); | 792 | struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get ( |
793 | handle->rooms, key); | ||
736 | 794 | ||
737 | if (!room) | 795 | if (! room) |
738 | { | 796 | { |
739 | room = create_room (handle, key); | 797 | room = create_room (handle, key); |
740 | 798 | ||
741 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (handle->rooms, key, room, | 799 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (handle->rooms, key, |
800 | room, | ||
742 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | 801 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) |
743 | { | 802 | { |
744 | destroy_room (room); | 803 | destroy_room (room); |
@@ -750,21 +809,24 @@ GNUNET_MESSENGER_open_room (struct GNUNET_MESSENGER_Handle *handle, | |||
750 | return room; | 809 | return room; |
751 | } | 810 | } |
752 | 811 | ||
812 | |||
753 | struct GNUNET_MESSENGER_Room* | 813 | struct GNUNET_MESSENGER_Room* |
754 | GNUNET_MESSENGER_enter_room (struct GNUNET_MESSENGER_Handle *handle, | 814 | GNUNET_MESSENGER_enter_room (struct GNUNET_MESSENGER_Handle *handle, |
755 | const struct GNUNET_PeerIdentity *door, | 815 | const struct GNUNET_PeerIdentity *door, |
756 | const struct GNUNET_HashCode *key) | 816 | const struct GNUNET_HashCode *key) |
757 | { | 817 | { |
758 | if ((!handle) || (!door) || (!key)) | 818 | if ((! handle) || (! door) || (! key)) |
759 | return NULL; | 819 | return NULL; |
760 | 820 | ||
761 | struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key); | 821 | struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get ( |
822 | handle->rooms, key); | ||
762 | 823 | ||
763 | if (!room) | 824 | if (! room) |
764 | { | 825 | { |
765 | room = create_room (handle, key); | 826 | room = create_room (handle, key); |
766 | 827 | ||
767 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (handle->rooms, key, room, | 828 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (handle->rooms, key, |
829 | room, | ||
768 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | 830 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) |
769 | { | 831 | { |
770 | destroy_room (room); | 832 | destroy_room (room); |
@@ -776,13 +838,14 @@ GNUNET_MESSENGER_enter_room (struct GNUNET_MESSENGER_Handle *handle, | |||
776 | return room; | 838 | return room; |
777 | } | 839 | } |
778 | 840 | ||
841 | |||
779 | void | 842 | void |
780 | GNUNET_MESSENGER_close_room (struct GNUNET_MESSENGER_Room *room) | 843 | GNUNET_MESSENGER_close_room (struct GNUNET_MESSENGER_Room *room) |
781 | { | 844 | { |
782 | if (!room) | 845 | if (! room) |
783 | return; | 846 | return; |
784 | 847 | ||
785 | struct GNUNET_MESSENGER_Message *message = create_message_leave(); | 848 | struct GNUNET_MESSENGER_Message *message = create_message_leave (); |
786 | 849 | ||
787 | if (message) | 850 | if (message) |
788 | { | 851 | { |
@@ -793,6 +856,7 @@ GNUNET_MESSENGER_close_room (struct GNUNET_MESSENGER_Room *room) | |||
793 | send_close_room (room->handle, room); | 856 | send_close_room (room->handle, room); |
794 | } | 857 | } |
795 | 858 | ||
859 | |||
796 | struct GNUNET_MESSENGER_RoomFind | 860 | struct GNUNET_MESSENGER_RoomFind |
797 | { | 861 | { |
798 | const struct GNUNET_MESSENGER_Contact *contact; | 862 | const struct GNUNET_MESSENGER_Contact *contact; |
@@ -802,33 +866,37 @@ struct GNUNET_MESSENGER_RoomFind | |||
802 | }; | 866 | }; |
803 | 867 | ||
804 | static int | 868 | static int |
805 | iterate_find_room (void* cls, | 869 | iterate_find_room (void *cls, |
806 | const struct GNUNET_HashCode *key, | 870 | const struct GNUNET_HashCode *key, |
807 | void *value) | 871 | void *value) |
808 | { | 872 | { |
809 | struct GNUNET_MESSENGER_RoomFind *find = cls; | 873 | struct GNUNET_MESSENGER_RoomFind *find = cls; |
810 | struct GNUNET_MESSENGER_Room *room = value; | 874 | struct GNUNET_MESSENGER_Room *room = value; |
811 | 875 | ||
812 | if ((find->counter > 0) && ((!find->contact) || (GNUNET_YES == find_room_member(room, find->contact)))) | 876 | if ((find->counter > 0) && ((! find->contact) || (GNUNET_YES == |
877 | find_room_member (room, | ||
878 | find-> | ||
879 | contact)))) | ||
813 | { | 880 | { |
814 | find->counter--; | 881 | find->counter--; |
815 | 882 | ||
816 | if (!find->callback) | 883 | if (! find->callback) |
817 | return GNUNET_YES; | 884 | return GNUNET_YES; |
818 | 885 | ||
819 | return find->callback(find->cls, room, find->contact); | 886 | return find->callback (find->cls, room, find->contact); |
820 | } | 887 | } |
821 | else | 888 | else |
822 | return GNUNET_NO; | 889 | return GNUNET_NO; |
823 | } | 890 | } |
824 | 891 | ||
892 | |||
825 | int | 893 | int |
826 | GNUNET_MESSENGER_find_rooms (const struct GNUNET_MESSENGER_Handle *handle, | 894 | GNUNET_MESSENGER_find_rooms (const struct GNUNET_MESSENGER_Handle *handle, |
827 | const struct GNUNET_MESSENGER_Contact *contact, | 895 | const struct GNUNET_MESSENGER_Contact *contact, |
828 | GNUNET_MESSENGER_MemberCallback callback, | 896 | GNUNET_MESSENGER_MemberCallback callback, |
829 | void *cls) | 897 | void *cls) |
830 | { | 898 | { |
831 | if (!handle) | 899 | if (! handle) |
832 | return GNUNET_SYSERR; | 900 | return GNUNET_SYSERR; |
833 | 901 | ||
834 | struct GNUNET_MESSENGER_RoomFind find; | 902 | struct GNUNET_MESSENGER_RoomFind find; |
@@ -838,79 +906,91 @@ GNUNET_MESSENGER_find_rooms (const struct GNUNET_MESSENGER_Handle *handle, | |||
838 | find.counter = (contact? contact->rc : SIZE_MAX); | 906 | find.counter = (contact? contact->rc : SIZE_MAX); |
839 | find.cls = cls; | 907 | find.cls = cls; |
840 | 908 | ||
841 | return GNUNET_CONTAINER_multihashmap_iterate(handle->rooms, iterate_find_room, &find); | 909 | return GNUNET_CONTAINER_multihashmap_iterate (handle->rooms, |
910 | iterate_find_room, &find); | ||
842 | } | 911 | } |
843 | 912 | ||
913 | |||
844 | const struct GNUNET_HashCode* | 914 | const struct GNUNET_HashCode* |
845 | GNUNET_MESSENGER_room_get_key (const struct GNUNET_MESSENGER_Room *room) | 915 | GNUNET_MESSENGER_room_get_key (const struct GNUNET_MESSENGER_Room *room) |
846 | { | 916 | { |
847 | if (!room) | 917 | if (! room) |
848 | return NULL; | 918 | return NULL; |
849 | 919 | ||
850 | return &(room->key); | 920 | return &(room->key); |
851 | } | 921 | } |
852 | 922 | ||
923 | |||
853 | const struct GNUNET_MESSENGER_Contact* | 924 | const struct GNUNET_MESSENGER_Contact* |
854 | GNUNET_MESSENGER_get_sender (const struct GNUNET_MESSENGER_Room *room, | 925 | GNUNET_MESSENGER_get_sender (const struct GNUNET_MESSENGER_Room *room, |
855 | const struct GNUNET_HashCode *hash) | 926 | const struct GNUNET_HashCode *hash) |
856 | { | 927 | { |
857 | if ((!room) || (!hash)) | 928 | if ((! room) || (! hash)) |
858 | return NULL; | 929 | return NULL; |
859 | 930 | ||
860 | return get_room_sender(room, hash); | 931 | return get_room_sender (room, hash); |
861 | } | 932 | } |
862 | 933 | ||
934 | |||
863 | const char* | 935 | const char* |
864 | GNUNET_MESSENGER_contact_get_name (const struct GNUNET_MESSENGER_Contact *contact) | 936 | GNUNET_MESSENGER_contact_get_name (const struct |
937 | GNUNET_MESSENGER_Contact *contact) | ||
865 | { | 938 | { |
866 | if (!contact) | 939 | if (! contact) |
867 | return NULL; | 940 | return NULL; |
868 | 941 | ||
869 | return get_contact_name (contact); | 942 | return get_contact_name (contact); |
870 | } | 943 | } |
871 | 944 | ||
945 | |||
872 | const struct GNUNET_IDENTITY_PublicKey* | 946 | const struct GNUNET_IDENTITY_PublicKey* |
873 | GNUNET_MESSENGER_contact_get_key (const struct GNUNET_MESSENGER_Contact *contact) | 947 | GNUNET_MESSENGER_contact_get_key (const struct |
948 | GNUNET_MESSENGER_Contact *contact) | ||
874 | { | 949 | { |
875 | if (!contact) | 950 | if (! contact) |
876 | return NULL; | 951 | return NULL; |
877 | 952 | ||
878 | return get_non_anonymous_key (get_contact_key (contact)); | 953 | return get_non_anonymous_key (get_contact_key (contact)); |
879 | } | 954 | } |
880 | 955 | ||
956 | |||
881 | void | 957 | void |
882 | GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room, | 958 | GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room, |
883 | struct GNUNET_MESSENGER_Message *message, | 959 | struct GNUNET_MESSENGER_Message *message, |
884 | const struct GNUNET_MESSENGER_Contact *contact) | 960 | const struct GNUNET_MESSENGER_Contact *contact) |
885 | { | 961 | { |
886 | if ((!room) || (!message)) | 962 | if ((! room) || (! message)) |
887 | return; | 963 | return; |
888 | 964 | ||
889 | switch (filter_message_sending (message)) | 965 | switch (filter_message_sending (message)) |
890 | { | 966 | { |
891 | case GNUNET_SYSERR: | 967 | case GNUNET_SYSERR: |
892 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Sending message aborted: This kind of message is reserved for the service!\n"); | 968 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
969 | "Sending message aborted: This kind of message is reserved for the service!\n"); | ||
893 | return; | 970 | return; |
894 | case GNUNET_NO: | 971 | case GNUNET_NO: |
895 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Sending message aborted: This kind of message could cause issues!\n"); | 972 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
973 | "Sending message aborted: This kind of message could cause issues!\n"); | ||
896 | return; | 974 | return; |
897 | default: | 975 | default: |
898 | break; | 976 | break; |
899 | } | 977 | } |
900 | 978 | ||
901 | char* original_name; | 979 | char *original_name; |
902 | char* changed_name = NULL; | 980 | char *changed_name = NULL; |
903 | 981 | ||
904 | if (GNUNET_MESSENGER_KIND_NAME != message->header.kind) | 982 | if (GNUNET_MESSENGER_KIND_NAME != message->header.kind) |
905 | goto skip_naming; | 983 | goto skip_naming; |
906 | 984 | ||
907 | original_name = message->body.name.name; | 985 | original_name = message->body.name.name; |
908 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Apply rule for using handle name in room: %s\n", GNUNET_h2s (&(room->key))); | 986 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
987 | "Apply rule for using handle name in room: %s\n", GNUNET_h2s ( | ||
988 | &(room->key))); | ||
909 | 989 | ||
910 | const char* handle_name = get_handle_name (room->handle); | 990 | const char *handle_name = get_handle_name (room->handle); |
911 | 991 | ||
912 | if ((handle_name) && (GNUNET_YES == room->use_handle_name) && | 992 | if ((handle_name) && (GNUNET_YES == room->use_handle_name) && |
913 | ((!original_name) || (0 == strlen (original_name)))) | 993 | ((! original_name) || (0 == strlen (original_name)))) |
914 | { | 994 | { |
915 | changed_name = GNUNET_strdup (handle_name); | 995 | changed_name = GNUNET_strdup (handle_name); |
916 | message->body.name.name = changed_name; | 996 | message->body.name.name = changed_name; |
@@ -920,23 +1000,25 @@ skip_naming: | |||
920 | if (contact) | 1000 | if (contact) |
921 | { | 1001 | { |
922 | const struct GNUNET_IDENTITY_PublicKey *public_key = get_non_anonymous_key ( | 1002 | const struct GNUNET_IDENTITY_PublicKey *public_key = get_non_anonymous_key ( |
923 | get_contact_key (contact) | 1003 | get_contact_key (contact) |
924 | ); | 1004 | ); |
925 | 1005 | ||
926 | if (!public_key) | 1006 | if (! public_key) |
927 | { | 1007 | { |
928 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Sending message aborted: Invalid key!\n"); | 1008 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1009 | "Sending message aborted: Invalid key!\n"); | ||
929 | goto reset_naming; | 1010 | goto reset_naming; |
930 | } | 1011 | } |
931 | 1012 | ||
932 | struct GNUNET_MESSENGER_Message *original = message; | 1013 | struct GNUNET_MESSENGER_Message *original = message; |
933 | message = copy_message(original); | 1014 | message = copy_message (original); |
934 | 1015 | ||
935 | if (GNUNET_YES != encrypt_message (message, public_key)) | 1016 | if (GNUNET_YES != encrypt_message (message, public_key)) |
936 | { | 1017 | { |
937 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Sending message aborted: Encryption failed!\n"); | 1018 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1019 | "Sending message aborted: Encryption failed!\n"); | ||
938 | 1020 | ||
939 | destroy_message(message); | 1021 | destroy_message (message); |
940 | message = original; | 1022 | message = original; |
941 | 1023 | ||
942 | goto reset_naming; | 1024 | goto reset_naming; |
@@ -955,36 +1037,39 @@ reset_naming: | |||
955 | message->body.name.name = original_name; | 1037 | message->body.name.name = original_name; |
956 | } | 1038 | } |
957 | 1039 | ||
1040 | |||
958 | const struct GNUNET_MESSENGER_Message* | 1041 | const struct GNUNET_MESSENGER_Message* |
959 | GNUNET_MESSENGER_get_message (const struct GNUNET_MESSENGER_Room *room, | 1042 | GNUNET_MESSENGER_get_message (const struct GNUNET_MESSENGER_Room *room, |
960 | const struct GNUNET_HashCode *hash) | 1043 | const struct GNUNET_HashCode *hash) |
961 | { | 1044 | { |
962 | if ((!room) || (!hash)) | 1045 | if ((! room) || (! hash)) |
963 | return NULL; | 1046 | return NULL; |
964 | 1047 | ||
965 | const struct GNUNET_MESSENGER_Message *message = get_room_message (room, hash); | 1048 | const struct GNUNET_MESSENGER_Message *message = get_room_message (room, |
1049 | hash); | ||
966 | 1050 | ||
967 | if (!message) | 1051 | if (! message) |
968 | { | 1052 | { |
969 | struct GNUNET_MESSENGER_GetMessage *msg; | 1053 | struct GNUNET_MESSENGER_GetMessage *msg; |
970 | struct GNUNET_MQ_Envelope *env; | 1054 | struct GNUNET_MQ_Envelope *env; |
971 | 1055 | ||
972 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE); | 1056 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE); |
973 | GNUNET_memcpy(&(msg->key), &(room->key), sizeof(msg->key)); | 1057 | GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key)); |
974 | GNUNET_memcpy(&(msg->hash), hash, sizeof(*hash)); | 1058 | GNUNET_memcpy (&(msg->hash), hash, sizeof(*hash)); |
975 | GNUNET_MQ_send (room->handle->mq, env); | 1059 | GNUNET_MQ_send (room->handle->mq, env); |
976 | } | 1060 | } |
977 | 1061 | ||
978 | return message; | 1062 | return message; |
979 | } | 1063 | } |
980 | 1064 | ||
1065 | |||
981 | int | 1066 | int |
982 | GNUNET_MESSENGER_iterate_members (struct GNUNET_MESSENGER_Room *room, | 1067 | GNUNET_MESSENGER_iterate_members (struct GNUNET_MESSENGER_Room *room, |
983 | GNUNET_MESSENGER_MemberCallback callback, | 1068 | GNUNET_MESSENGER_MemberCallback callback, |
984 | void *cls) | 1069 | void *cls) |
985 | { | 1070 | { |
986 | if (!room) | 1071 | if (! room) |
987 | return GNUNET_SYSERR; | 1072 | return GNUNET_SYSERR; |
988 | 1073 | ||
989 | return iterate_room_members(room, callback, cls); | 1074 | return iterate_room_members (room, callback, cls); |
990 | } | 1075 | } |
diff --git a/src/messenger/messenger_api_contact.c b/src/messenger/messenger_api_contact.c index a284c3b08..6f5dc7ead 100644 --- a/src/messenger/messenger_api_contact.c +++ b/src/messenger/messenger_api_contact.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--2021 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 |
@@ -29,69 +29,76 @@ | |||
29 | struct GNUNET_MESSENGER_Contact* | 29 | struct GNUNET_MESSENGER_Contact* |
30 | create_contact (const struct GNUNET_IDENTITY_PublicKey *key) | 30 | create_contact (const struct GNUNET_IDENTITY_PublicKey *key) |
31 | { | 31 | { |
32 | GNUNET_assert(key); | 32 | GNUNET_assert (key); |
33 | 33 | ||
34 | struct GNUNET_MESSENGER_Contact *contact = GNUNET_new(struct GNUNET_MESSENGER_Contact); | 34 | struct GNUNET_MESSENGER_Contact *contact = GNUNET_new (struct |
35 | GNUNET_MESSENGER_Contact); | ||
35 | 36 | ||
36 | contact->name = NULL; | 37 | contact->name = NULL; |
37 | contact->rc = 0; | 38 | contact->rc = 0; |
38 | 39 | ||
39 | GNUNET_memcpy(&(contact->public_key), key, sizeof(contact->public_key)); | 40 | GNUNET_memcpy (&(contact->public_key), key, sizeof(contact->public_key)); |
40 | 41 | ||
41 | return contact; | 42 | return contact; |
42 | } | 43 | } |
43 | 44 | ||
45 | |||
44 | void | 46 | void |
45 | destroy_contact (struct GNUNET_MESSENGER_Contact *contact) | 47 | destroy_contact (struct GNUNET_MESSENGER_Contact *contact) |
46 | { | 48 | { |
47 | GNUNET_assert(contact); | 49 | GNUNET_assert (contact); |
48 | 50 | ||
49 | if (contact->name) | 51 | if (contact->name) |
50 | GNUNET_free(contact->name); | 52 | GNUNET_free (contact->name); |
51 | 53 | ||
52 | GNUNET_free(contact); | 54 | GNUNET_free (contact); |
53 | } | 55 | } |
54 | 56 | ||
57 | |||
55 | const char* | 58 | const char* |
56 | get_contact_name (const struct GNUNET_MESSENGER_Contact *contact) | 59 | get_contact_name (const struct GNUNET_MESSENGER_Contact *contact) |
57 | { | 60 | { |
58 | GNUNET_assert(contact); | 61 | GNUNET_assert (contact); |
59 | 62 | ||
60 | return contact->name; | 63 | return contact->name; |
61 | } | 64 | } |
62 | 65 | ||
66 | |||
63 | void | 67 | void |
64 | set_contact_name (struct GNUNET_MESSENGER_Contact *contact, | 68 | set_contact_name (struct GNUNET_MESSENGER_Contact *contact, |
65 | const char *name) | 69 | const char *name) |
66 | { | 70 | { |
67 | GNUNET_assert(contact); | 71 | GNUNET_assert (contact); |
68 | 72 | ||
69 | if (contact->name) | 73 | if (contact->name) |
70 | GNUNET_free(contact->name); | 74 | GNUNET_free (contact->name); |
71 | 75 | ||
72 | contact->name = name ? GNUNET_strdup(name) : NULL; | 76 | contact->name = name ? GNUNET_strdup (name) : NULL; |
73 | } | 77 | } |
74 | 78 | ||
79 | |||
75 | const struct GNUNET_IDENTITY_PublicKey* | 80 | const struct GNUNET_IDENTITY_PublicKey* |
76 | get_contact_key (const struct GNUNET_MESSENGER_Contact *contact) | 81 | get_contact_key (const struct GNUNET_MESSENGER_Contact *contact) |
77 | { | 82 | { |
78 | GNUNET_assert(contact); | 83 | GNUNET_assert (contact); |
79 | 84 | ||
80 | return &(contact->public_key); | 85 | return &(contact->public_key); |
81 | } | 86 | } |
82 | 87 | ||
88 | |||
83 | void | 89 | void |
84 | increase_contact_rc (struct GNUNET_MESSENGER_Contact *contact) | 90 | increase_contact_rc (struct GNUNET_MESSENGER_Contact *contact) |
85 | { | 91 | { |
86 | GNUNET_assert(contact); | 92 | GNUNET_assert (contact); |
87 | 93 | ||
88 | contact->rc++; | 94 | contact->rc++; |
89 | } | 95 | } |
90 | 96 | ||
97 | |||
91 | int | 98 | int |
92 | decrease_contact_rc (struct GNUNET_MESSENGER_Contact *contact) | 99 | decrease_contact_rc (struct GNUNET_MESSENGER_Contact *contact) |
93 | { | 100 | { |
94 | GNUNET_assert(contact); | 101 | GNUNET_assert (contact); |
95 | 102 | ||
96 | if (contact->rc > 0) | 103 | if (contact->rc > 0) |
97 | contact->rc--; | 104 | contact->rc--; |
@@ -99,12 +106,13 @@ decrease_contact_rc (struct GNUNET_MESSENGER_Contact *contact) | |||
99 | return contact->rc ? GNUNET_NO : GNUNET_YES; | 106 | return contact->rc ? GNUNET_NO : GNUNET_YES; |
100 | } | 107 | } |
101 | 108 | ||
109 | |||
102 | void | 110 | void |
103 | get_context_from_member (const struct GNUNET_HashCode *key, | 111 | get_context_from_member (const struct GNUNET_HashCode *key, |
104 | const struct GNUNET_ShortHashCode *id, | 112 | const struct GNUNET_ShortHashCode *id, |
105 | struct GNUNET_HashCode *context) | 113 | struct GNUNET_HashCode *context) |
106 | { | 114 | { |
107 | GNUNET_assert((key) && (id) && (context)); | 115 | GNUNET_assert ((key) && (id) && (context)); |
108 | 116 | ||
109 | GNUNET_CRYPTO_hash (id, sizeof(*id), context); | 117 | GNUNET_CRYPTO_hash (id, sizeof(*id), context); |
110 | GNUNET_CRYPTO_hash_xor (key, context, context); | 118 | GNUNET_CRYPTO_hash_xor (key, context, context); |
diff --git a/src/messenger/messenger_api_contact_store.c b/src/messenger/messenger_api_contact_store.c index d42155e20..520e6cdd1 100644 --- a/src/messenger/messenger_api_contact_store.c +++ b/src/messenger/messenger_api_contact_store.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--2021 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 |
@@ -38,6 +38,7 @@ init_contact_store (struct GNUNET_MESSENGER_ContactStore *store) | |||
38 | store->contacts = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); | 38 | store->contacts = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); |
39 | } | 39 | } |
40 | 40 | ||
41 | |||
41 | static int | 42 | static int |
42 | iterate_destroy_contacts (void *cls, | 43 | iterate_destroy_contacts (void *cls, |
43 | const struct GNUNET_HashCode *key, | 44 | const struct GNUNET_HashCode *key, |
@@ -48,37 +49,43 @@ iterate_destroy_contacts (void *cls, | |||
48 | return GNUNET_YES; | 49 | return GNUNET_YES; |
49 | } | 50 | } |
50 | 51 | ||
52 | |||
51 | void | 53 | void |
52 | clear_contact_store (struct GNUNET_MESSENGER_ContactStore *store) | 54 | clear_contact_store (struct GNUNET_MESSENGER_ContactStore *store) |
53 | { | 55 | { |
54 | GNUNET_assert ((store) && (store->contacts)); | 56 | GNUNET_assert ((store) && (store->contacts)); |
55 | 57 | ||
56 | GNUNET_CONTAINER_multihashmap_iterate (store->anonymous, iterate_destroy_contacts, NULL); | 58 | GNUNET_CONTAINER_multihashmap_iterate (store->anonymous, |
57 | GNUNET_CONTAINER_multihashmap_iterate (store->contacts, iterate_destroy_contacts, NULL); | 59 | iterate_destroy_contacts, NULL); |
60 | GNUNET_CONTAINER_multihashmap_iterate (store->contacts, | ||
61 | iterate_destroy_contacts, NULL); | ||
58 | 62 | ||
59 | GNUNET_CONTAINER_multihashmap_destroy (store->anonymous); | 63 | GNUNET_CONTAINER_multihashmap_destroy (store->anonymous); |
60 | GNUNET_CONTAINER_multihashmap_destroy (store->contacts); | 64 | GNUNET_CONTAINER_multihashmap_destroy (store->contacts); |
61 | } | 65 | } |
62 | 66 | ||
67 | |||
63 | static struct GNUNET_CONTAINER_MultiHashMap* | 68 | static struct GNUNET_CONTAINER_MultiHashMap* |
64 | select_store_contact_map (struct GNUNET_MESSENGER_ContactStore *store, | 69 | select_store_contact_map (struct GNUNET_MESSENGER_ContactStore *store, |
65 | const struct GNUNET_HashCode *context, | 70 | const struct GNUNET_HashCode *context, |
66 | struct GNUNET_HashCode *hash) | 71 | struct GNUNET_HashCode *hash) |
67 | { | 72 | { |
68 | const struct GNUNET_IDENTITY_PublicKey *anonymous = get_anonymous_public_key (); | 73 | const struct GNUNET_IDENTITY_PublicKey *anonymous = |
74 | get_anonymous_public_key (); | ||
69 | 75 | ||
70 | struct GNUNET_HashCode anonHash; | 76 | struct GNUNET_HashCode anonHash; |
71 | GNUNET_CRYPTO_hash (anonymous, sizeof(*anonymous), &anonHash); | 77 | GNUNET_CRYPTO_hash (anonymous, sizeof(*anonymous), &anonHash); |
72 | 78 | ||
73 | if ((context) && (0 == GNUNET_CRYPTO_hash_cmp(hash, &anonHash))) | 79 | if ((context) && (0 == GNUNET_CRYPTO_hash_cmp (hash, &anonHash))) |
74 | { | 80 | { |
75 | GNUNET_memcpy(hash, context, sizeof(*context)); | 81 | GNUNET_memcpy (hash, context, sizeof(*context)); |
76 | return store->anonymous; | 82 | return store->anonymous; |
77 | } | 83 | } |
78 | else | 84 | else |
79 | return store->contacts; | 85 | return store->contacts; |
80 | } | 86 | } |
81 | 87 | ||
88 | |||
82 | struct GNUNET_MESSENGER_Contact* | 89 | struct GNUNET_MESSENGER_Contact* |
83 | get_store_contact_raw (struct GNUNET_MESSENGER_ContactStore *store, | 90 | get_store_contact_raw (struct GNUNET_MESSENGER_ContactStore *store, |
84 | const struct GNUNET_HashCode *context, | 91 | const struct GNUNET_HashCode *context, |
@@ -87,15 +94,16 @@ get_store_contact_raw (struct GNUNET_MESSENGER_ContactStore *store, | |||
87 | GNUNET_assert ((store) && (store->contacts) && (context) && (key_hash)); | 94 | GNUNET_assert ((store) && (store->contacts) && (context) && (key_hash)); |
88 | 95 | ||
89 | struct GNUNET_HashCode hash; | 96 | struct GNUNET_HashCode hash; |
90 | GNUNET_memcpy(&hash, key_hash, sizeof(*key_hash)); | 97 | GNUNET_memcpy (&hash, key_hash, sizeof(*key_hash)); |
91 | 98 | ||
92 | struct GNUNET_CONTAINER_MultiHashMap *map = select_store_contact_map ( | 99 | struct GNUNET_CONTAINER_MultiHashMap *map = select_store_contact_map ( |
93 | store, context, &hash | 100 | store, context, &hash |
94 | ); | 101 | ); |
95 | 102 | ||
96 | return GNUNET_CONTAINER_multihashmap_get (map, &hash); | 103 | return GNUNET_CONTAINER_multihashmap_get (map, &hash); |
97 | } | 104 | } |
98 | 105 | ||
106 | |||
99 | struct GNUNET_MESSENGER_Contact* | 107 | struct GNUNET_MESSENGER_Contact* |
100 | get_store_contact (struct GNUNET_MESSENGER_ContactStore *store, | 108 | get_store_contact (struct GNUNET_MESSENGER_ContactStore *store, |
101 | const struct GNUNET_HashCode *context, | 109 | const struct GNUNET_HashCode *context, |
@@ -107,17 +115,20 @@ get_store_contact (struct GNUNET_MESSENGER_ContactStore *store, | |||
107 | GNUNET_CRYPTO_hash (pubkey, sizeof(*pubkey), &hash); | 115 | GNUNET_CRYPTO_hash (pubkey, sizeof(*pubkey), &hash); |
108 | 116 | ||
109 | struct GNUNET_CONTAINER_MultiHashMap *map = select_store_contact_map ( | 117 | struct GNUNET_CONTAINER_MultiHashMap *map = select_store_contact_map ( |
110 | store, context, &hash | 118 | store, context, &hash |
111 | ); | 119 | ); |
112 | 120 | ||
113 | struct GNUNET_MESSENGER_Contact *contact = GNUNET_CONTAINER_multihashmap_get (map, &hash); | 121 | struct GNUNET_MESSENGER_Contact *contact = GNUNET_CONTAINER_multihashmap_get ( |
122 | map, &hash); | ||
114 | 123 | ||
115 | if (contact) | 124 | if (contact) |
116 | { | 125 | { |
117 | if (0 != GNUNET_memcmp(pubkey, get_contact_key(contact))) | 126 | if (0 != GNUNET_memcmp (pubkey, get_contact_key (contact))) |
118 | { | 127 | { |
119 | char* str = GNUNET_IDENTITY_public_key_to_string (get_contact_key(contact)); | 128 | char *str = GNUNET_IDENTITY_public_key_to_string (get_contact_key ( |
120 | GNUNET_log (GNUNET_ERROR_TYPE_INVALID, "Contact in store uses wrong key: %s\n", str); | 129 | contact)); |
130 | GNUNET_log (GNUNET_ERROR_TYPE_INVALID, | ||
131 | "Contact in store uses wrong key: %s\n", str); | ||
121 | GNUNET_free (str); | 132 | GNUNET_free (str); |
122 | return NULL; | 133 | return NULL; |
123 | } | 134 | } |
@@ -135,60 +146,62 @@ get_store_contact (struct GNUNET_MESSENGER_ContactStore *store, | |||
135 | return NULL; | 146 | return NULL; |
136 | } | 147 | } |
137 | 148 | ||
149 | |||
138 | void | 150 | void |
139 | update_store_contact (struct GNUNET_MESSENGER_ContactStore *store, | 151 | update_store_contact (struct GNUNET_MESSENGER_ContactStore *store, |
140 | struct GNUNET_MESSENGER_Contact* contact, | 152 | struct GNUNET_MESSENGER_Contact *contact, |
141 | const struct GNUNET_HashCode *context, | 153 | const struct GNUNET_HashCode *context, |
142 | const struct GNUNET_HashCode *next_context, | 154 | const struct GNUNET_HashCode *next_context, |
143 | const struct GNUNET_IDENTITY_PublicKey *pubkey) | 155 | const struct GNUNET_IDENTITY_PublicKey *pubkey) |
144 | { | 156 | { |
145 | GNUNET_assert ((store) && (store->contacts) && (contact) && (pubkey)); | 157 | GNUNET_assert ((store) && (store->contacts) && (contact) && (pubkey)); |
146 | 158 | ||
147 | const struct GNUNET_IDENTITY_PublicKey* oldkey = get_contact_key (contact); | 159 | const struct GNUNET_IDENTITY_PublicKey *oldkey = get_contact_key (contact); |
148 | 160 | ||
149 | struct GNUNET_HashCode hash; | 161 | struct GNUNET_HashCode hash; |
150 | GNUNET_CRYPTO_hash (oldkey, sizeof(*oldkey), &hash); | 162 | GNUNET_CRYPTO_hash (oldkey, sizeof(*oldkey), &hash); |
151 | 163 | ||
152 | struct GNUNET_CONTAINER_MultiHashMap *map = select_store_contact_map ( | 164 | struct GNUNET_CONTAINER_MultiHashMap *map = select_store_contact_map ( |
153 | store, context, &hash | 165 | store, context, &hash |
154 | ); | 166 | ); |
155 | 167 | ||
156 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (map, &hash, contact)) | 168 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (map, &hash, contact)) |
157 | { | 169 | { |
158 | GNUNET_memcpy(&(contact->public_key), pubkey, sizeof(*pubkey)); | 170 | GNUNET_memcpy (&(contact->public_key), pubkey, sizeof(*pubkey)); |
159 | 171 | ||
160 | GNUNET_CRYPTO_hash (pubkey, sizeof(*pubkey), &hash); | 172 | GNUNET_CRYPTO_hash (pubkey, sizeof(*pubkey), &hash); |
161 | 173 | ||
162 | map = select_store_contact_map ( | 174 | map = select_store_contact_map ( |
163 | store, next_context, &hash | 175 | store, next_context, &hash |
164 | ); | 176 | ); |
165 | 177 | ||
166 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (map, &hash, contact, | 178 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (map, &hash, contact, |
167 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | 179 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) |
168 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Updating a contact failed: %s\n", | 180 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Updating a contact failed: %s\n", |
169 | GNUNET_h2s(&hash)); | 181 | GNUNET_h2s (&hash)); |
170 | } | 182 | } |
171 | } | 183 | } |
172 | 184 | ||
185 | |||
173 | void | 186 | void |
174 | remove_store_contact (struct GNUNET_MESSENGER_ContactStore *store, | 187 | remove_store_contact (struct GNUNET_MESSENGER_ContactStore *store, |
175 | struct GNUNET_MESSENGER_Contact* contact, | 188 | struct GNUNET_MESSENGER_Contact *contact, |
176 | const struct GNUNET_HashCode *context) | 189 | const struct GNUNET_HashCode *context) |
177 | { | 190 | { |
178 | GNUNET_assert ((store) && (store->contacts) && (contact)); | 191 | GNUNET_assert ((store) && (store->contacts) && (contact)); |
179 | 192 | ||
180 | const struct GNUNET_IDENTITY_PublicKey* pubkey = get_contact_key(contact); | 193 | const struct GNUNET_IDENTITY_PublicKey *pubkey = get_contact_key (contact); |
181 | 194 | ||
182 | struct GNUNET_HashCode hash; | 195 | struct GNUNET_HashCode hash; |
183 | GNUNET_CRYPTO_hash (pubkey, sizeof(*pubkey), &hash); | 196 | GNUNET_CRYPTO_hash (pubkey, sizeof(*pubkey), &hash); |
184 | 197 | ||
185 | struct GNUNET_CONTAINER_MultiHashMap *map = select_store_contact_map ( | 198 | struct GNUNET_CONTAINER_MultiHashMap *map = select_store_contact_map ( |
186 | store, context, &hash | 199 | store, context, &hash |
187 | ); | 200 | ); |
188 | 201 | ||
189 | if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (map, &hash, contact)) | 202 | if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (map, &hash, contact)) |
190 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Removing a contact failed: %s\n", | 203 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Removing a contact failed: %s\n", |
191 | GNUNET_h2s(&hash)); | 204 | GNUNET_h2s (&hash)); |
192 | 205 | ||
193 | destroy_contact (contact); | 206 | destroy_contact (contact); |
194 | } | 207 | } |
diff --git a/src/messenger/messenger_api_contact_store.h b/src/messenger/messenger_api_contact_store.h index c74a67740..b61ef7f12 100644 --- a/src/messenger/messenger_api_contact_store.h +++ b/src/messenger/messenger_api_contact_store.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2020--2021 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 |
@@ -105,7 +105,7 @@ get_store_contact (struct GNUNET_MESSENGER_ContactStore *store, | |||
105 | */ | 105 | */ |
106 | void | 106 | void |
107 | update_store_contact (struct GNUNET_MESSENGER_ContactStore *store, | 107 | update_store_contact (struct GNUNET_MESSENGER_ContactStore *store, |
108 | struct GNUNET_MESSENGER_Contact* contact, | 108 | struct GNUNET_MESSENGER_Contact *contact, |
109 | const struct GNUNET_HashCode *context, | 109 | const struct GNUNET_HashCode *context, |
110 | const struct GNUNET_HashCode *next_context, | 110 | const struct GNUNET_HashCode *next_context, |
111 | const struct GNUNET_IDENTITY_PublicKey *pubkey); | 111 | const struct GNUNET_IDENTITY_PublicKey *pubkey); |
@@ -120,7 +120,7 @@ update_store_contact (struct GNUNET_MESSENGER_ContactStore *store, | |||
120 | */ | 120 | */ |
121 | void | 121 | void |
122 | remove_store_contact (struct GNUNET_MESSENGER_ContactStore *store, | 122 | remove_store_contact (struct GNUNET_MESSENGER_ContactStore *store, |
123 | struct GNUNET_MESSENGER_Contact* contact, | 123 | struct GNUNET_MESSENGER_Contact *contact, |
124 | const struct GNUNET_HashCode *context); | 124 | const struct GNUNET_HashCode *context); |
125 | 125 | ||
126 | #endif //GNUNET_MESSENGER_API_CONTACT_STORE_H | 126 | #endif //GNUNET_MESSENGER_API_CONTACT_STORE_H |
diff --git a/src/messenger/messenger_api_handle.c b/src/messenger/messenger_api_handle.c index abede8e21..7d5b55a06 100644 --- a/src/messenger/messenger_api_handle.c +++ b/src/messenger/messenger_api_handle.c | |||
@@ -34,9 +34,10 @@ create_handle (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
34 | GNUNET_MESSENGER_MessageCallback msg_callback, | 34 | GNUNET_MESSENGER_MessageCallback msg_callback, |
35 | void *msg_cls) | 35 | void *msg_cls) |
36 | { | 36 | { |
37 | GNUNET_assert(cfg); | 37 | GNUNET_assert (cfg); |
38 | 38 | ||
39 | struct GNUNET_MESSENGER_Handle *handle = GNUNET_new(struct GNUNET_MESSENGER_Handle); | 39 | struct GNUNET_MESSENGER_Handle *handle = GNUNET_new (struct |
40 | GNUNET_MESSENGER_Handle); | ||
40 | 41 | ||
41 | handle->cfg = cfg; | 42 | handle->cfg = cfg; |
42 | handle->mq = NULL; | 43 | handle->mq = NULL; |
@@ -53,11 +54,12 @@ create_handle (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
53 | 54 | ||
54 | handle->rooms = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); | 55 | handle->rooms = GNUNET_CONTAINER_multihashmap_create (8, GNUNET_NO); |
55 | 56 | ||
56 | init_contact_store(get_handle_contact_store(handle)); | 57 | init_contact_store (get_handle_contact_store (handle)); |
57 | 58 | ||
58 | return handle; | 59 | return handle; |
59 | } | 60 | } |
60 | 61 | ||
62 | |||
61 | static int | 63 | static int |
62 | iterate_destroy_room (void *cls, | 64 | iterate_destroy_room (void *cls, |
63 | const struct GNUNET_HashCode *key, | 65 | const struct GNUNET_HashCode *key, |
@@ -70,10 +72,11 @@ iterate_destroy_room (void *cls, | |||
70 | return GNUNET_YES; | 72 | return GNUNET_YES; |
71 | } | 73 | } |
72 | 74 | ||
75 | |||
73 | void | 76 | void |
74 | destroy_handle (struct GNUNET_MESSENGER_Handle *handle) | 77 | destroy_handle (struct GNUNET_MESSENGER_Handle *handle) |
75 | { | 78 | { |
76 | GNUNET_assert(handle); | 79 | GNUNET_assert (handle); |
77 | 80 | ||
78 | if (handle->reconnect_task) | 81 | if (handle->reconnect_task) |
79 | GNUNET_SCHEDULER_cancel (handle->reconnect_task); | 82 | GNUNET_SCHEDULER_cancel (handle->reconnect_task); |
@@ -82,26 +85,28 @@ destroy_handle (struct GNUNET_MESSENGER_Handle *handle) | |||
82 | GNUNET_MQ_destroy (handle->mq); | 85 | GNUNET_MQ_destroy (handle->mq); |
83 | 86 | ||
84 | if (handle->name) | 87 | if (handle->name) |
85 | GNUNET_free(handle->name); | 88 | GNUNET_free (handle->name); |
86 | 89 | ||
87 | if (handle->key) | 90 | if (handle->key) |
88 | GNUNET_free(handle->key); | 91 | GNUNET_free (handle->key); |
89 | 92 | ||
90 | if (handle->pubkey) | 93 | if (handle->pubkey) |
91 | GNUNET_free(handle->pubkey); | 94 | GNUNET_free (handle->pubkey); |
92 | 95 | ||
93 | if (handle->rooms) | 96 | if (handle->rooms) |
94 | { | 97 | { |
95 | GNUNET_CONTAINER_multihashmap_iterate (handle->rooms, iterate_destroy_room, NULL); | 98 | GNUNET_CONTAINER_multihashmap_iterate (handle->rooms, iterate_destroy_room, |
99 | NULL); | ||
96 | 100 | ||
97 | GNUNET_CONTAINER_multihashmap_destroy (handle->rooms); | 101 | GNUNET_CONTAINER_multihashmap_destroy (handle->rooms); |
98 | } | 102 | } |
99 | 103 | ||
100 | clear_contact_store(get_handle_contact_store(handle)); | 104 | clear_contact_store (get_handle_contact_store (handle)); |
101 | 105 | ||
102 | GNUNET_free(handle); | 106 | GNUNET_free (handle); |
103 | } | 107 | } |
104 | 108 | ||
109 | |||
105 | void | 110 | void |
106 | set_handle_name (struct GNUNET_MESSENGER_Handle *handle, | 111 | set_handle_name (struct GNUNET_MESSENGER_Handle *handle, |
107 | const char *name) | 112 | const char *name) |
@@ -114,21 +119,23 @@ set_handle_name (struct GNUNET_MESSENGER_Handle *handle, | |||
114 | handle->name = name ? GNUNET_strdup (name) : NULL; | 119 | handle->name = name ? GNUNET_strdup (name) : NULL; |
115 | } | 120 | } |
116 | 121 | ||
122 | |||
117 | const char* | 123 | const char* |
118 | get_handle_name (const struct GNUNET_MESSENGER_Handle *handle) | 124 | get_handle_name (const struct GNUNET_MESSENGER_Handle *handle) |
119 | { | 125 | { |
120 | GNUNET_assert(handle); | 126 | GNUNET_assert (handle); |
121 | 127 | ||
122 | return handle->name; | 128 | return handle->name; |
123 | } | 129 | } |
124 | 130 | ||
131 | |||
125 | void | 132 | void |
126 | set_handle_key (struct GNUNET_MESSENGER_Handle *handle, | 133 | set_handle_key (struct GNUNET_MESSENGER_Handle *handle, |
127 | const struct GNUNET_IDENTITY_PrivateKey *key) | 134 | const struct GNUNET_IDENTITY_PrivateKey *key) |
128 | { | 135 | { |
129 | GNUNET_assert (handle); | 136 | GNUNET_assert (handle); |
130 | 137 | ||
131 | if (!key) | 138 | if (! key) |
132 | { | 139 | { |
133 | if (handle->key) | 140 | if (handle->key) |
134 | GNUNET_free (handle->key); | 141 | GNUNET_free (handle->key); |
@@ -141,31 +148,33 @@ set_handle_key (struct GNUNET_MESSENGER_Handle *handle, | |||
141 | return; | 148 | return; |
142 | } | 149 | } |
143 | 150 | ||
144 | if (!handle->key) | 151 | if (! handle->key) |
145 | handle->key = GNUNET_new (struct GNUNET_IDENTITY_PrivateKey); | 152 | handle->key = GNUNET_new (struct GNUNET_IDENTITY_PrivateKey); |
146 | 153 | ||
147 | if (!handle->pubkey) | 154 | if (! handle->pubkey) |
148 | handle->pubkey = GNUNET_new (struct GNUNET_IDENTITY_PublicKey); | 155 | handle->pubkey = GNUNET_new (struct GNUNET_IDENTITY_PublicKey); |
149 | 156 | ||
150 | GNUNET_memcpy (handle->key, key, sizeof(*key)); | 157 | GNUNET_memcpy (handle->key, key, sizeof(*key)); |
151 | GNUNET_IDENTITY_key_get_public (key, handle->pubkey); | 158 | GNUNET_IDENTITY_key_get_public (key, handle->pubkey); |
152 | } | 159 | } |
153 | 160 | ||
161 | |||
154 | const struct GNUNET_IDENTITY_PrivateKey* | 162 | const struct GNUNET_IDENTITY_PrivateKey* |
155 | get_handle_key (const struct GNUNET_MESSENGER_Handle *handle) | 163 | get_handle_key (const struct GNUNET_MESSENGER_Handle *handle) |
156 | { | 164 | { |
157 | GNUNET_assert(handle); | 165 | GNUNET_assert (handle); |
158 | 166 | ||
159 | if (handle->key) | 167 | if (handle->key) |
160 | return handle->key; | 168 | return handle->key; |
161 | 169 | ||
162 | return get_anonymous_private_key(); | 170 | return get_anonymous_private_key (); |
163 | } | 171 | } |
164 | 172 | ||
173 | |||
165 | const struct GNUNET_IDENTITY_PublicKey* | 174 | const struct GNUNET_IDENTITY_PublicKey* |
166 | get_handle_pubkey (const struct GNUNET_MESSENGER_Handle *handle) | 175 | get_handle_pubkey (const struct GNUNET_MESSENGER_Handle *handle) |
167 | { | 176 | { |
168 | GNUNET_assert(handle); | 177 | GNUNET_assert (handle); |
169 | 178 | ||
170 | if (handle->pubkey) | 179 | if (handle->pubkey) |
171 | return handle->pubkey; | 180 | return handle->pubkey; |
@@ -173,28 +182,31 @@ get_handle_pubkey (const struct GNUNET_MESSENGER_Handle *handle) | |||
173 | return get_anonymous_public_key (); | 182 | return get_anonymous_public_key (); |
174 | } | 183 | } |
175 | 184 | ||
185 | |||
176 | struct GNUNET_MESSENGER_ContactStore* | 186 | struct GNUNET_MESSENGER_ContactStore* |
177 | get_handle_contact_store (struct GNUNET_MESSENGER_Handle *handle) | 187 | get_handle_contact_store (struct GNUNET_MESSENGER_Handle *handle) |
178 | { | 188 | { |
179 | GNUNET_assert(handle); | 189 | GNUNET_assert (handle); |
180 | 190 | ||
181 | return &(handle->contact_store); | 191 | return &(handle->contact_store); |
182 | } | 192 | } |
183 | 193 | ||
194 | |||
184 | struct GNUNET_MESSENGER_Contact* | 195 | struct GNUNET_MESSENGER_Contact* |
185 | get_handle_contact (struct GNUNET_MESSENGER_Handle *handle, | 196 | get_handle_contact (struct GNUNET_MESSENGER_Handle *handle, |
186 | const struct GNUNET_HashCode *key) | 197 | const struct GNUNET_HashCode *key) |
187 | { | 198 | { |
188 | GNUNET_assert((handle) && (key)); | 199 | GNUNET_assert ((handle) && (key)); |
189 | 200 | ||
190 | struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key); | 201 | struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get ( |
202 | handle->rooms, key); | ||
191 | 203 | ||
192 | if (!room) | 204 | if (! room) |
193 | return NULL; | 205 | return NULL; |
194 | 206 | ||
195 | const struct GNUNET_ShortHashCode *contact_id = get_room_sender_id (room); | 207 | const struct GNUNET_ShortHashCode *contact_id = get_room_sender_id (room); |
196 | 208 | ||
197 | if (!contact_id) | 209 | if (! contact_id) |
198 | return NULL; | 210 | return NULL; |
199 | 211 | ||
200 | struct GNUNET_HashCode context; | 212 | struct GNUNET_HashCode context; |
@@ -204,48 +216,56 @@ get_handle_contact (struct GNUNET_MESSENGER_Handle *handle, | |||
204 | get_handle_pubkey (handle)); | 216 | get_handle_pubkey (handle)); |
205 | } | 217 | } |
206 | 218 | ||
219 | |||
207 | void | 220 | void |
208 | open_handle_room (struct GNUNET_MESSENGER_Handle *handle, | 221 | open_handle_room (struct GNUNET_MESSENGER_Handle *handle, |
209 | const struct GNUNET_HashCode *key) | 222 | const struct GNUNET_HashCode *key) |
210 | { | 223 | { |
211 | GNUNET_assert((handle) && (key)); | 224 | GNUNET_assert ((handle) && (key)); |
212 | 225 | ||
213 | struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key); | 226 | struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get ( |
227 | handle->rooms, key); | ||
214 | 228 | ||
215 | if (room) | 229 | if (room) |
216 | room->opened = GNUNET_YES; | 230 | room->opened = GNUNET_YES; |
217 | } | 231 | } |
218 | 232 | ||
233 | |||
219 | void | 234 | void |
220 | entry_handle_room_at (struct GNUNET_MESSENGER_Handle *handle, | 235 | entry_handle_room_at (struct GNUNET_MESSENGER_Handle *handle, |
221 | const struct GNUNET_PeerIdentity *door, | 236 | const struct GNUNET_PeerIdentity *door, |
222 | const struct GNUNET_HashCode *key) | 237 | const struct GNUNET_HashCode *key) |
223 | { | 238 | { |
224 | GNUNET_assert((handle) && (door) && (key)); | 239 | GNUNET_assert ((handle) && (door) && (key)); |
225 | 240 | ||
226 | struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key); | 241 | struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get ( |
242 | handle->rooms, key); | ||
227 | 243 | ||
228 | if (room) | 244 | if (room) |
229 | add_to_list_tunnels (&(room->entries), door, NULL); | 245 | add_to_list_tunnels (&(room->entries), door, NULL); |
230 | } | 246 | } |
231 | 247 | ||
248 | |||
232 | void | 249 | void |
233 | close_handle_room (struct GNUNET_MESSENGER_Handle *handle, | 250 | close_handle_room (struct GNUNET_MESSENGER_Handle *handle, |
234 | const struct GNUNET_HashCode *key) | 251 | const struct GNUNET_HashCode *key) |
235 | { | 252 | { |
236 | GNUNET_assert((handle) && (key)); | 253 | GNUNET_assert ((handle) && (key)); |
237 | 254 | ||
238 | struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key); | 255 | struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get ( |
256 | handle->rooms, key); | ||
239 | 257 | ||
240 | if ((room) && (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (handle->rooms, key, room))) | 258 | if ((room) && (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove ( |
259 | handle->rooms, key, room))) | ||
241 | destroy_room (room); | 260 | destroy_room (room); |
242 | } | 261 | } |
243 | 262 | ||
263 | |||
244 | struct GNUNET_MESSENGER_Room* | 264 | struct GNUNET_MESSENGER_Room* |
245 | get_handle_room (struct GNUNET_MESSENGER_Handle *handle, | 265 | get_handle_room (struct GNUNET_MESSENGER_Handle *handle, |
246 | const struct GNUNET_HashCode *key) | 266 | const struct GNUNET_HashCode *key) |
247 | { | 267 | { |
248 | GNUNET_assert((handle) && (key)); | 268 | GNUNET_assert ((handle) && (key)); |
249 | 269 | ||
250 | return GNUNET_CONTAINER_multihashmap_get (handle->rooms, key); | 270 | return GNUNET_CONTAINER_multihashmap_get (handle->rooms, key); |
251 | } | 271 | } |
diff --git a/src/messenger/messenger_api_list_tunnels.c b/src/messenger/messenger_api_list_tunnels.c index 4d0deb95d..b2513370c 100644 --- a/src/messenger/messenger_api_list_tunnels.c +++ b/src/messenger/messenger_api_list_tunnels.c | |||
@@ -29,24 +29,27 @@ | |||
29 | void | 29 | void |
30 | init_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels) | 30 | init_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels) |
31 | { | 31 | { |
32 | GNUNET_assert(tunnels); | 32 | GNUNET_assert (tunnels); |
33 | 33 | ||
34 | tunnels->head = NULL; | 34 | tunnels->head = NULL; |
35 | tunnels->tail = NULL; | 35 | tunnels->tail = NULL; |
36 | } | 36 | } |
37 | 37 | ||
38 | |||
38 | void | 39 | void |
39 | clear_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels) | 40 | clear_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels) |
40 | { | 41 | { |
41 | GNUNET_assert(tunnels); | 42 | GNUNET_assert (tunnels); |
42 | 43 | ||
43 | struct GNUNET_MESSENGER_ListTunnel *element; | 44 | struct GNUNET_MESSENGER_ListTunnel *element; |
44 | for (element = tunnels->head; element; element = remove_from_list_tunnels(tunnels, element)) | 45 | for (element = tunnels->head; element; element = remove_from_list_tunnels ( |
46 | tunnels, element)) | ||
45 | 47 | ||
46 | tunnels->head = NULL; | 48 | tunnels->head = NULL; |
47 | tunnels->tail = NULL; | 49 | tunnels->tail = NULL; |
48 | } | 50 | } |
49 | 51 | ||
52 | |||
50 | static int | 53 | static int |
51 | compare_list_tunnels (void *cls, | 54 | compare_list_tunnels (void *cls, |
52 | struct GNUNET_MESSENGER_ListTunnel *element0, | 55 | struct GNUNET_MESSENGER_ListTunnel *element0, |
@@ -55,28 +58,33 @@ compare_list_tunnels (void *cls, | |||
55 | return ((int) element0->peer) - ((int) element1->peer); | 58 | return ((int) element0->peer) - ((int) element1->peer); |
56 | } | 59 | } |
57 | 60 | ||
61 | |||
58 | void | 62 | void |
59 | add_to_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, | 63 | add_to_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, |
60 | const struct GNUNET_PeerIdentity *peer, | 64 | const struct GNUNET_PeerIdentity *peer, |
61 | const struct GNUNET_HashCode *hash) | 65 | const struct GNUNET_HashCode *hash) |
62 | { | 66 | { |
63 | GNUNET_assert((tunnels) && (peer)); | 67 | GNUNET_assert ((tunnels) && (peer)); |
64 | 68 | ||
65 | struct GNUNET_MESSENGER_ListTunnel *element = GNUNET_new(struct GNUNET_MESSENGER_ListTunnel); | 69 | struct GNUNET_MESSENGER_ListTunnel *element = GNUNET_new (struct |
70 | GNUNET_MESSENGER_ListTunnel); | ||
66 | 71 | ||
67 | element->peer = GNUNET_PEER_intern (peer); | 72 | element->peer = GNUNET_PEER_intern (peer); |
68 | element->hash = hash ? GNUNET_memdup(hash, sizeof(struct GNUNET_HashCode)) : NULL; | 73 | element->hash = hash ? GNUNET_memdup (hash, sizeof(struct GNUNET_HashCode)) : |
74 | NULL; | ||
69 | 75 | ||
70 | GNUNET_CONTAINER_DLL_insert_sorted(struct GNUNET_MESSENGER_ListTunnel, compare_list_tunnels, NULL, tunnels->head, | 76 | GNUNET_CONTAINER_DLL_insert_sorted (struct GNUNET_MESSENGER_ListTunnel, |
71 | tunnels->tail, element); | 77 | compare_list_tunnels, NULL, tunnels->head, |
78 | tunnels->tail, element); | ||
72 | } | 79 | } |
73 | 80 | ||
81 | |||
74 | struct GNUNET_MESSENGER_ListTunnel* | 82 | struct GNUNET_MESSENGER_ListTunnel* |
75 | find_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, | 83 | find_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, |
76 | const struct GNUNET_PeerIdentity *peer, | 84 | const struct GNUNET_PeerIdentity *peer, |
77 | size_t *index) | 85 | size_t *index) |
78 | { | 86 | { |
79 | GNUNET_assert((tunnels) && (peer)); | 87 | GNUNET_assert ((tunnels) && (peer)); |
80 | 88 | ||
81 | struct GNUNET_MESSENGER_ListTunnel *element; | 89 | struct GNUNET_MESSENGER_ListTunnel *element; |
82 | struct GNUNET_PeerIdentity pid; | 90 | struct GNUNET_PeerIdentity pid; |
@@ -88,7 +96,7 @@ find_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, | |||
88 | { | 96 | { |
89 | GNUNET_PEER_resolve (element->peer, &pid); | 97 | GNUNET_PEER_resolve (element->peer, &pid); |
90 | 98 | ||
91 | if (0 == GNUNET_memcmp(&pid, peer)) | 99 | if (0 == GNUNET_memcmp (&pid, peer)) |
92 | return element; | 100 | return element; |
93 | 101 | ||
94 | if (index) | 102 | if (index) |
@@ -98,111 +106,121 @@ find_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, | |||
98 | return NULL; | 106 | return NULL; |
99 | } | 107 | } |
100 | 108 | ||
109 | |||
101 | void | 110 | void |
102 | update_to_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, | 111 | update_to_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, |
103 | const struct GNUNET_PeerIdentity *peer, | 112 | const struct GNUNET_PeerIdentity *peer, |
104 | const struct GNUNET_HashCode *hash) | 113 | const struct GNUNET_HashCode *hash) |
105 | { | 114 | { |
106 | GNUNET_assert((tunnels) && (peer)); | 115 | GNUNET_assert ((tunnels) && (peer)); |
107 | 116 | ||
108 | struct GNUNET_MESSENGER_ListTunnel* element = find_list_tunnels(tunnels, peer, NULL); | 117 | struct GNUNET_MESSENGER_ListTunnel *element = find_list_tunnels (tunnels, |
109 | if (!element) | 118 | peer, |
119 | NULL); | ||
120 | if (! element) | ||
110 | return; | 121 | return; |
111 | 122 | ||
112 | if (element->hash) | 123 | if (element->hash) |
113 | { | 124 | { |
114 | if (hash) | 125 | if (hash) |
115 | GNUNET_memcpy(element->hash, hash, sizeof(struct GNUNET_HashCode)); | 126 | GNUNET_memcpy (element->hash, hash, sizeof(struct GNUNET_HashCode)); |
116 | else | 127 | else |
117 | { | 128 | { |
118 | GNUNET_free(element->hash); | 129 | GNUNET_free (element->hash); |
119 | element->hash = NULL; | 130 | element->hash = NULL; |
120 | } | 131 | } |
121 | } | 132 | } |
122 | else if (hash) | 133 | else if (hash) |
123 | element->hash = GNUNET_memdup(hash, sizeof(struct GNUNET_HashCode)); | 134 | element->hash = GNUNET_memdup (hash, sizeof(struct GNUNET_HashCode)); |
124 | } | 135 | } |
125 | 136 | ||
137 | |||
126 | int | 138 | int |
127 | contains_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, | 139 | contains_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, |
128 | const struct GNUNET_PeerIdentity *peer) | 140 | const struct GNUNET_PeerIdentity *peer) |
129 | { | 141 | { |
130 | GNUNET_assert((tunnels) && (peer)); | 142 | GNUNET_assert ((tunnels) && (peer)); |
131 | 143 | ||
132 | return find_list_tunnels (tunnels, peer, NULL) != NULL ? GNUNET_YES : GNUNET_NO; | 144 | return find_list_tunnels (tunnels, peer, NULL) != NULL ? GNUNET_YES : |
145 | GNUNET_NO; | ||
133 | } | 146 | } |
134 | 147 | ||
148 | |||
135 | struct GNUNET_MESSENGER_ListTunnel* | 149 | struct GNUNET_MESSENGER_ListTunnel* |
136 | remove_from_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, | 150 | remove_from_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, |
137 | struct GNUNET_MESSENGER_ListTunnel *element) | 151 | struct GNUNET_MESSENGER_ListTunnel *element) |
138 | { | 152 | { |
139 | GNUNET_assert((tunnels) && (element)); | 153 | GNUNET_assert ((tunnels) && (element)); |
140 | 154 | ||
141 | struct GNUNET_MESSENGER_ListTunnel *next = element->next; | 155 | struct GNUNET_MESSENGER_ListTunnel *next = element->next; |
142 | 156 | ||
143 | if ((tunnels->head) && (tunnels->tail)) | 157 | if ((tunnels->head) && (tunnels->tail)) |
144 | GNUNET_CONTAINER_DLL_remove(tunnels->head, tunnels->tail, element); | 158 | GNUNET_CONTAINER_DLL_remove (tunnels->head, tunnels->tail, element); |
145 | 159 | ||
146 | if (element->hash) | 160 | if (element->hash) |
147 | GNUNET_free(element->hash); | 161 | GNUNET_free (element->hash); |
148 | 162 | ||
149 | GNUNET_PEER_change_rc (element->peer, -1); | 163 | GNUNET_PEER_change_rc (element->peer, -1); |
150 | GNUNET_free(element); | 164 | GNUNET_free (element); |
151 | 165 | ||
152 | return next; | 166 | return next; |
153 | } | 167 | } |
154 | 168 | ||
169 | |||
155 | void | 170 | void |
156 | load_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, | 171 | load_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, |
157 | const char *path) | 172 | const char *path) |
158 | { | 173 | { |
159 | GNUNET_assert((tunnels) && (path)); | 174 | GNUNET_assert ((tunnels) && (path)); |
160 | 175 | ||
161 | if (GNUNET_YES != GNUNET_DISK_file_test (path)) | 176 | if (GNUNET_YES != GNUNET_DISK_file_test (path)) |
162 | return; | 177 | return; |
163 | 178 | ||
164 | enum GNUNET_DISK_AccessPermissions permission = (GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); | 179 | enum GNUNET_DISK_AccessPermissions permission = (GNUNET_DISK_PERM_USER_READ |
180 | | GNUNET_DISK_PERM_USER_WRITE); | ||
165 | 181 | ||
166 | struct GNUNET_DISK_FileHandle *handle = GNUNET_DISK_file_open( | 182 | struct GNUNET_DISK_FileHandle *handle = GNUNET_DISK_file_open ( |
167 | path, GNUNET_DISK_OPEN_READ, permission | 183 | path, GNUNET_DISK_OPEN_READ, permission |
168 | ); | 184 | ); |
169 | 185 | ||
170 | if (!handle) | 186 | if (! handle) |
171 | return; | 187 | return; |
172 | 188 | ||
173 | GNUNET_DISK_file_seek(handle, 0, GNUNET_DISK_SEEK_SET); | 189 | GNUNET_DISK_file_seek (handle, 0, GNUNET_DISK_SEEK_SET); |
174 | 190 | ||
175 | struct GNUNET_PeerIdentity peer; | 191 | struct GNUNET_PeerIdentity peer; |
176 | ssize_t len; | 192 | ssize_t len; |
177 | 193 | ||
178 | do { | 194 | do { |
179 | len = GNUNET_DISK_file_read(handle, &peer, sizeof(peer)); | 195 | len = GNUNET_DISK_file_read (handle, &peer, sizeof(peer)); |
180 | 196 | ||
181 | if (len != sizeof(peer)) | 197 | if (len != sizeof(peer)) |
182 | break; | 198 | break; |
183 | 199 | ||
184 | add_to_list_tunnels(tunnels, &peer, NULL); | 200 | add_to_list_tunnels (tunnels, &peer, NULL); |
185 | } while (len == sizeof(peer)); | 201 | } while (len == sizeof(peer)); |
186 | 202 | ||
187 | GNUNET_DISK_file_close(handle); | 203 | GNUNET_DISK_file_close (handle); |
188 | } | 204 | } |
189 | 205 | ||
206 | |||
190 | void | 207 | void |
191 | save_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, | 208 | save_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, |
192 | const char *path) | 209 | const char *path) |
193 | { | 210 | { |
194 | GNUNET_assert((tunnels) && (path)); | 211 | GNUNET_assert ((tunnels) && (path)); |
195 | 212 | ||
196 | enum GNUNET_DISK_AccessPermissions permission = (GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); | 213 | enum GNUNET_DISK_AccessPermissions permission = (GNUNET_DISK_PERM_USER_READ |
214 | | GNUNET_DISK_PERM_USER_WRITE); | ||
197 | 215 | ||
198 | struct GNUNET_DISK_FileHandle *handle = GNUNET_DISK_file_open( | 216 | struct GNUNET_DISK_FileHandle *handle = GNUNET_DISK_file_open ( |
199 | path, GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_WRITE, permission | 217 | path, GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_WRITE, permission |
200 | ); | 218 | ); |
201 | 219 | ||
202 | if (!handle) | 220 | if (! handle) |
203 | return; | 221 | return; |
204 | 222 | ||
205 | GNUNET_DISK_file_seek(handle, 0, GNUNET_DISK_SEEK_SET); | 223 | GNUNET_DISK_file_seek (handle, 0, GNUNET_DISK_SEEK_SET); |
206 | 224 | ||
207 | struct GNUNET_MESSENGER_ListTunnel *element; | 225 | struct GNUNET_MESSENGER_ListTunnel *element; |
208 | struct GNUNET_PeerIdentity pid; | 226 | struct GNUNET_PeerIdentity pid; |
@@ -211,9 +229,9 @@ save_list_tunnels (struct GNUNET_MESSENGER_ListTunnels *tunnels, | |||
211 | { | 229 | { |
212 | GNUNET_PEER_resolve (element->peer, &pid); | 230 | GNUNET_PEER_resolve (element->peer, &pid); |
213 | 231 | ||
214 | GNUNET_DISK_file_write(handle, &pid, sizeof(pid)); | 232 | GNUNET_DISK_file_write (handle, &pid, sizeof(pid)); |
215 | } | 233 | } |
216 | 234 | ||
217 | GNUNET_DISK_file_sync(handle); | 235 | GNUNET_DISK_file_sync (handle); |
218 | GNUNET_DISK_file_close(handle); | 236 | GNUNET_DISK_file_close (handle); |
219 | } | 237 | } |
diff --git a/src/messenger/messenger_api_message.c b/src/messenger/messenger_api_message.c index 3d9e125a4..881b18bb5 100644 --- a/src/messenger/messenger_api_message.c +++ b/src/messenger/messenger_api_message.c | |||
@@ -41,7 +41,8 @@ struct GNUNET_MESSENGER_ShortMessage | |||
41 | struct GNUNET_MESSENGER_Message* | 41 | struct GNUNET_MESSENGER_Message* |
42 | create_message (enum GNUNET_MESSENGER_MessageKind kind) | 42 | create_message (enum GNUNET_MESSENGER_MessageKind kind) |
43 | { | 43 | { |
44 | struct GNUNET_MESSENGER_Message *message = GNUNET_new(struct GNUNET_MESSENGER_Message); | 44 | struct GNUNET_MESSENGER_Message *message = GNUNET_new (struct |
45 | GNUNET_MESSENGER_Message); | ||
45 | 46 | ||
46 | message->header.kind = kind; | 47 | message->header.kind = kind; |
47 | 48 | ||
@@ -67,32 +68,36 @@ create_message (enum GNUNET_MESSENGER_MessageKind kind) | |||
67 | return message; | 68 | return message; |
68 | } | 69 | } |
69 | 70 | ||
71 | |||
70 | struct GNUNET_MESSENGER_Message* | 72 | struct GNUNET_MESSENGER_Message* |
71 | copy_message (const struct GNUNET_MESSENGER_Message *message) | 73 | copy_message (const struct GNUNET_MESSENGER_Message *message) |
72 | { | 74 | { |
73 | GNUNET_assert(message); | 75 | GNUNET_assert (message); |
74 | 76 | ||
75 | struct GNUNET_MESSENGER_Message *copy = GNUNET_new(struct GNUNET_MESSENGER_Message); | 77 | struct GNUNET_MESSENGER_Message *copy = GNUNET_new (struct |
78 | GNUNET_MESSENGER_Message); | ||
76 | 79 | ||
77 | GNUNET_memcpy(copy, message, sizeof(struct GNUNET_MESSENGER_Message)); | 80 | GNUNET_memcpy (copy, message, sizeof(struct GNUNET_MESSENGER_Message)); |
78 | 81 | ||
79 | switch (message->header.kind) | 82 | switch (message->header.kind) |
80 | { | 83 | { |
81 | case GNUNET_MESSENGER_KIND_NAME: | 84 | case GNUNET_MESSENGER_KIND_NAME: |
82 | copy->body.name.name = GNUNET_strdup(message->body.name.name); | 85 | copy->body.name.name = GNUNET_strdup (message->body.name.name); |
83 | break; | 86 | break; |
84 | case GNUNET_MESSENGER_KIND_TEXT: | 87 | case GNUNET_MESSENGER_KIND_TEXT: |
85 | copy->body.text.text = GNUNET_strdup(message->body.text.text); | 88 | copy->body.text.text = GNUNET_strdup (message->body.text.text); |
86 | break; | 89 | break; |
87 | case GNUNET_MESSENGER_KIND_FILE: | 90 | case GNUNET_MESSENGER_KIND_FILE: |
88 | copy->body.file.uri = GNUNET_strdup(message->body.file.uri); | 91 | copy->body.file.uri = GNUNET_strdup (message->body.file.uri); |
89 | break; | 92 | break; |
90 | case GNUNET_MESSENGER_KIND_PRIVATE: | 93 | case GNUNET_MESSENGER_KIND_PRIVATE: |
91 | copy->body.privacy.data = copy->body.privacy.length ? GNUNET_malloc(copy->body.privacy.length) : NULL; | 94 | copy->body.privacy.data = copy->body.privacy.length ? GNUNET_malloc ( |
95 | copy->body.privacy.length) : NULL; | ||
92 | 96 | ||
93 | if (copy->body.privacy.data) | 97 | if (copy->body.privacy.data) |
94 | { | 98 | { |
95 | GNUNET_memcpy(copy->body.privacy.data, message->body.privacy.data, copy->body.privacy.length); | 99 | GNUNET_memcpy (copy->body.privacy.data, message->body.privacy.data, |
100 | copy->body.privacy.length); | ||
96 | } | 101 | } |
97 | 102 | ||
98 | break; | 103 | break; |
@@ -103,6 +108,7 @@ copy_message (const struct GNUNET_MESSENGER_Message *message) | |||
103 | return copy; | 108 | return copy; |
104 | } | 109 | } |
105 | 110 | ||
111 | |||
106 | static void | 112 | static void |
107 | destroy_message_body (enum GNUNET_MESSENGER_MessageKind kind, | 113 | destroy_message_body (enum GNUNET_MESSENGER_MessageKind kind, |
108 | struct GNUNET_MESSENGER_MessageBody *body) | 114 | struct GNUNET_MESSENGER_MessageBody *body) |
@@ -110,44 +116,47 @@ destroy_message_body (enum GNUNET_MESSENGER_MessageKind kind, | |||
110 | switch (kind) | 116 | switch (kind) |
111 | { | 117 | { |
112 | case GNUNET_MESSENGER_KIND_NAME: | 118 | case GNUNET_MESSENGER_KIND_NAME: |
113 | GNUNET_free(body->name.name); | 119 | GNUNET_free (body->name.name); |
114 | break; | 120 | break; |
115 | case GNUNET_MESSENGER_KIND_TEXT: | 121 | case GNUNET_MESSENGER_KIND_TEXT: |
116 | GNUNET_free(body->text.text); | 122 | GNUNET_free (body->text.text); |
117 | break; | 123 | break; |
118 | case GNUNET_MESSENGER_KIND_FILE: | 124 | case GNUNET_MESSENGER_KIND_FILE: |
119 | GNUNET_free(body->file.uri); | 125 | GNUNET_free (body->file.uri); |
120 | break; | 126 | break; |
121 | case GNUNET_MESSENGER_KIND_PRIVATE: | 127 | case GNUNET_MESSENGER_KIND_PRIVATE: |
122 | GNUNET_free(body->privacy.data); | 128 | GNUNET_free (body->privacy.data); |
123 | break; | 129 | break; |
124 | default: | 130 | default: |
125 | break; | 131 | break; |
126 | } | 132 | } |
127 | } | 133 | } |
128 | 134 | ||
135 | |||
129 | void | 136 | void |
130 | cleanup_message (struct GNUNET_MESSENGER_Message *message) | 137 | cleanup_message (struct GNUNET_MESSENGER_Message *message) |
131 | { | 138 | { |
132 | GNUNET_assert(message); | 139 | GNUNET_assert (message); |
133 | 140 | ||
134 | destroy_message_body (message->header.kind, &(message->body)); | 141 | destroy_message_body (message->header.kind, &(message->body)); |
135 | } | 142 | } |
136 | 143 | ||
144 | |||
137 | void | 145 | void |
138 | destroy_message (struct GNUNET_MESSENGER_Message *message) | 146 | destroy_message (struct GNUNET_MESSENGER_Message *message) |
139 | { | 147 | { |
140 | GNUNET_assert(message); | 148 | GNUNET_assert (message); |
141 | 149 | ||
142 | destroy_message_body (message->header.kind, &(message->body)); | 150 | destroy_message_body (message->header.kind, &(message->body)); |
143 | 151 | ||
144 | GNUNET_free(message); | 152 | GNUNET_free (message); |
145 | } | 153 | } |
146 | 154 | ||
155 | |||
147 | int | 156 | int |
148 | is_message_session_bound (const struct GNUNET_MESSENGER_Message *message) | 157 | is_message_session_bound (const struct GNUNET_MESSENGER_Message *message) |
149 | { | 158 | { |
150 | GNUNET_assert(message); | 159 | GNUNET_assert (message); |
151 | 160 | ||
152 | if ((GNUNET_MESSENGER_KIND_JOIN == message->header.kind) || | 161 | if ((GNUNET_MESSENGER_KIND_JOIN == message->header.kind) || |
153 | (GNUNET_MESSENGER_KIND_LEAVE == message->header.kind) || | 162 | (GNUNET_MESSENGER_KIND_LEAVE == message->header.kind) || |
@@ -159,15 +168,18 @@ is_message_session_bound (const struct GNUNET_MESSENGER_Message *message) | |||
159 | return GNUNET_NO; | 168 | return GNUNET_NO; |
160 | } | 169 | } |
161 | 170 | ||
171 | |||
162 | static void | 172 | static void |
163 | fold_short_message (const struct GNUNET_MESSENGER_Message *message, | 173 | fold_short_message (const struct GNUNET_MESSENGER_Message *message, |
164 | struct GNUNET_MESSENGER_ShortMessage *shortened) | 174 | struct GNUNET_MESSENGER_ShortMessage *shortened) |
165 | { | 175 | { |
166 | shortened->kind = message->header.kind; | 176 | shortened->kind = message->header.kind; |
167 | 177 | ||
168 | GNUNET_memcpy(&(shortened->body), &(message->body), sizeof(struct GNUNET_MESSENGER_MessageBody)); | 178 | GNUNET_memcpy (&(shortened->body), &(message->body), sizeof(struct |
179 | GNUNET_MESSENGER_MessageBody)); | ||
169 | } | 180 | } |
170 | 181 | ||
182 | |||
171 | static void | 183 | static void |
172 | unfold_short_message (struct GNUNET_MESSENGER_ShortMessage *shortened, | 184 | unfold_short_message (struct GNUNET_MESSENGER_ShortMessage *shortened, |
173 | struct GNUNET_MESSENGER_Message *message) | 185 | struct GNUNET_MESSENGER_Message *message) |
@@ -176,9 +188,11 @@ unfold_short_message (struct GNUNET_MESSENGER_ShortMessage *shortened, | |||
176 | 188 | ||
177 | message->header.kind = shortened->kind; | 189 | message->header.kind = shortened->kind; |
178 | 190 | ||
179 | GNUNET_memcpy(&(message->body), &(shortened->body), sizeof(struct GNUNET_MESSENGER_MessageBody)); | 191 | GNUNET_memcpy (&(message->body), &(shortened->body), sizeof(struct |
192 | GNUNET_MESSENGER_MessageBody)); | ||
180 | } | 193 | } |
181 | 194 | ||
195 | |||
182 | #define member_size(type, member) sizeof(((type*) NULL)->member) | 196 | #define member_size(type, member) sizeof(((type*) NULL)->member) |
183 | 197 | ||
184 | static uint16_t | 198 | static uint16_t |
@@ -189,40 +203,43 @@ get_message_body_kind_size (enum GNUNET_MESSENGER_MessageKind kind) | |||
189 | switch (kind) | 203 | switch (kind) |
190 | { | 204 | { |
191 | case GNUNET_MESSENGER_KIND_INFO: | 205 | case GNUNET_MESSENGER_KIND_INFO: |
192 | length += member_size(struct GNUNET_MESSENGER_Message, body.info.messenger_version); | 206 | length += member_size (struct GNUNET_MESSENGER_Message, |
207 | body.info.messenger_version); | ||
193 | break; | 208 | break; |
194 | case GNUNET_MESSENGER_KIND_PEER: | 209 | case GNUNET_MESSENGER_KIND_PEER: |
195 | length += member_size(struct GNUNET_MESSENGER_Message, body.peer.peer); | 210 | length += member_size (struct GNUNET_MESSENGER_Message, body.peer.peer); |
196 | break; | 211 | break; |
197 | case GNUNET_MESSENGER_KIND_ID: | 212 | case GNUNET_MESSENGER_KIND_ID: |
198 | length += member_size(struct GNUNET_MESSENGER_Message, body.id.id); | 213 | length += member_size (struct GNUNET_MESSENGER_Message, body.id.id); |
199 | break; | 214 | break; |
200 | case GNUNET_MESSENGER_KIND_MISS: | 215 | case GNUNET_MESSENGER_KIND_MISS: |
201 | length += member_size(struct GNUNET_MESSENGER_Message, body.miss.peer); | 216 | length += member_size (struct GNUNET_MESSENGER_Message, body.miss.peer); |
202 | break; | 217 | break; |
203 | case GNUNET_MESSENGER_KIND_MERGE: | 218 | case GNUNET_MESSENGER_KIND_MERGE: |
204 | length += member_size(struct GNUNET_MESSENGER_Message, body.merge.previous); | 219 | length += member_size (struct GNUNET_MESSENGER_Message, |
220 | body.merge.previous); | ||
205 | break; | 221 | break; |
206 | case GNUNET_MESSENGER_KIND_REQUEST: | 222 | case GNUNET_MESSENGER_KIND_REQUEST: |
207 | length += member_size(struct GNUNET_MESSENGER_Message, body.request.hash); | 223 | length += member_size (struct GNUNET_MESSENGER_Message, body.request.hash); |
208 | break; | 224 | break; |
209 | case GNUNET_MESSENGER_KIND_INVITE: | 225 | case GNUNET_MESSENGER_KIND_INVITE: |
210 | length += member_size(struct GNUNET_MESSENGER_Message, body.invite.door); | 226 | length += member_size (struct GNUNET_MESSENGER_Message, body.invite.door); |
211 | length += member_size(struct GNUNET_MESSENGER_Message, body.invite.key); | 227 | length += member_size (struct GNUNET_MESSENGER_Message, body.invite.key); |
212 | break; | 228 | break; |
213 | case GNUNET_MESSENGER_KIND_TEXT: | 229 | case GNUNET_MESSENGER_KIND_TEXT: |
214 | break; | 230 | break; |
215 | case GNUNET_MESSENGER_KIND_FILE: | 231 | case GNUNET_MESSENGER_KIND_FILE: |
216 | length += member_size(struct GNUNET_MESSENGER_Message, body.file.key); | 232 | length += member_size (struct GNUNET_MESSENGER_Message, body.file.key); |
217 | length += member_size(struct GNUNET_MESSENGER_Message, body.file.hash); | 233 | length += member_size (struct GNUNET_MESSENGER_Message, body.file.hash); |
218 | length += member_size(struct GNUNET_MESSENGER_Message, body.file.name); | 234 | length += member_size (struct GNUNET_MESSENGER_Message, body.file.name); |
219 | break; | 235 | break; |
220 | case GNUNET_MESSENGER_KIND_PRIVATE: | 236 | case GNUNET_MESSENGER_KIND_PRIVATE: |
221 | length += member_size(struct GNUNET_MESSENGER_Message, body.privacy.key); | 237 | length += member_size (struct GNUNET_MESSENGER_Message, body.privacy.key); |
222 | break; | 238 | break; |
223 | case GNUNET_MESSENGER_KIND_DELETE: | 239 | case GNUNET_MESSENGER_KIND_DELETE: |
224 | length += member_size(struct GNUNET_MESSENGER_Message, body.deletion.hash); | 240 | length += member_size (struct GNUNET_MESSENGER_Message, body.deletion.hash); |
225 | length += member_size(struct GNUNET_MESSENGER_Message, body.deletion.delay); | 241 | length += member_size (struct GNUNET_MESSENGER_Message, |
242 | body.deletion.delay); | ||
226 | break; | 243 | break; |
227 | default: | 244 | default: |
228 | break; | 245 | break; |
@@ -231,6 +248,7 @@ get_message_body_kind_size (enum GNUNET_MESSENGER_MessageKind kind) | |||
231 | return length; | 248 | return length; |
232 | } | 249 | } |
233 | 250 | ||
251 | |||
234 | typedef uint32_t kind_t; | 252 | typedef uint32_t kind_t; |
235 | 253 | ||
236 | uint16_t | 254 | uint16_t |
@@ -241,9 +259,9 @@ get_message_kind_size (enum GNUNET_MESSENGER_MessageKind kind, | |||
241 | 259 | ||
242 | if (GNUNET_YES == include_header) | 260 | if (GNUNET_YES == include_header) |
243 | { | 261 | { |
244 | length += member_size(struct GNUNET_MESSENGER_Message, header.timestamp); | 262 | length += member_size (struct GNUNET_MESSENGER_Message, header.timestamp); |
245 | length += member_size(struct GNUNET_MESSENGER_Message, header.sender_id); | 263 | length += member_size (struct GNUNET_MESSENGER_Message, header.sender_id); |
246 | length += member_size(struct GNUNET_MESSENGER_Message, header.previous); | 264 | length += member_size (struct GNUNET_MESSENGER_Message, header.previous); |
247 | } | 265 | } |
248 | 266 | ||
249 | length += sizeof(kind_t); | 267 | length += sizeof(kind_t); |
@@ -251,6 +269,7 @@ get_message_kind_size (enum GNUNET_MESSENGER_MessageKind kind, | |||
251 | return length + get_message_body_kind_size (kind); | 269 | return length + get_message_body_kind_size (kind); |
252 | } | 270 | } |
253 | 271 | ||
272 | |||
254 | static uint16_t | 273 | static uint16_t |
255 | get_message_body_size (enum GNUNET_MESSENGER_MessageKind kind, | 274 | get_message_body_size (enum GNUNET_MESSENGER_MessageKind kind, |
256 | const struct GNUNET_MESSENGER_MessageBody *body) | 275 | const struct GNUNET_MESSENGER_MessageBody *body) |
@@ -260,13 +279,13 @@ get_message_body_size (enum GNUNET_MESSENGER_MessageKind kind, | |||
260 | switch (kind) | 279 | switch (kind) |
261 | { | 280 | { |
262 | case GNUNET_MESSENGER_KIND_JOIN: | 281 | case GNUNET_MESSENGER_KIND_JOIN: |
263 | length += GNUNET_IDENTITY_public_key_get_length(&(body->join.key)); | 282 | length += GNUNET_IDENTITY_public_key_get_length (&(body->join.key)); |
264 | break; | 283 | break; |
265 | case GNUNET_MESSENGER_KIND_NAME: | 284 | case GNUNET_MESSENGER_KIND_NAME: |
266 | length += (body->name.name ? strlen (body->name.name) : 0); | 285 | length += (body->name.name ? strlen (body->name.name) : 0); |
267 | break; | 286 | break; |
268 | case GNUNET_MESSENGER_KIND_KEY: | 287 | case GNUNET_MESSENGER_KIND_KEY: |
269 | length += GNUNET_IDENTITY_public_key_get_length(&(body->key.key)); | 288 | length += GNUNET_IDENTITY_public_key_get_length (&(body->key.key)); |
270 | break; | 289 | break; |
271 | case GNUNET_MESSENGER_KIND_TEXT: | 290 | case GNUNET_MESSENGER_KIND_TEXT: |
272 | length += strlen (body->text.text); | 291 | length += strlen (body->text.text); |
@@ -284,16 +303,18 @@ get_message_body_size (enum GNUNET_MESSENGER_MessageKind kind, | |||
284 | return length; | 303 | return length; |
285 | } | 304 | } |
286 | 305 | ||
306 | |||
287 | uint16_t | 307 | uint16_t |
288 | get_message_size (const struct GNUNET_MESSENGER_Message *message, | 308 | get_message_size (const struct GNUNET_MESSENGER_Message *message, |
289 | int include_header) | 309 | int include_header) |
290 | { | 310 | { |
291 | GNUNET_assert(message); | 311 | GNUNET_assert (message); |
292 | 312 | ||
293 | uint16_t length = 0; | 313 | uint16_t length = 0; |
294 | 314 | ||
295 | if (GNUNET_YES == include_header) | 315 | if (GNUNET_YES == include_header) |
296 | length += GNUNET_IDENTITY_signature_get_length(&(message->header.signature)); | 316 | length += GNUNET_IDENTITY_signature_get_length ( |
317 | &(message->header.signature)); | ||
297 | 318 | ||
298 | length += get_message_kind_size (message->header.kind, include_header); | 319 | length += get_message_kind_size (message->header.kind, include_header); |
299 | length += get_message_body_size (message->header.kind, &(message->body)); | 320 | length += get_message_body_size (message->header.kind, &(message->body)); |
@@ -301,6 +322,7 @@ get_message_size (const struct GNUNET_MESSENGER_Message *message, | |||
301 | return length; | 322 | return length; |
302 | } | 323 | } |
303 | 324 | ||
325 | |||
304 | static uint16_t | 326 | static uint16_t |
305 | get_short_message_size (const struct GNUNET_MESSENGER_ShortMessage *message, | 327 | get_short_message_size (const struct GNUNET_MESSENGER_ShortMessage *message, |
306 | int include_body) | 328 | int include_body) |
@@ -309,19 +331,24 @@ get_short_message_size (const struct GNUNET_MESSENGER_ShortMessage *message, | |||
309 | 331 | ||
310 | if (message) | 332 | if (message) |
311 | return minimum_size + get_message_body_kind_size (message->kind) | 333 | return minimum_size + get_message_body_kind_size (message->kind) |
312 | + (include_body == GNUNET_YES? get_message_body_size (message->kind, &(message->body)) : 0); | 334 | + (include_body == GNUNET_YES? get_message_body_size (message->kind, |
335 | &(message->body)) | ||
336 | : 0); | ||
313 | else | 337 | else |
314 | return minimum_size; | 338 | return minimum_size; |
315 | } | 339 | } |
316 | 340 | ||
341 | |||
317 | static uint16_t | 342 | static uint16_t |
318 | calc_usual_padding () | 343 | calc_usual_padding () |
319 | { | 344 | { |
320 | uint16_t padding = 0; | 345 | uint16_t padding = 0; |
321 | uint16_t kind_size; | 346 | uint16_t kind_size; |
322 | 347 | ||
323 | for (int i = 0; i <= GNUNET_MESSENGER_KIND_MAX; i++) { | 348 | for (int i = 0; i <= GNUNET_MESSENGER_KIND_MAX; i++) |
324 | kind_size = get_message_kind_size ((enum GNUNET_MESSENGER_MessageKind) i, GNUNET_YES); | 349 | { |
350 | kind_size = get_message_kind_size ((enum GNUNET_MESSENGER_MessageKind) i, | ||
351 | GNUNET_YES); | ||
325 | 352 | ||
326 | if (kind_size > padding) | 353 | if (kind_size > padding) |
327 | padding = kind_size; | 354 | padding = kind_size; |
@@ -330,6 +357,7 @@ calc_usual_padding () | |||
330 | return padding + GNUNET_MESSENGER_PADDING_MIN; | 357 | return padding + GNUNET_MESSENGER_PADDING_MIN; |
331 | } | 358 | } |
332 | 359 | ||
360 | |||
333 | #define max(x, y) (x > y? x : y) | 361 | #define max(x, y) (x > y? x : y) |
334 | 362 | ||
335 | static uint16_t | 363 | static uint16_t |
@@ -337,13 +365,13 @@ calc_padded_length (uint16_t length) | |||
337 | { | 365 | { |
338 | static uint16_t usual_padding = 0; | 366 | static uint16_t usual_padding = 0; |
339 | 367 | ||
340 | if (!usual_padding) | 368 | if (! usual_padding) |
341 | usual_padding = calc_usual_padding(); | 369 | usual_padding = calc_usual_padding (); |
342 | 370 | ||
343 | const uint16_t padded_length = max( | 371 | const uint16_t padded_length = max ( |
344 | length + GNUNET_MESSENGER_PADDING_MIN, | 372 | length + GNUNET_MESSENGER_PADDING_MIN, |
345 | usual_padding | 373 | usual_padding |
346 | ); | 374 | ); |
347 | 375 | ||
348 | if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL0) | 376 | if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL0) |
349 | return GNUNET_MESSENGER_PADDING_LEVEL0; | 377 | return GNUNET_MESSENGER_PADDING_LEVEL0; |
@@ -358,35 +386,36 @@ calc_padded_length (uint16_t length) | |||
358 | 386 | ||
359 | } | 387 | } |
360 | 388 | ||
389 | |||
361 | #define min(x, y) (x < y? x : y) | 390 | #define min(x, y) (x < y? x : y) |
362 | 391 | ||
363 | #define encode_step_ext(dst, offset, src, size) do { \ | 392 | #define encode_step_ext(dst, offset, src, size) do { \ |
364 | GNUNET_memcpy(dst + offset, src, size); \ | 393 | GNUNET_memcpy (dst + offset, src, size); \ |
365 | offset += size; \ | 394 | offset += size; \ |
366 | } while (0) | 395 | } while (0) |
367 | 396 | ||
368 | #define encode_step(dst, offset, src) do { \ | 397 | #define encode_step(dst, offset, src) do { \ |
369 | encode_step_ext(dst, offset, src, sizeof(*src)); \ | 398 | encode_step_ext (dst, offset, src, sizeof(*src)); \ |
370 | } while (0) | 399 | } while (0) |
371 | 400 | ||
372 | #define encode_step_key(dst, offset, src, length) do { \ | 401 | #define encode_step_key(dst, offset, src, length) do { \ |
373 | ssize_t result = GNUNET_IDENTITY_write_public_key_to_buffer( \ | 402 | ssize_t result = GNUNET_IDENTITY_write_public_key_to_buffer ( \ |
374 | src, dst + offset, length - offset \ | 403 | src, dst + offset, length - offset \ |
375 | ); \ | 404 | ); \ |
376 | if (result < 0) \ | 405 | if (result < 0) \ |
377 | GNUNET_break (0); \ | 406 | GNUNET_break (0); \ |
378 | else \ | 407 | else \ |
379 | offset += result; \ | 408 | offset += result; \ |
380 | } while (0) | 409 | } while (0) |
381 | 410 | ||
382 | #define encode_step_signature(dst, offset, src, length) do { \ | 411 | #define encode_step_signature(dst, offset, src, length) do { \ |
383 | ssize_t result = GNUNET_IDENTITY_write_signature_to_buffer( \ | 412 | ssize_t result = GNUNET_IDENTITY_write_signature_to_buffer ( \ |
384 | src, dst + offset, length - offset \ | 413 | src, dst + offset, length - offset \ |
385 | ); \ | 414 | ); \ |
386 | if (result < 0) \ | 415 | if (result < 0) \ |
387 | GNUNET_break (0); \ | 416 | GNUNET_break (0); \ |
388 | else \ | 417 | else \ |
389 | offset += result; \ | 418 | offset += result; \ |
390 | } while (0) | 419 | } while (0) |
391 | 420 | ||
392 | static void | 421 | static void |
@@ -400,55 +429,63 @@ encode_message_body (enum GNUNET_MESSENGER_MessageKind kind, | |||
400 | switch (kind) | 429 | switch (kind) |
401 | { | 430 | { |
402 | case GNUNET_MESSENGER_KIND_INFO: | 431 | case GNUNET_MESSENGER_KIND_INFO: |
403 | version = GNUNET_htobe32(body->info.messenger_version); | 432 | version = GNUNET_htobe32 (body->info.messenger_version); |
404 | 433 | ||
405 | encode_step(buffer, offset, &version); | 434 | encode_step (buffer, offset, &version); |
406 | break; | 435 | break; |
407 | case GNUNET_MESSENGER_KIND_JOIN: | 436 | case GNUNET_MESSENGER_KIND_JOIN: |
408 | encode_step_key(buffer, offset, &(body->join.key), length); | 437 | encode_step_key (buffer, offset, &(body->join.key), length); |
409 | break; | 438 | break; |
410 | case GNUNET_MESSENGER_KIND_NAME: | 439 | case GNUNET_MESSENGER_KIND_NAME: |
411 | if (body->name.name) | 440 | if (body->name.name) |
412 | encode_step_ext(buffer, offset, body->name.name, min(length - offset, strlen(body->name.name))); | 441 | encode_step_ext (buffer, offset, body->name.name, min (length - offset, |
442 | strlen ( | ||
443 | body->name.name))); | ||
413 | break; | 444 | break; |
414 | case GNUNET_MESSENGER_KIND_KEY: | 445 | case GNUNET_MESSENGER_KIND_KEY: |
415 | encode_step_key(buffer, offset, &(body->key.key), length); | 446 | encode_step_key (buffer, offset, &(body->key.key), length); |
416 | break; | 447 | break; |
417 | case GNUNET_MESSENGER_KIND_PEER: | 448 | case GNUNET_MESSENGER_KIND_PEER: |
418 | encode_step(buffer, offset, &(body->peer.peer)); | 449 | encode_step (buffer, offset, &(body->peer.peer)); |
419 | break; | 450 | break; |
420 | case GNUNET_MESSENGER_KIND_ID: | 451 | case GNUNET_MESSENGER_KIND_ID: |
421 | encode_step(buffer, offset, &(body->id.id)); | 452 | encode_step (buffer, offset, &(body->id.id)); |
422 | break; | 453 | break; |
423 | case GNUNET_MESSENGER_KIND_MISS: | 454 | case GNUNET_MESSENGER_KIND_MISS: |
424 | encode_step(buffer, offset, &(body->miss.peer)); | 455 | encode_step (buffer, offset, &(body->miss.peer)); |
425 | break; | 456 | break; |
426 | case GNUNET_MESSENGER_KIND_MERGE: | 457 | case GNUNET_MESSENGER_KIND_MERGE: |
427 | encode_step(buffer, offset, &(body->merge.previous)); | 458 | encode_step (buffer, offset, &(body->merge.previous)); |
428 | break; | 459 | break; |
429 | case GNUNET_MESSENGER_KIND_REQUEST: | 460 | case GNUNET_MESSENGER_KIND_REQUEST: |
430 | encode_step(buffer, offset, &(body->request.hash)); | 461 | encode_step (buffer, offset, &(body->request.hash)); |
431 | break; | 462 | break; |
432 | case GNUNET_MESSENGER_KIND_INVITE: | 463 | case GNUNET_MESSENGER_KIND_INVITE: |
433 | encode_step(buffer, offset, &(body->invite.door)); | 464 | encode_step (buffer, offset, &(body->invite.door)); |
434 | encode_step(buffer, offset, &(body->invite.key)); | 465 | encode_step (buffer, offset, &(body->invite.key)); |
435 | break; | 466 | break; |
436 | case GNUNET_MESSENGER_KIND_TEXT: | 467 | case GNUNET_MESSENGER_KIND_TEXT: |
437 | encode_step_ext(buffer, offset, body->text.text, min(length - offset, strlen(body->text.text))); | 468 | encode_step_ext (buffer, offset, body->text.text, min (length - offset, |
469 | strlen ( | ||
470 | body->text.text))); | ||
438 | break; | 471 | break; |
439 | case GNUNET_MESSENGER_KIND_FILE: | 472 | case GNUNET_MESSENGER_KIND_FILE: |
440 | encode_step(buffer, offset, &(body->file.key)); | 473 | encode_step (buffer, offset, &(body->file.key)); |
441 | encode_step(buffer, offset, &(body->file.hash)); | 474 | encode_step (buffer, offset, &(body->file.hash)); |
442 | encode_step_ext(buffer, offset, body->file.name, sizeof(body->file.name)); | 475 | encode_step_ext (buffer, offset, body->file.name, sizeof(body->file.name)); |
443 | encode_step_ext(buffer, offset, body->file.uri, min(length - offset, strlen(body->file.uri))); | 476 | encode_step_ext (buffer, offset, body->file.uri, min (length - offset, |
477 | strlen ( | ||
478 | body->file.uri))); | ||
444 | break; | 479 | break; |
445 | case GNUNET_MESSENGER_KIND_PRIVATE: | 480 | case GNUNET_MESSENGER_KIND_PRIVATE: |
446 | encode_step(buffer, offset, &(body->privacy.key)); | 481 | encode_step (buffer, offset, &(body->privacy.key)); |
447 | encode_step_ext(buffer, offset, body->privacy.data, min(length - offset, body->privacy.length)); | 482 | encode_step_ext (buffer, offset, body->privacy.data, min (length - offset, |
483 | body->privacy. | ||
484 | length)); | ||
448 | break; | 485 | break; |
449 | case GNUNET_MESSENGER_KIND_DELETE: | 486 | case GNUNET_MESSENGER_KIND_DELETE: |
450 | encode_step(buffer, offset, &(body->deletion.hash)); | 487 | encode_step (buffer, offset, &(body->deletion.hash)); |
451 | encode_step(buffer, offset, &(body->deletion.delay)); | 488 | encode_step (buffer, offset, &(body->deletion.delay)); |
452 | break; | 489 | break; |
453 | default: | 490 | default: |
454 | break; | 491 | break; |
@@ -460,43 +497,48 @@ encode_message_body (enum GNUNET_MESSENGER_MessageKind kind, | |||
460 | const uint16_t padding = length - offset; | 497 | const uint16_t padding = length - offset; |
461 | const uint16_t used_padding = sizeof(padding) + sizeof(char); | 498 | const uint16_t used_padding = sizeof(padding) + sizeof(char); |
462 | 499 | ||
463 | GNUNET_assert(padding >= used_padding); | 500 | GNUNET_assert (padding >= used_padding); |
464 | 501 | ||
465 | buffer[offset++] = '\0'; | 502 | buffer[offset++] = '\0'; |
466 | 503 | ||
467 | if (padding > used_padding) | 504 | if (padding > used_padding) |
468 | GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, buffer + offset, padding - used_padding); | 505 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, buffer + offset, |
506 | padding - used_padding); | ||
469 | 507 | ||
470 | GNUNET_memcpy(buffer + length - sizeof(padding), &padding, sizeof(padding)); | 508 | GNUNET_memcpy (buffer + length - sizeof(padding), &padding, sizeof(padding)); |
471 | } | 509 | } |
472 | 510 | ||
511 | |||
473 | void | 512 | void |
474 | encode_message (const struct GNUNET_MESSENGER_Message *message, | 513 | encode_message (const struct GNUNET_MESSENGER_Message *message, |
475 | uint16_t length, | 514 | uint16_t length, |
476 | char *buffer, | 515 | char *buffer, |
477 | int include_header) | 516 | int include_header) |
478 | { | 517 | { |
479 | GNUNET_assert((message) && (buffer)); | 518 | GNUNET_assert ((message) && (buffer)); |
480 | 519 | ||
481 | uint16_t offset = 0; | 520 | uint16_t offset = 0; |
482 | 521 | ||
483 | if (GNUNET_YES == include_header) | 522 | if (GNUNET_YES == include_header) |
484 | encode_step_signature(buffer, offset, &(message->header.signature), length); | 523 | encode_step_signature (buffer, offset, &(message->header.signature), |
524 | length); | ||
485 | 525 | ||
486 | const kind_t kind = GNUNET_htobe32((kind_t) message->header.kind); | 526 | const kind_t kind = GNUNET_htobe32 ((kind_t) message->header.kind); |
487 | 527 | ||
488 | if (GNUNET_YES == include_header) | 528 | if (GNUNET_YES == include_header) |
489 | { | 529 | { |
490 | encode_step(buffer, offset, &(message->header.timestamp)); | 530 | encode_step (buffer, offset, &(message->header.timestamp)); |
491 | encode_step(buffer, offset, &(message->header.sender_id)); | 531 | encode_step (buffer, offset, &(message->header.sender_id)); |
492 | encode_step(buffer, offset, &(message->header.previous)); | 532 | encode_step (buffer, offset, &(message->header.previous)); |
493 | } | 533 | } |
494 | 534 | ||
495 | encode_step(buffer, offset, &kind); | 535 | encode_step (buffer, offset, &kind); |
496 | 536 | ||
497 | encode_message_body (message->header.kind, &(message->body), length, buffer, offset); | 537 | encode_message_body (message->header.kind, &(message->body), length, buffer, |
538 | offset); | ||
498 | } | 539 | } |
499 | 540 | ||
541 | |||
500 | static void | 542 | static void |
501 | encode_short_message (const struct GNUNET_MESSENGER_ShortMessage *message, | 543 | encode_short_message (const struct GNUNET_MESSENGER_ShortMessage *message, |
502 | uint16_t length, | 544 | uint16_t length, |
@@ -505,46 +547,47 @@ encode_short_message (const struct GNUNET_MESSENGER_ShortMessage *message, | |||
505 | struct GNUNET_HashCode hash; | 547 | struct GNUNET_HashCode hash; |
506 | uint16_t offset = sizeof(hash); | 548 | uint16_t offset = sizeof(hash); |
507 | 549 | ||
508 | const kind_t kind = GNUNET_htobe32((kind_t) message->kind); | 550 | const kind_t kind = GNUNET_htobe32 ((kind_t) message->kind); |
509 | 551 | ||
510 | encode_step(buffer, offset, &kind); | 552 | encode_step (buffer, offset, &kind); |
511 | 553 | ||
512 | encode_message_body (message->kind, &(message->body), length, buffer, offset); | 554 | encode_message_body (message->kind, &(message->body), length, buffer, offset); |
513 | 555 | ||
514 | GNUNET_CRYPTO_hash( | 556 | GNUNET_CRYPTO_hash ( |
515 | buffer + sizeof(hash), | 557 | buffer + sizeof(hash), |
516 | length - sizeof(hash), | 558 | length - sizeof(hash), |
517 | &hash | 559 | &hash |
518 | ); | 560 | ); |
519 | 561 | ||
520 | GNUNET_memcpy(buffer, &hash, sizeof(hash)); | 562 | GNUNET_memcpy (buffer, &hash, sizeof(hash)); |
521 | } | 563 | } |
522 | 564 | ||
565 | |||
523 | #define decode_step_ext(src, offset, dst, size) do { \ | 566 | #define decode_step_ext(src, offset, dst, size) do { \ |
524 | GNUNET_memcpy(dst, src + offset, size); \ | 567 | GNUNET_memcpy (dst, src + offset, size); \ |
525 | offset += size; \ | 568 | offset += size; \ |
526 | } while (0) | 569 | } while (0) |
527 | 570 | ||
528 | #define decode_step(src, offset, dst) do { \ | 571 | #define decode_step(src, offset, dst) do { \ |
529 | decode_step_ext(src, offset, dst, sizeof(*dst)); \ | 572 | decode_step_ext (src, offset, dst, sizeof(*dst)); \ |
530 | } while (0) | 573 | } while (0) |
531 | 574 | ||
532 | #define decode_step_malloc(src, offset, dst, size, zero) do { \ | 575 | #define decode_step_malloc(src, offset, dst, size, zero) do { \ |
533 | dst = GNUNET_malloc(size + zero); \ | 576 | dst = GNUNET_malloc (size + zero); \ |
534 | if (zero) dst[size] = 0; \ | 577 | if (zero) dst[size] = 0; \ |
535 | decode_step_ext(src, offset, dst, size); \ | 578 | decode_step_ext (src, offset, dst, size); \ |
536 | } while (0) | 579 | } while (0) |
537 | 580 | ||
538 | #define decode_step_key(src, offset, dst, length) do { \ | 581 | #define decode_step_key(src, offset, dst, length) do { \ |
539 | enum GNUNET_GenericReturnValue result; \ | 582 | enum GNUNET_GenericReturnValue result; \ |
540 | size_t read; \ | 583 | size_t read; \ |
541 | result = GNUNET_IDENTITY_read_public_key_from_buffer( \ | 584 | result = GNUNET_IDENTITY_read_public_key_from_buffer ( \ |
542 | src + offset, length - offset, dst, &read \ | 585 | src + offset, length - offset, dst, &read \ |
543 | ); \ | 586 | ); \ |
544 | if (GNUNET_SYSERR == result) \ | 587 | if (GNUNET_SYSERR == result) \ |
545 | GNUNET_break(0); \ | 588 | GNUNET_break (0); \ |
546 | else \ | 589 | else \ |
547 | offset += read; \ | 590 | offset += read; \ |
548 | } while (0) | 591 | } while (0) |
549 | 592 | ||
550 | static uint16_t | 593 | static uint16_t |
@@ -556,7 +599,7 @@ decode_message_body (enum GNUNET_MESSENGER_MessageKind *kind, | |||
556 | { | 599 | { |
557 | uint16_t padding = 0; | 600 | uint16_t padding = 0; |
558 | 601 | ||
559 | GNUNET_memcpy(&padding, buffer + length - sizeof(padding), sizeof(padding)); | 602 | GNUNET_memcpy (&padding, buffer + length - sizeof(padding), sizeof(padding)); |
560 | 603 | ||
561 | if (padding > length - offset) | 604 | if (padding > length - offset) |
562 | padding = 0; | 605 | padding = 0; |
@@ -572,59 +615,59 @@ decode_message_body (enum GNUNET_MESSENGER_MessageKind *kind, | |||
572 | switch (*kind) | 615 | switch (*kind) |
573 | { | 616 | { |
574 | case GNUNET_MESSENGER_KIND_INFO: { | 617 | case GNUNET_MESSENGER_KIND_INFO: { |
575 | decode_step(buffer, offset, &version); | 618 | decode_step (buffer, offset, &version); |
576 | 619 | ||
577 | body->info.messenger_version = GNUNET_be32toh(version); | 620 | body->info.messenger_version = GNUNET_be32toh (version); |
578 | break; | 621 | break; |
579 | } case GNUNET_MESSENGER_KIND_JOIN: { | 622 | } case GNUNET_MESSENGER_KIND_JOIN: { |
580 | decode_step_key(buffer, offset, &(body->join.key), length); | 623 | decode_step_key (buffer, offset, &(body->join.key), length); |
581 | break; | 624 | break; |
582 | } case GNUNET_MESSENGER_KIND_NAME: | 625 | } case GNUNET_MESSENGER_KIND_NAME: |
583 | if (length - offset > 0) | 626 | if (length - offset > 0) |
584 | decode_step_malloc(buffer, offset, body->name.name, length - offset, 1); | 627 | decode_step_malloc (buffer, offset, body->name.name, length - offset, 1); |
585 | else | 628 | else |
586 | body->name.name = NULL; | 629 | body->name.name = NULL; |
587 | break; | 630 | break; |
588 | case GNUNET_MESSENGER_KIND_KEY: | 631 | case GNUNET_MESSENGER_KIND_KEY: |
589 | decode_step_key(buffer, offset, &(body->key.key), length); | 632 | decode_step_key (buffer, offset, &(body->key.key), length); |
590 | break; | 633 | break; |
591 | case GNUNET_MESSENGER_KIND_PEER: | 634 | case GNUNET_MESSENGER_KIND_PEER: |
592 | decode_step(buffer, offset, &(body->peer.peer)); | 635 | decode_step (buffer, offset, &(body->peer.peer)); |
593 | break; | 636 | break; |
594 | case GNUNET_MESSENGER_KIND_ID: | 637 | case GNUNET_MESSENGER_KIND_ID: |
595 | decode_step(buffer, offset, &(body->id.id)); | 638 | decode_step (buffer, offset, &(body->id.id)); |
596 | break; | 639 | break; |
597 | case GNUNET_MESSENGER_KIND_MISS: | 640 | case GNUNET_MESSENGER_KIND_MISS: |
598 | decode_step(buffer, offset, &(body->miss.peer)); | 641 | decode_step (buffer, offset, &(body->miss.peer)); |
599 | break; | 642 | break; |
600 | case GNUNET_MESSENGER_KIND_MERGE: | 643 | case GNUNET_MESSENGER_KIND_MERGE: |
601 | decode_step(buffer, offset, &(body->merge.previous)); | 644 | decode_step (buffer, offset, &(body->merge.previous)); |
602 | break; | 645 | break; |
603 | case GNUNET_MESSENGER_KIND_REQUEST: | 646 | case GNUNET_MESSENGER_KIND_REQUEST: |
604 | decode_step(buffer, offset, &(body->request.hash)); | 647 | decode_step (buffer, offset, &(body->request.hash)); |
605 | break; | 648 | break; |
606 | case GNUNET_MESSENGER_KIND_INVITE: | 649 | case GNUNET_MESSENGER_KIND_INVITE: |
607 | decode_step(buffer, offset, &(body->invite.door)); | 650 | decode_step (buffer, offset, &(body->invite.door)); |
608 | decode_step(buffer, offset, &(body->invite.key)); | 651 | decode_step (buffer, offset, &(body->invite.key)); |
609 | break; | 652 | break; |
610 | case GNUNET_MESSENGER_KIND_TEXT: | 653 | case GNUNET_MESSENGER_KIND_TEXT: |
611 | decode_step_malloc(buffer, offset, body->text.text, length - offset, 1); | 654 | decode_step_malloc (buffer, offset, body->text.text, length - offset, 1); |
612 | break; | 655 | break; |
613 | case GNUNET_MESSENGER_KIND_FILE: | 656 | case GNUNET_MESSENGER_KIND_FILE: |
614 | decode_step(buffer, offset, &(body->file.key)); | 657 | decode_step (buffer, offset, &(body->file.key)); |
615 | decode_step(buffer, offset, &(body->file.hash)); | 658 | decode_step (buffer, offset, &(body->file.hash)); |
616 | decode_step_ext(buffer, offset, body->file.name, sizeof(body->file.name)); | 659 | decode_step_ext (buffer, offset, body->file.name, sizeof(body->file.name)); |
617 | decode_step_malloc(buffer, offset, body->file.uri, length - offset, 1); | 660 | decode_step_malloc (buffer, offset, body->file.uri, length - offset, 1); |
618 | break; | 661 | break; |
619 | case GNUNET_MESSENGER_KIND_PRIVATE: | 662 | case GNUNET_MESSENGER_KIND_PRIVATE: |
620 | decode_step(buffer, offset, &(body->privacy.key)); | 663 | decode_step (buffer, offset, &(body->privacy.key)); |
621 | 664 | ||
622 | body->privacy.length = (length - offset); | 665 | body->privacy.length = (length - offset); |
623 | decode_step_malloc(buffer, offset, body->privacy.data, length - offset, 0); | 666 | decode_step_malloc (buffer, offset, body->privacy.data, length - offset, 0); |
624 | break; | 667 | break; |
625 | case GNUNET_MESSENGER_KIND_DELETE: | 668 | case GNUNET_MESSENGER_KIND_DELETE: |
626 | decode_step(buffer, offset, &(body->deletion.hash)); | 669 | decode_step (buffer, offset, &(body->deletion.hash)); |
627 | decode_step(buffer, offset, &(body->deletion.delay)); | 670 | decode_step (buffer, offset, &(body->deletion.delay)); |
628 | break; | 671 | break; |
629 | default: | 672 | default: |
630 | *kind = GNUNET_MESSENGER_KIND_UNKNOWN; | 673 | *kind = GNUNET_MESSENGER_KIND_UNKNOWN; |
@@ -634,6 +677,7 @@ decode_message_body (enum GNUNET_MESSENGER_MessageKind *kind, | |||
634 | return padding; | 677 | return padding; |
635 | } | 678 | } |
636 | 679 | ||
680 | |||
637 | int | 681 | int |
638 | decode_message (struct GNUNET_MESSENGER_Message *message, | 682 | decode_message (struct GNUNET_MESSENGER_Message *message, |
639 | uint16_t length, | 683 | uint16_t length, |
@@ -641,19 +685,20 @@ decode_message (struct GNUNET_MESSENGER_Message *message, | |||
641 | int include_header, | 685 | int include_header, |
642 | uint16_t *padding) | 686 | uint16_t *padding) |
643 | { | 687 | { |
644 | GNUNET_assert( | 688 | GNUNET_assert ( |
645 | (message) && | 689 | (message) && |
646 | (buffer) && | 690 | (buffer) && |
647 | (length >= get_message_kind_size(GNUNET_MESSENGER_KIND_UNKNOWN, include_header)) | 691 | (length >= get_message_kind_size (GNUNET_MESSENGER_KIND_UNKNOWN, |
648 | ); | 692 | include_header)) |
693 | ); | ||
649 | 694 | ||
650 | uint16_t offset = 0; | 695 | uint16_t offset = 0; |
651 | 696 | ||
652 | if (GNUNET_YES == include_header) | 697 | if (GNUNET_YES == include_header) |
653 | { | 698 | { |
654 | ssize_t result = GNUNET_IDENTITY_read_signature_from_buffer( | 699 | ssize_t result = GNUNET_IDENTITY_read_signature_from_buffer ( |
655 | &(message->header.signature), buffer, length - offset | 700 | &(message->header.signature), buffer, length - offset |
656 | ); | 701 | ); |
657 | 702 | ||
658 | if (result < 0) | 703 | if (result < 0) |
659 | return GNUNET_NO; | 704 | return GNUNET_NO; |
@@ -663,26 +708,30 @@ decode_message (struct GNUNET_MESSENGER_Message *message, | |||
663 | 708 | ||
664 | const uint16_t count = length - offset; | 709 | const uint16_t count = length - offset; |
665 | 710 | ||
666 | if (count < get_message_kind_size (GNUNET_MESSENGER_KIND_UNKNOWN, include_header)) | 711 | if (count < get_message_kind_size (GNUNET_MESSENGER_KIND_UNKNOWN, |
712 | include_header)) | ||
667 | return GNUNET_NO; | 713 | return GNUNET_NO; |
668 | 714 | ||
669 | kind_t kind; | 715 | kind_t kind; |
670 | 716 | ||
671 | if (GNUNET_YES == include_header) | 717 | if (GNUNET_YES == include_header) |
672 | { | 718 | { |
673 | decode_step(buffer, offset, &(message->header.timestamp)); | 719 | decode_step (buffer, offset, &(message->header.timestamp)); |
674 | decode_step(buffer, offset, &(message->header.sender_id)); | 720 | decode_step (buffer, offset, &(message->header.sender_id)); |
675 | decode_step(buffer, offset, &(message->header.previous)); | 721 | decode_step (buffer, offset, &(message->header.previous)); |
676 | } | 722 | } |
677 | 723 | ||
678 | decode_step(buffer, offset, &kind); | 724 | decode_step (buffer, offset, &kind); |
679 | 725 | ||
680 | message->header.kind = (enum GNUNET_MESSENGER_MessageKind) GNUNET_be32toh(kind); | 726 | message->header.kind = (enum GNUNET_MESSENGER_MessageKind) GNUNET_be32toh ( |
727 | kind); | ||
681 | 728 | ||
682 | if (count < get_message_kind_size (message->header.kind, include_header)) | 729 | if (count < get_message_kind_size (message->header.kind, include_header)) |
683 | return GNUNET_NO; | 730 | return GNUNET_NO; |
684 | 731 | ||
685 | const uint16_t result = decode_message_body (&(message->header.kind), &(message->body), length, buffer, offset); | 732 | const uint16_t result = decode_message_body (&(message->header.kind), |
733 | &(message->body), length, buffer, | ||
734 | offset); | ||
686 | 735 | ||
687 | if (padding) | 736 | if (padding) |
688 | *padding = result; | 737 | *padding = result; |
@@ -690,6 +739,7 @@ decode_message (struct GNUNET_MESSENGER_Message *message, | |||
690 | return GNUNET_YES; | 739 | return GNUNET_YES; |
691 | } | 740 | } |
692 | 741 | ||
742 | |||
693 | static int | 743 | static int |
694 | decode_short_message (struct GNUNET_MESSENGER_ShortMessage *message, | 744 | decode_short_message (struct GNUNET_MESSENGER_ShortMessage *message, |
695 | uint16_t length, | 745 | uint16_t length, |
@@ -701,27 +751,28 @@ decode_short_message (struct GNUNET_MESSENGER_ShortMessage *message, | |||
701 | if (length < get_short_message_size (NULL, GNUNET_NO)) | 751 | if (length < get_short_message_size (NULL, GNUNET_NO)) |
702 | return GNUNET_NO; | 752 | return GNUNET_NO; |
703 | 753 | ||
704 | GNUNET_memcpy(&hash, buffer, sizeof(hash)); | 754 | GNUNET_memcpy (&hash, buffer, sizeof(hash)); |
705 | 755 | ||
706 | GNUNET_CRYPTO_hash( | 756 | GNUNET_CRYPTO_hash ( |
707 | buffer + sizeof(hash), | 757 | buffer + sizeof(hash), |
708 | length - sizeof(hash), | 758 | length - sizeof(hash), |
709 | &expected | 759 | &expected |
710 | ); | 760 | ); |
711 | 761 | ||
712 | if (0 != GNUNET_CRYPTO_hash_cmp(&hash, &expected)) | 762 | if (0 != GNUNET_CRYPTO_hash_cmp (&hash, &expected)) |
713 | return GNUNET_NO; | 763 | return GNUNET_NO; |
714 | 764 | ||
715 | kind_t kind; | 765 | kind_t kind; |
716 | 766 | ||
717 | decode_step(buffer, offset, &kind); | 767 | decode_step (buffer, offset, &kind); |
718 | 768 | ||
719 | message->kind = (enum GNUNET_MESSENGER_MessageKind) GNUNET_be32toh(kind); | 769 | message->kind = (enum GNUNET_MESSENGER_MessageKind) GNUNET_be32toh (kind); |
720 | 770 | ||
721 | if (length < get_short_message_size (message, GNUNET_NO)) | 771 | if (length < get_short_message_size (message, GNUNET_NO)) |
722 | return GNUNET_NO; | 772 | return GNUNET_NO; |
723 | 773 | ||
724 | decode_message_body (&(message->kind), &(message->body), length, buffer, offset); | 774 | decode_message_body (&(message->kind), &(message->body), length, buffer, |
775 | offset); | ||
725 | 776 | ||
726 | if (GNUNET_MESSENGER_KIND_UNKNOWN == message->kind) | 777 | if (GNUNET_MESSENGER_KIND_UNKNOWN == message->kind) |
727 | return GNUNET_NO; | 778 | return GNUNET_NO; |
@@ -729,21 +780,23 @@ decode_short_message (struct GNUNET_MESSENGER_ShortMessage *message, | |||
729 | return GNUNET_YES; | 780 | return GNUNET_YES; |
730 | } | 781 | } |
731 | 782 | ||
783 | |||
732 | void | 784 | void |
733 | hash_message (const struct GNUNET_MESSENGER_Message *message, | 785 | hash_message (const struct GNUNET_MESSENGER_Message *message, |
734 | uint16_t length, | 786 | uint16_t length, |
735 | const char *buffer, | 787 | const char *buffer, |
736 | struct GNUNET_HashCode *hash) | 788 | struct GNUNET_HashCode *hash) |
737 | { | 789 | { |
738 | GNUNET_assert((message) && (buffer) && (hash)); | 790 | GNUNET_assert ((message) && (buffer) && (hash)); |
739 | 791 | ||
740 | const ssize_t offset = GNUNET_IDENTITY_signature_get_length( | 792 | const ssize_t offset = GNUNET_IDENTITY_signature_get_length ( |
741 | &(message->header.signature) | 793 | &(message->header.signature) |
742 | ); | 794 | ); |
743 | 795 | ||
744 | GNUNET_CRYPTO_hash (buffer + offset, length - offset, hash); | 796 | GNUNET_CRYPTO_hash (buffer + offset, length - offset, hash); |
745 | } | 797 | } |
746 | 798 | ||
799 | |||
747 | void | 800 | void |
748 | sign_message (struct GNUNET_MESSENGER_Message *message, | 801 | sign_message (struct GNUNET_MESSENGER_Message *message, |
749 | uint16_t length, | 802 | uint16_t length, |
@@ -751,7 +804,7 @@ sign_message (struct GNUNET_MESSENGER_Message *message, | |||
751 | const struct GNUNET_HashCode *hash, | 804 | const struct GNUNET_HashCode *hash, |
752 | const struct GNUNET_IDENTITY_PrivateKey *key) | 805 | const struct GNUNET_IDENTITY_PrivateKey *key) |
753 | { | 806 | { |
754 | GNUNET_assert((message) && (buffer) && (hash) && (key)); | 807 | GNUNET_assert ((message) && (buffer) && (hash) && (key)); |
755 | 808 | ||
756 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sign message by member: %s\n", | 809 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sign message by member: %s\n", |
757 | GNUNET_h2s (hash)); | 810 | GNUNET_h2s (hash)); |
@@ -761,23 +814,24 @@ sign_message (struct GNUNET_MESSENGER_Message *message, | |||
761 | signature.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE); | 814 | signature.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE); |
762 | signature.purpose.size = htonl (sizeof(signature)); | 815 | signature.purpose.size = htonl (sizeof(signature)); |
763 | 816 | ||
764 | GNUNET_memcpy(&(signature.hash), hash, sizeof(struct GNUNET_HashCode)); | 817 | GNUNET_memcpy (&(signature.hash), hash, sizeof(struct GNUNET_HashCode)); |
765 | GNUNET_IDENTITY_sign(key, &signature, &(message->header.signature)); | 818 | GNUNET_IDENTITY_sign (key, &signature, &(message->header.signature)); |
766 | 819 | ||
767 | message->header.signature.type = key->type; | 820 | message->header.signature.type = key->type; |
768 | 821 | ||
769 | uint16_t offset = 0; | 822 | uint16_t offset = 0; |
770 | encode_step_signature(buffer, offset, &(message->header.signature), length); | 823 | encode_step_signature (buffer, offset, &(message->header.signature), length); |
771 | } | 824 | } |
772 | 825 | ||
826 | |||
773 | void | 827 | void |
774 | sign_message_by_peer (struct GNUNET_MESSENGER_Message *message, | 828 | sign_message_by_peer (struct GNUNET_MESSENGER_Message *message, |
775 | uint16_t length, | 829 | uint16_t length, |
776 | char *buffer, | 830 | char *buffer, |
777 | const struct GNUNET_HashCode *hash, | 831 | const struct GNUNET_HashCode *hash, |
778 | const struct GNUNET_CONFIGURATION_Handle* cfg) | 832 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
779 | { | 833 | { |
780 | GNUNET_assert((message) && (buffer) && (hash) && (cfg)); | 834 | GNUNET_assert ((message) && (buffer) && (hash) && (cfg)); |
781 | 835 | ||
782 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sign message by peer: %s\n", | 836 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sign message by peer: %s\n", |
783 | GNUNET_h2s (hash)); | 837 | GNUNET_h2s (hash)); |
@@ -787,21 +841,24 @@ sign_message_by_peer (struct GNUNET_MESSENGER_Message *message, | |||
787 | signature.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE); | 841 | signature.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE); |
788 | signature.purpose.size = htonl (sizeof(signature)); | 842 | signature.purpose.size = htonl (sizeof(signature)); |
789 | 843 | ||
790 | GNUNET_memcpy(&(signature.hash), hash, sizeof(struct GNUNET_HashCode)); | 844 | GNUNET_memcpy (&(signature.hash), hash, sizeof(struct GNUNET_HashCode)); |
791 | GNUNET_CRYPTO_sign_by_peer_identity(cfg, &signature.purpose, &(message->header.signature.eddsa_signature)); | 845 | GNUNET_CRYPTO_sign_by_peer_identity (cfg, &signature.purpose, |
846 | &(message->header.signature. | ||
847 | eddsa_signature)); | ||
792 | 848 | ||
793 | message->header.signature.type = htonl (GNUNET_IDENTITY_TYPE_EDDSA); | 849 | message->header.signature.type = htonl (GNUNET_IDENTITY_TYPE_EDDSA); |
794 | 850 | ||
795 | uint16_t offset = 0; | 851 | uint16_t offset = 0; |
796 | encode_step_signature(buffer, offset, &(message->header.signature), length); | 852 | encode_step_signature (buffer, offset, &(message->header.signature), length); |
797 | } | 853 | } |
798 | 854 | ||
855 | |||
799 | int | 856 | int |
800 | verify_message (const struct GNUNET_MESSENGER_Message *message, | 857 | verify_message (const struct GNUNET_MESSENGER_Message *message, |
801 | const struct GNUNET_HashCode *hash, | 858 | const struct GNUNET_HashCode *hash, |
802 | const struct GNUNET_IDENTITY_PublicKey *key) | 859 | const struct GNUNET_IDENTITY_PublicKey *key) |
803 | { | 860 | { |
804 | GNUNET_assert((message) && (hash) && (key)); | 861 | GNUNET_assert ((message) && (hash) && (key)); |
805 | 862 | ||
806 | if (key->type != message->header.signature.type) | 863 | if (key->type != message->header.signature.type) |
807 | return GNUNET_SYSERR; | 864 | return GNUNET_SYSERR; |
@@ -811,18 +868,20 @@ verify_message (const struct GNUNET_MESSENGER_Message *message, | |||
811 | signature.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE); | 868 | signature.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE); |
812 | signature.purpose.size = htonl (sizeof(signature)); | 869 | signature.purpose.size = htonl (sizeof(signature)); |
813 | 870 | ||
814 | GNUNET_memcpy(&(signature.hash), hash, sizeof(struct GNUNET_HashCode)); | 871 | GNUNET_memcpy (&(signature.hash), hash, sizeof(struct GNUNET_HashCode)); |
815 | 872 | ||
816 | return GNUNET_IDENTITY_signature_verify (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE, &signature, | 873 | return GNUNET_IDENTITY_signature_verify ( |
817 | &(message->header.signature), key); | 874 | GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE, &signature, |
875 | &(message->header.signature), key); | ||
818 | } | 876 | } |
819 | 877 | ||
878 | |||
820 | int | 879 | int |
821 | verify_message_by_peer (const struct GNUNET_MESSENGER_Message *message, | 880 | verify_message_by_peer (const struct GNUNET_MESSENGER_Message *message, |
822 | const struct GNUNET_HashCode *hash, | 881 | const struct GNUNET_HashCode *hash, |
823 | const struct GNUNET_PeerIdentity *identity) | 882 | const struct GNUNET_PeerIdentity *identity) |
824 | { | 883 | { |
825 | GNUNET_assert((message) && (hash) && (identity)); | 884 | GNUNET_assert ((message) && (hash) && (identity)); |
826 | 885 | ||
827 | if (ntohl (GNUNET_IDENTITY_TYPE_EDDSA) != message->header.signature.type) | 886 | if (ntohl (GNUNET_IDENTITY_TYPE_EDDSA) != message->header.signature.type) |
828 | return GNUNET_SYSERR; | 887 | return GNUNET_SYSERR; |
@@ -832,19 +891,22 @@ verify_message_by_peer (const struct GNUNET_MESSENGER_Message *message, | |||
832 | signature.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE); | 891 | signature.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE); |
833 | signature.purpose.size = htonl (sizeof(signature)); | 892 | signature.purpose.size = htonl (sizeof(signature)); |
834 | 893 | ||
835 | GNUNET_memcpy(&(signature.hash), hash, sizeof(struct GNUNET_HashCode)); | 894 | GNUNET_memcpy (&(signature.hash), hash, sizeof(struct GNUNET_HashCode)); |
836 | 895 | ||
837 | return GNUNET_CRYPTO_verify_peer_identity (GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE, &signature.purpose, | 896 | return GNUNET_CRYPTO_verify_peer_identity ( |
838 | &(message->header.signature.eddsa_signature), identity); | 897 | GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE, &signature.purpose, |
898 | &(message->header.signature. | ||
899 | eddsa_signature), identity); | ||
839 | } | 900 | } |
840 | 901 | ||
902 | |||
841 | int | 903 | int |
842 | encrypt_message (struct GNUNET_MESSENGER_Message *message, | 904 | encrypt_message (struct GNUNET_MESSENGER_Message *message, |
843 | const struct GNUNET_IDENTITY_PublicKey *key) | 905 | const struct GNUNET_IDENTITY_PublicKey *key) |
844 | { | 906 | { |
845 | GNUNET_assert((message) && (key)); | 907 | GNUNET_assert ((message) && (key)); |
846 | 908 | ||
847 | if (GNUNET_YES == is_service_message(message)) | 909 | if (GNUNET_YES == is_service_message (message)) |
848 | return GNUNET_NO; | 910 | return GNUNET_NO; |
849 | 911 | ||
850 | struct GNUNET_MESSENGER_ShortMessage shortened; | 912 | struct GNUNET_MESSENGER_ShortMessage shortened; |
@@ -854,7 +916,7 @@ encrypt_message (struct GNUNET_MESSENGER_Message *message, | |||
854 | const uint16_t length = get_short_message_size (&shortened, GNUNET_YES); | 916 | const uint16_t length = get_short_message_size (&shortened, GNUNET_YES); |
855 | const uint16_t padded_length = calc_padded_length ( | 917 | const uint16_t padded_length = calc_padded_length ( |
856 | length + GNUNET_IDENTITY_ENCRYPT_OVERHEAD_BYTES | 918 | length + GNUNET_IDENTITY_ENCRYPT_OVERHEAD_BYTES |
857 | ); | 919 | ); |
858 | 920 | ||
859 | message->header.kind = GNUNET_MESSENGER_KIND_PRIVATE; | 921 | message->header.kind = GNUNET_MESSENGER_KIND_PRIVATE; |
860 | message->body.privacy.data = GNUNET_malloc (padded_length); | 922 | message->body.privacy.data = GNUNET_malloc (padded_length); |
@@ -862,7 +924,7 @@ encrypt_message (struct GNUNET_MESSENGER_Message *message, | |||
862 | 924 | ||
863 | const uint16_t encoded_length = ( | 925 | const uint16_t encoded_length = ( |
864 | padded_length - GNUNET_IDENTITY_ENCRYPT_OVERHEAD_BYTES | 926 | padded_length - GNUNET_IDENTITY_ENCRYPT_OVERHEAD_BYTES |
865 | ); | 927 | ); |
866 | 928 | ||
867 | encode_short_message (&shortened, encoded_length, message->body.privacy.data); | 929 | encode_short_message (&shortened, encoded_length, message->body.privacy.data); |
868 | 930 | ||
@@ -882,6 +944,7 @@ encrypt_message (struct GNUNET_MESSENGER_Message *message, | |||
882 | return GNUNET_YES; | 944 | return GNUNET_YES; |
883 | } | 945 | } |
884 | 946 | ||
947 | |||
885 | int | 948 | int |
886 | decrypt_message (struct GNUNET_MESSENGER_Message *message, | 949 | decrypt_message (struct GNUNET_MESSENGER_Message *message, |
887 | const struct GNUNET_IDENTITY_PrivateKey *key) | 950 | const struct GNUNET_IDENTITY_PrivateKey *key) |
@@ -900,7 +963,7 @@ decrypt_message (struct GNUNET_MESSENGER_Message *message, | |||
900 | 963 | ||
901 | const uint16_t encoded_length = ( | 964 | const uint16_t encoded_length = ( |
902 | padded_length - GNUNET_IDENTITY_ENCRYPT_OVERHEAD_BYTES | 965 | padded_length - GNUNET_IDENTITY_ENCRYPT_OVERHEAD_BYTES |
903 | ); | 966 | ); |
904 | 967 | ||
905 | if (GNUNET_OK != GNUNET_IDENTITY_decrypt (message->body.privacy.data, | 968 | if (GNUNET_OK != GNUNET_IDENTITY_decrypt (message->body.privacy.data, |
906 | padded_length, | 969 | padded_length, |
@@ -929,6 +992,7 @@ decrypt_message (struct GNUNET_MESSENGER_Message *message, | |||
929 | return GNUNET_YES; | 992 | return GNUNET_YES; |
930 | } | 993 | } |
931 | 994 | ||
995 | |||
932 | struct GNUNET_MQ_Envelope* | 996 | struct GNUNET_MQ_Envelope* |
933 | pack_message (struct GNUNET_MESSENGER_Message *message, | 997 | pack_message (struct GNUNET_MESSENGER_Message *message, |
934 | struct GNUNET_HashCode *hash, | 998 | struct GNUNET_HashCode *hash, |
@@ -936,22 +1000,24 @@ pack_message (struct GNUNET_MESSENGER_Message *message, | |||
936 | int mode, | 1000 | int mode, |
937 | const void *cls) | 1001 | const void *cls) |
938 | { | 1002 | { |
939 | GNUNET_assert(message); | 1003 | GNUNET_assert (message); |
940 | 1004 | ||
941 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Packing message kind=%u and sender: %s\n", | 1005 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
942 | message->header.kind, GNUNET_sh2s(&(message->header.sender_id))); | 1006 | "Packing message kind=%u and sender: %s\n", |
1007 | message->header.kind, GNUNET_sh2s (&(message->header.sender_id))); | ||
943 | 1008 | ||
944 | struct GNUNET_MessageHeader *header; | 1009 | struct GNUNET_MessageHeader *header; |
945 | 1010 | ||
946 | const uint16_t length = get_message_size (message, GNUNET_YES); | 1011 | const uint16_t length = get_message_size (message, GNUNET_YES); |
947 | const uint16_t padded_length = calc_padded_length(length); | 1012 | const uint16_t padded_length = calc_padded_length (length); |
948 | 1013 | ||
949 | struct GNUNET_MQ_Envelope *env; | 1014 | struct GNUNET_MQ_Envelope *env; |
950 | char *buffer; | 1015 | char *buffer; |
951 | 1016 | ||
952 | if (GNUNET_MESSENGER_PACK_MODE_ENVELOPE == mode) | 1017 | if (GNUNET_MESSENGER_PACK_MODE_ENVELOPE == mode) |
953 | { | 1018 | { |
954 | env = GNUNET_MQ_msg_extra(header, padded_length, GNUNET_MESSAGE_TYPE_CADET_CLI); | 1019 | env = GNUNET_MQ_msg_extra (header, padded_length, |
1020 | GNUNET_MESSAGE_TYPE_CADET_CLI); | ||
955 | 1021 | ||
956 | buffer = (char*) &(header[1]); | 1022 | buffer = (char*) &(header[1]); |
957 | } | 1023 | } |
@@ -959,7 +1025,7 @@ pack_message (struct GNUNET_MESSENGER_Message *message, | |||
959 | { | 1025 | { |
960 | env = NULL; | 1026 | env = NULL; |
961 | 1027 | ||
962 | buffer = GNUNET_malloc(padded_length); | 1028 | buffer = GNUNET_malloc (padded_length); |
963 | } | 1029 | } |
964 | 1030 | ||
965 | encode_message (message, padded_length, buffer, GNUNET_YES); | 1031 | encode_message (message, padded_length, buffer, GNUNET_YES); |
@@ -973,11 +1039,12 @@ pack_message (struct GNUNET_MESSENGER_Message *message, | |||
973 | } | 1039 | } |
974 | 1040 | ||
975 | if (GNUNET_MESSENGER_PACK_MODE_ENVELOPE != mode) | 1041 | if (GNUNET_MESSENGER_PACK_MODE_ENVELOPE != mode) |
976 | GNUNET_free(buffer); | 1042 | GNUNET_free (buffer); |
977 | 1043 | ||
978 | return env; | 1044 | return env; |
979 | } | 1045 | } |
980 | 1046 | ||
1047 | |||
981 | int | 1048 | int |
982 | is_peer_message (const struct GNUNET_MESSENGER_Message *message) | 1049 | is_peer_message (const struct GNUNET_MESSENGER_Message *message) |
983 | { | 1050 | { |
@@ -993,10 +1060,11 @@ is_peer_message (const struct GNUNET_MESSENGER_Message *message) | |||
993 | } | 1060 | } |
994 | } | 1061 | } |
995 | 1062 | ||
1063 | |||
996 | int | 1064 | int |
997 | is_service_message (const struct GNUNET_MESSENGER_Message *message) | 1065 | is_service_message (const struct GNUNET_MESSENGER_Message *message) |
998 | { | 1066 | { |
999 | if (GNUNET_YES == is_peer_message(message)) | 1067 | if (GNUNET_YES == is_peer_message (message)) |
1000 | return GNUNET_YES; | 1068 | return GNUNET_YES; |
1001 | 1069 | ||
1002 | switch (message->header.kind) | 1070 | switch (message->header.kind) |
@@ -1036,10 +1104,11 @@ is_service_message (const struct GNUNET_MESSENGER_Message *message) | |||
1036 | } | 1104 | } |
1037 | } | 1105 | } |
1038 | 1106 | ||
1107 | |||
1039 | int | 1108 | int |
1040 | filter_message_sending (const struct GNUNET_MESSENGER_Message *message) | 1109 | filter_message_sending (const struct GNUNET_MESSENGER_Message *message) |
1041 | { | 1110 | { |
1042 | if (GNUNET_YES == is_peer_message(message)) | 1111 | if (GNUNET_YES == is_peer_message (message)) |
1043 | return GNUNET_SYSERR; // Requires signature of peer rather than ego! | 1112 | return GNUNET_SYSERR; // Requires signature of peer rather than ego! |
1044 | 1113 | ||
1045 | switch (message->header.kind) | 1114 | switch (message->header.kind) |
diff --git a/src/messenger/messenger_api_message.h b/src/messenger/messenger_api_message.h index 3544993f9..1d3c12ff3 100644 --- a/src/messenger/messenger_api_message.h +++ b/src/messenger/messenger_api_message.h | |||
@@ -33,7 +33,8 @@ | |||
33 | 33 | ||
34 | #include "gnunet_messenger_service.h" | 34 | #include "gnunet_messenger_service.h" |
35 | 35 | ||
36 | #define GNUNET_MESSENGER_MAX_MESSAGE_SIZE (GNUNET_MAX_MESSAGE_SIZE - GNUNET_MIN_MESSAGE_SIZE) | 36 | #define GNUNET_MESSENGER_MAX_MESSAGE_SIZE (GNUNET_MAX_MESSAGE_SIZE \ |
37 | - GNUNET_MIN_MESSAGE_SIZE) | ||
37 | 38 | ||
38 | #define GNUNET_MESSENGER_PADDING_MIN (sizeof(uint16_t) + sizeof(char)) | 39 | #define GNUNET_MESSENGER_PADDING_MIN (sizeof(uint16_t) + sizeof(char)) |
39 | #define GNUNET_MESSENGER_PADDING_LEVEL0 (512) | 40 | #define GNUNET_MESSENGER_PADDING_LEVEL0 (512) |
@@ -188,7 +189,7 @@ sign_message_by_peer (struct GNUNET_MESSENGER_Message *message, | |||
188 | uint16_t length, | 189 | uint16_t length, |
189 | char *buffer, | 190 | char *buffer, |
190 | const struct GNUNET_HashCode *hash, | 191 | const struct GNUNET_HashCode *hash, |
191 | const struct GNUNET_CONFIGURATION_Handle* cfg); | 192 | const struct GNUNET_CONFIGURATION_Handle *cfg); |
192 | 193 | ||
193 | /** | 194 | /** |
194 | * Verifies the signature of a given <i>message</i> and its <i>hash</i> with a specific | 195 | * Verifies the signature of a given <i>message</i> and its <i>hash</i> with a specific |
@@ -252,7 +253,7 @@ typedef void (*GNUNET_MESSENGER_SignFunction)( | |||
252 | uint16_t length, | 253 | uint16_t length, |
253 | char *buffer, | 254 | char *buffer, |
254 | const struct GNUNET_HashCode *hash | 255 | const struct GNUNET_HashCode *hash |
255 | ); | 256 | ); |
256 | 257 | ||
257 | #define GNUNET_MESSENGER_PACK_MODE_ENVELOPE 0x1 | 258 | #define GNUNET_MESSENGER_PACK_MODE_ENVELOPE 0x1 |
258 | #define GNUNET_MESSENGER_PACK_MODE_UNKNOWN 0x0 | 259 | #define GNUNET_MESSENGER_PACK_MODE_UNKNOWN 0x0 |
diff --git a/src/messenger/messenger_api_message_kind.c b/src/messenger/messenger_api_message_kind.c index 97eaa061b..5a13620cc 100644 --- a/src/messenger/messenger_api_message_kind.c +++ b/src/messenger/messenger_api_message_kind.c | |||
@@ -31,74 +31,84 @@ | |||
31 | struct GNUNET_MESSENGER_Message* | 31 | struct GNUNET_MESSENGER_Message* |
32 | create_message_join (const struct GNUNET_IDENTITY_PrivateKey *key) | 32 | create_message_join (const struct GNUNET_IDENTITY_PrivateKey *key) |
33 | { | 33 | { |
34 | if (!key) | 34 | if (! key) |
35 | return NULL; | 35 | return NULL; |
36 | 36 | ||
37 | struct GNUNET_MESSENGER_Message *message = create_message (GNUNET_MESSENGER_KIND_JOIN); | 37 | struct GNUNET_MESSENGER_Message *message = create_message ( |
38 | GNUNET_MESSENGER_KIND_JOIN); | ||
38 | 39 | ||
39 | if (!message) | 40 | if (! message) |
40 | return NULL; | 41 | return NULL; |
41 | 42 | ||
42 | GNUNET_IDENTITY_key_get_public (key, &(message->body.join.key)); | 43 | GNUNET_IDENTITY_key_get_public (key, &(message->body.join.key)); |
43 | return message; | 44 | return message; |
44 | } | 45 | } |
45 | 46 | ||
47 | |||
46 | struct GNUNET_MESSENGER_Message* | 48 | struct GNUNET_MESSENGER_Message* |
47 | create_message_leave () | 49 | create_message_leave () |
48 | { | 50 | { |
49 | return create_message (GNUNET_MESSENGER_KIND_LEAVE); | 51 | return create_message (GNUNET_MESSENGER_KIND_LEAVE); |
50 | } | 52 | } |
51 | 53 | ||
54 | |||
52 | struct GNUNET_MESSENGER_Message* | 55 | struct GNUNET_MESSENGER_Message* |
53 | create_message_name (const char *name) | 56 | create_message_name (const char *name) |
54 | { | 57 | { |
55 | if (!name) | 58 | if (! name) |
56 | return NULL; | 59 | return NULL; |
57 | 60 | ||
58 | struct GNUNET_MESSENGER_Message *message = create_message (GNUNET_MESSENGER_KIND_NAME); | 61 | struct GNUNET_MESSENGER_Message *message = create_message ( |
62 | GNUNET_MESSENGER_KIND_NAME); | ||
59 | 63 | ||
60 | if (!message) | 64 | if (! message) |
61 | return NULL; | 65 | return NULL; |
62 | 66 | ||
63 | message->body.name.name = GNUNET_strdup(name); | 67 | message->body.name.name = GNUNET_strdup (name); |
64 | return message; | 68 | return message; |
65 | } | 69 | } |
66 | 70 | ||
71 | |||
67 | struct GNUNET_MESSENGER_Message* | 72 | struct GNUNET_MESSENGER_Message* |
68 | create_message_key (const struct GNUNET_IDENTITY_PrivateKey *key) | 73 | create_message_key (const struct GNUNET_IDENTITY_PrivateKey *key) |
69 | { | 74 | { |
70 | if (!key) | 75 | if (! key) |
71 | return NULL; | 76 | return NULL; |
72 | 77 | ||
73 | struct GNUNET_MESSENGER_Message *message = create_message (GNUNET_MESSENGER_KIND_KEY); | 78 | struct GNUNET_MESSENGER_Message *message = create_message ( |
79 | GNUNET_MESSENGER_KIND_KEY); | ||
74 | 80 | ||
75 | if (!message) | 81 | if (! message) |
76 | return NULL; | 82 | return NULL; |
77 | 83 | ||
78 | GNUNET_IDENTITY_key_get_public (key, &(message->body.key.key)); | 84 | GNUNET_IDENTITY_key_get_public (key, &(message->body.key.key)); |
79 | return message; | 85 | return message; |
80 | } | 86 | } |
81 | 87 | ||
88 | |||
82 | struct GNUNET_MESSENGER_Message* | 89 | struct GNUNET_MESSENGER_Message* |
83 | create_message_id (const struct GNUNET_ShortHashCode *unique_id) | 90 | create_message_id (const struct GNUNET_ShortHashCode *unique_id) |
84 | { | 91 | { |
85 | if (!unique_id) | 92 | if (! unique_id) |
86 | return NULL; | 93 | return NULL; |
87 | 94 | ||
88 | struct GNUNET_MESSENGER_Message *message = create_message (GNUNET_MESSENGER_KIND_ID); | 95 | struct GNUNET_MESSENGER_Message *message = create_message ( |
96 | GNUNET_MESSENGER_KIND_ID); | ||
89 | 97 | ||
90 | if (!message) | 98 | if (! message) |
91 | return NULL; | 99 | return NULL; |
92 | 100 | ||
93 | GNUNET_memcpy(&(message->body.id.id), unique_id, sizeof(struct GNUNET_ShortHashCode)); | 101 | GNUNET_memcpy (&(message->body.id.id), unique_id, sizeof(struct |
102 | GNUNET_ShortHashCode)); | ||
94 | 103 | ||
95 | return message; | 104 | return message; |
96 | } | 105 | } |
97 | 106 | ||
107 | |||
98 | struct GNUNET_MESSENGER_Message* | 108 | struct GNUNET_MESSENGER_Message* |
99 | create_message_request (const struct GNUNET_HashCode *hash) | 109 | create_message_request (const struct GNUNET_HashCode *hash) |
100 | { | 110 | { |
101 | if (!hash) | 111 | if (! hash) |
102 | return NULL; | 112 | return NULL; |
103 | 113 | ||
104 | struct GNUNET_HashCode zero; | 114 | struct GNUNET_HashCode zero; |
@@ -107,62 +117,73 @@ create_message_request (const struct GNUNET_HashCode *hash) | |||
107 | if (0 == GNUNET_CRYPTO_hash_cmp (hash, &zero)) | 117 | if (0 == GNUNET_CRYPTO_hash_cmp (hash, &zero)) |
108 | return NULL; | 118 | return NULL; |
109 | 119 | ||
110 | struct GNUNET_MESSENGER_Message *message = create_message (GNUNET_MESSENGER_KIND_REQUEST); | 120 | struct GNUNET_MESSENGER_Message *message = create_message ( |
121 | GNUNET_MESSENGER_KIND_REQUEST); | ||
111 | 122 | ||
112 | if (!message) | 123 | if (! message) |
113 | return NULL; | 124 | return NULL; |
114 | 125 | ||
115 | GNUNET_memcpy(&(message->body.request.hash), hash, sizeof(struct GNUNET_HashCode)); | 126 | GNUNET_memcpy (&(message->body.request.hash), hash, sizeof(struct |
127 | GNUNET_HashCode)); | ||
116 | 128 | ||
117 | return message; | 129 | return message; |
118 | } | 130 | } |
119 | 131 | ||
132 | |||
120 | struct GNUNET_MESSENGER_Message* | 133 | struct GNUNET_MESSENGER_Message* |
121 | create_message_invite (const struct GNUNET_PeerIdentity *door, | 134 | create_message_invite (const struct GNUNET_PeerIdentity *door, |
122 | const struct GNUNET_HashCode *key) | 135 | const struct GNUNET_HashCode *key) |
123 | { | 136 | { |
124 | if ((!door) || (!key)) | 137 | if ((! door) || (! key)) |
125 | return NULL; | 138 | return NULL; |
126 | 139 | ||
127 | struct GNUNET_MESSENGER_Message *message = create_message (GNUNET_MESSENGER_KIND_INVITE); | 140 | struct GNUNET_MESSENGER_Message *message = create_message ( |
141 | GNUNET_MESSENGER_KIND_INVITE); | ||
128 | 142 | ||
129 | if (!message) | 143 | if (! message) |
130 | return NULL; | 144 | return NULL; |
131 | 145 | ||
132 | GNUNET_memcpy(&(message->body.invite.door), door, sizeof(struct GNUNET_PeerIdentity)); | 146 | GNUNET_memcpy (&(message->body.invite.door), door, sizeof(struct |
133 | GNUNET_memcpy(&(message->body.invite.key), key, sizeof(struct GNUNET_HashCode)); | 147 | GNUNET_PeerIdentity)); |
148 | GNUNET_memcpy (&(message->body.invite.key), key, sizeof(struct | ||
149 | GNUNET_HashCode)); | ||
134 | 150 | ||
135 | return message; | 151 | return message; |
136 | } | 152 | } |
137 | 153 | ||
154 | |||
138 | struct GNUNET_MESSENGER_Message* | 155 | struct GNUNET_MESSENGER_Message* |
139 | create_message_text (const char *text) | 156 | create_message_text (const char *text) |
140 | { | 157 | { |
141 | if (!text) | 158 | if (! text) |
142 | return NULL; | 159 | return NULL; |
143 | 160 | ||
144 | struct GNUNET_MESSENGER_Message *message = create_message (GNUNET_MESSENGER_KIND_TEXT); | 161 | struct GNUNET_MESSENGER_Message *message = create_message ( |
162 | GNUNET_MESSENGER_KIND_TEXT); | ||
145 | 163 | ||
146 | if (!message) | 164 | if (! message) |
147 | return NULL; | 165 | return NULL; |
148 | 166 | ||
149 | message->body.text.text = GNUNET_strdup(text); | 167 | message->body.text.text = GNUNET_strdup (text); |
150 | return message; | 168 | return message; |
151 | } | 169 | } |
152 | 170 | ||
171 | |||
153 | struct GNUNET_MESSENGER_Message* | 172 | struct GNUNET_MESSENGER_Message* |
154 | create_message_delete (const struct GNUNET_HashCode *hash, | 173 | create_message_delete (const struct GNUNET_HashCode *hash, |
155 | const struct GNUNET_TIME_Relative delay) | 174 | const struct GNUNET_TIME_Relative delay) |
156 | { | 175 | { |
157 | if (!hash) | 176 | if (! hash) |
158 | return NULL; | 177 | return NULL; |
159 | 178 | ||
160 | struct GNUNET_MESSENGER_Message *message = create_message (GNUNET_MESSENGER_KIND_DELETE); | 179 | struct GNUNET_MESSENGER_Message *message = create_message ( |
180 | GNUNET_MESSENGER_KIND_DELETE); | ||
161 | 181 | ||
162 | if (!message) | 182 | if (! message) |
163 | return NULL; | 183 | return NULL; |
164 | 184 | ||
165 | GNUNET_memcpy(&(message->body.deletion.hash), hash, sizeof(struct GNUNET_HashCode)); | 185 | GNUNET_memcpy (&(message->body.deletion.hash), hash, sizeof(struct |
186 | GNUNET_HashCode)); | ||
166 | message->body.deletion.delay = GNUNET_TIME_relative_hton (delay); | 187 | message->body.deletion.delay = GNUNET_TIME_relative_hton (delay); |
167 | 188 | ||
168 | return message; | 189 | return message; |
diff --git a/src/messenger/messenger_api_peer_store.c b/src/messenger/messenger_api_peer_store.c index f0b9eb0bb..949510960 100644 --- a/src/messenger/messenger_api_peer_store.c +++ b/src/messenger/messenger_api_peer_store.c | |||
@@ -37,25 +37,30 @@ init_peer_store (struct GNUNET_MESSENGER_PeerStore *store) | |||
37 | store->peers = GNUNET_CONTAINER_multishortmap_create (4, GNUNET_NO); | 37 | store->peers = GNUNET_CONTAINER_multishortmap_create (4, GNUNET_NO); |
38 | } | 38 | } |
39 | 39 | ||
40 | |||
40 | static enum GNUNET_GenericReturnValue | 41 | static enum GNUNET_GenericReturnValue |
41 | iterate_destroy_peers (void *cls, const struct GNUNET_ShortHashCode *id, void *value) | 42 | iterate_destroy_peers (void *cls, const struct GNUNET_ShortHashCode *id, |
43 | void *value) | ||
42 | { | 44 | { |
43 | struct GNUNET_PeerIdentity* peer = value; | 45 | struct GNUNET_PeerIdentity *peer = value; |
44 | GNUNET_free (peer); | 46 | GNUNET_free (peer); |
45 | return GNUNET_YES; | 47 | return GNUNET_YES; |
46 | } | 48 | } |
47 | 49 | ||
50 | |||
48 | void | 51 | void |
49 | clear_peer_store (struct GNUNET_MESSENGER_PeerStore *store) | 52 | clear_peer_store (struct GNUNET_MESSENGER_PeerStore *store) |
50 | { | 53 | { |
51 | GNUNET_assert ((store) && (store->peers)); | 54 | GNUNET_assert ((store) && (store->peers)); |
52 | 55 | ||
53 | GNUNET_CONTAINER_multishortmap_iterate (store->peers, iterate_destroy_peers, NULL); | 56 | GNUNET_CONTAINER_multishortmap_iterate (store->peers, iterate_destroy_peers, |
57 | NULL); | ||
54 | GNUNET_CONTAINER_multishortmap_destroy (store->peers); | 58 | GNUNET_CONTAINER_multishortmap_destroy (store->peers); |
55 | 59 | ||
56 | store->peers = NULL; | 60 | store->peers = NULL; |
57 | } | 61 | } |
58 | 62 | ||
63 | |||
59 | struct GNUNET_MESSENGER_ClosureVerifyPeer | 64 | struct GNUNET_MESSENGER_ClosureVerifyPeer |
60 | { | 65 | { |
61 | const struct GNUNET_MESSENGER_Message *message; | 66 | const struct GNUNET_MESSENGER_Message *message; |
@@ -64,12 +69,14 @@ struct GNUNET_MESSENGER_ClosureVerifyPeer | |||
64 | }; | 69 | }; |
65 | 70 | ||
66 | static enum GNUNET_GenericReturnValue | 71 | static enum GNUNET_GenericReturnValue |
67 | verify_store_peer(void *cls, const struct GNUNET_ShortHashCode *id, void *value) | 72 | verify_store_peer (void *cls, const struct GNUNET_ShortHashCode *id, |
73 | void *value) | ||
68 | { | 74 | { |
69 | struct GNUNET_MESSENGER_ClosureVerifyPeer *verify = cls; | 75 | struct GNUNET_MESSENGER_ClosureVerifyPeer *verify = cls; |
70 | struct GNUNET_PeerIdentity* peer = value; | 76 | struct GNUNET_PeerIdentity *peer = value; |
71 | 77 | ||
72 | if ((peer) && (GNUNET_OK == verify_message_by_peer (verify->message, verify->hash, peer))) | 78 | if ((peer) && (GNUNET_OK == verify_message_by_peer (verify->message, |
79 | verify->hash, peer))) | ||
73 | { | 80 | { |
74 | verify->sender = peer; | 81 | verify->sender = peer; |
75 | return GNUNET_NO; | 82 | return GNUNET_NO; |
@@ -78,6 +85,7 @@ verify_store_peer(void *cls, const struct GNUNET_ShortHashCode *id, void *value) | |||
78 | return GNUNET_YES; | 85 | return GNUNET_YES; |
79 | } | 86 | } |
80 | 87 | ||
88 | |||
81 | struct GNUNET_PeerIdentity* | 89 | struct GNUNET_PeerIdentity* |
82 | get_store_peer_of (struct GNUNET_MESSENGER_PeerStore *store, | 90 | get_store_peer_of (struct GNUNET_MESSENGER_PeerStore *store, |
83 | const struct GNUNET_MESSENGER_Message *message, | 91 | const struct GNUNET_MESSENGER_Message *message, |
@@ -89,7 +97,8 @@ get_store_peer_of (struct GNUNET_MESSENGER_PeerStore *store, | |||
89 | return NULL; | 97 | return NULL; |
90 | 98 | ||
91 | if ((GNUNET_MESSENGER_KIND_PEER == message->header.kind) && | 99 | if ((GNUNET_MESSENGER_KIND_PEER == message->header.kind) && |
92 | (GNUNET_OK == verify_message_by_peer (message, hash, &(message->body.peer.peer)))) | 100 | (GNUNET_OK == verify_message_by_peer (message, hash, |
101 | &(message->body.peer.peer)))) | ||
93 | { | 102 | { |
94 | struct GNUNET_ShortHashCode peer_id; | 103 | struct GNUNET_ShortHashCode peer_id; |
95 | convert_peer_identity_to_id (&(message->body.peer.peer), &peer_id); | 104 | convert_peer_identity_to_id (&(message->body.peer.peer), &peer_id); |
@@ -97,7 +106,8 @@ get_store_peer_of (struct GNUNET_MESSENGER_PeerStore *store, | |||
97 | if (0 == GNUNET_memcmp (&peer_id, &(message->header.sender_id))) | 106 | if (0 == GNUNET_memcmp (&peer_id, &(message->header.sender_id))) |
98 | update_store_peer (store, &(message->body.peer.peer)); | 107 | update_store_peer (store, &(message->body.peer.peer)); |
99 | else | 108 | else |
100 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Sender id does not match peer identity\n"); | 109 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
110 | "Sender id does not match peer identity\n"); | ||
101 | } | 111 | } |
102 | 112 | ||
103 | struct GNUNET_MESSENGER_ClosureVerifyPeer verify; | 113 | struct GNUNET_MESSENGER_ClosureVerifyPeer verify; |
@@ -105,12 +115,14 @@ get_store_peer_of (struct GNUNET_MESSENGER_PeerStore *store, | |||
105 | verify.hash = hash; | 115 | verify.hash = hash; |
106 | verify.sender = NULL; | 116 | verify.sender = NULL; |
107 | 117 | ||
108 | GNUNET_CONTAINER_multishortmap_get_multiple (store->peers, &(message->header.sender_id), | 118 | GNUNET_CONTAINER_multishortmap_get_multiple (store->peers, |
119 | &(message->header.sender_id), | ||
109 | verify_store_peer, &verify); | 120 | verify_store_peer, &verify); |
110 | 121 | ||
111 | return verify.sender; | 122 | return verify.sender; |
112 | } | 123 | } |
113 | 124 | ||
125 | |||
114 | struct GNUNET_MESSENGER_ClosureFindPeer | 126 | struct GNUNET_MESSENGER_ClosureFindPeer |
115 | { | 127 | { |
116 | const struct GNUNET_PeerIdentity *requested; | 128 | const struct GNUNET_PeerIdentity *requested; |
@@ -118,10 +130,10 @@ struct GNUNET_MESSENGER_ClosureFindPeer | |||
118 | }; | 130 | }; |
119 | 131 | ||
120 | static enum GNUNET_GenericReturnValue | 132 | static enum GNUNET_GenericReturnValue |
121 | find_store_peer(void *cls, const struct GNUNET_ShortHashCode *id, void *value) | 133 | find_store_peer (void *cls, const struct GNUNET_ShortHashCode *id, void *value) |
122 | { | 134 | { |
123 | struct GNUNET_MESSENGER_ClosureFindPeer *find = cls; | 135 | struct GNUNET_MESSENGER_ClosureFindPeer *find = cls; |
124 | struct GNUNET_PeerIdentity* peer = value; | 136 | struct GNUNET_PeerIdentity *peer = value; |
125 | 137 | ||
126 | if ((peer) && (0 == GNUNET_memcmp (find->requested, peer))) | 138 | if ((peer) && (0 == GNUNET_memcmp (find->requested, peer))) |
127 | { | 139 | { |
@@ -132,9 +144,10 @@ find_store_peer(void *cls, const struct GNUNET_ShortHashCode *id, void *value) | |||
132 | return GNUNET_YES; | 144 | return GNUNET_YES; |
133 | } | 145 | } |
134 | 146 | ||
147 | |||
135 | void | 148 | void |
136 | update_store_peer (struct GNUNET_MESSENGER_PeerStore *store, | 149 | update_store_peer (struct GNUNET_MESSENGER_PeerStore *store, |
137 | const struct GNUNET_PeerIdentity* peer) | 150 | const struct GNUNET_PeerIdentity *peer) |
138 | { | 151 | { |
139 | GNUNET_assert ((store) && (store->peers) && (peer)); | 152 | GNUNET_assert ((store) && (store->peers) && (peer)); |
140 | 153 | ||
@@ -151,11 +164,13 @@ update_store_peer (struct GNUNET_MESSENGER_PeerStore *store, | |||
151 | if (find.match) | 164 | if (find.match) |
152 | return; | 165 | return; |
153 | 166 | ||
154 | struct GNUNET_PeerIdentity* copy = GNUNET_memdup (peer, sizeof (struct GNUNET_PeerIdentity)); | 167 | struct GNUNET_PeerIdentity *copy = GNUNET_memdup (peer, sizeof (struct |
168 | GNUNET_PeerIdentity)); | ||
155 | GNUNET_CONTAINER_multishortmap_put (store->peers, &peer_id, copy, | 169 | GNUNET_CONTAINER_multishortmap_put (store->peers, &peer_id, copy, |
156 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 170 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
157 | } | 171 | } |
158 | 172 | ||
173 | |||
159 | void | 174 | void |
160 | remove_store_peer (struct GNUNET_MESSENGER_PeerStore *store, | 175 | remove_store_peer (struct GNUNET_MESSENGER_PeerStore *store, |
161 | const struct GNUNET_PeerIdentity *peer) | 176 | const struct GNUNET_PeerIdentity *peer) |
@@ -172,9 +187,11 @@ remove_store_peer (struct GNUNET_MESSENGER_PeerStore *store, | |||
172 | GNUNET_CONTAINER_multishortmap_get_multiple (store->peers, &peer_id, | 187 | GNUNET_CONTAINER_multishortmap_get_multiple (store->peers, &peer_id, |
173 | find_store_peer, &find); | 188 | find_store_peer, &find); |
174 | 189 | ||
175 | if (!find.match) | 190 | if (! find.match) |
176 | return; | 191 | return; |
177 | 192 | ||
178 | if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_remove (store->peers, &peer_id, find.match)) | 193 | if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_remove (store->peers, |
179 | GNUNET_free(find.match); | 194 | &peer_id, |
195 | find.match)) | ||
196 | GNUNET_free (find.match); | ||
180 | } | 197 | } |
diff --git a/src/messenger/messenger_api_peer_store.h b/src/messenger/messenger_api_peer_store.h index 526a1ca57..f4f948cb9 100644 --- a/src/messenger/messenger_api_peer_store.h +++ b/src/messenger/messenger_api_peer_store.h | |||
@@ -78,7 +78,7 @@ get_store_peer_of (struct GNUNET_MESSENGER_PeerStore *store, | |||
78 | */ | 78 | */ |
79 | void | 79 | void |
80 | update_store_peer (struct GNUNET_MESSENGER_PeerStore *store, | 80 | update_store_peer (struct GNUNET_MESSENGER_PeerStore *store, |
81 | const struct GNUNET_PeerIdentity* peer); | 81 | const struct GNUNET_PeerIdentity *peer); |
82 | 82 | ||
83 | /** | 83 | /** |
84 | * Removes a <i>peer</i> identity from the <i>store</i> entirely. | 84 | * Removes a <i>peer</i> identity from the <i>store</i> entirely. |
diff --git a/src/messenger/messenger_api_queue_messages.c b/src/messenger/messenger_api_queue_messages.c index bd99698cd..415fa6a3e 100644 --- a/src/messenger/messenger_api_queue_messages.c +++ b/src/messenger/messenger_api_queue_messages.c | |||
@@ -34,6 +34,7 @@ init_queue_messages (struct GNUNET_MESSENGER_QueueMessages *messages) | |||
34 | messages->tail = NULL; | 34 | messages->tail = NULL; |
35 | } | 35 | } |
36 | 36 | ||
37 | |||
37 | void | 38 | void |
38 | clear_queue_messages (struct GNUNET_MESSENGER_QueueMessages *messages) | 39 | clear_queue_messages (struct GNUNET_MESSENGER_QueueMessages *messages) |
39 | { | 40 | { |
@@ -55,6 +56,7 @@ clear_queue_messages (struct GNUNET_MESSENGER_QueueMessages *messages) | |||
55 | messages->tail = NULL; | 56 | messages->tail = NULL; |
56 | } | 57 | } |
57 | 58 | ||
59 | |||
58 | void | 60 | void |
59 | enqueue_to_messages (struct GNUNET_MESSENGER_QueueMessages *messages, | 61 | enqueue_to_messages (struct GNUNET_MESSENGER_QueueMessages *messages, |
60 | const struct GNUNET_IDENTITY_PrivateKey *sender, | 62 | const struct GNUNET_IDENTITY_PrivateKey *sender, |
@@ -62,9 +64,10 @@ enqueue_to_messages (struct GNUNET_MESSENGER_QueueMessages *messages, | |||
62 | { | 64 | { |
63 | GNUNET_assert ((messages) && (message)); | 65 | GNUNET_assert ((messages) && (message)); |
64 | 66 | ||
65 | struct GNUNET_MESSENGER_QueueMessage *element = GNUNET_new (struct GNUNET_MESSENGER_QueueMessage); | 67 | struct GNUNET_MESSENGER_QueueMessage *element = GNUNET_new (struct |
68 | GNUNET_MESSENGER_QueueMessage); | ||
66 | 69 | ||
67 | if (!element) | 70 | if (! element) |
68 | return; | 71 | return; |
69 | 72 | ||
70 | element->message = copy_message (message); | 73 | element->message = copy_message (message); |
@@ -72,7 +75,7 @@ enqueue_to_messages (struct GNUNET_MESSENGER_QueueMessages *messages, | |||
72 | if (sender) | 75 | if (sender) |
73 | GNUNET_memcpy (&(element->sender), sender, sizeof (element->sender)); | 76 | GNUNET_memcpy (&(element->sender), sender, sizeof (element->sender)); |
74 | 77 | ||
75 | if (!element->message) | 78 | if (! element->message) |
76 | { | 79 | { |
77 | GNUNET_free (element); | 80 | GNUNET_free (element); |
78 | return; | 81 | return; |
@@ -81,6 +84,7 @@ enqueue_to_messages (struct GNUNET_MESSENGER_QueueMessages *messages, | |||
81 | GNUNET_CONTAINER_DLL_insert_tail (messages->head, messages->tail, element); | 84 | GNUNET_CONTAINER_DLL_insert_tail (messages->head, messages->tail, element); |
82 | } | 85 | } |
83 | 86 | ||
87 | |||
84 | struct GNUNET_MESSENGER_Message* | 88 | struct GNUNET_MESSENGER_Message* |
85 | dequeue_from_messages (struct GNUNET_MESSENGER_QueueMessages *messages, | 89 | dequeue_from_messages (struct GNUNET_MESSENGER_QueueMessages *messages, |
86 | struct GNUNET_IDENTITY_PrivateKey *sender) | 90 | struct GNUNET_IDENTITY_PrivateKey *sender) |
@@ -89,7 +93,7 @@ dequeue_from_messages (struct GNUNET_MESSENGER_QueueMessages *messages, | |||
89 | 93 | ||
90 | struct GNUNET_MESSENGER_QueueMessage *element = messages->head; | 94 | struct GNUNET_MESSENGER_QueueMessage *element = messages->head; |
91 | 95 | ||
92 | if (!element) | 96 | if (! element) |
93 | return NULL; | 97 | return NULL; |
94 | 98 | ||
95 | struct GNUNET_MESSENGER_Message *message = element->message; | 99 | struct GNUNET_MESSENGER_Message *message = element->message; |
diff --git a/src/messenger/messenger_api_room.c b/src/messenger/messenger_api_room.c index fb4e11fd4..2c8b27bf8 100644 --- a/src/messenger/messenger_api_room.c +++ b/src/messenger/messenger_api_room.c | |||
@@ -32,14 +32,15 @@ struct GNUNET_MESSENGER_Room* | |||
32 | create_room (struct GNUNET_MESSENGER_Handle *handle, | 32 | create_room (struct GNUNET_MESSENGER_Handle *handle, |
33 | const struct GNUNET_HashCode *key) | 33 | const struct GNUNET_HashCode *key) |
34 | { | 34 | { |
35 | GNUNET_assert((handle) && (key)); | 35 | GNUNET_assert ((handle) && (key)); |
36 | 36 | ||
37 | struct GNUNET_MESSENGER_Room *room = GNUNET_new(struct GNUNET_MESSENGER_Room); | 37 | struct GNUNET_MESSENGER_Room *room = GNUNET_new (struct |
38 | GNUNET_MESSENGER_Room); | ||
38 | 39 | ||
39 | room->handle = handle; | 40 | room->handle = handle; |
40 | GNUNET_memcpy(&(room->key), key, sizeof(*key)); | 41 | GNUNET_memcpy (&(room->key), key, sizeof(*key)); |
41 | 42 | ||
42 | memset(&(room->last_message), 0, sizeof(room->last_message)); | 43 | memset (&(room->last_message), 0, sizeof(room->last_message)); |
43 | 44 | ||
44 | room->opened = GNUNET_NO; | 45 | room->opened = GNUNET_NO; |
45 | room->use_handle_name = GNUNET_YES; | 46 | room->use_handle_name = GNUNET_YES; |
@@ -55,6 +56,7 @@ create_room (struct GNUNET_MESSENGER_Handle *handle, | |||
55 | return room; | 56 | return room; |
56 | } | 57 | } |
57 | 58 | ||
59 | |||
58 | static int | 60 | static int |
59 | iterate_destroy_message (void *cls, | 61 | iterate_destroy_message (void *cls, |
60 | const struct GNUNET_HashCode *key, | 62 | const struct GNUNET_HashCode *key, |
@@ -63,22 +65,24 @@ iterate_destroy_message (void *cls, | |||
63 | struct GNUNET_MESSENGER_RoomMessageEntry *entry = value; | 65 | struct GNUNET_MESSENGER_RoomMessageEntry *entry = value; |
64 | 66 | ||
65 | destroy_message (entry->message); | 67 | destroy_message (entry->message); |
66 | GNUNET_free(entry); | 68 | GNUNET_free (entry); |
67 | 69 | ||
68 | return GNUNET_YES; | 70 | return GNUNET_YES; |
69 | } | 71 | } |
70 | 72 | ||
73 | |||
71 | void | 74 | void |
72 | destroy_room (struct GNUNET_MESSENGER_Room *room) | 75 | destroy_room (struct GNUNET_MESSENGER_Room *room) |
73 | { | 76 | { |
74 | GNUNET_assert(room); | 77 | GNUNET_assert (room); |
75 | 78 | ||
76 | clear_queue_messages(&(room->queue)); | 79 | clear_queue_messages (&(room->queue)); |
77 | clear_list_tunnels (&(room->entries)); | 80 | clear_list_tunnels (&(room->entries)); |
78 | 81 | ||
79 | if (room->messages) | 82 | if (room->messages) |
80 | { | 83 | { |
81 | GNUNET_CONTAINER_multihashmap_iterate (room->messages, iterate_destroy_message, NULL); | 84 | GNUNET_CONTAINER_multihashmap_iterate (room->messages, |
85 | iterate_destroy_message, NULL); | ||
82 | 86 | ||
83 | GNUNET_CONTAINER_multihashmap_destroy (room->messages); | 87 | GNUNET_CONTAINER_multihashmap_destroy (room->messages); |
84 | } | 88 | } |
@@ -87,17 +91,18 @@ destroy_room (struct GNUNET_MESSENGER_Room *room) | |||
87 | GNUNET_CONTAINER_multishortmap_destroy (room->members); | 91 | GNUNET_CONTAINER_multishortmap_destroy (room->members); |
88 | 92 | ||
89 | if (room->sender_id) | 93 | if (room->sender_id) |
90 | GNUNET_free(room->sender_id); | 94 | GNUNET_free (room->sender_id); |
91 | 95 | ||
92 | GNUNET_free(room); | 96 | GNUNET_free (room); |
93 | } | 97 | } |
94 | 98 | ||
99 | |||
95 | enum GNUNET_GenericReturnValue | 100 | enum GNUNET_GenericReturnValue |
96 | is_room_available (const struct GNUNET_MESSENGER_Room *room) | 101 | is_room_available (const struct GNUNET_MESSENGER_Room *room) |
97 | { | 102 | { |
98 | GNUNET_assert (room); | 103 | GNUNET_assert (room); |
99 | 104 | ||
100 | if (!get_room_sender_id(room)) | 105 | if (! get_room_sender_id (room)) |
101 | return GNUNET_NO; | 106 | return GNUNET_NO; |
102 | 107 | ||
103 | if ((GNUNET_YES == room->opened) || (room->entries.head)) | 108 | if ((GNUNET_YES == room->opened) || (room->entries.head)) |
@@ -106,6 +111,7 @@ is_room_available (const struct GNUNET_MESSENGER_Room *room) | |||
106 | return GNUNET_NO; | 111 | return GNUNET_NO; |
107 | } | 112 | } |
108 | 113 | ||
114 | |||
109 | const struct GNUNET_ShortHashCode* | 115 | const struct GNUNET_ShortHashCode* |
110 | get_room_sender_id (const struct GNUNET_MESSENGER_Room *room) | 116 | get_room_sender_id (const struct GNUNET_MESSENGER_Room *room) |
111 | { | 117 | { |
@@ -114,15 +120,17 @@ get_room_sender_id (const struct GNUNET_MESSENGER_Room *room) | |||
114 | return room->sender_id; | 120 | return room->sender_id; |
115 | } | 121 | } |
116 | 122 | ||
123 | |||
117 | void | 124 | void |
118 | set_room_sender_id (struct GNUNET_MESSENGER_Room *room, | 125 | set_room_sender_id (struct GNUNET_MESSENGER_Room *room, |
119 | const struct GNUNET_ShortHashCode *id) | 126 | const struct GNUNET_ShortHashCode *id) |
120 | { | 127 | { |
121 | GNUNET_assert (room); | 128 | GNUNET_assert (room); |
122 | 129 | ||
123 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Set member id for room: %s\n", GNUNET_h2s (&(room->key))); | 130 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Set member id for room: %s\n", |
131 | GNUNET_h2s (&(room->key))); | ||
124 | 132 | ||
125 | if (!id) | 133 | if (! id) |
126 | { | 134 | { |
127 | if (room->sender_id) | 135 | if (room->sender_id) |
128 | GNUNET_free (room->sender_id); | 136 | GNUNET_free (room->sender_id); |
@@ -131,76 +139,92 @@ set_room_sender_id (struct GNUNET_MESSENGER_Room *room, | |||
131 | return; | 139 | return; |
132 | } | 140 | } |
133 | 141 | ||
134 | if (!room->sender_id) | 142 | if (! room->sender_id) |
135 | room->sender_id = GNUNET_new (struct GNUNET_ShortHashCode); | 143 | room->sender_id = GNUNET_new (struct GNUNET_ShortHashCode); |
136 | 144 | ||
137 | GNUNET_memcpy (room->sender_id, id, sizeof(struct GNUNET_ShortHashCode)); | 145 | GNUNET_memcpy (room->sender_id, id, sizeof(struct GNUNET_ShortHashCode)); |
138 | } | 146 | } |
139 | 147 | ||
148 | |||
140 | const struct GNUNET_MESSENGER_Message* | 149 | const struct GNUNET_MESSENGER_Message* |
141 | get_room_message (const struct GNUNET_MESSENGER_Room *room, | 150 | get_room_message (const struct GNUNET_MESSENGER_Room *room, |
142 | const struct GNUNET_HashCode *hash) | 151 | const struct GNUNET_HashCode *hash) |
143 | { | 152 | { |
144 | GNUNET_assert((room) && (hash)); | 153 | GNUNET_assert ((room) && (hash)); |
145 | 154 | ||
146 | struct GNUNET_MESSENGER_RoomMessageEntry *entry = GNUNET_CONTAINER_multihashmap_get ( | 155 | struct GNUNET_MESSENGER_RoomMessageEntry *entry = |
156 | GNUNET_CONTAINER_multihashmap_get ( | ||
147 | room->messages, hash | 157 | room->messages, hash |
148 | ); | 158 | ); |
149 | 159 | ||
150 | return (entry? entry->message : NULL); | 160 | return (entry? entry->message : NULL); |
151 | } | 161 | } |
152 | 162 | ||
163 | |||
153 | struct GNUNET_MESSENGER_Contact* | 164 | struct GNUNET_MESSENGER_Contact* |
154 | get_room_sender (const struct GNUNET_MESSENGER_Room *room, | 165 | get_room_sender (const struct GNUNET_MESSENGER_Room *room, |
155 | const struct GNUNET_HashCode *hash) | 166 | const struct GNUNET_HashCode *hash) |
156 | { | 167 | { |
157 | GNUNET_assert((room) && (hash)); | 168 | GNUNET_assert ((room) && (hash)); |
158 | 169 | ||
159 | struct GNUNET_MESSENGER_RoomMessageEntry *entry = GNUNET_CONTAINER_multihashmap_get ( | 170 | struct GNUNET_MESSENGER_RoomMessageEntry *entry = |
171 | GNUNET_CONTAINER_multihashmap_get ( | ||
160 | room->messages, hash | 172 | room->messages, hash |
161 | ); | 173 | ); |
162 | 174 | ||
163 | return (entry? entry->sender : NULL); | 175 | return (entry? entry->sender : NULL); |
164 | } | 176 | } |
165 | 177 | ||
178 | |||
166 | static struct GNUNET_MESSENGER_Contact* | 179 | static struct GNUNET_MESSENGER_Contact* |
167 | handle_join_message (struct GNUNET_MESSENGER_Room *room, | 180 | handle_join_message (struct GNUNET_MESSENGER_Room *room, |
168 | struct GNUNET_MESSENGER_Contact *sender, | 181 | struct GNUNET_MESSENGER_Contact *sender, |
169 | const struct GNUNET_MESSENGER_Message *message, | 182 | const struct GNUNET_MESSENGER_Message *message, |
170 | const struct GNUNET_HashCode *hash) | 183 | const struct GNUNET_HashCode *hash) |
171 | { | 184 | { |
172 | if (!sender) | 185 | if (! sender) |
173 | { | 186 | { |
174 | struct GNUNET_MESSENGER_ContactStore *store = get_handle_contact_store(room->handle); | 187 | struct GNUNET_MESSENGER_ContactStore *store = get_handle_contact_store ( |
188 | room->handle); | ||
175 | struct GNUNET_HashCode context; | 189 | struct GNUNET_HashCode context; |
176 | 190 | ||
177 | get_context_from_member(&(room->key), &(message->header.sender_id), &context); | 191 | get_context_from_member (&(room->key), &(message->header.sender_id), |
192 | &context); | ||
178 | 193 | ||
179 | sender = get_store_contact(store, &context, &(message->body.join.key)); | 194 | sender = get_store_contact (store, &context, &(message->body.join.key)); |
180 | } | 195 | } |
181 | 196 | ||
182 | if ((GNUNET_YES != GNUNET_CONTAINER_multishortmap_contains_value(room->members, &(message->header.sender_id), sender)) && | 197 | if ((GNUNET_YES != GNUNET_CONTAINER_multishortmap_contains_value ( |
183 | (GNUNET_OK == GNUNET_CONTAINER_multishortmap_put(room->members, &(message->header.sender_id), sender, | 198 | room->members, &(message->header.sender_id), sender)) && |
184 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE))) | 199 | (GNUNET_OK == GNUNET_CONTAINER_multishortmap_put (room->members, |
185 | increase_contact_rc(sender); | 200 | &(message->header. |
201 | sender_id), sender, | ||
202 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE))) | ||
203 | increase_contact_rc (sender); | ||
186 | 204 | ||
187 | return sender; | 205 | return sender; |
188 | } | 206 | } |
189 | 207 | ||
208 | |||
190 | static void | 209 | static void |
191 | handle_leave_message (struct GNUNET_MESSENGER_Room *room, | 210 | handle_leave_message (struct GNUNET_MESSENGER_Room *room, |
192 | struct GNUNET_MESSENGER_Contact *sender, | 211 | struct GNUNET_MESSENGER_Contact *sender, |
193 | const struct GNUNET_MESSENGER_Message *message, | 212 | const struct GNUNET_MESSENGER_Message *message, |
194 | const struct GNUNET_HashCode *hash) | 213 | const struct GNUNET_HashCode *hash) |
195 | { | 214 | { |
196 | if ((!sender) || | 215 | if ((! sender) || |
197 | (GNUNET_YES != GNUNET_CONTAINER_multishortmap_remove(room->members, &(message->header.sender_id), sender))) | 216 | (GNUNET_YES != GNUNET_CONTAINER_multishortmap_remove (room->members, |
217 | &(message->header. | ||
218 | sender_id), | ||
219 | sender))) | ||
198 | return; | 220 | return; |
199 | 221 | ||
200 | if (GNUNET_YES == decrease_contact_rc(sender)) | 222 | if (GNUNET_YES == decrease_contact_rc (sender)) |
201 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "A contact does not share any room with you anymore!\n"); | 223 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
224 | "A contact does not share any room with you anymore!\n"); | ||
202 | } | 225 | } |
203 | 226 | ||
227 | |||
204 | static void | 228 | static void |
205 | handle_name_message (struct GNUNET_MESSENGER_Room *room, | 229 | handle_name_message (struct GNUNET_MESSENGER_Room *room, |
206 | struct GNUNET_MESSENGER_Contact *sender, | 230 | struct GNUNET_MESSENGER_Contact *sender, |
@@ -210,37 +234,44 @@ handle_name_message (struct GNUNET_MESSENGER_Room *room, | |||
210 | { | 234 | { |
211 | if (GNUNET_MESSENGER_FLAG_SENT & flags) | 235 | if (GNUNET_MESSENGER_FLAG_SENT & flags) |
212 | { | 236 | { |
213 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Set rule for using handle name in room: %s\n", GNUNET_h2s (&(room->key))); | 237 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
238 | "Set rule for using handle name in room: %s\n", | ||
239 | GNUNET_h2s (&(room->key))); | ||
214 | 240 | ||
215 | const char* handle_name = get_handle_name (room->handle); | 241 | const char *handle_name = get_handle_name (room->handle); |
216 | 242 | ||
217 | if ((handle_name) && (0 == strcmp (handle_name, message->body.name.name))) | 243 | if ((handle_name) && (0 == strcmp (handle_name, message->body.name.name))) |
218 | room->use_handle_name = GNUNET_YES; | 244 | room->use_handle_name = GNUNET_YES; |
219 | } | 245 | } |
220 | 246 | ||
221 | if (!sender) | 247 | if (! sender) |
222 | return; | 248 | return; |
223 | 249 | ||
224 | set_contact_name (sender, message->body.name.name); | 250 | set_contact_name (sender, message->body.name.name); |
225 | } | 251 | } |
226 | 252 | ||
253 | |||
227 | static void | 254 | static void |
228 | handle_key_message (struct GNUNET_MESSENGER_Room *room, | 255 | handle_key_message (struct GNUNET_MESSENGER_Room *room, |
229 | struct GNUNET_MESSENGER_Contact *sender, | 256 | struct GNUNET_MESSENGER_Contact *sender, |
230 | const struct GNUNET_MESSENGER_Message *message, | 257 | const struct GNUNET_MESSENGER_Message *message, |
231 | const struct GNUNET_HashCode *hash) | 258 | const struct GNUNET_HashCode *hash) |
232 | { | 259 | { |
233 | if (!sender) | 260 | if (! sender) |
234 | return; | 261 | return; |
235 | 262 | ||
236 | struct GNUNET_HashCode context; | 263 | struct GNUNET_HashCode context; |
237 | get_context_from_member(&(room->key), &(message->header.sender_id), &context); | 264 | get_context_from_member (&(room->key), &(message->header.sender_id), |
265 | &context); | ||
238 | 266 | ||
239 | struct GNUNET_MESSENGER_ContactStore *store = get_handle_contact_store(room->handle); | 267 | struct GNUNET_MESSENGER_ContactStore *store = get_handle_contact_store ( |
268 | room->handle); | ||
240 | 269 | ||
241 | update_store_contact(store, sender, &context, &context, &(message->body.key.key)); | 270 | update_store_contact (store, sender, &context, &context, |
271 | &(message->body.key.key)); | ||
242 | } | 272 | } |
243 | 273 | ||
274 | |||
244 | static void | 275 | static void |
245 | handle_id_message (struct GNUNET_MESSENGER_Room *room, | 276 | handle_id_message (struct GNUNET_MESSENGER_Room *room, |
246 | struct GNUNET_MESSENGER_Contact *sender, | 277 | struct GNUNET_MESSENGER_Contact *sender, |
@@ -251,21 +282,30 @@ handle_id_message (struct GNUNET_MESSENGER_Room *room, | |||
251 | if (GNUNET_MESSENGER_FLAG_SENT & flags) | 282 | if (GNUNET_MESSENGER_FLAG_SENT & flags) |
252 | set_room_sender_id (room, &(message->body.id.id)); | 283 | set_room_sender_id (room, &(message->body.id.id)); |
253 | 284 | ||
254 | if ((!sender) || | 285 | if ((! sender) || |
255 | (GNUNET_YES != GNUNET_CONTAINER_multishortmap_remove(room->members, &(message->header.sender_id), sender)) || | 286 | (GNUNET_YES != GNUNET_CONTAINER_multishortmap_remove (room->members, |
256 | (GNUNET_OK != GNUNET_CONTAINER_multishortmap_put(room->members, &(message->body.id.id), sender, | 287 | &(message->header. |
257 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE))) | 288 | sender_id), |
289 | sender)) || | ||
290 | (GNUNET_OK != GNUNET_CONTAINER_multishortmap_put (room->members, | ||
291 | &(message->body.id.id), | ||
292 | sender, | ||
293 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE))) | ||
258 | return; | 294 | return; |
259 | 295 | ||
260 | struct GNUNET_HashCode context, next_context; | 296 | struct GNUNET_HashCode context, next_context; |
261 | get_context_from_member(&(room->key), &(message->header.sender_id), &context); | 297 | get_context_from_member (&(room->key), &(message->header.sender_id), |
262 | get_context_from_member(&(room->key), &(message->body.id.id), &next_context); | 298 | &context); |
299 | get_context_from_member (&(room->key), &(message->body.id.id), &next_context); | ||
263 | 300 | ||
264 | struct GNUNET_MESSENGER_ContactStore *store = get_handle_contact_store(room->handle); | 301 | struct GNUNET_MESSENGER_ContactStore *store = get_handle_contact_store ( |
302 | room->handle); | ||
265 | 303 | ||
266 | update_store_contact(store, sender, &context, &next_context, get_contact_key(sender)); | 304 | update_store_contact (store, sender, &context, &next_context, |
305 | get_contact_key (sender)); | ||
267 | } | 306 | } |
268 | 307 | ||
308 | |||
269 | static void | 309 | static void |
270 | handle_miss_message (struct GNUNET_MESSENGER_Room *room, | 310 | handle_miss_message (struct GNUNET_MESSENGER_Room *room, |
271 | struct GNUNET_MESSENGER_Contact *sender, | 311 | struct GNUNET_MESSENGER_Contact *sender, |
@@ -275,31 +315,40 @@ handle_miss_message (struct GNUNET_MESSENGER_Room *room, | |||
275 | { | 315 | { |
276 | if (GNUNET_MESSENGER_FLAG_SENT & flags) | 316 | if (GNUNET_MESSENGER_FLAG_SENT & flags) |
277 | { | 317 | { |
278 | struct GNUNET_MESSENGER_ListTunnel *match = find_list_tunnels (&(room->entries), &(message->body.miss.peer), NULL); | 318 | struct GNUNET_MESSENGER_ListTunnel *match = find_list_tunnels ( |
319 | &(room->entries), &(message->body.miss.peer), NULL); | ||
279 | 320 | ||
280 | if (match) | 321 | if (match) |
281 | remove_from_list_tunnels (&(room->entries), match); | 322 | remove_from_list_tunnels (&(room->entries), match); |
282 | } | 323 | } |
283 | } | 324 | } |
284 | 325 | ||
326 | |||
285 | static void | 327 | static void |
286 | handle_delete_message (struct GNUNET_MESSENGER_Room *room, | 328 | handle_delete_message (struct GNUNET_MESSENGER_Room *room, |
287 | struct GNUNET_MESSENGER_Contact *sender, | 329 | struct GNUNET_MESSENGER_Contact *sender, |
288 | const struct GNUNET_MESSENGER_Message *message, | 330 | const struct GNUNET_MESSENGER_Message *message, |
289 | const struct GNUNET_HashCode *hash) | 331 | const struct GNUNET_HashCode *hash) |
290 | { | 332 | { |
291 | struct GNUNET_MESSENGER_RoomMessageEntry *entry = GNUNET_CONTAINER_multihashmap_get ( | 333 | struct GNUNET_MESSENGER_RoomMessageEntry *entry = |
334 | GNUNET_CONTAINER_multihashmap_get ( | ||
292 | room->messages, &(message->body.deletion.hash) | 335 | room->messages, &(message->body.deletion.hash) |
293 | ); | 336 | ); |
294 | 337 | ||
295 | if ((entry) && ((entry->sender == sender) || (get_handle_contact (room->handle, &(room->key)) == sender)) && | 338 | if ((entry) && ((entry->sender == sender) || (get_handle_contact ( |
296 | (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (room->messages, &(message->body.deletion.hash), entry))) | 339 | room->handle, &(room->key)) == |
340 | sender)) && | ||
341 | (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (room->messages, | ||
342 | &(message->body. | ||
343 | deletion.hash), | ||
344 | entry))) | ||
297 | { | 345 | { |
298 | destroy_message (entry->message); | 346 | destroy_message (entry->message); |
299 | GNUNET_free(entry); | 347 | GNUNET_free (entry); |
300 | } | 348 | } |
301 | } | 349 | } |
302 | 350 | ||
351 | |||
303 | struct GNUNET_MESSENGER_Contact* | 352 | struct GNUNET_MESSENGER_Contact* |
304 | handle_room_message (struct GNUNET_MESSENGER_Room *room, | 353 | handle_room_message (struct GNUNET_MESSENGER_Room *room, |
305 | struct GNUNET_MESSENGER_Contact *sender, | 354 | struct GNUNET_MESSENGER_Contact *sender, |
@@ -307,7 +356,8 @@ handle_room_message (struct GNUNET_MESSENGER_Room *room, | |||
307 | const struct GNUNET_HashCode *hash, | 356 | const struct GNUNET_HashCode *hash, |
308 | enum GNUNET_MESSENGER_MessageFlags flags) | 357 | enum GNUNET_MESSENGER_MessageFlags flags) |
309 | { | 358 | { |
310 | if (GNUNET_NO != GNUNET_CONTAINER_multihashmap_contains (room->messages, hash)) | 359 | if (GNUNET_NO != GNUNET_CONTAINER_multihashmap_contains (room->messages, |
360 | hash)) | ||
311 | return sender; | 361 | return sender; |
312 | 362 | ||
313 | switch (message->header.kind) | 363 | switch (message->header.kind) |
@@ -337,25 +387,28 @@ handle_room_message (struct GNUNET_MESSENGER_Room *room, | |||
337 | break; | 387 | break; |
338 | } | 388 | } |
339 | 389 | ||
340 | struct GNUNET_MESSENGER_RoomMessageEntry *entry = GNUNET_new(struct GNUNET_MESSENGER_RoomMessageEntry); | 390 | struct GNUNET_MESSENGER_RoomMessageEntry *entry = GNUNET_new (struct |
391 | GNUNET_MESSENGER_RoomMessageEntry); | ||
341 | 392 | ||
342 | if (!entry) | 393 | if (! entry) |
343 | return sender; | 394 | return sender; |
344 | 395 | ||
345 | entry->sender = sender; | 396 | entry->sender = sender; |
346 | entry->message = copy_message (message); | 397 | entry->message = copy_message (message); |
347 | 398 | ||
348 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (room->messages, hash, entry, | 399 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (room->messages, hash, |
400 | entry, | ||
349 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | 401 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) |
350 | { | 402 | { |
351 | destroy_message (entry->message); | 403 | destroy_message (entry->message); |
352 | GNUNET_free(entry); | 404 | GNUNET_free (entry); |
353 | } | 405 | } |
354 | 406 | ||
355 | GNUNET_memcpy (&(room->last_message), hash, sizeof(room->last_message)); | 407 | GNUNET_memcpy (&(room->last_message), hash, sizeof(room->last_message)); |
356 | return sender; | 408 | return sender; |
357 | } | 409 | } |
358 | 410 | ||
411 | |||
359 | struct GNUNET_MESSENGER_MemberCall | 412 | struct GNUNET_MESSENGER_MemberCall |
360 | { | 413 | { |
361 | struct GNUNET_MESSENGER_Room *room; | 414 | struct GNUNET_MESSENGER_Room *room; |
@@ -364,25 +417,26 @@ struct GNUNET_MESSENGER_MemberCall | |||
364 | }; | 417 | }; |
365 | 418 | ||
366 | static int | 419 | static int |
367 | iterate_local_members (void* cls, | 420 | iterate_local_members (void *cls, |
368 | const struct GNUNET_ShortHashCode *key, | 421 | const struct GNUNET_ShortHashCode *key, |
369 | void *value) | 422 | void *value) |
370 | { | 423 | { |
371 | struct GNUNET_MESSENGER_MemberCall *call = cls; | 424 | struct GNUNET_MESSENGER_MemberCall *call = cls; |
372 | struct GNUNET_MESSENGER_Contact *contact = value; | 425 | struct GNUNET_MESSENGER_Contact *contact = value; |
373 | 426 | ||
374 | return call->callback(call->cls, call->room, contact); | 427 | return call->callback (call->cls, call->room, contact); |
375 | } | 428 | } |
376 | 429 | ||
430 | |||
377 | int | 431 | int |
378 | iterate_room_members (struct GNUNET_MESSENGER_Room *room, | 432 | iterate_room_members (struct GNUNET_MESSENGER_Room *room, |
379 | GNUNET_MESSENGER_MemberCallback callback, | 433 | GNUNET_MESSENGER_MemberCallback callback, |
380 | void* cls) | 434 | void *cls) |
381 | { | 435 | { |
382 | GNUNET_assert(room); | 436 | GNUNET_assert (room); |
383 | 437 | ||
384 | if (!callback) | 438 | if (! callback) |
385 | return GNUNET_CONTAINER_multishortmap_iterate(room->members, NULL, NULL); | 439 | return GNUNET_CONTAINER_multishortmap_iterate (room->members, NULL, NULL); |
386 | 440 | ||
387 | struct GNUNET_MESSENGER_MemberCall call; | 441 | struct GNUNET_MESSENGER_MemberCall call; |
388 | 442 | ||
@@ -390,11 +444,14 @@ iterate_room_members (struct GNUNET_MESSENGER_Room *room, | |||
390 | call.callback = callback; | 444 | call.callback = callback; |
391 | call.cls = cls; | 445 | call.cls = cls; |
392 | 446 | ||
393 | GNUNET_assert(callback); | 447 | GNUNET_assert (callback); |
394 | 448 | ||
395 | return GNUNET_CONTAINER_multishortmap_iterate(room->members, iterate_local_members, &call); | 449 | return GNUNET_CONTAINER_multishortmap_iterate (room->members, |
450 | iterate_local_members, | ||
451 | &call); | ||
396 | } | 452 | } |
397 | 453 | ||
454 | |||
398 | struct GNUNET_MESSENGER_MemberFind | 455 | struct GNUNET_MESSENGER_MemberFind |
399 | { | 456 | { |
400 | const struct GNUNET_MESSENGER_Contact *contact; | 457 | const struct GNUNET_MESSENGER_Contact *contact; |
@@ -402,7 +459,7 @@ struct GNUNET_MESSENGER_MemberFind | |||
402 | }; | 459 | }; |
403 | 460 | ||
404 | static int | 461 | static int |
405 | iterate_find_member (void* cls, | 462 | iterate_find_member (void *cls, |
406 | const struct GNUNET_ShortHashCode *key, | 463 | const struct GNUNET_ShortHashCode *key, |
407 | void *value) | 464 | void *value) |
408 | { | 465 | { |
@@ -418,18 +475,20 @@ iterate_find_member (void* cls, | |||
418 | return GNUNET_YES; | 475 | return GNUNET_YES; |
419 | } | 476 | } |
420 | 477 | ||
478 | |||
421 | int | 479 | int |
422 | find_room_member (const struct GNUNET_MESSENGER_Room *room, | 480 | find_room_member (const struct GNUNET_MESSENGER_Room *room, |
423 | const struct GNUNET_MESSENGER_Contact *contact) | 481 | const struct GNUNET_MESSENGER_Contact *contact) |
424 | { | 482 | { |
425 | GNUNET_assert(room); | 483 | GNUNET_assert (room); |
426 | 484 | ||
427 | struct GNUNET_MESSENGER_MemberFind find; | 485 | struct GNUNET_MESSENGER_MemberFind find; |
428 | 486 | ||
429 | find.contact = contact; | 487 | find.contact = contact; |
430 | find.result = GNUNET_NO; | 488 | find.result = GNUNET_NO; |
431 | 489 | ||
432 | GNUNET_CONTAINER_multishortmap_iterate(room->members, iterate_find_member, &find); | 490 | GNUNET_CONTAINER_multishortmap_iterate (room->members, iterate_find_member, |
491 | &find); | ||
433 | 492 | ||
434 | return find.result; | 493 | return find.result; |
435 | } | 494 | } |
diff --git a/src/messenger/messenger_api_room.h b/src/messenger/messenger_api_room.h index 62e4711d0..c9d36a410 100644 --- a/src/messenger/messenger_api_room.h +++ b/src/messenger/messenger_api_room.h | |||
@@ -36,9 +36,10 @@ | |||
36 | #include "messenger_api_message.h" | 36 | #include "messenger_api_message.h" |
37 | #include "messenger_api_queue_messages.h" | 37 | #include "messenger_api_queue_messages.h" |
38 | 38 | ||
39 | struct GNUNET_MESSENGER_RoomMessageEntry { | 39 | struct GNUNET_MESSENGER_RoomMessageEntry |
40 | struct GNUNET_MESSENGER_Contact* sender; | 40 | { |
41 | struct GNUNET_MESSENGER_Message* message; | 41 | struct GNUNET_MESSENGER_Contact *sender; |
42 | struct GNUNET_MESSENGER_Message *message; | ||
42 | }; | 43 | }; |
43 | 44 | ||
44 | struct GNUNET_MESSENGER_Room | 45 | struct GNUNET_MESSENGER_Room |
@@ -165,7 +166,7 @@ handle_room_message (struct GNUNET_MESSENGER_Room *room, | |||
165 | int | 166 | int |
166 | iterate_room_members (struct GNUNET_MESSENGER_Room *room, | 167 | iterate_room_members (struct GNUNET_MESSENGER_Room *room, |
167 | GNUNET_MESSENGER_MemberCallback callback, | 168 | GNUNET_MESSENGER_MemberCallback callback, |
168 | void* cls); | 169 | void *cls); |
169 | 170 | ||
170 | /** | 171 | /** |
171 | * Checks through all members of a given <i>room</i> if a specific <i>contact</i> is found and | 172 | * Checks through all members of a given <i>room</i> if a specific <i>contact</i> is found and |
diff --git a/src/messenger/messenger_api_util.c b/src/messenger/messenger_api_util.c index 2fc58ed75..bac9d0a05 100644 --- a/src/messenger/messenger_api_util.c +++ b/src/messenger/messenger_api_util.c | |||
@@ -35,29 +35,34 @@ callback_close_channel (void *cls) | |||
35 | GNUNET_CADET_channel_destroy (channel); | 35 | GNUNET_CADET_channel_destroy (channel); |
36 | } | 36 | } |
37 | 37 | ||
38 | |||
38 | void | 39 | void |
39 | delayed_disconnect_channel (struct GNUNET_CADET_Channel *channel) | 40 | delayed_disconnect_channel (struct GNUNET_CADET_Channel *channel) |
40 | { | 41 | { |
41 | GNUNET_assert(channel); | 42 | GNUNET_assert (channel); |
42 | 43 | ||
43 | GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_relative_get_zero_ (), | 44 | GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_relative_get_zero_ (), |
44 | GNUNET_SCHEDULER_PRIORITY_URGENT, | 45 | GNUNET_SCHEDULER_PRIORITY_URGENT, |
45 | callback_close_channel, channel); | 46 | callback_close_channel, channel); |
46 | } | 47 | } |
47 | 48 | ||
49 | |||
48 | int | 50 | int |
49 | generate_free_member_id (struct GNUNET_ShortHashCode *id, | 51 | generate_free_member_id (struct GNUNET_ShortHashCode *id, |
50 | const struct GNUNET_CONTAINER_MultiShortmap *members) | 52 | const struct GNUNET_CONTAINER_MultiShortmap *members) |
51 | { | 53 | { |
52 | GNUNET_assert(id); | 54 | GNUNET_assert (id); |
53 | 55 | ||
54 | size_t counter = 1 + (members ? GNUNET_CONTAINER_multishortmap_size (members) : 0); | 56 | size_t counter = 1 + (members ? GNUNET_CONTAINER_multishortmap_size ( |
57 | members) : 0); | ||
55 | 58 | ||
56 | do | 59 | do |
57 | { | 60 | { |
58 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, id, sizeof(struct GNUNET_ShortHashCode)); | 61 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG, id, sizeof(struct |
62 | GNUNET_ShortHashCode)); | ||
59 | 63 | ||
60 | if ((members) && (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains (members, id))) | 64 | if ((members) && (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains ( |
65 | members, id))) | ||
61 | counter--; | 66 | counter--; |
62 | else | 67 | else |
63 | break; | 68 | break; |
@@ -70,48 +75,53 @@ generate_free_member_id (struct GNUNET_ShortHashCode *id, | |||
70 | return GNUNET_NO; | 75 | return GNUNET_NO; |
71 | } | 76 | } |
72 | 77 | ||
78 | |||
73 | const struct GNUNET_IDENTITY_PrivateKey* | 79 | const struct GNUNET_IDENTITY_PrivateKey* |
74 | get_anonymous_private_key () | 80 | get_anonymous_private_key () |
75 | { | 81 | { |
76 | const struct GNUNET_IDENTITY_Ego* ego = GNUNET_IDENTITY_ego_get_anonymous(); | 82 | const struct GNUNET_IDENTITY_Ego *ego = GNUNET_IDENTITY_ego_get_anonymous (); |
77 | return GNUNET_IDENTITY_ego_get_private_key(ego); | 83 | return GNUNET_IDENTITY_ego_get_private_key (ego); |
78 | } | 84 | } |
79 | 85 | ||
86 | |||
80 | const struct GNUNET_IDENTITY_PublicKey* | 87 | const struct GNUNET_IDENTITY_PublicKey* |
81 | get_anonymous_public_key () | 88 | get_anonymous_public_key () |
82 | { | 89 | { |
83 | static struct GNUNET_IDENTITY_PublicKey public_key; | 90 | static struct GNUNET_IDENTITY_PublicKey public_key; |
84 | static struct GNUNET_IDENTITY_Ego* ego = NULL; | 91 | static struct GNUNET_IDENTITY_Ego *ego = NULL; |
85 | 92 | ||
86 | if (!ego) | 93 | if (! ego) |
87 | { | 94 | { |
88 | ego = GNUNET_IDENTITY_ego_get_anonymous(); | 95 | ego = GNUNET_IDENTITY_ego_get_anonymous (); |
89 | GNUNET_IDENTITY_ego_get_public_key(ego, &public_key); | 96 | GNUNET_IDENTITY_ego_get_public_key (ego, &public_key); |
90 | } | 97 | } |
91 | 98 | ||
92 | return &public_key; | 99 | return &public_key; |
93 | } | 100 | } |
94 | 101 | ||
102 | |||
95 | void | 103 | void |
96 | convert_messenger_key_to_port(const struct GNUNET_HashCode *key, | 104 | convert_messenger_key_to_port (const struct GNUNET_HashCode *key, |
97 | struct GNUNET_HashCode *port) | 105 | struct GNUNET_HashCode *port) |
98 | { | 106 | { |
99 | static uint32_t version_value = 0; | 107 | static uint32_t version_value = 0; |
100 | static struct GNUNET_HashCode version; | 108 | static struct GNUNET_HashCode version; |
101 | 109 | ||
102 | if (!version_value) { | 110 | if (! version_value) |
111 | { | ||
103 | version_value = (uint32_t) (GNUNET_MESSENGER_VERSION); | 112 | version_value = (uint32_t) (GNUNET_MESSENGER_VERSION); |
104 | version_value = ((version_value >> 16) & 0xFFFF); | 113 | version_value = ((version_value >> 16) & 0xFFFF); |
105 | version_value = GNUNET_htole32(version_value); | 114 | version_value = GNUNET_htole32 (version_value); |
106 | GNUNET_CRYPTO_hash(&version_value, sizeof(version_value), &version); | 115 | GNUNET_CRYPTO_hash (&version_value, sizeof(version_value), &version); |
107 | } | 116 | } |
108 | 117 | ||
109 | GNUNET_CRYPTO_hash_sum(key, &version, port); | 118 | GNUNET_CRYPTO_hash_sum (key, &version, port); |
110 | } | 119 | } |
111 | 120 | ||
121 | |||
112 | void | 122 | void |
113 | convert_peer_identity_to_id(const struct GNUNET_PeerIdentity *identity, | 123 | convert_peer_identity_to_id (const struct GNUNET_PeerIdentity *identity, |
114 | struct GNUNET_ShortHashCode *id) | 124 | struct GNUNET_ShortHashCode *id) |
115 | { | 125 | { |
116 | GNUNET_memcpy(id, identity, sizeof(struct GNUNET_ShortHashCode)); | 126 | GNUNET_memcpy (id, identity, sizeof(struct GNUNET_ShortHashCode)); |
117 | } | 127 | } |
diff --git a/src/messenger/messenger_api_util.h b/src/messenger/messenger_api_util.h index f50abf445..6a7b4df89 100644 --- a/src/messenger/messenger_api_util.h +++ b/src/messenger/messenger_api_util.h | |||
@@ -81,8 +81,8 @@ get_anonymous_public_key (); | |||
81 | * @param[out] port CADET service port | 81 | * @param[out] port CADET service port |
82 | */ | 82 | */ |
83 | void | 83 | void |
84 | convert_messenger_key_to_port(const struct GNUNET_HashCode *key, | 84 | convert_messenger_key_to_port (const struct GNUNET_HashCode *key, |
85 | struct GNUNET_HashCode *port); | 85 | struct GNUNET_HashCode *port); |
86 | 86 | ||
87 | /** | 87 | /** |
88 | * Converts a peers identity to a short hash code which can be used | 88 | * Converts a peers identity to a short hash code which can be used |
@@ -92,7 +92,7 @@ convert_messenger_key_to_port(const struct GNUNET_HashCode *key, | |||
92 | * @param[out] id Short peer id | 92 | * @param[out] id Short peer id |
93 | */ | 93 | */ |
94 | void | 94 | void |
95 | convert_peer_identity_to_id(const struct GNUNET_PeerIdentity *identity, | 95 | convert_peer_identity_to_id (const struct GNUNET_PeerIdentity *identity, |
96 | struct GNUNET_ShortHashCode *id); | 96 | struct GNUNET_ShortHashCode *id); |
97 | 97 | ||
98 | #endif //GNUNET_SERVICE_MESSENGER_UTIL_H | 98 | #endif //GNUNET_SERVICE_MESSENGER_UTIL_H |
diff --git a/src/messenger/plugin_gnsrecord_messenger.c b/src/messenger/plugin_gnsrecord_messenger.c index e09a0330d..ed675dd1d 100644 --- a/src/messenger/plugin_gnsrecord_messenger.c +++ b/src/messenger/plugin_gnsrecord_messenger.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2021--2022 GNUnet e.V. | 3 | Copyright (C) 2021--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 |
@@ -59,8 +59,11 @@ messenger_value_to_string (void *cls, | |||
59 | 59 | ||
60 | const struct GNUNET_MESSENGER_RoomEntryRecord *record = data; | 60 | const struct GNUNET_MESSENGER_RoomEntryRecord *record = data; |
61 | 61 | ||
62 | char *door = GNUNET_CRYPTO_eddsa_public_key_to_string (&(record->door.public_key)); | 62 | char *door = GNUNET_CRYPTO_eddsa_public_key_to_string ( |
63 | char *key = GNUNET_STRINGS_data_to_string_alloc (&(record->key), sizeof(struct GNUNET_HashCode)); | 63 | &(record->door.public_key)); |
64 | char *key = GNUNET_STRINGS_data_to_string_alloc (&(record->key), | ||
65 | sizeof(struct | ||
66 | GNUNET_HashCode)); | ||
64 | 67 | ||
65 | char *ret; | 68 | char *ret; |
66 | GNUNET_asprintf (&ret, "%s-%s", key, door); | 69 | GNUNET_asprintf (&ret, "%s-%s", key, door); |
@@ -78,8 +81,9 @@ messenger_value_to_string (void *cls, | |||
78 | 81 | ||
79 | const struct GNUNET_MESSENGER_RoomDetailsRecord *record = data; | 82 | const struct GNUNET_MESSENGER_RoomDetailsRecord *record = data; |
80 | 83 | ||
81 | char *name = GNUNET_strndup(record->name, 256); | 84 | char *name = GNUNET_strndup (record->name, 256); |
82 | char *flags = GNUNET_STRINGS_data_to_string_alloc (&(record->flags), sizeof(uint32_t)); | 85 | char *flags = GNUNET_STRINGS_data_to_string_alloc (&(record->flags), |
86 | sizeof(uint32_t)); | ||
83 | 87 | ||
84 | char *ret; | 88 | char *ret; |
85 | GNUNET_asprintf (&ret, "%s-%s", flags, name); | 89 | GNUNET_asprintf (&ret, "%s-%s", flags, name); |
@@ -122,15 +126,17 @@ messenger_string_to_value (void *cls, | |||
122 | { | 126 | { |
123 | case GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY: | 127 | case GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY: |
124 | { | 128 | { |
125 | char key [103]; | 129 | char key[103]; |
126 | const char *dash; | 130 | const char *dash; |
127 | struct GNUNET_PeerIdentity door; | 131 | struct GNUNET_PeerIdentity door; |
128 | 132 | ||
129 | if ((NULL == (dash = strchr (s, '-'))) || | 133 | if ((NULL == (dash = strchr (s, '-'))) || |
130 | (1 != sscanf (s, "%103s-", key)) || | 134 | (1 != sscanf (s, "%103s-", key)) || |
131 | (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (dash + 1, | 135 | (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (dash + 1, |
132 | strlen (dash + 1), | 136 | strlen ( |
133 | &(door.public_key)))) | 137 | dash + 1), |
138 | &(door. | ||
139 | public_key)))) | ||
134 | { | 140 | { |
135 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 141 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
136 | _ ("Unable to parse MESSENGER_ROOM_ENTRY record `%s'\n"), | 142 | _ ("Unable to parse MESSENGER_ROOM_ENTRY record `%s'\n"), |
@@ -139,13 +145,14 @@ messenger_string_to_value (void *cls, | |||
139 | } | 145 | } |
140 | 146 | ||
141 | struct GNUNET_MESSENGER_RoomEntryRecord *record = GNUNET_new ( | 147 | struct GNUNET_MESSENGER_RoomEntryRecord *record = GNUNET_new ( |
142 | struct GNUNET_MESSENGER_RoomEntryRecord | 148 | struct GNUNET_MESSENGER_RoomEntryRecord |
143 | ); | 149 | ); |
144 | 150 | ||
145 | if (GNUNET_OK != GNUNET_STRINGS_string_to_data (key, | 151 | if (GNUNET_OK != GNUNET_STRINGS_string_to_data (key, |
146 | strlen (key), | 152 | strlen (key), |
147 | &(record->key), | 153 | &(record->key), |
148 | sizeof(struct GNUNET_HashCode))) | 154 | sizeof(struct |
155 | GNUNET_HashCode))) | ||
149 | { | 156 | { |
150 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 157 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
151 | _ ("Unable to parse MESSENGER_ROOM_ENTRY record `%s'\n"), | 158 | _ ("Unable to parse MESSENGER_ROOM_ENTRY record `%s'\n"), |
@@ -161,7 +168,7 @@ messenger_string_to_value (void *cls, | |||
161 | } | 168 | } |
162 | case GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_DETAILS: | 169 | case GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_DETAILS: |
163 | { | 170 | { |
164 | char flags [7]; | 171 | char flags[7]; |
165 | const char *dash; | 172 | const char *dash; |
166 | 173 | ||
167 | if ((NULL == (dash = strchr (s, '-'))) || | 174 | if ((NULL == (dash = strchr (s, '-'))) || |
@@ -175,8 +182,8 @@ messenger_string_to_value (void *cls, | |||
175 | } | 182 | } |
176 | 183 | ||
177 | struct GNUNET_MESSENGER_RoomDetailsRecord *record = GNUNET_new ( | 184 | struct GNUNET_MESSENGER_RoomDetailsRecord *record = GNUNET_new ( |
178 | struct GNUNET_MESSENGER_RoomDetailsRecord | 185 | struct GNUNET_MESSENGER_RoomDetailsRecord |
179 | ); | 186 | ); |
180 | 187 | ||
181 | if (GNUNET_OK != GNUNET_STRINGS_string_to_data (flags, | 188 | if (GNUNET_OK != GNUNET_STRINGS_string_to_data (flags, |
182 | strlen (flags), | 189 | strlen (flags), |
@@ -190,7 +197,7 @@ messenger_string_to_value (void *cls, | |||
190 | return GNUNET_SYSERR; | 197 | return GNUNET_SYSERR; |
191 | } | 198 | } |
192 | 199 | ||
193 | GNUNET_memcpy(record->name, dash + 1, strlen(dash + 1)); | 200 | GNUNET_memcpy (record->name, dash + 1, strlen (dash + 1)); |
194 | 201 | ||
195 | *data = record; | 202 | *data = record; |
196 | *data_size = sizeof(struct GNUNET_MESSENGER_RoomDetailsRecord); | 203 | *data_size = sizeof(struct GNUNET_MESSENGER_RoomDetailsRecord); |
diff --git a/src/messenger/test_messenger.c b/src/messenger/test_messenger.c index 9958ce19e..716105380 100644 --- a/src/messenger/test_messenger.c +++ b/src/messenger/test_messenger.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--2021 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 |
@@ -77,6 +77,7 @@ end (void *cls) | |||
77 | status = 0; | 77 | status = 0; |
78 | } | 78 | } |
79 | 79 | ||
80 | |||
80 | static void | 81 | static void |
81 | end_badly (void *cls) | 82 | end_badly (void *cls) |
82 | { | 83 | { |
@@ -86,12 +87,15 @@ end_badly (void *cls) | |||
86 | status = 1; | 87 | status = 1; |
87 | } | 88 | } |
88 | 89 | ||
90 | |||
89 | static void | 91 | static void |
90 | end_operation (void *cls) | 92 | end_operation (void *cls) |
91 | { | 93 | { |
92 | op_task = NULL; | 94 | op_task = NULL; |
93 | 95 | ||
94 | fprintf (stderr, "Testcase failed (operation: '%s').\n", cls ? (const char*) cls : "unknown"); | 96 | fprintf (stderr, "Testcase failed (operation: '%s').\n", cls ? (const |
97 | char*) cls : | ||
98 | "unknown"); | ||
95 | 99 | ||
96 | if (die_task) | 100 | if (die_task) |
97 | GNUNET_SCHEDULER_cancel (die_task); | 101 | GNUNET_SCHEDULER_cancel (die_task); |
@@ -100,6 +104,7 @@ end_operation (void *cls) | |||
100 | status = 1; | 104 | status = 1; |
101 | } | 105 | } |
102 | 106 | ||
107 | |||
103 | static int identity_counter = 0; | 108 | static int identity_counter = 0; |
104 | 109 | ||
105 | /** | 110 | /** |
@@ -122,18 +127,23 @@ on_iteration (void *cls) | |||
122 | 127 | ||
123 | const char *name = GNUNET_MESSENGER_get_name (handle); | 128 | const char *name = GNUNET_MESSENGER_get_name (handle); |
124 | 129 | ||
125 | if ((!name) || (0 != strcmp (name, TESTER_NAME))) | 130 | if ((! name) || (0 != strcmp (name, TESTER_NAME))) |
126 | { | 131 | { |
127 | op_task = GNUNET_SCHEDULER_add_now (&end_operation, "name"); | 132 | op_task = GNUNET_SCHEDULER_add_now (&end_operation, "name"); |
128 | return; | 133 | return; |
129 | } | 134 | } |
130 | 135 | ||
131 | const struct GNUNET_IDENTITY_PublicKey *key = GNUNET_MESSENGER_get_key (handle); | 136 | const struct GNUNET_IDENTITY_PublicKey *key = GNUNET_MESSENGER_get_key ( |
137 | handle); | ||
132 | 138 | ||
133 | struct GNUNET_IDENTITY_PublicKey pubkey; | 139 | struct GNUNET_IDENTITY_PublicKey pubkey; |
134 | GNUNET_IDENTITY_key_get_public(&identity, &pubkey); | 140 | GNUNET_IDENTITY_key_get_public (&identity, &pubkey); |
135 | 141 | ||
136 | if (((!identity_counter) && (key)) || ((identity_counter) && ((!key) || (0 != GNUNET_memcmp (key, &pubkey))))) | 142 | if (((! identity_counter) && (key)) || ((identity_counter) && ((! key) || |
143 | (0 != | ||
144 | GNUNET_memcmp ( | ||
145 | key, | ||
146 | &pubkey))))) | ||
137 | { | 147 | { |
138 | op_task = GNUNET_SCHEDULER_add_now (&end_operation, "key"); | 148 | op_task = GNUNET_SCHEDULER_add_now (&end_operation, "key"); |
139 | return; | 149 | return; |
@@ -159,6 +169,7 @@ on_iteration (void *cls) | |||
159 | it_task = GNUNET_SCHEDULER_add_now (&on_iteration, handle); | 169 | it_task = GNUNET_SCHEDULER_add_now (&on_iteration, handle); |
160 | } | 170 | } |
161 | 171 | ||
172 | |||
162 | /** | 173 | /** |
163 | * Main function for testcase. | 174 | * Main function for testcase. |
164 | * | 175 | * |
@@ -175,7 +186,8 @@ run (void *cls, | |||
175 | 186 | ||
176 | identity_counter = 0; | 187 | identity_counter = 0; |
177 | 188 | ||
178 | op_task = GNUNET_SCHEDULER_add_delayed (BASE_TIMEOUT, &end_operation, "connect"); | 189 | op_task = GNUNET_SCHEDULER_add_delayed (BASE_TIMEOUT, &end_operation, |
190 | "connect"); | ||
179 | messenger = GNUNET_MESSENGER_connect (cfg, TESTER_NAME, NULL, NULL, NULL); | 191 | messenger = GNUNET_MESSENGER_connect (cfg, TESTER_NAME, NULL, NULL, NULL); |
180 | 192 | ||
181 | identity.type = htonl (GNUNET_IDENTITY_TYPE_ECDSA); | 193 | identity.type = htonl (GNUNET_IDENTITY_TYPE_ECDSA); |
@@ -185,6 +197,7 @@ run (void *cls, | |||
185 | it_task = GNUNET_SCHEDULER_add_now (&on_iteration, messenger); | 197 | it_task = GNUNET_SCHEDULER_add_now (&on_iteration, messenger); |
186 | } | 198 | } |
187 | 199 | ||
200 | |||
188 | /** | 201 | /** |
189 | * The main function. | 202 | * The main function. |
190 | * | 203 | * |
@@ -196,7 +209,8 @@ int | |||
196 | main (int argc, | 209 | main (int argc, |
197 | char **argv) | 210 | char **argv) |
198 | { | 211 | { |
199 | if (0 != GNUNET_TESTING_peer_run ("test-messenger", "test_messenger_api.conf", &run, NULL)) | 212 | if (0 != GNUNET_TESTING_peer_run ("test-messenger", "test_messenger_api.conf", |
213 | &run, NULL)) | ||
200 | return 1; | 214 | return 1; |
201 | 215 | ||
202 | return status; | 216 | return status; |
diff --git a/src/messenger/test_messenger_anonymous.c b/src/messenger/test_messenger_anonymous.c index 8431d186f..1bb8e14da 100644 --- a/src/messenger/test_messenger_anonymous.c +++ b/src/messenger/test_messenger_anonymous.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--2021 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 |
@@ -73,6 +73,7 @@ end (void *cls) | |||
73 | status = 0; | 73 | status = 0; |
74 | } | 74 | } |
75 | 75 | ||
76 | |||
76 | static void | 77 | static void |
77 | end_badly (void *cls) | 78 | end_badly (void *cls) |
78 | { | 79 | { |
@@ -82,12 +83,15 @@ end_badly (void *cls) | |||
82 | status = 1; | 83 | status = 1; |
83 | } | 84 | } |
84 | 85 | ||
86 | |||
85 | static void | 87 | static void |
86 | end_operation (void *cls) | 88 | end_operation (void *cls) |
87 | { | 89 | { |
88 | op_task = NULL; | 90 | op_task = NULL; |
89 | 91 | ||
90 | fprintf (stderr, "Testcase failed (operation: '%s').\n", cls ? (const char*) cls : "unknown"); | 92 | fprintf (stderr, "Testcase failed (operation: '%s').\n", cls ? (const |
93 | char*) cls : | ||
94 | "unknown"); | ||
91 | 95 | ||
92 | if (die_task) | 96 | if (die_task) |
93 | GNUNET_SCHEDULER_cancel (die_task); | 97 | GNUNET_SCHEDULER_cancel (die_task); |
@@ -96,6 +100,7 @@ end_operation (void *cls) | |||
96 | status = 1; | 100 | status = 1; |
97 | } | 101 | } |
98 | 102 | ||
103 | |||
99 | /** | 104 | /** |
100 | * Function called when an identity is retrieved. | 105 | * Function called when an identity is retrieved. |
101 | * | 106 | * |
@@ -123,7 +128,8 @@ on_iteration (void *cls) | |||
123 | return; | 128 | return; |
124 | } | 129 | } |
125 | 130 | ||
126 | const struct GNUNET_IDENTITY_PublicKey *key = GNUNET_MESSENGER_get_key (handle); | 131 | const struct GNUNET_IDENTITY_PublicKey *key = GNUNET_MESSENGER_get_key ( |
132 | handle); | ||
127 | 133 | ||
128 | if (key) | 134 | if (key) |
129 | { | 135 | { |
@@ -141,6 +147,7 @@ on_iteration (void *cls) | |||
141 | die_task = GNUNET_SCHEDULER_add_now (&end, NULL); | 147 | die_task = GNUNET_SCHEDULER_add_now (&end, NULL); |
142 | } | 148 | } |
143 | 149 | ||
150 | |||
144 | /** | 151 | /** |
145 | * Main function for testcase. | 152 | * Main function for testcase. |
146 | * | 153 | * |
@@ -155,13 +162,15 @@ run (void *cls, | |||
155 | { | 162 | { |
156 | die_task = GNUNET_SCHEDULER_add_delayed (TOTAL_TIMEOUT, &end_badly, NULL); | 163 | die_task = GNUNET_SCHEDULER_add_delayed (TOTAL_TIMEOUT, &end_badly, NULL); |
157 | 164 | ||
158 | op_task = GNUNET_SCHEDULER_add_delayed (BASE_TIMEOUT, &end_operation, "connect"); | 165 | op_task = GNUNET_SCHEDULER_add_delayed (BASE_TIMEOUT, &end_operation, |
166 | "connect"); | ||
159 | messenger = GNUNET_MESSENGER_connect (cfg, NULL, NULL, NULL, NULL); | 167 | messenger = GNUNET_MESSENGER_connect (cfg, NULL, NULL, NULL, NULL); |
160 | 168 | ||
161 | if (messenger) | 169 | if (messenger) |
162 | it_task = GNUNET_SCHEDULER_add_now (&on_iteration, messenger); | 170 | it_task = GNUNET_SCHEDULER_add_now (&on_iteration, messenger); |
163 | } | 171 | } |
164 | 172 | ||
173 | |||
165 | /** | 174 | /** |
166 | * The main function. | 175 | * The main function. |
167 | * | 176 | * |
@@ -173,7 +182,8 @@ int | |||
173 | main (int argc, | 182 | main (int argc, |
174 | char **argv) | 183 | char **argv) |
175 | { | 184 | { |
176 | if (0 != GNUNET_TESTING_peer_run ("test-messenger", "test_messenger_api.conf", &run, NULL)) | 185 | if (0 != GNUNET_TESTING_peer_run ("test-messenger", "test_messenger_api.conf", |
186 | &run, NULL)) | ||
177 | return 1; | 187 | return 1; |
178 | 188 | ||
179 | return status; | 189 | return status; |
diff --git a/src/messenger/testing_messenger_barrier.c b/src/messenger/testing_messenger_barrier.c index 60d1fc0fe..ecebe1582 100644 --- a/src/messenger/testing_messenger_barrier.c +++ b/src/messenger/testing_messenger_barrier.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2021 GNUnet e.V. | 3 | Copyright (C) 2021, 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 |
@@ -35,7 +35,7 @@ struct GNUNET_BarrierHandle | |||
35 | struct GNUNET_BarrierWaitHandle *head; | 35 | struct GNUNET_BarrierWaitHandle *head; |
36 | struct GNUNET_BarrierWaitHandle *tail; | 36 | struct GNUNET_BarrierWaitHandle *tail; |
37 | 37 | ||
38 | struct GNUNET_SCHEDULER_Task* task; | 38 | struct GNUNET_SCHEDULER_Task *task; |
39 | }; | 39 | }; |
40 | 40 | ||
41 | struct GNUNET_BarrierHandle* | 41 | struct GNUNET_BarrierHandle* |
@@ -46,9 +46,10 @@ GNUNET_init_barrier (unsigned int requirement, | |||
46 | if (0 == requirement) | 46 | if (0 == requirement) |
47 | return NULL; | 47 | return NULL; |
48 | 48 | ||
49 | struct GNUNET_BarrierHandle *barrier = GNUNET_new(struct GNUNET_BarrierHandle); | 49 | struct GNUNET_BarrierHandle *barrier = GNUNET_new (struct |
50 | GNUNET_BarrierHandle); | ||
50 | 51 | ||
51 | if (!barrier) | 52 | if (! barrier) |
52 | return NULL; | 53 | return NULL; |
53 | 54 | ||
54 | barrier->requirement = requirement; | 55 | barrier->requirement = requirement; |
@@ -61,6 +62,7 @@ GNUNET_init_barrier (unsigned int requirement, | |||
61 | return barrier; | 62 | return barrier; |
62 | } | 63 | } |
63 | 64 | ||
65 | |||
64 | static void | 66 | static void |
65 | exit_status (struct GNUNET_BarrierHandle *barrier, | 67 | exit_status (struct GNUNET_BarrierHandle *barrier, |
66 | int status); | 68 | int status); |
@@ -71,21 +73,24 @@ cancel_barrier (void *cls) | |||
71 | exit_status ((struct GNUNET_BarrierHandle*) cls, GNUNET_SYSERR); | 73 | exit_status ((struct GNUNET_BarrierHandle*) cls, GNUNET_SYSERR); |
72 | } | 74 | } |
73 | 75 | ||
76 | |||
74 | static void | 77 | static void |
75 | complete_barrier (void *cls) | 78 | complete_barrier (void *cls) |
76 | { | 79 | { |
77 | exit_status ((struct GNUNET_BarrierHandle*) cls, GNUNET_OK); | 80 | exit_status ((struct GNUNET_BarrierHandle*) cls, GNUNET_OK); |
78 | } | 81 | } |
79 | 82 | ||
83 | |||
80 | void | 84 | void |
81 | GNUNET_cancel_barrier (struct GNUNET_BarrierHandle *barrier) | 85 | GNUNET_cancel_barrier (struct GNUNET_BarrierHandle *barrier) |
82 | { | 86 | { |
83 | if ((!barrier) || (barrier->task)) | 87 | if ((! barrier) || (barrier->task)) |
84 | return; | 88 | return; |
85 | 89 | ||
86 | barrier->task = GNUNET_SCHEDULER_add_now(cancel_barrier, barrier); | 90 | barrier->task = GNUNET_SCHEDULER_add_now (cancel_barrier, barrier); |
87 | } | 91 | } |
88 | 92 | ||
93 | |||
89 | struct GNUNET_BarrierWaitHandle | 94 | struct GNUNET_BarrierWaitHandle |
90 | { | 95 | { |
91 | GNUNET_BarrierWaitStatusCallback cb; | 96 | GNUNET_BarrierWaitStatusCallback cb; |
@@ -107,31 +112,33 @@ exit_status (struct GNUNET_BarrierHandle *barrier, | |||
107 | struct GNUNET_BarrierWaitHandle *current = waiting; | 112 | struct GNUNET_BarrierWaitHandle *current = waiting; |
108 | 113 | ||
109 | if (current->cb) | 114 | if (current->cb) |
110 | current->cb(current->cls, current, status); | 115 | current->cb (current->cls, current, status); |
111 | 116 | ||
112 | waiting = waiting->next; | 117 | waiting = waiting->next; |
113 | 118 | ||
114 | GNUNET_CONTAINER_DLL_remove(barrier->head, barrier->tail, current); | 119 | GNUNET_CONTAINER_DLL_remove (barrier->head, barrier->tail, current); |
115 | GNUNET_free(current); | 120 | GNUNET_free (current); |
116 | } | 121 | } |
117 | 122 | ||
118 | if (barrier->cb) | 123 | if (barrier->cb) |
119 | barrier->cb(barrier->cls, barrier, status); | 124 | barrier->cb (barrier->cls, barrier, status); |
120 | 125 | ||
121 | GNUNET_free(barrier); | 126 | GNUNET_free (barrier); |
122 | } | 127 | } |
123 | 128 | ||
129 | |||
124 | struct GNUNET_BarrierWaitHandle* | 130 | struct GNUNET_BarrierWaitHandle* |
125 | GNUNET_wait_barrier (struct GNUNET_BarrierHandle *barrier, | 131 | GNUNET_wait_barrier (struct GNUNET_BarrierHandle *barrier, |
126 | GNUNET_BarrierWaitStatusCallback cb, | 132 | GNUNET_BarrierWaitStatusCallback cb, |
127 | void *cb_cls) | 133 | void *cb_cls) |
128 | { | 134 | { |
129 | if ((!barrier) || (0 == barrier->requirement)) | 135 | if ((! barrier) || (0 == barrier->requirement)) |
130 | return NULL; | 136 | return NULL; |
131 | 137 | ||
132 | struct GNUNET_BarrierWaitHandle *waiting = GNUNET_new(struct GNUNET_BarrierWaitHandle); | 138 | struct GNUNET_BarrierWaitHandle *waiting = GNUNET_new (struct |
139 | GNUNET_BarrierWaitHandle); | ||
133 | 140 | ||
134 | if (!waiting) | 141 | if (! waiting) |
135 | return NULL; | 142 | return NULL; |
136 | 143 | ||
137 | waiting->cb = cb; | 144 | waiting->cb = cb; |
@@ -140,34 +147,35 @@ GNUNET_wait_barrier (struct GNUNET_BarrierHandle *barrier, | |||
140 | waiting->next = NULL; | 147 | waiting->next = NULL; |
141 | waiting->barrier = barrier; | 148 | waiting->barrier = barrier; |
142 | 149 | ||
143 | GNUNET_CONTAINER_DLL_insert_tail(barrier->head, barrier->tail, waiting); | 150 | GNUNET_CONTAINER_DLL_insert_tail (barrier->head, barrier->tail, waiting); |
144 | barrier->requirement--; | 151 | barrier->requirement--; |
145 | 152 | ||
146 | if ((barrier->requirement == 0) && (!barrier->task)) | 153 | if ((barrier->requirement == 0) && (! barrier->task)) |
147 | barrier->task = GNUNET_SCHEDULER_add_now(complete_barrier, barrier); | 154 | barrier->task = GNUNET_SCHEDULER_add_now (complete_barrier, barrier); |
148 | 155 | ||
149 | return waiting; | 156 | return waiting; |
150 | } | 157 | } |
151 | 158 | ||
159 | |||
152 | void | 160 | void |
153 | GNUNET_cancel_wait_barrier (struct GNUNET_BarrierWaitHandle *waiting) | 161 | GNUNET_cancel_wait_barrier (struct GNUNET_BarrierWaitHandle *waiting) |
154 | { | 162 | { |
155 | if (!waiting) | 163 | if (! waiting) |
156 | return; | 164 | return; |
157 | 165 | ||
158 | struct GNUNET_BarrierHandle *barrier = waiting->barrier; | 166 | struct GNUNET_BarrierHandle *barrier = waiting->barrier; |
159 | 167 | ||
160 | if (!barrier) | 168 | if (! barrier) |
161 | return; | 169 | return; |
162 | 170 | ||
163 | if ((barrier->requirement == 0) && (barrier->task)) | 171 | if ((barrier->requirement == 0) && (barrier->task)) |
164 | { | 172 | { |
165 | GNUNET_SCHEDULER_cancel(barrier->task); | 173 | GNUNET_SCHEDULER_cancel (barrier->task); |
166 | barrier->task = NULL; | 174 | barrier->task = NULL; |
167 | } | 175 | } |
168 | 176 | ||
169 | barrier->requirement++; | 177 | barrier->requirement++; |
170 | GNUNET_CONTAINER_DLL_remove(barrier->head, barrier->tail, waiting); | 178 | GNUNET_CONTAINER_DLL_remove (barrier->head, barrier->tail, waiting); |
171 | 179 | ||
172 | GNUNET_free(waiting); | 180 | GNUNET_free (waiting); |
173 | } | 181 | } |
diff --git a/src/messenger/testing_messenger_setup.c b/src/messenger/testing_messenger_setup.c index 29db25bd8..e4dfa203f 100644 --- a/src/messenger/testing_messenger_setup.c +++ b/src/messenger/testing_messenger_setup.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--2021 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 |
@@ -39,7 +39,8 @@ | |||
39 | 39 | ||
40 | struct test_properties; | 40 | struct test_properties; |
41 | 41 | ||
42 | struct test_peer { | 42 | struct test_peer |
43 | { | ||
43 | struct test_properties *props; | 44 | struct test_properties *props; |
44 | unsigned int num; | 45 | unsigned int num; |
45 | 46 | ||
@@ -58,7 +59,8 @@ struct test_peer { | |||
58 | const char *message; | 59 | const char *message; |
59 | }; | 60 | }; |
60 | 61 | ||
61 | struct test_properties { | 62 | struct test_properties |
63 | { | ||
62 | const struct test_configuration *cfg; | 64 | const struct test_configuration *cfg; |
63 | 65 | ||
64 | unsigned int num_hosts; | 66 | unsigned int num_hosts; |
@@ -83,10 +85,10 @@ shutdown_cb (void *cls) | |||
83 | { | 85 | { |
84 | struct test_peer *peer = &properties->peers[i]; | 86 | struct test_peer *peer = &properties->peers[i]; |
85 | 87 | ||
86 | GNUNET_assert(peer != NULL); | 88 | GNUNET_assert (peer != NULL); |
87 | 89 | ||
88 | if (peer->op_task) | 90 | if (peer->op_task) |
89 | GNUNET_SCHEDULER_cancel(peer->op_task); | 91 | GNUNET_SCHEDULER_cancel (peer->op_task); |
90 | 92 | ||
91 | peer->op_task = NULL; | 93 | peer->op_task = NULL; |
92 | 94 | ||
@@ -96,7 +98,7 @@ shutdown_cb (void *cls) | |||
96 | peer->op = NULL; | 98 | peer->op = NULL; |
97 | 99 | ||
98 | if (peer->wait) | 100 | if (peer->wait) |
99 | GNUNET_cancel_wait_barrier(peer->wait); | 101 | GNUNET_cancel_wait_barrier (peer->wait); |
100 | 102 | ||
101 | peer->wait = NULL; | 103 | peer->wait = NULL; |
102 | 104 | ||
@@ -115,23 +117,24 @@ shutdown_cb (void *cls) | |||
115 | } | 117 | } |
116 | 118 | ||
117 | if (properties->die_task) | 119 | if (properties->die_task) |
118 | GNUNET_SCHEDULER_cancel(properties->die_task); | 120 | GNUNET_SCHEDULER_cancel (properties->die_task); |
119 | 121 | ||
120 | properties->die_task = NULL; | 122 | properties->die_task = NULL; |
121 | properties->end_task = NULL; | 123 | properties->end_task = NULL; |
122 | 124 | ||
123 | if (properties->barrier) | 125 | if (properties->barrier) |
124 | GNUNET_cancel_barrier(properties->barrier); | 126 | GNUNET_cancel_barrier (properties->barrier); |
125 | 127 | ||
126 | properties->barrier = NULL; | 128 | properties->barrier = NULL; |
127 | } | 129 | } |
128 | 130 | ||
131 | |||
129 | static void | 132 | static void |
130 | end_cb (void *cls) | 133 | end_cb (void *cls) |
131 | { | 134 | { |
132 | struct test_properties *properties = cls; | 135 | struct test_properties *properties = cls; |
133 | 136 | ||
134 | GNUNET_assert(properties != NULL); | 137 | GNUNET_assert (properties != NULL); |
135 | 138 | ||
136 | properties->die_task = NULL; | 139 | properties->die_task = NULL; |
137 | 140 | ||
@@ -141,15 +144,17 @@ end_cb (void *cls) | |||
141 | { | 144 | { |
142 | struct test_peer *peer = &properties->peers[i]; | 145 | struct test_peer *peer = &properties->peers[i]; |
143 | 146 | ||
144 | GNUNET_assert(peer != NULL); | 147 | GNUNET_assert (peer != NULL); |
145 | 148 | ||
146 | const int members = GNUNET_MESSENGER_iterate_members(peer->room, NULL, NULL); | 149 | const int members = GNUNET_MESSENGER_iterate_members (peer->room, NULL, |
150 | NULL); | ||
147 | 151 | ||
148 | GNUNET_assert (members >= 0); | 152 | GNUNET_assert (members >= 0); |
149 | 153 | ||
150 | if (peer->props->num_peer != (unsigned int) members) | 154 | if (peer->props->num_peer != (unsigned int) members) |
151 | { | 155 | { |
152 | fprintf (stderr, "Testcase failed (members: %d/%u).\n", members, peer->props->num_peer); | 156 | fprintf (stderr, "Testcase failed (members: %d/%u).\n", members, |
157 | peer->props->num_peer); | ||
153 | status = 1; | 158 | status = 1; |
154 | break; | 159 | break; |
155 | } | 160 | } |
@@ -160,12 +165,13 @@ end_cb (void *cls) | |||
160 | properties->status = status; | 165 | properties->status = status; |
161 | } | 166 | } |
162 | 167 | ||
168 | |||
163 | static void | 169 | static void |
164 | end_badly_cb (void *cls) | 170 | end_badly_cb (void *cls) |
165 | { | 171 | { |
166 | struct test_properties *properties = cls; | 172 | struct test_properties *properties = cls; |
167 | 173 | ||
168 | GNUNET_assert(properties != NULL); | 174 | GNUNET_assert (properties != NULL); |
169 | 175 | ||
170 | fprintf (stderr, "Testcase failed (timeout).\n"); | 176 | fprintf (stderr, "Testcase failed (timeout).\n"); |
171 | 177 | ||
@@ -174,12 +180,13 @@ end_badly_cb (void *cls) | |||
174 | properties->status = 1; | 180 | properties->status = 1; |
175 | } | 181 | } |
176 | 182 | ||
183 | |||
177 | static void | 184 | static void |
178 | end_operation_cb (void *cls) | 185 | end_operation_cb (void *cls) |
179 | { | 186 | { |
180 | struct test_peer *peer = cls; | 187 | struct test_peer *peer = cls; |
181 | 188 | ||
182 | GNUNET_assert(peer != NULL); | 189 | GNUNET_assert (peer != NULL); |
183 | 190 | ||
184 | peer->op_task = NULL; | 191 | peer->op_task = NULL; |
185 | 192 | ||
@@ -188,12 +195,13 @@ end_operation_cb (void *cls) | |||
188 | GNUNET_SCHEDULER_shutdown (); | 195 | GNUNET_SCHEDULER_shutdown (); |
189 | } | 196 | } |
190 | 197 | ||
198 | |||
191 | static void | 199 | static void |
192 | end_error_cb (void *cls) | 200 | end_error_cb (void *cls) |
193 | { | 201 | { |
194 | struct test_peer *peer = cls; | 202 | struct test_peer *peer = cls; |
195 | 203 | ||
196 | GNUNET_assert(peer != NULL); | 204 | GNUNET_assert (peer != NULL); |
197 | 205 | ||
198 | peer->op_task = NULL; | 206 | peer->op_task = NULL; |
199 | 207 | ||
@@ -203,6 +211,7 @@ end_error_cb (void *cls) | |||
203 | GNUNET_SCHEDULER_shutdown (); | 211 | GNUNET_SCHEDULER_shutdown (); |
204 | } | 212 | } |
205 | 213 | ||
214 | |||
206 | static void | 215 | static void |
207 | barrier2_wait_cb (void *cls, | 216 | barrier2_wait_cb (void *cls, |
208 | struct GNUNET_BarrierWaitHandle *waiting, | 217 | struct GNUNET_BarrierWaitHandle *waiting, |
@@ -210,12 +219,13 @@ barrier2_wait_cb (void *cls, | |||
210 | { | 219 | { |
211 | struct test_peer *peer = cls; | 220 | struct test_peer *peer = cls; |
212 | 221 | ||
213 | GNUNET_assert(peer != NULL); | 222 | GNUNET_assert (peer != NULL); |
214 | 223 | ||
215 | if (peer->wait == waiting) | 224 | if (peer->wait == waiting) |
216 | peer->wait = NULL; | 225 | peer->wait = NULL; |
217 | } | 226 | } |
218 | 227 | ||
228 | |||
219 | static void | 229 | static void |
220 | barrier_wait_cb (void *cls, | 230 | barrier_wait_cb (void *cls, |
221 | struct GNUNET_BarrierWaitHandle *waiting, | 231 | struct GNUNET_BarrierWaitHandle *waiting, |
@@ -223,7 +233,7 @@ barrier_wait_cb (void *cls, | |||
223 | { | 233 | { |
224 | struct test_peer *peer = cls; | 234 | struct test_peer *peer = cls; |
225 | 235 | ||
226 | GNUNET_assert(peer != NULL); | 236 | GNUNET_assert (peer != NULL); |
227 | 237 | ||
228 | if (peer->wait == waiting) | 238 | if (peer->wait == waiting) |
229 | peer->wait = NULL; | 239 | peer->wait = NULL; |
@@ -233,7 +243,8 @@ barrier_wait_cb (void *cls, | |||
233 | unsigned int door = peer->props->cfg->doors[peer->num - 1]; | 243 | unsigned int door = peer->props->cfg->doors[peer->num - 1]; |
234 | 244 | ||
235 | if (door == 0) | 245 | if (door == 0) |
236 | door = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, peer->props->cfg->count); | 246 | door = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
247 | peer->props->cfg->count); | ||
237 | else | 248 | else |
238 | door = door - 1; | 249 | door = door - 1; |
239 | 250 | ||
@@ -241,17 +252,20 @@ barrier_wait_cb (void *cls, | |||
241 | GNUNET_CRYPTO_hash (TEST_ROOM, sizeof(TEST_ROOM), &hash); | 252 | GNUNET_CRYPTO_hash (TEST_ROOM, sizeof(TEST_ROOM), &hash); |
242 | 253 | ||
243 | struct GNUNET_MESSENGER_Room *room; | 254 | struct GNUNET_MESSENGER_Room *room; |
244 | room = GNUNET_MESSENGER_enter_room(peer->handle, &(peer->props->peers[door].peer_id), &hash); | 255 | room = GNUNET_MESSENGER_enter_room (peer->handle, |
256 | &(peer->props->peers[door].peer_id), | ||
257 | &hash); | ||
245 | 258 | ||
246 | if (peer->room) | 259 | if (peer->room) |
247 | GNUNET_assert(room == peer->room); | 260 | GNUNET_assert (room == peer->room); |
248 | else | 261 | else |
249 | GNUNET_assert(room != NULL); | 262 | GNUNET_assert (room != NULL); |
250 | 263 | ||
251 | peer->room = room; | 264 | peer->room = room; |
252 | } | 265 | } |
253 | } | 266 | } |
254 | 267 | ||
268 | |||
255 | /** | 269 | /** |
256 | * Function called whenever a message is received or sent. | 270 | * Function called whenever a message is received or sent. |
257 | * | 271 | * |
@@ -272,44 +286,48 @@ on_message (void *cls, | |||
272 | { | 286 | { |
273 | struct test_peer *peer = cls; | 287 | struct test_peer *peer = cls; |
274 | 288 | ||
275 | GNUNET_assert(peer != NULL); | 289 | GNUNET_assert (peer != NULL); |
276 | 290 | ||
277 | fprintf (stderr, "Peer: %s; [%s] Message: %s (%s)\n", | 291 | fprintf (stderr, "Peer: %s; [%s] Message: %s (%s)\n", |
278 | GNUNET_i2s(&(peer->peer_id)), | 292 | GNUNET_i2s (&(peer->peer_id)), |
279 | GNUNET_sh2s(&(message->header.sender_id)), | 293 | GNUNET_sh2s (&(message->header.sender_id)), |
280 | GNUNET_MESSENGER_name_of_kind(message->header.kind), | 294 | GNUNET_MESSENGER_name_of_kind (message->header.kind), |
281 | GNUNET_h2s(hash)); | 295 | GNUNET_h2s (hash)); |
282 | 296 | ||
283 | if (GNUNET_MESSENGER_KIND_PEER == message->header.kind) | 297 | if (GNUNET_MESSENGER_KIND_PEER == message->header.kind) |
284 | GNUNET_CONTAINER_multipeermap_put (peer->map, &(message->body.peer.peer), NULL, | 298 | GNUNET_CONTAINER_multipeermap_put (peer->map, &(message->body.peer.peer), |
299 | NULL, | ||
285 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); | 300 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); |
286 | 301 | ||
287 | const int members = GNUNET_MESSENGER_iterate_members(peer->room, NULL, NULL); | 302 | const int members = GNUNET_MESSENGER_iterate_members (peer->room, NULL, NULL); |
288 | 303 | ||
289 | const uint32_t num_peers = GNUNET_CONTAINER_multipeermap_size (peer->map); | 304 | const uint32_t num_peers = GNUNET_CONTAINER_multipeermap_size (peer->map); |
290 | if ((members == peer->props->num_peer) && (peer->props->num_hosts == num_peers)) | 305 | if ((members == peer->props->num_peer) && (peer->props->num_hosts == |
291 | peer->wait = GNUNET_wait_barrier (peer->props->barrier, &barrier2_wait_cb, peer); | 306 | num_peers)) |
307 | peer->wait = GNUNET_wait_barrier (peer->props->barrier, &barrier2_wait_cb, | ||
308 | peer); | ||
292 | else if (peer->props->num_hosts < num_peers) | 309 | else if (peer->props->num_hosts < num_peers) |
293 | { | 310 | { |
294 | if (peer->wait) | 311 | if (peer->wait) |
295 | GNUNET_cancel_wait_barrier(peer->wait); | 312 | GNUNET_cancel_wait_barrier (peer->wait); |
296 | 313 | ||
297 | peer->wait = NULL; | 314 | peer->wait = NULL; |
298 | 315 | ||
299 | if (peer->op_task) | 316 | if (peer->op_task) |
300 | GNUNET_SCHEDULER_cancel(peer->op_task); | 317 | GNUNET_SCHEDULER_cancel (peer->op_task); |
301 | 318 | ||
302 | peer->message = "peer"; | 319 | peer->message = "peer"; |
303 | peer->op_task = GNUNET_SCHEDULER_add_now (&end_operation_cb, peer); | 320 | peer->op_task = GNUNET_SCHEDULER_add_now (&end_operation_cb, peer); |
304 | } | 321 | } |
305 | } | 322 | } |
306 | 323 | ||
324 | |||
307 | static void | 325 | static void |
308 | second_stage (void *cls) | 326 | second_stage (void *cls) |
309 | { | 327 | { |
310 | struct test_peer *peer = cls; | 328 | struct test_peer *peer = cls; |
311 | 329 | ||
312 | GNUNET_assert(peer != NULL); | 330 | GNUNET_assert (peer != NULL); |
313 | 331 | ||
314 | peer->op_task = NULL; | 332 | peer->op_task = NULL; |
315 | 333 | ||
@@ -322,9 +340,9 @@ second_stage (void *cls) | |||
322 | room = GNUNET_MESSENGER_open_room (peer->handle, &hash); | 340 | room = GNUNET_MESSENGER_open_room (peer->handle, &hash); |
323 | 341 | ||
324 | if (peer->room) | 342 | if (peer->room) |
325 | GNUNET_assert(room == peer->room); | 343 | GNUNET_assert (room == peer->room); |
326 | else | 344 | else |
327 | GNUNET_assert(room != NULL); | 345 | GNUNET_assert (room != NULL); |
328 | 346 | ||
329 | peer->room = room; | 347 | peer->room = room; |
330 | } | 348 | } |
@@ -334,22 +352,26 @@ second_stage (void *cls) | |||
334 | unsigned int door = peer->props->cfg->doors[peer->num - 1]; | 352 | unsigned int door = peer->props->cfg->doors[peer->num - 1]; |
335 | 353 | ||
336 | if (door == 0) | 354 | if (door == 0) |
337 | door = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, peer->props->cfg->count); | 355 | door = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
356 | peer->props->cfg->count); | ||
338 | else | 357 | else |
339 | door = door - 1; | 358 | door = door - 1; |
340 | 359 | ||
341 | struct GNUNET_MESSENGER_Room *room; | 360 | struct GNUNET_MESSENGER_Room *room; |
342 | room = GNUNET_MESSENGER_enter_room(peer->handle, &(peer->props->peers[door].peer_id), &hash); | 361 | room = GNUNET_MESSENGER_enter_room (peer->handle, |
362 | &(peer->props->peers[door].peer_id), | ||
363 | &hash); | ||
343 | 364 | ||
344 | if (peer->room) | 365 | if (peer->room) |
345 | GNUNET_assert(room == peer->room); | 366 | GNUNET_assert (room == peer->room); |
346 | else | 367 | else |
347 | GNUNET_assert(room != NULL); | 368 | GNUNET_assert (room != NULL); |
348 | 369 | ||
349 | peer->room = room; | 370 | peer->room = room; |
350 | } | 371 | } |
351 | } | 372 | } |
352 | 373 | ||
374 | |||
353 | static void | 375 | static void |
354 | on_peer (void *cb_cls, | 376 | on_peer (void *cb_cls, |
355 | struct GNUNET_TESTBED_Operation *op, | 377 | struct GNUNET_TESTBED_Operation *op, |
@@ -358,16 +380,16 @@ on_peer (void *cb_cls, | |||
358 | { | 380 | { |
359 | struct test_peer *peer = cb_cls; | 381 | struct test_peer *peer = cb_cls; |
360 | 382 | ||
361 | GNUNET_assert(peer != NULL); | 383 | GNUNET_assert (peer != NULL); |
362 | 384 | ||
363 | if (emsg) | 385 | if (emsg) |
364 | { | 386 | { |
365 | peer->message = GNUNET_strdup(emsg); | 387 | peer->message = GNUNET_strdup (emsg); |
366 | peer->op_task = GNUNET_SCHEDULER_add_now (&end_error_cb, peer); | 388 | peer->op_task = GNUNET_SCHEDULER_add_now (&end_error_cb, peer); |
367 | return; | 389 | return; |
368 | } | 390 | } |
369 | 391 | ||
370 | if (!pinfo) | 392 | if (! pinfo) |
371 | { | 393 | { |
372 | peer->message = "info"; | 394 | peer->message = "info"; |
373 | peer->op_task = GNUNET_SCHEDULER_add_now (&end_operation_cb, peer); | 395 | peer->op_task = GNUNET_SCHEDULER_add_now (&end_operation_cb, peer); |
@@ -381,11 +403,12 @@ on_peer (void *cb_cls, | |||
381 | return; | 403 | return; |
382 | } | 404 | } |
383 | 405 | ||
384 | peer->handle = GNUNET_MESSENGER_connect (pinfo->result.cfg, TEST_NAME, NULL, &on_message, peer); | 406 | peer->handle = GNUNET_MESSENGER_connect (pinfo->result.cfg, TEST_NAME, NULL, |
407 | &on_message, peer); | ||
385 | 408 | ||
386 | GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_get_peer_identity( | 409 | GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_get_peer_identity ( |
387 | pinfo->result.cfg, &(peer->peer_id) | 410 | pinfo->result.cfg, &(peer->peer_id) |
388 | )); | 411 | )); |
389 | 412 | ||
390 | if (0 != (peer->props->cfg->stages[peer->num - 1] & 0x01)) | 413 | if (0 != (peer->props->cfg->stages[peer->num - 1] & 0x01)) |
391 | { | 414 | { |
@@ -394,14 +417,16 @@ on_peer (void *cb_cls, | |||
394 | 417 | ||
395 | peer->room = GNUNET_MESSENGER_open_room (peer->handle, &hash); | 418 | peer->room = GNUNET_MESSENGER_open_room (peer->handle, &hash); |
396 | 419 | ||
397 | GNUNET_assert(peer->room != NULL); | 420 | GNUNET_assert (peer->room != NULL); |
398 | } | 421 | } |
399 | else | 422 | else |
400 | peer->room = NULL; | 423 | peer->room = NULL; |
401 | 424 | ||
402 | peer->wait = GNUNET_wait_barrier (peer->props->barrier, &barrier_wait_cb, peer); | 425 | peer->wait = GNUNET_wait_barrier (peer->props->barrier, &barrier_wait_cb, |
426 | peer); | ||
403 | } | 427 | } |
404 | 428 | ||
429 | |||
405 | /** | 430 | /** |
406 | * Main function for a peer of the testcase. | 431 | * Main function for a peer of the testcase. |
407 | * | 432 | * |
@@ -414,7 +439,7 @@ run (void *cls, | |||
414 | { | 439 | { |
415 | struct test_properties *properties = cls; | 440 | struct test_properties *properties = cls; |
416 | 441 | ||
417 | GNUNET_assert(properties != NULL); | 442 | GNUNET_assert (properties != NULL); |
418 | 443 | ||
419 | if (GNUNET_TESTBED_ET_PEER_START != event->type) | 444 | if (GNUNET_TESTBED_ET_PEER_START != event->type) |
420 | { | 445 | { |
@@ -430,11 +455,15 @@ run (void *cls, | |||
430 | peer->num = properties->num_peer; | 455 | peer->num = properties->num_peer; |
431 | 456 | ||
432 | peer->peer = event->details.peer_start.peer; | 457 | peer->peer = event->details.peer_start.peer; |
433 | peer->op = GNUNET_TESTBED_peer_get_information (peer->peer, GNUNET_TESTBED_PIT_CONFIGURATION, on_peer, peer); | 458 | peer->op = GNUNET_TESTBED_peer_get_information (peer->peer, |
459 | GNUNET_TESTBED_PIT_CONFIGURATION, | ||
460 | on_peer, peer); | ||
434 | 461 | ||
435 | peer->map = GNUNET_CONTAINER_multipeermap_create(peer->props->num_hosts, GNUNET_NO); | 462 | peer->map = GNUNET_CONTAINER_multipeermap_create (peer->props->num_hosts, |
463 | GNUNET_NO); | ||
436 | } | 464 | } |
437 | 465 | ||
466 | |||
438 | static void | 467 | static void |
439 | barrier2_cb (void *cls, | 468 | barrier2_cb (void *cls, |
440 | struct GNUNET_BarrierHandle *barrier, | 469 | struct GNUNET_BarrierHandle *barrier, |
@@ -442,7 +471,7 @@ barrier2_cb (void *cls, | |||
442 | { | 471 | { |
443 | struct test_properties *properties = cls; | 472 | struct test_properties *properties = cls; |
444 | 473 | ||
445 | GNUNET_assert(properties != NULL); | 474 | GNUNET_assert (properties != NULL); |
446 | 475 | ||
447 | if (properties->barrier == barrier) | 476 | if (properties->barrier == barrier) |
448 | properties->barrier = NULL; | 477 | properties->barrier = NULL; |
@@ -457,15 +486,17 @@ barrier2_cb (void *cls, | |||
457 | else if (GNUNET_OK == status) | 486 | else if (GNUNET_OK == status) |
458 | { | 487 | { |
459 | if (properties->die_task) | 488 | if (properties->die_task) |
460 | GNUNET_SCHEDULER_cancel(properties->die_task); | 489 | GNUNET_SCHEDULER_cancel (properties->die_task); |
461 | 490 | ||
462 | properties->die_task = GNUNET_SCHEDULER_add_delayed ( | 491 | properties->die_task = GNUNET_SCHEDULER_add_delayed ( |
463 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, properties->cfg->count), | 492 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, |
464 | &end_cb, properties | 493 | properties->cfg->count), |
465 | ); | 494 | &end_cb, properties |
495 | ); | ||
466 | } | 496 | } |
467 | } | 497 | } |
468 | 498 | ||
499 | |||
469 | static void | 500 | static void |
470 | barrier_cb (void *cls, | 501 | barrier_cb (void *cls, |
471 | struct GNUNET_BarrierHandle *barrier, | 502 | struct GNUNET_BarrierHandle *barrier, |
@@ -473,11 +504,11 @@ barrier_cb (void *cls, | |||
473 | { | 504 | { |
474 | struct test_properties *properties = cls; | 505 | struct test_properties *properties = cls; |
475 | 506 | ||
476 | GNUNET_assert(properties != NULL); | 507 | GNUNET_assert (properties != NULL); |
477 | 508 | ||
478 | if (properties->barrier == barrier) | 509 | if (properties->barrier == barrier) |
479 | properties->barrier = NULL; | 510 | properties->barrier = NULL; |
480 | else if (!properties->barrier) | 511 | else if (! properties->barrier) |
481 | return; | 512 | return; |
482 | 513 | ||
483 | if (properties->num_peer != properties->cfg->count) | 514 | if (properties->num_peer != properties->cfg->count) |
@@ -497,13 +528,17 @@ barrier_cb (void *cls, | |||
497 | } | 528 | } |
498 | else if (GNUNET_OK == status) | 529 | else if (GNUNET_OK == status) |
499 | { | 530 | { |
500 | properties->barrier = GNUNET_init_barrier (properties->num_peer, &barrier2_cb, properties); | 531 | properties->barrier = GNUNET_init_barrier (properties->num_peer, |
532 | &barrier2_cb, properties); | ||
501 | 533 | ||
502 | for (unsigned int i = 0; i < properties->num_peer; i++) | 534 | for (unsigned int i = 0; i < properties->num_peer; i++) |
503 | properties->peers[i].op_task = GNUNET_SCHEDULER_add_now (&second_stage, &(properties->peers[i])); | 535 | properties->peers[i].op_task = GNUNET_SCHEDULER_add_now (&second_stage, |
536 | &(properties-> | ||
537 | peers[i])); | ||
504 | } | 538 | } |
505 | } | 539 | } |
506 | 540 | ||
541 | |||
507 | static void | 542 | static void |
508 | init (void *cls, | 543 | init (void *cls, |
509 | struct GNUNET_TESTBED_RunHandle *h, | 544 | struct GNUNET_TESTBED_RunHandle *h, |
@@ -514,40 +549,46 @@ init (void *cls, | |||
514 | { | 549 | { |
515 | struct test_properties *properties = cls; | 550 | struct test_properties *properties = cls; |
516 | 551 | ||
517 | GNUNET_assert(properties != NULL); | 552 | GNUNET_assert (properties != NULL); |
518 | 553 | ||
519 | properties->end_task = GNUNET_SCHEDULER_add_shutdown(&shutdown_cb, properties); | 554 | properties->end_task = GNUNET_SCHEDULER_add_shutdown (&shutdown_cb, |
555 | properties); | ||
520 | properties->die_task = GNUNET_SCHEDULER_add_delayed ( | 556 | properties->die_task = GNUNET_SCHEDULER_add_delayed ( |
521 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, properties->cfg->count * 5), | 557 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, |
522 | &end_badly_cb, properties | 558 | properties->cfg->count * 5), |
523 | ); | 559 | &end_badly_cb, properties |
560 | ); | ||
524 | } | 561 | } |
525 | 562 | ||
563 | |||
526 | int | 564 | int |
527 | GNUNET_run_messenger_setup (const char* test_name, | 565 | GNUNET_run_messenger_setup (const char *test_name, |
528 | const struct test_configuration *cfg) | 566 | const struct test_configuration *cfg) |
529 | { | 567 | { |
530 | struct test_properties properties; | 568 | struct test_properties properties; |
531 | memset(&properties, 0, sizeof(properties)); | 569 | memset (&properties, 0, sizeof(properties)); |
532 | 570 | ||
533 | properties.cfg = cfg; | 571 | properties.cfg = cfg; |
534 | properties.peers = GNUNET_new_array(cfg->count, struct test_peer); | 572 | properties.peers = GNUNET_new_array (cfg->count, struct test_peer); |
535 | 573 | ||
536 | for (unsigned int i = 0; i < cfg->count; i++) | 574 | for (unsigned int i = 0; i < cfg->count; i++) |
537 | if (0 != (cfg->stages[i] & 0x11)) | 575 | if (0 != (cfg->stages[i] & 0x11)) |
538 | properties.num_hosts++; | 576 | properties.num_hosts++; |
539 | 577 | ||
540 | properties.status = 1; | 578 | properties.status = 1; |
541 | properties.barrier = GNUNET_init_barrier (cfg->count, &barrier_cb, &properties); | 579 | properties.barrier = GNUNET_init_barrier (cfg->count, &barrier_cb, |
580 | &properties); | ||
542 | 581 | ||
543 | if (GNUNET_OK != GNUNET_TESTBED_test_run (test_name, "test_messenger_api.conf", | 582 | if (GNUNET_OK != GNUNET_TESTBED_test_run (test_name, |
583 | "test_messenger_api.conf", | ||
544 | cfg->count, | 584 | cfg->count, |
545 | (1LL << GNUNET_TESTBED_ET_PEER_START), | 585 | (1LL << |
586 | GNUNET_TESTBED_ET_PEER_START), | ||
546 | &run, &properties, | 587 | &run, &properties, |
547 | &init, &properties)) | 588 | &init, &properties)) |
548 | return 1; | 589 | return 1; |
549 | 590 | ||
550 | GNUNET_free(properties.peers); | 591 | GNUNET_free (properties.peers); |
551 | 592 | ||
552 | return properties.status; | 593 | return properties.status; |
553 | } | 594 | } |
diff --git a/src/messenger/testing_messenger_setup.h b/src/messenger/testing_messenger_setup.h index e5ae0c151..d2e72b51f 100644 --- a/src/messenger/testing_messenger_setup.h +++ b/src/messenger/testing_messenger_setup.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2021 GNUnet e.V. | 3 | Copyright (C) 2021, 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 |
@@ -34,7 +34,7 @@ struct test_configuration | |||
34 | }; | 34 | }; |
35 | 35 | ||
36 | int | 36 | int |
37 | GNUNET_run_messenger_setup (const char* test_name, | 37 | GNUNET_run_messenger_setup (const char *test_name, |
38 | const struct test_configuration *cfg); | 38 | const struct test_configuration *cfg); |
39 | 39 | ||
40 | #endif /* GNUNET_TESTING_MESSENGER_SETUP_H_ */ | 40 | #endif /* GNUNET_TESTING_MESSENGER_SETUP_H_ */ |