*** empty log message ***

This commit is contained in:
Arvid Norberg 2003-12-17 19:03:23 +00:00
parent 7de3079ef0
commit 3b551ac272
4 changed files with 40 additions and 19 deletions

View File

@ -68,9 +68,6 @@ POSSIBILITY OF SUCH DAMAGE.
// only should be given to those we are not interested
// in?
// TODO: the interested flag has to be updated when we
// get pieces.
namespace libtorrent
{
class torrent;

View File

@ -60,7 +60,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/debug.hpp"
// TODO: if we're not interested and the peer isn't interested, close the connections
// TODO: if we're a seed and the peer is a seed, close the connections
namespace libtorrent
{

View File

@ -377,6 +377,7 @@ bool libtorrent::peer_connection::dispatch_message(int received)
else
{
m_have_piece[index] = true;
// TODO: maybe this if-statement should be moved into the policy
if (!m_torrent->peer_has(index) && !is_interesting())
m_torrent->get_policy().peer_is_interesting(*this);
}
@ -397,15 +398,17 @@ bool libtorrent::peer_connection::dispatch_message(int received)
#ifndef NDEBUG
(*m_logger) << m_socket->sender().as_string() << " <== BITFIELD\n";
#endif
bool interesting = false;
bool is_seed = true;
// build a vector of all pieces
std::vector<int> piece_list;
for (std::size_t i = 0; i < m_have_piece.size(); ++i)
{
bool have = m_recv_buffer[1 + (i>>3)] & (1 << (7 - (i&7)));
if (have && !m_have_piece[i])
{
m_have_piece[i] = true;
if (m_torrent->peer_has(i)) interesting = true;
piece_list.push_back(i);
}
else if (!have && m_have_piece[i])
{
@ -414,6 +417,22 @@ bool libtorrent::peer_connection::dispatch_message(int received)
}
if (!have) is_seed = false;
}
// shuffle the piece list
std::random_shuffle(piece_list.begin(), piece_list.end());
// let the torrent know which pieces the
// peer has, in a shuffled order
bool interesting = false;
for (std::vector<int>::iterator i = piece_list.begin();
i != piece_list.end();
++i)
{
int index = *i;
if (m_torrent->peer_has(index))
interesting = true;
}
if (is_seed)
{
#ifndef NDEBUG

View File

@ -33,6 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include "libtorrent/piece_picker.hpp"
@ -73,13 +74,30 @@ namespace libtorrent
void piece_picker::files_checked(const std::vector<bool>& pieces)
{
// build a vector of all the pieces we don't have
std::vector<int> piece_list;
piece_list.reserve(
pieces.size()
- std::accumulate(pieces.begin(), pieces.end(), 0));
for (std::vector<bool>::const_iterator i = pieces.begin();
i != pieces.end();
++i)
{
if (*i) continue;
int index = i - pieces.begin();
piece_list.push_back(index);
}
// random shuffle the list
std::random_shuffle(piece_list.begin(), piece_list.end());
// add the pieces to the piece_picker
for (std::vector<int>::iterator i = piece_list.begin();
i != piece_list.end();
++i)
{
int index = *i;
assert(index < m_piece_map.size());
assert(m_piece_map[index].index == 0xffffff);
@ -93,7 +111,6 @@ namespace libtorrent
#ifndef NDEBUG
// integrity_check();
#endif
// TODO: random_shuffle
}
#ifndef NDEBUG
@ -309,18 +326,6 @@ namespace libtorrent
#endif
}
// TODO: since inc_refcount is called
// with sequential indices when peers
// connect, the pieces will be sorted.
// that is not good. one solution is
// to insert the element at a random
// index when moving it to another
// vector.
// one solution might be to create a
// vector of all piece indices that
// are to have their ref_count increased
// and then random_shuffle that vector
// before processing them.
bool piece_picker::inc_refcount(int i)
{
assert(i >= 0);