diff options
Diffstat (limited to 'src/chat/gnunet-service-chat.c')
-rw-r--r-- | src/chat/gnunet-service-chat.c | 266 |
1 files changed, 113 insertions, 153 deletions
diff --git a/src/chat/gnunet-service-chat.c b/src/chat/gnunet-service-chat.c index 7afa18d68..e04d8d099 100644 --- a/src/chat/gnunet-service-chat.c +++ b/src/chat/gnunet-service-chat.c | |||
@@ -254,18 +254,15 @@ send_message_noficiation (void *cls, const GNUNET_HashCode * key, void *value) | |||
254 | 254 | ||
255 | GNUNET_PEER_resolve (cp->pid, &pid); | 255 | GNUNET_PEER_resolve (cp->pid, &pid); |
256 | #if DEBUG_CHAT_SERVICE | 256 | #if DEBUG_CHAT_SERVICE |
257 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 257 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message notification to `%s'\n", |
258 | "Sending message notification to `%s'\n", GNUNET_i2s (&pid)); | 258 | GNUNET_i2s (&pid)); |
259 | #endif | 259 | #endif |
260 | my_msg = GNUNET_memdup (msg, ntohs (msg->header.size)); | 260 | my_msg = GNUNET_memdup (msg, ntohs (msg->header.size)); |
261 | if (NULL == GNUNET_CORE_notify_transmit_ready (core, | 261 | if (NULL == |
262 | GNUNET_NO, | 262 | GNUNET_CORE_notify_transmit_ready (core, GNUNET_NO, 1, MAX_TRANSMIT_DELAY, |
263 | 1, | 263 | &pid, ntohs (msg->header.size), |
264 | MAX_TRANSMIT_DELAY, | 264 | &transmit_message_notification_to_peer, |
265 | &pid, | 265 | my_msg)) |
266 | ntohs (msg->header.size), | ||
267 | &transmit_message_notification_to_peer, | ||
268 | my_msg)) | ||
269 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 266 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
270 | _("Failed to queue a message notification\n")); | 267 | _("Failed to queue a message notification\n")); |
271 | return GNUNET_YES; | 268 | return GNUNET_YES; |
@@ -281,8 +278,7 @@ send_message_noficiation (void *cls, const GNUNET_HashCode * key, void *value) | |||
281 | * @param message the actual message | 278 | * @param message the actual message |
282 | */ | 279 | */ |
283 | static void | 280 | static void |
284 | handle_transmit_request (void *cls, | 281 | handle_transmit_request (void *cls, struct GNUNET_SERVER_Client *client, |
285 | struct GNUNET_SERVER_Client *client, | ||
286 | const struct GNUNET_MessageHeader *message) | 282 | const struct GNUNET_MessageHeader *message) |
287 | { | 283 | { |
288 | static GNUNET_HashCode all_zeros; | 284 | static GNUNET_HashCode all_zeros; |
@@ -316,12 +312,11 @@ handle_transmit_request (void *cls, | |||
316 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting the message text\n"); | 312 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting the message text\n"); |
317 | #endif | 313 | #endif |
318 | GNUNET_CRYPTO_aes_create_session_key (&key); | 314 | GNUNET_CRYPTO_aes_create_session_key (&key); |
319 | msg_len = GNUNET_CRYPTO_aes_encrypt (&trmsg[1], | 315 | msg_len = |
320 | msg_len, | 316 | GNUNET_CRYPTO_aes_encrypt (&trmsg[1], msg_len, &key, |
321 | &key, | 317 | (const struct |
322 | (const struct | 318 | GNUNET_CRYPTO_AesInitializationVector *) |
323 | GNUNET_CRYPTO_AesInitializationVector | 319 | INITVALUE, encrypted_msg); |
324 | *) INITVALUE, encrypted_msg); | ||
325 | if (-1 == msg_len) | 320 | if (-1 == msg_len) |
326 | { | 321 | { |
327 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 322 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -332,8 +327,8 @@ handle_transmit_request (void *cls, | |||
332 | } | 327 | } |
333 | } | 328 | } |
334 | rnmsg = GNUNET_malloc (sizeof (struct ReceiveNotificationMessage) + msg_len); | 329 | rnmsg = GNUNET_malloc (sizeof (struct ReceiveNotificationMessage) + msg_len); |
335 | rnmsg->header.size = htons (sizeof (struct ReceiveNotificationMessage) + | 330 | rnmsg->header.size = |
336 | msg_len); | 331 | htons (sizeof (struct ReceiveNotificationMessage) + msg_len); |
337 | rnmsg->header.type = htons (GNUNET_MESSAGE_TYPE_CHAT_MESSAGE_NOTIFICATION); | 332 | rnmsg->header.type = htons (GNUNET_MESSAGE_TYPE_CHAT_MESSAGE_NOTIFICATION); |
338 | rnmsg->msg_options = trmsg->msg_options; | 333 | rnmsg->msg_options = trmsg->msg_options; |
339 | rnmsg->timestamp = trmsg->timestamp; | 334 | rnmsg->timestamp = trmsg->timestamp; |
@@ -382,8 +377,8 @@ handle_transmit_request (void *cls, | |||
382 | memcpy (&rnmsg[1], encrypted_msg, msg_len); | 377 | memcpy (&rnmsg[1], encrypted_msg, msg_len); |
383 | target = client_list_head; | 378 | target = client_list_head; |
384 | while ((NULL != target) && | 379 | while ((NULL != target) && |
385 | (0 != memcmp (&target->id, | 380 | (0 != |
386 | &trmsg->target, sizeof (GNUNET_HashCode)))) | 381 | memcmp (&target->id, &trmsg->target, sizeof (GNUNET_HashCode)))) |
387 | target = target->next; | 382 | target = target->next; |
388 | if (NULL == target) | 383 | if (NULL == target) |
389 | { | 384 | { |
@@ -394,11 +389,10 @@ handle_transmit_request (void *cls, | |||
394 | GNUNET_free (rnmsg); | 389 | GNUNET_free (rnmsg); |
395 | return; | 390 | return; |
396 | } | 391 | } |
397 | if (GNUNET_SYSERR == GNUNET_CRYPTO_rsa_encrypt (&key, | 392 | if (GNUNET_SYSERR == |
398 | sizeof (struct | 393 | GNUNET_CRYPTO_rsa_encrypt (&key, |
399 | GNUNET_CRYPTO_AesSessionKey), | 394 | sizeof (struct GNUNET_CRYPTO_AesSessionKey), |
400 | &target->public_key, | 395 | &target->public_key, &rnmsg->encrypted_key)) |
401 | &rnmsg->encrypted_key)) | ||
402 | { | 396 | { |
403 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 397 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
404 | "Could not encrypt the session key\n"); | 398 | "Could not encrypt the session key\n"); |
@@ -419,17 +413,14 @@ handle_transmit_request (void *cls, | |||
419 | #endif | 413 | #endif |
420 | while (NULL != pos) | 414 | while (NULL != pos) |
421 | { | 415 | { |
422 | if ((0 == strcmp (room, pos->room)) && | 416 | if ((0 == strcmp (room, pos->room)) && (NULL != pos->client) && |
423 | (NULL != pos->client) && (pos->client != client)) | 417 | (pos->client != client)) |
424 | { | 418 | { |
425 | if (((!is_priv) || | 419 | if (((!is_priv) || |
426 | (0 == memcmp (&trmsg->target, | 420 | (0 == memcmp (&trmsg->target, &pos->id, sizeof (GNUNET_HashCode)))) |
427 | &pos->id, | 421 | && (0 == (ntohl (trmsg->msg_options) & (~pos->msg_options)))) |
428 | sizeof (GNUNET_HashCode)))) && | ||
429 | (0 == (ntohl (trmsg->msg_options) & (~pos->msg_options)))) | ||
430 | { | 422 | { |
431 | GNUNET_SERVER_notification_context_unicast (nc, | 423 | GNUNET_SERVER_notification_context_unicast (nc, pos->client, |
432 | pos->client, | ||
433 | &rnmsg->header, GNUNET_NO); | 424 | &rnmsg->header, GNUNET_NO); |
434 | } | 425 | } |
435 | } | 426 | } |
@@ -442,8 +433,9 @@ handle_transmit_request (void *cls, | |||
442 | if (is_anon) | 433 | if (is_anon) |
443 | { | 434 | { |
444 | room_len = strlen (room); | 435 | room_len = strlen (room); |
445 | p2p_rnmsg = GNUNET_malloc (sizeof (struct P2PReceiveNotificationMessage) + | 436 | p2p_rnmsg = |
446 | msg_len + room_len); | 437 | GNUNET_malloc (sizeof (struct P2PReceiveNotificationMessage) + msg_len + |
438 | room_len); | ||
447 | p2p_rnmsg->header.size = | 439 | p2p_rnmsg->header.size = |
448 | htons (sizeof (struct P2PReceiveNotificationMessage) + msg_len + | 440 | htons (sizeof (struct P2PReceiveNotificationMessage) + msg_len + |
449 | room_len); | 441 | room_len); |
@@ -453,15 +445,14 @@ handle_transmit_request (void *cls, | |||
453 | } | 445 | } |
454 | else | 446 | else |
455 | { | 447 | { |
456 | p2p_rnmsg = GNUNET_malloc (sizeof (struct P2PReceiveNotificationMessage) + | 448 | p2p_rnmsg = |
457 | msg_len); | 449 | GNUNET_malloc (sizeof (struct P2PReceiveNotificationMessage) + msg_len); |
458 | p2p_rnmsg->header.size = | 450 | p2p_rnmsg->header.size = |
459 | htons (sizeof (struct P2PReceiveNotificationMessage) + msg_len); | 451 | htons (sizeof (struct P2PReceiveNotificationMessage) + msg_len); |
460 | if (is_priv) | 452 | if (is_priv) |
461 | { | 453 | { |
462 | memcpy (&p2p_rnmsg[1], encrypted_msg, msg_len); | 454 | memcpy (&p2p_rnmsg[1], encrypted_msg, msg_len); |
463 | memcpy (&p2p_rnmsg->encrypted_key, | 455 | memcpy (&p2p_rnmsg->encrypted_key, &rnmsg->encrypted_key, |
464 | &rnmsg->encrypted_key, | ||
465 | sizeof (struct GNUNET_CRYPTO_RsaEncryptedData)); | 456 | sizeof (struct GNUNET_CRYPTO_RsaEncryptedData)); |
466 | } | 457 | } |
467 | else | 458 | else |
@@ -540,19 +531,17 @@ send_join_noficiation (void *cls, const GNUNET_HashCode * key, void *value) | |||
540 | 531 | ||
541 | GNUNET_PEER_resolve (cp->pid, &pid); | 532 | GNUNET_PEER_resolve (cp->pid, &pid); |
542 | #if DEBUG_CHAT_SERVICE | 533 | #if DEBUG_CHAT_SERVICE |
543 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 534 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending join notification to `%s'\n", |
544 | "Sending join notification to `%s'\n", GNUNET_i2s (&pid)); | 535 | GNUNET_i2s (&pid)); |
545 | #endif | 536 | #endif |
546 | msg_size = sizeof (struct P2PJoinNotificationMessage) + | 537 | msg_size = |
547 | strlen (entry->room) + entry->meta_len; | 538 | sizeof (struct P2PJoinNotificationMessage) + strlen (entry->room) + |
548 | if (NULL == GNUNET_CORE_notify_transmit_ready (core, | 539 | entry->meta_len; |
549 | GNUNET_NO, | 540 | if (NULL == |
550 | 1, | 541 | GNUNET_CORE_notify_transmit_ready (core, GNUNET_NO, 1, MAX_TRANSMIT_DELAY, |
551 | MAX_TRANSMIT_DELAY, | 542 | &pid, msg_size, |
552 | &pid, | 543 | &transmit_join_notification_to_peer, |
553 | msg_size, | 544 | entry)) |
554 | &transmit_join_notification_to_peer, | ||
555 | entry)) | ||
556 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 545 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
557 | _("Failed to queue a join notification\n")); | 546 | _("Failed to queue a join notification\n")); |
558 | return GNUNET_YES; | 547 | return GNUNET_YES; |
@@ -568,8 +557,7 @@ send_join_noficiation (void *cls, const GNUNET_HashCode * key, void *value) | |||
568 | * @param message the actual message | 557 | * @param message the actual message |
569 | */ | 558 | */ |
570 | static void | 559 | static void |
571 | handle_join_request (void *cls, | 560 | handle_join_request (void *cls, struct GNUNET_SERVER_Client *client, |
572 | struct GNUNET_SERVER_Client *client, | ||
573 | const struct GNUNET_MessageHeader *message) | 561 | const struct GNUNET_MessageHeader *message) |
574 | { | 562 | { |
575 | const struct JoinRequestMessage *jrmsg; | 563 | const struct JoinRequestMessage *jrmsg; |
@@ -644,8 +632,7 @@ handle_join_request (void *cls, | |||
644 | if (0 == strcmp (room_name, entry->room)) | 632 | if (0 == strcmp (room_name, entry->room)) |
645 | { | 633 | { |
646 | if (NULL != entry->client) | 634 | if (NULL != entry->client) |
647 | GNUNET_SERVER_notification_context_unicast (nc, | 635 | GNUNET_SERVER_notification_context_unicast (nc, entry->client, |
648 | entry->client, | ||
649 | &jnmsg->header, GNUNET_NO); | 636 | &jnmsg->header, GNUNET_NO); |
650 | if (entry->client != client) | 637 | if (entry->client != client) |
651 | { | 638 | { |
@@ -659,8 +646,7 @@ handle_join_request (void *cls, | |||
659 | entry_jnmsg->msg_options = entry->msg_options; | 646 | entry_jnmsg->msg_options = entry->msg_options; |
660 | entry_jnmsg->public_key = entry->public_key; | 647 | entry_jnmsg->public_key = entry->public_key; |
661 | memcpy (&entry_jnmsg[1], entry->member_info, entry->meta_len); | 648 | memcpy (&entry_jnmsg[1], entry->member_info, entry->meta_len); |
662 | GNUNET_SERVER_notification_context_unicast (nc, | 649 | GNUNET_SERVER_notification_context_unicast (nc, client, |
663 | client, | ||
664 | &entry_jnmsg->header, | 650 | &entry_jnmsg->header, |
665 | GNUNET_NO); | 651 | GNUNET_NO); |
666 | GNUNET_free (entry_jnmsg); | 652 | GNUNET_free (entry_jnmsg); |
@@ -728,20 +714,17 @@ send_confirmation_receipt (void *cls, const GNUNET_HashCode * key, void *value) | |||
728 | 714 | ||
729 | GNUNET_PEER_resolve (cp->pid, &pid); | 715 | GNUNET_PEER_resolve (cp->pid, &pid); |
730 | #if DEBUG_CHAT_SERVICE | 716 | #if DEBUG_CHAT_SERVICE |
731 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 717 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending confirmation receipt to `%s'\n", |
732 | "Sending confirmation receipt to `%s'\n", GNUNET_i2s (&pid)); | 718 | GNUNET_i2s (&pid)); |
733 | #endif | 719 | #endif |
734 | msg_size = sizeof (struct P2PConfirmationReceiptMessage); | 720 | msg_size = sizeof (struct P2PConfirmationReceiptMessage); |
735 | my_receipt = GNUNET_memdup (receipt, | 721 | my_receipt = |
736 | sizeof (struct P2PConfirmationReceiptMessage)); | 722 | GNUNET_memdup (receipt, sizeof (struct P2PConfirmationReceiptMessage)); |
737 | if (NULL == GNUNET_CORE_notify_transmit_ready (core, | 723 | if (NULL == |
738 | GNUNET_YES, | 724 | GNUNET_CORE_notify_transmit_ready (core, GNUNET_YES, 1, |
739 | 1, | 725 | MAX_TRANSMIT_DELAY, &pid, msg_size, |
740 | MAX_TRANSMIT_DELAY, | 726 | &transmit_confirmation_receipt_to_peer, |
741 | &pid, | 727 | my_receipt)) |
742 | msg_size, | ||
743 | &transmit_confirmation_receipt_to_peer, | ||
744 | my_receipt)) | ||
745 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 728 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
746 | _("Failed to queue a confirmation receipt\n")); | 729 | _("Failed to queue a confirmation receipt\n")); |
747 | return GNUNET_YES; | 730 | return GNUNET_YES; |
@@ -758,8 +741,7 @@ send_confirmation_receipt (void *cls, const GNUNET_HashCode * key, void *value) | |||
758 | * @param message the actual message | 741 | * @param message the actual message |
759 | */ | 742 | */ |
760 | static void | 743 | static void |
761 | handle_acknowledge_request (void *cls, | 744 | handle_acknowledge_request (void *cls, struct GNUNET_SERVER_Client *client, |
762 | struct GNUNET_SERVER_Client *client, | ||
763 | const struct GNUNET_MessageHeader *message) | 745 | const struct GNUNET_MessageHeader *message) |
764 | { | 746 | { |
765 | const struct ConfirmationReceiptMessage *receipt; | 747 | const struct ConfirmationReceiptMessage *receipt; |
@@ -772,8 +754,8 @@ handle_acknowledge_request (void *cls, | |||
772 | receipt = (const struct ConfirmationReceiptMessage *) message; | 754 | receipt = (const struct ConfirmationReceiptMessage *) message; |
773 | author = client_list_head; | 755 | author = client_list_head; |
774 | while ((NULL != author) && | 756 | while ((NULL != author) && |
775 | (0 != memcmp (&receipt->author, | 757 | (0 != |
776 | &author->id, sizeof (GNUNET_HashCode)))) | 758 | memcmp (&receipt->author, &author->id, sizeof (GNUNET_HashCode)))) |
777 | author = author->next; | 759 | author = author->next; |
778 | if (NULL == author) | 760 | if (NULL == author) |
779 | { | 761 | { |
@@ -785,8 +767,8 @@ handle_acknowledge_request (void *cls, | |||
785 | } | 767 | } |
786 | target = client_list_head; | 768 | target = client_list_head; |
787 | while ((NULL != target) && | 769 | while ((NULL != target) && |
788 | (0 != memcmp (&receipt->target, | 770 | (0 != |
789 | &target->id, sizeof (GNUNET_HashCode)))) | 771 | memcmp (&receipt->target, &target->id, sizeof (GNUNET_HashCode)))) |
790 | target = target->next; | 772 | target = target->next; |
791 | if (NULL == target) | 773 | if (NULL == target) |
792 | { | 774 | { |
@@ -831,8 +813,8 @@ handle_acknowledge_request (void *cls, | |||
831 | #endif | 813 | #endif |
832 | if (GNUNET_OK != | 814 | if (GNUNET_OK != |
833 | GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT, | 815 | GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT, |
834 | &receipt->purpose, | 816 | &receipt->purpose, &receipt->signature, |
835 | &receipt->signature, &target->public_key)) | 817 | &target->public_key)) |
836 | { | 818 | { |
837 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 819 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
838 | "Invalid signature of the receipt\n"); | 820 | "Invalid signature of the receipt\n"); |
@@ -909,13 +891,13 @@ send_leave_noficiation (void *cls, const GNUNET_HashCode * key, void *value) | |||
909 | 891 | ||
910 | GNUNET_PEER_resolve (cp->pid, &pid); | 892 | GNUNET_PEER_resolve (cp->pid, &pid); |
911 | #if DEBUG_CHAT_SERVICE | 893 | #if DEBUG_CHAT_SERVICE |
912 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 894 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending leave notification to `%s'\n", |
913 | "Sending leave notification to `%s'\n", GNUNET_i2s (&pid)); | 895 | GNUNET_i2s (&pid)); |
914 | #endif | 896 | #endif |
915 | msg_size = sizeof (struct P2PLeaveNotificationMessage); | 897 | msg_size = sizeof (struct P2PLeaveNotificationMessage); |
916 | public_key = GNUNET_memdup (&entry->public_key, | 898 | public_key = |
917 | sizeof (struct | 899 | GNUNET_memdup (&entry->public_key, |
918 | GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); | 900 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); |
919 | if (NULL == | 901 | if (NULL == |
920 | GNUNET_CORE_notify_transmit_ready (core, GNUNET_YES, 1, | 902 | GNUNET_CORE_notify_transmit_ready (core, GNUNET_YES, 1, |
921 | MAX_TRANSMIT_DELAY, &pid, msg_size, | 903 | MAX_TRANSMIT_DELAY, &pid, msg_size, |
@@ -975,8 +957,7 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | |||
975 | { | 957 | { |
976 | if ((0 == strcmp (pos->room, entry->room)) && (NULL != entry->client)) | 958 | if ((0 == strcmp (pos->room, entry->room)) && (NULL != entry->client)) |
977 | { | 959 | { |
978 | GNUNET_SERVER_notification_context_unicast (nc, | 960 | GNUNET_SERVER_notification_context_unicast (nc, entry->client, |
979 | entry->client, | ||
980 | &lnmsg.header, GNUNET_NO); | 961 | &lnmsg.header, GNUNET_NO); |
981 | } | 962 | } |
982 | entry = entry->next; | 963 | entry = entry->next; |
@@ -1093,8 +1074,7 @@ handle_p2p_join_notification (void *cls, | |||
1093 | { | 1074 | { |
1094 | if ((0 == strcmp (room_name, entry->room)) && (NULL != entry->client)) | 1075 | if ((0 == strcmp (room_name, entry->room)) && (NULL != entry->client)) |
1095 | { | 1076 | { |
1096 | GNUNET_SERVER_notification_context_unicast (nc, | 1077 | GNUNET_SERVER_notification_context_unicast (nc, entry->client, |
1097 | entry->client, | ||
1098 | &jnmsg->header, GNUNET_NO); | 1078 | &jnmsg->header, GNUNET_NO); |
1099 | } | 1079 | } |
1100 | entry = entry->next; | 1080 | entry = entry->next; |
@@ -1173,8 +1153,7 @@ handle_p2p_leave_notification (void *cls, | |||
1173 | { | 1153 | { |
1174 | if (0 == strcmp (pos->room, entry->room) && (NULL != entry->client)) | 1154 | if (0 == strcmp (pos->room, entry->room) && (NULL != entry->client)) |
1175 | { | 1155 | { |
1176 | GNUNET_SERVER_notification_context_unicast (nc, | 1156 | GNUNET_SERVER_notification_context_unicast (nc, entry->client, |
1177 | entry->client, | ||
1178 | &lnmsg.header, GNUNET_NO); | 1157 | &lnmsg.header, GNUNET_NO); |
1179 | } | 1158 | } |
1180 | entry = entry->next; | 1159 | entry = entry->next; |
@@ -1230,7 +1209,8 @@ handle_p2p_message_notification (void *cls, | |||
1230 | return GNUNET_SYSERR; | 1209 | return GNUNET_SYSERR; |
1231 | } | 1210 | } |
1232 | p2p_rnmsg = (const struct P2PReceiveNotificationMessage *) message; | 1211 | p2p_rnmsg = (const struct P2PReceiveNotificationMessage *) message; |
1233 | msg_len = ntohs (p2p_rnmsg->header.size) - | 1212 | msg_len = |
1213 | ntohs (p2p_rnmsg->header.size) - | ||
1234 | sizeof (struct P2PReceiveNotificationMessage); | 1214 | sizeof (struct P2PReceiveNotificationMessage); |
1235 | 1215 | ||
1236 | is_anon = (0 != (ntohl (p2p_rnmsg->msg_options) & GNUNET_CHAT_MSG_ANONYMOUS)); | 1216 | is_anon = (0 != (ntohl (p2p_rnmsg->msg_options) & GNUNET_CHAT_MSG_ANONYMOUS)); |
@@ -1263,8 +1243,8 @@ handle_p2p_message_notification (void *cls, | |||
1263 | { | 1243 | { |
1264 | sender = client_list_head; | 1244 | sender = client_list_head; |
1265 | while ((NULL != sender) && | 1245 | while ((NULL != sender) && |
1266 | (0 != memcmp (&sender->id, | 1246 | (0 != |
1267 | &p2p_rnmsg->sender, sizeof (GNUNET_HashCode)))) | 1247 | memcmp (&sender->id, &p2p_rnmsg->sender, sizeof (GNUNET_HashCode)))) |
1268 | sender = sender->next; | 1248 | sender = sender->next; |
1269 | if (NULL == sender) | 1249 | if (NULL == sender) |
1270 | { | 1250 | { |
@@ -1297,18 +1277,17 @@ handle_p2p_message_notification (void *cls, | |||
1297 | "Sending message to local room members\n"); | 1277 | "Sending message to local room members\n"); |
1298 | #endif | 1278 | #endif |
1299 | rnmsg = GNUNET_malloc (sizeof (struct ReceiveNotificationMessage) + msg_len); | 1279 | rnmsg = GNUNET_malloc (sizeof (struct ReceiveNotificationMessage) + msg_len); |
1300 | rnmsg->header.size = htons (sizeof (struct ReceiveNotificationMessage) + | 1280 | rnmsg->header.size = |
1301 | msg_len); | 1281 | htons (sizeof (struct ReceiveNotificationMessage) + msg_len); |
1302 | rnmsg->header.type = htons (GNUNET_MESSAGE_TYPE_CHAT_MESSAGE_NOTIFICATION); | 1282 | rnmsg->header.type = htons (GNUNET_MESSAGE_TYPE_CHAT_MESSAGE_NOTIFICATION); |
1303 | rnmsg->msg_options = p2p_rnmsg->msg_options; | 1283 | rnmsg->msg_options = p2p_rnmsg->msg_options; |
1304 | rnmsg->sequence_number = p2p_rnmsg->sequence_number; | 1284 | rnmsg->sequence_number = p2p_rnmsg->sequence_number; |
1305 | rnmsg->reserved = htonl (0); | 1285 | rnmsg->reserved = htonl (0); |
1306 | rnmsg->timestamp = p2p_rnmsg->timestamp; | 1286 | rnmsg->timestamp = p2p_rnmsg->timestamp; |
1307 | is_priv = (0 != memcmp (&all_zeros, | 1287 | is_priv = |
1308 | &p2p_rnmsg->target, sizeof (GNUNET_HashCode))); | 1288 | (0 != memcmp (&all_zeros, &p2p_rnmsg->target, sizeof (GNUNET_HashCode))); |
1309 | if (is_priv) | 1289 | if (is_priv) |
1310 | memcpy (&rnmsg->encrypted_key, | 1290 | memcpy (&rnmsg->encrypted_key, &p2p_rnmsg->encrypted_key, |
1311 | &p2p_rnmsg->encrypted_key, | ||
1312 | sizeof (struct GNUNET_CRYPTO_RsaEncryptedData)); | 1291 | sizeof (struct GNUNET_CRYPTO_RsaEncryptedData)); |
1313 | rnmsg->sender = p2p_rnmsg->sender; | 1292 | rnmsg->sender = p2p_rnmsg->sender; |
1314 | memcpy (&rnmsg[1], text, msg_len); | 1293 | memcpy (&rnmsg[1], text, msg_len); |
@@ -1318,13 +1297,11 @@ handle_p2p_message_notification (void *cls, | |||
1318 | if ((0 == strcmp (room_name, pos->room)) && (NULL != pos->client)) | 1297 | if ((0 == strcmp (room_name, pos->room)) && (NULL != pos->client)) |
1319 | { | 1298 | { |
1320 | if (((!is_priv) || | 1299 | if (((!is_priv) || |
1321 | (0 == memcmp (&p2p_rnmsg->target, | 1300 | (0 == |
1322 | &pos->id, | 1301 | memcmp (&p2p_rnmsg->target, &pos->id, sizeof (GNUNET_HashCode)))) && |
1323 | sizeof (GNUNET_HashCode)))) && | ||
1324 | (0 == (ntohl (p2p_rnmsg->msg_options) & (~pos->msg_options)))) | 1302 | (0 == (ntohl (p2p_rnmsg->msg_options) & (~pos->msg_options)))) |
1325 | { | 1303 | { |
1326 | GNUNET_SERVER_notification_context_unicast (nc, | 1304 | GNUNET_SERVER_notification_context_unicast (nc, pos->client, |
1327 | pos->client, | ||
1328 | &rnmsg->header, GNUNET_NO); | 1305 | &rnmsg->header, GNUNET_NO); |
1329 | } | 1306 | } |
1330 | } | 1307 | } |
@@ -1356,8 +1333,7 @@ handle_p2p_message_notification (void *cls, | |||
1356 | * GNUNET_SYSERR to close it (signal serious error) | 1333 | * GNUNET_SYSERR to close it (signal serious error) |
1357 | */ | 1334 | */ |
1358 | static int | 1335 | static int |
1359 | handle_p2p_sync_request (void *cls, | 1336 | handle_p2p_sync_request (void *cls, const struct GNUNET_PeerIdentity *other, |
1360 | const struct GNUNET_PeerIdentity *other, | ||
1361 | const struct GNUNET_MessageHeader *message, | 1337 | const struct GNUNET_MessageHeader *message, |
1362 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 1338 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
1363 | { | 1339 | { |
@@ -1373,14 +1349,11 @@ handle_p2p_sync_request (void *cls, | |||
1373 | entry = client_list_head; | 1349 | entry = client_list_head; |
1374 | while (NULL != entry) | 1350 | while (NULL != entry) |
1375 | { | 1351 | { |
1376 | msg_size = sizeof (struct P2PJoinNotificationMessage) + | 1352 | msg_size = |
1377 | strlen (entry->room) + entry->meta_len; | 1353 | sizeof (struct P2PJoinNotificationMessage) + strlen (entry->room) + |
1378 | th = GNUNET_CORE_notify_transmit_ready (core, | 1354 | entry->meta_len; |
1379 | GNUNET_NO, | 1355 | th = GNUNET_CORE_notify_transmit_ready (core, GNUNET_NO, 1, |
1380 | 1, | 1356 | MAX_TRANSMIT_DELAY, other, msg_size, |
1381 | MAX_TRANSMIT_DELAY, | ||
1382 | other, | ||
1383 | msg_size, | ||
1384 | &transmit_join_notification_to_peer, | 1357 | &transmit_join_notification_to_peer, |
1385 | entry); | 1358 | entry); |
1386 | GNUNET_assert (NULL != th); | 1359 | GNUNET_assert (NULL != th); |
@@ -1417,8 +1390,8 @@ handle_p2p_confirmation_receipt (void *cls, | |||
1417 | p2p_crmsg = (const struct P2PConfirmationReceiptMessage *) message; | 1390 | p2p_crmsg = (const struct P2PConfirmationReceiptMessage *) message; |
1418 | target = client_list_head; | 1391 | target = client_list_head; |
1419 | while ((NULL != target) && | 1392 | while ((NULL != target) && |
1420 | (0 != memcmp (&target->id, | 1393 | (0 != |
1421 | &p2p_crmsg->target, sizeof (GNUNET_HashCode)))) | 1394 | memcmp (&target->id, &p2p_crmsg->target, sizeof (GNUNET_HashCode)))) |
1422 | target = target->next; | 1395 | target = target->next; |
1423 | if (NULL == target) | 1396 | if (NULL == target) |
1424 | { | 1397 | { |
@@ -1441,8 +1414,8 @@ handle_p2p_confirmation_receipt (void *cls, | |||
1441 | target->rcpt_sequence_number = ntohl (p2p_crmsg->sequence_number); | 1414 | target->rcpt_sequence_number = ntohl (p2p_crmsg->sequence_number); |
1442 | author = client_list_head; | 1415 | author = client_list_head; |
1443 | while ((NULL != author) && | 1416 | while ((NULL != author) && |
1444 | (0 != memcmp (&author->id, | 1417 | (0 != |
1445 | &p2p_crmsg->author, sizeof (GNUNET_HashCode)))) | 1418 | memcmp (&author->id, &p2p_crmsg->author, sizeof (GNUNET_HashCode)))) |
1446 | author = author->next; | 1419 | author = author->next; |
1447 | if (NULL == author) | 1420 | if (NULL == author) |
1448 | { | 1421 | { |
@@ -1488,8 +1461,8 @@ handle_p2p_confirmation_receipt (void *cls, | |||
1488 | crmsg->content = p2p_crmsg->content; | 1461 | crmsg->content = p2p_crmsg->content; |
1489 | if (GNUNET_OK != | 1462 | if (GNUNET_OK != |
1490 | GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT, | 1463 | GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT, |
1491 | &crmsg->purpose, | 1464 | &crmsg->purpose, &crmsg->signature, |
1492 | &crmsg->signature, &target->public_key)) | 1465 | &target->public_key)) |
1493 | { | 1466 | { |
1494 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1467 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1495 | "Invalid signature of the receipt\n"); | 1468 | "Invalid signature of the receipt\n"); |
@@ -1501,8 +1474,7 @@ handle_p2p_confirmation_receipt (void *cls, | |||
1501 | "The author of the original message is a local client." | 1474 | "The author of the original message is a local client." |
1502 | " Sending receipt to the client\n"); | 1475 | " Sending receipt to the client\n"); |
1503 | #endif | 1476 | #endif |
1504 | GNUNET_SERVER_notification_context_unicast (nc, | 1477 | GNUNET_SERVER_notification_context_unicast (nc, author->client, |
1505 | author->client, | ||
1506 | &crmsg->header, GNUNET_NO); | 1478 | &crmsg->header, GNUNET_NO); |
1507 | GNUNET_free (crmsg); | 1479 | GNUNET_free (crmsg); |
1508 | } | 1480 | } |
@@ -1545,8 +1517,7 @@ transmit_sync_request_to_peer (void *cls, size_t size, void *buf) | |||
1545 | * @param atsi performance data | 1517 | * @param atsi performance data |
1546 | */ | 1518 | */ |
1547 | static void | 1519 | static void |
1548 | peer_connect_handler (void *cls, | 1520 | peer_connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer, |
1549 | const struct GNUNET_PeerIdentity *peer, | ||
1550 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 1521 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
1551 | { | 1522 | { |
1552 | struct ConnectedPeer *cp; | 1523 | struct ConnectedPeer *cp; |
@@ -1554,13 +1525,10 @@ peer_connect_handler (void *cls, | |||
1554 | 1525 | ||
1555 | if (0 == memcmp (peer, me, sizeof (struct GNUNET_PeerIdentity))) | 1526 | if (0 == memcmp (peer, me, sizeof (struct GNUNET_PeerIdentity))) |
1556 | return; | 1527 | return; |
1557 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1528 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer connected: %s\n", |
1558 | "Peer connected: %s\n", GNUNET_i2s (peer)); | 1529 | GNUNET_i2s (peer)); |
1559 | th = GNUNET_CORE_notify_transmit_ready (core, | 1530 | th = GNUNET_CORE_notify_transmit_ready (core, GNUNET_YES, 1, |
1560 | GNUNET_YES, | 1531 | MAX_TRANSMIT_DELAY, peer, |
1561 | 1, | ||
1562 | MAX_TRANSMIT_DELAY, | ||
1563 | peer, | ||
1564 | sizeof (struct GNUNET_MessageHeader), | 1532 | sizeof (struct GNUNET_MessageHeader), |
1565 | &transmit_sync_request_to_peer, NULL); | 1533 | &transmit_sync_request_to_peer, NULL); |
1566 | GNUNET_assert (NULL != th); | 1534 | GNUNET_assert (NULL != th); |
@@ -1574,8 +1542,7 @@ peer_connect_handler (void *cls, | |||
1574 | cp->pid = GNUNET_PEER_intern (peer); | 1542 | cp->pid = GNUNET_PEER_intern (peer); |
1575 | GNUNET_break (GNUNET_OK == | 1543 | GNUNET_break (GNUNET_OK == |
1576 | GNUNET_CONTAINER_multihashmap_put (connected_peers, | 1544 | GNUNET_CONTAINER_multihashmap_put (connected_peers, |
1577 | &peer->hashPubKey, | 1545 | &peer->hashPubKey, cp, |
1578 | cp, | ||
1579 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1546 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
1580 | } | 1547 | } |
1581 | 1548 | ||
@@ -1619,8 +1586,8 @@ peer_disconnect_handler (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
1619 | 1586 | ||
1620 | if (0 == memcmp (peer, me, sizeof (struct GNUNET_PeerIdentity))) | 1587 | if (0 == memcmp (peer, me, sizeof (struct GNUNET_PeerIdentity))) |
1621 | return; | 1588 | return; |
1622 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1589 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer disconnected: %s\n", |
1623 | "Peer disconnected: %s\n", GNUNET_i2s (peer)); | 1590 | GNUNET_i2s (peer)); |
1624 | clean_peer (NULL, (const GNUNET_HashCode *) peer, NULL); | 1591 | clean_peer (NULL, (const GNUNET_HashCode *) peer, NULL); |
1625 | } | 1592 | } |
1626 | 1593 | ||
@@ -1677,8 +1644,7 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1677 | * @param publicKey the public key of this peer | 1644 | * @param publicKey the public key of this peer |
1678 | */ | 1645 | */ |
1679 | static void | 1646 | static void |
1680 | core_init (void *cls, | 1647 | core_init (void *cls, struct GNUNET_CORE_Handle *server, |
1681 | struct GNUNET_CORE_Handle *server, | ||
1682 | const struct GNUNET_PeerIdentity *my_identity, | 1648 | const struct GNUNET_PeerIdentity *my_identity, |
1683 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) | 1649 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) |
1684 | { | 1650 | { |
@@ -1695,8 +1661,7 @@ core_init (void *cls, | |||
1695 | * @param c configuration to use | 1661 | * @param c configuration to use |
1696 | */ | 1662 | */ |
1697 | static void | 1663 | static void |
1698 | run (void *cls, | 1664 | run (void *cls, struct GNUNET_SERVER_Handle *server, |
1699 | struct GNUNET_SERVER_Handle *server, | ||
1700 | const struct GNUNET_CONFIGURATION_Handle *c) | 1665 | const struct GNUNET_CONFIGURATION_Handle *c) |
1701 | { | 1666 | { |
1702 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | 1667 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { |
@@ -1738,17 +1703,14 @@ run (void *cls, | |||
1738 | connected_peers = | 1703 | connected_peers = |
1739 | GNUNET_CONTAINER_multihashmap_create (EXPECTED_NEIGHBOUR_COUNT); | 1704 | GNUNET_CONTAINER_multihashmap_create (EXPECTED_NEIGHBOUR_COUNT); |
1740 | GNUNET_SERVER_add_handlers (server, handlers); | 1705 | GNUNET_SERVER_add_handlers (server, handlers); |
1741 | core = GNUNET_CORE_connect (cfg, | 1706 | core = |
1742 | QUEUE_SIZE, | 1707 | GNUNET_CORE_connect (cfg, QUEUE_SIZE, NULL, &core_init, |
1743 | NULL, | 1708 | &peer_connect_handler, &peer_disconnect_handler, |
1744 | &core_init, | 1709 | NULL, NULL, GNUNET_NO, NULL, GNUNET_NO, |
1745 | &peer_connect_handler, | 1710 | p2p_handlers); |
1746 | &peer_disconnect_handler, | ||
1747 | NULL, | ||
1748 | NULL, GNUNET_NO, NULL, GNUNET_NO, p2p_handlers); | ||
1749 | GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); | 1711 | GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); |
1750 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 1712 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task, |
1751 | &cleanup_task, NULL); | 1713 | NULL); |
1752 | } | 1714 | } |
1753 | 1715 | ||
1754 | 1716 | ||
@@ -1763,10 +1725,8 @@ int | |||
1763 | main (int argc, char *const *argv) | 1725 | main (int argc, char *const *argv) |
1764 | { | 1726 | { |
1765 | return (GNUNET_OK == | 1727 | return (GNUNET_OK == |
1766 | GNUNET_SERVICE_run (argc, | 1728 | GNUNET_SERVICE_run (argc, argv, "chat", GNUNET_SERVICE_OPTION_NONE, |
1767 | argv, | 1729 | &run, NULL)) ? 0 : 1; |
1768 | "chat", | ||
1769 | GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; | ||
1770 | } | 1730 | } |
1771 | 1731 | ||
1772 | /* end of gnunet-service-chat.c */ | 1732 | /* end of gnunet-service-chat.c */ |