*** empty log message ***

This commit is contained in:
Arvid Norberg 2003-11-08 02:16:26 +00:00
parent eb90660022
commit 01d9d10157
8 changed files with 48 additions and 41 deletions

View File

@ -156,6 +156,7 @@ class session: public boost::noncopyable
session(int listen_port, const std::string& fingerprint = std::string()); session(int listen_port, const std::string& fingerprint = std::string());
torrent_handle add_torrent(const torrent_info& t, const std::string& save_path); torrent_handle add_torrent(const torrent_info& t, const std::string& save_path);
void remove_torrent(const torrent_handle& h);
void set_http_settings(const http_settings& settings); void set_http_settings(const http_settings& settings);
}; };
@ -170,6 +171,11 @@ want to save the files. The <tt>save_path</tt> will be prepended to the director
structure in the torrent-file. structure in the torrent-file.
</p> </p>
<p>
<tt>remove_torrent()</tt> will close all peer connections associated with the torrent and tell
the tracker that we've stopped participating in the swarm.
</p>
<p> <p>
If the torrent you are trying to add already exists in the session (is either queued If the torrent you are trying to add already exists in the session (is either queued
for checking, being checked or downloading) <tt>add_torrent()</tt> will throw for checking, being checked or downloading) <tt>add_torrent()</tt> will throw
@ -476,7 +482,6 @@ Its declaration looks like this:
struct torrent_handle struct torrent_handle
{ {
torrent_handle(); torrent_handle();
void abort();
torrent_status status() const; torrent_status status() const;
void get_download_queue(std::vector&lt;partial_piece_info&gt;&amp; queue); void get_download_queue(std::vector&lt;partial_piece_info&gt;&amp; queue);
@ -490,13 +495,6 @@ perform any operation on it, unless you first assign it a valid handle. If you t
any operation they will simply return. any operation they will simply return.
</p> </p>
<p>
<tt>abort()</tt> will close all peer connections associated with this torrent and tell
the tracker that we've stopped participating in the swarm. This handle will become invalid
shortly after this call has been made.
</p>
<h3>status()</h3> <h3>status()</h3>
<p> <p>

View File

@ -40,7 +40,6 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent namespace libtorrent
{ {
#if defined(TORRENT_VERBOSE_LOGGING)
// DEBUG API // DEBUG API
struct logger struct logger
@ -94,7 +93,6 @@ namespace libtorrent
std::ofstream m_file; std::ofstream m_file;
}; };
#endif
} }

View File

@ -158,7 +158,7 @@ namespace libtorrent
const peer_id& get_peer_id() const { return m_peer_id; } const peer_id& get_peer_id() const { return m_peer_id; }
const std::vector<bool>& get_bitfield() const { return m_have_piece; } const std::vector<bool>& get_bitfield() const { return m_have_piece; }
#if defined(TORRENT_VERBOSE_LOGGING) #ifndef NDEBUG
boost::shared_ptr<logger> m_logger; boost::shared_ptr<logger> m_logger;
#endif #endif
@ -228,7 +228,7 @@ namespace libtorrent
// something that generates data to be // something that generates data to be
// sent to this peer, we check this and // sent to this peer, we check this and
// if it's not added to the selector we // if it's not added to the selector we
// add it. // add it. (this is done in send_buffer_updated())
bool m_added_to_selector; bool m_added_to_selector;
// remote peer's id // remote peer's id

View File

