*** empty log message ***
This commit is contained in:
parent
7de3079ef0
commit
3b551ac272
|
@ -68,9 +68,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
// only should be given to those we are not interested
|
// only should be given to those we are not interested
|
||||||
// in?
|
// in?
|
||||||
|
|
||||||
// TODO: the interested flag has to be updated when we
|
|
||||||
// get pieces.
|
|
||||||
|
|
||||||
namespace libtorrent
|
namespace libtorrent
|
||||||
{
|
{
|
||||||
class torrent;
|
class torrent;
|
||||||
|
|
|
@ -60,7 +60,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "libtorrent/debug.hpp"
|
#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
|
namespace libtorrent
|
||||||
{
|
{
|
||||||
|
|
|
@ -377,6 +377,7 @@ bool libtorrent::peer_connection::dispatch_message(int received)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_have_piece[index] = true;
|
m_have_piece[index] = true;
|
||||||
|
// TODO: maybe this if-statement should be moved into the policy
|
||||||
if (!m_torrent->peer_has(index) && !is_interesting())
|
if (!m_torrent->peer_has(index) && !is_interesting())
|
||||||
m_torrent->get_policy().peer_is_interesting(*this);
|
m_torrent->get_policy().peer_is_interesting(*this);
|
||||||
}
|
}
|
||||||
|
@ -397,15 +398,17 @@ bool libtorrent::peer_connection::dispatch_message(int received)
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
(*m_logger) << m_socket->sender().as_string() << " <== BITFIELD\n";
|
(*m_logger) << m_socket->sender().as_string() << " <== BITFIELD\n";
|
||||||
#endif
|
#endif
|
||||||
bool interesting = false;
|
|
||||||
bool is_seed = true;
|
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)
|
for (std::size_t i = 0; i < m_have_piece.size(); ++i)
|
||||||
{
|
{
|
||||||
bool have = m_recv_buffer[1 + (i>>3)] & (1 << (7 - (i&7)));
|
bool have = m_recv_buffer[1 + (i>>3)] & (1 << (7 - (i&7)));
|
||||||
if (have && !m_have_piece[i])
|
if (have && !m_have_piece[i])
|
||||||
{
|
{
|
||||||
m_have_piece[i] = true;
|
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])
|
else if (!have && m_have_piece[i])
|
||||||
{
|
{
|
||||||
|
@ -414,6 +417,22 @@ bool libtorrent::peer_connection::dispatch_message(int received)
|
||||||
}
|
}
|
||||||
if (!have) is_seed = false;
|
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)
|
if (is_seed)
|
||||||
{
|
{
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
|
|
@ -33,6 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <numeric>
|
||||||
|
|
||||||
#include "libtorrent/piece_picker.hpp"
|
#include "libtorrent/piece_picker.hpp"
|
||||||
|
|
||||||
|
@ -73,13 +74,30 @@ namespace libtorrent
|
||||||
|
|
||||||
void piece_picker::files_checked(const std::vector<bool>& pieces)
|
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();
|
for (std::vector<bool>::const_iterator i = pieces.begin();
|
||||||
i != pieces.end();
|
i != pieces.end();
|
||||||
++i)
|
++i)
|
||||||
{
|
{
|
||||||
if (*i) continue;
|
if (*i) continue;
|
||||||
int index = i - pieces.begin();
|
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(index < m_piece_map.size());
|
||||||
assert(m_piece_map[index].index == 0xffffff);
|
assert(m_piece_map[index].index == 0xffffff);
|
||||||
|
|
||||||
|
@ -93,7 +111,6 @@ namespace libtorrent
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
// integrity_check();
|
// integrity_check();
|
||||||
#endif
|
#endif
|
||||||
// TODO: random_shuffle
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
@ -309,18 +326,6 @@ namespace libtorrent
|
||||||
#endif
|
#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)
|
bool piece_picker::inc_refcount(int i)
|
||||||
{
|
{
|
||||||
assert(i >= 0);
|
assert(i >= 0);
|
||||||
|
|
Loading…
Reference in New Issue