aboutsummaryrefslogtreecommitdiff
path: root/src/messenger/gnunet-service-messenger.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/messenger/gnunet-service-messenger.c')
-rw-r--r--src/messenger/gnunet-service-messenger.c71
1 files changed, 50 insertions, 21 deletions
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
53static void 54static void
54handle_destroy (void *cls, 55handle_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
64static int 66static int
65check_room_initial_key (const struct GNUNET_MESSENGER_RoomMessage *msg) 67check_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
87static void 92static void
88initialize_handle_via_key (struct GNUNET_MESSENGER_SrvHandle *handle, 93initialize_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
111static int 121static int
112check_room_open (void *cls, 122check_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
118static void 129static void
119handle_room_open (void *cls, 130handle_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
151static int 163static int
152check_room_entry (void *cls, 164check_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
158static void 171static void
159handle_room_entry (void *cls, 172handle_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
194static void 208static void
195handle_room_close (void *cls, 209handle_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
222static int 237static int
223check_send_message (void *cls, 238check_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
249static void 267static void
250handle_send_message (void *cls, 268handle_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: 290end_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
278static void 297static void
279callback_found_message (void *cls, 298callback_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
331static void 354static void
332handle_get_message (void *cls, 355handle_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: 413end_handling:
390 GNUNET_SERVICE_client_continue (msg_client->client); 414 GNUNET_SERVICE_client_continue (msg_client->client);
391} 415}
392 416
417
393static void* 418static void*
394callback_client_connect (void *cls, 419callback_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
407static void 433static void
408callback_client_disconnect (void *cls, 434callback_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,