*** empty log message ***

This commit is contained in:
Arvid Norberg 2004-03-27 22:02:31 +00:00
parent 3689e48a3b
commit a9b3c6dd41
9 changed files with 79 additions and 48 deletions

View File

@ -61,7 +61,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <iostream> #include <iostream>
#include <map> #include <map>
#include <vector> #include <list>
#include <string> #include <string>
#include <stdexcept> #include <stdexcept>
#include <cassert> #include <cassert>
@ -111,9 +111,9 @@ namespace libtorrent
// of elements. Since the info-hash is reconstructed // of elements. Since the info-hash is reconstructed
// from an entry, it's important that the order is // from an entry, it's important that the order is
// preserved. // 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::string string_type;
typedef std::vector<entry> list_type; typedef std::list<entry> list_type;
typedef size_type integer_type; typedef size_type integer_type;
enum data_type enum data_type

View File

@ -37,12 +37,21 @@ namespace libtorrent
{ {
struct resource_request 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: // I'm right now actively using:
int used; 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): // Reply: Okay, you're allowed to use this much (a compromise):
int given; int given;
}; };

View File

@ -67,13 +67,13 @@ namespace libtorrent
int give(resource_request& r, int num_resources) int give(resource_request& r, int num_resources)
{ {
assert(num_resources >= 0); 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); assert(accepted >= 0);
r.given += accepted; r.given += accepted;
assert(r.given <= r.wanted); assert(r.given <= r.max);
return accepted; return accepted;
} }
@ -103,7 +103,7 @@ namespace libtorrent
for (It i = m_start, end(m_end); i != end; ++i) for (It i = m_start, end(m_end); i != end; ++i)
{ {
assert(((*i).*m_res).used >= 0); assert(((*i).*m_res).used >= 0);
assert(((*i).*m_res).wanted >= 0); assert(((*i).*m_res).max >= 0);
assert(((*i).*m_res).given >= 0); assert(((*i).*m_res).given >= 0);
} }
} }
@ -111,17 +111,17 @@ namespace libtorrent
~allocate_resources_contract_check() ~allocate_resources_contract_check()
{ {
int sum_given = 0; int sum_given = 0;
int sum_wanted = 0; int sum_max = 0;
for (It i = m_start, end(m_end); i != end; ++i) 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 >= 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_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. // Just give everyone what they want.
for (It i = start; i != end; ++i) for (It i = start; i != end; ++i)
{ {
((*i).*res).given = ((*i).*res).wanted; ((*i).*res).given = ((*i).*res).max;
} }
return; return;
} }
// Resources are scarce // Resources are scarce
int total_wanted = 0; int sum_max = 0;
int sum_min = 0;
for (It i = start; i != end; ++i) for (It i = start; i != end; ++i)
{ {
((*i).*res).given = 0; sum_max = saturated_add(sum_max, ((*i).*res).max);
total_wanted = saturated_add(total_wanted, ((*i).*res).wanted); 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; return;
int resources_to_distribute = std::min(resources, total_wanted); int resources_to_distribute = std::min(resources, sum_max) - sum_min;
assert(resources_to_distribute > 0); assert(resources_to_distribute >= 0);
while (resources_to_distribute > 0) while (resources_to_distribute > 0)
{ {
@ -175,9 +180,9 @@ namespace libtorrent
for (It i = start; i != end; ++i) for (It i = start; i != end; ++i)
{ {
resource_request& r = (*i).*res; 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); max_used = std::max(max_used, (size_type)r.used + 1);
total_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) for (It i = start; i != end && resources_to_distribute > 0; ++i)
{ {
resource_request& r = (*i).*res; 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 used = (size_type)r.used + 1;
size_type toGive = used * kNumer / kDenom; size_type toGive = used * kNumer / kDenom;

View File

@ -30,6 +30,7 @@ POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <algorithm>
#include "libtorrent/entry.hpp" #include "libtorrent/entry.hpp"
#include <boost/bind.hpp> #include <boost/bind.hpp>

View File

@ -152,10 +152,11 @@ namespace libtorrent
m_send_buffer += event_string[req.event - 1]; m_send_buffer += event_string[req.event - 1];
} }
m_send_buffer += "&key="; m_send_buffer += "&key=";
// TODO: this should be encoded as hex std::stringstream key_string;
m_send_buffer += boost::lexical_cast<std::string>((unsigned int)req.key); key_string << std::hex << req.key;
m_send_buffer += key_string.str();
m_send_buffer += "&compact=1"; 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); m_send_buffer += boost::lexical_cast<std::string>(req.num_want);
// extension that tells the tracker that // extension that tells the tracker that

View File

@ -107,10 +107,12 @@ namespace libtorrent
, m_disconnecting(false) , m_disconnecting(false)
, m_became_uninterested(boost::posix_time::second_clock::local_time()) , m_became_uninterested(boost::posix_time::second_clock::local_time())
, m_became_uninteresting(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; INVARIANT_CHECK;
m_upload_bandwidth_quota.min = 10;
m_upload_bandwidth_quota.max = 10;
assert(!m_socket->is_blocking()); assert(!m_socket->is_blocking());
assert(m_torrent != 0); assert(m_torrent != 0);
@ -174,6 +176,14 @@ namespace libtorrent
{ {
INVARIANT_CHECK; 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()); assert(!m_socket->is_blocking());
std::fill(m_peer_id.begin(), m_peer_id.end(), 0); 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 // than we have uploaded OR if we are a seed
// have an unlimited upload rate // have an unlimited upload rate
if(!m_send_buffer.empty() || (!m_requests.empty() && !is_choked())) 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 else
m_upload_bandwidth_quota.wanted = 1; m_upload_bandwidth_quota.max = m_upload_bandwidth_quota.min;
} }
else else
{ {
@ -1336,17 +1346,17 @@ namespace libtorrent
size_type soon_downloaded = size_type soon_downloaded =
have_downloaded + (size_type)(download_speed * break_even_time*1.5); 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()); soon_downloaded = (size_type)(soon_downloaded*(double)m_torrent->ratio());
double upload_speed_limit = (soon_downloaded - have_uploaded double upload_speed_limit = (soon_downloaded - have_uploaded
+ bias) / break_even_time; + bias) / break_even_time;
upload_speed_limit=std::max(upload_speed_limit,1.0); upload_speed_limit = std::min(upload_speed_limit,
upload_speed_limit=std::min(upload_speed_limit, (double)std::numeric_limits<int>::max());
(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; return;
} }
assert(send_quota_left()>0); assert(send_quota_left() > 0);
assert(has_data()); assert(has_data());
if (!m_added_to_selector) if (!m_added_to_selector)
{ {

View File

@ -197,6 +197,7 @@ namespace libtorrent
m_currently_trying_tracker = 0; m_currently_trying_tracker = 0;
m_duration = interval; 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 // connect to random peers from the list
std::random_shuffle(peer_list.begin(), peer_list.end()); std::random_shuffle(peer_list.begin(), peer_list.end());
@ -412,7 +413,9 @@ namespace libtorrent
tracker_request torrent::generate_tracker_request() tracker_request torrent::generate_tracker_request()
{ {
m_duration = 1800; 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; tracker_request req;
req.info_hash = m_torrent_file.info_hash(); req.info_hash = m_torrent_file.info_hash();
@ -637,7 +640,8 @@ namespace libtorrent
} }
m_upload_bandwidth_quota.used = 0; 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(); for (peer_iterator i = m_connections.begin();
i != m_connections.end(); i != m_connections.end();
@ -647,13 +651,14 @@ namespace libtorrent
m_stat += p->statistics(); m_stat += p->statistics();
p->second_tick(); p->second_tick();
m_upload_bandwidth_quota.used += p->m_upload_bandwidth_quota.used; m_upload_bandwidth_quota.used += p->m_upload_bandwidth_quota.used;
m_upload_bandwidth_quota.wanted = saturated_add( m_upload_bandwidth_quota.min += p->m_upload_bandwidth_quota.min;
m_upload_bandwidth_quota.wanted m_upload_bandwidth_quota.max = saturated_add(
, p->m_upload_bandwidth_quota.wanted); m_upload_bandwidth_quota.max
, p->m_upload_bandwidth_quota.max);
} }
m_upload_bandwidth_quota.wanted m_upload_bandwidth_quota.max
= std::min(m_upload_bandwidth_quota.wanted, m_upload_bandwidth_limit); = std::min(m_upload_bandwidth_quota.max, m_upload_bandwidth_limit);
m_stat.second_tick(); m_stat.second_tick();
} }

View File

@ -451,10 +451,10 @@ namespace libtorrent
else else
p.upload_limit = peer->upload_bandwidth_quota()->given; 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; p.upload_ceiling = -1;
else else
p.upload_ceiling = peer->upload_bandwidth_quota()->wanted; p.upload_ceiling = peer->upload_bandwidth_quota()->max;
p.load_balancing = peer->total_free_upload(); p.load_balancing = peer->total_free_upload();

View File

@ -138,7 +138,7 @@ namespace libtorrent
for (entry::list_type::const_iterator k = ll.begin(); k != ll.end(); ++k) for (entry::list_type::const_iterator k = ll.begin(); k != ll.end(); ++k)
{ {
announce_entry e; announce_entry e;
e.tier = (int)(j - l.begin()); e.tier = (int)std::distance(l.begin(), j);
e.url = k->string(); e.url = k->string();
m_urls.push_back(e); m_urls.push_back(e);
} }