aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_http.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-07-10 13:35:28 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-07-10 13:35:28 +0000
commitf42ded3716ac792efe84e05cc6f1d5d5d8523e69 (patch)
tree8599e71f4ff9de1f1983cd46820d789b5e2ae1c3 /src/transport/plugin_transport_http.c
parent61b74e5d953a59b93d8e814c1e55965c015818aa (diff)
downloadgnunet-f42ded3716ac792efe84e05cc6f1d5d5d8523e69.tar.gz
gnunet-f42ded3716ac792efe84e05cc6f1d5d5d8523e69.zip
- improving client disconnect code to fix mantis 2486
Diffstat (limited to 'src/transport/plugin_transport_http.c')
-rw-r--r--src/transport/plugin_transport_http.c123
1 files changed, 56 insertions, 67 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c
index 9b23be168..b3c463382 100644
--- a/src/transport/plugin_transport_http.c
+++ b/src/transport/plugin_transport_http.c
@@ -585,12 +585,34 @@ exist_session (struct Plugin *plugin, struct Session *s)
585 return GNUNET_NO; 585 return GNUNET_NO;
586} 586}
587 587
588/**
589 * Deleting the session
590 * Must not be used afterwards
591 */
588 592
589void 593void
590delete_session (struct Session *s) 594delete_session (struct Session *s)
591{ 595{
596 struct Plugin *plugin = s->plugin;
592 stop_session_timeout(s); 597 stop_session_timeout(s);
593 598
599 GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s);
600 struct HTTP_Message *msg = s->msg_head;
601 struct HTTP_Message *tmp = NULL;
602
603 while (msg != NULL)
604 {
605 tmp = msg->next;
606
607 GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg);
608 if (msg->transmit_cont != NULL)
609 {
610 msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_SYSERR);
611 }
612 GNUNET_free (msg);
613 msg = tmp;
614 }
615
594 if (s->msg_tk != NULL) 616 if (s->msg_tk != NULL)
595 { 617 {
596 GNUNET_SERVER_mst_destroy (s->msg_tk); 618 GNUNET_SERVER_mst_destroy (s->msg_tk);
@@ -669,11 +691,12 @@ notify_session_end (void *cls, const struct GNUNET_PeerIdentity *peer,
669{ 691{
670 struct Plugin *plugin = cls; 692 struct Plugin *plugin = cls;
671 693
672 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, 694 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
673 "Notifying transport about ending session %p\n"); 695 "Notifying transport about ending session %p (`%s')\n",
696 s,
697 http_plugin_address_to_string(NULL, s->addr,s->addrlen));
674 698
675 plugin->env->session_end (plugin->env->cls, peer, s); 699 plugin->env->session_end (plugin->env->cls, peer, s);
676 GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s);
677 delete_session (s); 700 delete_session (s);
678} 701}
679 702
@@ -845,7 +868,7 @@ http_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
845 struct Session *next = NULL; 868 struct Session *next = NULL;
846 struct Session *s = plugin->head; 869 struct Session *s = plugin->head;
847 870
848 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, 871 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
849 "Transport tells me to disconnect `%s'\n", 872 "Transport tells me to disconnect `%s'\n",
850 GNUNET_i2s (target)); 873 GNUNET_i2s (target));
851 while (s != NULL) 874 while (s != NULL)
@@ -853,29 +876,15 @@ http_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
853 next = s->next; 876 next = s->next;
854 if (0 == memcmp (target, &s->target, sizeof (struct GNUNET_PeerIdentity))) 877 if (0 == memcmp (target, &s->target, sizeof (struct GNUNET_PeerIdentity)))
855 { 878 {
879 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
880 "Disconnecting %s session %p to `%s'\n",
881 (s->inbound == GNUNET_NO) ? "outbound" : "inbound",
882 s, GNUNET_i2s (target));
883
856 if (s->inbound == GNUNET_NO) 884 if (s->inbound == GNUNET_NO)
857 GNUNET_assert (GNUNET_OK == client_disconnect (s)); 885 GNUNET_assert (GNUNET_OK == client_disconnect (s));
858 else 886 else
859 GNUNET_assert (GNUNET_OK == server_disconnect (s)); 887 GNUNET_assert (GNUNET_OK == server_disconnect (s));
860 GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s);
861
862 struct HTTP_Message *msg = s->msg_head;
863 struct HTTP_Message *tmp = NULL;
864
865 while (msg != NULL)
866 {
867 tmp = msg->next;
868
869 GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg);
870 if (msg->transmit_cont != NULL)
871 {
872 msg->transmit_cont (msg->transmit_cont_cls, target, GNUNET_SYSERR);
873 }
874 GNUNET_free (msg);
875 msg = tmp;
876 }
877
878 delete_session (s);
879 } 888 }
880 s = next; 889 s = next;
881 } 890 }
@@ -1326,10 +1335,6 @@ start_report_addresses (struct Plugin *plugin)
1326 while (res > 0) 1335 while (res > 0)
1327 { 1336 {
1328 res--; 1337 res--;
1329#if 0
1330 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, _("FREEING %s\n"),
1331 GNUNET_a2s (addrs[res], addrlens[res]));
1332#endif
1333 GNUNET_assert (addrs[res] != NULL); 1338 GNUNET_assert (addrs[res] != NULL);
1334 GNUNET_free (addrs[res]); 1339 GNUNET_free (addrs[res]);
1335 } 1340 }
@@ -1500,6 +1505,16 @@ fail:
1500 return res; 1505 return res;
1501} 1506}
1502 1507
1508#define TESTING GNUNET_NO
1509
1510#if TESTING
1511#define TIMEOUT_LOG GNUNET_ERROR_TYPE_ERROR
1512#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
1513#else
1514#define TIMEOUT_LOG GNUNET_ERROR_TYPE_DEBUG
1515#define TIMEOUT GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
1516#endif
1517
1503 1518
1504/** 1519/**
1505 * Session was idle, so disconnect it 1520 * Session was idle, so disconnect it
@@ -1511,9 +1526,9 @@ session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1511 struct Session *s = cls; 1526 struct Session *s = cls;
1512 1527
1513 s->timeout_task = GNUNET_SCHEDULER_NO_TASK; 1528 s->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1514 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1529 GNUNET_log (TIMEOUT_LOG,
1515 "Session %p was idle for %llu ms, disconnecting\n", 1530 "Session %p was idle for %llu ms, disconnecting\n",
1516 s, (unsigned long long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value); 1531 s, (unsigned long long) TIMEOUT.rel_value);
1517 1532
1518 /* call session destroy function */ 1533 /* call session destroy function */
1519 if (s->inbound == GNUNET_NO) 1534 if (s->inbound == GNUNET_NO)
@@ -1531,12 +1546,12 @@ start_session_timeout (struct Session *s)
1531{ 1546{
1532 GNUNET_assert (NULL != s); 1547 GNUNET_assert (NULL != s);
1533 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == s->timeout_task); 1548 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == s->timeout_task);
1534 s->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 1549 s->timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
1535 &session_timeout, 1550 &session_timeout,
1536 s); 1551 s);
1537 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1552 GNUNET_log (TIMEOUT_LOG,
1538 "Timeout for session %p set to %llu ms\n", 1553 "Timeout for session %p set to %llu ms\n",
1539 s, (unsigned long long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value); 1554 s, (unsigned long long) TIMEOUT.rel_value);
1540} 1555}
1541 1556
1542 1557
@@ -1550,12 +1565,12 @@ reschedule_session_timeout (struct Session *s)
1550 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != s->timeout_task); 1565 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != s->timeout_task);
1551 1566
1552 GNUNET_SCHEDULER_cancel (s->timeout_task); 1567 GNUNET_SCHEDULER_cancel (s->timeout_task);
1553 s->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 1568 s->timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
1554 &session_timeout, 1569 &session_timeout,
1555 s); 1570 s);
1556 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1571 GNUNET_log (TIMEOUT_LOG,
1557 "Timeout rescheduled for session %p set to %llu ms\n", 1572 "Timeout rescheduled for session %p set to %llu ms\n",
1558 s, (unsigned long long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value); 1573 s, (unsigned long long) TIMEOUT.rel_value);
1559} 1574}
1560 1575
1561 1576
@@ -1571,9 +1586,9 @@ stop_session_timeout (struct Session *s)
1571 { 1586 {
1572 GNUNET_SCHEDULER_cancel (s->timeout_task); 1587 GNUNET_SCHEDULER_cancel (s->timeout_task);
1573 s->timeout_task = GNUNET_SCHEDULER_NO_TASK; 1588 s->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1574 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1589 GNUNET_log (TIMEOUT_LOG,
1575 "Timeout stopped for session %p canceled\n", 1590 "Timeout stopped for session %p\n",
1576 s, (unsigned long long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value); 1591 s);
1577 } 1592 }
1578} 1593}
1579 1594
@@ -1680,6 +1695,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
1680 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 1695 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
1681 struct Plugin *plugin = api->cls; 1696 struct Plugin *plugin = api->cls;
1682 struct Session *s; 1697 struct Session *s;
1698 struct Session *next;
1683 1699
1684 if (NULL == plugin) 1700 if (NULL == plugin)
1685 { 1701 {
@@ -1694,13 +1710,14 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
1694 s = plugin->head; 1710 s = plugin->head;
1695 while (s != NULL) 1711 while (s != NULL)
1696 { 1712 {
1713 next = s->next;
1697 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 1714 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1698 "Disconnecting `%s' \n", GNUNET_i2s (&s->target)); 1715 "Disconnecting `%s' \n", GNUNET_i2s (&s->target));
1699 if (s->inbound == GNUNET_NO) 1716 if (s->inbound == GNUNET_NO)
1700 GNUNET_assert (GNUNET_OK == client_disconnect (s)); 1717 GNUNET_assert (GNUNET_OK == client_disconnect (s));
1701 else 1718 else
1702 GNUNET_assert (GNUNET_OK == server_disconnect (s)); 1719 GNUNET_assert (GNUNET_OK == server_disconnect (s));
1703 s = s->next; 1720 s = next;
1704 } 1721 }
1705 1722
1706 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Stopping server\n"); 1723 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Stopping server\n");
@@ -1711,34 +1728,6 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
1711 /* Stop client */ 1728 /* Stop client */
1712 client_stop (plugin); 1729 client_stop (plugin);
1713 1730
1714 /* deleting up sessions */
1715 s = plugin->head;
1716 while (s != NULL)
1717 {
1718 struct Session *t = s->next;
1719
1720 GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s);
1721
1722 struct HTTP_Message *msg = s->msg_head;
1723 struct HTTP_Message *tmp = NULL;
1724
1725 while (msg != NULL)
1726 {
1727 tmp = msg->next;
1728
1729 GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg);
1730 if (msg->transmit_cont != NULL)
1731 {
1732 msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_SYSERR);
1733 }
1734 GNUNET_free (msg);
1735 msg = tmp;
1736 }
1737
1738 delete_session (s);
1739 s = t;
1740 }
1741
1742 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 1731 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1743 "Plugin `%s' unloaded\n", plugin->name); 1732 "Plugin `%s' unloaded\n", plugin->name);
1744 GNUNET_free_non_null (plugin->server_addr_v4); 1733 GNUNET_free_non_null (plugin->server_addr_v4);