better error reports from tracker failures (with http status codes)

This commit is contained in:
Arvid Norberg 2005-04-20 23:00:27 +00:00
parent 7f7dac2d50
commit dc40b2e7cd
5 changed files with 29 additions and 9 deletions

View File

@ -1758,16 +1758,20 @@ struct file_error_alert: alert
<p>This alert is generated on tracker time outs, premature disconnects, invalid response or
a HTTP response other than &quot;200 OK&quot;. From the alert you can get the handle to the torrent
the tracker belongs to. This alert is generated as severity level <tt class="docutils literal"><span class="pre">warning</span></tt>.</p>
<p>The <tt class="docutils literal"><span class="pre">times_in_row</span></tt> member says how many times in a row this tracker has failed.</p>
<p>The <tt class="docutils literal"><span class="pre">times_in_row</span></tt> member says how many times in a row this tracker has failed.
<tt class="docutils literal"><span class="pre">status_code</span></tt> is the code returned from the HTTP server. 401 means the tracker needs
authentication, 404 means not found etc. If the tracker timed out, the code will be set
to 0.</p>
<pre class="literal-block">
struct tracker_alert: alert
{
tracker_alert(const torrent_handle&amp; h, int times
tracker_alert(const torrent_handle&amp; h, int times, int status
, const std::string&amp; msg);
virtual std::auto_ptr&lt;alert&gt; clone() const;
torrent_handle handle;
int times_in_row;
int status_code;
};
</pre>
</div>

View File

@ -1768,17 +1768,21 @@ a HTTP response other than "200 OK". From the alert you can get the handle to th
the tracker belongs to. This alert is generated as severity level ``warning``.
The ``times_in_row`` member says how many times in a row this tracker has failed.
``status_code`` is the code returned from the HTTP server. 401 means the tracker needs
authentication, 404 means not found etc. If the tracker timed out, the code will be set
to 0.
::
struct tracker_alert: alert
{
tracker_alert(const torrent_handle& h, int times
tracker_alert(const torrent_handle& h, int times, int status
, const std::string& msg);
virtual std::auto_ptr<alert> clone() const;
torrent_handle handle;
int times_in_row;
int status_code;
};

View File

@ -44,10 +44,12 @@ namespace libtorrent
{
tracker_alert(const torrent_handle& h
, int times
, int status
, const std::string& msg)
: alert(alert::warning, msg)
, handle(h)
, times_in_row(times)
, status_code(status)
{}
virtual std::auto_ptr<alert> clone() const
@ -55,6 +57,7 @@ namespace libtorrent
torrent_handle handle;
int times_in_row;
int status_code;
};
struct tracker_reply_alert: alert

View File

@ -503,8 +503,17 @@ namespace libtorrent
}
// handle tracker response
entry e = bdecode(m_buffer.begin(), m_buffer.end());
parse(e);
try
{
entry e = bdecode(m_buffer.begin(), m_buffer.end());
parse(e);
}
catch (std::exception&)
{
std::string error_str(m_buffer.begin(), m_buffer.end());
if (has_requester()) requester().tracker_request_error(m_req, m_code, error_str);
}
return true;
}
return false;
@ -641,11 +650,11 @@ namespace libtorrent
}
catch(type_error& e)
{
requester().tracker_request_error(m_req, -1, e.what());
requester().tracker_request_error(m_req, m_code, e.what());
}
catch(std::runtime_error& e)
{
requester().tracker_request_error(m_req, -1, e.what());
requester().tracker_request_error(m_req, m_code, e.what());
}
}

View File

@ -1278,7 +1278,7 @@ namespace libtorrent
<< m_trackers[m_currently_trying_tracker].url
<< "\" timed out";
m_ses.m_alerts.post_alert(tracker_alert(get_handle()
, m_failed_trackers + 1, s.str()));
, m_failed_trackers + 1, 0, s.str()));
}
try_next_tracker();
}
@ -1299,7 +1299,7 @@ namespace libtorrent
<< m_trackers[m_currently_trying_tracker].url
<< "\" " << str;
m_ses.m_alerts.post_alert(tracker_alert(get_handle()
, m_failed_trackers + 1, s.str()));
, m_failed_trackers + 1, response_code, s.str()));
}