aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-05-25 14:04:41 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-05-25 14:04:41 +0000
commit70b173c768c3a43fc392507562df0ede641edbbe (patch)
tree8561d190e02e09e226219f0421859341bde24e36
parentd87b9a8065669e71342b8e6823b596b1db02f4d6 (diff)
downloadgnunet-70b173c768c3a43fc392507562df0ede641edbbe.tar.gz
gnunet-70b173c768c3a43fc392507562df0ede641edbbe.zip
- timeout for http/s
-rw-r--r--src/transport/plugin_transport_http.c121
-rw-r--r--src/transport/plugin_transport_http.h10
2 files changed, 114 insertions, 17 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c
index de616173e..37f7f798d 100644
--- a/src/transport/plugin_transport_http.c
+++ b/src/transport/plugin_transport_http.c
@@ -106,7 +106,23 @@ struct PrettyPrinterContext
106 */ 106 */
107struct Plugin; 107struct Plugin;
108 108
109/**
110 * Start session timeout
111 */
112static void
113start_session_timeout (struct Session *s);
109 114
115/**
116 * Increment session timeout due to activity
117 */
118static void
119reschedule_session_timeout (struct Session *s);
120
121/**
122 * Cancel timeout
123 */
124static void
125stop_session_timeout (struct Session *s);
110 126
111/** 127/**
112 * Append our port and forward the result. 128 * Append our port and forward the result.
@@ -320,6 +336,8 @@ http_plugin_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
320 atsi[1].value = session->ats_address_network_type; 336 atsi[1].value = session->ats_address_network_type;
321 GNUNET_break (session->ats_address_network_type != ntohl (GNUNET_ATS_NET_UNSPECIFIED)); 337 GNUNET_break (session->ats_address_network_type != ntohl (GNUNET_ATS_NET_UNSPECIFIED));
322 338
339 reschedule_session_timeout (session);
340
323 delay = 341 delay =
324 plugin->env->receive (plugin->env->cls, &s->target, message, 342 plugin->env->receive (plugin->env->cls, &s->target, message,
325 (const struct GNUNET_ATS_Information *) &atsi, 343 (const struct GNUNET_ATS_Information *) &atsi,
@@ -575,6 +593,8 @@ exist_session (struct Plugin *plugin, struct Session *s)
575void 593void
576delete_session (struct Session *s) 594delete_session (struct Session *s)
577{ 595{
596 stop_session_timeout(s);
597
578 if (s->msg_tk != NULL) 598 if (s->msg_tk != NULL)
579 { 599 {
580 GNUNET_SERVER_mst_destroy (s->msg_tk); 600 GNUNET_SERVER_mst_destroy (s->msg_tk);
@@ -588,8 +608,7 @@ delete_session (struct Session *s)
588 608
589struct Session * 609struct Session *
590create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, 610create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
591 const void *addr, size_t addrlen, 611 const void *addr, size_t addrlen)
592 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
593{ 612{
594 struct Session *s = NULL; 613 struct Session *s = NULL;
595 614
@@ -604,9 +623,12 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
604 s->next = NULL; 623 s->next = NULL;
605 s->next_receive = GNUNET_TIME_absolute_get_zero (); 624 s->next_receive = GNUNET_TIME_absolute_get_zero ();
606 s->ats_address_network_type = htonl (GNUNET_ATS_NET_UNSPECIFIED); 625 s->ats_address_network_type = htonl (GNUNET_ATS_NET_UNSPECIFIED);
626 start_session_timeout(s);
607 return s; 627 return s;
608} 628}
609 629
630
631
610void 632void
611notify_session_end (void *cls, const struct GNUNET_PeerIdentity *peer, 633notify_session_end (void *cls, const struct GNUNET_PeerIdentity *peer,
612 struct Session *s) 634 struct Session *s)
@@ -662,16 +684,7 @@ http_get_session (void *cls,
662 GNUNET_assert ((addrlen == sizeof (struct IPv6HttpAddress)) || 684 GNUNET_assert ((addrlen == sizeof (struct IPv6HttpAddress)) ||
663 (addrlen == sizeof (struct IPv4HttpAddress))); 685 (addrlen == sizeof (struct IPv4HttpAddress)));
664 686
665 s = GNUNET_malloc (sizeof (struct Session)); 687 s = create_session (plugin, &address->peer, address->address, address->address_length);
666 memcpy (&s->target, &address->peer, sizeof (struct GNUNET_PeerIdentity));
667 s->plugin = plugin;
668 s->addr = GNUNET_malloc (address->address_length);
669 memcpy (s->addr, address->address, address->address_length);
670 s->addrlen = addrlen;
671 s->next = NULL;
672 s->next_receive = GNUNET_TIME_absolute_get_zero ();
673 s->inbound = GNUNET_NO;
674 s->ats_address_network_type = htonl (GNUNET_ATS_NET_UNSPECIFIED);
675 688
676 /* Get ATS type */ 689 /* Get ATS type */
677 if (addrlen == sizeof (struct IPv4HttpAddress)) 690 if (addrlen == sizeof (struct IPv4HttpAddress))
@@ -790,6 +803,8 @@ http_plugin_send (void *cls,
790 msg->transmit_cont_cls = cont_cls; 803 msg->transmit_cont_cls = cont_cls;
791 memcpy (msg->buf, msgbuf, msgbuf_size); 804 memcpy (msg->buf, msgbuf, msgbuf_size);
792 805
806 reschedule_session_timeout (session);
807
793 if (session->inbound == GNUNET_NO) 808 if (session->inbound == GNUNET_NO)
794 { 809 {
795 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, 810 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
@@ -1468,6 +1483,88 @@ fail:
1468 return res; 1483 return res;
1469} 1484}
1470 1485
1486
1487/**
1488 * Session was idle, so disconnect it
1489 */
1490static void
1491session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1492{
1493 GNUNET_assert (NULL != cls);
1494 struct Session *s = cls;
1495
1496 s->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1497
1498 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Session %p was idle for %llu, disconnecting\n",
1499 s, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
1500
1501 /* call session destroy function */
1502 if (s->inbound == GNUNET_NO)
1503 GNUNET_assert (GNUNET_OK == client_disconnect (s));
1504 else
1505 GNUNET_assert (GNUNET_OK == server_disconnect (s));
1506
1507}
1508
1509/**
1510 * Start session timeout
1511 */
1512static void
1513start_session_timeout (struct Session *s)
1514{
1515 GNUNET_assert (NULL != s);
1516 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == s->timeout_task);
1517
1518 s->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1519 &session_timeout,
1520 s);
1521
1522 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Timeout for session %p set to %llu\n",
1523 s, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
1524}
1525
1526/**
1527 * Increment session timeout due to activity
1528 */
1529static void
1530reschedule_session_timeout (struct Session *s)
1531{
1532 GNUNET_assert (NULL != s);
1533 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != s->timeout_task);
1534
1535 GNUNET_SCHEDULER_cancel (s->timeout_task);
1536 s->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1537 &session_timeout,
1538 s);
1539
1540 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Timeout rescheduled for session %p set to %llu\n",
1541 s, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
1542}
1543
1544/**
1545 * Cancel timeout
1546 */
1547static void
1548stop_session_timeout (struct Session *s)
1549{
1550 GNUNET_assert (NULL != s);
1551
1552 if (GNUNET_SCHEDULER_NO_TASK != s->timeout_task)
1553 {
1554 GNUNET_SCHEDULER_cancel (s->timeout_task);
1555 s->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1556
1557 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Timeout rescheduled for session %p canceled\n",
1558 s, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
1559 }
1560 else
1561 {
1562 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Timeout for session %p was not active\n",
1563 s);
1564 }
1565}
1566
1567
1471/** 1568/**
1472 * Entry point for the plugin. 1569 * Entry point for the plugin.
1473 */ 1570 */
diff --git a/src/transport/plugin_transport_http.h b/src/transport/plugin_transport_http.h
index 89fb86dd9..b1a7fcaf3 100644
--- a/src/transport/plugin_transport_http.h
+++ b/src/transport/plugin_transport_http.h
@@ -400,6 +400,11 @@ struct Session
400 GNUNET_SCHEDULER_TaskIdentifier recv_wakeup_task; 400 GNUNET_SCHEDULER_TaskIdentifier recv_wakeup_task;
401 401
402 /** 402 /**
403 * Session timeout task
404 */
405 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
406
407 /**
403 * Is client send handle paused since there are no data to send? 408 * Is client send handle paused since there are no data to send?
404 * GNUNET_YES/NO 409 * GNUNET_YES/NO
405 */ 410 */
@@ -469,11 +474,6 @@ exist_session (struct Plugin *plugin, struct Session *s);
469void 474void
470delete_session (struct Session *s); 475delete_session (struct Session *s);
471 476
472struct Session *
473create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
474 const void *addr, size_t addrlen,
475 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls);
476
477int 477int
478exist_session (struct Plugin *plugin, struct Session *s); 478exist_session (struct Plugin *plugin, struct Session *s);
479 479