*** empty log message ***
This commit is contained in:
@@ -252,7 +252,7 @@ int main(int argc, char* argv[])
|
|||||||
boost::posix_time::time_duration t = s.next_announce;
|
boost::posix_time::time_duration t = s.next_announce;
|
||||||
// std::cout << "next announce: " << boost::posix_time::to_simple_string(t) << "\n";
|
// std::cout << "next announce: " << boost::posix_time::to_simple_string(t) << "\n";
|
||||||
std::cout << "next announce: " << t.hours() << ":" << t.minutes() << ":" << t.seconds() << "\n";
|
std::cout << "next announce: " << t.hours() << ":" << t.minutes() << ":" << t.seconds() << "\n";
|
||||||
|
/*
|
||||||
for (std::vector<peer_info>::iterator i = peers.begin();
|
for (std::vector<peer_info>::iterator i = peers.begin();
|
||||||
i != peers.end();
|
i != peers.end();
|
||||||
++i)
|
++i)
|
||||||
@@ -267,8 +267,8 @@ int main(int argc, char* argv[])
|
|||||||
<< static_cast<const char*>((i->flags & peer_info::remote_choked)?"c":"_") << "\n";
|
<< static_cast<const char*>((i->flags & peer_info::remote_choked)?"c":"_") << "\n";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
i->get_download_queue(queue);
|
i->get_download_queue(queue);
|
||||||
for (std::vector<partial_piece_info>::iterator i = queue.begin();
|
for (std::vector<partial_piece_info>::iterator i = queue.begin();
|
||||||
i != queue.end();
|
i != queue.end();
|
||||||
@@ -283,7 +283,7 @@ int main(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
std::cout << "\n";
|
std::cout << "\n";
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
std::cout << "___________________________________\n";
|
std::cout << "___________________________________\n";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -258,6 +258,7 @@ namespace libtorrent
|
|||||||
int slot_for_piece(int piece_index);
|
int slot_for_piece(int piece_index);
|
||||||
|
|
||||||
void check_invariant() const;
|
void check_invariant() const;
|
||||||
|
void debug_log() const;
|
||||||
|
|
||||||
storage m_storage;
|
storage m_storage;
|
||||||
|
|
||||||
|
@@ -1282,6 +1282,16 @@ void libtorrent::storage::write(const char* buf, int slot, size_type offset, siz
|
|||||||
|
|
||||||
namespace fs = boost::filesystem;
|
namespace fs = boost::filesystem;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
void print_to_log(const std::string& s)
|
||||||
|
{
|
||||||
|
static std::ofstream log("log.txt");
|
||||||
|
log << s;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
namespace libtorrent {
|
namespace libtorrent {
|
||||||
|
|
||||||
storage::storage(const torrent_info& info, const fs::path& path)
|
storage::storage(const torrent_info& info, const fs::path& path)
|
||||||
@@ -1297,6 +1307,8 @@ namespace libtorrent {
|
|||||||
, size_type offset
|
, size_type offset
|
||||||
, size_type size)
|
, size_type size)
|
||||||
{
|
{
|
||||||
|
assert(size > 0);
|
||||||
|
|
||||||
size_type start = slot * m_info.piece_length() + offset;
|
size_type start = slot * m_info.piece_length() + offset;
|
||||||
|
|
||||||
// find the file iterator and file offset
|
// find the file iterator and file offset
|
||||||
@@ -1319,7 +1331,9 @@ namespace libtorrent {
|
|||||||
|
|
||||||
assert(file_offset < file_iter->size);
|
assert(file_offset < file_iter->size);
|
||||||
|
|
||||||
in.seekg(std::ios_base::beg, file_offset);
|
in.seekg(file_offset);
|
||||||
|
|
||||||
|
assert(size_type(in.tellg()) == file_offset);
|
||||||
|
|
||||||
size_type left_to_read = size;
|
size_type left_to_read = size;
|
||||||
size_type slot_size = m_info.piece_size(slot);
|
size_type slot_size = m_info.piece_size(slot);
|
||||||
@@ -1366,6 +1380,8 @@ namespace libtorrent {
|
|||||||
|
|
||||||
void storage::write(const char* buf, int slot, size_type offset, size_type size)
|
void storage::write(const char* buf, int slot, size_type offset, size_type size)
|
||||||
{
|
{
|
||||||
|
assert(size > 0);
|
||||||
|
|
||||||
size_type start = slot * m_info.piece_length() + offset;
|
size_type start = slot * m_info.piece_length() + offset;
|
||||||
|
|
||||||
// find the file iterator and file offset
|
// find the file iterator and file offset
|
||||||
@@ -1381,14 +1397,19 @@ namespace libtorrent {
|
|||||||
++file_iter;
|
++file_iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
fs::ofstream out(
|
fs::path path(m_save_path / file_iter->path / file_iter->filename);
|
||||||
m_save_path / file_iter->path / file_iter->filename
|
fs::ofstream out;
|
||||||
, std::ios_base::in | std::ios_base::binary
|
|
||||||
);
|
if (fs::exists(path))
|
||||||
|
out.open(path, std::ios_base::binary | std::ios_base::in);
|
||||||
|
else
|
||||||
|
out.open(path, std::ios_base::binary);
|
||||||
|
|
||||||
assert(file_offset < file_iter->size);
|
assert(file_offset < file_iter->size);
|
||||||
|
|
||||||
out.seekp(std::ios_base::beg, file_offset);
|
out.seekp(file_offset);
|
||||||
|
|
||||||
|
assert(file_offset == out.tellp());
|
||||||
|
|
||||||
size_type left_to_write = size;
|
size_type left_to_write = size;
|
||||||
size_type slot_size = m_info.piece_size(slot);
|
size_type slot_size = m_info.piece_size(slot);
|
||||||
@@ -1432,7 +1453,11 @@ namespace libtorrent {
|
|||||||
file_offset = 0;
|
file_offset = 0;
|
||||||
out.close();
|
out.close();
|
||||||
out.clear();
|
out.clear();
|
||||||
out.open(path, std::ios_base::in | std::ios_base::binary);
|
|
||||||
|
if (fs::exists(path))
|
||||||
|
out.open(path, std::ios_base::binary | std::ios_base::in);
|
||||||
|
else
|
||||||
|
out.open(path, std::ios_base::binary);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1517,7 +1542,7 @@ namespace libtorrent {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(current_piece < m_info.num_pieces());
|
assert(current_piece <= m_info.num_pieces());
|
||||||
|
|
||||||
fs::path path(m_save_path / file_iter->path);
|
fs::path path(m_save_path / file_iter->path);
|
||||||
|
|
||||||
@@ -1728,11 +1753,28 @@ namespace libtorrent {
|
|||||||
|
|
||||||
// there is another piece already assigned to
|
// there is another piece already assigned to
|
||||||
// the slot we are interested in, swap positions
|
// the slot we are interested in, swap positions
|
||||||
if (m_slot_to_piece[piece_index] >= 0)
|
if (slot_index != piece_index
|
||||||
|
&& m_slot_to_piece[piece_index] >= 0)
|
||||||
{
|
{
|
||||||
|
std::stringstream s;
|
||||||
|
|
||||||
|
s << "there is another piece at our slot, swapping..";
|
||||||
|
|
||||||
|
s << "\n piece_index: ";
|
||||||
|
s << piece_index;
|
||||||
|
s << "\n slot_index: ";
|
||||||
|
s << slot_index;
|
||||||
|
s << "\n piece at our slot: ";
|
||||||
|
s << m_slot_to_piece[piece_index];
|
||||||
|
s << "\n";
|
||||||
|
|
||||||
|
print_to_log(s.str());
|
||||||
|
|
||||||
|
debug_log();
|
||||||
|
|
||||||
std::vector<char> buf(m_info.piece_length());
|
std::vector<char> buf(m_info.piece_length());
|
||||||
m_storage.read(&buf[0], piece_index, m_info.piece_length(), 0);
|
m_storage.read(&buf[0], piece_index, 0, m_info.piece_length());
|
||||||
m_storage.write(&buf[0], slot_index, m_info.piece_length(), 0);
|
m_storage.write(&buf[0], slot_index, 0, m_info.piece_length());
|
||||||
|
|
||||||
std::swap(
|
std::swap(
|
||||||
m_slot_to_piece[piece_index]
|
m_slot_to_piece[piece_index]
|
||||||
@@ -1743,8 +1785,12 @@ namespace libtorrent {
|
|||||||
, m_piece_to_slot[slot_index]);
|
, m_piece_to_slot[slot_index]);
|
||||||
|
|
||||||
slot_index = piece_index;
|
slot_index = piece_index;
|
||||||
|
|
||||||
|
debug_log();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check_invariant();
|
||||||
|
|
||||||
return slot_index;
|
return slot_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1848,6 +1894,8 @@ namespace libtorrent {
|
|||||||
if (last_piece_index != -1)
|
if (last_piece_index != -1)
|
||||||
std::swap(m_free_pieces[last_piece_index], m_free_pieces.front());
|
std::swap(m_free_pieces[last_piece_index], m_free_pieces.front());
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
check_invariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
void piece_manager::check_invariant() const
|
void piece_manager::check_invariant() const
|
||||||
@@ -1858,11 +1906,27 @@ namespace libtorrent {
|
|||||||
|
|
||||||
for (int i = 0; i < m_info.num_pieces(); ++i)
|
for (int i = 0; i < m_info.num_pieces(); ++i)
|
||||||
{
|
{
|
||||||
if (m_piece_to_slot[i] != i)
|
if (m_piece_to_slot[i] != i && m_piece_to_slot[i] >= 0)
|
||||||
assert(m_slot_to_piece[i] < 0);
|
assert(m_slot_to_piece[i] == -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void piece_manager::debug_log() const
|
||||||
|
{
|
||||||
|
std::stringstream s;
|
||||||
|
|
||||||
|
s << "index\tslot\tpiece\n";
|
||||||
|
|
||||||
|
for (int i = 0; i < m_info.num_pieces(); ++i)
|
||||||
|
{
|
||||||
|
s << i << "\t" << m_slot_to_piece[i] << "\t";
|
||||||
|
s << m_piece_to_slot[i] << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
s << "---------------------------------\n";
|
||||||
|
|
||||||
|
print_to_log(s.str());
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace libtorrent
|
} // namespace libtorrent
|
||||||
|
|
||||||
|
@@ -544,7 +544,7 @@ namespace libtorrent
|
|||||||
{
|
{
|
||||||
size_type size = m_torrent_file.piece_size(piece_index);
|
size_type size = m_torrent_file.piece_size(piece_index);
|
||||||
std::vector<char> buffer(size);
|
std::vector<char> buffer(size);
|
||||||
m_storage.read(&buffer[0], piece_index, size, 0);
|
m_storage.read(&buffer[0], piece_index, 0, size);
|
||||||
|
|
||||||
hasher h;
|
hasher h;
|
||||||
h.update(&buffer[0], size);
|
h.update(&buffer[0], size);
|
||||||
|
Reference in New Issue
Block a user