extensions are now instantiated for web seeds as well

This commit is contained in:
Arvid Norberg 2007-04-02 20:00:24 +00:00
parent 2fc73e9aeb
commit ec2962dd62
7 changed files with 93 additions and 72 deletions

View File

@ -88,6 +88,7 @@ namespace libtorrent
virtual ~peer_plugin() {} virtual ~peer_plugin() {}
// can add entries to the extension handshake // can add entries to the extension handshake
// this is not called for web seeds
virtual void add_handshake(entry&) {} virtual void add_handshake(entry&) {}
// throwing an exception from any of the handlers (except add_handshake) // throwing an exception from any of the handlers (except add_handshake)
@ -96,12 +97,14 @@ namespace libtorrent
// this is called when the initial BT handshake is received. Returning false // this is called when the initial BT handshake is received. Returning false
// means that the other end doesn't support this extension and will remove // means that the other end doesn't support this extension and will remove
// it from the list of plugins. // it from the list of plugins.
// this is not called for web seeds
virtual bool on_handshake() { return true; } virtual bool on_handshake() { return true; }
// called when the extension handshake from the other end is received // called when the extension handshake from the other end is received
// if this returns false, it means that this extension isn't // if this returns false, it means that this extension isn't
// supported by this peer. It will result in this peer_plugin // supported by this peer. It will result in this peer_plugin
// being removed from the peer_connection and destructed. // being removed from the peer_connection and destructed.
// this is not called for web seeds
virtual bool on_extension_handshake(entry const& h) { return true; } virtual bool on_extension_handshake(entry const& h) { return true; }
// returning true from any of the message handlers // returning true from any of the message handlers
@ -141,10 +144,12 @@ namespace libtorrent
// the message is not processed by any other plugin and if false // the message is not processed by any other plugin and if false
// is returned the next plugin in the chain will receive it to // is returned the next plugin in the chain will receive it to
// be able to handle it // be able to handle it
// this is not called for web seeds
virtual bool on_extended(int length virtual bool on_extended(int length
, int msg, buffer::const_interval body) , int msg, buffer::const_interval body)
{ return false; } { return false; }
// this is not called for web seeds
virtual bool on_unknown_message(int length, int msg virtual bool on_unknown_message(int length, int msg
, buffer::const_interval body) , buffer::const_interval body)
{ return false; } { return false; }

View File

@ -373,14 +373,6 @@ namespace libtorrent
m_statistics.received_bytes(0, received); m_statistics.received_bytes(0, received);
if (!packet_finished()) return; if (!packet_finished()) return;
#ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
{
if ((*i)->on_choke()) return;
}
#endif
incoming_choke(); incoming_choke();
} }
@ -398,14 +390,6 @@ namespace libtorrent
m_statistics.received_bytes(0, received); m_statistics.received_bytes(0, received);
if (!packet_finished()) return; if (!packet_finished()) return;
#ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
{
if ((*i)->on_unchoke()) return;
}
#endif
incoming_unchoke(); incoming_unchoke();
} }
@ -423,14 +407,6 @@ namespace libtorrent
m_statistics.received_bytes(0, received); m_statistics.received_bytes(0, received);
if (!packet_finished()) return; if (!packet_finished()) return;
#ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
{
if ((*i)->on_interested()) return;
}
#endif
incoming_interested(); incoming_interested();
} }
@ -448,14 +424,6 @@ namespace libtorrent
m_statistics.received_bytes(0, received); m_statistics.received_bytes(0, received);
if (!packet_finished()) return; if (!packet_finished()) return;
#ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
{
if ((*i)->on_not_interested()) return;
}
#endif
incoming_not_interested(); incoming_not_interested();
} }
@ -478,14 +446,6 @@ namespace libtorrent
const char* ptr = recv_buffer.begin + 1; const char* ptr = recv_buffer.begin + 1;
int index = detail::read_int32(ptr); int index = detail::read_int32(ptr);
#ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
{
if ((*i)->on_have(index)) return;
}
#endif
incoming_have(index); incoming_have(index);
} }
@ -527,14 +487,6 @@ namespace libtorrent
for (int i = 0; i < (int)bitfield.size(); ++i) for (int i = 0; i < (int)bitfield.size(); ++i)
bitfield[i] = (recv_buffer[1 + (i>>3)] & (1 << (7 - (i&7)))) != 0; bitfield[i] = (recv_buffer[1 + (i>>3)] & (1 << (7 - (i&7)))) != 0;
#ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
{
if ((*i)->on_bitfield(bitfield)) return;
}
#endif
incoming_bitfield(bitfield); incoming_bitfield(bitfield);
} }
@ -560,14 +512,6 @@ namespace libtorrent
r.start = detail::read_int32(ptr); r.start = detail::read_int32(ptr);
r.length = detail::read_int32(ptr); r.length = detail::read_int32(ptr);
#ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
{
if ((*i)->on_request(r)) return;
}
#endif
incoming_request(r); incoming_request(r);
} }
@ -612,14 +556,6 @@ namespace libtorrent
p.start = detail::read_int32(ptr); p.start = detail::read_int32(ptr);
p.length = packet_size() - 9; p.length = packet_size() - 9;
#ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
{
if ((*i)->on_piece(p, recv_buffer.begin + 9)) return;
}
#endif
incoming_piece(p, recv_buffer.begin + 9); incoming_piece(p, recv_buffer.begin + 9);
} }
@ -645,14 +581,6 @@ namespace libtorrent
r.start = detail::read_int32(ptr); r.start = detail::read_int32(ptr);
r.length = detail::read_int32(ptr); r.length = detail::read_int32(ptr);
#ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
{
if ((*i)->on_cancel(r)) return;
}
#endif
incoming_cancel(r); incoming_cancel(r);
} }

