1
0
mirror of https://github.com/PurpleI2P/i2pd.git synced 2025-08-26 12:51:54 +00:00

handle session with STYLE=DATAGRAM2 and STYLE=DATAGRAM3

This commit is contained in:
orignal 2025-07-23 12:54:46 -04:00
parent 6b9278fdd3
commit d5769080c8
2 changed files with 27 additions and 7 deletions

View File

@ -353,8 +353,27 @@ namespace client
} }
SAMSessionType type = eSAMSessionTypeUnknown; SAMSessionType type = eSAMSessionTypeUnknown;
i2p::datagram::DatagramVersion datagramVersion = i2p::datagram::eDatagramV1;
if (style == SAM_VALUE_STREAM) type = eSAMSessionTypeStream; if (style == SAM_VALUE_STREAM) type = eSAMSessionTypeStream;
else if (style == SAM_VALUE_DATAGRAM) type = eSAMSessionTypeDatagram; #if __cplusplus >= 202002L // C++20
else if (style.starts_with (SAM_VALUE_DATAGRAM))
#else
else if (style.substr (0, SAM_VALUE_DATAGRAM.size ()) == SAM_VALUE_DATAGRAM)
#endif
{
// DATAGRAM, DATAGRAM1, DATAGRAM2, DATAGRAM3
type = eSAMSessionTypeDatagram;
if (style.size () > SAM_VALUE_DATAGRAM.size ())
{
switch (style[SAM_VALUE_DATAGRAM.size ()])
{
case '1': datagramVersion = i2p::datagram::eDatagramV1; break;
case '2': datagramVersion = i2p::datagram::eDatagramV2; break;
case '3': datagramVersion = i2p::datagram::eDatagramV3; break;
default: type = eSAMSessionTypeUnknown;
}
}
}
else if (style == SAM_VALUE_RAW) type = eSAMSessionTypeRaw; else if (style == SAM_VALUE_RAW) type = eSAMSessionTypeRaw;
else if (style == SAM_VALUE_MASTER) type = eSAMSessionTypeMaster; else if (style == SAM_VALUE_MASTER) type = eSAMSessionTypeMaster;
if (type == eSAMSessionTypeUnknown) if (type == eSAMSessionTypeUnknown)
@ -416,7 +435,7 @@ namespace client
if (type == eSAMSessionTypeDatagram || type == eSAMSessionTypeRaw) if (type == eSAMSessionTypeDatagram || type == eSAMSessionTypeRaw)
{ {
session->UDPEndpoint = forward; session->UDPEndpoint = forward;
auto dest = session->GetLocalDestination ()->CreateDatagramDestination (); auto dest = session->GetLocalDestination ()->CreateDatagramDestination (false, datagramVersion);
uint16_t port = 0; uint16_t port = 0;
if (forward) if (forward)
{ {

View File

@ -83,13 +83,14 @@ namespace client
const char SAM_PARAM_PORT[] = "PORT"; const char SAM_PARAM_PORT[] = "PORT";
const char SAM_PARAM_FROM_PORT[] = "FROM_PORT"; const char SAM_PARAM_FROM_PORT[] = "FROM_PORT";
const char SAM_VALUE_TRANSIENT[] = "TRANSIENT"; const char SAM_VALUE_TRANSIENT[] = "TRANSIENT";
const char SAM_VALUE_STREAM[] = "STREAM";
const char SAM_VALUE_DATAGRAM[] = "DATAGRAM";
const char SAM_VALUE_RAW[] = "RAW";
const char SAM_VALUE_MASTER[] = "MASTER";
const char SAM_VALUE_TRUE[] = "true"; const char SAM_VALUE_TRUE[] = "true";
const char SAM_VALUE_FALSE[] = "false"; const char SAM_VALUE_FALSE[] = "false";
constexpr std::string_view SAM_VALUE_STREAM { "STREAM" };
constexpr std::string_view SAM_VALUE_DATAGRAM { "DATAGRAM" };
constexpr std::string_view SAM_VALUE_RAW { "RAW" };
constexpr std::string_view SAM_VALUE_MASTER { "MASTER" };
enum SAMSocketType enum SAMSocketType
{ {
eSAMSocketTypeUnknown, eSAMSocketTypeUnknown,