1
0
mirror of https://github.com/PurpleI2P/i2pd.git synced 2025-08-26 17:01:49 +00:00

handle SESSION ADD without FROM_PORT

This commit is contained in:
orignal 2025-08-13 17:16:56 -04:00
parent 91027168f9
commit d496b15249

View File

@ -893,12 +893,18 @@ namespace client
SendSessionI2PError("Unsupported STYLE"); SendSessionI2PError("Unsupported STYLE");
return; return;
} }
auto fromPort = std::stoi(std::string (params[SAM_PARAM_FROM_PORT])); uint16_t fromPort = 0;
if (fromPort == -1) auto it = params.find (SAM_PARAM_FROM_PORT);
if (it != params.end ())
{
auto p = it->second;
auto res = std::from_chars(p.data(), p.data() + p.size(), fromPort);
if (res.ec != std::errc())
{ {
SendSessionI2PError("Invalid from port"); SendSessionI2PError("Invalid from port");
return; return;
} }
}
auto subsession = std::make_shared<SAMSubSession>(masterSession, id, type, fromPort); auto subsession = std::make_shared<SAMSubSession>(masterSession, id, type, fromPort);
if (m_Owner.AddSession (subsession)) if (m_Owner.AddSession (subsession))
{ {
@ -1365,8 +1371,9 @@ namespace client
SAMSubSession::SAMSubSession (std::shared_ptr<SAMMasterSession> master, std::string_view name, SAMSessionType type, uint16_t port): SAMSubSession::SAMSubSession (std::shared_ptr<SAMMasterSession> master, std::string_view name, SAMSessionType type, uint16_t port):
SAMSession (master->m_Bridge, name, type), masterSession (master), inPort (port) SAMSession (master->m_Bridge, name, type), masterSession (master), inPort (port)
{ {
if (Type == SAMSessionType::eSAMSessionTypeStream) if (Type == SAMSessionType::eSAMSessionTypeStream && port)
{ {
// additional streaming destination, use default if port is 0
auto d = masterSession->GetLocalDestination ()->CreateStreamingDestination (inPort); auto d = masterSession->GetLocalDestination ()->CreateStreamingDestination (inPort);
if (d) d->Start (); if (d) d->Start ();
} }