mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-06-03 04:46:23 +02:00
Merge pull request #2191 from nobs2p/fix_SAM_FORWARD
Some checks are pending
Build Debian packages / bookworm (push) Waiting to run
Build Debian packages / bullseye (push) Waiting to run
Build Debian packages / buster (push) Waiting to run
Build on FreeBSD / with UPnP (push) Waiting to run
Build on OSX / With USE_UPNP=no (push) Waiting to run
Build on OSX / With USE_UPNP=yes (push) Waiting to run
Build on Windows / clang-x86_64 (push) Waiting to run
Build on Windows / i686 (push) Waiting to run
Build on Windows / ucrt-x86_64 (push) Waiting to run
Build on Windows / x86_64 (push) Waiting to run
Build on Windows / CMake clang-x86_64 (push) Waiting to run
Build on Windows / CMake i686 (push) Waiting to run
Build on Windows / CMake ucrt-x86_64 (push) Waiting to run
Build on Windows / CMake x86_64 (push) Waiting to run
Build on Windows / XP (push) Waiting to run
Build on Ubuntu / Make with USE_UPNP=no (push) Waiting to run
Build on Ubuntu / Make with USE_UPNP=yes (push) Waiting to run
Build on Ubuntu / CMake with -DWITH_UPNP=OFF (push) Waiting to run
Build on Ubuntu / CMake with -DWITH_UPNP=ON (push) Waiting to run
Build containers / Building container for linux/amd64 (push) Waiting to run
Build containers / Building container for linux/arm64 (push) Waiting to run
Build containers / Building container for linux/arm/v7 (push) Waiting to run
Build containers / Building container for linux/386 (push) Waiting to run
Build containers / Pushing merged manifest (push) Blocked by required conditions
Some checks are pending
Build Debian packages / bookworm (push) Waiting to run
Build Debian packages / bullseye (push) Waiting to run
Build Debian packages / buster (push) Waiting to run
Build on FreeBSD / with UPnP (push) Waiting to run
Build on OSX / With USE_UPNP=no (push) Waiting to run
Build on OSX / With USE_UPNP=yes (push) Waiting to run
Build on Windows / clang-x86_64 (push) Waiting to run
Build on Windows / i686 (push) Waiting to run
Build on Windows / ucrt-x86_64 (push) Waiting to run
Build on Windows / x86_64 (push) Waiting to run
Build on Windows / CMake clang-x86_64 (push) Waiting to run
Build on Windows / CMake i686 (push) Waiting to run
Build on Windows / CMake ucrt-x86_64 (push) Waiting to run
Build on Windows / CMake x86_64 (push) Waiting to run
Build on Windows / XP (push) Waiting to run
Build on Ubuntu / Make with USE_UPNP=no (push) Waiting to run
Build on Ubuntu / Make with USE_UPNP=yes (push) Waiting to run
Build on Ubuntu / CMake with -DWITH_UPNP=OFF (push) Waiting to run
Build on Ubuntu / CMake with -DWITH_UPNP=ON (push) Waiting to run
Build containers / Building container for linux/amd64 (push) Waiting to run
Build containers / Building container for linux/arm64 (push) Waiting to run
Build containers / Building container for linux/arm/v7 (push) Waiting to run
Build containers / Building container for linux/386 (push) Waiting to run
Build containers / Pushing merged manifest (push) Blocked by required conditions
Fix FORWARD session host handling in SAM and refactor SAMSocket::ProcessStreamForward
This commit is contained in:
commit
f93b354c36
1 changed files with 66 additions and 24 deletions
|
@ -637,53 +637,95 @@ namespace client
|
|||
SendMessageReply (SAM_STREAM_STATUS_INVALID_ID, strlen(SAM_STREAM_STATUS_INVALID_ID), true);
|
||||
}
|
||||
|
||||
void SAMSocket::ProcessStreamForward (char * buf, size_t len)
|
||||
void SAMSocket::ProcessStreamForward(char* buf, size_t len)
|
||||
{
|
||||
LogPrint (eLogDebug, "SAM: Stream forward: ", buf);
|
||||
LogPrint(eLogDebug, "SAM: Stream forward: ", buf);
|
||||
|
||||
std::map<std::string, std::string> params;
|
||||
ExtractParams (buf, params);
|
||||
std::string& id = params[SAM_PARAM_ID];
|
||||
auto session = m_Owner.FindSession (id);
|
||||
ExtractParams(buf, params);
|
||||
|
||||
const auto itId = params.find(SAM_PARAM_ID);
|
||||
if (itId == params.end())
|
||||
{
|
||||
SendSessionI2PError("Missing ID");
|
||||
return;
|
||||
}
|
||||
const std::string& id = itId->second;
|
||||
|
||||
auto session = m_Owner.FindSession(id);
|
||||
if (!session)
|
||||
{
|
||||
SendMessageReply (SAM_STREAM_STATUS_INVALID_ID, strlen(SAM_STREAM_STATUS_INVALID_ID), true);
|
||||
SendMessageReply(SAM_STREAM_STATUS_INVALID_ID, strlen(SAM_STREAM_STATUS_INVALID_ID), true);
|
||||
return;
|
||||
}
|
||||
if (session->GetLocalDestination ()->IsAcceptingStreams ())
|
||||
if (session->GetLocalDestination()->IsAcceptingStreams())
|
||||
{
|
||||
SendSessionI2PError ("Already accepting");
|
||||
SendSessionI2PError("Already accepting");
|
||||
return;
|
||||
}
|
||||
auto it = params.find (SAM_PARAM_PORT);
|
||||
if (it == params.end ())
|
||||
|
||||
const auto itPort = params.find(SAM_PARAM_PORT);
|
||||
if (itPort == params.end())
|
||||
{
|
||||
SendSessionI2PError ("PORT is missing");
|
||||
SendSessionI2PError("PORT is missing");
|
||||
return;
|
||||
}
|
||||
auto port = std::stoi (it->second);
|
||||
|
||||
const std::string& portStr = itPort->second;
|
||||
if (!std::all_of(portStr.begin(), portStr.end(), ::isdigit))
|
||||
{
|
||||
SendSessionI2PError("Port must be numeric");
|
||||
return;
|
||||
}
|
||||
|
||||
int port = std::stoi(portStr);
|
||||
if (port <= 0 || port >= 0xFFFF)
|
||||
{
|
||||
SendSessionI2PError ("Invalid PORT");
|
||||
SendSessionI2PError("Invalid port");
|
||||
return;
|
||||
}
|
||||
boost::system::error_code ec;
|
||||
auto ep = m_Socket.remote_endpoint (ec);
|
||||
if (ec)
|
||||
|
||||
boost::asio::ip::tcp::endpoint ep;
|
||||
const auto itHost = params.find(SAM_PARAM_HOST);
|
||||
|
||||
if (itHost != params.end())
|
||||
{
|
||||
SendSessionI2PError ("Socket error");
|
||||
return;
|
||||
boost::system::error_code ec;
|
||||
auto addr = boost::asio::ip::make_address(itHost->second, ec);
|
||||
if (ec)
|
||||
{
|
||||
SendSessionI2PError("Invalid IP Address in HOST");
|
||||
return;
|
||||
}
|
||||
ep = boost::asio::ip::tcp::endpoint(addr, port);
|
||||
}
|
||||
ep.port (port);
|
||||
else
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
ep = m_Socket.remote_endpoint(ec);
|
||||
if (ec)
|
||||
{
|
||||
SendSessionI2PError("Socket error: cannot get remote endpoint");
|
||||
return;
|
||||
}
|
||||
ep.port(port);
|
||||
}
|
||||
|
||||
m_SocketType = eSAMSocketTypeForward;
|
||||
m_ID = id;
|
||||
m_IsAccepting = true;
|
||||
std::string& silent = params[SAM_PARAM_SILENT];
|
||||
if (silent == SAM_VALUE_TRUE) m_IsSilent = true;
|
||||
session->GetLocalDestination ()->AcceptStreams (std::bind (&SAMSocket::HandleI2PForward,
|
||||
shared_from_this (), std::placeholders::_1, ep));
|
||||
SendMessageReply (SAM_STREAM_STATUS_OK, strlen(SAM_STREAM_STATUS_OK), false);
|
||||
|
||||
auto itSilent = params.find(SAM_PARAM_SILENT);
|
||||
if (itSilent != params.end() && itSilent->second == SAM_VALUE_TRUE)
|
||||
m_IsSilent = true;
|
||||
|
||||
session->GetLocalDestination()->AcceptStreams(
|
||||
std::bind(&SAMSocket::HandleI2PForward, shared_from_this(), std::placeholders::_1, ep));
|
||||
|
||||
SendMessageReply(SAM_STREAM_STATUS_OK, strlen(SAM_STREAM_STATUS_OK), false);
|
||||
}
|
||||
|
||||
|
||||
size_t SAMSocket::ProcessDatagramSend (char * buf, size_t len, const char * data)
|
||||
{
|
||||
LogPrint (eLogDebug, "SAM: Datagram send: ", buf, " ", len);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue