supports retry for web seeds that respond with 503

This commit is contained in:
Arvid Norberg 2007-11-27 03:37:47 +00:00
parent 77cea2eafc
commit 1cc0118c9c
5 changed files with 39 additions and 1 deletions

View File

@ -542,6 +542,7 @@ int main(int ac, char* av[])
std::string proxy_login;
std::string proxy_type;
int poll_interval;
int wait_retry;
namespace po = boost::program_options;
try
@ -582,6 +583,9 @@ int main(int ac, char* av[])
("poll-interval,t", po::value<int>(&poll_interval)->default_value(2)
, "if a directory is being monitored, this is the interval (given "
"in seconds) between two refreshes of the directory listing")
("wait-retry,w", po::value<int>(&wait_retry)->default_value(30)
, "if the download of a url seed failes, this is the interval (given "
"in seconds) to wait until the next retry")
("half-open-limit,o", po::value<int>(&half_open_limit)->default_value(-1)
, "Sets the maximum number of simultaneous half-open tcp connections")
("bind,b", po::value<std::string>(&bind_to_interface)->default_value("")
@ -615,6 +619,7 @@ int main(int ac, char* av[])
if (download_limit <= 0) download_limit = -1;
if (upload_limit <= 0) upload_limit = -1;
if (poll_interval < 2) poll_interval = 2;
if (wait_retry < 0) wait_retry = 0;
if (half_open_limit < 1) half_open_limit = -1;
if (upload_slots_limit <= 0) upload_slots_limit = -1;
if (!monitor_dir.empty() && !exists(monitor_dir))
@ -681,6 +686,7 @@ int main(int ac, char* av[])
}
settings.user_agent = "client_test/" LIBTORRENT_VERSION;
settings.urlseed_wait_retry = wait_retry;
std::deque<std::string> events;

View File

@ -95,6 +95,7 @@ namespace libtorrent
, peer_timeout(120)
, urlseed_timeout(20)
, urlseed_pipeline_size(5)
, urlseed_wait_retry(30)
, file_pool_size(40)
, allow_multiple_connections_per_ip(false)
, max_failcount(3)
@ -185,6 +186,9 @@ namespace libtorrent
// controls the pipelining size of url-seeds
int urlseed_pipeline_size;
// time to wait until a new retry takes place
int urlseed_wait_retry;
// sets the upper limit on the total number of files this
// session will keep open. The reason why files are

View File

@ -254,6 +254,8 @@ namespace libtorrent
void remove_url_seed(std::string const& url)
{ m_web_seeds.erase(url); }
void retry_url_seed(std::string const& url);
std::set<std::string> url_seeds() const
{ return m_web_seeds; }
@ -626,6 +628,10 @@ namespace libtorrent
// The list of web seeds in this torrent. Seeds
// with fatal errors are removed from the set
std::set<std::string> m_web_seeds;
// a list of web seeds that have failed and are
// waiting to be retried
std::map<std::string, ptime> m_web_seeds_next_retry;
// urls of the web seeds that we are currently
// resolving the address for

View File

@ -2857,6 +2857,18 @@ namespace libtorrent
// if we have everything we want we don't need to connect to any web-seed
if (!is_finished() && !m_web_seeds.empty())
{
// re-insert urls that are to be retries into the m_web_seeds
typedef std::map<std::string, ptime>::iterator iter_t;
for (iter_t i = m_web_seeds_next_retry.begin(); i != m_web_seeds_next_retry.end();)
{
iter_t erase_element = i++;
if (erase_element->second <= time_now())
{
m_web_seeds.insert(erase_element->first);
m_web_seeds_next_retry.erase(erase_element);
}
}
// keep trying web-seeds if there are any
// first find out which web seeds we are connected to
std::set<std::string> web_seeds;
@ -2916,6 +2928,12 @@ namespace libtorrent
}
}
void torrent::retry_url_seed(std::string const& url)
{
m_web_seeds_next_retry[url] = time_now()
+ seconds(m_ses.settings().urlseed_wait_retry);
}
bool torrent::try_connect_peer()
{
TORRENT_ASSERT(want_more_peers());

View File

@ -360,7 +360,11 @@ namespace libtorrent
&& !(m_parser.status_code() >= 300 // redirect
&& m_parser.status_code() < 400))
{
// we should not try this server again.
if (m_parser.status_code() == 503)
{
// temporarily unavailable, retry later
t->retry_url_seed(m_url);
}
t->remove_url_seed(m_url);
std::string error_msg = boost::lexical_cast<std::string>(m_parser.status_code())
+ " " + m_parser.message();