straighten out some type-safety in port mapping enums (#2285)

This commit is contained in:
Arvid Norberg 2017-08-30 20:47:49 +02:00 committed by GitHub
parent fe09ca9b97
commit f734ad067b
17 changed files with 195 additions and 105 deletions

View File

@ -576,32 +576,34 @@ void bind_alert()
class_<portmap_error_alert, bases<alert>, 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_<portmap_alert, bases<alert>, noncopyable>(
"portmap_alert", no_init)
class_<portmap_alert, bases<alert>, 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_<portmap_log_alert, bases<alert>, noncopyable>(
"portmap_log_alert", no_init)
.def_readonly("map_type", &portmap_log_alert::map_type)
class_<portmap_log_alert, bases<alert>, 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
;

View File

@ -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_<lt::session, boost::noncopyable>("session", no_init)
enum_<lt::portmap_protocol>("portmap_protocol")
.value("none", lt::portmap_protocol::none)
.value("udp", lt::portmap_protocol::udp)
.value("tcp", lt::portmap_protocol::tcp)
;
enum_<lt::portmap_transport>("portmap_transport")
.value("natpmp", lt::portmap_transport::natpmp)
.value("upnp", lt::portmap_transport::upnp)
;
{
scope s = class_<lt::session, boost::noncopyable>("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_<lt::session::protocol_type>("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_<dummy>("protocol_type");
s.attr("udp") = lt::portmap_protocol::udp;
s.attr("tcp") = lt::portmap_protocol::tcp;
}
#endif
{
scope s = class_<dummy9>("save_state_flags_t");

View File

@ -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 \

View File

@ -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 <boost/shared_array.hpp>
@ -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

View File

@ -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

View File

@ -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<char const> 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;

View File

@ -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();

View File

@ -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

View File

@ -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

View File

@ -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;
};

View File

@ -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<int>(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<int>(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<int>(proto))
, map_type(static_cast<int>(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<int>(map_transport)]
, protocol_str[static_cast<int>(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<int>(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<int>(map_transport)]
, log_message());
return ret;
}

View File

@ -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;

View File

@ -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<int>(&session_impl::add_port_mapping, int(t), external_port, local_port);
return sync_call_ret<int>(&session_impl::add_port_mapping, t, external_port, local_port);
}
void session_handle::delete_port_mapping(int handle)

View File

@ -5414,32 +5414,29 @@ namespace {
}
namespace {
bool find_tcp_port_mapping(int transport, int mapping, std::shared_ptr<listen_socket_t> const& ls)
bool find_tcp_port_mapping(portmap_transport const transport
, int mapping, std::shared_ptr<listen_socket_t> const& ls)
{
return ls->tcp_port_mapping[transport] == mapping;
return ls->tcp_port_mapping[static_cast<int>(transport)] == mapping;
}
bool find_udp_port_mapping(int transport, int mapping, std::shared_ptr<listen_socket_t> const& ls)
bool find_udp_port_mapping(portmap_transport const transport
, int mapping, std::shared_ptr<listen_socket_t> const& ls)
{
return ls->udp_port_mapping[transport] == mapping;
return ls->udp_port_mapping[static_cast<int>(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<std::underlying_type<aux::portmap_transport>::type>(transport);
TORRENT_ASSERT(map_transport >= 0 && map_transport <= 1);
if (ec && m_alerts.should_post<portmap_error_alert>())
{
m_alerts.emplace_alert<portmap_error_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<portmap_alert>())
{
m_alerts.emplace_alert<portmap_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<portmap_protocol>(t), external_port
if (m_upnp) ret = m_upnp->add_mapping(t, external_port
, tcp::endpoint({}, static_cast<std::uint16_t>(local_port)));
if (m_natpmp) ret = m_natpmp->add_mapping(static_cast<portmap_protocol>(t), external_port
if (m_natpmp) ret = m_natpmp->add_mapping(t, external_port
, tcp::endpoint({}, static_cast<std::uint16_t>(local_port)));
return ret;
}
@ -6725,19 +6722,15 @@ namespace {
m_alerts.emplace_alert<dht_pkt_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<portmap_log_alert>();
}
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<std::underlying_type<aux::portmap_transport>::type>(transport);
TORRENT_ASSERT(map_transport >= 0 && map_transport <= 1);
if (m_alerts.should_post<portmap_log_alert>())
m_alerts.emplace_alert<portmap_log_alert>(map_transport, msg);
m_alerts.emplace_alert<portmap_log_alert>(transport, msg);
}
bool session_impl::should_log_lsd() const

View File

@ -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;

View File

@ -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;
}

View File

@ -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