updated udp_socket error handling
This commit is contained in:
@@ -364,6 +364,21 @@ namespace libtorrent
|
||||
{ return std::auto_ptr<alert>(new metadata_received_alert(*this)); }
|
||||
};
|
||||
|
||||
struct TORRENT_EXPORT udp_error_alert: alert
|
||||
{
|
||||
udp_error_alert(
|
||||
udp::endpoint const& ep
|
||||
, std::string const& msg)
|
||||
: alert(alert::info, msg)
|
||||
, endpoint(ep)
|
||||
{}
|
||||
|
||||
udp::endpoint endpoint;
|
||||
|
||||
virtual std::auto_ptr<alert> clone() const
|
||||
{ return std::auto_ptr<alert>(new udp_error_alert(*this)); }
|
||||
};
|
||||
|
||||
struct TORRENT_EXPORT listen_failed_alert: alert
|
||||
{
|
||||
listen_failed_alert(
|
||||
|
@@ -509,7 +509,8 @@ namespace libtorrent
|
||||
|
||||
udp_socket m_dht_socket;
|
||||
|
||||
void on_receive_udp(udp::endpoint const& ep, char const* buf, int len);
|
||||
void on_receive_udp(asio::error_code const& e
|
||||
, udp::endpoint const& ep, char const* buf, int len);
|
||||
#endif
|
||||
|
||||
#ifndef TORRENT_DISABLE_ENCRYPTION
|
||||
|
@@ -46,7 +46,8 @@ namespace libtorrent
|
||||
class udp_socket
|
||||
{
|
||||
public:
|
||||
typedef boost::function<void(udp::endpoint const&, char const* buf, int size)> callback_t;
|
||||
typedef boost::function<void(asio::error_code const& ec
|
||||
, udp::endpoint const&, char const* buf, int size)> callback_t;
|
||||
|
||||
udp_socket(asio::io_service& ios, callback_t const& c, connection_queue& cc);
|
||||
|
||||
@@ -80,7 +81,7 @@ namespace libtorrent
|
||||
void connect2(asio::error_code const& e);
|
||||
|
||||
void wrap(udp::endpoint const& ep, char const* p, int len, asio::error_code& ec);
|
||||
void unwrap(char const* buf, int size);
|
||||
void unwrap(asio::error_code const& e, char const* buf, int size);
|
||||
|
||||
udp::socket m_ipv4_sock;
|
||||
udp::socket m_ipv6_sock;
|
||||
|
@@ -92,7 +92,8 @@ namespace libtorrent
|
||||
void name_lookup(asio::error_code const& error, udp::resolver::iterator i);
|
||||
void timeout(asio::error_code const& error);
|
||||
|
||||
void on_receive(udp::endpoint const& ep, char const* buf, int size);
|
||||
void on_receive(asio::error_code const& e, udp::endpoint const& ep
|
||||
, char const* buf, int size);
|
||||
void on_connect_response(char const* buf, int size);
|
||||
void on_announce_response(char const* buf, int size);
|
||||
void on_scrape_response(char const* buf, int size);
|
||||
|
@@ -39,7 +39,37 @@ void udp_socket::send(udp::endpoint const& ep, char const* p, int len, asio::err
|
||||
|
||||
void udp_socket::on_read(udp::socket* s, asio::error_code const& e, std::size_t bytes_transferred)
|
||||
{
|
||||
if (e) return;
|
||||
if (e)
|
||||
{
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
try {
|
||||
#endif
|
||||
if (s == &m_ipv4_sock)
|
||||
m_callback(e, m_v4_ep, 0, 0);
|
||||
else
|
||||
m_callback(e, m_v6_ep, 0, 0);
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
} catch(std::exception&) {}
|
||||
#endif
|
||||
|
||||
// don't stop listening on recoverable errors
|
||||
if (e != asio::error::host_unreachable
|
||||
&& e != asio::error::fault
|
||||
&& e != asio::error::connection_reset
|
||||
&& e != asio::error::connection_refused
|
||||
&& e != asio::error::connection_aborted
|
||||
&& e != asio::error::message_size)
|
||||
return;
|
||||
|
||||
if (s == &m_ipv4_sock)
|
||||
s->async_receive_from(asio::buffer(m_v4_buf, sizeof(m_v4_buf))
|
||||
, m_v4_ep, boost::bind(&udp_socket::on_read, this, s, _1, _2));
|
||||
else
|
||||
s->async_receive_from(asio::buffer(m_v6_buf, sizeof(m_v6_buf))
|
||||
, m_v6_ep, boost::bind(&udp_socket::on_read, this, s, _1, _2));
|
||||
|
||||
return;
|
||||
}
|
||||
if (!m_callback) return;
|
||||
|
||||
if (s == &m_ipv4_sock)
|
||||
@@ -49,9 +79,9 @@ void udp_socket::on_read(udp::socket* s, asio::error_code const& e, std::size_t
|
||||
#endif
|
||||
|
||||
if (m_tunnel_packets && m_v4_ep == m_proxy_addr)
|
||||
unwrap(m_v4_buf, bytes_transferred);
|
||||
unwrap(e, m_v4_buf, bytes_transferred);
|
||||
else
|
||||
m_callback(m_v4_ep, m_v4_buf, bytes_transferred);
|
||||
m_callback(e, m_v4_ep, m_v4_buf, bytes_transferred);
|
||||
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
} catch(std::exception&) {}
|
||||
@@ -66,9 +96,9 @@ void udp_socket::on_read(udp::socket* s, asio::error_code const& e, std::size_t
|
||||
#endif
|
||||
|
||||
if (m_tunnel_packets && m_v6_ep == m_proxy_addr)
|
||||
unwrap(m_v6_buf, bytes_transferred);
|
||||
unwrap(e, m_v6_buf, bytes_transferred);
|
||||
else
|
||||
m_callback(m_v6_ep, m_v6_buf, bytes_transferred);
|
||||
m_callback(e, m_v6_ep, m_v6_buf, bytes_transferred);
|
||||
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
} catch(std::exception&) {}
|
||||
@@ -102,7 +132,7 @@ void udp_socket::wrap(udp::endpoint const& ep, char const* p, int len, asio::err
|
||||
}
|
||||
|
||||
// unwrap the UDP packet from the SOCKS5 header
|
||||
void udp_socket::unwrap(char const* buf, int size)
|
||||
void udp_socket::unwrap(asio::error_code const& e, char const* buf, int size)
|
||||
{
|
||||
using namespace libtorrent::detail;
|
||||
|
||||
@@ -128,7 +158,6 @@ void udp_socket::unwrap(char const* buf, int size)
|
||||
{
|
||||
// IPv6
|
||||
TORRENT_ASSERT(false && "not supported yet");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -136,7 +165,7 @@ void udp_socket::unwrap(char const* buf, int size)
|
||||
return;
|
||||
}
|
||||
|
||||
m_callback(sender, p, size - (p - buf));
|
||||
m_callback(e, sender, p, size - (p - buf));
|
||||
}
|
||||
|
||||
void udp_socket::close()
|
||||
|
@@ -84,7 +84,7 @@ namespace libtorrent
|
||||
: tracker_connection(man, req, ios, bind_infc, c)
|
||||
, m_man(man)
|
||||
, m_name_lookup(ios)
|
||||
, m_socket(ios, boost::bind(&udp_tracker_connection::on_receive, this, _1, _2, _3), cc)
|
||||
, m_socket(ios, boost::bind(&udp_tracker_connection::on_receive, this, _1, _2, _3, _4), cc)
|
||||
, m_transaction_id(0)
|
||||
, m_connection_id(0)
|
||||
, m_settings(stn)
|
||||
@@ -185,7 +185,8 @@ namespace libtorrent
|
||||
tracker_connection::close();
|
||||
}
|
||||
|
||||
void udp_tracker_connection::on_receive(udp::endpoint const& ep, char const* buf, int size)
|
||||
void udp_tracker_connection::on_receive(asio::error_code const& e
|
||||
, udp::endpoint const& ep, char const* buf, int size)
|
||||
{
|
||||
// ignore resposes before we've sent any requests
|
||||
if (m_state == action_error) return;
|
||||
@@ -194,6 +195,8 @@ namespace libtorrent
|
||||
|
||||
// ignore packet not sent from the tracker
|
||||
if (m_target != ep) return;
|
||||
|
||||
if (e) fail(-1, e.message().c_str());
|
||||
|
||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING
|
||||
boost::shared_ptr<request_callback> cb = requester();
|
||||
|
Reference in New Issue
Block a user