forked from premiere/premiere-libtorrent
include socket type in listen_failed_alert and listen_succeeded_alert
This commit is contained in:
parent
f2e3e613b2
commit
e4c805c988
|
@ -1297,14 +1297,18 @@ namespace libtorrent
|
|||
// listen on it.
|
||||
struct TORRENT_EXPORT listen_failed_alert: alert
|
||||
{
|
||||
enum socket_type_t { tcp, tcp_ssl, udp, i2p, socks5 };
|
||||
|
||||
// internal
|
||||
listen_failed_alert(
|
||||
tcp::endpoint const& ep
|
||||
, int op
|
||||
, error_code const& ec)
|
||||
, error_code const& ec
|
||||
, socket_type_t t)
|
||||
: endpoint(ep)
|
||||
, error(ec)
|
||||
, operation(op)
|
||||
, sock_type(t)
|
||||
{}
|
||||
|
||||
TORRENT_DEFINE_ALERT(listen_failed_alert);
|
||||
|
@ -1313,13 +1317,22 @@ namespace libtorrent
|
|||
virtual std::string message() const;
|
||||
virtual bool discardable() const { return false; }
|
||||
|
||||
// the endpoint libtorrent attempted to listen on
|
||||
tcp::endpoint endpoint;
|
||||
|
||||
// the error the system returned
|
||||
error_code error;
|
||||
|
||||
enum op_t
|
||||
{
|
||||
parse_addr, open, bind, listen, get_peer_name, accept
|
||||
};
|
||||
|
||||
// the specific low level operation that failed. See op_t.
|
||||
int operation;
|
||||
|
||||
// the type of listen socket this alert refers to.
|
||||
socket_type_t sock_type;
|
||||
};
|
||||
|
||||
// This alert is posted when the listen port succeeds to be opened on a
|
||||
|
@ -1327,9 +1340,12 @@ namespace libtorrent
|
|||
// was opened for listening.
|
||||
struct TORRENT_EXPORT listen_succeeded_alert: alert
|
||||
{
|
||||
enum socket_type_t { tcp, tcp_ssl, udp };
|
||||
|
||||
// internal
|
||||
listen_succeeded_alert(tcp::endpoint const& ep)
|
||||
listen_succeeded_alert(tcp::endpoint const& ep, socket_type_t t)
|
||||
: endpoint(ep)
|
||||
, sock_type(t)
|
||||
{}
|
||||
|
||||
TORRENT_DEFINE_ALERT(listen_succeeded_alert);
|
||||
|
@ -1338,7 +1354,12 @@ namespace libtorrent
|
|||
virtual std::string message() const;
|
||||
virtual bool discardable() const { return false; }
|
||||
|
||||
// the endpoint libtorrent ended up listening on. The address
|
||||
// refers to the local interface and the port is the listen port.
|
||||
tcp::endpoint endpoint;
|
||||
|
||||
// the type of listen socket this alert refers to.
|
||||
socket_type_t sock_type;
|
||||
};
|
||||
|
||||
// This alert is generated when a NAT router was successfully found but some
|
||||
|
|
|
@ -283,7 +283,7 @@ namespace libtorrent {
|
|||
|
||||
std::string listen_failed_alert::message() const
|
||||
{
|
||||
char const* op_str[] =
|
||||
static char const* op_str[] =
|
||||
{
|
||||
"parse_addr",
|
||||
"open",
|
||||
|
@ -292,18 +292,28 @@ namespace libtorrent {
|
|||
"get_peer_name",
|
||||
"accept"
|
||||
};
|
||||
static char const* type_str[] =
|
||||
{
|
||||
"TCP", "TCP/SSL", "UDP", "I2P", "Socks5"
|
||||
};
|
||||
char ret[250];
|
||||
snprintf(ret, sizeof(ret), "listening on %s failed: [%s] %s"
|
||||
snprintf(ret, sizeof(ret), "listening on %s failed: [%s] [%s] %s"
|
||||
, print_endpoint(endpoint).c_str()
|
||||
, op_str[operation]
|
||||
, type_str[sock_type]
|
||||
, convert_from_native(error.message()).c_str());
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string listen_succeeded_alert::message() const
|
||||
{
|
||||
static char const* type_str[] =
|
||||
{
|
||||
"TCP", "TCP/SSL", "UDP"
|
||||
};
|
||||
char ret[200];
|
||||
snprintf(ret, sizeof(ret), "successfully listening on %s", print_endpoint(endpoint).c_str());
|
||||
snprintf(ret, sizeof(ret), "successfully listening on [%s] %s"
|
||||
, type_str[sock_type], print_endpoint(endpoint).c_str());
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -2244,13 +2244,14 @@ namespace aux {
|
|||
, int& retries, bool v6_only, int flags, error_code& ec)
|
||||
{
|
||||
int last_op = 0;
|
||||
listen_failed_alert::socket_type_t sock_type = s->ssl ? listen_failed_alert::tcp_ssl : listen_failed_alert::tcp;
|
||||
s->sock.reset(new socket_acceptor(m_io_service));
|
||||
s->sock->open(ep.protocol(), ec);
|
||||
last_op = listen_failed_alert::open;
|
||||
if (ec)
|
||||
{
|
||||
if (m_alerts.should_post<listen_failed_alert>())
|
||||
m_alerts.post_alert(listen_failed_alert(ep, last_op, ec));
|
||||
m_alerts.post_alert(listen_failed_alert(ep, last_op, ec, sock_type));
|
||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||
session_log("failed to open socket: %s: %s"
|
||||
, print_endpoint(ep).c_str(), ec.message().c_str());
|
||||
|
@ -2311,7 +2312,7 @@ namespace aux {
|
|||
{
|
||||
// not even that worked, give up
|
||||
if (m_alerts.should_post<listen_failed_alert>())
|
||||
m_alerts.post_alert(listen_failed_alert(ep, last_op, ec));
|
||||
m_alerts.post_alert(listen_failed_alert(ep, last_op, ec, sock_type));
|
||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||
session_log("cannot bind to interface \"%s\": %s"
|
||||
, print_endpoint(ep).c_str(), ec.message().c_str());
|
||||
|
@ -2329,7 +2330,7 @@ namespace aux {
|
|||
if (ec)
|
||||
{
|
||||
if (m_alerts.should_post<listen_failed_alert>())
|
||||
m_alerts.post_alert(listen_failed_alert(ep, last_op, ec));
|
||||
m_alerts.post_alert(listen_failed_alert(ep, last_op, ec, sock_type));
|
||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||
session_log("cannot listen on interface \"%s\": %s"
|
||||
, print_endpoint(ep).c_str(), ec.message().c_str());
|
||||
|
@ -2346,7 +2347,7 @@ namespace aux {
|
|||
if (ec)
|
||||
{
|
||||
if (m_alerts.should_post<listen_failed_alert>())
|
||||
m_alerts.post_alert(listen_failed_alert(ep, last_op, ec));
|
||||
m_alerts.post_alert(listen_failed_alert(ep, last_op, ec, sock_type));
|
||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||
char msg[200];
|
||||
snprintf(msg, 200, "failed to get peer name \"%s\": %s"
|
||||
|
@ -2357,7 +2358,7 @@ namespace aux {
|
|||
}
|
||||
|
||||
if (m_alerts.should_post<listen_succeeded_alert>())
|
||||
m_alerts.post_alert(listen_succeeded_alert(ep));
|
||||
m_alerts.post_alert(listen_succeeded_alert(ep, s->ssl ? listen_succeeded_alert::tcp_ssl : listen_succeeded_alert::tcp));
|
||||
|
||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||
session_log(" listening on: %s external port: %d"
|
||||
|
@ -2523,13 +2524,15 @@ retry:
|
|||
}
|
||||
if (m_alerts.should_post<listen_failed_alert>())
|
||||
m_alerts.post_alert(listen_failed_alert(m_listen_interface
|
||||
, listen_failed_alert::bind, ec));
|
||||
, listen_failed_alert::bind, ec, listen_failed_alert::udp));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_external_udp_port = m_udp_socket.local_port();
|
||||
maybe_update_udp_mapping(0, m_listen_interface.port(), m_listen_interface.port());
|
||||
maybe_update_udp_mapping(1, m_listen_interface.port(), m_listen_interface.port());
|
||||
if (m_alerts.should_post<listen_succeeded_alert>())
|
||||
m_alerts.post_alert(listen_succeeded_alert(m_listen_interface, listen_succeeded_alert::udp));
|
||||
}
|
||||
|
||||
m_udp_socket.set_option(type_of_service(m_settings.peer_tos), ec);
|
||||
|
@ -2652,7 +2655,8 @@ retry:
|
|||
{
|
||||
if (m_alerts.should_post<listen_failed_alert>())
|
||||
m_alerts.post_alert(listen_failed_alert(tcp::endpoint(
|
||||
address_v4::any(), m_listen_interface.port()), listen_failed_alert::accept, e));
|
||||
address_v4::any(), m_listen_interface.port()), listen_failed_alert::accept
|
||||
, e, listen_failed_alert::i2p));
|
||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||
session_log("cannot bind to port %d: %s"
|
||||
, m_listen_interface.port(), e.message().c_str());
|
||||
|
@ -2787,7 +2791,8 @@ retry:
|
|||
async_accept(listener, ssl);
|
||||
}
|
||||
if (m_alerts.should_post<listen_failed_alert>())
|
||||
m_alerts.post_alert(listen_failed_alert(ep, listen_failed_alert::accept, e));
|
||||
m_alerts.post_alert(listen_failed_alert(ep, listen_failed_alert::accept, e
|
||||
, ssl ? listen_failed_alert::tcp_ssl : listen_failed_alert::tcp));
|
||||
return;
|
||||
}
|
||||
async_accept(listener, ssl);
|
||||
|
@ -3039,7 +3044,8 @@ retry:
|
|||
{
|
||||
if (m_alerts.should_post<listen_failed_alert>())
|
||||
m_alerts.post_alert(listen_failed_alert(tcp::endpoint(
|
||||
address_v4::any(), m_listen_interface.port()), listen_failed_alert::accept, e));
|
||||
address_v4::any(), m_listen_interface.port()), listen_failed_alert::accept, e
|
||||
, listen_failed_alert::socks5));
|
||||
return;
|
||||
}
|
||||
open_new_incoming_socks_connection();
|
||||
|
@ -5538,7 +5544,8 @@ retry:
|
|||
if (ec)
|
||||
{
|
||||
if (m_alerts.should_post<listen_failed_alert>())
|
||||
m_alerts.post_alert(listen_failed_alert(new_interface, listen_failed_alert::parse_addr, ec));
|
||||
m_alerts.post_alert(listen_failed_alert(new_interface, listen_failed_alert::parse_addr, ec
|
||||
, listen_failed_alert::tcp));
|
||||
|
||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||
session_log("listen_on: %s failed: %s"
|
||||
|
|
Loading…
Reference in New Issue