diff options
author | Nathan S. Evans <evans@in.tum.de> | 2011-02-16 14:22:08 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2011-02-16 14:22:08 +0000 |
commit | 29b5e3a06f33ce1f2baf97d02f40306d34add009 (patch) | |
tree | 0dfe834514abcc46278edbb6cb02fbbb8d31673f | |
parent | b3cb3dbe5058d4a1d1336d1e1a2dd89434d9e66e (diff) | |
download | gnunet-29b5e3a06f33ce1f2baf97d02f40306d34add009.tar.gz gnunet-29b5e3a06f33ce1f2baf97d02f40306d34add009.zip |
attempt to avoid issuing connect request for already connected peers
-rw-r--r-- | src/testing/testing.c | 154 |
1 files changed, 88 insertions, 66 deletions
diff --git a/src/testing/testing.c b/src/testing/testing.c index c97b3bda3..e5e528b91 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c | |||
@@ -1606,8 +1606,8 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1606 | GNUNET_TIME_relative_divide | 1606 | GNUNET_TIME_relative_divide |
1607 | (ctx->relative_timeout, | 1607 | (ctx->relative_timeout, |
1608 | ctx->max_connect_attempts + 1), | 1608 | ctx->max_connect_attempts + 1), |
1609 | &ctx->d2->id, | 1609 | &ctx->d2->id, |
1610 | &core_connect_request_cont, ctx); | 1610 | &core_connect_request_cont, ctx); |
1611 | #if DEBUG_TESTING | 1611 | #if DEBUG_TESTING |
1612 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1612 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1613 | "Sending connect request to CORE of %s for peer %s\n", | 1613 | "Sending connect request to CORE of %s for peer %s\n", |
@@ -1623,6 +1623,14 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1623 | &send_hello, ctx); | 1623 | &send_hello, ctx); |
1624 | } | 1624 | } |
1625 | 1625 | ||
1626 | /** | ||
1627 | * Notify of a successful connection to the core service. | ||
1628 | * | ||
1629 | * @param cls a ConnectContext | ||
1630 | * @param server handle to the core service | ||
1631 | * @param my_identity the peer identity of this peer | ||
1632 | * @param publicKey the public key of the peer | ||
1633 | */ | ||
1626 | void | 1634 | void |
1627 | core_init_notify (void *cls, | 1635 | core_init_notify (void *cls, |
1628 | struct GNUNET_CORE_Handle * server, | 1636 | struct GNUNET_CORE_Handle * server, |
@@ -1633,11 +1641,86 @@ core_init_notify (void *cls, | |||
1633 | publicKey) | 1641 | publicKey) |
1634 | { | 1642 | { |
1635 | struct ConnectContext *connect_ctx = cls; | 1643 | struct ConnectContext *connect_ctx = cls; |
1636 | |||
1637 | connect_ctx->d1core_ready = GNUNET_YES; | 1644 | connect_ctx->d1core_ready = GNUNET_YES; |
1638 | } | 1645 | } |
1639 | 1646 | ||
1640 | /** | 1647 | /** |
1648 | * Iterator for currently known peers, to ensure | ||
1649 | * that we don't try to send duplicate connect | ||
1650 | * requests to core. | ||
1651 | * | ||
1652 | * @param cls our "struct ConnectContext" | ||
1653 | * @param peer identity of the peer that has connected, | ||
1654 | * NULL when iteration has finished | ||
1655 | * @param atsi performance information | ||
1656 | * | ||
1657 | */ | ||
1658 | static void | ||
1659 | core_initial_iteration (void *cls, | ||
1660 | const struct GNUNET_PeerIdentity *peer, | ||
1661 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | ||
1662 | { | ||
1663 | struct ConnectContext *ctx = cls; | ||
1664 | |||
1665 | if ((peer != NULL) && | ||
1666 | (0 == memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity)))) | ||
1667 | { | ||
1668 | ctx->connected = GNUNET_YES; | ||
1669 | ctx->distance = 0; /* FIXME: distance */ | ||
1670 | GNUNET_SCHEDULER_cancel (ctx->timeout_task); | ||
1671 | ctx->timeout_task = GNUNET_SCHEDULER_add_now (¬ify_connect_result, | ||
1672 | ctx); | ||
1673 | } | ||
1674 | else if (peer == NULL) /* Peer not already connected, need to schedule connect request! */ | ||
1675 | { | ||
1676 | ctx->d1core = GNUNET_CORE_connect (ctx->d1->cfg, 1, | ||
1677 | ctx, | ||
1678 | &core_init_notify, | ||
1679 | &connect_notify, NULL, NULL, | ||
1680 | NULL, GNUNET_NO, | ||
1681 | NULL, GNUNET_NO, no_handlers); | ||
1682 | if (ctx->d1core == NULL) | ||
1683 | { | ||
1684 | GNUNET_free (ctx); | ||
1685 | if (NULL != ctx->cb) | ||
1686 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, | ||
1687 | _("Failed to connect to core service of first peer!\n")); | ||
1688 | return; | ||
1689 | } | ||
1690 | |||
1691 | #if DEBUG_TESTING > 2 | ||
1692 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1693 | "Asked to connect peer %s to peer %s\n", | ||
1694 | ctx->d1->shortname, ctx->d2->shortname); | ||
1695 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1696 | "Connecting to transport service of peer %s\n", ctx->d2->shortname); | ||
1697 | |||
1698 | #endif | ||
1699 | |||
1700 | ctx->d1th = GNUNET_TRANSPORT_connect (ctx->d1->cfg, | ||
1701 | &ctx->d1->id, ctx->d1, NULL, NULL, NULL); | ||
1702 | if (ctx->d1th == NULL) | ||
1703 | { | ||
1704 | GNUNET_CORE_disconnect (ctx->d1core); | ||
1705 | GNUNET_free (ctx); | ||
1706 | if (NULL != ctx->cb) | ||
1707 | ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, | ||
1708 | _("Failed to connect to transport service!\n")); | ||
1709 | return; | ||
1710 | } | ||
1711 | |||
1712 | ctx->timeout_task = | ||
1713 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide | ||
1714 | (ctx->relative_timeout, | ||
1715 | ctx->max_connect_attempts), | ||
1716 | ¬ify_connect_result, ctx); | ||
1717 | |||
1718 | ctx->hello_send_task = GNUNET_SCHEDULER_add_now (&send_hello, ctx); | ||
1719 | } | ||
1720 | } | ||
1721 | |||
1722 | |||
1723 | /** | ||
1641 | * Establish a connection between two GNUnet daemons. | 1724 | * Establish a connection between two GNUnet daemons. |
1642 | * | 1725 | * |
1643 | * @param d1 handle for the first daemon | 1726 | * @param d1 handle for the first daemon |
@@ -1683,70 +1766,9 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1, | |||
1683 | d1->shortname, d2->shortname); | 1766 | d1->shortname, d2->shortname); |
1684 | #endif | 1767 | #endif |
1685 | 1768 | ||
1686 | /* FIXME: possible bug, core gets connected after peers are connected, thus the connect_notify function is never called (?) */ | 1769 | /* Core is up! Iterate over all _known_ peers first to check if we are already connected to the peer! */ |
1687 | ctx->d1core = GNUNET_CORE_connect (d1->cfg, 1, | 1770 | GNUNET_CORE_iterate_peers(ctx->d1->cfg, &core_initial_iteration, ctx); |
1688 | ctx, | ||
1689 | &core_init_notify, | ||
1690 | &connect_notify, NULL, NULL, | ||
1691 | NULL, GNUNET_NO, | ||
1692 | NULL, GNUNET_NO, no_handlers); | ||
1693 | if (ctx->d1core == NULL) | ||
1694 | { | ||
1695 | GNUNET_free (ctx); | ||
1696 | if (NULL != cb) | ||
1697 | cb (cb_cls, &d1->id, &d2->id, 0, d1->cfg, d2->cfg, d1, d2, | ||
1698 | _("Failed to connect to core service of first peer!\n")); | ||
1699 | return; | ||
1700 | } | ||
1701 | |||
1702 | #if CONNECT_CORE2 | ||
1703 | ctx->d2core = GNUNET_CORE_connect (d2->cfg, 1, | ||
1704 | #if NO_MORE_TIMEOUT_FIXME | ||
1705 | timeout, | ||
1706 | #endif | ||
1707 | ctx, | ||
1708 | NULL, | ||
1709 | NULL, NULL, NULL, | ||
1710 | NULL, GNUNET_NO, | ||
1711 | NULL, GNUNET_NO, no_handlers); | ||
1712 | if (ctx->d2core == NULL) | ||
1713 | { | ||
1714 | GNUNET_free (ctx); | ||
1715 | if (NULL != cb) | ||
1716 | cb (cb_cls, &d1->id, &d2->id, 0, d1->cfg, d2->cfg, d1, d2, | ||
1717 | _("Failed to connect to core service of second peer!\n")); | ||
1718 | return; | ||
1719 | } | ||
1720 | #endif | ||
1721 | 1771 | ||
1722 | #if DEBUG_TESTING > 2 | ||
1723 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1724 | "Asked to connect peer %s to peer %s\n", | ||
1725 | d1->shortname, d2->shortname); | ||
1726 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1727 | "Connecting to transport service of peer %s\n", d2->shortname); | ||
1728 | |||
1729 | #endif | ||
1730 | |||
1731 | ctx->d1th = GNUNET_TRANSPORT_connect (d1->cfg, | ||
1732 | &d1->id, d1, NULL, NULL, NULL); | ||
1733 | if (ctx->d1th == NULL) | ||
1734 | { | ||
1735 | GNUNET_CORE_disconnect (ctx->d1core); | ||
1736 | GNUNET_free (ctx); | ||
1737 | if (NULL != cb) | ||
1738 | cb (cb_cls, &d1->id, &d2->id, 0, d1->cfg, d2->cfg, d1, d2, | ||
1739 | _("Failed to connect to transport service!\n")); | ||
1740 | return; | ||
1741 | } | ||
1742 | |||
1743 | ctx->timeout_task = | ||
1744 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide | ||
1745 | (ctx->relative_timeout, | ||
1746 | ctx->max_connect_attempts), | ||
1747 | ¬ify_connect_result, ctx); | ||
1748 | |||
1749 | ctx->hello_send_task = GNUNET_SCHEDULER_add_now (&send_hello, ctx); | ||
1750 | } | 1772 | } |
1751 | 1773 | ||
1752 | static void | 1774 | static void |