View File

@ -487,6 +487,8 @@ namespace libtorrent { namespace
boost::shared_ptr<peer_plugin> metadata_plugin::new_connection( boost::shared_ptr<peer_plugin> metadata_plugin::new_connection(
peer_connection* pc) peer_connection* pc)
{ {
bt_peer_connection* c = dynamic_cast<bt_peer_connection*>(pc);
if (!c) return boost::shared_ptr<peer_plugin>();
return boost::shared_ptr<peer_plugin>(new metadata_peer_plugin(m_torrent, *pc, *this)); return boost::shared_ptr<peer_plugin>(new metadata_peer_plugin(m_torrent, *pc, *this));
} }

View File

@ -532,6 +532,14 @@ namespace libtorrent
boost::shared_ptr<torrent> t = m_torrent.lock(); boost::shared_ptr<torrent> t = m_torrent.lock();
assert(t); assert(t);
#ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
{
if ((*i)->on_choke()) return;
}
#endif
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time; using namespace boost::posix_time;
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::universal_time())
@ -574,6 +582,14 @@ namespace libtorrent
boost::shared_ptr<torrent> t = m_torrent.lock(); boost::shared_ptr<torrent> t = m_torrent.lock();
assert(t); assert(t);
#ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
{
if ((*i)->on_unchoke()) return;
}
#endif
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time; using namespace boost::posix_time;
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::universal_time())
@ -594,6 +610,14 @@ namespace libtorrent
boost::shared_ptr<torrent> t = m_torrent.lock(); boost::shared_ptr<torrent> t = m_torrent.lock();
assert(t); assert(t);
#ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
{
if ((*i)->on_interested()) return;
}
#endif
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time; using namespace boost::posix_time;
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::universal_time())
@ -611,6 +635,14 @@ namespace libtorrent
{ {
INVARIANT_CHECK; INVARIANT_CHECK;
#ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
{
if ((*i)->on_not_interested()) return;
}
#endif
m_became_uninterested = second_clock::universal_time(); m_became_uninterested = second_clock::universal_time();
// clear the request queue if the client isn't interested // clear the request queue if the client isn't interested
@ -641,6 +673,14 @@ namespace libtorrent
boost::shared_ptr<torrent> t = m_torrent.lock(); boost::shared_ptr<torrent> t = m_torrent.lock();
assert(t); assert(t);
#ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
{
if ((*i)->on_have(index)) return;
}
#endif
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time; using namespace boost::posix_time;
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::universal_time())
@ -700,6 +740,14 @@ namespace libtorrent
boost::shared_ptr<torrent> t = m_torrent.lock(); boost::shared_ptr<torrent> t = m_torrent.lock();
assert(t); assert(t);
#ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
{
if ((*i)->on_bitfield(bitfield)) return;
}
#endif
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time; using namespace boost::posix_time;
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::universal_time())
@ -784,6 +832,14 @@ namespace libtorrent
boost::shared_ptr<torrent> t = m_torrent.lock(); boost::shared_ptr<torrent> t = m_torrent.lock();
assert(t); assert(t);
#ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
{
if ((*i)->on_request(r)) return;
}
#endif
if (!t->valid_metadata()) if (!t->valid_metadata())
{ {
// if we don't have valid metadata yet, // if we don't have valid metadata yet,
@ -922,6 +978,15 @@ namespace libtorrent
boost::shared_ptr<torrent> t = m_torrent.lock(); boost::shared_ptr<torrent> t = m_torrent.lock();
assert(t); assert(t);
#ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
{
if ((*i)->on_piece(p, data)) return;
}
#endif
#ifndef NDEBUG #ifndef NDEBUG
check_postcondition post_checker_(t); check_postcondition post_checker_(t);
t->check_invariant(); t->check_invariant();
@ -1173,6 +1238,14 @@ namespace libtorrent
{ {
INVARIANT_CHECK; INVARIANT_CHECK;
#ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
{
if ((*i)->on_cancel(r)) return;
}
#endif
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
using namespace boost::posix_time; using namespace boost::posix_time;
(*m_logger) << to_simple_string(second_clock::universal_time()) (*m_logger) << to_simple_string(second_clock::universal_time())

View File

@ -1693,6 +1693,8 @@ namespace libtorrent { namespace detail
m_thread->join(); m_thread->join();
assert(m_torrents.empty());
// it's important that the main thread is closed completely before // it's important that the main thread is closed completely before
// the checker thread is terminated. Because all the connections // the checker thread is terminated. Because all the connections
// have to be closed and removed from the torrents before they // have to be closed and removed from the torrents before they

View File

@ -1488,6 +1488,15 @@ namespace libtorrent
c->m_in_constructor = false; c->m_in_constructor = false;
#endif #endif
#ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
{
boost::shared_ptr<peer_plugin> pp((*i)->new_connection(c.get()));
if (pp) c->add_extension(pp);
}
#endif
try try
{ {
m_ses.m_connection_queue.push_back(c); m_ses.m_connection_queue.push_back(c);

View File

@ -321,6 +321,8 @@ namespace libtorrent { namespace
boost::shared_ptr<peer_plugin> ut_pex_plugin::new_connection(peer_connection* pc) boost::shared_ptr<peer_plugin> ut_pex_plugin::new_connection(peer_connection* pc)
{ {
bt_peer_connection* c = dynamic_cast<bt_peer_connection*>(pc);
if (!c) return boost::shared_ptr<peer_plugin>();
return boost::shared_ptr<peer_plugin>(new ut_pex_peer_plugin(m_torrent return boost::shared_ptr<peer_plugin>(new ut_pex_peer_plugin(m_torrent
, *pc, *this)); , *pc, *this));
} }