make connection_type enum an enum class (#1146)

This commit is contained in:
Arvid Norberg 2016-09-24 10:47:17 -07:00 committed by GitHub
parent d2002c5248
commit 372d992d8e
12 changed files with 38 additions and 33 deletions

View File

@ -120,8 +120,8 @@ namespace libtorrent
void switch_recv_crypto(std::shared_ptr<crypto_plugin> crypto); void switch_recv_crypto(std::shared_ptr<crypto_plugin> crypto);
#endif #endif
virtual int type() const override virtual connection_type type() const override
{ return peer_connection::bittorrent_connection; } { return connection_type::bittorrent; }
enum message_type enum message_type
{ {

View File

@ -59,8 +59,8 @@ namespace libtorrent
http_seed_connection(peer_connection_args const& pack http_seed_connection(peer_connection_args const& pack
, web_seed_t& web); , web_seed_t& web);
virtual int type() const override virtual connection_type type() const override
{ return peer_connection::http_seed_connection; } { return connection_type::http_seed; }
// called from the main loop when this connection has any // called from the main loop when this connection has any
// work to do. // work to do.

View File

@ -245,6 +245,13 @@ namespace libtorrent
peer_connection_hot_members& operator=(peer_connection_hot_members const&); peer_connection_hot_members& operator=(peer_connection_hot_members const&);
}; };
enum class connection_type : std::uint8_t
{
bittorrent,
url_seed,
http_seed
};
class TORRENT_EXTRA_EXPORT peer_connection class TORRENT_EXTRA_EXPORT peer_connection
: public peer_connection_hot_members : public peer_connection_hot_members
, public bandwidth_socket , public bandwidth_socket
@ -257,14 +264,7 @@ namespace libtorrent
friend class torrent; friend class torrent;
public: public:
enum connection_type virtual connection_type type() const = 0;
{
bittorrent_connection = 0,
url_seed_connection = 1,
http_seed_connection = 2
};
virtual int type() const = 0;
enum channels enum channels
{ {

View File

@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/peer_id.hpp" #include "libtorrent/peer_id.hpp"
#include "libtorrent/operations.hpp" #include "libtorrent/operations.hpp"
#include "libtorrent/alert_types.hpp" #include "libtorrent/alert_types.hpp"
#include "libtorrent/peer_connection.hpp" // for connection_type
namespace libtorrent namespace libtorrent
{ {
@ -57,7 +58,7 @@ struct TORRENT_EXPORT peer_connection_handle
: m_connection(impl) : m_connection(impl)
{} {}
int type() const; connection_type type() const;
void add_extension(std::shared_ptr<peer_plugin>); void add_extension(std::shared_ptr<peer_plugin>);

View File

@ -66,8 +66,8 @@ namespace libtorrent
virtual void on_connected() override; virtual void on_connected() override;
virtual int type() const override virtual connection_type type() const override
{ return peer_connection::url_seed_connection; } { return connection_type::url_seed; }
// called from the main loop when this connection has any // called from the main loop when this connection has any
// work to do. // work to do.

View File

@ -4161,7 +4161,7 @@ namespace libtorrent
else m_counters.inc_stats_counter(counters::error_incoming_peers); else m_counters.inc_stats_counter(counters::error_incoming_peers);
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) #if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
if (type() == bittorrent_connection && op != op_connect) if (type() == connection_type::bittorrent && op != op_connect)
{ {
bt_peer_connection* bt = static_cast<bt_peer_connection*>(this); bt_peer_connection* bt = static_cast<bt_peer_connection*>(this);
if (bt->supports_encryption()) m_counters.inc_stats_counter( if (bt->supports_encryption()) m_counters.inc_stats_counter(

View File

@ -41,7 +41,7 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent namespace libtorrent
{ {
int peer_connection_handle::type() const connection_type peer_connection_handle::type() const
{ {
std::shared_ptr<peer_connection> pc = native_handle(); std::shared_ptr<peer_connection> pc = native_handle();
TORRENT_ASSERT(pc); TORRENT_ASSERT(pc);

View File

@ -77,9 +77,10 @@ namespace libtorrent
// we don't want to request more blocks while trying to gracefully pause // we don't want to request more blocks while trying to gracefully pause
if (t.graceful_pause()) return false; if (t.graceful_pause()) return false;
TORRENT_ASSERT(c.peer_info_struct() != nullptr || c.type() != peer_connection::bittorrent_connection); TORRENT_ASSERT(c.peer_info_struct() != nullptr
|| c.type() != connection_type::bittorrent);
bool time_critical_mode = t.num_time_critical_pieces() > 0; bool const time_critical_mode = t.num_time_critical_pieces() > 0;
// in time critical mode, only have 1 outstanding request at a time // in time critical mode, only have 1 outstanding request at a time
// via normal requests // via normal requests
@ -161,7 +162,7 @@ namespace libtorrent
// the last argument is if we should prefer whole pieces // the last argument is if we should prefer whole pieces
// for this peer. If we're downloading one piece in 20 seconds // for this peer. If we're downloading one piece in 20 seconds
// then use this mode. // then use this mode.
std::uint32_t flags = p.pick_pieces(*bits, interesting_pieces std::uint32_t const flags = p.pick_pieces(*bits, interesting_pieces
, num_requests, prefer_contiguous_blocks, c.peer_info_struct() , num_requests, prefer_contiguous_blocks, c.peer_info_struct()
, c.picker_options(), suggested, t.num_peers() , c.picker_options(), suggested, t.num_peers()
, ses.stats_counters()); , ses.stats_counters());

View File

@ -2060,6 +2060,8 @@ namespace aux {
return; return;
} }
if (m_abort) return;
error_code ec; error_code ec;
tcp::endpoint ep = sock->local_endpoint(ec); tcp::endpoint ep = sock->local_endpoint(ec);
TORRENT_ASSERT(!ec); TORRENT_ASSERT(!ec);
@ -2092,6 +2094,7 @@ namespace aux {
, listen_failed_alert::socks5); , listen_failed_alert::socks5);
return; return;
} }
if (m_abort) return;
open_new_incoming_socks_connection(); open_new_incoming_socks_connection();
incoming_connection(s); incoming_connection(s);
} }
@ -6143,9 +6146,9 @@ namespace aux {
for (connection_map::iterator i = m_connections.begin() for (connection_map::iterator i = m_connections.begin()
, end(m_connections.end()); i != end; ++i) , end(m_connections.end()); i != end; ++i)
{ {
int type = (*i)->type(); connection_type const type = (*i)->type();
if (type == peer_connection::url_seed_connection if (type == connection_type::url_seed
|| type == peer_connection::http_seed_connection) || type == connection_type::http_seed)
(*i)->ignore_stats(!report); (*i)->ignore_stats(!report);
} }
} }

View File

@ -919,7 +919,7 @@ namespace libtorrent
for (peer_iterator i = m_connections.begin() for (peer_iterator i = m_connections.begin()
, end(m_connections.end()); i != end; ++i) , end(m_connections.end()); i != end; ++i)
{ {
if ((*i)->type() != peer_connection::bittorrent_connection) continue; if ((*i)->type() != connection_type::bittorrent) continue;
bt_peer_connection* p = static_cast<bt_peer_connection*>(*i); bt_peer_connection* p = static_cast<bt_peer_connection*>(*i);
p->write_share_mode(); p->write_share_mode();
} }
@ -940,7 +940,7 @@ namespace libtorrent
// delete the entry from this container, make sure // delete the entry from this container, make sure
// to increment the iterator early // to increment the iterator early
bt_peer_connection* p = static_cast<bt_peer_connection*>(*i); bt_peer_connection* p = static_cast<bt_peer_connection*>(*i);
if (p->type() == peer_connection::bittorrent_connection) if (p->type() == connection_type::bittorrent)
{ {
std::shared_ptr<peer_connection> me(p->self()); std::shared_ptr<peer_connection> me(p->self());
if (!p->is_disconnecting()) if (!p->is_disconnecting())
@ -2122,7 +2122,7 @@ namespace libtorrent
#ifndef TORRENT_DISABLE_EXTENSIONS #ifndef TORRENT_DISABLE_EXTENSIONS
for (auto pe : m_connections) for (auto pe : m_connections)
{ {
if (pe->type() != peer_connection::bittorrent_connection) continue; if (pe->type() != connection_type::bittorrent) continue;
bt_peer_connection* p = static_cast<bt_peer_connection*>(pe); bt_peer_connection* p = static_cast<bt_peer_connection*>(pe);
if (!p->supports_holepunch()) continue; if (!p->supports_holepunch()) continue;
if (p->was_introduced_by(ep)) return p; if (p->was_introduced_by(ep)) return p;
@ -2137,7 +2137,7 @@ namespace libtorrent
{ {
for (auto p : m_connections) for (auto p : m_connections)
{ {
if (p->type() != peer_connection::bittorrent_connection) continue; if (p->type() != connection_type::bittorrent) continue;
if (p->remote() == ep) return static_cast<bt_peer_connection*>(p); if (p->remote() == ep) return static_cast<bt_peer_connection*>(p);
} }
return nullptr; return nullptr;
@ -6805,11 +6805,11 @@ namespace libtorrent
, [peerinfo] (peer_connection const* p) { return p->remote() == peerinfo->ip(); }); , [peerinfo] (peer_connection const* p) { return p->remote() == peerinfo->ip(); });
#if TORRENT_USE_I2P #if TORRENT_USE_I2P
TORRENT_ASSERT(i_ == m_connections.end() TORRENT_ASSERT(i_ == m_connections.end()
|| (*i_)->type() != peer_connection::bittorrent_connection || (*i_)->type() != connection_type::bittorrent
|| peerinfo->is_i2p_addr); || peerinfo->is_i2p_addr);
#else #else
TORRENT_ASSERT(i_ == m_connections.end() TORRENT_ASSERT(i_ == m_connections.end()
|| (*i_)->type() != peer_connection::bittorrent_connection); || (*i_)->type() != connection_type::bittorrent);
#endif #endif
} }
#endif // TORRENT_USE_ASSERTS #endif // TORRENT_USE_ASSERTS

View File

@ -495,7 +495,7 @@ namespace libtorrent { namespace
std::shared_ptr<peer_plugin> ut_metadata_plugin::new_connection( std::shared_ptr<peer_plugin> ut_metadata_plugin::new_connection(
peer_connection_handle const& pc) peer_connection_handle const& pc)
{ {
if (pc.type() != peer_connection::bittorrent_connection) if (pc.type() != connection_type::bittorrent)
return std::shared_ptr<peer_plugin>(); return std::shared_ptr<peer_plugin>();
bt_peer_connection* c = static_cast<bt_peer_connection*>(pc.native_handle().get()); bt_peer_connection* c = static_cast<bt_peer_connection*>(pc.native_handle().get());

View File

@ -144,7 +144,7 @@ namespace libtorrent { namespace
if (num_added >= max_peer_entries) break; if (num_added >= max_peer_entries) break;
// only send proper bittorrent peers // only send proper bittorrent peers
if (peer->type() != peer_connection::bittorrent_connection) if (peer->type() != connection_type::bittorrent)
continue; continue;
bt_peer_connection* p = static_cast<bt_peer_connection*>(peer); bt_peer_connection* p = static_cast<bt_peer_connection*>(peer);
@ -544,7 +544,7 @@ namespace libtorrent { namespace
if (num_added >= max_peer_entries) break; if (num_added >= max_peer_entries) break;
// only send proper bittorrent peers // only send proper bittorrent peers
if (peer->type() != peer_connection::bittorrent_connection) if (peer->type() != connection_type::bittorrent)
continue; continue;
bt_peer_connection* p = static_cast<bt_peer_connection*>(peer); bt_peer_connection* p = static_cast<bt_peer_connection*>(peer);
@ -639,7 +639,7 @@ namespace libtorrent { namespace
std::shared_ptr<peer_plugin> ut_pex_plugin::new_connection(peer_connection_handle const& pc) std::shared_ptr<peer_plugin> ut_pex_plugin::new_connection(peer_connection_handle const& pc)
{ {
if (pc.type() != peer_connection::bittorrent_connection) if (pc.type() != connection_type::bittorrent)
return std::shared_ptr<peer_plugin>(); return std::shared_ptr<peer_plugin>();
bt_peer_connection* c = static_cast<bt_peer_connection*>(pc.native_handle().get()); bt_peer_connection* c = static_cast<bt_peer_connection*>(pc.native_handle().get());