*** empty log message ***

This commit is contained in:
Arvid Norberg
2004-02-01 17:42:20 +00:00
parent 1a198769cf
commit 268d96020e
3 changed files with 69 additions and 78 deletions

View File

@@ -252,9 +252,6 @@ namespace libtorrent
bool support_extensions() const bool support_extensions() const
{ return m_supports_extensions; } { return m_supports_extensions; }
const boost::posix_time::time_duration& last_piece_time() const
{ return m_last_piece_time; }
// a connection is local if it was initiated by us. // a connection is local if it was initiated by us.
// if it was an incoming connection, it is remote // if it was an incoming connection, it is remote
bool is_local() const bool is_local() const
@@ -523,10 +520,6 @@ namespace libtorrent
// message from this peer // message from this peer
boost::posix_time::ptime m_last_piece; boost::posix_time::ptime m_last_piece;
// the time it took for the peer to send the piece
// message
boost::posix_time::time_duration m_last_piece_time;
// this is true if this connection has been added // this is true if this connection has been added
// to the list of connections that will be closed. // to the list of connections that will be closed.
bool m_disconnecting; bool m_disconnecting;

View File

@@ -106,7 +106,6 @@ namespace libtorrent
, m_trust_points(0) , m_trust_points(0)
, m_num_invalid_requests(0) , m_num_invalid_requests(0)
, m_last_piece(boost::posix_time::second_clock::local_time()) , m_last_piece(boost::posix_time::second_clock::local_time())
, m_last_piece_time(boost::posix_time::seconds(0))
, 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())
@@ -171,7 +170,6 @@ namespace libtorrent
, m_trust_points(0) , m_trust_points(0)
, m_num_invalid_requests(0) , m_num_invalid_requests(0)
, m_last_piece(boost::posix_time::second_clock::local_time()) , m_last_piece(boost::posix_time::second_clock::local_time())
, m_last_piece_time(boost::posix_time::seconds(0))
, 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())
@@ -647,9 +645,6 @@ namespace libtorrent
if (m_recv_pos < m_packet_size) return; if (m_recv_pos < m_packet_size) return;
m_last_piece_time = m_last_piece
- boost::posix_time::second_clock::local_time();
const char* ptr = &m_recv_buffer[1]; const char* ptr = &m_recv_buffer[1];
peer_request p; peer_request p;
p.piece = detail::read_int32(ptr); p.piece = detail::read_int32(ptr);

View File

@@ -63,7 +63,7 @@ namespace
{ {
// the limits of the download queue size // the limits of the download queue size
max_request_queue = 16, max_request_queue = 16,
min_request_queue = 4, min_request_queue = 2,
// the amount of free upload allowed before // the amount of free upload allowed before
// the peer is choked // the peer is choked
@@ -157,78 +157,81 @@ namespace
// (then we can cancel those and request them // (then we can cancel those and request them
// from this peer instead) // from this peer instead)
peer_connection* peer = 0; while (num_requests > 0)
float min_weight = std::numeric_limits<float>::max();
// find the peer with the lowest download
// speed that also has a piece that this
// peer could send us
for (torrent::peer_iterator i = t.begin();
i != t.end();
++i)
{ {
// don't try to take over blocks from ourself peer_connection* peer = 0;
if (i->second == &c) float min_weight = std::numeric_limits<float>::max();
continue; // find the peer with the lowest download
// speed that also has a piece that this
// peer could send us
for (torrent::peer_iterator i = t.begin();
i != t.end();
++i)
{
// don't try to take over blocks from ourself
if (i->second == &c)
continue;
// ignore all peers in the ignore list // ignore all peers in the ignore list
if (std::find(ignore.begin(), ignore.end(), i->second) != ignore.end()) if (std::find(ignore.begin(), ignore.end(), i->second) != ignore.end())
continue; continue;
const std::deque<piece_block>& queue = i->second->download_queue(); const std::deque<piece_block>& queue = i->second->download_queue();
const int queue_size = (int)i->second->download_queue().size(); const int queue_size = (int)i->second->download_queue().size();
const float weight = queue_size == 0
? std::numeric_limits<float>::max()
: i->second->statistics().down_peak() / queue_size;
if (weight < min_weight
&& std::find_first_of(
busy_pieces.begin()
, busy_pieces.end()
, queue.begin()
, queue.end()) != busy_pieces.end())
{
peer = i->second;
min_weight = weight;
}
}
if (peer == 0)
{
// we probably couldn't request the block because
// we are ignoring some peers
return;
}
// this peer doesn't have a faster connection than the
// slowest peer. Don't take over any blocks
const int queue_size = (int)c.download_queue().size();
const float weight = queue_size == 0 const float weight = queue_size == 0
? std::numeric_limits<float>::max() ? std::numeric_limits<float>::max()
: i->second->statistics().down_peak() / queue_size; : c.statistics().down_peak() / queue_size;
if (weight < min_weight if (weight <= min_weight) return;
&& std::find_first_of(
busy_pieces.begin() // find a suitable block to take over from this peer
, busy_pieces.end()
, queue.begin() std::deque<piece_block>::const_reverse_iterator common_block =
, queue.end()) != busy_pieces.end()) std::find_first_of(
{ peer->download_queue().rbegin()
peer = i->second; , peer->download_queue().rend()
min_weight = weight; , busy_pieces.begin()
} , busy_pieces.end());
assert(common_block != peer->download_queue().rend());
piece_block block = *common_block;
peer->send_cancel(block);
c.send_request(block);
// the one we interrupted may need to request a new piece
// make sure it doesn't take over a block from the peer
// that just took over its block
ignore.push_back(&c);
request_a_block(t, *peer, ignore);
num_requests--;
} }
if (peer == 0)
{
// we probably couldn't request the block because
// we are ignoring some peers
return;
}
// this peer doesn't have a faster connection than the
// slowest peer. Don't take over any blocks
const int queue_size = (int)c.download_queue().size();
const float weight = queue_size == 0
? std::numeric_limits<float>::max()
: c.statistics().down_peak() / queue_size;
if (weight <= min_weight) return;
// find a suitable block to take over from this peer
std::deque<piece_block>::const_reverse_iterator common_block =
std::find_first_of(
peer->download_queue().rbegin()
, peer->download_queue().rend()
, busy_pieces.begin()
, busy_pieces.end());
assert(common_block != peer->download_queue().rend());
piece_block block = *common_block;
peer->send_cancel(block);
c.send_request(block);
// the one we interrupted may need to request a new piece
// make sure it doesn't take over a block from the peer
// that just took over its block
ignore.push_back(&c);
request_a_block(t, *peer, ignore);
num_requests--;
} }