diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-10-05 11:53:18 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-10-05 11:53:18 +0000 |
commit | 87eac53659e293cf7366ca735cb5d1730b3fa19e (patch) | |
tree | cd6e1a9fccba8c9af44bb9987a976b2260e0310b /src/transport/plugin_transport_http.c | |
parent | 8c00da274a936ca1ec70bfb5e994a91317a30088 (diff) | |
download | gnunet-87eac53659e293cf7366ca735cb5d1730b3fa19e.tar.gz gnunet-87eac53659e293cf7366ca735cb5d1730b3fa19e.zip |
implemented inbound quota regulation
Diffstat (limited to 'src/transport/plugin_transport_http.c')
-rw-r--r-- | src/transport/plugin_transport_http.c | 99 |
1 files changed, 86 insertions, 13 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index eaa7b1199..675645aa3 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c | |||
@@ -223,6 +223,16 @@ struct HTTP_PeerContext | |||
223 | * Last session used to send data | 223 | * Last session used to send data |
224 | */ | 224 | */ |
225 | struct Session * last_session; | 225 | struct Session * last_session; |
226 | |||
227 | /** | ||
228 | * The task resetting inbound quota delay | ||
229 | */ | ||
230 | GNUNET_SCHEDULER_TaskIdentifier reset_task; | ||
231 | |||
232 | /** | ||
233 | * Delay from transport service inbound quota tracker when to receive data again | ||
234 | */ | ||
235 | struct GNUNET_TIME_Relative delay; | ||
226 | }; | 236 | }; |
227 | 237 | ||
228 | 238 | ||
@@ -516,6 +526,27 @@ static int send_check_connections (struct Plugin *plugin, struct Session *ps); | |||
516 | */ | 526 | */ |
517 | static int curl_schedule (struct Plugin *plugin); | 527 | static int curl_schedule (struct Plugin *plugin); |
518 | 528 | ||
529 | /** | ||
530 | * Task scheduled to reset the inbound quota delay for a specific peer | ||
531 | * @param cls plugin as closure | ||
532 | * @param tc task context | ||
533 | */ | ||
534 | static void reset_inbound_quota_delay (void *cls, | ||
535 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
536 | { | ||
537 | struct HTTP_PeerContext * pc; | ||
538 | |||
539 | GNUNET_assert(cls !=NULL); | ||
540 | |||
541 | pc = (struct HTTP_PeerContext *) cls; | ||
542 | pc->reset_task = GNUNET_SCHEDULER_NO_TASK; | ||
543 | |||
544 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
545 | return; | ||
546 | |||
547 | pc->delay = GNUNET_TIME_relative_get_zero (); | ||
548 | } | ||
549 | |||
519 | 550 | ||
520 | /** | 551 | /** |
521 | * Creates a valid url from passed address and id | 552 | * Creates a valid url from passed address and id |
@@ -824,7 +855,7 @@ static void mhd_write_mst_cb (void *cls, | |||
824 | void *client, | 855 | void *client, |
825 | const struct GNUNET_MessageHeader *message) | 856 | const struct GNUNET_MessageHeader *message) |
826 | { | 857 | { |
827 | 858 | struct GNUNET_TIME_Relative delay; | |
828 | struct Session *ps = cls; | 859 | struct Session *ps = cls; |
829 | GNUNET_assert(ps != NULL); | 860 | GNUNET_assert(ps != NULL); |
830 | 861 | ||
@@ -838,11 +869,22 @@ static void mhd_write_mst_cb (void *cls, | |||
838 | ntohs(message->size), | 869 | ntohs(message->size), |
839 | GNUNET_i2s(&(ps->peercontext)->identity),http_plugin_address_to_string(NULL,ps->addr,ps->addrlen)); | 870 | GNUNET_i2s(&(ps->peercontext)->identity),http_plugin_address_to_string(NULL,ps->addr,ps->addrlen)); |
840 | #endif | 871 | #endif |
841 | pc->plugin->env->receive (ps->peercontext->plugin->env->cls, | 872 | delay = pc->plugin->env->receive (ps->peercontext->plugin->env->cls, |
842 | &pc->identity, | 873 | &pc->identity, |
843 | message, 1, ps, | 874 | message, 1, ps, |
844 | NULL, | 875 | NULL, |
845 | 0); | 876 | 0); |
877 | pc->delay = delay; | ||
878 | if (pc->reset_task != GNUNET_SCHEDULER_NO_TASK) | ||
879 | GNUNET_SCHEDULER_cancel (pc->plugin->env->sched, pc->reset_task); | ||
880 | |||
881 | if (delay.value > 0) | ||
882 | { | ||
883 | #if DEBUG_HTTP | ||
884 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR,"Connection %X: Inbound quota management: delay next read for %llu ms \n", ps, delay.value); | ||
885 | #endif | ||
886 | pc->reset_task = GNUNET_SCHEDULER_add_delayed (pc->plugin->env->sched, delay, &reset_inbound_quota_delay, pc); | ||
887 | } | ||
846 | } | 888 | } |
847 | 889 | ||
848 | /** | 890 | /** |
@@ -1133,8 +1175,17 @@ mdh_access_cb (void *cls, | |||
1133 | /* Recieving data */ | 1175 | /* Recieving data */ |
1134 | if ((*upload_data_size > 0) && (ps->recv_active == GNUNET_YES)) | 1176 | if ((*upload_data_size > 0) && (ps->recv_active == GNUNET_YES)) |
1135 | { | 1177 | { |
1136 | res = GNUNET_SERVER_mst_receive(ps->msgtok, ps, upload_data,*upload_data_size, GNUNET_NO, GNUNET_NO); | 1178 | if (pc->delay.value == 0) |
1137 | (*upload_data_size) = 0; | 1179 | { |
1180 | res = GNUNET_SERVER_mst_receive(ps->msgtok, ps, upload_data,*upload_data_size, GNUNET_NO, GNUNET_NO); | ||
1181 | (*upload_data_size) = 0; | ||
1182 | } | ||
1183 | else | ||
1184 | { | ||
1185 | #if DEBUG_HTTP | ||
1186 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: no inbound bandwidth available! Next read was delayed for %llu ms\n", ps, ps->peercontext->delay.value); | ||
1187 | #endif | ||
1188 | } | ||
1138 | return MHD_YES; | 1189 | return MHD_YES; |
1139 | } | 1190 | } |
1140 | else | 1191 | else |
@@ -1504,6 +1555,7 @@ static void curl_receive_mst_cb (void *cls, | |||
1504 | const struct GNUNET_MessageHeader *message) | 1555 | const struct GNUNET_MessageHeader *message) |
1505 | { | 1556 | { |
1506 | struct Session *ps = cls; | 1557 | struct Session *ps = cls; |
1558 | struct GNUNET_TIME_Relative delay; | ||
1507 | GNUNET_assert(ps != NULL); | 1559 | GNUNET_assert(ps != NULL); |
1508 | 1560 | ||
1509 | struct HTTP_PeerContext *pc = ps->peercontext; | 1561 | struct HTTP_PeerContext *pc = ps->peercontext; |
@@ -1516,11 +1568,23 @@ static void curl_receive_mst_cb (void *cls, | |||
1516 | ntohs(message->size), | 1568 | ntohs(message->size), |
1517 | GNUNET_i2s(&(pc->identity)),http_plugin_address_to_string(NULL,ps->addr,ps->addrlen)); | 1569 | GNUNET_i2s(&(pc->identity)),http_plugin_address_to_string(NULL,ps->addr,ps->addrlen)); |
1518 | #endif | 1570 | #endif |
1519 | pc->plugin->env->receive (pc->plugin->env->cls, | 1571 | delay = pc->plugin->env->receive (pc->plugin->env->cls, |
1520 | &pc->identity, | 1572 | &pc->identity, |
1521 | message, 1, ps, | 1573 | message, 1, ps, |
1522 | ps->addr, | 1574 | ps->addr, |
1523 | ps->addrlen); | 1575 | ps->addrlen); |
1576 | |||
1577 | pc->delay = delay; | ||
1578 | if (pc->reset_task != GNUNET_SCHEDULER_NO_TASK) | ||
1579 | GNUNET_SCHEDULER_cancel (pc->plugin->env->sched, pc->reset_task); | ||
1580 | |||
1581 | if (delay.value > 0) | ||
1582 | { | ||
1583 | #if DEBUG_HTTP | ||
1584 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR,"Connection %X: Inbound quota management: delay next read for %llu ms \n", ps, delay.value); | ||
1585 | #endif | ||
1586 | pc->reset_task = GNUNET_SCHEDULER_add_delayed (pc->plugin->env->sched, delay, &reset_inbound_quota_delay, pc); | ||
1587 | } | ||
1524 | } | 1588 | } |
1525 | 1589 | ||
1526 | 1590 | ||
@@ -1536,6 +1600,15 @@ static void curl_receive_mst_cb (void *cls, | |||
1536 | static size_t curl_receive_cb( void *stream, size_t size, size_t nmemb, void *ptr) | 1600 | static size_t curl_receive_cb( void *stream, size_t size, size_t nmemb, void *ptr) |
1537 | { | 1601 | { |
1538 | struct Session * ps = ptr; | 1602 | struct Session * ps = ptr; |
1603 | |||
1604 | if (ps->peercontext->delay.value > 0) | ||
1605 | { | ||
1606 | #if DEBUG_HTTP | ||
1607 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: no inbound bandwidth available! Next read was delayed for %llu ms\n", ps, ps->peercontext->delay.value); | ||
1608 | #endif | ||
1609 | return (0); | ||
1610 | } | ||
1611 | |||
1539 | #if DEBUG_CONNECTIONS | 1612 | #if DEBUG_CONNECTIONS |
1540 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: %u bytes received\n",ps, size*nmemb); | 1613 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: %u bytes received\n",ps, size*nmemb); |
1541 | #endif | 1614 | #endif |