diff --git a/include/libtorrent/bt_peer_connection.hpp b/include/libtorrent/bt_peer_connection.hpp index 13d7cfc14..098090ac4 100644 --- a/include/libtorrent/bt_peer_connection.hpp +++ b/include/libtorrent/bt_peer_connection.hpp @@ -120,8 +120,8 @@ namespace libtorrent void switch_recv_crypto(std::shared_ptr 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 { diff --git a/include/libtorrent/http_seed_connection.hpp b/include/libtorrent/http_seed_connection.hpp index 75d815b59..48f7c6ab4 100644 --- a/include/libtorrent/http_seed_connection.hpp +++ b/include/libtorrent/http_seed_connection.hpp @@ -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. diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index e590723a4..6f53606b1 100644 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -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 { diff --git a/include/libtorrent/peer_connection_handle.hpp b/include/libtorrent/peer_connection_handle.hpp index 643c844ee..0f070370b 100644 --- a/include/libtorrent/peer_connection_handle.hpp +++ b/include/libtorrent/peer_connection_handle.hpp @@ -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); diff --git a/include/libtorrent/web_peer_connection.hpp b/include/libtorrent/web_peer_connection.hpp index b2f9445c4..c8596775a 100644 --- a/include/libtorrent/web_peer_connection.hpp +++ b/include/libtorrent/web_peer_connection.hpp @@ -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. diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 330545fc8..96f8ea8c7 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -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(this); if (bt->supports_encryption()) m_counters.inc_stats_counter( diff --git a/src/peer_connection_handle.cpp b/src/peer_connection_handle.cpp index fc5a8654f..2cf426673 100644 --- a/src/peer_connection_handle.cpp +++ b/src/peer_connection_handle.cpp @@ -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 pc = native_handle(); TORRENT_ASSERT(pc); diff --git a/src/request_blocks.cpp b/src/request_blocks.cpp index 0964b256b..b1e0580f3 100644 --- a/src/request_blocks.cpp +++ b/src/request_blocks.cpp @@ -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()); diff --git a/src/session_impl.cpp b/src/session_impl.cpp index fd3a08387..ac32e7ef6 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -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); } } diff --git a/src/torrent.cpp b/src/torrent.cpp index 9cfb90fc1..270fd680c 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -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(*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(*i); - if (p->type() == peer_connection::bittorrent_connection) + if (p->type() == connection_type::bittorrent) { std::shared_ptr 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(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(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 diff --git a/src/ut_metadata.cpp b/src/ut_metadata.cpp index 167084a96..4a822c3ea 100644 --- a/src/ut_metadata.cpp +++ b/src/ut_metadata.cpp @@ -495,7 +495,7 @@ namespace libtorrent { namespace std::shared_ptr 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(); bt_peer_connection* c = static_cast(pc.native_handle().get()); diff --git a/src/ut_pex.cpp b/src/ut_pex.cpp index 8f11f8304..194defd2c 100644 --- a/src/ut_pex.cpp +++ b/src/ut_pex.cpp @@ -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(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(peer); @@ -639,7 +639,7 @@ namespace libtorrent { namespace std::shared_ptr 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(); bt_peer_connection* c = static_cast(pc.native_handle().get());