file_error_alert
If the storage fails to read or write files that it needs access to, this alert is
diff --git a/docs/manual.rst b/docs/manual.rst
index 13a1a91f6..7f8351304 100644
--- a/docs/manual.rst
+++ b/docs/manual.rst
@@ -4072,6 +4072,23 @@ the index returned from add_mapping_.
int type;
};
+portmap_log_alert
+-----------------
+
+This alert is generated to log informational events related to either
+UPnP or NAT-PMP. They contain a log line and the type (0 = NAT-PMP
+and 1 = UPnP). Displaying these messages to an end user is only useful
+for debugging the UPnP or NAT-PMP implementation.
+
+::
+
+ struct portmap_log_alert: alert
+ {
+ //...
+ int type;
+ std::string msg;
+ };
+
file_error_alert
----------------
diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp
index 52ae8dd57..e2e5567e9 100644
--- a/include/libtorrent/alert_types.hpp
+++ b/include/libtorrent/alert_types.hpp
@@ -1103,6 +1103,29 @@ namespace libtorrent
}
};
+ struct TORRENT_EXPORT portmap_log_alert: alert
+ {
+ portmap_log_alert(int t, std::string const& m)
+ : type(t), msg(m)
+ {}
+
+ int type;
+ std::string msg;
+
+ virtual std::auto_ptr clone() const
+ { return std::auto_ptr(new portmap_log_alert(*this)); }
+ virtual char const* what() const { return "port map log"; }
+ const static int static_category = alert::port_mapping_notification;
+ virtual int category() const { return static_category; }
+ virtual std::string message() const
+ {
+ static char const* type_str[] = {"NAT-PMP", "UPnP"};
+ std::stringstream ret;
+ ret << type_str[type] << ": " << msg;
+ return ret.str();
+ }
+ };
+
struct TORRENT_EXPORT fastresume_rejected_alert: torrent_alert
{
fastresume_rejected_alert(torrent_handle const& h
diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp
index 740617b28..fe1f71d4e 100644
--- a/include/libtorrent/aux_/session_impl.hpp
+++ b/include/libtorrent/aux_/session_impl.hpp
@@ -605,6 +605,9 @@ namespace libtorrent
boost::shared_ptr m_logger;
private:
+#endif
+#ifdef TORRENT_UPNP_LOGGING
+ std::ofstream m_upnp_log;
#endif
address m_external_address;
diff --git a/include/libtorrent/broadcast_socket.hpp b/include/libtorrent/broadcast_socket.hpp
index 3a8d6a76e..ad0be1299 100644
--- a/include/libtorrent/broadcast_socket.hpp
+++ b/include/libtorrent/broadcast_socket.hpp
@@ -65,6 +65,7 @@ namespace libtorrent
void send(char const* buffer, int size, error_code& ec);
void close();
+ int num_send_sockets() const { return m_unicast_sockets.size(); }
private:
diff --git a/include/libtorrent/upnp.hpp b/include/libtorrent/upnp.hpp
index 5913e70d0..c82bb3232 100644
--- a/include/libtorrent/upnp.hpp
+++ b/include/libtorrent/upnp.hpp
@@ -62,6 +62,8 @@ namespace libtorrent
// int: external port
// std::string: error message
// an empty string as error means success
+// a port-mapping index of -1 means it's
+// an informational log message
typedef boost::function portmap_callback_t;
class upnp : public intrusive_ptr_base
@@ -117,6 +119,7 @@ private:
void disable(char const* msg);
void return_error(int mapping, int code);
+ void log(std::string const&);
void delete_port_mapping(rootdevice& d, int i);
void create_port_mapping(http_connection& c, rootdevice& d, int i);
@@ -272,10 +275,6 @@ private:
mutex_t m_mutex;
std::string m_model;
-
-#ifdef TORRENT_UPNP_LOGGING
- std::ofstream m_log;
-#endif
};
}
diff --git a/src/broadcast_socket.cpp b/src/broadcast_socket.cpp
index 43654a11a..5e3372ee5 100644
--- a/src/broadcast_socket.cpp
+++ b/src/broadcast_socket.cpp
@@ -219,9 +219,6 @@ namespace libtorrent
if (ec) return;
s->bind(udp::endpoint(addr, 0), ec);
if (ec) return;
- if (addr.is_v4())
- s->set_option(outbound_interface(addr.to_v4()), ec);
- if (ec) return;
m_unicast_sockets.push_back(socket_entry(s));
socket_entry& se = m_unicast_sockets.back();
s->async_receive_from(asio::buffer(se.buffer, sizeof(se.buffer))
diff --git a/src/session.cpp b/src/session.cpp
index 474f88a24..893090a5e 100644
--- a/src/session.cpp
+++ b/src/session.cpp
@@ -566,9 +566,10 @@ namespace libtorrent
{
case alert::debug: m = alert::all_categories; break;
case alert::info: m = alert::all_categories & ~(alert::debug_notification
- | alert::progress_notification); break;
+ | alert::progress_notification | alert::dht_notification); break;
case alert::warning: m = alert::all_categories & ~(alert::debug_notification
- | alert::status_notification | alert::progress_notification); break;
+ | alert::status_notification | alert::progress_notification
+ | alert::dht_notification); break;
case alert::critical: m = alert::error_notification | alert::storage_notification; break;
case alert::fatal: m = alert::error_notification; break;
default: break;
diff --git a/src/session_impl.cpp b/src/session_impl.cpp
index 253bf0778..87eb50ec4 100644
--- a/src/session_impl.cpp
+++ b/src/session_impl.cpp
@@ -212,6 +212,9 @@ namespace aux {
m_bandwidth_manager[peer_connection::download_channel] = &m_download_channel;
m_bandwidth_manager[peer_connection::upload_channel] = &m_upload_channel;
+#ifdef TORRENT_UPNP_LOGGING
+ m_upnp_log.open("upnp.log", std::ios::in | std::ios::out | std::ios::trunc);
+#endif
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
m_logger = create_log("main_session", listen_port(), false);
(*m_logger) << time_now_string() << "\n";
@@ -1990,6 +1993,20 @@ namespace aux {
void session_impl::on_port_mapping(int mapping, int port
, std::string const& errmsg, int map_transport)
{
+ TORRENT_ASSERT(map_transport >= 0 && map_transport <= 1);
+ // log message
+ if (mapping == -1)
+ {
+#ifdef TORRENT_UPNP_LOGGING
+ char const* transport_names[] = {"NAT-PMP", "UPnP"};
+ m_upnp_log << time_now_string() << " "
+ << transport_names[map_transport] << ": " << errmsg;
+#endif
+ if (m_alerts.should_post())
+ m_alerts.post_alert(portmap_log_alert(map_transport, errmsg));
+ return;
+ }
+
#ifndef TORRENT_DISABLE_DHT
if (mapping == m_udp_mapping[map_transport] && port != 0)
{
diff --git a/src/upnp.cpp b/src/upnp.cpp
index baac6ca4f..92b21d373 100644
--- a/src/upnp.cpp
+++ b/src/upnp.cpp
@@ -52,10 +52,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include
#include
-#if (defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING)) && !defined(TORRENT_UPNP_LOGGING)
-#define TORRENT_UPNP_LOGGING
-#endif
-
using boost::bind;
using namespace libtorrent;
@@ -75,9 +71,7 @@ upnp::upnp(io_service& ios, connection_queue& cc
, m_ignore_non_routers(ignore_nonrouters)
, m_cc(cc)
{
-#ifdef TORRENT_UPNP_LOGGING
- m_log.open("upnp.log", std::ios::in | std::ios::out | std::ios::trunc);
-#endif
+ TORRENT_ASSERT(cb);
m_retry_count = 0;
if (state)
@@ -108,10 +102,17 @@ upnp::~upnp()
void upnp::discover_device()
{
mutex_t::scoped_lock l(m_mutex);
+ if (m_socket.num_send_sockets() == 0)
+ log("No network interfaces to broadcast to");
discover_device_impl();
}
+void upnp::log(std::string const& msg)
+{
+ m_callback(-1, 0, msg);
+}
+
void upnp::discover_device_impl()
{
const char msearch[] =
@@ -131,11 +132,9 @@ void upnp::discover_device_impl()
if (ec)
{
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string()
- << " ==> Broadcast FAILED: " << ec.message() << std::endl
- << "aborting" << std::endl;
-#endif
+ std::stringstream msg;
+ msg << "broadcast failed: " << ec.message() << ". Aborting.";
+ log(msg.str());
disable(ec.message().c_str());
return;
}
@@ -145,10 +144,7 @@ void upnp::discover_device_impl()
m_broadcast_timer.async_wait(bind(&upnp::resend_request
, self(), _1));
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string()
- << " ==> Broadcasting search for rootdevice" << std::endl;
-#endif
+ log("broadcasting search for rootdevice");
}
// returns a reference to a mapping or -1 on failure
@@ -156,14 +152,12 @@ int upnp::add_mapping(upnp::protocol_type p, int external_port, int local_port)
{
mutex_t::scoped_lock l(m_mutex);
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string()
- << " *** add mapping [ proto: " << (p == tcp?"tcp":"udp")
+ std::stringstream msg;
+ msg << "adding port map: [ protocol: " << (p == tcp?"tcp":"udp")
<< " ext_port: " << external_port
<< " local_port :" << local_port << " ]";
- if (m_disabled) m_log << " DISABLED";
- m_log << std::endl;
-#endif
+ if (m_disabled) msg << " DISABLED";
+ log(msg.str());
if (m_disabled) return -1;
std::vector::iterator i = std::find_if(
@@ -211,13 +205,11 @@ void upnp::delete_mapping(int mapping)
global_mapping_t& m = m_mappings[mapping];
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string()
- << " *** delete mapping [ proto: " << (m.protocol == tcp?"tcp":"udp")
- << " ext_port:" << m.external_port
- << " local_port:" << m.local_port << " ]";
- m_log << std::endl;
-#endif
+ std::stringstream msg;
+ msg << "deleting port map: [ protocol: " << (m.protocol == tcp?"tcp":"udp")
+ << " ext_port: " << m.external_port
+ << " local_port :" << m.local_port << " ]";
+ log(msg.str());
if (m.protocol == none) return;
@@ -249,12 +241,7 @@ void upnp::resend_request(error_code const& e)
if (m_devices.empty())
{
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string()
- << " *** Got no response in 12 retries. Giving up, "
- "disabling UPnP." << std::endl;
-#endif
- disable("no UPnP router found");
+ disable("no UPnP router found (no response)");
return;
}
@@ -269,10 +256,9 @@ void upnp::resend_request(error_code const& e)
TORRENT_ASSERT(d.magic == 1337);
try
{
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string()
- << " ==> connecting to " << d.url << std::endl;
-#endif
+ std::stringstream msg;
+ msg << "connecting to: " << d.url;
+ log(msg.str());
if (d.upnp_connection) d.upnp_connection->close();
d.upnp_connection.reset(new http_connection(m_io_service
, m_cc, bind(&upnp::on_upnp_xml, self(), _1, _2
@@ -282,11 +268,9 @@ void upnp::resend_request(error_code const& e)
catch (std::exception& e)
{
(void)e;
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string()
- << " *** Connection failed to: " << d.url
- << " " << e.what() << std::endl;
-#endif
+ std::stringstream msg;
+ msg << "connection failed to: " << d.url << " " << e.what();
+ log(msg.str());
d.disabled = true;
}
}
@@ -329,25 +313,25 @@ void upnp::on_reply(udp::endpoint const& from, char* buffer
error_code ec;
if (!in_local_network(m_io_service, from.address(), ec))
{
-#ifdef TORRENT_UPNP_LOGGING
if (ec)
{
- m_log << time_now_string() << " <== (" << from << ") error: "
- << ec.message() << std::endl;
+ std::stringstream msg;
+ msg << "when receiving response from: " << from << ": " << ec.message();
+ log(msg.str());
}
else
{
- m_log << time_now_string() << " <== (" << from << ") UPnP device "
- "ignored because it's not on our local network ";
+ std::stringstream msg;
+ msg << "ignoring response from: " << from << ". IP is not on local network. ";
+
std::vector net = enum_net_interfaces(m_io_service, ec);
for (std::vector::const_iterator i = net.begin()
, end(net.end()); i != end; ++i)
{
- m_log << "(" << i->interface_address << ", " << i->netmask << ") ";
+ msg << "(" << i->interface_address << ", " << i->netmask << ") ";
}
- m_log << std::endl;
+ log(msg.str());
}
-#endif
return;
}
@@ -357,24 +341,23 @@ void upnp::on_reply(udp::endpoint const& from, char* buffer
{
// this upnp device is filtered because it's not in the
// list of configured routers
-#ifdef TORRENT_UPNP_LOGGING
if (ec)
{
- m_log << time_now_string() << " <== (" << from << ") error: "
- << ec.message() << std::endl;
+ std::stringstream msg;
+ msg << "when receiving response from: " << from << ": " << ec.message();
+ log(msg.str());
}
else
{
- m_log << time_now_string() << " <== (" << from << ") UPnP device "
- "ignored because it's not a router on our network ";
+ std::stringstream msg;
+ msg << "ignoring response from: " << from << ". IP is not a router. ";
for (std::vector::const_iterator i = routes.begin()
, end(routes.end()); i != end; ++i)
{
- m_log << "(" << i->gateway << ", " << i->netmask << ") ";
+ msg << "(" << i->gateway << ", " << i->netmask << ") ";
}
- m_log << std::endl;
+ log(msg.str());
}
-#endif
return;
}
@@ -384,46 +367,43 @@ void upnp::on_reply(udp::endpoint const& from, char* buffer
, buffer + bytes_transferred), error);
if (error)
{
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string() << " <== (" << from << ") Rootdevice "
- "responded with incorrect HTTP packet. Ignoring device" << std::endl;
-#endif
+ std::stringstream msg;
+ msg << "received malformed HTTP from " << from;
+ log(msg.str());
return;
}
if (p.status_code() != 200 && p.method() != "notify")
{
-#ifdef TORRENT_UPNP_LOGGING
if (p.method().empty())
- m_log << time_now_string()
- << " <== (" << from << ") Device responded with HTTP status: " << p.status_code()
- << ". Ignoring device" << std::endl;
+ {
+ std::stringstream msg;
+ msg << "HTTP status " << p.status_code() << " from " << from;
+ log(msg.str());
+ }
else
- m_log << time_now_string()
- << " <== (" << from << ") Device with HTTP method: " << p.method()
- << ". Ignoring device" << std::endl;
-#endif
+ {
+ std::stringstream msg;
+ msg << "HTTP method " << p.method() << " from " << from;
+ log(msg.str());
+ }
return;
}
if (!p.header_finished())
{
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string()
- << " <== (" << from << ") Rootdevice responded with incomplete HTTP "
- "packet. Ignoring device" << std::endl;
-#endif
+ std::stringstream msg;
+ msg << "incomplete HTTP packet from " << from;
+ log(msg.str());
return;
}
std::string url = p.header("location");
if (url.empty())
{
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string()
- << " <== (" << from << ") Rootdevice response is missing a location header. "
- "Ignoring device" << std::endl;
-#endif
+ std::stringstream msg;
+ msg << "missing location header from " << from;
+ log(msg.str());
return;
}
@@ -444,11 +424,9 @@ void upnp::on_reply(udp::endpoint const& from, char* buffer
if (error)
{
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string()
- << " <== (" << from << ") Rootdevice advertized an invalid url: '" << d.url
- << "'. " << error << ". Ignoring device" << std::endl;
-#endif
+ std::stringstream msg;
+ msg << "invalid URL " << d.url << " from " << from << ": " << error;
+ log(msg.str());
return;
}
@@ -457,36 +435,29 @@ void upnp::on_reply(udp::endpoint const& from, char* buffer
if (protocol != "http")
{
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string()
- << " <== (" << from << ") Rootdevice uses unsupported protocol: '" << protocol
- << "'. Ignoring device" << std::endl;
-#endif
+ std::stringstream msg;
+ msg << "unsupported protocol " << protocol << " from " << from;
+ log(msg.str());
return;
}
if (d.port == 0)
{
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string()
- << " <== (" << from << ") Rootdevice responded with a url with port 0. "
- "Ignoring device" << std::endl;
-#endif
+ std::stringstream msg;
+ msg << "URL with port 0 from " << from;
+ log(msg.str());
return;
}
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string()
- << " <== (" << from << ") Found rootdevice: " << d.url
- << " total: " << m_devices.size() << std::endl;
-#endif
+
+ std::stringstream msg;
+ msg << "found rootdevice: " << d.url << ". (" << m_devices.size() << ")";
+ log(msg.str());
if (m_devices.size() >= 50)
{
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string()
- << " <== (" << from << ") Too many devices (" << m_devices.size() << "), "
- "ignoring: " << d.url << std::endl;
-#endif
+ std::stringstream msg;
+ msg << "too many devices (" << m_devices.size() << "). Ignoring " << d.url;
+ log(msg.str());
return;
}
@@ -525,10 +496,10 @@ void upnp::on_reply(udp::endpoint const& from, char* buffer
try
{
#endif
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string()
- << " ==> connecting to " << d.url << std::endl;
-#endif
+ std::stringstream msg;
+ msg << "connecting to: " << d.url;
+ log(msg.str());
+
if (d.upnp_connection) d.upnp_connection->close();
d.upnp_connection.reset(new http_connection(m_io_service
, m_cc, bind(&upnp::on_upnp_xml, self(), _1, _2
@@ -539,11 +510,9 @@ void upnp::on_reply(udp::endpoint const& from, char* buffer
catch (std::exception& e)
{
(void)e;
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string()
- << " *** Connection failed to: " << d.url
- << " " << e.what() << std::endl;
-#endif
+ std::stringstream msg;
+ msg << "connection failed to: " << d.url << " " << e.what();
+ log(msg.str());
d.disabled = true;
}
#endif
@@ -568,11 +537,9 @@ void upnp::post(upnp::rootdevice const& d, std::string const& soap
d.upnp_connection->sendbuffer = header.str();
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string()
- << " ==> sending: " << header.str() << std::endl;
-#endif
-
+ std::stringstream msg;
+ msg << "sending: " << header.str();
+ log(msg.str());
}
void upnp::create_port_mapping(http_connection& c, rootdevice& d, int i)
@@ -584,10 +551,9 @@ void upnp::create_port_mapping(http_connection& c, rootdevice& d, int i)
if (!d.upnp_connection)
{
TORRENT_ASSERT(d.disabled);
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string() << " *** mapping (" << i
- << ") aborted" << std::endl;
-#endif
+ std::stringstream msg;
+ msg << "mapping " << i << " aborted";
+ log(msg.str());
return;
}
@@ -644,11 +610,9 @@ void upnp::update_map(rootdevice& d, int i)
if (m.action == mapping_t::action_none
|| m.protocol == none)
{
-#ifdef TORRENT_UPNP_LOGGING
- if (m.protocol != none)
- m_log << time_now_string() << " *** mapping (" << i
- << ") does not need update, skipping" << std::endl;
-#endif
+ std::stringstream msg;
+ msg << "mapping " << i << " does not need updating, skipping";
+ log(msg.str());
next(d, i);
return;
}
@@ -656,10 +620,9 @@ void upnp::update_map(rootdevice& d, int i)
TORRENT_ASSERT(!d.upnp_connection);
TORRENT_ASSERT(d.service_namespace);
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string()
- << " ==> connecting to " << d.hostname << std::endl;
-#endif
+ std::stringstream msg;
+ msg << "connecting to " << d.hostname;
+ log(msg.str());
if (m.action == mapping_t::action_add)
{
if (m.failcount > 5)
@@ -701,10 +664,9 @@ void upnp::delete_port_mapping(rootdevice& d, int i)
if (!d.upnp_connection)
{
TORRENT_ASSERT(d.disabled);
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string() << " *** unmapping (" << i
- << ") aborted" << std::endl;
-#endif
+ std::stringstream msg;
+ msg << "unmapping " << i << " aborted";
+ log(msg.str());
return;
}
@@ -806,31 +768,27 @@ void upnp::on_upnp_xml(error_code const& e
if (e && e != asio::error::eof)
{
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string()
- << " <== (" << d.url << ") error while fetching control url: "
- << e.message() << std::endl;
-#endif
+ std::stringstream msg;
+ msg << "error while fetching control url from " << d.url << ": " << e.message();
+ log(msg.str());
d.disabled = true;
return;
}
if (!p.header_finished())
{
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string()
- << " <== (" << d.url << ") error while fetching control url: incomplete http message" << std::endl;
-#endif
+ std::stringstream msg;
+ msg << "error while fetching control url from " << d.url << ": incomplete HTTP message";
+ log(msg.str());
d.disabled = true;
return;
}
if (p.status_code() != 200)
{
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string()
- << " <== (" << d.url << ") error while fetching control url: " << p.message() << std::endl;
-#endif
+ std::stringstream msg;
+ msg << "error while fetching control url from " << d.url << ": " << p.message();
+ log(msg.str());
d.disabled = true;
return;
}
@@ -858,21 +816,18 @@ void upnp::on_upnp_xml(error_code const& e
}
else
{
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string()
- << " <== (" << d.url << ") Rootdevice response, did not find "
- "a port mapping interface" << std::endl;
-#endif
+ std::stringstream msg;
+ msg << "Could not find a port mapping interface in response from " << d.url;
+ log(msg.str());
d.disabled = true;
return;
}
}
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string()
- << " <== (" << d.url << ") Rootdevice response, found control URL: " << s.control_url
- << " namespace: " << d.service_namespace << std::endl;
-#endif
+ std::stringstream msg;
+ msg << "found control URL: " << s.control_url << " namespace: "
+ << d.service_namespace << " in response from " << d.url;
+ log(msg.str());
d.control_url = s.control_url;
@@ -884,10 +839,9 @@ void upnp::on_upnp_xml(error_code const& e
if (error)
{
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string()
- << " *** Failed to parse URL '" << d.control_url << "': " << error << std::endl;
-#endif
+ std::stringstream msg;
+ msg << "failed to parse URL '" << d.control_url << "': " << error;
+ log(msg.str());
d.disabled = true;
return;
}
@@ -982,10 +936,9 @@ void upnp::on_upnp_map_response(error_code const& e
if (e && e != asio::error::eof)
{
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string()
- << " <== error while adding portmap: " << e.message() << std::endl;
-#endif
+ std::stringstream msg;
+ msg << "error while adding port map: " << e.message();
+ log(msg.str());
d.disabled = true;
return;
}
@@ -1011,10 +964,9 @@ void upnp::on_upnp_map_response(error_code const& e
if (!p.header_finished())
{
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string()
- << " <== error while adding portmap: incomplete http message" << std::endl;
-#endif
+ std::stringstream msg;
+ msg << "error while adding port map: incomplete http message";
+ log(msg.str());
next(d, mapping);
return;
}
@@ -1026,13 +978,12 @@ void upnp::on_upnp_map_response(error_code const& e
xml_parse((char*)p.get_body().begin, (char*)p.get_body().end
, bind(&find_error_code, _1, _2, boost::ref(s)));
-#ifdef TORRENT_UPNP_LOGGING
if (s.error_code != -1)
{
- m_log << time_now_string()
- << " <== got error message: " << s.error_code << std::endl;
+ std::stringstream msg;
+ msg << "error while adding port map, code: " << s.error_code;
+ log(msg.str());
}
-#endif
mapping_t& m = d.mapping[mapping];
@@ -1074,11 +1025,9 @@ void upnp::on_upnp_map_response(error_code const& e
return_error(mapping, s.error_code);
}
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string()
- << " <== map response: " << std::string(p.get_body().begin, p.get_body().end)
- << std::endl;
-#endif
+ std::stringstream msg;
+ msg << "map response: " << std::string(p.get_body().begin, p.get_body().end);
+ log(msg.str());
if (s.error_code == -1)
{
@@ -1138,32 +1087,27 @@ void upnp::on_upnp_unmap_response(error_code const& e
if (e && e != asio::error::eof)
{
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string()
- << " <== error while deleting portmap: " << e.message() << std::endl;
-#endif
- } else if (!p.header_finished())
+ std::stringstream msg;
+ msg << "error while deleting portmap: " << e.message();
+ log(msg.str());
+ }
+ else if (!p.header_finished())
{
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string()
- << " <== error while deleting portmap: incomplete http message" << std::endl;
-#endif
+ std::stringstream msg;
+ msg << "error while deleting portmap: incomplete http message";
+ log(msg.str());
}
else if (p.status_code() != 200)
{
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string()
- << " <== error while deleting portmap: " << p.message() << std::endl;
-#endif
+ std::stringstream msg;
+ msg << "error while deleting portmap: " << p.message();
+ log(msg.str());
}
else
{
-
-#ifdef TORRENT_UPNP_LOGGING
- m_log << time_now_string()
- << " <== unmap response: " << std::string(p.get_body().begin, p.get_body().end)
- << std::endl;
-#endif
+ std::stringstream msg;
+ msg << "unmap response: " << std::string(p.get_body().begin, p.get_body().end);
+ log(msg.str());
}
d.mapping[mapping].protocol = none;