aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing.c')
-rw-r--r--src/testing/testing.c380
1 files changed, 235 insertions, 145 deletions
diff --git a/src/testing/testing.c b/src/testing/testing.c
index ddfe17d43..4a321c6e6 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -38,7 +38,7 @@
38#include "gnunet_hello_lib.h" 38#include "gnunet_hello_lib.h"
39 39
40#define DEBUG_TESTING GNUNET_NO 40#define DEBUG_TESTING GNUNET_NO
41#define DEBUG_TESTING_RECONNECT GNUNET_NO 41#define DEBUG_TESTING_RECONNECT GNUNET_YES
42 42
43/** 43/**
44 * How long do we wait after starting gnunet-service-arm 44 * How long do we wait after starting gnunet-service-arm
@@ -65,10 +65,19 @@ static void
65process_hello (void *cls, const struct GNUNET_MessageHeader *message) 65process_hello (void *cls, const struct GNUNET_MessageHeader *message)
66{ 66{
67 struct GNUNET_TESTING_Daemon *daemon = cls; 67 struct GNUNET_TESTING_Daemon *daemon = cls;
68 GNUNET_TESTING_NotifyDaemonRunning cb;
69
68 int msize; 70 int msize;
69 if (daemon == NULL) 71 if (daemon == NULL)
70 return; 72 return;
71 73
74 GNUNET_assert (daemon->phase == SP_GET_HELLO);
75
76 cb = daemon->cb;
77 daemon->cb = NULL;
78 if (daemon->task != GNUNET_SCHEDULER_NO_TASK) /* Assertion here instead? */
79 GNUNET_SCHEDULER_cancel(daemon->task);
80
72 if (daemon->server != NULL) 81 if (daemon->server != NULL)
73 { 82 {
74#if DEBUG_TESTING 83#if DEBUG_TESTING
@@ -105,9 +114,15 @@ process_hello (void *cls, const struct GNUNET_MessageHeader *message)
105 GNUNET_TRANSPORT_disconnect (daemon->th); 114 GNUNET_TRANSPORT_disconnect (daemon->th);
106 daemon->th = NULL; 115 daemon->th = NULL;
107 } 116 }
117 daemon->phase = SP_START_DONE;
108 118
119 if (NULL != cb) /* FIXME: what happens when this callback calls GNUNET_TESTING_daemon_stop? */
120 cb (daemon->cb_cls, &daemon->id, daemon->cfg, daemon, NULL);
109} 121}
110 122
123static void
124start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
125
111/** 126/**
112 * Function called after GNUNET_CORE_connect has succeeded 127 * Function called after GNUNET_CORE_connect has succeeded
113 * (or failed for good). Note that the private key of the 128 * (or failed for good). Note that the private key of the
@@ -127,12 +142,10 @@ testing_init (void *cls,
127 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) 142 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
128{ 143{
129 struct GNUNET_TESTING_Daemon *d = cls; 144 struct GNUNET_TESTING_Daemon *d = cls;
130 GNUNET_TESTING_NotifyDaemonRunning cb;
131 145
132 GNUNET_assert (d->phase == SP_START_CORE); 146 GNUNET_assert (d->phase == SP_START_CORE);
133 d->phase = SP_START_DONE; 147 d->phase = SP_GET_HELLO;
134 cb = d->cb; 148
135 d->cb = NULL;
136 if (server == NULL) 149 if (server == NULL)
137 { 150 {
138 d->server = NULL; 151 d->server = NULL;
@@ -141,8 +154,8 @@ testing_init (void *cls,
141 GNUNET_TIME_absolute_get_remaining 154 GNUNET_TIME_absolute_get_remaining
142 (d->max_timeout), d->dead_cb, 155 (d->max_timeout), d->dead_cb,
143 d->dead_cb_cls, GNUNET_YES, GNUNET_NO); 156 d->dead_cb_cls, GNUNET_YES, GNUNET_NO);
144 else if (NULL != cb) 157 else if (NULL != d->cb)
145 cb (d->cb_cls, NULL, d->cfg, d, 158 d->cb (d->cb_cls, NULL, d->cfg, d,
146 _("Failed to connect to core service\n")); 159 _("Failed to connect to core service\n"));
147 return; 160 return;
148 } 161 }
@@ -155,9 +168,6 @@ testing_init (void *cls,
155 d->server = server; 168 d->server = server;
156 d->running = GNUNET_YES; 169 d->running = GNUNET_YES;
157 170
158 if (NULL != cb) /* FIXME: what happens when this callback calls GNUNET_TESTING_daemon_stop? */
159 cb (d->cb_cls, my_identity, d->cfg, d, NULL);
160
161 if (GNUNET_NO == d->running) 171 if (GNUNET_NO == d->running)
162 { 172 {
163#if DEBUG_TESTING 173#if DEBUG_TESTING
@@ -192,6 +202,12 @@ testing_init (void *cls,
192#endif 202#endif
193 203
194 GNUNET_TRANSPORT_get_hello (d->th, &process_hello, d); 204 GNUNET_TRANSPORT_get_hello (d->th, &process_hello, d);
205 /* wait some more */
206 if (d->task != GNUNET_SCHEDULER_NO_TASK)
207 GNUNET_SCHEDULER_cancel(d->task);
208 d->task
209 = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT,
210 &start_fsm, d);
195} 211}
196 212
197 213
@@ -551,7 +567,12 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
551 (NULL == d->hostname) 567 (NULL == d->hostname)
552 ? _("`gnunet-arm' does not seem to terminate.\n") 568 ? _("`gnunet-arm' does not seem to terminate.\n")
553 : _("`ssh' does not seem to terminate.\n")); 569 : _("`ssh' does not seem to terminate.\n"));
570 GNUNET_CONFIGURATION_destroy (d->cfg);
571 GNUNET_free (d->cfgfile);
572 GNUNET_free_non_null (d->hostname);
573 GNUNET_free_non_null (d->username);
554 GNUNET_free(d->proc); 574 GNUNET_free(d->proc);
575 GNUNET_free(d);
555 return; 576 return;
556 } 577 }
557 /* wait some more */ 578 /* wait some more */
@@ -570,18 +591,68 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
570 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 591 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
571 "Calling CORE_connect\n"); 592 "Calling CORE_connect\n");
572#endif 593#endif
594 /* Fall through */
595 case SP_START_CORE:
596 if (d->server != NULL)
597 GNUNET_CORE_disconnect(d->server);
598
599 if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value ==
600 0)
601 {
602 cb = d->cb;
603 d->cb = NULL;
604 if (NULL != cb)
605 cb (d->cb_cls,
606 NULL,
607 d->cfg,
608 d,
609 _("Unable to connect to CORE service for peer!\n"));
610 GNUNET_CONFIGURATION_destroy (d->cfg);
611 GNUNET_free (d->cfgfile);
612 GNUNET_free_non_null (d->hostname);
613 GNUNET_free_non_null (d->username);
614 GNUNET_free (d);
615 return;
616 }
573 d->server = GNUNET_CORE_connect (d->cfg, 1, 617 d->server = GNUNET_CORE_connect (d->cfg, 1,
574#if NO_MORE_TIMEOUT_FIXME
575 ARM_START_WAIT,
576#endif
577 d, 618 d,
578 &testing_init, 619 &testing_init,
579 NULL, NULL, NULL, 620 NULL, NULL, NULL,
580 NULL, GNUNET_NO, 621 NULL, GNUNET_NO,
581 NULL, GNUNET_NO, no_handlers); 622 NULL, GNUNET_NO, no_handlers);
623 d->task
624 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_CONSTANTS_SERVICE_RETRY, 2),
625 &start_fsm, d);
582 break; 626 break;
583 case SP_START_CORE: 627 case SP_GET_HELLO:
584 GNUNET_break (0); 628 if (GNUNET_TIME_absolute_get_remaining (d->max_timeout).rel_value ==
629 0)
630 {
631 if (d->server != NULL)
632 GNUNET_CORE_disconnect(d->server);
633 if (d->th != NULL)
634 GNUNET_TRANSPORT_disconnect(d->th);
635 cb = d->cb;
636 d->cb = NULL;
637 if (NULL != cb)
638 cb (d->cb_cls,
639 NULL,
640 d->cfg,
641 d,
642 _("Unable to get HELLO for peer!\n"));
643 GNUNET_CONFIGURATION_destroy (d->cfg);
644 GNUNET_free (d->cfgfile);
645 GNUNET_free_non_null (d->hostname);
646 GNUNET_free_non_null (d->username);
647 GNUNET_free (d);
648 return;
649 }
650 if (d->hello != NULL)
651 return;
652 GNUNET_assert(d->task == GNUNET_SCHEDULER_NO_TASK);
653 d->task
654 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_CONSTANTS_SERVICE_RETRY, 2),
655 &start_fsm, d);
585 break; 656 break;
586 case SP_START_DONE: 657 case SP_START_DONE:
587 GNUNET_break (0); 658 GNUNET_break (0);
@@ -1368,12 +1439,6 @@ struct ConnectContext
1368 void *cb_cls; 1439 void *cb_cls;
1369 1440
1370 /** 1441 /**
1371 * When should this operation be complete (or we must trigger
1372 * a timeout).
1373 */
1374 struct GNUNET_TIME_Absolute timeout;
1375
1376 /**
1377 * The relative timeout from whence this connect attempt was 1442 * The relative timeout from whence this connect attempt was
1378 * started. Allows for reconnect attempts. 1443 * started. Allows for reconnect attempts.
1379 */ 1444 */
@@ -1383,7 +1448,7 @@ struct ConnectContext
1383 * Maximum number of connect attempts, will retry connection 1448 * Maximum number of connect attempts, will retry connection
1384 * this number of times on failures. 1449 * this number of times on failures.
1385 */ 1450 */
1386 unsigned int max_connect_attempts; 1451 unsigned int connect_attempts;
1387 1452
1388 /** 1453 /**
1389 * Hello timeout task 1454 * Hello timeout task
@@ -1407,6 +1472,11 @@ struct ConnectContext
1407 int connected; 1472 int connected;
1408 1473
1409 /** 1474 /**
1475 * When connecting, do we need to send the HELLO?
1476 */
1477 int send_hello;
1478
1479 /**
1410 * The distance between the two connected peers 1480 * The distance between the two connected peers
1411 */ 1481 */
1412 uint32_t distance; 1482 uint32_t distance;
@@ -1431,8 +1501,6 @@ notify_connect_result (void *cls,
1431 const struct GNUNET_SCHEDULER_TaskContext *tc) 1501 const struct GNUNET_SCHEDULER_TaskContext *tc)
1432{ 1502{
1433 struct ConnectContext *ctx = cls; 1503 struct ConnectContext *ctx = cls;
1434 struct GNUNET_TIME_Relative remaining;
1435
1436 ctx->timeout_task = GNUNET_SCHEDULER_NO_TASK; 1504 ctx->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1437 if (ctx->hello_send_task != GNUNET_SCHEDULER_NO_TASK) 1505 if (ctx->hello_send_task != GNUNET_SCHEDULER_NO_TASK)
1438 { 1506 {
@@ -1445,6 +1513,7 @@ notify_connect_result (void *cls,
1445 GNUNET_CORE_peer_request_connect_cancel (ctx->connect_request_handle); 1513 GNUNET_CORE_peer_request_connect_cancel (ctx->connect_request_handle);
1446 ctx->connect_request_handle = NULL; 1514 ctx->connect_request_handle = NULL;
1447 } 1515 }
1516
1448 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) 1517 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
1449 { 1518 {
1450 if (ctx->d1th != NULL) 1519 if (ctx->d1th != NULL)
@@ -1458,12 +1527,16 @@ notify_connect_result (void *cls,
1458 ctx->d2core = NULL; 1527 ctx->d2core = NULL;
1459#endif 1528#endif
1460 ctx->d1core = NULL; 1529 ctx->d1core = NULL;
1461
1462 GNUNET_free (ctx); 1530 GNUNET_free (ctx);
1463 return; 1531 return;
1464 } 1532 }
1465 1533
1466 remaining = GNUNET_TIME_absolute_get_remaining (ctx->timeout); 1534 if (ctx->d1th != NULL)
1535 GNUNET_TRANSPORT_disconnect (ctx->d1th);
1536 ctx->d1th = NULL;
1537 if (ctx->d1core != NULL)
1538 GNUNET_CORE_disconnect (ctx->d1core);
1539 ctx->d1core = NULL;
1467 1540
1468 if (ctx->connected == GNUNET_YES) 1541 if (ctx->connected == GNUNET_YES)
1469 { 1542 {
@@ -1476,13 +1549,8 @@ notify_connect_result (void *cls,
1476 ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, NULL); 1549 ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, NULL);
1477 } 1550 }
1478 } 1551 }
1479 else if (remaining.rel_value > 0) 1552 else if (ctx->connect_attempts > 0)
1480 { 1553 {
1481 if (ctx->d1core != NULL)
1482 {
1483 GNUNET_CORE_disconnect (ctx->d1core);
1484 ctx->d1core = NULL;
1485 }
1486 ctx->d1core_ready = GNUNET_NO; 1554 ctx->d1core_ready = GNUNET_NO;
1487#if CONNECT_CORE2 1555#if CONNECT_CORE2
1488 if (ctx->d2core != NULL) 1556 if (ctx->d2core != NULL)
@@ -1491,12 +1559,6 @@ notify_connect_result (void *cls,
1491 ctx->d2core = NULL; 1559 ctx->d2core = NULL;
1492 } 1560 }
1493#endif 1561#endif
1494
1495 if (ctx->d1th != NULL)
1496 {
1497 GNUNET_TRANSPORT_disconnect (ctx->d1th);
1498 ctx->d1th = NULL;
1499 }
1500 GNUNET_SCHEDULER_add_now (&reattempt_daemons_connect, ctx); 1562 GNUNET_SCHEDULER_add_now (&reattempt_daemons_connect, ctx);
1501 return; 1563 return;
1502 } 1564 }
@@ -1510,12 +1572,6 @@ notify_connect_result (void *cls,
1510 } 1572 }
1511 } 1573 }
1512 1574
1513 if (ctx->d1th != NULL)
1514 GNUNET_TRANSPORT_disconnect (ctx->d1th);
1515 ctx->d1th = NULL;
1516 if (ctx->d1core != NULL)
1517 GNUNET_CORE_disconnect (ctx->d1core);
1518 ctx->d1core = NULL;
1519 GNUNET_free (ctx); 1575 GNUNET_free (ctx);
1520} 1576}
1521 1577
@@ -1535,8 +1591,15 @@ connect_notify (void *cls,
1535{ 1591{
1536 struct ConnectContext *ctx = cls; 1592 struct ConnectContext *ctx = cls;
1537 1593
1594#if DEBUG_TESTING
1595 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1596 "Connected peer %s to peer %s\n",
1597 ctx->d1->shortname, GNUNET_i2s(peer));
1598#endif
1599
1538 if (0 == memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity))) 1600 if (0 == memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity)))
1539 { 1601 {
1602
1540 ctx->connected = GNUNET_YES; 1603 ctx->connected = GNUNET_YES;
1541 ctx->distance = 0; /* FIXME: distance */ 1604 ctx->distance = 0; /* FIXME: distance */
1542 if (ctx->hello_send_task != GNUNET_SCHEDULER_NO_TASK) 1605 if (ctx->hello_send_task != GNUNET_SCHEDULER_NO_TASK)
@@ -1606,17 +1669,16 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1606 { 1669 {
1607 hello = GNUNET_HELLO_get_header (ctx->d2->hello); 1670 hello = GNUNET_HELLO_get_header (ctx->d2->hello);
1608 GNUNET_assert (hello != NULL); 1671 GNUNET_assert (hello != NULL);
1609 GNUNET_TRANSPORT_offer_hello (ctx->d1th, hello); 1672 GNUNET_TRANSPORT_offer_hello (ctx->d1th, hello, NULL, NULL);
1610 GNUNET_assert (ctx->d1core != NULL); 1673 GNUNET_assert (ctx->d1core != NULL);
1611 ctx->connect_request_handle = 1674 ctx->connect_request_handle =
1612 GNUNET_CORE_peer_request_connect (ctx->d1core, 1675 GNUNET_CORE_peer_request_connect (ctx->d1core,
1613 GNUNET_TIME_relative_divide 1676 ctx->relative_timeout,
1614 (ctx->relative_timeout, 1677 &ctx->d2->id,
1615 ctx->max_connect_attempts + 1), 1678 &core_connect_request_cont, ctx);
1616 &ctx->d2->id, 1679
1617 &core_connect_request_cont, ctx);
1618#if DEBUG_TESTING 1680#if DEBUG_TESTING
1619 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1681 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1620 "Sending connect request to CORE of %s for peer %s\n", 1682 "Sending connect request to CORE of %s for peer %s\n",
1621 GNUNET_i2s (&ctx->d1->id), 1683 GNUNET_i2s (&ctx->d1->id),
1622 GNUNET_h2s (&ctx->d2->id.hashPubKey)); 1684 GNUNET_h2s (&ctx->d2->id.hashPubKey));
@@ -1649,6 +1711,88 @@ core_init_notify (void *cls,
1649{ 1711{
1650 struct ConnectContext *connect_ctx = cls; 1712 struct ConnectContext *connect_ctx = cls;
1651 connect_ctx->d1core_ready = GNUNET_YES; 1713 connect_ctx->d1core_ready = GNUNET_YES;
1714
1715 if (connect_ctx->send_hello == GNUNET_NO)
1716 {
1717 connect_ctx->connect_request_handle =
1718 GNUNET_CORE_peer_request_connect (connect_ctx->d1core,
1719 connect_ctx->relative_timeout,
1720 &connect_ctx->d2->id,
1721 &core_connect_request_cont, connect_ctx);
1722 GNUNET_assert(connect_ctx->connect_request_handle != NULL);
1723#if DEBUG_TESTING
1724 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1725 "Sending connect request to CORE of %s for peer %s\n",
1726 connect_ctx->d1->shortname,
1727 connect_ctx->d2->shortname);
1728#endif
1729 }
1730
1731}
1732
1733
1734static void
1735reattempt_daemons_connect (void *cls,
1736 const struct GNUNET_SCHEDULER_TaskContext *tc)
1737{
1738 struct ConnectContext *ctx = cls;
1739 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
1740 {
1741 GNUNET_free(ctx);
1742 return;
1743 }
1744#if DEBUG_TESTING_RECONNECT
1745 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1746 "re-attempting connect of peer %s to peer %s\n",
1747 ctx->d1->shortname, ctx->d2->shortname);
1748#endif
1749 ctx->connect_attempts--;
1750 GNUNET_assert (ctx->d1core == NULL);
1751 ctx->d1core_ready = GNUNET_NO;
1752 ctx->d1core = GNUNET_CORE_connect (ctx->d1->cfg, 1,
1753 ctx,
1754 &core_init_notify,
1755 &connect_notify, NULL, NULL,
1756 NULL, GNUNET_NO,
1757 NULL, GNUNET_NO, no_handlers);
1758 if (ctx->d1core == NULL)
1759 {
1760 if (NULL != ctx->cb)
1761 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg,
1762 ctx->d2->cfg, ctx->d1, ctx->d2,
1763 _("Failed to connect to core service of first peer!\n"));
1764 GNUNET_free (ctx);
1765 return;
1766 }
1767
1768 if (ctx->send_hello == GNUNET_YES)
1769 {
1770 ctx->d1th = GNUNET_TRANSPORT_connect (ctx->d1->cfg,
1771 &ctx->d1->id,
1772 ctx->d1, NULL, NULL, NULL);
1773 if (ctx->d1th == NULL)
1774 {
1775 GNUNET_CORE_disconnect (ctx->d1core);
1776 GNUNET_free (ctx);
1777 if (NULL != ctx->cb)
1778 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg,
1779 ctx->d2->cfg, ctx->d1, ctx->d2,
1780 _("Failed to connect to transport service!\n"));
1781 return;
1782 }
1783 ctx->hello_send_task = GNUNET_SCHEDULER_add_now (&send_hello, ctx);
1784 }
1785 else
1786 {
1787 ctx->connect_request_handle =
1788 GNUNET_CORE_peer_request_connect (ctx->d1core,
1789 ctx->relative_timeout,
1790 &ctx->d2->id,
1791 &core_connect_request_cont, ctx);
1792 }
1793 ctx->timeout_task =
1794 GNUNET_SCHEDULER_add_delayed (ctx->relative_timeout,
1795 &notify_connect_result, ctx);
1652} 1796}
1653 1797
1654/** 1798/**
@@ -1676,7 +1820,7 @@ core_initial_iteration (void *cls,
1676 ctx->distance = 0; /* FIXME: distance */ 1820 ctx->distance = 0; /* FIXME: distance */
1677 return; 1821 return;
1678 } 1822 }
1679 else if (peer == NULL) /* Peer not already connected, need to schedule connect request! */ 1823 else if (peer == NULL) /* End of iteration over peers */
1680 { 1824 {
1681 if (ctx->connected == GNUNET_YES) 1825 if (ctx->connected == GNUNET_YES)
1682 { 1826 {
@@ -1685,12 +1829,21 @@ core_initial_iteration (void *cls,
1685 return; 1829 return;
1686 } 1830 }
1687 1831
1688 ctx->d1core = GNUNET_CORE_connect (ctx->d1->cfg, 1, 1832 /* Peer not already connected, need to schedule connect request! */
1689 ctx, 1833 if (ctx->d1core == NULL)
1690 &core_init_notify, 1834 {
1691 &connect_notify, NULL, NULL, 1835#if DEBUG_TESTING
1692 NULL, GNUNET_NO, 1836 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1693 NULL, GNUNET_NO, no_handlers); 1837 "Peers are NOT connected, connecting to core!\n");
1838#endif
1839 ctx->d1core = GNUNET_CORE_connect (ctx->d1->cfg, 1,
1840 ctx,
1841 &core_init_notify,
1842 &connect_notify, NULL, NULL,
1843 NULL, GNUNET_NO,
1844 NULL, GNUNET_NO, no_handlers);
1845 }
1846
1694 if (ctx->d1core == NULL) 1847 if (ctx->d1core == NULL)
1695 { 1848 {
1696 GNUNET_free (ctx); 1849 GNUNET_free (ctx);
@@ -1700,34 +1853,25 @@ core_initial_iteration (void *cls,
1700 return; 1853 return;
1701 } 1854 }
1702 1855
1703#if DEBUG_TESTING > 2 1856 if (ctx->send_hello == GNUNET_YES)
1704 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1705 "Asked to connect peer %s to peer %s\n",
1706 ctx->d1->shortname, ctx->d2->shortname);
1707 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1708 "Connecting to transport service of peer %s\n", ctx->d2->shortname);
1709
1710#endif
1711
1712 ctx->d1th = GNUNET_TRANSPORT_connect (ctx->d1->cfg,
1713 &ctx->d1->id, ctx->d1, NULL, NULL, NULL);
1714 if (ctx->d1th == NULL)
1715 { 1857 {
1716 GNUNET_CORE_disconnect (ctx->d1core); 1858 ctx->d1th = GNUNET_TRANSPORT_connect (ctx->d1->cfg,
1717 GNUNET_free (ctx); 1859 &ctx->d1->id, ctx->d1, NULL, NULL, NULL);
1718 if (NULL != ctx->cb) 1860 if (ctx->d1th == NULL)
1719 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2, 1861 {
1720 _("Failed to connect to transport service!\n")); 1862 GNUNET_CORE_disconnect (ctx->d1core);
1721 return; 1863 GNUNET_free (ctx);
1864 if (NULL != ctx->cb)
1865 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg, ctx->d2->cfg, ctx->d1, ctx->d2,
1866 _("Failed to connect to transport service!\n"));
1867 return;
1868 }
1869 ctx->hello_send_task = GNUNET_SCHEDULER_add_now (&send_hello, ctx);
1722 } 1870 }
1723 1871
1724 ctx->timeout_task = 1872 ctx->timeout_task =
1725 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide 1873 GNUNET_SCHEDULER_add_delayed (ctx->relative_timeout,
1726 (ctx->relative_timeout, 1874 &notify_connect_result, ctx);
1727 ctx->max_connect_attempts),
1728 &notify_connect_result, ctx);
1729
1730 ctx->hello_send_task = GNUNET_SCHEDULER_add_now (&send_hello, ctx);
1731 } 1875 }
1732} 1876}
1733 1877
@@ -1741,6 +1885,8 @@ core_initial_iteration (void *cls,
1741 * allowed to take? 1885 * allowed to take?
1742 * @param max_connect_attempts how many times should we try to reconnect 1886 * @param max_connect_attempts how many times should we try to reconnect
1743 * (within timeout) 1887 * (within timeout)
1888 * @param send_hello GNUNET_YES to send the HELLO, GNUNET_NO to assume
1889 * the HELLO has already been exchanged
1744 * @param cb function to call at the end 1890 * @param cb function to call at the end
1745 * @param cb_cls closure for cb 1891 * @param cb_cls closure for cb
1746 */ 1892 */
@@ -1749,6 +1895,7 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
1749 struct GNUNET_TESTING_Daemon *d2, 1895 struct GNUNET_TESTING_Daemon *d2,
1750 struct GNUNET_TIME_Relative timeout, 1896 struct GNUNET_TIME_Relative timeout,
1751 unsigned int max_connect_attempts, 1897 unsigned int max_connect_attempts,
1898 int send_hello,
1752 GNUNET_TESTING_NotifyConnection cb, 1899 GNUNET_TESTING_NotifyConnection cb,
1753 void *cb_cls) 1900 void *cb_cls)
1754{ 1901{
@@ -1761,17 +1908,18 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
1761 _("Peers are not fully running yet, can not connect!\n")); 1908 _("Peers are not fully running yet, can not connect!\n"));
1762 return; 1909 return;
1763 } 1910 }
1911
1764 ctx = GNUNET_malloc (sizeof (struct ConnectContext)); 1912 ctx = GNUNET_malloc (sizeof (struct ConnectContext));
1765 ctx->d1 = d1; 1913 ctx->d1 = d1;
1766 ctx->d2 = d2; 1914 ctx->d2 = d2;
1767 ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
1768 ctx->timeout_hello = 1915 ctx->timeout_hello =
1769 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500); 1916 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500);
1770 ctx->relative_timeout = timeout; 1917 ctx->relative_timeout = GNUNET_TIME_relative_divide(timeout, max_connect_attempts);
1771 ctx->cb = cb; 1918 ctx->cb = cb;
1772 ctx->cb_cls = cb_cls; 1919 ctx->cb_cls = cb_cls;
1773 ctx->max_connect_attempts = max_connect_attempts; 1920 ctx->connect_attempts = max_connect_attempts;
1774 ctx->connected = GNUNET_NO; 1921 ctx->connected = GNUNET_NO;
1922 ctx->send_hello = send_hello;
1775#if DEBUG_TESTING 1923#if DEBUG_TESTING
1776 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1924 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1777 "Asked to connect peer %s to peer %s\n", 1925 "Asked to connect peer %s to peer %s\n",
@@ -1779,66 +1927,8 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1,
1779#endif 1927#endif
1780 1928
1781 /* Core is up! Iterate over all _known_ peers first to check if we are already connected to the peer! */ 1929 /* Core is up! Iterate over all _known_ peers first to check if we are already connected to the peer! */
1782 GNUNET_CORE_is_peer_connected (ctx->d1->cfg, &ctx->d2->id, &core_initial_iteration, ctx); 1930 GNUNET_assert(GNUNET_OK == GNUNET_CORE_is_peer_connected (ctx->d1->cfg, &ctx->d2->id, &core_initial_iteration, ctx));
1783 /* GNUNET_CORE_iterate_peers(ctx->d1->cfg, &core_initial_iteration, ctx); */ 1931 /*GNUNET_assert(GNUNET_OK == GNUNET_CORE_iterate_peers (ctx->d1->cfg, &core_initial_iteration, ctx));*/
1784
1785}
1786
1787static void
1788reattempt_daemons_connect (void *cls,
1789 const struct GNUNET_SCHEDULER_TaskContext *tc)
1790{
1791
1792 struct ConnectContext *ctx = cls;
1793 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
1794 {
1795 return;
1796 }
1797#if DEBUG_TESTING_RECONNECT
1798 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1799 "re-attempting connect of peer %s to peer %s\n",
1800 ctx->d1->shortname, ctx->d2->shortname);
1801#endif
1802
1803 GNUNET_assert (ctx->d1core == NULL);
1804 ctx->d1core_ready = GNUNET_NO;
1805 ctx->d1core = GNUNET_CORE_connect (ctx->d1->cfg, 1,
1806 ctx,
1807 &core_init_notify,
1808 &connect_notify, NULL, NULL,
1809 NULL, GNUNET_NO,
1810 NULL, GNUNET_NO, no_handlers);
1811 if (ctx->d1core == NULL)
1812 {
1813 if (NULL != ctx->cb)
1814 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg,
1815 ctx->d2->cfg, ctx->d1, ctx->d2,
1816 _("Failed to connect to core service of first peer!\n"));
1817 GNUNET_free (ctx);
1818 return;
1819 }
1820
1821 ctx->d1th = GNUNET_TRANSPORT_connect (ctx->d1->cfg,
1822 &ctx->d1->id,
1823 ctx->d1, NULL, NULL, NULL);
1824 if (ctx->d1th == NULL)
1825 {
1826 GNUNET_CORE_disconnect (ctx->d1core);
1827 GNUNET_free (ctx);
1828 if (NULL != ctx->cb)
1829 ctx->cb (ctx->cb_cls, &ctx->d1->id, &ctx->d2->id, 0, ctx->d1->cfg,
1830 ctx->d2->cfg, ctx->d1, ctx->d2,
1831 _("Failed to connect to transport service!\n"));
1832 return;
1833 }
1834
1835 ctx->timeout_task =
1836 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide
1837 (ctx->relative_timeout,
1838 ctx->max_connect_attempts),
1839 &notify_connect_result, ctx);
1840
1841 ctx->hello_send_task = GNUNET_SCHEDULER_add_now (&send_hello, ctx);
1842} 1932}
1843 1933
1844/* end of testing.c */ 1934/* end of testing.c */