@ -175,7 +175,7 @@ namespace libtorrent
volatile bool m_abort; volatile bool m_abort;
#if defined(TORRENT_VERBOSE_LOGGING) #ifndef NDEBUG
boost::shared_ptr<logger> create_log(std::string name) boost::shared_ptr<logger> create_log(std::string name)
{ {
name = "libtorrent_log_" + name + ".log"; name = "libtorrent_log_" + name + ".log";
@ -205,6 +205,7 @@ namespace libtorrent
torrent_handle add_torrent( torrent_handle add_torrent(
const torrent_info& ti const torrent_info& ti
, const boost::filesystem::path& save_path); , const boost::filesystem::path& save_path);
void remove_torrent(const torrent_handle& h);
void set_http_settings(const http_settings& s); void set_http_settings(const http_settings& s);

View File

@ -89,16 +89,18 @@ namespace libtorrent
friend class session; friend class session;
torrent_handle(): m_ses(0) {} torrent_handle(): m_ses(0) {}
void abort();
void get_peer_info(std::vector<peer_info>& v); void get_peer_info(std::vector<peer_info>& v);
torrent_status status() const; torrent_status status() const;
void get_download_queue(std::vector<partial_piece_info>& queue) const; void get_download_queue(std::vector<partial_piece_info>& queue) const;
// TODO: add force reannounce // TODO: add force reannounce
// TODO: add torrent_info getter
private: private:
// called by session::remove_torrent()
void abort() const;
torrent_handle(detail::session_impl* s, torrent_handle(detail::session_impl* s,
detail::checker_impl* c, detail::checker_impl* c,
const sha1_hash& h) const sha1_hash& h)

View File

@ -318,7 +318,10 @@ bool libtorrent::peer_connection::dispatch_message()
r.length = read_int(&m_recv_buffer[9]); r.length = read_int(&m_recv_buffer[9]);
m_requests.push_back(r); m_requests.push_back(r);
send_buffer_updated(); if (!m_choked)
{
send_buffer_updated();
}
#if defined(TORRENT_VERBOSE_LOGGING) #if defined(TORRENT_VERBOSE_LOGGING)
(*m_logger) << m_socket->sender().as_string() << " <== REQUEST [ piece: " << r.piece << " | s: " << r.start << " | l: " << r.length << " ]\n"; (*m_logger) << m_socket->sender().as_string() << " <== REQUEST [ piece: " << r.piece << " | s: " << r.start << " | l: " << r.length << " ]\n";
@ -912,34 +915,29 @@ void libtorrent::peer_connection::send_data()
if (m_sending_piece.index() != r.piece) if (m_sending_piece.index() != r.piece)
{ {
m_sending_piece.open(m_torrent->filesystem(), r.piece, piece_file::in); m_sending_piece.open(
m_torrent->filesystem()
, r.piece
, piece_file::in
, r.start);
#ifndef NDEBUG #ifndef NDEBUG
assert(m_torrent->filesystem()->verify_piece(m_sending_piece) && "internal error"); assert(m_torrent->filesystem()->verify_piece(m_sending_piece) && "internal error");
m_sending_piece.open(m_torrent->filesystem(), r.piece, piece_file::in); m_sending_piece.open(m_torrent->filesystem(), r.piece, piece_file::in);
#endif #endif
} }
const int send_buffer_offset = m_send_buffer.size();
const int packet_size = 4 + 5 + 4 + r.length; const int packet_size = 4 + 5 + 4 + r.length;
m_send_buffer.resize(packet_size); m_send_buffer.resize(send_buffer_offset + packet_size);
write_int(packet_size-4, &m_send_buffer[0]); write_int(packet_size-4, &m_send_buffer[send_buffer_offset]);
m_send_buffer[4] = msg_piece; m_send_buffer[send_buffer_offset+4] = msg_piece;
write_int(r.piece, &m_send_buffer[5]); write_int(r.piece, &m_send_buffer[send_buffer_offset+5]);
write_int(r.start, &m_send_buffer[9]); write_int(r.start, &m_send_buffer[send_buffer_offset+9]);
if (r.start > m_sending_piece.tell()) assert(r.start == m_sending_piece.tell());
{
m_sending_piece.seek_forward(r.start - m_sending_piece.tell());
}
else if (r.start < m_sending_piece.tell())
{
int index = m_sending_piece.index();
m_sending_piece.close();
m_sending_piece.open(m_torrent->filesystem(), index, piece_file::in);
m_sending_piece.seek_forward(r.start);
}
m_sending_piece.read(&m_send_buffer[13], r.length); m_sending_piece.read(&m_send_buffer[send_buffer_offset+13], r.length);
#if defined(TORRENT_VERBOSE_LOGGING) #if defined(TORRENT_VERBOSE_LOGGING)
(*m_logger) << m_socket->sender().as_string() << " ==> PIECE [ idx: " << r.piece << " | s: " << r.start << " | l: " << r.length << " ]\n"; (*m_logger) << m_socket->sender().as_string() << " ==> PIECE [ piece: " << r.piece << " | s: " << r.start << " | l: " << r.length << " ]\n";
#endif #endif
// let the torrent keep track of how much we have uploaded // let the torrent keep track of how much we have uploaded
m_torrent->uploaded_bytes(r.length); m_torrent->uploaded_bytes(r.length);
@ -947,7 +945,14 @@ void libtorrent::peer_connection::send_data()
else else
{ {
#if defined(TORRENT_VERBOSE_LOGGING) #if defined(TORRENT_VERBOSE_LOGGING)
(*m_logger) << m_socket->sender().as_string() << " *** WARNING [ illegal piece request idx: " << r.piece << " | s: " << r.start << " | l: " << r.length << " ]\n"; (*m_logger) << m_socket->sender().as_string()
<< " *** WARNING [ illegal piece request idx: " << r.piece
<< " | s: " << r.start
<< " | l: " << r.length
<< " | max_piece: " << m_have_piece.size()
<< " | torrent: " << (m_torrent != 0)
<< " | have: " << m_torrent->have_piece(r.piece)
<< " ]\n";
#endif #endif
} }
m_requests.erase(m_requests.begin()); m_requests.erase(m_requests.begin());

View File

@ -590,6 +590,13 @@ namespace libtorrent
return torrent_handle(&m_impl, &m_checker_impl, ti.info_hash()); return torrent_handle(&m_impl, &m_checker_impl, ti.info_hash());
} }
void session::remove_torrent(const torrent_handle& h)
{
if (h.m_ses != &m_impl) return;
// TODO: move the code of abort() here instead of calling it
h.abort();
}
void session::set_http_settings(const http_settings& s) void session::set_http_settings(const http_settings& s)
{ {
boost::mutex::scoped_lock l(m_impl.m_mutex); boost::mutex::scoped_lock l(m_impl.m_mutex);

View File

@ -184,7 +184,7 @@ namespace libtorrent
} }
} }
void torrent_handle::abort() void torrent_handle::abort() const
{ {
if (m_ses == 0) return; if (m_ses == 0) return;
assert(m_chk != 0); assert(m_chk != 0);
@ -195,7 +195,6 @@ namespace libtorrent
if (t != 0) if (t != 0)
{ {
t->abort(); t->abort();
m_ses = 0;
return; return;
} }
} }
@ -207,12 +206,9 @@ namespace libtorrent
if (d != 0) if (d != 0)
{ {
d->abort = true; d->abort = true;
m_ses = 0;
return; return;
} }
} }
m_ses = 0;
} }
} }