made it possible to build without RTTI

This commit is contained in:
Arvid Norberg 2009-11-02 20:43:38 +00:00
parent 0a8c3a6419
commit e43340c961
11 changed files with 60 additions and 50 deletions

View File

@ -2,6 +2,7 @@
* replaced dependency on boost.thread by asio's internal thread primitives
* added support for i2p torrents
* cleaned up usage of MAX_PATH and related macros
* made it possible to build libtorrent without RTTI support
0.15 release

View File

@ -111,6 +111,8 @@ namespace libtorrent
{ return m_encrypted; }
#endif
virtual int type() const { return peer_connection::bittorrent_connection; }
enum message_type
{
// standard messages
@ -151,18 +153,6 @@ namespace libtorrent
#ifndef TORRENT_DISABLE_EXTENSIONS
bool support_extensions() const { return m_supports_extensions; }
template <class T>
T* supports_extension() const
{
for (extension_list_t::const_iterator i = m_extensions.begin()
, end(m_extensions.end()); i != end; ++i)
{
T* ret = dynamic_cast<T*>(i->get());
if (ret) return ret;
}
return 0;
}
#endif
// the message handlers are called

View File

@ -101,6 +101,8 @@ namespace libtorrent
~http_seed_connection();
virtual int type() const { return peer_connection::http_seed_connection; }
// called from the main loop when this connection has any
// work to do.
void on_sent(error_code const& error

View File

@ -134,6 +134,15 @@ namespace libtorrent
friend class invariant_access;
public:
enum connection_type
{
bittorrent_connection = 0,
url_seed_connection = 1,
http_seed_connection = 2
};
virtual int type() const = 0;
enum channels
{
upload_channel,

View File

@ -101,6 +101,8 @@ namespace libtorrent
~web_peer_connection();
virtual int type() const { return peer_connection::url_seed_connection; }
// called from the main loop when this connection has any
// work to do.
void on_sent(error_code const& error

View File

@ -327,8 +327,10 @@ namespace libtorrent { namespace
boost::shared_ptr<peer_plugin> lt_tracker_plugin::new_connection(
peer_connection* pc)
{
bt_peer_connection* c = dynamic_cast<bt_peer_connection*>(pc);
if (!c) return boost::shared_ptr<peer_plugin>();
if (pc->type() != peer_connection::bittorrent_connection)
return boost::shared_ptr<peer_plugin>();
bt_peer_connection* c = static_cast<bt_peer_connection*>(pc);
return boost::shared_ptr<peer_plugin>(new lt_tracker_peer_plugin(m_torrent, *c, *this));
}

View File

@ -527,32 +527,17 @@ namespace libtorrent { namespace
boost::shared_ptr<peer_plugin> metadata_plugin::new_connection(
peer_connection* pc)
{
bt_peer_connection* c = dynamic_cast<bt_peer_connection*>(pc);
if (!c) return boost::shared_ptr<peer_plugin>();
if (pc->type() != peer_connection::bittorrent_connection)
return boost::shared_ptr<peer_plugin>();
bt_peer_connection* c = static_cast<bt_peer_connection*>(pc);
return boost::shared_ptr<peer_plugin>(new metadata_peer_plugin(m_torrent, *pc, *this));
}
std::pair<int, int> metadata_plugin::metadata_request()
{
// count the number of peers that supports the
// extension and that has metadata
int peers = 0;
#ifndef TORRENT_DISABLE_EXTENSIONS
for (torrent::peer_iterator i = m_torrent.begin()
, end(m_torrent.end()); i != end; ++i)
{
bt_peer_connection* c = dynamic_cast<bt_peer_connection*>(*i);
if (c == 0) continue;
metadata_peer_plugin* p
= c->supports_extension<metadata_peer_plugin>();
if (p == 0) continue;
if (!p->has_metadata()) continue;
++peers;
}
#endif
// the number of blocks to request
int num_blocks = 256 / (peers + 1);
int num_blocks = 256 / 4;
if (num_blocks < 1) num_blocks = 1;
TORRENT_ASSERT(num_blocks <= 128);

View File

@ -136,7 +136,7 @@ namespace libtorrent
if (!t.are_files_checked()) return;
TORRENT_ASSERT(t.valid_metadata());
TORRENT_ASSERT(c.peer_info_struct() != 0 || !dynamic_cast<bt_peer_connection*>(&c));
TORRENT_ASSERT(c.peer_info_struct() != 0 || c.type() != peer_connection::bittorrent_connection);
int num_requests = c.desired_queue_size()
- (int)c.download_queue().size()
- (int)c.request_queue().size();
@ -1345,7 +1345,7 @@ namespace libtorrent
if ((*i)->is_disconnecting()) continue;
// ignore web_peer_connections since they are not managed
// by the policy class
if (dynamic_cast<web_peer_connection*>(*i)) continue;
if ((*i)->type() != peer_connection::bittorrent_connection) continue;
++num_torrent_peers;
}

View File

@ -3897,12 +3897,12 @@ namespace libtorrent
, bind(&peer_connection::remote, _1) == peerinfo->ip());
#if TORRENT_USE_I2P
TORRENT_ASSERT(i_ == m_connections.end()
|| dynamic_cast<bt_peer_connection*>(*i_) == 0
|| (*i_)->type() != peer_connection::bittorrent_connection
|| peerinfo->is_i2p_addr
);
#else
TORRENT_ASSERT(i_ == m_connections.end()
|| dynamic_cast<bt_peer_connection*>(*i_) == 0
|| (*i_)->type() != peer_connection::bittorrent_connection
);
#endif
#endif
@ -5315,10 +5315,21 @@ namespace libtorrent
for (peer_iterator i = m_connections.begin();
i != m_connections.end(); ++i)
{
web_peer_connection* p = dynamic_cast<web_peer_connection*>(*i);
if (p) web_seeds.insert(web_seed_entry(p->url(), web_seed_entry::url_seed));
http_seed_connection* s = dynamic_cast<http_seed_connection*>(*i);
if (s) web_seeds.insert(web_seed_entry(s->url(), web_seed_entry::http_seed));
switch ((*i)->type())
{
case peer_connection::url_seed_connection:
{
web_peer_connection* p = static_cast<web_peer_connection*>(*i);
web_seeds.insert(web_seed_entry(p->url(), web_seed_entry::url_seed));
break;
}
case peer_connection::http_seed_connection:
{
http_seed_connection* p = static_cast<http_seed_connection*>(*i);
web_seeds.insert(web_seed_entry(p->url(), web_seed_entry::http_seed));
break;
}
}
}
for (std::set<web_seed_entry>::iterator i = m_resolving_web_seeds.begin()

View File

@ -406,8 +406,10 @@ namespace libtorrent { namespace
boost::shared_ptr<peer_plugin> ut_metadata_plugin::new_connection(
peer_connection* pc)
{
bt_peer_connection* c = dynamic_cast<bt_peer_connection*>(pc);
if (!c) return boost::shared_ptr<peer_plugin>();
if (pc->type() != peer_connection::bittorrent_connection)
return boost::shared_ptr<peer_plugin>();
bt_peer_connection* c = static_cast<bt_peer_connection*>(pc);
return boost::shared_ptr<peer_plugin>(new ut_metadata_peer_plugin(m_torrent, *c, *this));
}

View File

@ -136,8 +136,10 @@ namespace libtorrent { namespace
if (num_added >= max_peer_entries) break;
// only send proper bittorrent peers
bt_peer_connection* p = dynamic_cast<bt_peer_connection*>(peer);
if (!p) continue;
if (peer->type() != peer_connection::bittorrent_connection)
continue;
bt_peer_connection* p = static_cast<bt_peer_connection*>(peer);
// no supported flags to set yet
// 0x01 - peer supports encryption
@ -369,8 +371,10 @@ namespace libtorrent { namespace
if (num_added >= max_peer_entries) break;
// only send proper bittorrent peers
bt_peer_connection* p = dynamic_cast<bt_peer_connection*>(peer);
if (!p) continue;
if (peer->type() != peer_connection::bittorrent_connection)
continue;
bt_peer_connection* p = static_cast<bt_peer_connection*>(peer);
// no supported flags to set yet
// 0x01 - peer supports encryption
@ -425,8 +429,10 @@ namespace libtorrent { namespace
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>();
if (pc->type() != peer_connection::bittorrent_connection)
return boost::shared_ptr<peer_plugin>();
bt_peer_connection* c = static_cast<bt_peer_connection*>(pc);
return boost::shared_ptr<peer_plugin>(new ut_pex_peer_plugin(m_torrent
, *pc, *this));
}