diff --git a/bindings/python/src/alert.cpp b/bindings/python/src/alert.cpp index 826b86152..994eb880d 100644 --- a/bindings/python/src/alert.cpp +++ b/bindings/python/src/alert.cpp @@ -576,32 +576,34 @@ void bind_alert() class_, noncopyable>( "portmap_error_alert", no_init) .def_readonly("mapping", &portmap_error_alert::mapping) - .def_readonly("map_type", &portmap_error_alert::map_type) .def_readonly("error", &portmap_error_alert::error) + .def_readonly("map_transport", &portmap_error_alert::map_transport) #ifndef TORRENT_NO_DEPRECATE + .def_readonly("map_type", &portmap_error_alert::map_type) .def_readonly("type", &portmap_error_alert::map_type) .def_readonly("msg", &portmap_error_alert::msg) #endif ; - class_, noncopyable>( - "portmap_alert", no_init) + class_, noncopyable>("portmap_alert", no_init) .def_readonly("mapping", &portmap_alert::mapping) .def_readonly("external_port", &portmap_alert::external_port) + .def_readonly("map_protocol", &portmap_alert::map_protocol) + .def_readonly("map_transport", &portmap_alert::map_transport) #ifndef TORRENT_NO_DEPRECATE .def_readonly("type", &portmap_alert::map_type) -#endif .def_readonly("map_type", &portmap_alert::map_type) +#endif ; #ifndef TORRENT_DISABLE_LOGGING - class_, noncopyable>( - "portmap_log_alert", no_init) - .def_readonly("map_type", &portmap_log_alert::map_type) + class_, noncopyable>("portmap_log_alert", no_init) + .def_readonly("map_transport", &portmap_log_alert::map_transport) #ifndef TORRENT_NO_DEPRECATE .def_readonly("type", &portmap_log_alert::map_type) .def_readonly("msg", &portmap_log_alert::msg) + .def_readonly("map_type", &portmap_log_alert::map_type) #endif ; diff --git a/bindings/python/src/session.cpp b/bindings/python/src/session.cpp index 2aa239631..c600de714 100644 --- a/bindings/python/src/session.cpp +++ b/bindings/python/src/session.cpp @@ -51,6 +51,8 @@ using namespace lt; namespace { #ifndef TORRENT_NO_DEPRECATE + struct dummy {}; + void listen_on(lt::session& s, int min_, int max_, char const* interface, int flags) { allow_threading_guard guard; @@ -794,7 +796,19 @@ void bind_session() #endif ; - class_("session", no_init) + enum_("portmap_protocol") + .value("none", lt::portmap_protocol::none) + .value("udp", lt::portmap_protocol::udp) + .value("tcp", lt::portmap_protocol::tcp) + ; + + enum_("portmap_transport") + .value("natpmp", lt::portmap_transport::natpmp) + .value("upnp", lt::portmap_transport::upnp) + ; + + { + scope s = class_("session", no_init) .def("__init__", boost::python::make_constructor(&make_session , default_call_policies() , (arg("settings") @@ -932,10 +946,17 @@ void bind_session() #endif // TORRENT_NO_DEPRECATE ; - enum_("protocol_type") - .value("udp", lt::session::udp) - .value("tcp", lt::session::tcp) - ; + s.attr("tcp") = lt::portmap_protocol::tcp; + s.attr("udp") = lt::portmap_protocol::udp; + } + +#ifndef TORRENT_NO_DEPRECATE + { + scope s = class_("protocol_type"); + s.attr("udp") = lt::portmap_protocol::udp; + s.attr("tcp") = lt::portmap_protocol::tcp; + } +#endif { scope s = class_("save_state_flags_t"); diff --git a/include/libtorrent/Makefile.am b/include/libtorrent/Makefile.am index c6504cbab..1430fbe67 100644 --- a/include/libtorrent/Makefile.am +++ b/include/libtorrent/Makefile.am @@ -101,6 +101,7 @@ nobase_include_HEADERS = \ piece_picker.hpp \ platform_util.hpp \ peer_list.hpp \ + portmap.hpp \ proxy_base.hpp \ puff.hpp \ random.hpp \ diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index 9332caf93..734ba8ae4 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -53,6 +53,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/string_view.hpp" #include "libtorrent/stack_allocator.hpp" #include "libtorrent/aux_/noexcept_movable.hpp" +#include "libtorrent/portmap.hpp" // for portmap_transport #include "libtorrent/aux_/disable_warnings_push.hpp" #include @@ -1391,7 +1392,8 @@ namespace libtorrent { struct TORRENT_EXPORT portmap_error_alert final : alert { // internal - portmap_error_alert(aux::stack_allocator& alloc, int i, int t + portmap_error_alert(aux::stack_allocator& alloc, int i + , portmap_transport t , error_code const& e); TORRENT_DEFINE_ALERT(portmap_error_alert, 50) @@ -1404,12 +1406,15 @@ namespace libtorrent { // the index returned from add_mapping(). int const mapping; - // is 0 for NAT-PMP and 1 for UPnP. - int const map_type; + // UPnP or NAT-PMP + portmap_transport map_transport; // tells you what failed. error_code const error; #ifndef TORRENT_NO_DEPRECATE + // is 0 for NAT-PMP and 1 for UPnP. + int const TORRENT_DEPRECATED_MEMBER map_type; + std::string TORRENT_DEPRECATED_MEMBER msg; #endif }; @@ -1421,7 +1426,8 @@ namespace libtorrent { struct TORRENT_EXPORT portmap_alert final : alert { // internal - portmap_alert(aux::stack_allocator& alloc, int i, int port, int t, int protocol); + portmap_alert(aux::stack_allocator& alloc, int i, int port + , portmap_transport t, portmap_protocol protocol); TORRENT_DEFINE_ALERT(portmap_alert, 51) @@ -1435,9 +1441,11 @@ namespace libtorrent { // the external port allocated for the mapping. int const external_port; - // 0 for NAT-PMP and 1 for UPnP. - int const map_type; + portmap_protocol const map_protocol; + portmap_transport const map_transport; + +#ifndef TORRENT_NO_DEPRECATE enum protocol_t { tcp, @@ -1445,7 +1453,11 @@ namespace libtorrent { }; // the protocol this mapping was for. one of protocol_t enums - int const protocol; + int const TORRENT_DEPRECATED_MEMBER protocol; + + // 0 for NAT-PMP and 1 for UPnP. + int const TORRENT_DEPRECATED_MEMBER map_type; +#endif }; // This alert is generated to log informational events related to either @@ -1457,14 +1469,14 @@ namespace libtorrent { struct TORRENT_EXPORT portmap_log_alert final : alert { // internal - portmap_log_alert(aux::stack_allocator& alloc, int t, const char* m); + portmap_log_alert(aux::stack_allocator& alloc, portmap_transport t, const char* m); TORRENT_DEFINE_ALERT(portmap_log_alert, 52) static constexpr alert_category_t static_category = alert::port_mapping_log_notification; virtual std::string message() const override; - int const map_type; + portmap_transport const map_transport; // the message associated with this log line char const* log_message() const; @@ -1476,6 +1488,7 @@ namespace libtorrent { aux::allocation_slot m_log_idx; #ifndef TORRENT_NO_DEPRECATE public: + int const TORRENT_DEPRECATED_MEMBER map_type; std::string TORRENT_DEPRECATED_MEMBER msg; #endif diff --git a/include/libtorrent/aux_/portmap.hpp b/include/libtorrent/aux_/portmap.hpp index 42e64a1ca..d76c023d3 100644 --- a/include/libtorrent/aux_/portmap.hpp +++ b/include/libtorrent/aux_/portmap.hpp @@ -30,23 +30,14 @@ POSSIBILITY OF SUCH DAMAGE. */ -#ifndef LIBTORRENT_PORTMAP_HPP -#define LIBTORRENT_PORTMAP_HPP +#ifndef LIBTORRENT_AUX_PORTMAP_HPP_INCLUDED +#define LIBTORRENT_AUX_PORTMAP_HPP_INCLUDED #include "libtorrent/config.hpp" +#include "libtorrent/portmap.hpp" -namespace libtorrent { namespace aux { - // TODO: move this for a better place and integrate it with - // portmap error alerts - enum class portmap_transport : std::uint8_t - { - natpmp, upnp - }; - - enum class portmap_protocol : std::uint8_t - { - none, tcp, udp - }; +namespace libtorrent { +namespace aux { enum class portmap_action : std::uint8_t { @@ -97,4 +88,4 @@ namespace libtorrent { namespace aux { } }} -#endif // LIBTORRENT_PORTMAP_HPP +#endif // LIBTORRENT_AUX_PORTMAP_HPP_INCLUDED diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index 4527895a9..ac6212e48 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -435,7 +435,7 @@ namespace aux { // a failure to map a port void on_port_mapping(int mapping, address const& ip, int port , portmap_protocol proto, error_code const& ec - , aux::portmap_transport transport) override; + , portmap_transport transport) override; bool is_aborted() const override { return m_abort; } bool is_paused() const { return m_paused; } @@ -633,7 +633,7 @@ namespace aux { void stop_natpmp(); void stop_upnp(); - int add_port_mapping(int t, int external_port + int add_port_mapping(portmap_protocol t, int external_port , int local_port); void delete_port_mapping(int handle); @@ -659,8 +659,8 @@ namespace aux { virtual void log_packet(message_direction_t dir, span pkt , udp::endpoint const& node) override; - virtual bool should_log_portmap(aux::portmap_transport transport) const override; - virtual void log_portmap(aux::portmap_transport transport, char const* msg) + virtual bool should_log_portmap(portmap_transport transport) const override; + virtual void log_portmap(portmap_transport transport, char const* msg) const override; virtual bool should_log_lsd() const override; diff --git a/include/libtorrent/natpmp.hpp b/include/libtorrent/natpmp.hpp index 2b6241c41..1d44e972b 100644 --- a/include/libtorrent/natpmp.hpp +++ b/include/libtorrent/natpmp.hpp @@ -55,10 +55,10 @@ struct TORRENT_EXTRA_EXPORT natpmp // maps the ports, if a port is set to 0 // it will not be mapped - int add_mapping(aux::portmap_protocol p, int external_port, tcp::endpoint local_ep); + int add_mapping(portmap_protocol p, int external_port, tcp::endpoint local_ep); void delete_mapping(int mapping_index); bool get_mapping(int mapping_index, int& local_port, int& external_port - , aux::portmap_protocol& protocol) const; + , portmap_protocol& protocol) const; void close(); diff --git a/include/libtorrent/portmap.hpp b/include/libtorrent/portmap.hpp new file mode 100644 index 000000000..30fd5536b --- /dev/null +++ b/include/libtorrent/portmap.hpp @@ -0,0 +1,52 @@ +/* + +Copyright (c) 2003-2017, Arvid Norberg +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the distribution. + * Neither the name of the author nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifndef TORRENT_PORTMAP_HPP_INCLUDED +#define TORRENT_PORTMAP_HPP_INCLUDED + +#include "libtorrent/config.hpp" + +namespace libtorrent { + + enum class portmap_transport : std::uint8_t + { + natpmp, upnp + }; + + enum class portmap_protocol : std::uint8_t + { + none, tcp, udp + }; + +} + +#endif //TORRENT_PORTMAP_HPP_INCLUDED diff --git a/include/libtorrent/session_handle.hpp b/include/libtorrent/session_handle.hpp index b60feb836..35cf54e85 100644 --- a/include/libtorrent/session_handle.hpp +++ b/include/libtorrent/session_handle.hpp @@ -44,6 +44,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/peer_id.hpp" #include "libtorrent/io_service.hpp" #include "libtorrent/session_types.hpp" +#include "libtorrent/portmap.hpp" // for portmap_protocol #include "libtorrent/kademlia/dht_storage.hpp" @@ -996,13 +997,14 @@ namespace libtorrent { #endif // protocols used by add_port_mapping() - enum protocol_type { udp = 1, tcp = 2 }; + constexpr static portmap_protocol udp = portmap_protocol::udp; + constexpr static portmap_protocol tcp = portmap_protocol::tcp; // add_port_mapping adds a port forwarding on UPnP and/or NAT-PMP, // whichever is enabled. The return value is a handle referring to the // port mapping that was just created. Pass it to delete_port_mapping() // to remove it. - int add_port_mapping(protocol_type t, int external_port, int local_port); + int add_port_mapping(portmap_protocol t, int external_port, int local_port); void delete_port_mapping(int handle); // This function is intended only for use by plugins. This type does diff --git a/include/libtorrent/upnp.hpp b/include/libtorrent/upnp.hpp index f2c027f00..547679188 100644 --- a/include/libtorrent/upnp.hpp +++ b/include/libtorrent/upnp.hpp @@ -172,14 +172,14 @@ struct TORRENT_EXTRA_EXPORT upnp final // portmap_alert_ respectively. If The mapping fails immediately, the return value // is -1, which means failure. There will not be any error alert notification for // mappings that fail with a -1 return value. - int add_mapping(aux::portmap_protocol p, int external_port, tcp::endpoint local_ep); + int add_mapping(portmap_protocol p, int external_port, tcp::endpoint local_ep); // This function removes a port mapping. ``mapping_index`` is the index that refers // to the mapping you want to remove, which was returned from add_mapping(). void delete_mapping(int mapping_index); bool get_mapping(int mapping_index, tcp::endpoint& local_ep, int& external_port - , aux::portmap_protocol& protocol) const; + , portmap_protocol& protocol) const; void discover_device(); void close(); @@ -241,7 +241,7 @@ private: struct global_mapping_t { - aux::portmap_protocol protocol = aux::portmap_protocol::none; + portmap_protocol protocol = portmap_protocol::none; int external_port = 0; tcp::endpoint local_ep; }; diff --git a/src/alert.cpp b/src/alert.cpp index aa7c78dc7..074d9c27d 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -1065,37 +1065,52 @@ namespace { } portmap_error_alert::portmap_error_alert(aux::stack_allocator& - , int i, int t, error_code const& e) - : mapping(i), map_type(t), error(e) + , int i, portmap_transport const t, error_code const& e) + : mapping(i) + , map_transport(t) + , error(e) #ifndef TORRENT_NO_DEPRECATE + , map_type(static_cast(t)) , msg(convert_from_native(error.message())) #endif {} std::string portmap_error_alert::message() const { - return std::string("could not map port using ") + nat_type_str[map_type] + return std::string("could not map port using ") + + nat_type_str[static_cast(map_transport)] + ": " + convert_from_native(error.message()); } - portmap_alert::portmap_alert(aux::stack_allocator&, int i, int port, int t - , int proto) - : mapping(i), external_port(port), map_type(t), protocol(proto) + portmap_alert::portmap_alert(aux::stack_allocator&, int i, int port + , portmap_transport const t + , portmap_protocol const proto) + : mapping(i) + , external_port(port) + , map_protocol(proto) + , map_transport(t) +#ifndef TORRENT_NO_DEPRECATE + , protocol(static_cast(proto)) + , map_type(static_cast(t)) +#endif {} std::string portmap_alert::message() const { char ret[200]; std::snprintf(ret, sizeof(ret), "successfully mapped port using %s. external port: %s/%u" - , nat_type_str[map_type], protocol_str[protocol], external_port); + , nat_type_str[static_cast(map_transport)] + , protocol_str[static_cast(map_protocol)], external_port); return ret; } - portmap_log_alert::portmap_log_alert(aux::stack_allocator& alloc, int t, const char* m) - : map_type(t) + portmap_log_alert::portmap_log_alert(aux::stack_allocator& alloc + , portmap_transport const t, const char* m) + : map_transport(t) , m_alloc(alloc) , m_log_idx(alloc.copy_string(m)) #ifndef TORRENT_NO_DEPRECATE + , map_type(static_cast(t)) , msg(m) #endif {} @@ -1108,7 +1123,8 @@ namespace { std::string portmap_log_alert::message() const { char ret[600]; - std::snprintf(ret, sizeof(ret), "%s: %s", nat_type_str[map_type] + std::snprintf(ret, sizeof(ret), "%s: %s" + , nat_type_str[static_cast(map_transport)] , log_message()); return ret; } diff --git a/src/natpmp.cpp b/src/natpmp.cpp index 43a0343c6..0d0eef2fe 100644 --- a/src/natpmp.cpp +++ b/src/natpmp.cpp @@ -173,7 +173,7 @@ bool natpmp::get_mapping(int const index, int& local_port #ifndef TORRENT_DISABLE_LOGGING bool natpmp::should_log() const { - return m_callback.should_log_portmap(aux::portmap_transport::natpmp); + return m_callback.should_log_portmap(portmap_transport::natpmp); } void natpmp::mapping_log(char const* op, mapping_t const& m) const @@ -201,7 +201,7 @@ void natpmp::log(char const* fmt, ...) const va_start(v, fmt); std::vsnprintf(msg, sizeof(msg), fmt, v); va_end(v); - m_callback.log_portmap(aux::portmap_transport::natpmp, msg); + m_callback.log_portmap(portmap_transport::natpmp, msg); } #endif @@ -218,7 +218,7 @@ void natpmp::disable(error_code const& ec) i->protocol = portmap_protocol::none; int const index = int(i - m_mappings.begin()); m_callback.on_port_mapping(index, address(), 0, proto, ec - , aux::portmap_transport::natpmp); + , portmap_transport::natpmp); } close_impl(); } @@ -573,13 +573,13 @@ void natpmp::on_reply(error_code const& e m->expires = aux::time_now() + hours(2); portmap_protocol const proto = m->protocol; m_callback.on_port_mapping(index, address(), 0, proto - , ev, aux::portmap_transport::natpmp); + , ev, portmap_transport::natpmp); } else if (m->act == portmap_action::add) { portmap_protocol const proto = m->protocol; m_callback.on_port_mapping(index, m_external_ip, m->external_port, proto - , errors::no_error, aux::portmap_transport::natpmp); + , errors::no_error, portmap_transport::natpmp); } if (m_abort) return; diff --git a/src/session_handle.cpp b/src/session_handle.cpp index 6a7606bdc..3ef8a8b2e 100644 --- a/src/session_handle.cpp +++ b/src/session_handle.cpp @@ -1201,9 +1201,10 @@ namespace { } #endif // TORRENT_NO_DEPRECATE - int session_handle::add_port_mapping(session::protocol_type t, int external_port, int local_port) + int session_handle::add_port_mapping(portmap_protocol const t + , int external_port, int local_port) { - return sync_call_ret(&session_impl::add_port_mapping, int(t), external_port, local_port); + return sync_call_ret(&session_impl::add_port_mapping, t, external_port, local_port); } void session_handle::delete_port_mapping(int handle) diff --git a/src/session_impl.cpp b/src/session_impl.cpp index f106fe183..2611d81d7 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -5414,32 +5414,29 @@ namespace { } namespace { - bool find_tcp_port_mapping(int transport, int mapping, std::shared_ptr const& ls) + bool find_tcp_port_mapping(portmap_transport const transport + , int mapping, std::shared_ptr const& ls) { - return ls->tcp_port_mapping[transport] == mapping; + return ls->tcp_port_mapping[static_cast(transport)] == mapping; } - bool find_udp_port_mapping(int transport, int mapping, std::shared_ptr const& ls) + bool find_udp_port_mapping(portmap_transport const transport + , int mapping, std::shared_ptr const& ls) { - return ls->udp_port_mapping[transport] == mapping; + return ls->udp_port_mapping[static_cast(transport)] == mapping; } } - // transport is 0 for NAT-PMP and 1 for UPnP void session_impl::on_port_mapping(int mapping, address const& ip, int port , portmap_protocol const proto, error_code const& ec - , aux::portmap_transport transport) + , portmap_transport const transport) { TORRENT_ASSERT(is_single_thread()); - int map_transport = - static_cast::type>(transport); - TORRENT_ASSERT(map_transport >= 0 && map_transport <= 1); - if (ec && m_alerts.should_post()) { m_alerts.emplace_alert(mapping - , map_transport, ec); + , transport, ec); } // look through our listen sockets to see if this mapping is for one of @@ -5447,13 +5444,13 @@ namespace { auto ls = std::find_if(m_listen_sockets.begin(), m_listen_sockets.end() - , std::bind(find_tcp_port_mapping, map_transport, mapping, _1)); + , std::bind(find_tcp_port_mapping, transport, mapping, _1)); bool tcp = true; if (ls == m_listen_sockets.end()) { ls = std::find_if(m_listen_sockets.begin(), m_listen_sockets.end() - , std::bind(find_udp_port_mapping, map_transport, mapping, _1)); + , std::bind(find_udp_port_mapping, transport, mapping, _1)); tcp = false; } @@ -5473,8 +5470,7 @@ namespace { if (!ec && m_alerts.should_post()) { m_alerts.emplace_alert(mapping, port - , map_transport, proto == portmap_protocol::udp - ? portmap_alert::udp : portmap_alert::tcp); + , transport, proto); } } @@ -6597,13 +6593,14 @@ namespace { return m_upnp.get(); } - int session_impl::add_port_mapping(int t, int external_port - , int local_port) + int session_impl::add_port_mapping(portmap_protocol const t + , int const external_port + , int const local_port) { int ret = 0; - if (m_upnp) ret = m_upnp->add_mapping(static_cast(t), external_port + if (m_upnp) ret = m_upnp->add_mapping(t, external_port , tcp::endpoint({}, static_cast(local_port))); - if (m_natpmp) ret = m_natpmp->add_mapping(static_cast(t), external_port + if (m_natpmp) ret = m_natpmp->add_mapping(t, external_port , tcp::endpoint({}, static_cast(local_port))); return ret; } @@ -6725,19 +6722,15 @@ namespace { m_alerts.emplace_alert(pkt, d, node); } - bool session_impl::should_log_portmap(aux::portmap_transport) const + bool session_impl::should_log_portmap(portmap_transport) const { return m_alerts.should_post(); } - void session_impl::log_portmap(aux::portmap_transport transport, char const* msg) const + void session_impl::log_portmap(portmap_transport transport, char const* msg) const { - int map_transport = - static_cast::type>(transport); - TORRENT_ASSERT(map_transport >= 0 && map_transport <= 1); - if (m_alerts.should_post()) - m_alerts.emplace_alert(map_transport, msg); + m_alerts.emplace_alert(transport, msg); } bool session_impl::should_log_lsd() const diff --git a/src/upnp.cpp b/src/upnp.cpp index 9a401d08d..11a7d5f6b 100644 --- a/src/upnp.cpp +++ b/src/upnp.cpp @@ -121,7 +121,7 @@ void upnp::discover_device() #ifndef TORRENT_DISABLE_LOGGING bool upnp::should_log() const { - return m_callback.should_log_portmap(aux::portmap_transport::upnp); + return m_callback.should_log_portmap(portmap_transport::upnp); } TORRENT_FORMAT(2,3) @@ -134,7 +134,7 @@ void upnp::log(char const* fmt, ...) const char msg[500]; std::vsnprintf(msg, sizeof(msg), fmt, v); va_end(v); - m_callback.log_portmap(aux::portmap_transport::upnp, msg); + m_callback.log_portmap(portmap_transport::upnp, msg); } #endif @@ -1083,7 +1083,7 @@ void upnp::disable(error_code const& ec) portmap_protocol const proto = i->protocol; i->protocol = portmap_protocol::none; m_callback.on_port_mapping(int(i - m_mappings.begin()), address(), 0, proto, ec - , aux::portmap_transport::upnp); + , portmap_transport::upnp); } // we cannot clear the devices since there @@ -1415,7 +1415,7 @@ void upnp::on_upnp_map_response(error_code const& e if (s.error_code == -1) { m_callback.on_port_mapping(mapping, d.external_ip, m.external_port, m.protocol, error_code() - , aux::portmap_transport::upnp); + , portmap_transport::upnp); if (d.lease_duration > 0) { m.expires = aux::time_now() @@ -1459,7 +1459,7 @@ void upnp::return_error(int const mapping, int const code) } portmap_protocol const proto = m_mappings[mapping].protocol; m_callback.on_port_mapping(mapping, address(), 0, proto, error_code(code, upnp_category()) - , aux::portmap_transport::upnp); + , portmap_transport::upnp); } void upnp::on_upnp_unmap_response(error_code const& e @@ -1526,7 +1526,7 @@ void upnp::on_upnp_unmap_response(error_code const& e m_callback.on_port_mapping(mapping, address(), 0, proto, p.status_code() != 200 ? error_code(p.status_code(), http_category()) : error_code(s.error_code, upnp_category()) - , aux::portmap_transport::upnp); + , portmap_transport::upnp); d.mapping[mapping].protocol = portmap_protocol::none; diff --git a/test/test_natpmp.cpp b/test/test_natpmp.cpp index 61c5dde67..16a8e2c2d 100644 --- a/test/test_natpmp.cpp +++ b/test/test_natpmp.cpp @@ -39,15 +39,13 @@ POSSIBILITY OF SUCH DAMAGE. using namespace lt; -using lt::aux::portmap_protocol; - namespace { struct natpmp_callback : aux::portmap_callback { void on_port_mapping(int mapping, address const& ip, int port , portmap_protocol const protocol, error_code const& err - , aux::portmap_transport transport) override + , portmap_transport const transport) override { std::cout << "mapping: " << mapping @@ -57,12 +55,12 @@ namespace << ", error: \"" << err.message() << "\"\n"; } #ifndef TORRENT_DISABLE_LOGGING - virtual bool should_log_portmap(aux::portmap_transport transport) const override + virtual bool should_log_portmap(portmap_transport transport) const override { return true; } - virtual void log_portmap(aux::portmap_transport transport, char const* msg) const override + virtual void log_portmap(portmap_transport transport, char const* msg) const override { std::cout << msg << std::endl; } diff --git a/test/test_upnp.cpp b/test/test_upnp.cpp index c992d5296..e488a733f 100644 --- a/test/test_upnp.cpp +++ b/test/test_upnp.cpp @@ -43,7 +43,7 @@ POSSIBILITY OF SUCH DAMAGE. using namespace lt; -using lt::aux::portmap_protocol; +using lt::portmap_protocol; broadcast_socket* sock = nullptr; int g_port = 0; @@ -121,7 +121,7 @@ namespace { void on_port_mapping(int mapping, address const& ip, int port , portmap_protocol const protocol, error_code const& err - , aux::portmap_transport transport) override + , portmap_transport const transport) override { callback_info info = {mapping, port, err}; callbacks.push_back(info); @@ -130,12 +130,12 @@ namespace << ", error: \"" << err.message() << "\"\n"; } #ifndef TORRENT_DISABLE_LOGGING - virtual bool should_log_portmap(aux::portmap_transport transport) const override + virtual bool should_log_portmap(portmap_transport transport) const override { return true; } - virtual void log_portmap(aux::portmap_transport transport, char const* msg) const override + virtual void log_portmap(portmap_transport transport, char const* msg) const override { std::cout << "UPnP: " << msg << std::endl; //TODO: store the log and verify that some key messages are there