From d736b158a063cb5c321bfbef3264036bb0873be5 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 20 Nov 2013 01:19:42 +0000 Subject: [PATCH] fix udp_socket proxy issue --- include/libtorrent/udp_socket.hpp | 20 +++++++++++++------- src/udp_socket.cpp | 16 ++++++++++------ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/include/libtorrent/udp_socket.hpp b/include/libtorrent/udp_socket.hpp index e7f6bc918..67044b0a8 100644 --- a/include/libtorrent/udp_socket.hpp +++ b/include/libtorrent/udp_socket.hpp @@ -70,7 +70,7 @@ namespace libtorrent udp_socket(io_service& ios, connection_queue& cc); ~udp_socket(); - enum flags_t { dont_drop = 1, peer_connection = 2 }; + enum flags_t { dont_drop = 1, peer_connection = 2, dont_queue = 4 }; bool is_open() const { @@ -86,9 +86,11 @@ namespace libtorrent void unsubscribe(udp_socket_observer* o); // this is only valid when using a socks5 proxy - void send_hostname(char const* hostname, int port, char const* p, int len, error_code& ec); + void send_hostname(char const* hostname, int port, char const* p + , int len, error_code& ec, int flags = 0); - void send(udp::endpoint const& ep, char const* p, int len, error_code& ec, int flags = 0); + void send(udp::endpoint const& ep, char const* p, int len + , error_code& ec, int flags = 0); void bind(udp::endpoint const& ep, error_code& ec); void close(); int local_port() const { return m_bind_port; } @@ -154,7 +156,8 @@ namespace libtorrent } private: -#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING +#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING \ + || defined TORRENT_ERROR_LOGGING // necessary for logging member offsets public: #endif @@ -171,8 +174,10 @@ namespace libtorrent // and they will be added later bool m_observers_locked; - void call_handler(error_code const& ec, udp::endpoint const& ep, char const* buf, int size); - void call_handler(error_code const& ec, const char* host, char const* buf, int size); + void call_handler(error_code const& ec, udp::endpoint const& ep + , char const* buf, int size); + void call_handler(error_code const& ec, const char* host + , char const* buf, int size); void call_drained_handler(); void call_writable_handler(); @@ -292,7 +297,8 @@ namespace libtorrent { rate_limited_udp_socket(io_service& ios, connection_queue& cc); void set_rate_limit(int limit) { m_rate_limit = limit; } - bool send(udp::endpoint const& ep, char const* p, int len, error_code& ec, int flags = 0); + bool send(udp::endpoint const& ep, char const* p, int len + , error_code& ec, int flags = 0); private: diff --git a/src/udp_socket.cpp b/src/udp_socket.cpp index a6aee814e..3e65ed6bd 100644 --- a/src/udp_socket.cpp +++ b/src/udp_socket.cpp @@ -130,7 +130,7 @@ udp_socket::~udp_socket() #endif void udp_socket::send_hostname(char const* hostname, int port - , char const* p, int len, error_code& ec) + , char const* p, int len, error_code& ec, int flags) { CHECK_MAGIC; @@ -158,12 +158,15 @@ void udp_socket::send_hostname(char const* hostname, int port return; } - if (m_queue.size() > 1000) return; + if (m_queue.size() > 1000 || (flags & dont_queue)) return; m_queue.push_back(queued_packet()); queued_packet& qp = m_queue.back(); qp.ep.port(port); - qp.hostname = allocate_string_copy(hostname); + + address target = address::from_string(hostname, ec); + if (ec) qp.ep.address(target); + else qp.hostname = allocate_string_copy(hostname); qp.buf.insert(qp.buf.begin(), p, p + len); qp.flags = 0; } @@ -193,7 +196,7 @@ void udp_socket::send(udp::endpoint const& ep, char const* p, int len if (m_queue_packets) { - if (m_queue.size() > 1000) return; + if (m_queue.size() > 1000 || (flags & dont_queue)) return; m_queue.push_back(queued_packet()); queued_packet& qp = m_queue.back(); @@ -1364,12 +1367,13 @@ void udp_socket::drain_queue() error_code ec; if (p.hostname) { - udp_socket::send_hostname(p.hostname, p.ep.port(), &p.buf[0], p.buf.size(), ec); + udp_socket::send_hostname(p.hostname, p.ep.port(), &p.buf[0] + , p.buf.size(), ec, p.flags | dont_queue); free(p.hostname); } else { - udp_socket::send(p.ep, &p.buf[0], p.buf.size(), ec, p.flags); + udp_socket::send(p.ep, &p.buf[0], p.buf.size(), ec, p.flags | dont_queue); } m_queue.pop_front(); }