aboutsummaryrefslogtreecommitdiff
path: root/src/testbed
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-08-07 12:23:05 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-08-07 12:23:05 +0000
commita0ebfc6a72f42eab9ce0859e0f2e565424cf2118 (patch)
tree2a8fa412954c0ba0d7fb68536e5e0fbe4164c9d1 /src/testbed
parent844aabc796c0d1b955eb8a2229ea46ca8e78a92e (diff)
downloadgnunet-a0ebfc6a72f42eab9ce0859e0f2e565424cf2118.tar.gz
gnunet-a0ebfc6a72f42eab9ce0859e0f2e565424cf2118.zip
hacking overlay connect
Diffstat (limited to 'src/testbed')
-rw-r--r--src/testbed/Makefile.am1
-rw-r--r--src/testbed/gnunet-service-testbed.c176
-rw-r--r--src/testbed/test_testbed_api_2peers.c4
-rw-r--r--src/testbed/testbed_api_operations.c10
4 files changed, 124 insertions, 67 deletions
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am
index 29e5270c6..36ef3cae8 100644
--- a/src/testbed/Makefile.am
+++ b/src/testbed/Makefile.am
@@ -22,6 +22,7 @@ gnunet_service_testbed_SOURCES = \
22 gnunet-service-testbed.c 22 gnunet-service-testbed.c
23gnunet_service_testbed_LDADD = $(XLIB) \ 23gnunet_service_testbed_LDADD = $(XLIB) \
24 $(top_builddir)/src/util/libgnunetutil.la \ 24 $(top_builddir)/src/util/libgnunetutil.la \
25 $(top_builddir)/src/core/libgnunetcore.la \
25 $(top_builddir)/src/transport/libgnunettransport.la \ 26 $(top_builddir)/src/transport/libgnunettransport.la \
26 $(top_builddir)/src/testing/libgnunettesting.la \ 27 $(top_builddir)/src/testing/libgnunettesting.la \
27 $(top_builddir)/src/testbed/libgnunettestbed.la \ 28 $(top_builddir)/src/testbed/libgnunettestbed.la \
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c
index a4ff40659..2aa22d213 100644
--- a/src/testbed/gnunet-service-testbed.c
+++ b/src/testbed/gnunet-service-testbed.c
@@ -28,6 +28,7 @@
28#include "gnunet_service_lib.h" 28#include "gnunet_service_lib.h"
29#include "gnunet_server_lib.h" 29#include "gnunet_server_lib.h"
30#include "gnunet_transport_service.h" 30#include "gnunet_transport_service.h"
31#include "gnunet_core_service.h"
31#include <zlib.h> 32#include <zlib.h>
32 33
33#include "gnunet_testbed_service.h" 34#include "gnunet_testbed_service.h"
@@ -337,7 +338,12 @@ struct OverlayConnectContext
337 * Transport handle of peers 338 * Transport handle of peers
338 */ 339 */
339 struct GNUNET_TRANSPORT_Handle *peers_transport[2]; 340 struct GNUNET_TRANSPORT_Handle *peers_transport[2];
340 341
342 /**
343 * Core handles of peers
344 */
345 struct GNUNET_CORE_Handle *peers_core[2];
346
341 /** 347 /**
342 * HELLO of peers 348 * HELLO of peers
343 */ 349 */
@@ -1537,57 +1543,7 @@ handle_peer_get_config (void *cls,
1537} 1543}
1538 1544
1539 1545
1540/**
1541 * Exchanges HELLO of peers among them
1542 *
1543 * @param occ the OverlayConnectContext to look into for HELLO messages
1544 */
1545static void
1546exchange_hellos (struct OverlayConnectContext *occ)
1547{
1548 unsigned int peer;
1549 1546
1550 GNUNET_assert (NULL != occ->peers_hello[0]);
1551 GNUNET_assert (NULL != occ->peers_hello[1]);
1552 LOG_DEBUG ("Exchanging hellos\n");
1553 for (peer = 0; peer < 2; peer++)
1554 {
1555 GNUNET_TRANSPORT_offer_hello (occ->peers_transport[peer],
1556 occ->peers_hello[peer ^ 1],
1557 NULL, NULL);
1558 GNUNET_TRANSPORT_try_connect (occ->peers_transport[peer],
1559 &occ->peers_identity[peer ^ 1]);
1560 GNUNET_free (occ->peers_hello[peer ^ 1]);
1561 }
1562}
1563
1564
1565/**
1566 * Function called whenever there is an update to the
1567 * HELLO of peers in the OverlayConnectClosure
1568 *
1569 * @param cls closure
1570 * @param hello our updated HELLO
1571 */
1572static void
1573hello_update_cb (void *cls, const struct GNUNET_MessageHeader *hello)
1574{
1575 struct OverlayConnectContextWrapper *occw = cls;
1576 struct OverlayConnectContext *occ;
1577 unsigned int peer;
1578 uint16_t msize;
1579
1580 msize = ntohs (hello->size);
1581 peer = occw->peer;
1582 GNUNET_assert (peer <= 1);
1583 occ = occw->occ;
1584 occ->peers_hello[peer] = GNUNET_malloc (msize);
1585 memcpy (occ->peers_hello[peer], hello, msize);
1586 GNUNET_TRANSPORT_get_hello_cancel (occ->peers_ghh[peer]);
1587 occ->peers_ghh[peer] = NULL;
1588 if (NULL != occ->peers_hello[peer ^ 1])
1589 exchange_hellos (occ);
1590}
1591 1547
1592 1548
1593/** 1549/**
@@ -1603,26 +1559,36 @@ static void
1603overlay_connect_notify (void *cls, 1559overlay_connect_notify (void *cls,
1604 const struct GNUNET_PeerIdentity * new_peer, 1560 const struct GNUNET_PeerIdentity * new_peer,
1605 const struct GNUNET_ATS_Information * ats, 1561 const struct GNUNET_ATS_Information * ats,
1606 uint32_t ats_count) 1562 unsigned int ats_count)
1607{ 1563{
1608 struct OverlayConnectContextWrapper *occw = cls; 1564 struct OverlayConnectContextWrapper *occw = cls;
1609 struct OverlayConnectContext *occ; 1565 struct OverlayConnectContext *occ;
1610 struct GNUNET_TESTBED_ConnectionEventMessage *msg; 1566 struct GNUNET_TESTBED_ConnectionEventMessage *msg;
1567 char *new_peer_str;
1568 char *other_peer_str;
1611 unsigned int peer; 1569 unsigned int peer;
1612 1570
1571 LOG_DEBUG ("Overlay connect notify\n");
1613 peer = occw->peer; 1572 peer = occw->peer;
1614 occ = occw->occ; 1573 occ = occw->occ;
1574 if (0 == memcmp (new_peer, &occ->peers_identity[peer],
1575 sizeof (struct GNUNET_PeerIdentity)))
1576 return;
1577 new_peer_str = GNUNET_strdup (GNUNET_i2s (new_peer));
1578 other_peer_str = GNUNET_strdup (GNUNET_i2s (&occ->peers_identity[peer ^ 1]));
1615 if (0 != memcmp (new_peer, &occ->peers_identity[peer ^ 1], 1579 if (0 != memcmp (new_peer, &occ->peers_identity[peer ^ 1],
1616 sizeof (struct GNUNET_PeerIdentity))) 1580 sizeof (struct GNUNET_PeerIdentity)))
1617 { 1581 {
1618 LOG_DEBUG ("Unexpected peer %4s connected to peer %4s\n", 1582 LOG_DEBUG ("Unexpected peer %4s connected to peer %4s\n",
1619 GNUNET_i2s (new_peer), 1583 new_peer_str, other_peer_str);
1620 GNUNET_i2s (&occ->peers_identity[peer ^ 1])); 1584 GNUNET_free (new_peer_str);
1585 GNUNET_free (other_peer_str);
1621 return; 1586 return;
1622 } 1587 }
1623 GNUNET_free (occw); 1588 GNUNET_free (occw);
1624 LOG_DEBUG ("Peer %4s connected to peer %4s\n", GNUNET_i2s (new_peer), 1589 LOG_DEBUG ("Peer %4s connected to peer %4s\n", new_peer_str, other_peer_str);
1625 GNUNET_i2s (&occ->peers_identity[peer ^ 1])); 1590 GNUNET_free (new_peer_str);
1591 GNUNET_free (other_peer_str);
1626 GNUNET_TRANSPORT_disconnect (occ->peers_transport[peer]); 1592 GNUNET_TRANSPORT_disconnect (occ->peers_transport[peer]);
1627 occ->peers_transport[peer] = NULL; 1593 occ->peers_transport[peer] = NULL;
1628 if (NULL != occ->peers_transport[peer ^ 1]) 1594 if (NULL != occ->peers_transport[peer ^ 1])
@@ -1644,6 +1610,93 @@ overlay_connect_notify (void *cls,
1644 1610
1645 1611
1646/** 1612/**
1613 * For peers that haven't yet connected, send
1614 * CORE connect requests.
1615 *
1616 * @param cls the 'struct SendHelloContext *'
1617 * @param tc scheduler context
1618 */
1619static void
1620send_core_connect_requests (void *cls,
1621 const struct GNUNET_SCHEDULER_TaskContext *tc)
1622{
1623 struct OverlayConnectContext *occ = cls;
1624 unsigned int peer;
1625
1626 LOG_DEBUG ("Sending connect requests to transport\n");
1627 for (peer = 0; peer < 2; peer++)
1628 GNUNET_TRANSPORT_try_connect (occ->peers_transport[peer],
1629 &occ->peers_identity[peer ^ 1]);
1630}
1631
1632
1633/**
1634 * Exchanges HELLO of peers among them
1635 *
1636 * @param occ the OverlayConnectContext to look into for HELLO messages
1637 */
1638static void
1639exchange_hellos (struct OverlayConnectContext *occ)
1640{
1641 struct GNUNET_CORE_MessageHandler no_handlers[] = {
1642 {NULL, 0, 0}
1643 };
1644 struct OverlayConnectContextWrapper *occw;
1645 unsigned int peer;
1646
1647 GNUNET_assert (NULL != occ->peers_hello[0]);
1648 GNUNET_assert (NULL != occ->peers_hello[1]);
1649 LOG_DEBUG ("Exchanging hellos\n");
1650 for (peer = 0; peer < 2; peer++)
1651 {
1652 GNUNET_TRANSPORT_offer_hello (occ->peers_transport[peer],
1653 occ->peers_hello[peer ^ 1],
1654 NULL, NULL);
1655 GNUNET_free (occ->peers_hello[peer ^ 1]);
1656 occ->peers_hello[peer ^ 1] = NULL;
1657 occw = GNUNET_malloc (sizeof (struct OverlayConnectContextWrapper));
1658 occw->occ = occ;
1659 occw->peer = peer;
1660 occ->peers_core[peer] =
1661 GNUNET_CORE_connect (occ->peers[peer]->cfg,
1662 occw, NULL, &overlay_connect_notify, NULL,
1663 NULL, GNUNET_NO, NULL, GNUNET_NO, no_handlers);
1664 }
1665 if ((NULL == occ->peers_hello[peer]) && (NULL == occ->peers_hello[peer ^ 1]))
1666 GNUNET_SCHEDULER_add_now (&send_core_connect_requests, occ);
1667}
1668
1669
1670/**
1671 * Function called whenever there is an update to the
1672 * HELLO of peers in the OverlayConnectClosure
1673 *
1674 * @param cls closure
1675 * @param hello our updated HELLO
1676 */
1677static void
1678hello_update_cb (void *cls, const struct GNUNET_MessageHeader *hello)
1679{
1680 struct OverlayConnectContextWrapper *occw = cls;
1681 struct OverlayConnectContext *occ;
1682 unsigned int peer;
1683 uint16_t msize;
1684
1685 msize = ntohs (hello->size);
1686 peer = occw->peer;
1687 GNUNET_assert (peer <= 1);
1688 occ = occw->occ;
1689 GNUNET_free (occw);
1690 occ->peers_hello[peer] = GNUNET_malloc (msize);
1691 memcpy (occ->peers_hello[peer], hello, msize);
1692 GNUNET_TRANSPORT_get_hello_cancel (occ->peers_ghh[peer]);
1693 occ->peers_ghh[peer] = NULL;
1694 if (NULL != occ->peers_hello[peer ^ 1])
1695 exchange_hellos (occ);
1696}
1697
1698
1699/**
1647 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_OLCONNECT messages 1700 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_OLCONNECT messages
1648 * 1701 *
1649 * @param cls NULL 1702 * @param cls NULL
@@ -1678,15 +1731,15 @@ handle_overlay_connect (void *cls,
1678 occ->op_id = GNUNET_ntohll (msg->operation_id); 1731 occ->op_id = GNUNET_ntohll (msg->operation_id);
1679 for (peer = 0; peer < 2; peer++) 1732 for (peer = 0; peer < 2; peer++)
1680 { 1733 {
1681 occw = GNUNET_malloc (sizeof (struct OverlayConnectContextWrapper));
1682 occw->occ = occ;
1683 occw->peer = peer;
1684 GNUNET_TESTING_peer_get_identity (occ->peers[peer]->peer, 1734 GNUNET_TESTING_peer_get_identity (occ->peers[peer]->peer,
1685 &occ->peers_identity[peer]); 1735 &occ->peers_identity[peer]);
1686 occ->peers_transport[peer] = 1736 occ->peers_transport[peer] =
1687 GNUNET_TRANSPORT_connect (occ->peers[peer]->cfg, 1737 GNUNET_TRANSPORT_connect (occ->peers[peer]->cfg,
1688 &occ->peers_identity[peer], occw, NULL, 1738 &occ->peers_identity[peer],
1689 &overlay_connect_notify, NULL); 1739 NULL, NULL, NULL, NULL);
1740 occw = GNUNET_malloc (sizeof (struct OverlayConnectContextWrapper));
1741 occw->occ = occ;
1742 occw->peer = peer;
1690 occ->peers_ghh[peer] = 1743 occ->peers_ghh[peer] =
1691 GNUNET_TRANSPORT_get_hello (occ->peers_transport[peer], 1744 GNUNET_TRANSPORT_get_hello (occ->peers_transport[peer],
1692 &hello_update_cb, occw); 1745 &hello_update_cb, occw);
@@ -1873,6 +1926,7 @@ testbed_run (void *cls,
1873 */ 1926 */
1874int main (int argc, char *const *argv) 1927int main (int argc, char *const *argv)
1875{ 1928{
1929 //sleep (60); /* Debugging */
1876 return 1930 return
1877 (GNUNET_OK == 1931 (GNUNET_OK ==
1878 GNUNET_SERVICE_run (argc, 1932 GNUNET_SERVICE_run (argc,
diff --git a/src/testbed/test_testbed_api_2peers.c b/src/testbed/test_testbed_api_2peers.c
index aff71afe0..781194bf4 100644
--- a/src/testbed/test_testbed_api_2peers.c
+++ b/src/testbed/test_testbed_api_2peers.c
@@ -389,7 +389,7 @@ run (void *cls, char *const *args, const char *cfgfile,
389 cfg = GNUNET_CONFIGURATION_dup (config); 389 cfg = GNUNET_CONFIGURATION_dup (config);
390 cp = GNUNET_TESTBED_controller_start ("127.0.0.1", host, cfg, status_cb, NULL); 390 cp = GNUNET_TESTBED_controller_start ("127.0.0.1", host, cfg, status_cb, NULL);
391 abort_task = GNUNET_SCHEDULER_add_delayed 391 abort_task = GNUNET_SCHEDULER_add_delayed
392 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5), &do_abort, NULL); 392 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30), &do_abort, NULL);
393} 393}
394 394
395 395
@@ -409,7 +409,7 @@ int main (int argc, char **argv)
409 }; 409 };
410 result = INIT; 410 result = INIT;
411 ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, 411 ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
412 "test_testbed_api", "nohelp", options, &run, 412 "test_testbed_api_2peers", "nohelp", options, &run,
413 NULL); 413 NULL);
414 if ((GNUNET_OK != ret) || (SUCCESS != result)) 414 if ((GNUNET_OK != ret) || (SUCCESS != result))
415 return 1; 415 return 1;
diff --git a/src/testbed/testbed_api_operations.c b/src/testbed/testbed_api_operations.c
index a3e3c30b1..2bd82949e 100644
--- a/src/testbed/testbed_api_operations.c
+++ b/src/testbed/testbed_api_operations.c
@@ -163,7 +163,9 @@ static void
163check_readiness (struct GNUNET_TESTBED_Operation *op) 163check_readiness (struct GNUNET_TESTBED_Operation *op)
164{ 164{
165 unsigned int i; 165 unsigned int i;
166 166
167 if (GNUNET_SCHEDULER_NO_TASK != op->start_task_id)
168 return;
167 for (i = 0; i < op->nqueues; i++) 169 for (i = 0; i < op->nqueues; i++)
168 { 170 {
169 if (0 == op->queues[i]->active) 171 if (0 == op->queues[i]->active)
@@ -173,8 +175,7 @@ check_readiness (struct GNUNET_TESTBED_Operation *op)
173 { 175 {
174 op->queues[i]->active--; 176 op->queues[i]->active--;
175 } 177 }
176 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == op->start_task_id); 178 op->start_task_id = GNUNET_SCHEDULER_add_now (&call_start, op);
177 op->start_task_id = GNUNET_SCHEDULER_add_now (&call_start, op);
178} 179}
179 180
180 181
@@ -197,7 +198,8 @@ GNUNET_TESTBED_operation_create_ (void *cls,
197 op->start = start; 198 op->start = start;
198 op->release = release; 199 op->release = release;
199 op->cb_cls = cls; 200 op->cb_cls = cls;
200 return op; 201 op->start_task_id = GNUNET_SCHEDULER_NO_TASK;
202 return op;
201} 203}
202 204
203 205