fix udp_socket proxy issue
This commit is contained in:
parent
d120dc1bc4
commit
d736b158a0
|
@ -70,7 +70,7 @@ namespace libtorrent
|
||||||
udp_socket(io_service& ios, connection_queue& cc);
|
udp_socket(io_service& ios, connection_queue& cc);
|
||||||
~udp_socket();
|
~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
|
bool is_open() const
|
||||||
{
|
{
|
||||||
|
@ -86,9 +86,11 @@ namespace libtorrent
|
||||||
void unsubscribe(udp_socket_observer* o);
|
void unsubscribe(udp_socket_observer* o);
|
||||||
|
|
||||||
// this is only valid when using a socks5 proxy
|
// 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 bind(udp::endpoint const& ep, error_code& ec);
|
||||||
void close();
|
void close();
|
||||||
int local_port() const { return m_bind_port; }
|
int local_port() const { return m_bind_port; }
|
||||||
|
@ -154,7 +156,8 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
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
|
// necessary for logging member offsets
|
||||||
public:
|
public:
|
||||||
#endif
|
#endif
|
||||||
|
@ -171,8 +174,10 @@ namespace libtorrent
|
||||||
// and they will be added later
|
// and they will be added later
|
||||||
bool m_observers_locked;
|
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, udp::endpoint const& ep
|
||||||
void call_handler(error_code const& ec, const char* host, char const* buf, int size);
|
, 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_drained_handler();
|
||||||
void call_writable_handler();
|
void call_writable_handler();
|
||||||
|
|
||||||
|
@ -292,7 +297,8 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
rate_limited_udp_socket(io_service& ios, connection_queue& cc);
|
rate_limited_udp_socket(io_service& ios, connection_queue& cc);
|
||||||
void set_rate_limit(int limit) { m_rate_limit = limit; }
|
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:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -130,7 +130,7 @@ udp_socket::~udp_socket()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void udp_socket::send_hostname(char const* hostname, int port
|
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;
|
CHECK_MAGIC;
|
||||||
|
|
||||||
|
@ -158,12 +158,15 @@ void udp_socket::send_hostname(char const* hostname, int port
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_queue.size() > 1000) return;
|
if (m_queue.size() > 1000 || (flags & dont_queue)) return;
|
||||||
|
|
||||||
m_queue.push_back(queued_packet());
|
m_queue.push_back(queued_packet());
|
||||||
queued_packet& qp = m_queue.back();
|
queued_packet& qp = m_queue.back();
|
||||||
qp.ep.port(port);
|
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.buf.insert(qp.buf.begin(), p, p + len);
|
||||||
qp.flags = 0;
|
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_packets)
|
||||||
{
|
{
|
||||||
if (m_queue.size() > 1000) return;
|
if (m_queue.size() > 1000 || (flags & dont_queue)) return;
|
||||||
|
|
||||||
m_queue.push_back(queued_packet());
|
m_queue.push_back(queued_packet());
|
||||||
queued_packet& qp = m_queue.back();
|
queued_packet& qp = m_queue.back();
|
||||||
|
@ -1364,12 +1367,13 @@ void udp_socket::drain_queue()
|
||||||
error_code ec;
|
error_code ec;
|
||||||
if (p.hostname)
|
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);
|
free(p.hostname);
|
||||||
}
|
}
|
||||||
else
|
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();
|
m_queue.pop_front();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue