From 1fd350cf600e97595b4ec91eaa2a27f5aeaafa58 Mon Sep 17 00:00:00 2001 From: arvidn Date: Wed, 14 Jun 2017 18:46:11 -0400 Subject: [PATCH] make operation_t an enum class, for type safety --- bindings/python/src/alert.cpp | 27 +++++++ examples/client_test.cpp | 2 +- include/libtorrent/alert_types.hpp | 25 ++++--- include/libtorrent/operations.hpp | 110 +++++++++++++++++++++++------ src/alert.cpp | 76 +++++++++++--------- src/bt_peer_connection.cpp | 102 +++++++++++++------------- src/http_seed_connection.cpp | 18 ++--- src/peer_connection.cpp | 96 ++++++++++++------------- src/peer_list.cpp | 24 +++---- src/session_impl.cpp | 8 +-- src/smart_ban.cpp | 4 +- src/torrent.cpp | 52 +++++++------- src/ut_metadata.cpp | 6 +- src/ut_pex.cpp | 6 +- src/web_peer_connection.cpp | 24 +++---- 15 files changed, 342 insertions(+), 238 deletions(-) diff --git a/bindings/python/src/alert.cpp b/bindings/python/src/alert.cpp index 18f002b3b..9f747a7d9 100644 --- a/bindings/python/src/alert.cpp +++ b/bindings/python/src/alert.cpp @@ -289,6 +289,29 @@ void bind_alert() } + enum_("operation_t") + .value("bittorrent", operation_t::bittorrent) + .value("iocontrol", operation_t::iocontrol) + .value("getpeername", operation_t::getpeername) + .value("getname", operation_t::getname) + .value("alloc_recvbuf", operation_t::alloc_recvbuf) + .value("alloc_sndbuf", operation_t::alloc_sndbuf) + .value("file_write", operation_t::file_write) + .value("file_read", operation_t::file_read) + .value("file", operation_t::file) + .value("sock_write", operation_t::sock_write) + .value("sock_read", operation_t::sock_read) + .value("sock_open", operation_t::sock_open) + .value("sock_bind", operation_t::sock_bind) + .value("available", operation_t::available) + .value("encryption", operation_t::encryption) + .value("connect", operation_t::connect) + .value("ssl_handshake", operation_t::ssl_handshake) + .value("get_interface", operation_t::get_interface) + .value("unknown", operation_t::unknown) + ; + + class_, noncopyable>( "torrent_alert", no_init) .def_readonly("handle", &torrent_alert::handle) @@ -367,6 +390,7 @@ void bind_alert() class_, noncopyable>( "peer_error_alert", no_init) .def_readonly("error", &peer_error_alert::error) + .def_readonly("op", &peer_error_alert::op) ; class_, noncopyable>( @@ -690,7 +714,10 @@ void bind_alert() class_, noncopyable>( "peer_disconnected_alert", no_init) + .def_readonly("socket_type", &peer_disconnected_alert::socket_type) + .def_readonly("op", &peer_disconnected_alert::op) .def_readonly("error", &peer_disconnected_alert::error) + .def_readonly("reason", &peer_disconnected_alert::reason) #ifndef TORRENT_NO_DEPRECATE .def_readonly("msg", &peer_disconnected_alert::msg) #endif diff --git a/examples/client_test.cpp b/examples/client_test.cpp index d51931af2..2ccea479d 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -835,7 +835,7 @@ bool handle_alert(torrent_view& view, session_view& ses_view // ignore failures to connect and peers not responding with a // handshake. The peers that we successfully connect to and then // disconnect is more interesting. - if (pd->operation == op_connect + if (pd->op == operation_t::connect || pd->error == errors::timed_out_no_handshake) return true; } diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index 228c1ba5b..404d02152 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -62,7 +62,11 @@ namespace libtorrent { // maps an operation id (from peer_error_alert and peer_disconnected_alert) // to its name. See peer_connection for the constants - TORRENT_EXPORT char const* operation_name(int op); + TORRENT_EXPORT char const* operation_name(operation_t op); + +#ifndef TORRENT_NO_DEPRECATE + TORRENT_DEPRECATED_EXPORT char const* operation_name(int op); +#endif // user defined alerts should use IDs greater than this static const int user_alert_id = 10000; @@ -648,7 +652,7 @@ namespace libtorrent { { // internal peer_error_alert(aux::stack_allocator& alloc, torrent_handle const& h - , tcp::endpoint const& ep, peer_id const& peer_id, int op + , tcp::endpoint const& ep, peer_id const& peer_id, operation_t op , error_code const& e); TORRENT_DEFINE_ALERT(peer_error_alert, 22) @@ -658,12 +662,13 @@ namespace libtorrent { // a 0-terminated string of the low-level operation that failed, or nullptr if // there was no low level disk operation. - int const operation; + operation_t op; // tells you what error caused this alert. error_code const error; #ifndef TORRENT_NO_DEPRECATE + int const TORRENT_DEPRECATED_MEMBER operation; std::string TORRENT_DEPRECATED_MEMBER msg; #endif }; @@ -703,7 +708,7 @@ namespace libtorrent { // the operation or level where the error occurred. Specified as an // value from the operation_t enum. Defined in operations.hpp. - operation_t const operation; + operation_t const op; // tells you what error caused peer to disconnect. error_code const error; @@ -712,6 +717,7 @@ namespace libtorrent { close_reason_t const reason; #ifndef TORRENT_NO_DEPRECATE + int const TORRENT_DEPRECATED_MEMBER operation; std::string TORRENT_DEPRECATED_MEMBER msg; #endif }; @@ -1253,7 +1259,7 @@ namespace libtorrent { struct TORRENT_EXPORT listen_failed_alert final : alert { #ifndef TORRENT_NO_DEPRECATE - enum socket_type_t { tcp, tcp_ssl, udp, i2p, socks5, utp_ssl }; + enum socket_type_t : std::uint8_t { tcp, tcp_ssl, udp, i2p, socks5, utp_ssl }; #endif // internal @@ -1321,7 +1327,7 @@ namespace libtorrent { struct TORRENT_EXPORT listen_succeeded_alert final : alert { #ifndef TORRENT_NO_DEPRECATE - enum socket_type_t { tcp, tcp_ssl, udp, i2p, socks5, utp_ssl }; + enum socket_type_t : std::uint8_t { tcp, tcp_ssl, udp, i2p, socks5, utp_ssl }; #endif // internal @@ -1480,11 +1486,6 @@ namespace libtorrent { error_code error; -#ifndef TORRENT_NO_DEPRECATE - // If the error happened to a specific file, ``file`` is the path to it. - std::string TORRENT_DEPRECATED_MEMBER file; -#endif - // If the error happened to a specific file, this returns the path to it. char const* file_path() const; @@ -1493,6 +1494,8 @@ namespace libtorrent { char const* operation; #ifndef TORRENT_NO_DEPRECATE + // If the error happened to a specific file, ``file`` is the path to it. + std::string TORRENT_DEPRECATED_MEMBER file; std::string TORRENT_DEPRECATED_MEMBER msg; #endif private: diff --git a/include/libtorrent/operations.hpp b/include/libtorrent/operations.hpp index 363a52bc8..0dda0ee1d 100644 --- a/include/libtorrent/operations.hpp +++ b/include/libtorrent/operations.hpp @@ -30,78 +30,146 @@ POSSIBILITY OF SUCH DAMAGE. */ - #ifndef TORRENT_OPERATIONS_HPP_INCLUDED #define TORRENT_OPERATIONS_HPP_INCLUDED +#include "libtorrent/config.hpp" +#include + namespace libtorrent { // these constants are used to identify the operation that failed, causing a // peer to disconnect - enum operation_t + enum class operation_t : std::uint8_t { // this is used when the bittorrent logic // determines to disconnect - op_bittorrent = 0, + bittorrent = 0, // a call to iocontrol failed - op_iocontrol, + iocontrol, // a call to getpeername failed (querying the remote IP of a // connection) - op_getpeername, + getpeername, // a call to getname failed (querying the local IP of a // connection) - op_getname, + getname, // an attempt to allocate a receive buffer failed - op_alloc_recvbuf, + alloc_recvbuf, // an attempt to allocate a send buffer failed - op_alloc_sndbuf, + alloc_sndbuf, // writing to a file failed - op_file_write, + file_write, // reading from a file failed - op_file_read, + file_read, // a non-read and non-write file operation failed - op_file, + file, // a socket write operation failed - op_sock_write, + sock_write, // a socket read operation failed - op_sock_read, + sock_read, // a call to open(), to create a socket socket failed - op_sock_open, + sock_open, // a call to bind() on a socket failed - op_sock_bind, + sock_bind, // an attempt to query the number of bytes available to read from a socket // failed - op_available, + available, // a call related to bittorrent protocol encryption failed - op_encryption, + encryption, // an attempt to connect a socket failed - op_connect, + connect, // establishing an SSL connection failed - op_ssl_handshake, + ssl_handshake, // a connection failed to satisfy the bind interface setting - op_get_interface, + get_interface, // the error was unexpected and it is unknown which operation caused it - op_unknown, + unknown, }; +#ifndef TORRENT_NO_DEPRECATE + enum deprecated_operation_t : std::uint8_t + { + // this is used when the bittorrent logic + // determines to disconnect + op_bittorrent TORRENT_DEPRECATED_ENUM = 0, + + // a call to iocontrol failed + op_iocontrol TORRENT_DEPRECATED_ENUM, + + // a call to getpeername failed (querying the remote IP of a + // connection) + op_getpeername TORRENT_DEPRECATED_ENUM, + + // a call to getname failed (querying the local IP of a + // connection) + op_getname TORRENT_DEPRECATED_ENUM, + + // an attempt to allocate a receive buffer failed + op_alloc_recvbuf TORRENT_DEPRECATED_ENUM, + + // an attempt to allocate a send buffer failed + op_alloc_sndbuf TORRENT_DEPRECATED_ENUM, + + // writing to a file failed + op_file_write TORRENT_DEPRECATED_ENUM, + + // reading from a file failed + op_file_read TORRENT_DEPRECATED_ENUM, + + // a non-read and non-write file operation failed + op_file TORRENT_DEPRECATED_ENUM, + + // a socket write operation failed + op_sock_write TORRENT_DEPRECATED_ENUM, + + // a socket read operation failed + op_sock_read TORRENT_DEPRECATED_ENUM, + + // a call to open(), to create a socket socket failed + op_sock_open TORRENT_DEPRECATED_ENUM, + + // a call to bind() on a socket failed + op_sock_bind TORRENT_DEPRECATED_ENUM, + + // an attempt to query the number of bytes available to read from a socket + // failed + op_available TORRENT_DEPRECATED_ENUM, + + // a call related to bittorrent protocol encryption failed + op_encryption TORRENT_DEPRECATED_ENUM, + + // an attempt to connect a socket failed + op_connect TORRENT_DEPRECATED_ENUM, + + // establishing an SSL connection failed + op_ssl_handshake TORRENT_DEPRECATED_ENUM, + + // a connection failed to satisfy the bind interface setting + op_get_interface TORRENT_DEPRECATED_ENUM, + + // the error was unexpected and it is unknown which operation caused it + op_unknown TORRENT_DEPRECATED_ENUM, + }; +#endif + } #endif // TORRENT_OPERATIONS_HPP_INCLUDED diff --git a/src/alert.cpp b/src/alert.cpp index 58ee69827..42ddf8055 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -1036,15 +1036,13 @@ namespace { , char const* op) : torrent_alert(alloc, h) , error(ec) + , operation(op) #ifndef TORRENT_NO_DEPRECATE , file(f) + , msg(convert_from_native(error.message())) #endif - , operation(op) , m_path_idx(alloc.copy_string(f)) { -#ifndef TORRENT_NO_DEPRECATE - msg = convert_from_native(error.message()); -#endif } std::string fastresume_rejected_alert::message() const @@ -1394,29 +1392,7 @@ namespace { } #endif - peer_error_alert::peer_error_alert(aux::stack_allocator& alloc, torrent_handle const& h - , tcp::endpoint const& ep, peer_id const& peer_id, int op - , error_code const& e) - : peer_alert(alloc, h, ep, peer_id) - , operation(op) - , error(e) - { -#ifndef TORRENT_NO_DEPRECATE - msg = convert_from_native(error.message()); -#endif - } - - std::string peer_error_alert::message() const - { - char buf[200]; - std::snprintf(buf, sizeof(buf), "%s peer error [%s] [%s]: %s" - , peer_alert::message().c_str() - , operation_name(operation), error.category().name() - , convert_from_native(error.message()).c_str()); - return buf; - } - - char const* operation_name(int op) + char const* operation_name(operation_t const op) { static char const* names[] = { "bittorrent", @@ -1440,10 +1416,40 @@ namespace { "unknown", }; - if (op < 0 || op >= int(sizeof(names)/sizeof(names[0]))) + int const idx = static_cast(op); + if (idx < 0 || idx >= int(sizeof(names)/sizeof(names[0]))) return "unknown operation"; - return names[op]; + return names[idx]; + } + +#ifndef TORRENT_NO_DEPRECATE + char const* operation_name(int const op) + { + return operation_name(static_cast(op)); + } +#endif + + peer_error_alert::peer_error_alert(aux::stack_allocator& alloc, torrent_handle const& h + , tcp::endpoint const& ep, peer_id const& peer_id, operation_t const op_ + , error_code const& e) + : peer_alert(alloc, h, ep, peer_id) + , op(op_) + , error(e) +#ifndef TORRENT_NO_DEPRECATE + , operation(static_cast(op_)) + , msg(convert_from_native(error.message())) +#endif + {} + + std::string peer_error_alert::message() const + { + char buf[200]; + std::snprintf(buf, sizeof(buf), "%s peer error [%s] [%s]: %s" + , peer_alert::message().c_str() + , operation_name(op), error.category().name() + , convert_from_native(error.message()).c_str()); + return buf; } #ifndef TORRENT_NO_DEPRECATE @@ -1466,18 +1472,18 @@ namespace { peer_disconnected_alert::peer_disconnected_alert(aux::stack_allocator& alloc , torrent_handle const& h, tcp::endpoint const& ep - , peer_id const& peer_id, operation_t op, int type, error_code const& e + , peer_id const& peer_id, operation_t op_, int type, error_code const& e , close_reason_t r) : peer_alert(alloc, h, ep, peer_id) , socket_type(type) - , operation(op) + , op(op_) , error(e) , reason(r) - { #ifndef TORRENT_NO_DEPRECATE - msg = convert_from_native(error.message()); + , operation(static_cast(op)) + , msg(convert_from_native(error.message())) #endif - } + {} std::string peer_disconnected_alert::message() const { @@ -1485,7 +1491,7 @@ namespace { std::snprintf(buf, sizeof(buf), "%s disconnecting (%s) [%s] [%s]: %s (reason: %d)" , peer_alert::message().c_str() , socket_type_str[socket_type] - , operation_name(operation), error.category().name() + , operation_name(op), error.category().name() , convert_from_native(error.message()).c_str() , int(reason)); return buf; diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index 7a666dfc5..8f1718caa 100644 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -213,7 +213,7 @@ namespace { #ifndef TORRENT_DISABLE_LOGGING peer_log(peer_log_alert::info, "ON_CONNECTED", "graceful-paused"); #endif - disconnect(error_code(errors::torrent_paused), op_bittorrent); + disconnect(error_code(errors::torrent_paused), operation_t::bittorrent); return; } @@ -495,7 +495,7 @@ namespace { m_dh_key_exchange.reset(new (std::nothrow) dh_key_exchange); if (!m_dh_key_exchange || !m_dh_key_exchange->good()) { - disconnect(errors::no_memory, op_encryption); + disconnect(errors::no_memory, operation_t::encryption); return; } @@ -855,7 +855,7 @@ namespace { received_bytes(0, received); if (m_recv_buffer.packet_size() != 1) { - disconnect(errors::invalid_choke, op_bittorrent, 2); + disconnect(errors::invalid_choke, operation_t::bittorrent, 2); return; } if (!m_recv_buffer.packet_finished()) return; @@ -905,7 +905,7 @@ namespace { received_bytes(0, received); if (m_recv_buffer.packet_size() != 1) { - disconnect(errors::invalid_unchoke, op_bittorrent, 2); + disconnect(errors::invalid_unchoke, operation_t::bittorrent, 2); return; } if (!m_recv_buffer.packet_finished()) return; @@ -925,7 +925,7 @@ namespace { received_bytes(0, received); if (m_recv_buffer.packet_size() != 1) { - disconnect(errors::invalid_interested, op_bittorrent, 2); + disconnect(errors::invalid_interested, operation_t::bittorrent, 2); return; } if (!m_recv_buffer.packet_finished()) return; @@ -954,7 +954,7 @@ namespace { received_bytes(0, received); if (m_recv_buffer.packet_size() != 1) { - disconnect(errors::invalid_not_interested, op_bittorrent, 2); + disconnect(errors::invalid_not_interested, operation_t::bittorrent, 2); return; } if (!m_recv_buffer.packet_finished()) return; @@ -974,7 +974,7 @@ namespace { received_bytes(0, received); if (m_recv_buffer.packet_size() != 5) { - disconnect(errors::invalid_have, op_bittorrent, 2); + disconnect(errors::invalid_have, operation_t::bittorrent, 2); return; } if (!m_recv_buffer.packet_finished()) return; @@ -1006,7 +1006,7 @@ namespace { if (t->valid_metadata() && m_recv_buffer.packet_size() - 1 != (t->torrent_file().num_pieces() + 7) / 8) { - disconnect(errors::invalid_bitfield_size, op_bittorrent, 2); + disconnect(errors::invalid_bitfield_size, operation_t::bittorrent, 2); return; } @@ -1033,7 +1033,7 @@ namespace { received_bytes(0, received); if (m_recv_buffer.packet_size() != 13) { - disconnect(errors::invalid_request, op_bittorrent, 2); + disconnect(errors::invalid_request, operation_t::bittorrent, 2); return; } if (!m_recv_buffer.packet_finished()) return; @@ -1084,13 +1084,13 @@ namespace { if (list_size > m_recv_buffer.packet_size() - 13) { - disconnect(errors::invalid_hash_list, op_bittorrent, 2); + disconnect(errors::invalid_hash_list, operation_t::bittorrent, 2); return; } if (m_recv_buffer.packet_size() - 13 - list_size > t->block_size()) { - disconnect(errors::packet_too_large, op_bittorrent, 2); + disconnect(errors::packet_too_large, operation_t::bittorrent, 2); return; } } @@ -1101,7 +1101,7 @@ namespace { { if (m_recv_buffer.packet_size() - 9 > t->block_size()) { - disconnect(errors::packet_too_large, op_bittorrent, 2); + disconnect(errors::packet_too_large, operation_t::bittorrent, 2); return; } } @@ -1191,7 +1191,7 @@ namespace { if (bdecode(recv_buffer.begin() + 13, recv_buffer.begin() + 13 + list_size , hash_list, ec) != 0) { - disconnect(errors::invalid_hash_piece, op_bittorrent, 2); + disconnect(errors::invalid_hash_piece, operation_t::bittorrent, 2); return; } @@ -1199,7 +1199,7 @@ namespace { // [ [node-index, hash], [node-index, hash], ... ] if (hash_list.type() != bdecode_node::list_t) { - disconnect(errors::invalid_hash_list, op_bittorrent, 2); + disconnect(errors::invalid_hash_list, operation_t::bittorrent, 2); return; } @@ -1218,7 +1218,7 @@ namespace { } if (!nodes.empty() && !t->add_merkle_nodes(nodes, p.piece)) { - disconnect(errors::invalid_hash_piece, op_bittorrent, 2); + disconnect(errors::invalid_hash_piece, operation_t::bittorrent, 2); return; } } @@ -1238,7 +1238,7 @@ namespace { received_bytes(0, received); if (m_recv_buffer.packet_size() != 13) { - disconnect(errors::invalid_cancel, op_bittorrent, 2); + disconnect(errors::invalid_cancel, operation_t::bittorrent, 2); return; } if (!m_recv_buffer.packet_finished()) return; @@ -1266,7 +1266,7 @@ namespace { received_bytes(0, received); if (m_recv_buffer.packet_size() != 3) { - disconnect(errors::invalid_dht_port, op_bittorrent, 2); + disconnect(errors::invalid_dht_port, operation_t::bittorrent, 2); return; } if (!m_recv_buffer.packet_finished()) return; @@ -1292,7 +1292,7 @@ namespace { received_bytes(0, received); if (!m_supports_fast) { - disconnect(errors::invalid_suggest, op_bittorrent, 2); + disconnect(errors::invalid_suggest, operation_t::bittorrent, 2); return; } @@ -1312,7 +1312,7 @@ namespace { received_bytes(0, received); if (!m_supports_fast) { - disconnect(errors::invalid_have_all, op_bittorrent, 2); + disconnect(errors::invalid_have_all, operation_t::bittorrent, 2); return; } incoming_have_all(); @@ -1325,7 +1325,7 @@ namespace { received_bytes(0, received); if (!m_supports_fast) { - disconnect(errors::invalid_have_none, op_bittorrent, 2); + disconnect(errors::invalid_have_none, operation_t::bittorrent, 2); return; } incoming_have_none(); @@ -1338,7 +1338,7 @@ namespace { received_bytes(0, received); if (!m_supports_fast) { - disconnect(errors::invalid_reject, op_bittorrent, 2); + disconnect(errors::invalid_reject, operation_t::bittorrent, 2); return; } @@ -1362,7 +1362,7 @@ namespace { received_bytes(0, received); if (!m_supports_fast) { - disconnect(errors::invalid_allow_fast, op_bittorrent, 2); + disconnect(errors::invalid_allow_fast, operation_t::bittorrent, 2); return; } @@ -1606,13 +1606,13 @@ namespace { received_bytes(0, received); if (m_recv_buffer.packet_size() < 2) { - disconnect(errors::invalid_extended, op_bittorrent, 2); + disconnect(errors::invalid_extended, operation_t::bittorrent, 2); return; } if (associated_torrent().expired()) { - disconnect(errors::invalid_extended, op_bittorrent, 2); + disconnect(errors::invalid_extended, operation_t::bittorrent, 2); return; } @@ -1710,7 +1710,7 @@ namespace { return; } - disconnect(errors::invalid_message, op_bittorrent, 2); + disconnect(errors::invalid_message, operation_t::bittorrent, 2); return; } @@ -1830,7 +1830,7 @@ namespace { if (t->is_finished() && upload_only() && m_settings.get_bool(settings_pack::close_redundant_connections) && !t->share_mode()) - disconnect(errors::upload_upload_connection, op_bittorrent); + disconnect(errors::upload_upload_connection, operation_t::bittorrent); stats_counters().inc_stats_counter(counters::num_incoming_ext_handshake); } @@ -1899,7 +1899,7 @@ namespace { } #endif received_bytes(0, received); - disconnect(errors::invalid_message, op_bittorrent); + disconnect(errors::invalid_message, operation_t::bittorrent); return m_recv_buffer.packet_finished(); } } @@ -2427,7 +2427,7 @@ namespace { #endif if (bytes_transferred == SIZE_MAX) { - disconnect(errors::parse_failed, op_encryption); + disconnect(errors::parse_failed, operation_t::encryption); return; } received_bytes(0, consumed); @@ -2436,7 +2436,7 @@ namespace { if (!m_recv_buffer.crypto_packet_finished() && m_recv_buffer.crypto_packet_size() > 1025 * 1024) { - disconnect(errors::packet_too_large, op_encryption, 2); + disconnect(errors::packet_too_large, operation_t::encryption, 2); return; } @@ -2551,7 +2551,7 @@ namespace { received_bytes(0, int(bytes_transferred)); if (m_recv_buffer.packet_finished()) - disconnect(errors::sync_hash_not_found, op_bittorrent, 1); + disconnect(errors::sync_hash_not_found, operation_t::bittorrent, 1); return; } @@ -2589,7 +2589,7 @@ namespace { m_sync_bytes_read += bytes_processed; if (m_sync_bytes_read >= 512) { - disconnect(errors::sync_hash_not_found, op_encryption, 1); + disconnect(errors::sync_hash_not_found, operation_t::encryption, 1); return; } @@ -2665,7 +2665,7 @@ namespace { if (!m_rc4.get()) { - disconnect(errors::invalid_info_hash, op_bittorrent, 1); + disconnect(errors::invalid_info_hash, operation_t::bittorrent, 1); return; } @@ -2675,7 +2675,7 @@ namespace { static const char sh_vc[] = {0,0,0,0, 0,0,0,0}; if (!std::equal(sh_vc, sh_vc + 8, recv_buffer.begin() + 20)) { - disconnect(errors::invalid_encryption_constant, op_encryption, 2); + disconnect(errors::invalid_encryption_constant, operation_t::encryption, 2); return; } @@ -2699,7 +2699,7 @@ namespace { { received_bytes(0, int(bytes_transferred)); if (m_recv_buffer.packet_finished()) - disconnect(errors::invalid_encryption_constant, op_encryption, 2); + disconnect(errors::invalid_encryption_constant, operation_t::encryption, 2); return; } @@ -2711,7 +2711,7 @@ namespace { m_sync_vc.reset(new (std::nothrow) char[8]); if (!m_sync_vc) { - disconnect(errors::no_memory, op_encryption); + disconnect(errors::no_memory, operation_t::encryption); return; } std::fill(m_sync_vc.get(), m_sync_vc.get() + 8, char{0}); @@ -2731,7 +2731,7 @@ namespace { if (m_sync_bytes_read >= 512) { - disconnect(errors::invalid_encryption_constant, op_encryption, 2); + disconnect(errors::invalid_encryption_constant, operation_t::encryption, 2); return; } @@ -2821,7 +2821,7 @@ namespace { if (crypto_select == 0) { - disconnect(errors::unsupported_encryption_mode, op_encryption, 1); + disconnect(errors::unsupported_encryption_mode, operation_t::encryption, 1); return; } @@ -2837,7 +2837,7 @@ namespace { if (crypto_field == 0) { // we don't allow any of the offered encryption levels - disconnect(errors::unsupported_encryption_mode_selected, op_encryption, 2); + disconnect(errors::unsupported_encryption_mode_selected, operation_t::encryption, 2); return; } @@ -2850,7 +2850,7 @@ namespace { int len_pad = aux::read_int16(recv_buffer); if (len_pad < 0 || len_pad > 512) { - disconnect(errors::invalid_pad_size, op_encryption, 2); + disconnect(errors::invalid_pad_size, operation_t::encryption, 2); return; } @@ -2897,7 +2897,7 @@ namespace { if (len_ia < 0) { - disconnect(errors::invalid_encrypt_handshake, op_encryption, 2); + disconnect(errors::invalid_encrypt_handshake, operation_t::encryption, 2); return; } @@ -3034,7 +3034,7 @@ namespace { peer_log(peer_log_alert::info, "ENCRYPTION" , "SSL peers are not allowed to use any other encryption"); #endif - disconnect(errors::invalid_info_hash, op_bittorrent, 1); + disconnect(errors::invalid_info_hash, operation_t::bittorrent, 1); return; } #endif // TORRENT_USE_OPENSSL @@ -3043,7 +3043,7 @@ namespace { && m_settings.get_int(settings_pack::in_enc_policy) == settings_pack::pe_disabled) { - disconnect(errors::no_incoming_encrypted, op_bittorrent); + disconnect(errors::no_incoming_encrypted, operation_t::bittorrent); return; } @@ -3053,7 +3053,7 @@ namespace { // handshake by this point if (m_encrypted || is_outgoing()) { - disconnect(errors::invalid_info_hash, op_bittorrent, 1); + disconnect(errors::invalid_info_hash, operation_t::bittorrent, 1); return; } @@ -3065,7 +3065,7 @@ namespace { TORRENT_ASSERT(!m_recv_buffer.packet_finished()); return; #else - disconnect(errors::invalid_info_hash, op_bittorrent, 1); + disconnect(errors::invalid_info_hash, operation_t::bittorrent, 1); return; #endif // TORRENT_DISABLE_ENCRYPTION } @@ -3080,7 +3080,7 @@ namespace { && !m_encrypted && !is_ssl(*get_socket())) { - disconnect(errors::no_incoming_regular, op_bittorrent); + disconnect(errors::no_incoming_regular, operation_t::bittorrent); return; } #endif @@ -3160,7 +3160,7 @@ namespace { #ifndef TORRENT_DISABLE_LOGGING peer_log(peer_log_alert::info, "ERROR", "received invalid info_hash"); #endif - disconnect(errors::invalid_info_hash, op_bittorrent, 1); + disconnect(errors::invalid_info_hash, operation_t::bittorrent, 1); return; } @@ -3236,11 +3236,11 @@ namespace { // if not, we should close the outgoing one. if (pid < m_our_peer_id && is_outgoing()) { - p->disconnect(errors::duplicate_peer_id, op_bittorrent); + p->disconnect(errors::duplicate_peer_id, operation_t::bittorrent); } else { - disconnect(errors::duplicate_peer_id, op_bittorrent); + disconnect(errors::duplicate_peer_id, operation_t::bittorrent); return; } } @@ -3253,7 +3253,7 @@ namespace { if (pid == m_our_peer_id) { if (peer_info_struct()) t->ban_peer(peer_info_struct()); - disconnect(errors::self_connection, op_bittorrent, 1); + disconnect(errors::self_connection, operation_t::bittorrent, 1); return; } @@ -3358,7 +3358,7 @@ namespace { { // packet too large received_bytes(0, int(bytes_transferred)); - disconnect(errors::packet_too_large, op_bittorrent, 2); + disconnect(errors::packet_too_large, operation_t::bittorrent, 2); return; } @@ -3389,7 +3389,7 @@ namespace { if (!t) { received_bytes(0, int(bytes_transferred)); - disconnect(errors::torrent_removed, op_bittorrent, 1); + disconnect(errors::torrent_removed, operation_t::bittorrent, 1); return; } #if TORRENT_USE_ASSERTS diff --git a/src/http_seed_connection.cpp b/src/http_seed_connection.cpp index e7f7fc2e1..f137564fe 100644 --- a/src/http_seed_connection.cpp +++ b/src/http_seed_connection.cpp @@ -83,7 +83,7 @@ namespace libtorrent { { if (is_disconnecting()) return; - if (op == op_connect && m_web && !m_web->endpoints.empty()) + if (op == operation_t::connect && m_web && !m_web->endpoints.empty()) { // we failed to connect to this IP. remove it so that the next attempt // uses the next IP in the list. @@ -231,7 +231,7 @@ namespace libtorrent { if (m_requests.empty()) { received_bytes(0, int(bytes_transferred)); - disconnect(errors::http_error, op_bittorrent, 2); + disconnect(errors::http_error, operation_t::bittorrent, 2); return; } @@ -255,7 +255,7 @@ namespace libtorrent { if (parse_error) { received_bytes(0, int(bytes_transferred)); - disconnect(errors::http_parse_error, op_bittorrent, 2); + disconnect(errors::http_parse_error, operation_t::bittorrent, 2); return; } @@ -287,7 +287,7 @@ namespace libtorrent { , error_msg); } received_bytes(0, int(bytes_transferred)); - disconnect(error_code(m_parser.status_code(), http_category()), op_bittorrent, 1); + disconnect(error_code(m_parser.status_code(), http_category()), operation_t::bittorrent, 1); return; } if (!m_parser.header_finished()) @@ -311,13 +311,13 @@ namespace libtorrent { if (location.empty()) { // we should not try this server again. - t->remove_web_seed_conn(this, errors::missing_location, op_bittorrent, 2); + t->remove_web_seed_conn(this, errors::missing_location, operation_t::bittorrent, 2); return; } // add the redirected url and remove the current one t->add_web_seed(location, web_seed_entry::http_seed); - t->remove_web_seed_conn(this, errors::redirecting, op_bittorrent, 2); + t->remove_web_seed_conn(this, errors::redirecting, operation_t::bittorrent, 2); return; } @@ -336,14 +336,14 @@ namespace libtorrent { { received_bytes(0, int(bytes_transferred)); // we should not try this server again. - t->remove_web_seed_conn(this, errors::no_content_length, op_bittorrent, 2); + t->remove_web_seed_conn(this, errors::no_content_length, operation_t::bittorrent, 2); return; } if (m_response_left != front_request.length) { received_bytes(0, int(bytes_transferred)); // we should not try this server again. - t->remove_web_seed_conn(this, errors::invalid_range, op_bittorrent, 2); + t->remove_web_seed_conn(this, errors::invalid_range, operation_t::bittorrent, 2); return; } m_body_start = m_parser.body_start(); @@ -422,7 +422,7 @@ namespace libtorrent { received_bytes(0, int(bytes_transferred)); // temporarily unavailable, retry later t->retry_web_seed(this, retry_time); - disconnect(error_code(m_parser.status_code(), http_category()), op_bittorrent, 1); + disconnect(error_code(m_parser.status_code(), http_category()), operation_t::bittorrent, 1); return; } diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index f822ae4a5..a9504f6b4 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -203,12 +203,12 @@ namespace libtorrent { peer_log(peer_log_alert::info, "PEER_ERROR" ,"error: %s" , e.what()); #endif - disconnect(error_code(), op_unknown, 2); + disconnect(error_code(), operation_t::unknown, 2); } void peer_connection::on_error(error_code const& ec) { - disconnect(ec, op_unknown, 2); + disconnect(ec, operation_t::unknown, 2); } void peer_connection::increase_est_reciprocation_rate() @@ -269,19 +269,19 @@ namespace libtorrent { m_socket->io_control(ioc, ec); if (ec) { - disconnect(ec, op_iocontrol); + disconnect(ec, operation_t::iocontrol); return; } m_remote = m_socket->remote_endpoint(ec); if (ec) { - disconnect(ec, op_getpeername); + disconnect(ec, operation_t::getpeername); return; } m_local = m_socket->local_endpoint(ec); if (ec) { - disconnect(ec, op_getname); + disconnect(ec, operation_t::getname); return; } if (m_remote.address().is_v4() && m_settings.get_int(settings_pack::peer_tos) != 0) @@ -342,7 +342,7 @@ namespace libtorrent { m_socket->open(m_remote.protocol(), ec); if (ec) { - disconnect(ec, op_sock_open); + disconnect(ec, operation_t::sock_open); return; } @@ -360,7 +360,7 @@ namespace libtorrent { #endif if (ec) { - disconnect(ec, op_sock_bind); + disconnect(ec, operation_t::sock_bind); return; } @@ -1200,7 +1200,7 @@ namespace libtorrent { m_ses.ban_ip(m_remote.address()); } #endif - disconnect(errors::invalid_info_hash, op_bittorrent, 1); + disconnect(errors::invalid_info_hash, operation_t::bittorrent, 1); return; } @@ -1222,7 +1222,7 @@ namespace libtorrent { #ifndef TORRENT_DISABLE_LOGGING peer_log(peer_log_alert::info, "ATTACH", "rejected connection to paused torrent"); #endif - disconnect(errors::torrent_paused, op_bittorrent, 2); + disconnect(errors::torrent_paused, operation_t::bittorrent, 2); return; } @@ -1236,7 +1236,7 @@ namespace libtorrent { #ifndef TORRENT_DISABLE_LOGGING peer_log(peer_log_alert::info, "ATTACH", "rejected regular connection to i2p torrent"); #endif - disconnect(errors::peer_banned, op_bittorrent, 2); + disconnect(errors::peer_banned, operation_t::bittorrent, 2); return; } #endif // TORRENT_USE_I2P @@ -1264,17 +1264,17 @@ namespace libtorrent { { if (other_t->num_peers() <= t->num_peers()) { - disconnect(errors::too_many_connections, op_bittorrent); + disconnect(errors::too_many_connections, operation_t::bittorrent); return; } // find the lowest ranking peer and disconnect that peer_connection* p = other_t->find_lowest_ranking_peer(); - p->disconnect(errors::too_many_connections, op_bittorrent); + p->disconnect(errors::too_many_connections, operation_t::bittorrent); peer_disconnected_other(); } else { - disconnect(errors::too_many_connections, op_bittorrent); + disconnect(errors::too_many_connections, operation_t::bittorrent); return; } } @@ -1834,7 +1834,7 @@ namespace libtorrent { peer_log(peer_log_alert::info, "ERROR", "have-metadata have_piece: %d size: %d" , static_cast(index), m_have_piece.size()); #endif - disconnect(errors::invalid_have, op_bittorrent, 2); + disconnect(errors::invalid_have, operation_t::bittorrent, 2); return; } @@ -1959,7 +1959,7 @@ namespace libtorrent { // if we got an invalid message, abort if (index >= piece_index_t(m_have_piece.size()) || index < piece_index_t(0)) { - disconnect(errors::invalid_dont_have, op_bittorrent, 2); + disconnect(errors::invalid_dont_have, operation_t::bittorrent, 2); return; } @@ -2036,7 +2036,7 @@ namespace libtorrent { , m_have_piece.size()); } #endif - disconnect(errors::invalid_bitfield_size, op_bittorrent, 2); + disconnect(errors::invalid_bitfield_size, operation_t::bittorrent, 2); return; } @@ -2151,7 +2151,7 @@ namespace libtorrent { #ifndef TORRENT_DISABLE_LOGGING peer_log(peer_log_alert::info, "UPLOAD_ONLY", "the peer is upload-only and our torrent is also upload-only"); #endif - disconnect(errors::upload_upload_connection, op_bittorrent); + disconnect(errors::upload_upload_connection, operation_t::bittorrent); return true; } @@ -2164,7 +2164,7 @@ namespace libtorrent { #ifndef TORRENT_DISABLE_LOGGING peer_log(peer_log_alert::info, "UPLOAD_ONLY", "the peer is upload-only and we're not interested in it"); #endif - disconnect(errors::uninteresting_upload_peer, op_bittorrent); + disconnect(errors::uninteresting_upload_peer, operation_t::bittorrent); return true; } @@ -2377,7 +2377,7 @@ namespace libtorrent { if (m_num_invalid_requests > 300 && !m_peer_choked && can_disconnect(errors::too_many_requests_when_choked)) { - disconnect(errors::too_many_requests_when_choked, op_bittorrent, 2); + disconnect(errors::too_many_requests_when_choked, operation_t::bittorrent, 2); return; } #ifndef TORRENT_DISABLE_LOGGING @@ -2399,7 +2399,7 @@ namespace libtorrent { if (m_choked && fast_idx != -1 && m_accept_fast_piece_cnt[fast_idx] >= 3 * blocks_per_piece && can_disconnect(errors::too_many_requests_when_choked)) { - disconnect(errors::too_many_requests_when_choked, op_bittorrent, 2); + disconnect(errors::too_many_requests_when_choked, operation_t::bittorrent, 2); return; } @@ -2418,7 +2418,7 @@ namespace libtorrent { if (aux::time_now() - seconds(2) > m_last_choke && can_disconnect(errors::too_many_requests_when_choked)) { - disconnect(errors::too_many_requests_when_choked, op_bittorrent, 2); + disconnect(errors::too_many_requests_when_choked, operation_t::bittorrent, 2); return; } } @@ -2507,7 +2507,7 @@ namespace libtorrent { peer_log(peer_log_alert::info, "INVALID_PIECE", "piece: %d s: %d l: %d" , static_cast(r.piece), r.start, r.length); #endif - disconnect(errors::invalid_piece, op_bittorrent, 2); + disconnect(errors::invalid_piece, operation_t::bittorrent, 2); return; } @@ -2662,7 +2662,7 @@ namespace libtorrent { if (t->alerts().should_post()) { t->alerts().emplace_alert(t->get_handle(), m_remote - , m_peer_id, op_bittorrent, errors::peer_sent_empty_piece); + , m_peer_id, operation_t::bittorrent, errors::peer_sent_empty_piece); } // This is used as a reject-request by bitcomet incoming_reject_request(p); @@ -2950,7 +2950,7 @@ namespace libtorrent { #ifndef TORRENT_DISABLE_LOGGING peer_log(peer_log_alert::info, "GRACEFUL_PAUSE", "NO MORE DOWNLOAD"); #endif - disconnect(errors::torrent_paused, op_bittorrent); + disconnect(errors::torrent_paused, operation_t::bittorrent); } void peer_connection::on_disk_write_complete(storage_error const& error @@ -2983,7 +2983,7 @@ namespace libtorrent { if (!t) { - disconnect(error.ec, op_file_write); + disconnect(error.ec, operation_t::file_write); return; } @@ -4020,7 +4020,7 @@ namespace libtorrent { m_peer_info->supports_utp = false; // reconnect immediately using TCP fast_reconnect(true); - disconnect(e, op_connect, 0); + disconnect(e, operation_t::connect, 0); if (t && m_peer_info) { std::weak_ptr weak_t = t; @@ -4060,7 +4060,7 @@ namespace libtorrent { } #endif - disconnect(e, op_connect, 1); + disconnect(e, operation_t::connect, 1); return; } @@ -4098,15 +4098,15 @@ namespace libtorrent { { case 0: peer_log(peer_log_alert::info, "CONNECTION_CLOSED", "op: %d error: %s" - , op, ec.message().c_str()); + , static_cast(op), ec.message().c_str()); break; case 1: peer_log(peer_log_alert::info, "CONNECTION_FAILED", "op: %d error: %s" - , op, ec.message().c_str()); + , static_cast(op), ec.message().c_str()); break; case 2: peer_log(peer_log_alert::info, "PEER_ERROR" ,"op: %d error: %s" - , op, ec.message().c_str()); + , static_cast(op), ec.message().c_str()); break; } @@ -4208,7 +4208,7 @@ namespace libtorrent { else m_counters.inc_stats_counter(counters::error_incoming_peers); #if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) - if (type() == connection_type::bittorrent && op != op_connect) + if (type() == connection_type::bittorrent && op != operation_t::connect) { bt_peer_connection* bt = static_cast(this); if (bt->supports_encryption()) m_counters.inc_stats_counter( @@ -4677,7 +4677,7 @@ namespace libtorrent { if (t) t->dec_num_connecting(m_peer_info); m_connecting = false; } - disconnect(errors::torrent_aborted, op_bittorrent); + disconnect(errors::torrent_aborted, operation_t::bittorrent); return; } @@ -4769,7 +4769,7 @@ namespace libtorrent { peer_log(peer_log_alert::info, "LAST_ACTIVITY", "%d seconds ago" , int(total_seconds(d))); #endif - disconnect(errors::timed_out_inactivity, op_bittorrent); + disconnect(errors::timed_out_inactivity, operation_t::bittorrent); return; } @@ -4787,7 +4787,7 @@ namespace libtorrent { peer_log(peer_log_alert::info, "NO_HANDSHAKE", "waited %d seconds" , int(total_seconds(d))); #endif - disconnect(errors::timed_out_no_handshake, op_bittorrent); + disconnect(errors::timed_out_no_handshake, operation_t::bittorrent); return; } @@ -4812,7 +4812,7 @@ namespace libtorrent { peer_log(peer_log_alert::info, "NO_REQUEST", "waited %d seconds" , int(total_seconds(d))); #endif - disconnect(errors::timed_out_no_request, op_bittorrent); + disconnect(errors::timed_out_no_request, operation_t::bittorrent); return; } @@ -4845,7 +4845,7 @@ namespace libtorrent { , int(total_seconds(d1)), int(total_seconds(d2))); } #endif - disconnect(errors::timed_out_no_interest, op_bittorrent); + disconnect(errors::timed_out_no_interest, operation_t::bittorrent); return; } @@ -5257,7 +5257,7 @@ namespace libtorrent { { if (!t) { - disconnect(error.ec, op_file_read); + disconnect(error.ec, operation_t::file_read); return; } @@ -5270,7 +5270,7 @@ namespace libtorrent { , error.operation_str(), t->get_handle()); ++m_disk_read_failures; - if (m_disk_read_failures > 100) disconnect(error.ec, op_file_read); + if (m_disk_read_failures > 100) disconnect(error.ec, operation_t::file_read); return; } @@ -5292,7 +5292,7 @@ namespace libtorrent { if (!t) { - disconnect(error.ec, op_file_read); + disconnect(error.ec, operation_t::file_read); return; } @@ -5777,7 +5777,7 @@ namespace libtorrent { } #endif on_receive(error, bytes_transferred); - disconnect(error, op_sock_read); + disconnect(error, operation_t::sock_read); return; } @@ -5818,7 +5818,7 @@ namespace libtorrent { int buffer_size = int(m_socket->available(ec)); if (ec) { - disconnect(ec, op_available); + disconnect(ec, operation_t::available); return; } @@ -5855,7 +5855,7 @@ namespace libtorrent { } else if (ec) { - disconnect(ec, op_sock_read); + disconnect(ec, operation_t::sock_read); return; } else @@ -5997,7 +5997,7 @@ namespace libtorrent { m_local = m_socket->local_endpoint(ec); if (ec) { - disconnect(ec, op_getname); + disconnect(ec, operation_t::getname); return; } @@ -6010,12 +6010,12 @@ namespace libtorrent { { if (ec) { - disconnect(ec, op_get_interface); + disconnect(ec, operation_t::get_interface); return; } disconnect(error_code( boost::system::errc::no_such_device, generic_category()) - , op_connect); + , operation_t::connect); return; } } @@ -6048,7 +6048,7 @@ namespace libtorrent { m_socket->io_control(ioc, ec); if (ec) { - disconnect(ec, op_iocontrol); + disconnect(ec, operation_t::iocontrol); return; } @@ -6057,7 +6057,7 @@ namespace libtorrent { // if the remote endpoint is the same as the local endpoint, we're connected // to ourselves if (m_peer_info && t) t->ban_peer(m_peer_info); - disconnect(errors::self_connection, op_bittorrent, 1); + disconnect(errors::self_connection, operation_t::bittorrent, 1); return; } @@ -6175,7 +6175,7 @@ namespace libtorrent { , "%s in peer_connection::on_send_data", error.message().c_str()); } #endif - disconnect(error, op_sock_write); + disconnect(error, operation_t::sock_write); return; } if (m_disconnecting) diff --git a/src/peer_list.cpp b/src/peer_list.cpp index d2be86ae0..1a048e6c9 100644 --- a/src/peer_list.cpp +++ b/src/peer_list.cpp @@ -170,7 +170,7 @@ namespace libtorrent { banned.push_back(p->remote().address()); p->disconnect(errors::banned_by_ip_filter - , op_bittorrent); + , operation_t::bittorrent); // what *i refers to has changed, i.e. cur was deleted if (m_peers.size() < count) @@ -230,7 +230,7 @@ namespace libtorrent { banned.push_back(p->remote().address()); - p->disconnect(errors::banned_by_port_filter, op_bittorrent); + p->disconnect(errors::banned_by_port_filter, operation_t::bittorrent); // what *i refers to has changed, i.e. cur was deleted if (int(m_peers.size()) < count) { @@ -619,7 +619,7 @@ namespace libtorrent { #endif if (i->banned) { - c.disconnect(errors::peer_banned, op_bittorrent); + c.disconnect(errors::peer_banned, operation_t::bittorrent); return false; } @@ -631,9 +631,9 @@ namespace libtorrent { if (self_connection) { - c.disconnect(errors::self_connection, op_bittorrent, 1); + c.disconnect(errors::self_connection, operation_t::bittorrent, 1); TORRENT_ASSERT(i->connection->peer_info_struct() == i); - i->connection->disconnect(errors::self_connection, op_bittorrent, 1); + i->connection->disconnect(errors::self_connection, operation_t::bittorrent, 1); TORRENT_ASSERT(i->connection == nullptr); return false; } @@ -645,7 +645,7 @@ namespace libtorrent { { // if the other end connected to us both times, just drop // the second one. Or if we made both connections. - c.disconnect(errors::duplicate_peer_id, op_bittorrent); + c.disconnect(errors::duplicate_peer_id, operation_t::bittorrent); return false; } else @@ -683,12 +683,12 @@ namespace libtorrent { // we should keep our outgoing connection if (!outgoing1) { - c.disconnect(errors::duplicate_peer_id, op_bittorrent); + c.disconnect(errors::duplicate_peer_id, operation_t::bittorrent); return false; } TORRENT_ASSERT(m_locked_peer == nullptr); m_locked_peer = i; - i->connection->disconnect(errors::duplicate_peer_id, op_bittorrent); + i->connection->disconnect(errors::duplicate_peer_id, operation_t::bittorrent); m_locked_peer = nullptr; } else @@ -705,12 +705,12 @@ namespace libtorrent { // they should keep their outgoing connection if (outgoing1) { - c.disconnect(errors::duplicate_peer_id, op_bittorrent); + c.disconnect(errors::duplicate_peer_id, operation_t::bittorrent); return false; } TORRENT_ASSERT(m_locked_peer == nullptr); m_locked_peer = i; - i->connection->disconnect(errors::duplicate_peer_id, op_bittorrent); + i->connection->disconnect(errors::duplicate_peer_id, operation_t::bittorrent); m_locked_peer = nullptr; } } @@ -731,7 +731,7 @@ namespace libtorrent { erase_peers(state, force_erase); if (int(m_peers.size()) >= state->max_peerlist_size) { - c.disconnect(errors::too_many_connections, op_bittorrent); + c.disconnect(errors::too_many_connections, operation_t::bittorrent); return false; } // restore it @@ -827,7 +827,7 @@ namespace libtorrent { // we need to make sure we don't let it do that, locking i TORRENT_ASSERT(m_locked_peer == nullptr); m_locked_peer = p; - p->connection->disconnect(errors::duplicate_peer_id, op_bittorrent); + p->connection->disconnect(errors::duplicate_peer_id, operation_t::bittorrent); m_locked_peer = nullptr; erase_peer(p, state); return false; diff --git a/src/session_impl.cpp b/src/session_impl.cpp index eea9131cb..c37ac50d5 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -1004,7 +1004,7 @@ namespace aux { // can't iterate over it here auto conns = m_connections; for (auto const& p : conns) - p->disconnect(errors::stopping_torrent, op_bittorrent); + p->disconnect(errors::stopping_torrent, operation_t::bittorrent); // close the listen sockets for (auto const& l : m_listen_sockets) @@ -2735,7 +2735,7 @@ namespace { if (m_alerts.should_post()) { m_alerts.emplace_alert(torrent_handle(), endp - , peer_id(), op_ssl_handshake, ec); + , peer_id(), operation_t::ssl_handshake, ec); } return; } @@ -2911,7 +2911,7 @@ namespace { if (m_alerts.should_post()) { m_alerts.emplace_alert(torrent_handle(), endp, peer_id() - , op_bittorrent, s->type() + , operation_t::bittorrent, s->type() , error_code(errors::too_many_connections) , close_reason_t::none); } @@ -3381,7 +3381,7 @@ namespace { timeout *= is_i2p(*p->get_socket()) ? 4 : 1; #endif if (m_last_tick - p->connected_time () > seconds(timeout)) - p->disconnect(errors::timed_out, op_bittorrent); + p->disconnect(errors::timed_out, operation_t::bittorrent); } // -------------------------------------------------------------- diff --git a/src/smart_ban.cpp b/src/smart_ban.cpp index 32b26f5ba..cb99c916f 100644 --- a/src/smart_ban.cpp +++ b/src/smart_ban.cpp @@ -226,7 +226,7 @@ namespace { #endif m_torrent.ban_peer(p); if (p->connection) p->connection->disconnect( - errors::peer_banned, op_bittorrent); + errors::peer_banned, operation_t::bittorrent); } // we already have this exact entry in the map // we don't have to insert it @@ -302,7 +302,7 @@ namespace { #endif m_torrent.ban_peer(p); if (p->connection) p->connection->disconnect( - errors::peer_banned, op_bittorrent); + errors::peer_banned, operation_t::bittorrent); } torrent& m_torrent; diff --git a/src/torrent.cpp b/src/torrent.cpp index 01d924825..3a9582b42 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -1038,7 +1038,7 @@ namespace libtorrent { if (alerts().should_post()) alerts().emplace_alert(error.ec , resolve_filename(error.file()), error.operation_str(), get_handle()); - if (c) c->disconnect(errors::no_memory, op_file); + if (c) c->disconnect(errors::no_memory, operation_t::file); return; } @@ -2132,7 +2132,7 @@ namespace libtorrent { clear_error(); - disconnect_all(errors::stopping_torrent, op_bittorrent); + disconnect_all(errors::stopping_torrent, operation_t::bittorrent); stop_announcing(); // we're checking everything anyway, no point in assuming we are a seed @@ -4113,7 +4113,7 @@ namespace libtorrent { } peer->peer_log(peer_log_alert::info, "BANNING_PEER", "Too many corrupt pieces"); #endif - peer->disconnect(errors::too_many_corrupt_pieces, op_bittorrent); + peer->disconnect(errors::too_many_corrupt_pieces, operation_t::bittorrent); } } } @@ -4313,7 +4313,7 @@ namespace libtorrent { // disconnect all peers and close all // files belonging to the torrents - disconnect_all(errors::torrent_aborted, op_bittorrent); + disconnect_all(errors::torrent_aborted, operation_t::bittorrent); // make sure to destruct the peers immediately on_remove_peers(); @@ -5487,7 +5487,7 @@ namespace libtorrent { // disconnect it and clear its reference to the peer_info object // that's part of the web_seed_t we're about to remove TORRENT_ASSERT(peer->m_in_use == 1337); - peer->disconnect(boost::asio::error::operation_aborted, op_bittorrent); + peer->disconnect(boost::asio::error::operation_aborted, operation_t::bittorrent); peer->set_peer_info(nullptr); } if (has_picker()) picker().clear_peer(&web->peer_info); @@ -6553,7 +6553,7 @@ namespace libtorrent { TORRENT_CATCH (std::exception const&) { TORRENT_ASSERT(m_iterating_connections == 0); - c->disconnect(errors::no_error, op_bittorrent, 1); + c->disconnect(errors::no_error, operation_t::bittorrent, 1); return false; } @@ -6675,14 +6675,14 @@ namespace libtorrent { if (ssl_conn == nullptr) { // don't allow non SSL peers on SSL torrents - p->disconnect(errors::requires_ssl_connection, op_bittorrent); + p->disconnect(errors::requires_ssl_connection, operation_t::bittorrent); return false; } if (!m_ssl_ctx) { // we don't have a valid cert, don't accept any connection! - p->disconnect(errors::invalid_ssl_cert, op_ssl_handshake); + p->disconnect(errors::invalid_ssl_cert, operation_t::ssl_handshake); return false; } @@ -6693,7 +6693,7 @@ namespace libtorrent { // connected to one torrent, and the BitTorrent protocol // to a different one. This is probably an attempt to circumvent // access control. Don't allow it. - p->disconnect(errors::invalid_ssl_cert, op_bittorrent); + p->disconnect(errors::invalid_ssl_cert, operation_t::bittorrent); return false; } } @@ -6705,7 +6705,7 @@ namespace libtorrent { { // Don't accidentally allow seeding of SSL torrents, just // because libtorrent wasn't built with SSL support - p->disconnect(errors::requires_ssl_connection, op_ssl_handshake); + p->disconnect(errors::requires_ssl_connection, operation_t::ssl_handshake); return false; } #endif // TORRENT_USE_OPENSSL @@ -6722,7 +6722,7 @@ namespace libtorrent { if (m_ses.alerts().should_post()) m_ses.alerts().emplace_alert(get_handle() , p->remote(), peer_blocked_alert::ip_filter); - p->disconnect(errors::banned_by_ip_filter, op_bittorrent); + p->disconnect(errors::banned_by_ip_filter, operation_t::bittorrent); return false; } @@ -6730,19 +6730,19 @@ namespace libtorrent { || m_state == torrent_status::checking_resume_data) && valid_metadata()) { - p->disconnect(errors::torrent_not_ready, op_bittorrent); + p->disconnect(errors::torrent_not_ready, operation_t::bittorrent); return false; } if (!m_ses.has_connection(p)) { - p->disconnect(errors::peer_not_constructed, op_bittorrent); + p->disconnect(errors::peer_not_constructed, operation_t::bittorrent); return false; } if (m_ses.is_aborted()) { - p->disconnect(errors::session_closing, op_bittorrent); + p->disconnect(errors::session_closing, operation_t::bittorrent); return false; } @@ -6778,10 +6778,10 @@ namespace libtorrent { if (i == end() || !(*i)->is_connecting() || (*i)->is_disconnecting()) { // this seems odd, but we might as well handle it - p->disconnect(errors::too_many_connections, op_bittorrent); + p->disconnect(errors::too_many_connections, operation_t::bittorrent); return false; } - (*i)->disconnect(errors::too_many_connections, op_bittorrent); + (*i)->disconnect(errors::too_many_connections, operation_t::bittorrent); // if this peer was let in via connections slack, // it has done its duty of causing the disconnection @@ -6817,7 +6817,7 @@ namespace libtorrent { , m_max_connections); } #endif - p->disconnect(errors::too_many_connections, op_bittorrent); + p->disconnect(errors::too_many_connections, operation_t::bittorrent); return false; } peers_erased(st.erased); @@ -6869,7 +6869,7 @@ namespace libtorrent { , m_max_connections); } #endif - peer->disconnect(errors::too_many_connections, op_bittorrent); + peer->disconnect(errors::too_many_connections, operation_t::bittorrent); p->peer_disconnected_other(); } else @@ -6884,7 +6884,7 @@ namespace libtorrent { , m_max_connections); } #endif - p->disconnect(errors::too_many_connections, op_bittorrent); + p->disconnect(errors::too_many_connections, operation_t::bittorrent); // we have to do this here because from the peer's point of view // it wasn't really attached to the torrent, but we do need // to let peer_list know we're removing it @@ -7152,7 +7152,7 @@ namespace libtorrent { for (auto p : range(to_disconnect.begin(), end)) { TORRENT_ASSERT(p->associated_torrent().lock().get() == this); - p->disconnect(ec, op_bittorrent); + p->disconnect(ec, operation_t::bittorrent); } return static_cast(end - to_disconnect.begin()); } @@ -7204,7 +7204,7 @@ namespace libtorrent { } std::for_each(seeds.begin(), seeds.end() , std::bind(&peer_connection::disconnect, _1, errors::torrent_finished - , op_bittorrent, 0)); + , operation_t::bittorrent, 0)); } if (m_abort) return; @@ -8029,7 +8029,7 @@ namespace libtorrent { log_to_all_peers("deleting files"); #endif - disconnect_all(errors::torrent_removed, op_bittorrent); + disconnect_all(errors::torrent_removed, operation_t::bittorrent); stop_announcing(); // storage may be nullptr during shutdown @@ -8414,7 +8414,7 @@ namespace libtorrent { if (alerts().should_post()) alerts().emplace_alert(get_handle()); } - disconnect_all(errors::torrent_paused, op_bittorrent); + disconnect_all(errors::torrent_paused, operation_t::bittorrent); return; } @@ -8434,7 +8434,7 @@ namespace libtorrent { alerts().emplace_alert(get_handle()); } - disconnect_all(errors::torrent_paused, op_bittorrent); + disconnect_all(errors::torrent_paused, operation_t::bittorrent); } else { @@ -8466,7 +8466,7 @@ namespace libtorrent { #ifndef TORRENT_DISABLE_LOGGING p->peer_log(peer_log_alert::info, "CLOSING_CONNECTION", "torrent_paused"); #endif - p->disconnect(errors::torrent_paused, op_bittorrent); + p->disconnect(errors::torrent_paused, operation_t::bittorrent); } } @@ -9149,7 +9149,7 @@ namespace libtorrent { TORRENT_ASSERT(to_disconnect <= seeds.end_index()); for (int i = 0; i < to_disconnect; ++i) seeds[i]->disconnect(errors::upload_upload_connection - , op_bittorrent); + , operation_t::bittorrent); } if (num_downloaders == 0) return; diff --git a/src/ut_metadata.cpp b/src/ut_metadata.cpp index 1894bf999..8a071b0a9 100644 --- a/src/ut_metadata.cpp +++ b/src/ut_metadata.cpp @@ -304,7 +304,7 @@ namespace libtorrent {namespace { m_pc.peer_log(peer_log_alert::incoming_message, "UT_METADATA" , "packet too big %d", length); #endif - m_pc.disconnect(errors::invalid_metadata_message, op_bittorrent, 2); + m_pc.disconnect(errors::invalid_metadata_message, operation_t::bittorrent, 2); return true; } @@ -318,7 +318,7 @@ namespace libtorrent {namespace { m_pc.peer_log(peer_log_alert::incoming_message, "UT_METADATA" , "not a dictionary"); #endif - m_pc.disconnect(errors::invalid_metadata_message, op_bittorrent, 2); + m_pc.disconnect(errors::invalid_metadata_message, operation_t::bittorrent, 2); return true; } @@ -331,7 +331,7 @@ namespace libtorrent {namespace { m_pc.peer_log(peer_log_alert::incoming_message, "UT_METADATA" , "missing or invalid keys"); #endif - m_pc.disconnect(errors::invalid_metadata_message, op_bittorrent, 2); + m_pc.disconnect(errors::invalid_metadata_message, operation_t::bittorrent, 2); return true; } int type = int(type_ent->integer()); diff --git a/src/ut_pex.cpp b/src/ut_pex.cpp index 245daf592..713f95434 100644 --- a/src/ut_pex.cpp +++ b/src/ut_pex.cpp @@ -271,7 +271,7 @@ namespace libtorrent {namespace { if (length > 500 * 1024) { - m_pc.disconnect(errors::pex_message_too_large, op_bittorrent, 2); + m_pc.disconnect(errors::pex_message_too_large, operation_t::bittorrent, 2); return true; } @@ -282,7 +282,7 @@ namespace libtorrent {namespace { { // this client appears to be trying to flood us // with pex messages. Don't allow that. - m_pc.disconnect(errors::too_frequent_pex, op_bittorrent); + m_pc.disconnect(errors::too_frequent_pex, operation_t::bittorrent); return true; } @@ -296,7 +296,7 @@ namespace libtorrent {namespace { int const ret = bdecode(body.begin(), body.end(), pex_msg, ec); if (ret != 0 || pex_msg.type() != bdecode_node::dict_t) { - m_pc.disconnect(errors::invalid_pex_message, op_bittorrent, 2); + m_pc.disconnect(errors::invalid_pex_message, operation_t::bittorrent, 2); return true; } diff --git a/src/web_peer_connection.cpp b/src/web_peer_connection.cpp index df67247c2..f4bfec9b8 100644 --- a/src/web_peer_connection.cpp +++ b/src/web_peer_connection.cpp @@ -181,7 +181,7 @@ void web_peer_connection::disconnect(error_code const& ec { if (is_disconnecting()) return; - if (op == op_sock_write && ec == boost::system::errc::broken_pipe) + if (op == operation_t::sock_write && ec == boost::system::errc::broken_pipe) { #ifndef TORRENT_DISABLE_LOGGING // a write operation failed with broken-pipe. This typically happens @@ -204,7 +204,7 @@ void web_peer_connection::disconnect(error_code const& ec return; } - if (op == op_connect && m_web && !m_web->endpoints.empty()) + if (op == operation_t::connect && m_web && !m_web->endpoints.empty()) { // we failed to connect to this IP. remove it so that the next attempt // uses the next IP in the list. @@ -590,7 +590,7 @@ void web_peer_connection::handle_error(int const bytes_left) , error_msg); } received_bytes(0, bytes_left); - disconnect(error_code(m_parser.status_code(), http_category()), op_bittorrent, 1); + disconnect(error_code(m_parser.status_code(), http_category()), operation_t::bittorrent, 1); return; } @@ -607,7 +607,7 @@ void web_peer_connection::handle_redirect(int const bytes_left) if (location.empty()) { // we should not try this server again. - t->remove_web_seed_conn(this, errors::missing_location, op_bittorrent, 2); + t->remove_web_seed_conn(this, errors::missing_location, operation_t::bittorrent, 2); m_web = nullptr; TORRENT_ASSERT(is_disconnecting()); return; @@ -637,7 +637,7 @@ void web_peer_connection::handle_redirect(int const bytes_left) if (ec) { // we should not try this server again. - disconnect(errors::missing_location, op_bittorrent, 1); + disconnect(errors::missing_location, operation_t::bittorrent, 1); return; } @@ -680,7 +680,7 @@ void web_peer_connection::handle_redirect(int const bytes_left) if (m_web->have_files.get_bit(file_index) == true) { m_web->have_files.clear_bit(file_index); - disconnect(errors::redirecting, op_bittorrent, 2); + disconnect(errors::redirecting, operation_t::bittorrent, 2); } } else @@ -694,7 +694,7 @@ void web_peer_connection::handle_redirect(int const bytes_left) // this web seed doesn't have any files. Don't try to request from it // again this session m_web->have_files.resize(t->torrent_file().num_files(), false); - disconnect(errors::redirecting, op_bittorrent, 2); + disconnect(errors::redirecting, operation_t::bittorrent, 2); m_web = nullptr; TORRENT_ASSERT(is_disconnecting()); } @@ -750,7 +750,7 @@ void web_peer_connection::on_receive(error_code const& error , "%*s", int(recv_buffer.size()), recv_buffer.data()); } #endif - disconnect(errors::http_parse_error, op_bittorrent, 2); + disconnect(errors::http_parse_error, operation_t::bittorrent, 2); return; } @@ -842,7 +842,7 @@ void web_peer_connection::on_receive(error_code const& error { received_bytes(0, int(recv_buffer.size())); // we should not try this server again. - t->remove_web_seed_conn(this, ec, op_bittorrent, 2); + t->remove_web_seed_conn(this, ec, operation_t::bittorrent, 2); m_web = nullptr; TORRENT_ASSERT(is_disconnecting()); return; @@ -865,7 +865,7 @@ void web_peer_connection::on_receive(error_code const& error , static_cast(file_req.file_index), file_req.start, file_req.start + file_req.length - 1); } #endif - disconnect(errors::invalid_range, op_bittorrent, 2); + disconnect(errors::invalid_range, operation_t::bittorrent, 2); return; } @@ -895,7 +895,7 @@ void web_peer_connection::on_receive(error_code const& error , "received body: %d request size: %d" , m_received_body, file_req.length); #endif - disconnect(errors::invalid_range, op_bittorrent, 2); + disconnect(errors::invalid_range, operation_t::bittorrent, 2); return; } incoming_payload(recv_buffer.data(), copy_size); @@ -957,7 +957,7 @@ void web_peer_connection::on_receive(error_code const& error , "received body: %d request size: %d" , m_received_body, file_req.length); #endif - disconnect(errors::invalid_range, op_bittorrent, 2); + disconnect(errors::invalid_range, operation_t::bittorrent, 2); return; } // we just completed an HTTP file request. pop it from m_file_requests