| 744 | } |
| 745 | |
| 746 | void SOCKSHandler::ForwardSOCKS() |
| 747 | { |
| 748 | LogPrint(eLogInfo, "SOCKS: Forwarding to upstream"); |
| 749 | if (m_UpstreamProxyPort) // TCP |
| 750 | { |
| 751 | EnterState(UPSTREAM_RESOLVE); |
| 752 | m_proxy_resolver.async_resolve(m_UpstreamProxyAddress, std::to_string(m_UpstreamProxyPort), |
| 753 | std::bind(&SOCKSHandler::HandleUpstreamResolved, shared_from_this(), std::placeholders::_1, std::placeholders::_2)); |
| 754 | } |
| 755 | else if (!m_UpstreamProxyAddress.empty ())// local |
| 756 | { |
| 757 | #if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS) |
| 758 | EnterState(UPSTREAM_CONNECT); |
| 759 | m_upstreamLocalSock = std::make_shared<boost::asio::local::stream_protocol::socket>(GetOwner()->GetService()); |
| 760 | auto s = shared_from_this (); |
| 761 | m_upstreamLocalSock->async_connect(m_UpstreamProxyAddress, |
| 762 | [s](const boost::system::error_code& ecode) |
| 763 | { |
| 764 | if (ecode) |
| 765 | { |
| 766 | LogPrint(eLogWarning, "SOCKS: Could not connect to local upstream proxy: ", ecode.message()); |
| 767 | s->SocksRequestFailed(SOCKS5_NET_UNREACH); |
| 768 | return; |
| 769 | } |
| 770 | LogPrint(eLogInfo, "SOCKS: Connected to local upstream proxy"); |
| 771 | s->SendUpstreamRequest(s->m_upstreamLocalSock); |
| 772 | }); |
| 773 | #else |
| 774 | LogPrint(eLogError, "SOCKS: Local sockets for upstream proxy not supported"); |
| 775 | SocksRequestFailed(SOCKS5_ADDR_UNSUP); |
| 776 | #endif |
| 777 | } |
| 778 | else |
| 779 | { |
| 780 | LogPrint(eLogError, "SOCKS: Incorrect upstream proxy address"); |
| 781 | SocksRequestFailed(SOCKS5_ADDR_UNSUP); |
| 782 | } |
| 783 | } |
| 784 | |
| 785 | template<typename Socket> |
| 786 | void SOCKSHandler::SocksUpstreamSuccess(std::shared_ptr<Socket>& upstreamSock) |
nothing calls this directly
no test coverage detected