aboutsummaryrefslogtreecommitdiff
path: root/src/testbed
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-08-10 09:56:15 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-08-10 09:56:15 +0000
commit575a3430d3e7112241706ace8a53de3900e936ec (patch)
tree2a9b0ea19cfd71d8cde1f4778146f3fcba1fe9fa /src/testbed
parent89731c0e26a6bbc224fd9b797a7aea6ad000cfe9 (diff)
downloadgnunet-575a3430d3e7112241706ace8a53de3900e936ec.tar.gz
gnunet-575a3430d3e7112241706ace8a53de3900e936ec.zip
overlay connect operation failure reporting
Diffstat (limited to 'src/testbed')
-rw-r--r--src/testbed/gnunet-service-testbed.c98
1 files changed, 93 insertions, 5 deletions
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c
index 1d8732902..ff19250aa 100644
--- a/src/testbed/gnunet-service-testbed.c
+++ b/src/testbed/gnunet-service-testbed.c
@@ -364,6 +364,11 @@ struct OverlayConnectContext
364 * Get hello handle for the other peer 364 * Get hello handle for the other peer
365 */ 365 */
366 struct GNUNET_TRANSPORT_GetHelloHandle *ghh; 366 struct GNUNET_TRANSPORT_GetHelloHandle *ghh;
367
368 /**
369 * The error message we send if this overlay connect operation has timed out
370 */
371 char *emsg;
367 372
368 /** 373 /**
369 * The peer identity of the first peer 374 * The peer identity of the first peer
@@ -385,6 +390,11 @@ struct OverlayConnectContext
385 * connect to peer 2 390 * connect to peer 2
386 */ 391 */
387 GNUNET_SCHEDULER_TaskIdentifier send_hello_task; 392 GNUNET_SCHEDULER_TaskIdentifier send_hello_task;
393
394 /**
395 * The id of the overlay connect timeout task
396 */
397 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
388 398
389 /** 399 /**
390 * State information for determining whose HELLOs have been successfully 400 * State information for determining whose HELLOs have been successfully
@@ -716,6 +726,36 @@ route_message (uint32_t host_id, const struct GNUNET_MessageHeader *msg)
716 726
717 727
718/** 728/**
729 * Send operation failure message to client
730 *
731 * @param client the client to which the failure message has to be sent to
732 * @param operation_id the id of the failed operation
733 * @param emsg the error message; can be NULL
734 */
735static void
736send_operation_fail_msg (struct GNUNET_SERVER_Client *client,
737 uint64_t operation_id,
738 const char *emsg)
739{
740 struct GNUNET_TESTBED_OperationFailureEventMessage *msg;
741 uint16_t msize;
742 uint16_t emsg_len;
743
744 msize = sizeof (struct GNUNET_TESTBED_OperationFailureEventMessage);
745 emsg_len = (NULL == emsg) ? 0 : strlen (emsg) + 1;
746 msize += emsg_len;
747 msg = GNUNET_malloc (msize);
748 msg->header.size = htons (msize);
749 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_OPERATIONEVENT);
750 msg->event_type = htonl (GNUNET_TESTBED_ET_OPERATION_FINISHED);
751 msg->operation_id = GNUNET_htonll (operation_id);
752 if (0 != emsg_len)
753 memcpy (&msg[1], emsg, emsg_len);
754 queue_message (client, &msg->header);
755}
756
757
758/**
719 * The Link Controller forwarding task 759 * The Link Controller forwarding task
720 * 760 *
721 * @param cls the LCFContext 761 * @param cls the LCFContext
@@ -1005,7 +1045,7 @@ handle_add_host (void *cls,
1005 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM); 1045 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM);
1006 reply->header.size = htons (reply_size); 1046 reply->header.size = htons (reply_size);
1007 reply->host_id = htonl (host_id); 1047 reply->host_id = htonl (host_id);
1008 queue_message (client, (struct GNUNET_MessageHeader *) reply); 1048 queue_message (client, &reply->header);
1009} 1049}
1010 1050
1011 1051
@@ -1574,9 +1614,11 @@ static void
1574occ_cleanup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 1614occ_cleanup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1575{ 1615{
1576 struct OverlayConnectContext *occ = cls; 1616 struct OverlayConnectContext *occ = cls;
1577 1617
1578 if (NULL != occ->hello) 1618 GNUNET_free_non_null (occ->emsg);
1579 GNUNET_free (occ->hello); 1619 GNUNET_free_non_null (occ->hello);
1620 if (GNUNET_SCHEDULER_NO_TASK != occ->send_hello_task)
1621 GNUNET_SCHEDULER_cancel (occ->send_hello_task);
1580 if (NULL != occ->ch) 1622 if (NULL != occ->ch)
1581 GNUNET_CORE_disconnect (occ->ch); 1623 GNUNET_CORE_disconnect (occ->ch);
1582 if (NULL != occ->ghh) 1624 if (NULL != occ->ghh)
@@ -1590,6 +1632,26 @@ occ_cleanup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1590 1632
1591 1633
1592/** 1634/**
1635 * Task which will be run when overlay connect request has been timed out
1636 *
1637 * @param
1638 * @return
1639 */
1640static void
1641timeout_overlay_connect (void *cls,
1642 const struct GNUNET_SCHEDULER_TaskContext *tc)
1643{
1644 struct OverlayConnectContext *occ = cls;
1645
1646 occ->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1647 send_operation_fail_msg (occ->client, occ->op_id, occ->emsg);
1648 GNUNET_SERVER_client_drop (occ->client);
1649 occ_cleanup (occ, tc);
1650}
1651
1652
1653
1654/**
1593 * Function called to notify transport users that another 1655 * Function called to notify transport users that another
1594 * peer connected to us. 1656 * peer connected to us.
1595 * 1657 *
@@ -1632,6 +1694,11 @@ overlay_connect_notify (void *cls,
1632 GNUNET_SCHEDULER_cancel (occ->send_hello_task); 1694 GNUNET_SCHEDULER_cancel (occ->send_hello_task);
1633 occ->send_hello_task = GNUNET_SCHEDULER_NO_TASK; 1695 occ->send_hello_task = GNUNET_SCHEDULER_NO_TASK;
1634 } 1696 }
1697 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != occ->timeout_task);
1698 GNUNET_SCHEDULER_cancel (occ->timeout_task);
1699 occ->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1700 GNUNET_free_non_null (occ->emsg);
1701 occ->emsg = NULL;
1635 GNUNET_TRANSPORT_disconnect (occ->p1th); 1702 GNUNET_TRANSPORT_disconnect (occ->p1th);
1636 occ->p1th = NULL; 1703 occ->p1th = NULL;
1637 /* Peer 1 has connected connect to peer2 - now send overlay connect success message */ 1704 /* Peer 1 has connected connect to peer2 - now send overlay connect success message */
@@ -1726,6 +1793,8 @@ hello_update_cb (void *cls, const struct GNUNET_MessageHeader *hello)
1726 occ->ghh = NULL; 1793 occ->ghh = NULL;
1727 GNUNET_TRANSPORT_disconnect (occ->p2th); 1794 GNUNET_TRANSPORT_disconnect (occ->p2th);
1728 occ->p2th = NULL; 1795 occ->p2th = NULL;
1796 GNUNET_free_non_null (occ->emsg);
1797 occ->emsg = GNUNET_strdup ("Timeout while offering HELLO to other peer");
1729 occ->send_hello_task = GNUNET_SCHEDULER_add_now (&send_hello, occ); 1798 occ->send_hello_task = GNUNET_SCHEDULER_add_now (&send_hello, occ);
1730} 1799}
1731 1800
@@ -1747,6 +1816,8 @@ core_startup_cb (void *cls, struct GNUNET_CORE_Handle * server,
1747{ 1816{
1748 struct OverlayConnectContext *occ = cls; 1817 struct OverlayConnectContext *occ = cls;
1749 1818
1819 GNUNET_free_non_null (occ->emsg);
1820 occ->emsg = NULL;
1750 memcpy (&occ->peer_identity, my_identity, sizeof (struct GNUNET_PeerIdentity)); 1821 memcpy (&occ->peer_identity, my_identity, sizeof (struct GNUNET_PeerIdentity));
1751 occ->p1th = 1822 occ->p1th =
1752 GNUNET_TRANSPORT_connect (occ->peer->cfg, &occ->peer_identity, NULL, NULL, 1823 GNUNET_TRANSPORT_connect (occ->peer->cfg, &occ->peer_identity, NULL, NULL,
@@ -1757,8 +1828,20 @@ core_startup_cb (void *cls, struct GNUNET_CORE_Handle * server,
1757 occ->p2th = 1828 occ->p2th =
1758 GNUNET_TRANSPORT_connect (occ->other_peer->cfg, &occ->other_peer_identity, 1829 GNUNET_TRANSPORT_connect (occ->other_peer->cfg, &occ->other_peer_identity,
1759 NULL, NULL, NULL, NULL); 1830 NULL, NULL, NULL, NULL);
1760 LOG_DEBUG ("Acquiring HELLO of peer %s\n", GNUNET_i2s (&occ->other_peer_identity)); 1831 if ((NULL == occ->p1th) || (NULL == occ->p2th))
1832 {
1833 occ->emsg = GNUNET_strdup ("Cannot connect to TRANSPORTs of peers");
1834 goto send_failure;
1835 }
1836 LOG_DEBUG ("Acquiring HELLO of peer %s\n", GNUNET_i2s
1837 (&occ->other_peer_identity));
1838 occ->emsg = GNUNET_strdup ("Timeout while acquiring HELLO message");
1761 occ->ghh = GNUNET_TRANSPORT_get_hello (occ->p2th, &hello_update_cb, occ); 1839 occ->ghh = GNUNET_TRANSPORT_get_hello (occ->p2th, &hello_update_cb, occ);
1840 return;
1841
1842 send_failure:
1843 GNUNET_SCHEDULER_cancel (occ->timeout_task);
1844 occ->timeout_task = GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ);
1762} 1845}
1763 1846
1764 1847
@@ -1796,7 +1879,12 @@ handle_overlay_connect (void *cls,
1796 occ->peer = peer_list[p1]; 1879 occ->peer = peer_list[p1];
1797 occ->other_peer = peer_list[p2]; 1880 occ->other_peer = peer_list[p2];
1798 occ->op_id = GNUNET_ntohll (msg->operation_id); 1881 occ->op_id = GNUNET_ntohll (msg->operation_id);
1882 occ->timeout_task =
1883 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
1884 (GNUNET_TIME_UNIT_SECONDS, 30),
1885 &timeout_overlay_connect, occ);
1799 /* Connect to the core of 1st peer and wait for the 2nd peer to connect */ 1886 /* Connect to the core of 1st peer and wait for the 2nd peer to connect */
1887 occ->emsg = GNUNET_strdup ("Timeout while connecting to CORE");
1800 occ->ch = 1888 occ->ch =
1801 GNUNET_CORE_connect (occ->peer->cfg, occ, &core_startup_cb, 1889 GNUNET_CORE_connect (occ->peer->cfg, occ, &core_startup_cb,
1802 &overlay_connect_notify, NULL, NULL, GNUNET_NO, NULL, 1890 &overlay_connect_notify, NULL, NULL, GNUNET_NO, NULL,