improved plugin support

This commit is contained in:
Arvid Norberg 2008-05-12 03:05:27 +00:00
parent e51c8bea37
commit eabe9cad2d
5 changed files with 36 additions and 8 deletions

View File

@ -187,7 +187,7 @@ peer_plugin
virtual ~peer_plugin();
virtual void add_handshake(entry&);
virtual bool on_handshake();
virtual bool on_handshake(char const* reserved_bits);
virtual bool on_extension_handshake(entry const& h);
virtual bool on_choke();

View File

@ -363,6 +363,7 @@ private:
// the peer indicated that it supports the
// extension protocol
bool m_supports_extensions;
char m_reserved_bits[20];
#endif
bool m_supports_dht_port;
bool m_supports_fast;

View File

@ -99,7 +99,7 @@ namespace libtorrent
// means that the other end doesn't support this extension and will remove
// it from the list of plugins.
// this is not called for web seeds
virtual bool on_handshake() { return true; }
virtual bool on_handshake(char const* reserved_bits) { return true; }
// called when the extension handshake from the other end is received
// if this returns false, it means that this extension isn't

View File

@ -807,6 +807,7 @@ namespace libtorrent
if (!packet_finished()) return;
incoming_choke();
if (is_disconnecting()) return;
if (!m_supports_fast)
{
boost::shared_ptr<torrent> t = associated_torrent().lock();
@ -1021,6 +1022,7 @@ namespace libtorrent
}
incoming_piece_fragment();
if (is_disconnecting()) return;
if (!packet_finished()) return;
const char* ptr = recv_buffer.begin + 1;
@ -2329,6 +2331,7 @@ namespace libtorrent
#endif
#ifndef DISABLE_EXTENSIONS
std::memcpy(m_reserved_bits, recv_buffer.begin, 20);
if ((recv_buffer[5] & 0x10))
m_supports_extensions = true;
#endif
@ -2475,7 +2478,7 @@ namespace libtorrent
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end;)
{
if (!(*i)->on_handshake())
if (!(*i)->on_handshake(m_reserved_bits))
{
i = m_extensions.erase(i);
}
@ -2484,6 +2487,7 @@ namespace libtorrent
++i;
}
}
if (is_disconnecting()) return;
if (m_supports_extensions) write_extensions();
#endif
@ -2549,6 +2553,7 @@ namespace libtorrent
if (packet_size == 0)
{
incoming_keepalive();
if (is_disconnecting()) return;
// keepalive message
m_state = read_packet_size;
cut_receive_buffer(4, 4);

View File

@ -611,6 +611,7 @@ namespace libtorrent
#endif
}
#endif
if (is_disconnecting()) return;
if (peer_info_struct())
{
@ -780,6 +781,7 @@ namespace libtorrent
if ((*i)->on_choke()) return;
}
#endif
if (is_disconnecting()) return;
#ifdef TORRENT_VERBOSE_LOGGING
(*m_logger) << time_now_string() << " <== CHOKE\n";
@ -833,6 +835,8 @@ namespace libtorrent
}
#endif
if (is_disconnecting()) return;
std::deque<piece_block>::iterator i = std::find_if(
m_download_queue.begin(), m_download_queue.end()
, bind(match_request, boost::cref(r), _1, t->block_size()));
@ -916,6 +920,7 @@ namespace libtorrent
}
#endif
if (is_disconnecting()) return;
if (t->have_piece(index)) return;
if (m_suggested_pieces.size() > 9)
@ -951,6 +956,8 @@ namespace libtorrent
(*m_logger) << time_now_string() << " <== UNCHOKE\n";
#endif
m_peer_choked = false;
if (is_disconnecting()) return;
t->get_policy().unchoked(*this);
}
@ -977,6 +984,7 @@ namespace libtorrent
(*m_logger) << time_now_string() << " <== INTERESTED\n";
#endif
m_peer_interested = true;
if (is_disconnecting()) return;
t->get_policy().interested(*this);
}
@ -1001,11 +1009,12 @@ namespace libtorrent
#ifdef TORRENT_VERBOSE_LOGGING
(*m_logger) << time_now_string() << " <== NOT_INTERESTED\n";
#endif
m_peer_interested = false;
if (is_disconnecting()) return;
boost::shared_ptr<torrent> t = m_torrent.lock();
TORRENT_ASSERT(t);
m_peer_interested = false;
t->get_policy().not_interested(*this);
}
@ -1028,6 +1037,8 @@ namespace libtorrent
}
#endif
if (is_disconnecting()) return;
#ifdef TORRENT_VERBOSE_LOGGING
(*m_logger) << time_now_string()
<< " <== HAVE [ piece: " << index << "]\n";
@ -1126,6 +1137,8 @@ namespace libtorrent
}
#endif
if (is_disconnecting()) return;
#ifdef TORRENT_VERBOSE_LOGGING
(*m_logger) << time_now_string() << " <== BITFIELD ";
@ -1235,6 +1248,7 @@ namespace libtorrent
if ((*i)->on_request(r)) return;
}
#endif
if (is_disconnecting()) return;
if (!t->valid_metadata())
{
@ -1431,6 +1445,7 @@ namespace libtorrent
if ((*i)->on_piece(p, data)) return;
}
#endif
if (is_disconnecting()) return;
#ifndef NDEBUG
check_postcondition post_checker_(t);
@ -1643,6 +1658,7 @@ namespace libtorrent
if ((*i)->on_cancel(r)) return;
}
#endif
if (is_disconnecting()) return;
#ifdef TORRENT_VERBOSE_LOGGING
(*m_logger) << time_now_string()
@ -1712,6 +1728,7 @@ namespace libtorrent
if ((*i)->on_have_all()) return;
}
#endif
if (is_disconnecting()) return;
m_have_all = true;
@ -1757,13 +1774,13 @@ namespace libtorrent
{
INVARIANT_CHECK;
boost::shared_ptr<torrent> t = m_torrent.lock();
TORRENT_ASSERT(t);
#ifdef TORRENT_VERBOSE_LOGGING
(*m_logger) << time_now_string() << " <== HAVE_NONE\n";
#endif
boost::shared_ptr<torrent> t = m_torrent.lock();
TORRENT_ASSERT(t);
#ifndef TORRENT_DISABLE_EXTENSIONS
for (extension_list_t::iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
@ -1771,8 +1788,9 @@ namespace libtorrent
if ((*i)->on_have_none()) return;
}
#endif
if (is_disconnecting()) return;
if (m_peer_info) m_peer_info->seed = false;
TORRENT_ASSERT(!m_have_piece.empty() || !t->ready_for_connections());
}
@ -1798,6 +1816,7 @@ namespace libtorrent
if ((*i)->on_allowed_fast(index)) return;
}
#endif
if (is_disconnecting()) return;
if (index < 0 || index >= int(m_have_piece.size()))
{
@ -2104,6 +2123,7 @@ namespace libtorrent
{
if (handled = (*i)->write_request(r)) break;
}
if (is_disconnecting()) return;
if (!handled)
{
write_request(r);
@ -2423,6 +2443,7 @@ namespace libtorrent
INVARIANT_CHECK;
ptime now(time_now());
boost::intrusive_ptr<peer_connection> me(self());
boost::shared_ptr<torrent> t = m_torrent.lock();
if (!t || m_disconnecting)
@ -2464,6 +2485,7 @@ namespace libtorrent
}
#endif
}
if (is_disconnecting()) return;
if (!t->valid_metadata()) return;