mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2026-06-04 10:51:41 +00:00
Added FROM_PORT and TO_PORT datagram options
This commit is contained in:
+32
-4
@@ -1288,9 +1288,25 @@ namespace client
|
||||
else
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
size_t l = sprintf_s ((char *)m_StreamBuffer, SAM_STREAM_BUFFER_SIZE, SAM_DATAGRAM_RECEIVED, base64.c_str (), (long unsigned int)len);
|
||||
size_t l = sprintf_s (
|
||||
(char *)m_StreamBuffer,
|
||||
SAM_STREAM_BUFFER_SIZE,
|
||||
SAM_DATAGRAM_RECEIVED,
|
||||
base64.c_str (),
|
||||
(long unsigned int)len,
|
||||
(unsigned)fromPort,
|
||||
(unsigned)toPort
|
||||
);
|
||||
#else
|
||||
size_t l = snprintf ((char *)m_StreamBuffer, SAM_STREAM_BUFFER_SIZE, SAM_DATAGRAM_RECEIVED, base64.c_str (), (long unsigned int)len);
|
||||
size_t l = snprintf (
|
||||
(char *)m_StreamBuffer,
|
||||
SAM_STREAM_BUFFER_SIZE,
|
||||
SAM_DATAGRAM_RECEIVED,
|
||||
base64.c_str (),
|
||||
(long unsigned int)len,
|
||||
(unsigned)fromPort,
|
||||
(unsigned)toPort
|
||||
);
|
||||
#endif
|
||||
if (len < SAM_STREAM_BUFFER_SIZE - l)
|
||||
{
|
||||
@@ -1661,6 +1677,18 @@ namespace client
|
||||
auto session = FindSession (sessionID);
|
||||
if (session)
|
||||
{
|
||||
uint16_t fromPort = 0;
|
||||
uint16_t toPort = 0;
|
||||
char *raw_params = strchr(destination, ' ');
|
||||
if (raw_params)
|
||||
{
|
||||
*raw_params = 0; raw_params++;
|
||||
auto params = SAMSocket::ExtractParams(raw_params);
|
||||
params.Get(SAM_PARAM_FROM_PORT, fromPort);
|
||||
params.Get(SAM_PARAM_TO_PORT, toPort);
|
||||
LogPrint (eLogInfo, "SAM: Datagram params are FROM_PORT=", fromPort, " TO_PORT=", toPort);
|
||||
}
|
||||
|
||||
auto localDest = session->GetLocalDestination ();
|
||||
auto datagramDest = localDest ? localDest->GetDatagramDestination () : nullptr;
|
||||
if (datagramDest)
|
||||
@@ -1687,9 +1715,9 @@ namespace client
|
||||
if (isDest)
|
||||
{
|
||||
if (session->Type == SAMSessionType::eSAMSessionTypeDatagram)
|
||||
datagramDest->SendDatagramTo ((uint8_t *)eol, payloadLen, ident);
|
||||
datagramDest->SendDatagramTo ((uint8_t *)eol, payloadLen, ident, fromPort, toPort);
|
||||
else if (session->Type == SAMSessionType::eSAMSessionTypeRaw)
|
||||
datagramDest->SendRawDatagramTo ((uint8_t *)eol, payloadLen, ident);
|
||||
datagramDest->SendRawDatagramTo ((uint8_t *)eol, payloadLen, ident, fromPort, toPort);
|
||||
else
|
||||
LogPrint (eLogError, "SAM: Unexpected session type ", (int)session->Type, "for session ", sessionID);
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace client
|
||||
const char SAM_DEST_REPLY_I2P_ERROR[] = "DEST REPLY RESULT=I2P_ERROR\n";
|
||||
const char SAM_NAMING_LOOKUP[] = "NAMING LOOKUP";
|
||||
const char SAM_NAMING_REPLY[] = "NAMING REPLY RESULT=OK NAME=%s VALUE=%s\n";
|
||||
const char SAM_DATAGRAM_RECEIVED[] = "DATAGRAM RECEIVED DESTINATION=%s SIZE=%lu\n";
|
||||
const char SAM_DATAGRAM_RECEIVED[] = "DATAGRAM RECEIVED DESTINATION=%s SIZE=%lu FROM_PORT=%u TO_PORT=%u\n";
|
||||
const char SAM_RAW_RECEIVED[] = "RAW RECEIVED SIZE=%lu\n";
|
||||
const char SAM_NAMING_REPLY_INVALID_KEY[] = "NAMING REPLY RESULT=INVALID_KEY NAME=%s\n";
|
||||
const char SAM_NAMING_REPLY_KEY_NOT_FOUND[] = "NAMING REPLY RESULT=KEY_NOT_FOUND NAME=%s\n";
|
||||
@@ -83,6 +83,7 @@ namespace client
|
||||
const char SAM_PARAM_HOST[] = "HOST";
|
||||
const char SAM_PARAM_PORT[] = "PORT";
|
||||
const char SAM_PARAM_FROM_PORT[] = "FROM_PORT";
|
||||
const char SAM_PARAM_TO_PORT[] = "TO_PORT";
|
||||
const char SAM_VALUE_TRANSIENT[] = "TRANSIENT";
|
||||
const char SAM_VALUE_TRUE[] = "true";
|
||||
const char SAM_VALUE_FALSE[] = "false";
|
||||
@@ -129,6 +130,8 @@ namespace client
|
||||
|
||||
bool IsSession(std::string_view id) const;
|
||||
|
||||
static i2p::util::Mapping ExtractParams (std::string_view buf);
|
||||
|
||||
private:
|
||||
|
||||
void TerminateClose() { Terminate(nullptr); }
|
||||
@@ -164,7 +167,6 @@ namespace client
|
||||
void SendStreamI2PError(const std::string & msg);
|
||||
void SendStreamCantReachPeer(const std::string & msg);
|
||||
size_t ProcessDatagramSend (char * buf, size_t len, const char * data); // from SAM 1.0
|
||||
static i2p::util::Mapping ExtractParams (std::string_view buf);
|
||||
|
||||
void Connect (std::shared_ptr<const i2p::data::LeaseSet> remote, std::shared_ptr<SAMSession> session = nullptr);
|
||||
void HandleConnectLeaseSetRequestComplete (std::shared_ptr<i2p::data::LeaseSet> leaseSet);
|
||||
|
||||
Reference in New Issue
Block a user