diff --git a/include/libtorrent/udp_socket.hpp b/include/libtorrent/udp_socket.hpp index 4272eede9..d826e5d42 100644 --- a/include/libtorrent/udp_socket.hpp +++ b/include/libtorrent/udp_socket.hpp @@ -132,6 +132,8 @@ namespace libtorrent { m_socket.get_option(opt, ec); } + bool active_socks5() const; + private: // non-copyable diff --git a/src/udp_socket.cpp b/src/udp_socket.cpp index ed5b3e435..355cdd81f 100644 --- a/src/udp_socket.cpp +++ b/src/udp_socket.cpp @@ -213,7 +213,7 @@ int udp_socket::read(span pkts, error_code& ec) p.data = {m_buf->data(), len}; // support packets coming from the SOCKS5 proxy - if (m_socks5_connection && m_socks5_connection->active()) + if (active_socks5()) { // if the source IP doesn't match the proxy's, ignore the packet if (p.from != m_socks5_connection->target()) continue; @@ -247,6 +247,11 @@ int udp_socket::read(span pkts, error_code& ec) return ret; } +bool udp_socket::active_socks5() const +{ + return (m_socks5_connection && m_socks5_connection->active()); +} + void udp_socket::send_hostname(char const* hostname, int const port , span p, error_code& ec, udp_send_flags_t const flags) { @@ -267,7 +272,7 @@ void udp_socket::send_hostname(char const* hostname, int const port if (use_proxy && m_proxy_settings.type != settings_pack::none) { - if (m_socks5_connection && m_socks5_connection->active()) + if (active_socks5()) { // send udp packets through SOCKS5 server wrap(hostname, port, p, ec, flags); @@ -305,7 +310,7 @@ void udp_socket::send(udp::endpoint const& ep, span p if (use_proxy && m_proxy_settings.type != settings_pack::none) { - if (m_socks5_connection && m_socks5_connection->active()) + if (active_socks5()) { // send udp packets through SOCKS5 server wrap(ep, p, ec, flags);