*** empty log message ***
This commit is contained in:
parent
3689e48a3b
commit
a9b3c6dd41
|
@ -61,7 +61,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <cassert>
|
||||
|
@ -111,9 +111,9 @@ namespace libtorrent
|
|||
// of elements. Since the info-hash is reconstructed
|
||||
// from an entry, it's important that the order is
|
||||
// preserved.
|
||||
typedef std::vector<std::pair<std::string, entry> > dictionary_type;
|
||||
typedef std::list<std::pair<std::string, entry> > dictionary_type;
|
||||
typedef std::string string_type;
|
||||
typedef std::vector<entry> list_type;
|
||||
typedef std::list<entry> list_type;
|
||||
typedef size_type integer_type;
|
||||
|
||||
enum data_type
|
||||
|
|
|
@ -37,12 +37,21 @@ namespace libtorrent
|
|||
{
|
||||
struct resource_request
|
||||
{
|
||||
resource_request() : used(0), wanted(0), given(0) {}
|
||||
resource_request()
|
||||
: used(0)
|
||||
, min(0)
|
||||
, max(0)
|
||||
, given(0)
|
||||
{}
|
||||
|
||||
// I'm right now actively using:
|
||||
int used;
|
||||
// I would like to use this much:
|
||||
int wanted;
|
||||
|
||||
// given cannot be smaller than min
|
||||
// and not greater than max.
|
||||
int min;
|
||||
int max;
|
||||
|
||||
// Reply: Okay, you're allowed to use this much (a compromise):
|
||||
int given;
|
||||
};
|
||||
|
|
|
@ -67,13 +67,13 @@ namespace libtorrent
|
|||
int give(resource_request& r, int num_resources)
|
||||
{
|
||||
assert(num_resources >= 0);
|
||||
assert(r.given <= r.wanted);
|
||||
assert(r.given <= r.max);
|
||||
|
||||
int accepted = std::min(num_resources, r.wanted - r.given);
|
||||
int accepted = std::min(num_resources, r.max - r.given);
|
||||
assert(accepted >= 0);
|
||||
|
||||
r.given += accepted;
|
||||
assert(r.given <= r.wanted);
|
||||
assert(r.given <= r.max);
|
||||
|
||||
return accepted;
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ namespace libtorrent
|
|||
for (It i = m_start, end(m_end); i != end; ++i)
|
||||
{
|
||||
assert(((*i).*m_res).used >= 0);
|
||||
assert(((*i).*m_res).wanted >= 0);
|
||||
assert(((*i).*m_res).max >= 0);
|
||||
assert(((*i).*m_res).given >= 0);
|
||||
}
|
||||
}
|
||||
|
@ -111,17 +111,17 @@ namespace libtorrent
|
|||
~allocate_resources_contract_check()
|
||||
{
|
||||
int sum_given = 0;
|
||||
int sum_wanted = 0;
|
||||
int sum_max = 0;
|
||||
for (It i = m_start, end(m_end); i != end; ++i)
|
||||
{
|
||||
assert(((*i).*m_res).wanted >= 0);
|
||||
assert(((*i).*m_res).max >= 0);
|
||||
assert(((*i).*m_res).given >= 0);
|
||||
assert(((*i).*m_res).given <= ((*i).*m_res).wanted);
|
||||
assert(((*i).*m_res).given <= ((*i).*m_res).max);
|
||||
|
||||
sum_given = saturated_add(sum_given, ((*i).*m_res).given);
|
||||
sum_wanted = saturated_add(sum_wanted, ((*i).*m_res).wanted);
|
||||
sum_max = saturated_add(sum_max, ((*i).*m_res).max);
|
||||
}
|
||||
assert(sum_given == std::min(m_resources, sum_wanted));
|
||||
assert(sum_given == std::min(m_resources, sum_max));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -148,25 +148,30 @@ namespace libtorrent
|
|||
// Just give everyone what they want.
|
||||
for (It i = start; i != end; ++i)
|
||||
{
|
||||
((*i).*res).given = ((*i).*res).wanted;
|
||||
((*i).*res).given = ((*i).*res).max;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Resources are scarce
|
||||
|
||||
int total_wanted = 0;
|
||||
int sum_max = 0;
|
||||
int sum_min = 0;
|
||||
for (It i = start; i != end; ++i)
|
||||
{
|
||||
((*i).*res).given = 0;
|
||||
total_wanted = saturated_add(total_wanted, ((*i).*res).wanted);
|
||||
sum_max = saturated_add(sum_max, ((*i).*res).max);
|
||||
assert(((*i).*res).min < std::numeric_limits<int>::max());
|
||||
assert(((*i).*res).min >= 0);
|
||||
assert(((*i).*res).min <= ((*i).*res).max);
|
||||
sum_min += ((*i).*res).min;
|
||||
((*i).*res).given = ((*i).*res).min;
|
||||
}
|
||||
|
||||
if (resources == 0 || total_wanted == 0)
|
||||
if (resources == 0 || sum_max == 0)
|
||||
return;
|
||||
|
||||
int resources_to_distribute = std::min(resources, total_wanted);
|
||||
assert(resources_to_distribute > 0);
|
||||
int resources_to_distribute = std::min(resources, sum_max) - sum_min;
|
||||
assert(resources_to_distribute >= 0);
|
||||
|
||||
while (resources_to_distribute > 0)
|
||||
{
|
||||
|
@ -175,9 +180,9 @@ namespace libtorrent
|
|||
for (It i = start; i != end; ++i)
|
||||
{
|
||||
resource_request& r = (*i).*res;
|
||||
if(r.given == r.wanted) continue;
|
||||
if(r.given == r.max) continue;
|
||||
|
||||
assert(r.given < r.wanted);
|
||||
assert(r.given < r.max);
|
||||
|
||||
max_used = std::max(max_used, (size_type)r.used + 1);
|
||||
total_used += (size_type)r.used + 1;
|
||||
|
@ -195,9 +200,9 @@ namespace libtorrent
|
|||
for (It i = start; i != end && resources_to_distribute > 0; ++i)
|
||||
{
|
||||
resource_request& r = (*i).*res;
|
||||
if(r.given == r.wanted) continue;
|
||||
if(r.given == r.max) continue;
|
||||
|
||||
assert(r.given < r.wanted);
|
||||
assert(r.given < r.max);
|
||||
|
||||
size_type used = (size_type)r.used + 1;
|
||||
size_type toGive = used * kNumer / kDenom;
|
||||
|
|
|
@ -30,6 +30,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include "libtorrent/entry.hpp"
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
|
|
|
@ -152,10 +152,11 @@ namespace libtorrent
|
|||
m_send_buffer += event_string[req.event - 1];
|
||||
}
|
||||
m_send_buffer += "&key=";
|
||||
// TODO: this should be encoded as hex
|
||||
m_send_buffer += boost::lexical_cast<std::string>((unsigned int)req.key);
|
||||
std::stringstream key_string;
|
||||
key_string << std::hex << req.key;
|
||||
m_send_buffer += key_string.str();
|
||||
m_send_buffer += "&compact=1";
|
||||
m_send_buffer += "&num_want=";
|
||||
m_send_buffer += "&numwant=";
|
||||
m_send_buffer += boost::lexical_cast<std::string>(req.num_want);
|
||||
|
||||
// extension that tells the tracker that
|
||||
|
|
|
@ -107,10 +107,12 @@ namespace libtorrent
|
|||
, m_disconnecting(false)
|
||||
, m_became_uninterested(boost::posix_time::second_clock::local_time())
|
||||
, m_became_uninteresting(boost::posix_time::second_clock::local_time())
|
||||
// , m_upload_bandwidth_quota_used(0)
|
||||
{
|
||||
INVARIANT_CHECK;
|
||||
|
||||
m_upload_bandwidth_quota.min = 10;
|
||||
m_upload_bandwidth_quota.max = 10;
|
||||
|
||||
assert(!m_socket->is_blocking());
|
||||
assert(m_torrent != 0);
|
||||
|
||||
|
@ -174,6 +176,14 @@ namespace libtorrent
|
|||
{
|
||||
INVARIANT_CHECK;
|
||||
|
||||
// upload bandwidth will only be given to connections
|
||||
// that are part of a torrent. Since this is an incoming
|
||||
// connection, we have to give it some initial bandwidth
|
||||
// to send the handshake
|
||||
m_upload_bandwidth_quota.min = 10;
|
||||
m_upload_bandwidth_quota.max = 400;
|
||||
m_upload_bandwidth_quota.given = 400;
|
||||
|
||||
assert(!m_socket->is_blocking());
|
||||
|
||||
std::fill(m_peer_id.begin(), m_peer_id.end(), 0);
|
||||
|
@ -1319,9 +1329,9 @@ namespace libtorrent
|
|||
// than we have uploaded OR if we are a seed
|
||||
// have an unlimited upload rate
|
||||
if(!m_send_buffer.empty() || (!m_requests.empty() && !is_choked()))
|
||||
m_upload_bandwidth_quota.wanted = std::numeric_limits<int>::max();
|
||||
m_upload_bandwidth_quota.max = std::numeric_limits<int>::max();
|
||||
else
|
||||
m_upload_bandwidth_quota.wanted = 1;
|
||||
m_upload_bandwidth_quota.max = m_upload_bandwidth_quota.min;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1336,17 +1346,17 @@ namespace libtorrent
|
|||
size_type soon_downloaded =
|
||||
have_downloaded + (size_type)(download_speed * break_even_time*1.5);
|
||||
|
||||
if(m_torrent->ratio() != 1.0f)
|
||||
if(m_torrent->ratio() != 1.f)
|
||||
soon_downloaded = (size_type)(soon_downloaded*(double)m_torrent->ratio());
|
||||
|
||||
double upload_speed_limit = (soon_downloaded - have_uploaded
|
||||
+ bias) / break_even_time;
|
||||
|
||||
upload_speed_limit=std::max(upload_speed_limit,1.0);
|
||||
upload_speed_limit=std::min(upload_speed_limit,
|
||||
(double)std::numeric_limits<int>::max());
|
||||
upload_speed_limit = std::min(upload_speed_limit,
|
||||
(double)std::numeric_limits<int>::max());
|
||||
|
||||
m_upload_bandwidth_quota.wanted = (int) upload_speed_limit;
|
||||
m_upload_bandwidth_quota.max
|
||||
= std::max((int)upload_speed_limit, m_upload_bandwidth_quota.min);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1924,7 +1934,7 @@ namespace libtorrent
|
|||
return;
|
||||
}
|
||||
|
||||
assert(send_quota_left()>0);
|
||||
assert(send_quota_left() > 0);
|
||||
assert(has_data());
|
||||
if (!m_added_to_selector)
|
||||
{
|
||||
|
|
|
@ -197,6 +197,7 @@ namespace libtorrent
|
|||
m_currently_trying_tracker = 0;
|
||||
|
||||
m_duration = interval;
|
||||
m_next_request = boost::posix_time::second_clock::local_time() + boost::posix_time::seconds(m_duration);
|
||||
|
||||
// connect to random peers from the list
|
||||
std::random_shuffle(peer_list.begin(), peer_list.end());
|
||||
|
@ -412,7 +413,9 @@ namespace libtorrent
|
|||
tracker_request torrent::generate_tracker_request()
|
||||
{
|
||||
m_duration = 1800;
|
||||
m_next_request = boost::posix_time::second_clock::local_time() + boost::posix_time::seconds(m_duration);
|
||||
m_next_request
|
||||
= boost::posix_time::second_clock::local_time()
|
||||
+ boost::posix_time::seconds(tracker_retry_delay);
|
||||
|
||||
tracker_request req;
|
||||
req.info_hash = m_torrent_file.info_hash();
|
||||
|
@ -637,7 +640,8 @@ namespace libtorrent
|
|||
}
|
||||
|
||||
m_upload_bandwidth_quota.used = 0;
|
||||
m_upload_bandwidth_quota.wanted = 0;
|
||||
m_upload_bandwidth_quota.max = 0;
|
||||
m_upload_bandwidth_quota.min = 0;
|
||||
|
||||
for (peer_iterator i = m_connections.begin();
|
||||
i != m_connections.end();
|
||||
|
@ -647,13 +651,14 @@ namespace libtorrent
|
|||
m_stat += p->statistics();
|
||||
p->second_tick();
|
||||
m_upload_bandwidth_quota.used += p->m_upload_bandwidth_quota.used;
|
||||
m_upload_bandwidth_quota.wanted = saturated_add(
|
||||
m_upload_bandwidth_quota.wanted
|
||||
, p->m_upload_bandwidth_quota.wanted);
|
||||
m_upload_bandwidth_quota.min += p->m_upload_bandwidth_quota.min;
|
||||
m_upload_bandwidth_quota.max = saturated_add(
|
||||
m_upload_bandwidth_quota.max
|
||||
, p->m_upload_bandwidth_quota.max);
|
||||
}
|
||||
|
||||
m_upload_bandwidth_quota.wanted
|
||||
= std::min(m_upload_bandwidth_quota.wanted, m_upload_bandwidth_limit);
|
||||
m_upload_bandwidth_quota.max
|
||||
= std::min(m_upload_bandwidth_quota.max, m_upload_bandwidth_limit);
|
||||
|
||||
m_stat.second_tick();
|
||||
}
|
||||
|
|
|
@ -451,10 +451,10 @@ namespace libtorrent
|
|||
else
|
||||
p.upload_limit = peer->upload_bandwidth_quota()->given;
|
||||
|
||||
if (peer->upload_bandwidth_quota()->wanted == std::numeric_limits<int>::max())
|
||||
if (peer->upload_bandwidth_quota()->max == std::numeric_limits<int>::max())
|
||||
p.upload_ceiling = -1;
|
||||
else
|
||||
p.upload_ceiling = peer->upload_bandwidth_quota()->wanted;
|
||||
p.upload_ceiling = peer->upload_bandwidth_quota()->max;
|
||||
|
||||
p.load_balancing = peer->total_free_upload();
|
||||
|
||||
|
|
|
@ -138,7 +138,7 @@ namespace libtorrent
|
|||
for (entry::list_type::const_iterator k = ll.begin(); k != ll.end(); ++k)
|
||||
{
|
||||
announce_entry e;
|
||||
e.tier = (int)(j - l.begin());
|
||||
e.tier = (int)std::distance(l.begin(), j);
|
||||
e.url = k->string();
|
||||
m_urls.push_back(e);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue