*** empty log message ***
This commit is contained in:
parent
95026395f3
commit
3033f16f47
|
@ -106,7 +106,9 @@ namespace libtorrent
|
||||||
// after the local files has been checked.
|
// after the local files has been checked.
|
||||||
// the vector tells which pieces we already have
|
// the vector tells which pieces we already have
|
||||||
// and which we don't have.
|
// and which we don't have.
|
||||||
void files_checked(const std::vector<bool>& pieces);
|
void files_checked(
|
||||||
|
const std::vector<bool>& pieces
|
||||||
|
, const std::vector<downloading_piece>& unfinished);
|
||||||
|
|
||||||
// increases the peer count for the given piece
|
// increases the peer count for the given piece
|
||||||
// (is used when a HAVE or BITFIELD message is received)
|
// (is used when a HAVE or BITFIELD message is received)
|
||||||
|
@ -172,6 +174,15 @@ namespace libtorrent
|
||||||
void integrity_check(const torrent* t = 0) const;
|
void integrity_check(const torrent* t = 0) const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// functor that compares indices on downloading_pieces
|
||||||
|
struct has_index
|
||||||
|
{
|
||||||
|
has_index(int i): index(i) {}
|
||||||
|
bool operator()(const downloading_piece& p) const
|
||||||
|
{ return p.index == index; }
|
||||||
|
int index;
|
||||||
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
struct piece_pos
|
struct piece_pos
|
||||||
|
@ -199,15 +210,6 @@ namespace libtorrent
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct has_index
|
|
||||||
{
|
|
||||||
has_index(int i): index(i) {}
|
|
||||||
bool operator()(const downloading_piece& p) const
|
|
||||||
{ return p.index == index; }
|
|
||||||
int index;
|
|
||||||
};
|
|
||||||
|
|
||||||
void move(bool downloading, int vec_index, int elem_index);
|
void move(bool downloading, int vec_index, int elem_index);
|
||||||
void remove(bool downloading, int vec_index, int elem_index);
|
void remove(bool downloading, int vec_index, int elem_index);
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,9 @@ namespace libtorrent
|
||||||
std::fill(m_piece_map.begin(), m_piece_map.end(), piece_pos(0, 0xffffff));
|
std::fill(m_piece_map.begin(), m_piece_map.end(), piece_pos(0, 0xffffff));
|
||||||
}
|
}
|
||||||
|
|
||||||
void piece_picker::files_checked(const std::vector<bool>& pieces)
|
void piece_picker::files_checked(
|
||||||
|
const std::vector<bool>& pieces
|
||||||
|
, const std::vector<downloading_piece>& unfinished)
|
||||||
{
|
{
|
||||||
// build a vector of all the pieces we don't have
|
// build a vector of all the pieces we don't have
|
||||||
std::vector<int> piece_list;
|
std::vector<int> piece_list;
|
||||||
|
@ -108,6 +110,25 @@ namespace libtorrent
|
||||||
m_piece_map[index].index = m_piece_info[peer_count].size();
|
m_piece_map[index].index = m_piece_info[peer_count].size();
|
||||||
m_piece_info[peer_count].push_back(index);
|
m_piece_info[peer_count].push_back(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if we have fast resume info
|
||||||
|
// use it
|
||||||
|
if (!unfinished.empty())
|
||||||
|
{
|
||||||
|
for (std::vector<downloading_piece>::const_iterator i
|
||||||
|
= unfinished.begin();
|
||||||
|
i != unfinished.end();
|
||||||
|
++i)
|
||||||
|
{
|
||||||
|
peer_id peer;
|
||||||
|
std::fill(peer.begin(), peer.end(), 0);
|
||||||
|
for (int j = 0; j < m_blocks_per_piece; ++j)
|
||||||
|
{
|
||||||
|
if (i->finished_blocks[j])
|
||||||
|
mark_as_finished(piece_block(i->index, j), peer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
// integrity_check();
|
// integrity_check();
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -916,7 +916,7 @@ namespace libtorrent
|
||||||
|
|
||||||
int num_unfinished = read_int(ptr);
|
int num_unfinished = read_int(ptr);
|
||||||
if (num_unfinished < 0) return;
|
if (num_unfinished < 0) return;
|
||||||
if (data.size() != (3 + num_slots + 1 + num_unfinished) * 4)
|
if (data.size() != (1 + num_slots + 2 + num_unfinished * (num_blocks_per_piece / 32 + 1)) * 4)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
tmp_unfinished.reserve(num_unfinished);
|
tmp_unfinished.reserve(num_unfinished);
|
||||||
|
@ -934,7 +934,12 @@ namespace libtorrent
|
||||||
for (int j = 0; j < num_blocks_per_piece / 32; ++j)
|
for (int j = 0; j < num_blocks_per_piece / 32; ++j)
|
||||||
{
|
{
|
||||||
unsigned int bits = read_int(ptr);
|
unsigned int bits = read_int(ptr);
|
||||||
for (int k = 0; k < 32; ++k) p.finished_blocks[j * 32 + k] = true;
|
for (int k = 0; k < 32; ++k)
|
||||||
|
{
|
||||||
|
const int bit = j * 32 + k;
|
||||||
|
if (bits & (1 << bit))
|
||||||
|
p.finished_blocks[bit] = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
tmp_unfinished.push_back(p);
|
tmp_unfinished.push_back(p);
|
||||||
}
|
}
|
||||||
|
|
|
@ -513,6 +513,50 @@ namespace libtorrent {
|
||||||
const std::size_t last_piece_size = m_info.piece_size(
|
const std::size_t last_piece_size = m_info.piece_size(
|
||||||
m_info.num_pieces() - 1);
|
m_info.num_pieces() - 1);
|
||||||
|
|
||||||
|
// if we have fast-resume info
|
||||||
|
// use it instead of doingthe actual checking
|
||||||
|
if (!data.piece_map.empty()
|
||||||
|
&& data.piece_map.size() <= m_slot_to_piece.size())
|
||||||
|
{
|
||||||
|
for (int i = 0; i < data.piece_map.size(); ++i)
|
||||||
|
{
|
||||||
|
m_slot_to_piece[i] = data.piece_map[i];
|
||||||
|
if (data.piece_map[i] >= 0)
|
||||||
|
{
|
||||||
|
m_piece_to_slot[data.piece_map[i]] = i;
|
||||||
|
int found_piece = data.piece_map[i];
|
||||||
|
|
||||||
|
// if the piece is not in the unfinished list
|
||||||
|
// we have all of it
|
||||||
|
if (std::find_if(
|
||||||
|
data.unfinished_pieces.begin()
|
||||||
|
, data.unfinished_pieces.end()
|
||||||
|
, piece_picker::has_index(found_piece))
|
||||||
|
== data.unfinished_pieces.end())
|
||||||
|
{
|
||||||
|
m_bytes_left -= m_info.piece_size(found_piece);
|
||||||
|
pieces[found_piece] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (data.piece_map[i] == -2)
|
||||||
|
{
|
||||||
|
m_free_slots.push_back(i);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
assert(data.piece_map[i] == -1);
|
||||||
|
m_unallocated_slots.push_back(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = data.piece_map.size(); i < pieces.size(); ++i)
|
||||||
|
{
|
||||||
|
m_unallocated_slots.push_back(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
bool changed_file = true;
|
bool changed_file = true;
|
||||||
fs::ifstream in;
|
fs::ifstream in;
|
||||||
|
|
||||||
|
@ -658,6 +702,9 @@ namespace libtorrent {
|
||||||
|
|
||||||
if (found_piece != -1)
|
if (found_piece != -1)
|
||||||
{
|
{
|
||||||
|
// if we have found this piece hash once already
|
||||||
|
// move it to the free pieces and don't decrease
|
||||||
|
// bytes_left
|
||||||
if (pieces[found_piece])
|
if (pieces[found_piece])
|
||||||
{
|
{
|
||||||
assert(m_piece_to_slot[found_piece] != -1);
|
assert(m_piece_to_slot[found_piece] != -1);
|
||||||
|
|
|
@ -571,7 +571,7 @@ namespace libtorrent
|
||||||
, m_have_pieces.end()
|
, m_have_pieces.end()
|
||||||
, 0);
|
, 0);
|
||||||
|
|
||||||
m_picker.files_checked(m_have_pieces);
|
m_picker.files_checked(m_have_pieces, data.unfinished_pieces);
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
m_picker.integrity_check(this);
|
m_picker.integrity_check(this);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -185,6 +185,7 @@ namespace libtorrent
|
||||||
std::back_insert_iterator<std::vector<char> > out(buf);
|
std::back_insert_iterator<std::vector<char> > out(buf);
|
||||||
|
|
||||||
// TODO: write file header
|
// TODO: write file header
|
||||||
|
// TODO: write modification-dates for all files
|
||||||
// TODO: write info hash
|
// TODO: write info hash
|
||||||
|
|
||||||
// number of slots
|
// number of slots
|
||||||
|
|
Loading…
Reference in New Issue