forked from premiere/premiere-libtorrent
bind SOCKS5 connection to correct outgoing interface
This commit is contained in:
parent
95df88e7a3
commit
571952fd19
|
@ -370,6 +370,8 @@ void bind_alert()
|
|||
.value("partfile_write", operation_t::partfile_write)
|
||||
.value("hostname_lookup", operation_t::hostname_lookup)
|
||||
.value("symlink", operation_t::symlink)
|
||||
.value("handshake", operation_t::handshake)
|
||||
.value("sock_option", operation_t::sock_option)
|
||||
;
|
||||
|
||||
def("operation_name", static_cast<char const*(*)(operation_t)>(<::operation_name));
|
||||
|
|
|
@ -169,6 +169,9 @@ namespace libtorrent {
|
|||
|
||||
// handshake with a peer or server
|
||||
handshake,
|
||||
|
||||
// set socket option
|
||||
sock_option,
|
||||
};
|
||||
|
||||
// maps an operation id (from peer_error_alert and peer_disconnected_alert)
|
||||
|
|
|
@ -896,6 +896,7 @@ namespace {
|
|||
case o::hostname_lookup: return -1;
|
||||
case o::symlink: return -1;
|
||||
case o::handshake: return -1;
|
||||
case o::sock_option: return -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
@ -1562,7 +1563,8 @@ namespace {
|
|||
"partfile_write",
|
||||
"hostname_lookup",
|
||||
"symlink",
|
||||
"handshake"
|
||||
"handshake",
|
||||
"sock_option"
|
||||
};
|
||||
|
||||
int const idx = static_cast<int>(op);
|
||||
|
|
|
@ -556,9 +556,33 @@ void socks5::on_name_lookup(error_code const& e, tcp::resolver::iterator i)
|
|||
|
||||
error_code ec;
|
||||
m_socks5_sock.open(is_v4(m_proxy_addr) ? tcp::v4() : tcp::v6(), ec);
|
||||
if (ec)
|
||||
{
|
||||
if (m_alerts.should_post<socks5_alert>())
|
||||
m_alerts.emplace_alert<socks5_alert>(m_proxy_addr, operation_t::sock_open, ec);
|
||||
return;
|
||||
}
|
||||
|
||||
// enable keepalives
|
||||
m_socks5_sock.set_option(boost::asio::socket_base::keep_alive(true), ec);
|
||||
if (ec)
|
||||
{
|
||||
if (m_alerts.should_post<socks5_alert>())
|
||||
m_alerts.emplace_alert<socks5_alert>(m_proxy_addr, operation_t::sock_option, ec);
|
||||
return;
|
||||
}
|
||||
|
||||
tcp::endpoint const bind_ep(m_listen_socket.get_local_endpoint().address(), 0);
|
||||
m_socks5_sock.bind(bind_ep, ec);
|
||||
if (ec)
|
||||
{
|
||||
if (m_alerts.should_post<socks5_alert>())
|
||||
m_alerts.emplace_alert<socks5_alert>(m_proxy_addr, operation_t::sock_bind, ec);
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: perhaps an attempt should be made to bind m_socks5_sock to the
|
||||
// device of m_listen_socket
|
||||
|
||||
ADD_OUTSTANDING_ASYNC("socks5::on_connected");
|
||||
m_socks5_sock.async_connect(m_proxy_addr
|
||||
|
|
Loading…
Reference in New Issue