support trackerid tracker extension

This commit is contained in:
Arvid Norberg 2010-11-18 05:51:52 +00:00
parent 40ed231366
commit a05acc4bac
10 changed files with 55 additions and 5 deletions

View File

@ -1,3 +1,4 @@
* support trackerid tracker extension
* graceful peer disconnect mode which finishes transactions before disconnecting peers
* support chunked encoding for web seeds
* optimized session startup time

View File

@ -84,6 +84,7 @@ namespace libtorrent
bool upload_mode;
std::vector<boost::uint8_t> const* file_priorities;
bool share_mode;
std::string trackerid;
};
}

View File

@ -1167,6 +1167,23 @@ namespace libtorrent
virtual std::string message() const;
};
struct TORRENT_EXPORT trackerid_alert: tracker_alert
{
trackerid_alert(torrent_handle const& h
, std::string const& url_
, const std::string& id)
: tracker_alert(h, url_)
, trackerid(id)
{}
TORRENT_DEFINE_ALERT(trackerid_alert);
const static int static_category = alert::status_notification;
virtual std::string message() const;
std::string trackerid;
};
}

View File

@ -444,7 +444,8 @@ namespace libtorrent
, address const& tracker_ip
, std::list<address> const& ip_list
, std::vector<peer_entry>& e, int interval, int min_interval
, int complete, int incomplete, address const& external_ip);
, int complete, int incomplete, address const& external_ip
, std::string const& trackerid);
virtual void tracker_request_error(tracker_request const& r
, int response_code, error_code const& ec, const std::string& msg
, int retry_interval);
@ -942,6 +943,7 @@ namespace libtorrent
// this list is sorted by time_critical_piece::deadline
std::list<time_critical_piece> m_time_critical_pieces;
std::string m_trackerid;
std::string m_username;
std::string m_password;

View File

@ -91,6 +91,7 @@ namespace libtorrent
// tracker URL as it appeared in the torrent file
std::string url;
std::string trackerid;
// if this tracker has returned an error or warning message
// that message is stored here

View File

@ -115,6 +115,7 @@ namespace libtorrent
unsigned short listen_port;
event_t event;
std::string url;
std::string trackerid;
int key;
int num_want;
std::string ipv6;
@ -142,7 +143,8 @@ namespace libtorrent
, int min_interval
, int complete
, int incomplete
, address const& external_ip) = 0;
, address const& external_ip
, std::string const& trackerid) = 0;
virtual void tracker_request_error(
tracker_request const& req
, int response_code

View File

@ -486,5 +486,10 @@ namespace libtorrent {
return msg;
}
std::string trackerid_alert::message() const
{
return "trackerid received: " + trackerid;
}
} // namespace libtorrent

View File

@ -156,6 +156,12 @@ namespace libtorrent
if (m_ses.get_pe_settings().in_enc_policy != pe_settings::disabled)
url += "&supportcrypto=1";
#endif
if (!tracker_req().trackerid.empty())
{
std::string id = tracker_req().trackerid;
url += "&trackerid=";
url += escape_string(id.c_str(), id.length());
}
if (tracker_req().event != tracker_request::none)
{
@ -363,6 +369,10 @@ namespace libtorrent
int interval = e.dict_find_int_value("interval", 1800);
int min_interval = e.dict_find_int_value("min interval", 60);
std::string trackerid;
lazy_entry const* tracker_id = e.dict_find_string("tracker id");
if (tracker_id)
trackerid = tracker_id->string_value();
// parse the response
lazy_entry const* failure = e.dict_find_string("failure reason");
if (failure)
@ -506,7 +516,7 @@ namespace libtorrent
}
cb->tracker_response(tracker_req(), m_tracker_ip, ip_list, peer_list
, interval, min_interval, complete, incomplete, external_ip);
, interval, min_interval, complete, incomplete, external_ip, trackerid);
}
}

View File

@ -329,6 +329,7 @@ namespace libtorrent
, m_ses(ses)
, m_trackers(m_torrent_file->trackers())
, m_save_path(complete(p.save_path))
, m_trackerid(p.trackerid)
, m_storage_constructor(p.storage)
, m_ratio(0.f)
, m_available_free_upload(0)
@ -1494,6 +1495,8 @@ namespace libtorrent
for (int i = 0; i < int(m_trackers.size()); ++i)
{
announce_entry& ae = m_trackers[i];
// if trackerid is not specified for tracker use default one, probably set explicitly
req.trackerid = ae.trackerid.empty() ? m_trackerid : ae.trackerid;
if (settings().announce_to_all_tiers
&& !settings().announce_to_all_trackers
&& sent_announce
@ -1652,7 +1655,8 @@ namespace libtorrent
, int min_interval
, int complete
, int incomplete
, address const& external_ip)
, address const& external_ip
, const std::string& trackerid)
{
TORRENT_ASSERT(m_ses.is_network_thread());
@ -1681,6 +1685,13 @@ namespace libtorrent
ae->min_announce = now + seconds(min_interval);
int tracker_index = ae - &m_trackers[0];
m_last_working_tracker = prioritize_tracker(tracker_index);
if ((!trackerid.empty()) && (ae->trackerid != trackerid))
{
ae->trackerid = trackerid;
if (m_ses.m_alerts.should_post<trackerid_alert>())
m_ses.m_alerts.post_alert(trackerid_alert(get_handle(), r.url, trackerid));
}
}
update_tracker_timer(now);

View File

@ -527,7 +527,7 @@ namespace libtorrent
}
cb->tracker_response(tracker_req(), m_target.address(), ip_list
, peer_list, interval, min_interval, complete, incomplete, address());
, peer_list, interval, min_interval, complete, incomplete, address(), "" /*trackerid*/);
close();
return true;