prefer udp trackers. Fixes #433

This commit is contained in:
Arvid Norberg 2008-12-08 09:13:21 +00:00
parent b41cdd6469
commit 2a9353cf48
4 changed files with 54 additions and 0 deletions

View File

@ -3146,6 +3146,7 @@ that will be sent to the tracker. The user-agent is a good way to identify your
bool rate_limit_ip_overhead;
bool announce_to_all_trackers;
bool prefer_udp_trackers;
};
``user_agent`` this is the client identification to the tracker.
@ -3438,6 +3439,11 @@ set to false, the behavior is as defined by the multi tracker
specification. It defaults to false, which is the same behavior previous
versions of libtorrent has had as well.
``prefer_udp_trackers`` is true by default. It means that trackers may
be rearranged in a way that udp trackers are always tried before http
trackers for the same hostname. Setting this to fails means that the
trackers' tier is respected and there's no preference of one protocol
over another.
pe_settings
===========

View File

@ -145,6 +145,7 @@ namespace libtorrent
, auto_manage_startup(120)
, rate_limit_ip_overhead(true)
, announce_to_all_trackers(false)
, prefer_udp_trackers(true)
{}
// this is the user agent that will be sent to the tracker
@ -462,6 +463,11 @@ namespace libtorrent
// the same way uTorrent treats them. It defaults to
// false in order to comply with the extension definition.
bool announce_to_all_trackers;
// when this is set to true, if there is a tracker entry
// with udp:// protocol, it is preferred over the same
// tracker over http://.
bool prefer_udp_trackers;
};
#ifndef TORRENT_DISABLE_DHT

View File

@ -680,6 +680,7 @@ namespace libtorrent
bool request_bandwidth_from_session(int channel) const;
void update_peer_interest(bool was_finished);
void prioritize_udp_trackers();
policy m_policy;

View File

@ -191,6 +191,9 @@ namespace libtorrent
{
if (resume_data) m_resume_data.swap(*resume_data);
if (m_settings.prefer_udp_trackers)
prioritize_udp_trackers();
#ifndef TORRENT_DISABLE_ENCRYPTION
hasher h;
h.update("req2", 4);
@ -2206,10 +2209,45 @@ namespace libtorrent
, end(m_trackers.end()); i != end; ++i)
if (i->source == 0) i->source = announce_entry::source_client;
if (m_settings.prefer_udp_trackers)
prioritize_udp_trackers();
if (!m_trackers.empty()) start_announcing();
else stop_announcing();
}
void torrent::prioritize_udp_trackers()
{
// look for udp-trackers
for (std::vector<announce_entry>::iterator i = m_trackers.begin()
, end(m_trackers.end()); i != end; ++i)
{
if (i->url.substr(0, 6) != "udp://") continue;
// now, look for trackers with the same hostname
// that is has higher priority than this one
// if we find one, swap with the udp-tracker
std::string udp_hostname;
using boost::tuples::ignore;
boost::tie(ignore, ignore, udp_hostname, ignore, ignore, ignore)
= parse_url_components(i->url);
for (std::vector<announce_entry>::iterator j = m_trackers.begin();
j != i; ++j)
{
std::string hostname;
boost::tie(ignore, ignore, hostname, ignore, ignore, ignore)
= parse_url_components(j->url);
if (hostname != udp_hostname) continue;
if (j->url.substr(0, 6) == "udp://") continue;
using std::swap;
using std::iter_swap;
swap(i->tier, j->tier);
iter_swap(i, j);
break;
}
}
}
void torrent::add_tracker(announce_entry const& url)
{
std::vector<announce_entry>::iterator k = std::find_if(m_trackers.begin()
@ -2788,6 +2826,9 @@ namespace libtorrent
}
std::sort(m_trackers.begin(), m_trackers.end(), boost::bind(&announce_entry::tier, _1)
< boost::bind(&announce_entry::tier, _2));
if (m_settings.prefer_udp_trackers)
prioritize_udp_trackers();
}
lazy_entry const* mapped_files = rd.dict_find_list("mapped_files");