*** empty log message ***
This commit is contained in:
parent
c0f8ea13e4
commit
1bd0a8234a
@ -292,7 +292,7 @@ public:
|
|||||||
dictionary_type& dict();
|
dictionary_type& dict();
|
||||||
const dictionary_type& dict() const;
|
const dictionary_type& dict() const;
|
||||||
|
|
||||||
void print(std::ostream& os, int indent) const;
|
void print(std::ostream& os, int indent = 0) const;
|
||||||
};
|
};
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
|
@ -60,7 +60,14 @@ int main(int argc, char* argv[])
|
|||||||
entry e = bdecode(std::istream_iterator<char>(in), std::istream_iterator<char>());
|
entry e = bdecode(std::istream_iterator<char>(in), std::istream_iterator<char>());
|
||||||
torrent_info t(e);
|
torrent_info t(e);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
std::cout << "\n\n----- raw info -----\n\n";
|
||||||
|
e.print(std::cout);
|
||||||
|
|
||||||
|
|
||||||
// print info about torrent
|
// print info about torrent
|
||||||
|
std::cout << "\n\n----- torrent file info -----\n\n";
|
||||||
std::cout << "trackers:\n";
|
std::cout << "trackers:\n";
|
||||||
for (std::vector<announce_entry>::const_iterator i = t.trackers().begin();
|
for (std::vector<announce_entry>::const_iterator i = t.trackers().begin();
|
||||||
i != t.trackers().end();
|
i != t.trackers().end();
|
||||||
@ -76,7 +83,8 @@ int main(int argc, char* argv[])
|
|||||||
i != t.end_files();
|
i != t.end_files();
|
||||||
++i)
|
++i)
|
||||||
{
|
{
|
||||||
std::cout << " " << std::setw(11) << i->size << " " << i->path << " " << i->filename << "\n";
|
std::cout << " " << std::setw(11) << i->size
|
||||||
|
<< " " << i->path << " " << i->filename << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -188,7 +188,7 @@ namespace libtorrent
|
|||||||
return *reinterpret_cast<const dictionary_type*>(data);
|
return *reinterpret_cast<const dictionary_type*>(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print(std::ostream& os, int indent) const;
|
void print(std::ostream& os, int indent = 0) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ namespace libtorrent
|
|||||||
#if defined(TORRENT_VERBOSE_LOGGING)
|
#if defined(TORRENT_VERBOSE_LOGGING)
|
||||||
boost::shared_ptr<logger> create_log(std::string name)
|
boost::shared_ptr<logger> create_log(std::string name)
|
||||||
{
|
{
|
||||||
name += ".log";
|
name = "libtorrent_log_" + name + ".log";
|
||||||
// current options are file_logger and cout_logger
|
// current options are file_logger and cout_logger
|
||||||
return boost::shared_ptr<logger>(new file_logger(name.c_str()));
|
return boost::shared_ptr<logger>(new file_logger(name.c_str()));
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ namespace libtorrent
|
|||||||
enum open_mode { in, out };
|
enum open_mode { in, out };
|
||||||
|
|
||||||
// opens a piece with the given index from storage s
|
// opens a piece with the given index from storage s
|
||||||
void open(storage* s, int index, open_mode m);
|
void open(storage* s, int index, open_mode m, int seek_offset = 0);
|
||||||
void close()
|
void close()
|
||||||
{
|
{
|
||||||
//std::cout << std::clock() << "close " << m_piece_index << "\n";
|
//std::cout << std::clock() << "close " << m_piece_index << "\n";
|
||||||
|
@ -109,6 +109,7 @@ namespace libtorrent
|
|||||||
entry::integer_type piece_length() const { return m_piece_length; }
|
entry::integer_type piece_length() const { return m_piece_length; }
|
||||||
std::size_t num_pieces() const { return m_piece_hash.size(); }
|
std::size_t num_pieces() const { return m_piece_hash.size(); }
|
||||||
const sha1_hash& info_hash() const { return m_info_hash; }
|
const sha1_hash& info_hash() const { return m_info_hash; }
|
||||||
|
const std::string& name() const { return m_name; }
|
||||||
void print(std::ostream& os) const;
|
void print(std::ostream& os) const;
|
||||||
|
|
||||||
entry::integer_type piece_size(unsigned int index) const
|
entry::integer_type piece_size(unsigned int index) const
|
||||||
@ -149,6 +150,8 @@ namespace libtorrent
|
|||||||
|
|
||||||
// the hash that identifies this torrent
|
// the hash that identifies this torrent
|
||||||
sha1_hash m_info_hash;
|
sha1_hash m_info_hash;
|
||||||
|
|
||||||
|
std::string m_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -369,16 +369,12 @@ bool libtorrent::peer_connection::dispatch_message()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (m_receiving_piece.index() < 0 || m_receiving_piece.index() != index)
|
m_receiving_piece.open(m_torrent->filesystem(), index, piece_file::out, offset);
|
||||||
// {
|
|
||||||
m_receiving_piece.open(m_torrent->filesystem(), index, piece_file::out);
|
|
||||||
// }
|
|
||||||
|
|
||||||
#if defined(TORRENT_VERBOSE_LOGGING)
|
#if defined(TORRENT_VERBOSE_LOGGING)
|
||||||
(*m_logger) << m_socket->sender().as_string() << " <== PIECE [ piece: " << index << " | s: " << offset << " | l: " << len << " ]\n";
|
(*m_logger) << m_socket->sender().as_string() << " <== PIECE [ piece: " << index << " | s: " << offset << " | l: " << len << " ]\n";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_receiving_piece.seek_forward(offset);
|
|
||||||
m_receiving_piece.write(&m_recv_buffer[9], len);
|
m_receiving_piece.write(&m_recv_buffer[9], len);
|
||||||
m_torrent->downloaded_bytes(len);
|
m_torrent->downloaded_bytes(len);
|
||||||
|
|
||||||
|
@ -564,8 +564,12 @@ namespace libtorrent
|
|||||||
const unsigned char* c = p.begin();
|
const unsigned char* c = p.begin();
|
||||||
while (c != p.end() && *c != 0)
|
while (c != p.end() && *c != 0)
|
||||||
{
|
{
|
||||||
if (!std::isprint(*c)) return std::string();
|
if (std::isprint(*c))
|
||||||
ret += *c;
|
ret += *c;
|
||||||
|
else if (*c <= 9)
|
||||||
|
ret += '0'+ *c;
|
||||||
|
else
|
||||||
|
return std::string();
|
||||||
++c;
|
++c;
|
||||||
}
|
}
|
||||||
if (c == p.end()) return std::string();
|
if (c == p.end()) return std::string();
|
||||||
|
@ -30,6 +30,11 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// TODO: Use two algorithms to estimate transfer rate.
|
||||||
|
// one (simple) for transfer rates that are >= 1 packet
|
||||||
|
// per second and one (low pass-filter) for rates < 1
|
||||||
|
// packet per second.
|
||||||
|
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
|
|
||||||
#include "libtorrent/stat.hpp"
|
#include "libtorrent/stat.hpp"
|
||||||
|
@ -57,7 +57,7 @@ using namespace libtorrent;
|
|||||||
// accepted as an argument, this way we may avoid opening a
|
// accepted as an argument, this way we may avoid opening a
|
||||||
// file in vain if we're about to seek forward anyway
|
// file in vain if we're about to seek forward anyway
|
||||||
|
|
||||||
void libtorrent::piece_file::open(storage* s, int index, open_mode o)
|
void libtorrent::piece_file::open(storage* s, int index, open_mode o, int seek_offset)
|
||||||
{
|
{
|
||||||
open_mode old_mode = m_mode;
|
open_mode old_mode = m_mode;
|
||||||
storage* old_storage = m_storage;
|
storage* old_storage = m_storage;
|
||||||
@ -71,11 +71,14 @@ void libtorrent::piece_file::open(storage* s, int index, open_mode o)
|
|||||||
|
|
||||||
assert(index < m_storage->m_torrent_file->num_pieces() && "internal error");
|
assert(index < m_storage->m_torrent_file->num_pieces() && "internal error");
|
||||||
|
|
||||||
m_piece_offset = 0;
|
m_piece_offset = seek_offset;
|
||||||
int piece_byte_offset = index * m_storage->m_torrent_file->piece_length();
|
int piece_byte_offset = index * m_storage->m_torrent_file->piece_length()
|
||||||
|
+ m_piece_offset;
|
||||||
|
|
||||||
entry::integer_type file_byte_offset = 0;
|
entry::integer_type file_byte_offset = 0;
|
||||||
for (m_file_iter = m_storage->m_torrent_file->begin_files(); m_file_iter != m_storage->m_torrent_file->end_files(); ++m_file_iter)
|
for (m_file_iter = m_storage->m_torrent_file->begin_files();
|
||||||
|
m_file_iter != m_storage->m_torrent_file->end_files();
|
||||||
|
++m_file_iter)
|
||||||
{
|
{
|
||||||
if (file_byte_offset + m_file_iter->size > piece_byte_offset) break;
|
if (file_byte_offset + m_file_iter->size > piece_byte_offset) break;
|
||||||
file_byte_offset += m_file_iter->size;
|
file_byte_offset += m_file_iter->size;
|
||||||
@ -86,6 +89,7 @@ void libtorrent::piece_file::open(storage* s, int index, open_mode o)
|
|||||||
if ((m_mode == out && !(m_file_mode & std::ios_base::out))
|
if ((m_mode == out && !(m_file_mode & std::ios_base::out))
|
||||||
|| old_file_iter != m_file_iter
|
|| old_file_iter != m_file_iter
|
||||||
|| !m_file.is_open()
|
|| !m_file.is_open()
|
||||||
|
|| m_file.fail()
|
||||||
|| old_storage != m_storage)
|
|| old_storage != m_storage)
|
||||||
{
|
{
|
||||||
std::ios_base::openmode m;
|
std::ios_base::openmode m;
|
||||||
@ -108,15 +112,18 @@ void libtorrent::piece_file::open(storage* s, int index, open_mode o)
|
|||||||
assert(!m_file.fail());
|
assert(!m_file.fail());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
assert(!m_file.fail());
|
||||||
|
|
||||||
m_file_offset = piece_byte_offset - file_byte_offset;
|
m_file_offset = piece_byte_offset - file_byte_offset;
|
||||||
if (m_mode == in) m_file.seekg(m_file_offset, std::ios_base::beg);
|
if (m_mode == in) m_file.seekg(m_file_offset, std::ios_base::beg);
|
||||||
else m_file.seekp(m_file_offset, std::ios_base::beg);
|
else m_file.seekp(m_file_offset, std::ios_base::beg);
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
int gpos = m_file.tellg();
|
int gpos = m_file.tellg();
|
||||||
int ppos = m_file.tellp();
|
int ppos = m_file.tellp();
|
||||||
assert(m_mode == out || m_file_offset == gpos && "internal error");
|
assert(m_mode == out || m_file_offset == gpos && "internal error");
|
||||||
assert(m_mode == in || m_file_offset == ppos && "internal error");
|
assert(m_mode == in || m_file_offset == ppos && "internal error");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int libtorrent::piece_file::read(char* buf, int size)
|
int libtorrent::piece_file::read(char* buf, int size)
|
||||||
@ -125,6 +132,8 @@ int libtorrent::piece_file::read(char* buf, int size)
|
|||||||
// std::cout << std::clock() << "read " << m_piece_index << "\n";
|
// std::cout << std::clock() << "read " << m_piece_index << "\n";
|
||||||
|
|
||||||
assert(m_mode == in);
|
assert(m_mode == in);
|
||||||
|
assert(!m_file.fail());
|
||||||
|
assert(m_file.is_open());
|
||||||
int left_to_read = size;
|
int left_to_read = size;
|
||||||
|
|
||||||
// make sure we don't read more than what belongs to this piece
|
// make sure we don't read more than what belongs to this piece
|
||||||
@ -172,7 +181,10 @@ int libtorrent::piece_file::read(char* buf, int size)
|
|||||||
}
|
}
|
||||||
} while (left_to_read > 0);
|
} while (left_to_read > 0);
|
||||||
|
|
||||||
assert(m_file_offset == (long)m_file.tellg() && "internal error");
|
#ifndef NDEBUG
|
||||||
|
int gpos = m_file.tellg();
|
||||||
|
assert(m_file_offset == gpos && "internal error");
|
||||||
|
#endif
|
||||||
return read_total;
|
return read_total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ namespace libtorrent
|
|||||||
// extract file name (or the directory name if it's a multifile libtorrent)
|
// extract file name (or the directory name if it's a multifile libtorrent)
|
||||||
i = info.dict().find("name");
|
i = info.dict().find("name");
|
||||||
if (i == info.dict().end()) throw invalid_torrent_file();
|
if (i == info.dict().end()) throw invalid_torrent_file();
|
||||||
std::string filename = i->second.string();
|
m_name = i->second.string();
|
||||||
|
|
||||||
// extract file list
|
// extract file list
|
||||||
i = info.dict().find("files");
|
i = info.dict().find("files");
|
||||||
@ -161,12 +161,12 @@ namespace libtorrent
|
|||||||
if (i == info.dict().end()) throw invalid_torrent_file();
|
if (i == info.dict().end()) throw invalid_torrent_file();
|
||||||
|
|
||||||
m_files.push_back(file());
|
m_files.push_back(file());
|
||||||
m_files.back().filename = filename;
|
m_files.back().filename = m_name;
|
||||||
m_files.back().size = i->second.integer();
|
m_files.back().size = i->second.integer();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
extract_files(i->second.list(), m_files, filename);
|
extract_files(i->second.list(), m_files, m_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculate total size of all pieces
|
// calculate total size of all pieces
|
||||||
|
Loading…
x
Reference in New Issue
Block a user