From 0ac403717d4bde6dd8a74b6a640629aae645bf13 Mon Sep 17 00:00:00 2001 From: gardners Date: Sat, 16 Feb 2013 19:43:33 +1030 Subject: [PATCH] improve rhizome mdp re-request timeout handling so that it doesn't do amazingly bad things on low-bandwidth packet radio links. --- rhizome_fetch.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/rhizome_fetch.c b/rhizome_fetch.c index f4178b6d..68263eb1 100644 --- a/rhizome_fetch.c +++ b/rhizome_fetch.c @@ -1111,6 +1111,23 @@ static void rhizome_fetch_mdp_slot_callback(struct sched_ent *alarm) OUT(); } +static int rhizome_fetch_mdp_touch_timeout(struct rhizome_fetch_slot *slot) +{ + // 266ms @ 1mbit (WiFi broadcast speed) = 32x1024 byte packets. + // But on a packet radio interface at perhaps 50kbit, this is clearly + // a bad policy. Ideally we should know about the interface speed + // and adjust behaviour accordingly. + // For now, we will just make the timeout 1 second from the time of the last + // received block. + unschedule(&slot->alarm); + slot->alarm.stats=&rfmsc_stats; + slot->alarm.function = rhizome_fetch_mdp_slot_callback; + slot->alarm.alarm=gettime_ms()+1000; + slot->alarm.deadline=slot->alarm.alarm+500; + schedule(&slot->alarm); + return 0; +} + static int rhizome_fetch_mdp_requestblocks(struct rhizome_fetch_slot *slot) { IN(); @@ -1150,13 +1167,7 @@ static int rhizome_fetch_mdp_requestblocks(struct rhizome_fetch_slot *slot) // interval based on how fast the packets arrive. slot->mdpResponsesOutstanding=32; // TODO: set according to bitmap - unschedule(&slot->alarm); - slot->alarm.stats=&rfmsc_stats; - slot->alarm.function = rhizome_fetch_mdp_slot_callback; - // 266ms @ 1mbit (WiFi broadcast speed) = 32x1024 byte packets. - slot->alarm.alarm=gettime_ms()+266; - slot->alarm.deadline=slot->alarm.alarm+500; - schedule(&slot->alarm); + rhizome_fetch_mdp_touch_timeout(slot); RETURN(0); } @@ -1514,6 +1525,7 @@ int rhizome_received_content(unsigned char *bidprefix, if (slot->file_ofs==offset) { if (!rhizome_write_content(slot,(char *)bytes,count)) { + rhizome_fetch_mdp_touch_timeout(slot); slot->mdpResponsesOutstanding--; if (slot->mdpResponsesOutstanding==0) { // We have received all responses, so immediately ask for more