some socks5 cleanup
This commit is contained in:
parent
19d0087911
commit
931c5530c2
|
@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
#include "libtorrent/proxy_base.hpp"
|
#include "libtorrent/proxy_base.hpp"
|
||||||
|
#include "libtorrent/assert.hpp"
|
||||||
#if defined TORRENT_ASIO_DEBUGGING
|
#if defined TORRENT_ASIO_DEBUGGING
|
||||||
#include "libtorrent/debug.hpp"
|
#include "libtorrent/debug.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
@ -73,16 +74,27 @@ class socks5_stream : public proxy_base
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
// commands
|
||||||
|
enum {
|
||||||
|
socks5_connect = 1,
|
||||||
|
socks5_bind = 2,
|
||||||
|
socks5_udp_associate = 3
|
||||||
|
};
|
||||||
|
|
||||||
explicit socks5_stream(io_service& io_service)
|
explicit socks5_stream(io_service& io_service)
|
||||||
: proxy_base(io_service)
|
: proxy_base(io_service)
|
||||||
, m_version(5)
|
, m_version(5)
|
||||||
, m_command(1)
|
, m_command(socks5_connect)
|
||||||
, m_listen(0)
|
, m_listen(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void set_version(int v) { m_version = v; }
|
void set_version(int v) { m_version = v; }
|
||||||
|
|
||||||
void set_command(int c) { m_command = c; }
|
void set_command(int c)
|
||||||
|
{
|
||||||
|
TORRENT_ASSERT(c >= socks5_connect && c <=socks5_udp_associate);
|
||||||
|
m_command = c;
|
||||||
|
}
|
||||||
|
|
||||||
void set_username(std::string const& user
|
void set_username(std::string const& user
|
||||||
, std::string const& password)
|
, std::string const& password)
|
||||||
|
@ -114,11 +126,17 @@ public:
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//#error fix error messages to use custom error_code category
|
// TODO: 2 fix error messages to use custom error_code category
|
||||||
//#error add async_connect() that takes a hostname and port as well
|
// TODO: 2 add async_connect() that takes a hostname and port as well
|
||||||
template <class Handler>
|
template <class Handler>
|
||||||
void async_connect(endpoint_type const& endpoint, Handler const& handler)
|
void async_connect(endpoint_type const& endpoint, Handler const& handler)
|
||||||
{
|
{
|
||||||
|
// make sure we don't try to connect to INADDR_ANY. binding is fine,
|
||||||
|
// and using a hostname is fine on SOCKS version 5.
|
||||||
|
TORRENT_ASSERT(m_command == socks5_bind
|
||||||
|
|| endpoint.address() != address()
|
||||||
|
|| (!m_dst_name.empty() && m_version == 5));
|
||||||
|
|
||||||
m_remote_endpoint = endpoint;
|
m_remote_endpoint = endpoint;
|
||||||
|
|
||||||
// the connect is split up in the following steps:
|
// the connect is split up in the following steps:
|
||||||
|
@ -163,7 +181,11 @@ private:
|
||||||
std::string m_password;
|
std::string m_password;
|
||||||
std::string m_dst_name;
|
std::string m_dst_name;
|
||||||
int m_version;
|
int m_version;
|
||||||
|
|
||||||
|
// the socks command to send for this connection (connect, bind,
|
||||||
|
// udp associate)
|
||||||
int m_command;
|
int m_command;
|
||||||
|
|
||||||
// set to one when we're waiting for the
|
// set to one when we're waiting for the
|
||||||
// second message to accept an incoming connection
|
// second message to accept an incoming connection
|
||||||
int m_listen;
|
int m_listen;
|
||||||
|
|
|
@ -294,6 +294,10 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// we either need a hostname or a valid endpoint
|
||||||
|
TORRENT_ASSERT(m_command == socks5_bind
|
||||||
|
|| m_remote_endpoint.address() != address());
|
||||||
|
|
||||||
write_uint8(m_remote_endpoint.address().is_v4()?1:4, p); // address type
|
write_uint8(m_remote_endpoint.address().is_v4()?1:4, p); // address type
|
||||||
write_address(m_remote_endpoint.address(), p);
|
write_address(m_remote_endpoint.address(), p);
|
||||||
}
|
}
|
||||||
|
@ -398,7 +402,7 @@ namespace libtorrent
|
||||||
// we ignore the proxy IP it was bound to
|
// we ignore the proxy IP it was bound to
|
||||||
if (atyp == 1)
|
if (atyp == 1)
|
||||||
{
|
{
|
||||||
if (m_command == 2)
|
if (m_command == socks5_bind)
|
||||||
{
|
{
|
||||||
if (m_listen == 0)
|
if (m_listen == 0)
|
||||||
{
|
{
|
||||||
|
@ -459,7 +463,7 @@ namespace libtorrent
|
||||||
// access granted
|
// access granted
|
||||||
if (response == 90)
|
if (response == 90)
|
||||||
{
|
{
|
||||||
if (m_command == 2)
|
if (m_command == socks5_bind)
|
||||||
{
|
{
|
||||||
if (m_listen == 0)
|
if (m_listen == 0)
|
||||||
{
|
{
|
||||||
|
@ -505,7 +509,7 @@ namespace libtorrent
|
||||||
|
|
||||||
if (handle_error(e, h)) return;
|
if (handle_error(e, h)) return;
|
||||||
|
|
||||||
if (m_command == 2)
|
if (m_command == socks5_bind)
|
||||||
{
|
{
|
||||||
if (m_listen == 0)
|
if (m_listen == 0)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue