From 4b9087b60d9f1bb1d48b97070f2eb611699b71a2 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 11 Mar 2013 20:33:49 +0000 Subject: [PATCH] removed dead-end for peers not answering downloads, that would get file cache transfers to get stuck indefinitly when peers are too much stressed for a short period. The offline state is entirely given by setPeerState() git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6206 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/ft/fttransfermodule.cc | 34 +++++++++--------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/libretroshare/src/ft/fttransfermodule.cc b/libretroshare/src/ft/fttransfermodule.cc index 747076569..3bf394bc0 100644 --- a/libretroshare/src/ft/fttransfermodule.cc +++ b/libretroshare/src/ft/fttransfermodule.cc @@ -48,12 +48,11 @@ * */ -const double FT_TM_MAX_PEER_RATE = 10 * 1024 * 1024; /* 10MB/s */ -const uint32_t FT_TM_MAX_RESETS = 5; - -const uint32_t FT_TM_MINIMUM_CHUNK = 1024; /* ie 1Kb / sec */ -const uint32_t FT_TM_RESTART_DOWNLOAD = 20; /* 20 seconds */ -const uint32_t FT_TM_DOWNLOAD_TIMEOUT = 20; /* 10 seconds */ +const double FT_TM_MAX_PEER_RATE = 10 * 1024 * 1024; /* 10MB/s */ +const uint32_t FT_TM_MAX_RESETS = 5; +const uint32_t FT_TM_MINIMUM_CHUNK = 1024; /* ie 1Kb / sec */ +const uint32_t FT_TM_RESTART_DOWNLOAD = 20; /* 20 seconds */ +const uint32_t FT_TM_DOWNLOAD_TIMEOUT = 20; /* 10 seconds */ const uint32_t FT_TM_CRC_MAP_MAX_WAIT_PER_GIG = 20; /* 20 seconds per gigabyte */ // const double FT_TM_MAX_INCREASE = 1.00; @@ -873,38 +872,29 @@ bool ftTransferModule::locked_tickPeerTransfer(peerInfo &info) int ageReq = ts - info.lastTS; /* if offline - ignore */ - if ((info.state == PQIPEER_SUSPEND) || - (info.state == PQIPEER_NOT_ONLINE)) - { - + if(info.state == PQIPEER_SUSPEND) return false; - } if (ageReq > (int) (FT_TM_RESTART_DOWNLOAD * (info.nResets + 1))) { + // The succession of ifs, makes the process continue every 6 * FT_TM_RESTART_DOWNLOAD * FT_TM_MAX_RESETS seconds + // on average, which is one attempt every 600 seconds in the least, which corresponds to once every 10 minutes in + // average. + // if (info.nResets > 1) /* 3rd timeout */ { /* 90% chance of return false... * will mean variations in which peer * starts first. hopefully stop deadlocks. */ - if (rand() % 10 != 0) - { + if (rand() % 12 != 0) return false; - } } info.state = PQIPEER_DOWNLOADING; info.recvTS = ts; /* reset to activate */ - info.nResets++; + info.nResets = std::min(FT_TM_MAX_RESETS,info.nResets + 1); ageRecv = 0; - - if (info.nResets >= FT_TM_MAX_RESETS) - { - /* for this file anyway */ - info.state = PQIPEER_NOT_ONLINE; - return false; - } } if (ageRecv > (int) FT_TM_DOWNLOAD_TIMEOUT)