MCPcopy Create free account
hub / github.com/PurpleI2P/i2pd / ForwardSOCKS

Method ForwardSOCKS

libi2pd_client/SOCKS.cpp:746–783  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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)

Callers

nothing calls this directly

Calls 4

LogPrintFunction · 0.85
to_stringFunction · 0.85
SocksRequestFailedMethod · 0.80
SendUpstreamRequestMethod · 0.80

Tested by

no test coverage detected