*** empty log message ***

This commit is contained in:
Arvid Norberg 2003-12-18 03:30:41 +00:00
parent ac0921599d
commit cb89ccf6be
6 changed files with 35 additions and 21 deletions

View File

@ -110,9 +110,10 @@ namespace libtorrent
// increases the peer count for the given piece
// (is used when a HAVE or BITFIELD message is received)
// returns true if this piece was interesting
bool inc_refcount(int index);
void inc_refcount(int index);
// decreases the peer count for the given piece
// (used when a peer disconnects)
void dec_refcount(int index);
// This indicates that we just received this piece

View File

@ -197,17 +197,12 @@ namespace libtorrent
// when we get a have- or bitfield- messages, this is called for every
// piece a peer has gained.
// returns true if this piece is interesting (i.e. if we would like to download it)
bool peer_has(int index)
{
return m_picker.inc_refcount(index);
}
void peer_has(int index)
{ m_picker.inc_refcount(index); }
// when peer disconnects, this is called for every piece it had
void peer_lost(int index)
{
m_picker.dec_refcount(index);
}
{ m_picker.dec_refcount(index); }
int block_size() const { return m_block_size; }

View File

@ -380,8 +380,10 @@ 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->peer_has(index);
if (!m_torrent->have_piece(index) && !is_interesting())
m_torrent->get_policy().peer_is_interesting(*this);
}
break;
@ -401,8 +403,6 @@ bool libtorrent::peer_connection::dispatch_message(int received)
#ifndef NDEBUG
(*m_logger) << m_socket->sender().as_string() << " <== BITFIELD\n";
#endif
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)
@ -418,7 +418,6 @@ bool libtorrent::peer_connection::dispatch_message(int received)
m_have_piece[i] = false;
m_torrent->peer_lost(i);
}
if (!have) is_seed = false;
}
// shuffle the piece list
@ -432,11 +431,12 @@ bool libtorrent::peer_connection::dispatch_message(int received)
++i)
{
int index = *i;
if (m_torrent->peer_has(index))
m_torrent->peer_has(index);
if (!m_torrent->have_piece(index))
interesting = true;
}
if (is_seed)
if (piece_list.empty())
{
#ifndef NDEBUG
(*m_logger) << m_socket->sender().as_string() << " *** THIS IS A SEED ***\n";

View File

@ -326,7 +326,7 @@ namespace libtorrent
#endif
}
bool piece_picker::inc_refcount(int i)
void piece_picker::inc_refcount(int i)
{
assert(i >= 0);
assert(i < m_piece_map.size());
@ -336,14 +336,16 @@ namespace libtorrent
m_piece_map[i].peer_count++;
if (index == 0xffffff) return false;
// if we have the piece, we don't have to move
// any entries in the piece_info vector
if (index == 0xffffff) return;
move(m_piece_map[i].downloading, peer_count, index);
#ifndef NDEBUG
// integrity_check();
#endif
return true;
return;
}
void piece_picker::dec_refcount(int i)

View File

@ -568,6 +568,8 @@ namespace libtorrent
// called when a peer is no longer interested in us
void policy::not_interested(peer_connection& c)
{
// TODO: return the diff() of this peer to the
// pool of undistributed free upload
}
bool policy::unchoke_one_peer()

View File

@ -411,9 +411,23 @@ namespace libtorrent
m_picker.abort_download(*i);
}
for (std::size_t i = 0; i < torrent_file().num_pieces(); ++i)
std::vector<int> piece_list;
const std::vector<bool>& pieces = p->get_bitfield();
for (std::vector<bool>::const_iterator i = pieces.begin();
i != pieces.end();
++i)
{
if (p->has_piece(i)) peer_lost(i);
if (*i) piece_list.push_back(i - pieces.begin());
}
std::random_shuffle(piece_list.begin(), piece_list.end());
for (std::vector<int>::iterator i = piece_list.begin();
i != piece_list.end();
++i)
{
peer_lost(*i);
}
// std::cout << p->get_socket()->sender().as_string() << " *** DISCONNECT\n";