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);
#endif
virtual int type() const override
{ return peer_connection::bittorrent_connection; }
virtual connection_type type() const override
{ return connection_type::bittorrent; }
enum message_type
{

View File

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

View File

@ -245,6 +245,13 @@ namespace libtorrent
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
: public peer_connection_hot_members
, public bandwidth_socket
@ -257,14 +264,7 @@ namespace libtorrent
friend class torrent;
public:
enum connection_type
{
bittorrent_connection = 0,
url_seed_connection = 1,
http_seed_connection = 2
};
virtual int type() const = 0;
virtual connection_type type() const = 0;
enum channels
{

View File

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

View File

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

View File

@ -4161,7 +4161,7 @@ namespace libtorrent
else m_counters.inc_stats_counter(counters::error_incoming_peers);
#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);
if (bt->supports_encryption()) m_counters.inc_stats_counter(

View File

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

View File

@ -77,9 +77,10 @@ namespace libtorrent
// we don't want to request more blocks while trying to gracefully pause
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
// via normal requests
@ -161,7 +162,7 @@ namespace libtorrent
// the last argument is if we should prefer whole pieces
// for this peer. If we're downloading one piece in 20 seconds
// 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()
, c.picker_options(), suggested, t.num_peers()
, ses.stats_counters());

View File

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

View File

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

View File

@ -495,7 +495,7 @@ namespace libtorrent { namespace
std::shared_ptr<peer_plugin> ut_metadata_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>();
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;
// only send proper bittorrent peers
if (peer->type() != peer_connection::bittorrent_connection)
if (peer->type() != connection_type::bittorrent)
continue;
bt_peer_connection* p = static_cast<bt_peer_connection*>(peer);
@ -544,7 +544,7 @@ namespace libtorrent { namespace
if (num_added >= max_peer_entries) break;
// only send proper bittorrent peers
if (peer->type() != peer_connection::bittorrent_connection)
if (peer->type() != connection_type::bittorrent)
continue;
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)
{
if (pc.type() != peer_connection::bittorrent_connection)
if (pc.type() != connection_type::bittorrent)
return std::shared_ptr<peer_plugin>();
bt_peer_connection* c = static_cast<bt_peer_connection*>(pc.native_handle().get());