diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-03-17 11:53:24 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-03-17 11:53:24 +0100 |
commit | c253a40bae417335fab8446f3c7182c8c5d4833f (patch) | |
tree | 0517ab35f90bf290744e5a9ddfeb75ca9547cdbe /src/core | |
parent | 273188e646ed4d91ced1dac443e976336be877b4 (diff) | |
parent | 79fb947eb8fba243ea65e19b40b65e04f8806865 (diff) | |
download | gnunet-c253a40bae417335fab8446f3c7182c8c5d4833f.tar.gz gnunet-c253a40bae417335fab8446f3c7182c8c5d4833f.zip |
Merge branch 'master' into getopt
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/gnunet-service-core_kx.c | 152 |
1 files changed, 62 insertions, 90 deletions
diff --git a/src/core/gnunet-service-core_kx.c b/src/core/gnunet-service-core_kx.c index 906898512..8a7cada5c 100644 --- a/src/core/gnunet-service-core_kx.c +++ b/src/core/gnunet-service-core_kx.c | |||
@@ -263,6 +263,11 @@ struct GSC_KeyExchangeInfo | |||
263 | struct GNUNET_MQ_Handle *mq; | 263 | struct GNUNET_MQ_Handle *mq; |
264 | 264 | ||
265 | /** | 265 | /** |
266 | * Our message stream tokenizer (for encrypted payload). | ||
267 | */ | ||
268 | struct GNUNET_MessageStreamTokenizer *mst; | ||
269 | |||
270 | /** | ||
266 | * PING message we transmit to the other peer. | 271 | * PING message we transmit to the other peer. |
267 | */ | 272 | */ |
268 | struct PingMessage ping; | 273 | struct PingMessage ping; |
@@ -370,11 +375,6 @@ static struct GNUNET_CRYPTO_EcdhePrivateKey *my_ephemeral_key; | |||
370 | static struct EphemeralKeyMessage current_ekm; | 375 | static struct EphemeralKeyMessage current_ekm; |
371 | 376 | ||
372 | /** | 377 | /** |
373 | * Our message stream tokenizer (for encrypted payload). | ||
374 | */ | ||
375 | static struct GNUNET_SERVER_MessageStreamTokenizer *mst; | ||
376 | |||
377 | /** | ||
378 | * DLL head. | 378 | * DLL head. |
379 | */ | 379 | */ |
380 | static struct GSC_KeyExchangeInfo *kx_head; | 380 | static struct GSC_KeyExchangeInfo *kx_head; |
@@ -702,6 +702,55 @@ setup_fresh_ping (struct GSC_KeyExchangeInfo *kx) | |||
702 | 702 | ||
703 | 703 | ||
704 | /** | 704 | /** |
705 | * Deliver P2P message to interested clients. Invokes send twice, | ||
706 | * once for clients that want the full message, and once for clients | ||
707 | * that only want the header | ||
708 | * | ||
709 | * @param cls the `struct GSC_KeyExchangeInfo` | ||
710 | * @param m the message | ||
711 | */ | ||
712 | static int | ||
713 | deliver_message (void *cls, | ||
714 | const struct GNUNET_MessageHeader *m) | ||
715 | { | ||
716 | struct GSC_KeyExchangeInfo *kx = cls; | ||
717 | |||
718 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
719 | "Decrypted message of type %d from %s\n", | ||
720 | ntohs (m->type), | ||
721 | GNUNET_i2s (kx->peer)); | ||
722 | if (GNUNET_CORE_KX_STATE_UP != kx->status) | ||
723 | { | ||
724 | GNUNET_STATISTICS_update (GSC_stats, | ||
725 | gettext_noop ("# PAYLOAD dropped (out of order)"), | ||
726 | 1, | ||
727 | GNUNET_NO); | ||
728 | return GNUNET_OK; | ||
729 | } | ||
730 | switch (ntohs (m->type)) | ||
731 | { | ||
732 | case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP: | ||
733 | case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP: | ||
734 | GSC_SESSIONS_set_typemap (kx->peer, m); | ||
735 | return GNUNET_OK; | ||
736 | case GNUNET_MESSAGE_TYPE_CORE_CONFIRM_TYPE_MAP: | ||
737 | GSC_SESSIONS_confirm_typemap (kx->peer, m); | ||
738 | return GNUNET_OK; | ||
739 | default: | ||
740 | GSC_CLIENTS_deliver_message (kx->peer, | ||
741 | m, | ||
742 | ntohs (m->size), | ||
743 | GNUNET_CORE_OPTION_SEND_FULL_INBOUND); | ||
744 | GSC_CLIENTS_deliver_message (kx->peer, | ||
745 | m, | ||
746 | sizeof (struct GNUNET_MessageHeader), | ||
747 | GNUNET_CORE_OPTION_SEND_HDR_INBOUND); | ||
748 | } | ||
749 | return GNUNET_OK; | ||
750 | } | ||
751 | |||
752 | |||
753 | /** | ||
705 | * Function called by transport to notify us that | 754 | * Function called by transport to notify us that |
706 | * a peer connected to us (on the network level). | 755 | * a peer connected to us (on the network level). |
707 | * Starts the key exchange with the given peer. | 756 | * Starts the key exchange with the given peer. |
@@ -727,6 +776,8 @@ handle_transport_notify_connect (void *cls, | |||
727 | 1, | 776 | 1, |
728 | GNUNET_NO); | 777 | GNUNET_NO); |
729 | kx = GNUNET_new (struct GSC_KeyExchangeInfo); | 778 | kx = GNUNET_new (struct GSC_KeyExchangeInfo); |
779 | kx->mst = GNUNET_MST_create (&deliver_message, | ||
780 | kx); | ||
730 | kx->mq = mq; | 781 | kx->mq = mq; |
731 | kx->peer = pid; | 782 | kx->peer = pid; |
732 | kx->set_key_retry_frequency = INITIAL_SET_KEY_RETRY_FREQUENCY; | 783 | kx->set_key_retry_frequency = INITIAL_SET_KEY_RETRY_FREQUENCY; |
@@ -801,6 +852,7 @@ handle_transport_notify_disconnect (void *cls, | |||
801 | GNUNET_CONTAINER_DLL_remove (kx_head, | 852 | GNUNET_CONTAINER_DLL_remove (kx_head, |
802 | kx_tail, | 853 | kx_tail, |
803 | kx); | 854 | kx); |
855 | GNUNET_MST_destroy (kx->mst); | ||
804 | GNUNET_free (kx); | 856 | GNUNET_free (kx); |
805 | } | 857 | } |
806 | 858 | ||
@@ -1417,24 +1469,6 @@ GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx, | |||
1417 | 1469 | ||
1418 | 1470 | ||
1419 | /** | 1471 | /** |
1420 | * Closure for #deliver_message() | ||
1421 | */ | ||
1422 | struct DeliverMessageContext | ||
1423 | { | ||
1424 | |||
1425 | /** | ||
1426 | * Key exchange context. | ||
1427 | */ | ||
1428 | struct GSC_KeyExchangeInfo *kx; | ||
1429 | |||
1430 | /** | ||
1431 | * Sender of the message. | ||
1432 | */ | ||
1433 | const struct GNUNET_PeerIdentity *peer; | ||
1434 | }; | ||
1435 | |||
1436 | |||
1437 | /** | ||
1438 | * We received an encrypted message. Check that it is | 1472 | * We received an encrypted message. Check that it is |
1439 | * well-formed (size-wise). | 1473 | * well-formed (size-wise). |
1440 | * | 1474 | * |
@@ -1475,7 +1509,6 @@ handle_encrypted (void *cls, | |||
1475 | struct GNUNET_TIME_Absolute t; | 1509 | struct GNUNET_TIME_Absolute t; |
1476 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; | 1510 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; |
1477 | struct GNUNET_CRYPTO_AuthKey auth_key; | 1511 | struct GNUNET_CRYPTO_AuthKey auth_key; |
1478 | struct DeliverMessageContext dmc; | ||
1479 | uint16_t size = ntohs (m->header.size); | 1512 | uint16_t size = ntohs (m->header.size); |
1480 | char buf[size] GNUNET_ALIGN; | 1513 | char buf[size] GNUNET_ALIGN; |
1481 | 1514 | ||
@@ -1620,15 +1653,12 @@ handle_encrypted (void *cls, | |||
1620 | gettext_noop ("# bytes of payload decrypted"), | 1653 | gettext_noop ("# bytes of payload decrypted"), |
1621 | size - sizeof (struct EncryptedMessage), | 1654 | size - sizeof (struct EncryptedMessage), |
1622 | GNUNET_NO); | 1655 | GNUNET_NO); |
1623 | dmc.kx = kx; | ||
1624 | dmc.peer = kx->peer; | ||
1625 | if (GNUNET_OK != | 1656 | if (GNUNET_OK != |
1626 | GNUNET_SERVER_mst_receive (mst, | 1657 | GNUNET_MST_from_buffer (kx->mst, |
1627 | &dmc, | 1658 | &buf[sizeof (struct EncryptedMessage)], |
1628 | &buf[sizeof (struct EncryptedMessage)], | 1659 | size - sizeof (struct EncryptedMessage), |
1629 | size - sizeof (struct EncryptedMessage), | 1660 | GNUNET_YES, |
1630 | GNUNET_YES, | 1661 | GNUNET_NO)) |
1631 | GNUNET_NO)) | ||
1632 | GNUNET_break_op (0); | 1662 | GNUNET_break_op (0); |
1633 | } | 1663 | } |
1634 | 1664 | ||
@@ -1656,57 +1686,6 @@ handle_transport_notify_excess_bw (void *cls, | |||
1656 | 1686 | ||
1657 | 1687 | ||
1658 | /** | 1688 | /** |
1659 | * Deliver P2P message to interested clients. Invokes send twice, | ||
1660 | * once for clients that want the full message, and once for clients | ||
1661 | * that only want the header | ||
1662 | * | ||
1663 | * @param cls always NULL | ||
1664 | * @param client who sent us the message (struct GSC_KeyExchangeInfo) | ||
1665 | * @param m the message | ||
1666 | */ | ||
1667 | static int | ||
1668 | deliver_message (void *cls, | ||
1669 | void *client, | ||
1670 | const struct GNUNET_MessageHeader *m) | ||
1671 | { | ||
1672 | struct DeliverMessageContext *dmc = client; | ||
1673 | |||
1674 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1675 | "Decrypted message of type %d from %s\n", | ||
1676 | ntohs (m->type), | ||
1677 | GNUNET_i2s (dmc->peer)); | ||
1678 | if (GNUNET_CORE_KX_STATE_UP != dmc->kx->status) | ||
1679 | { | ||
1680 | GNUNET_STATISTICS_update (GSC_stats, | ||
1681 | gettext_noop ("# PAYLOAD dropped (out of order)"), | ||
1682 | 1, | ||
1683 | GNUNET_NO); | ||
1684 | return GNUNET_OK; | ||
1685 | } | ||
1686 | switch (ntohs (m->type)) | ||
1687 | { | ||
1688 | case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP: | ||
1689 | case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP: | ||
1690 | GSC_SESSIONS_set_typemap (dmc->peer, m); | ||
1691 | return GNUNET_OK; | ||
1692 | case GNUNET_MESSAGE_TYPE_CORE_CONFIRM_TYPE_MAP: | ||
1693 | GSC_SESSIONS_confirm_typemap (dmc->peer, m); | ||
1694 | return GNUNET_OK; | ||
1695 | default: | ||
1696 | GSC_CLIENTS_deliver_message (dmc->peer, | ||
1697 | m, | ||
1698 | ntohs (m->size), | ||
1699 | GNUNET_CORE_OPTION_SEND_FULL_INBOUND); | ||
1700 | GSC_CLIENTS_deliver_message (dmc->peer, | ||
1701 | m, | ||
1702 | sizeof (struct GNUNET_MessageHeader), | ||
1703 | GNUNET_CORE_OPTION_SEND_HDR_INBOUND); | ||
1704 | } | ||
1705 | return GNUNET_OK; | ||
1706 | } | ||
1707 | |||
1708 | |||
1709 | /** | ||
1710 | * Setup the message that links the ephemeral key to our persistent | 1689 | * Setup the message that links the ephemeral key to our persistent |
1711 | * public key and generate the appropriate signature. | 1690 | * public key and generate the appropriate signature. |
1712 | */ | 1691 | */ |
@@ -1829,8 +1808,6 @@ GSC_KX_init (struct GNUNET_CRYPTO_EddsaPrivateKey *pk) | |||
1829 | rekey_task = GNUNET_SCHEDULER_add_delayed (REKEY_FREQUENCY, | 1808 | rekey_task = GNUNET_SCHEDULER_add_delayed (REKEY_FREQUENCY, |
1830 | &do_rekey, | 1809 | &do_rekey, |
1831 | NULL); | 1810 | NULL); |
1832 | mst = GNUNET_SERVER_mst_create (&deliver_message, | ||
1833 | NULL); | ||
1834 | transport | 1811 | transport |
1835 | = GNUNET_TRANSPORT_core_connect (GSC_cfg, | 1812 | = GNUNET_TRANSPORT_core_connect (GSC_cfg, |
1836 | &GSC_my_identity, | 1813 | &GSC_my_identity, |
@@ -1874,11 +1851,6 @@ GSC_KX_done () | |||
1874 | GNUNET_free (my_private_key); | 1851 | GNUNET_free (my_private_key); |
1875 | my_private_key = NULL; | 1852 | my_private_key = NULL; |
1876 | } | 1853 | } |
1877 | if (NULL != mst) | ||
1878 | { | ||
1879 | GNUNET_SERVER_mst_destroy (mst); | ||
1880 | mst = NULL; | ||
1881 | } | ||
1882 | if (NULL != nc) | 1854 | if (NULL != nc) |
1883 | { | 1855 | { |
1884 | GNUNET_notification_context_destroy (nc); | 1856 | GNUNET_notification_context_destroy (nc); |