mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-08-26 10:10:24 +01:00
Merge branch 'openssl' into BandwithParameter
This commit is contained in:
commit
b3d566c6f2
15 changed files with 357 additions and 213 deletions
|
@ -60,28 +60,49 @@ namespace datagram
|
|||
{
|
||||
if (session)
|
||||
{
|
||||
if (session->GetVersion () == eDatagramV3)
|
||||
std::shared_ptr<I2NPMessage> msg;
|
||||
switch (session->GetVersion ())
|
||||
{
|
||||
constexpr uint8_t flags[] = { 0x00, 0x03 }; // datagram3, no options
|
||||
auto msg = CreateDataMessage ({{m_Owner->GetIdentity ()->GetIdentHash (), 32},
|
||||
{flags, 2}, {payload, len}}, fromPort, toPort, i2p::client::PROTOCOL_TYPE_DATAGRAM3, false); // datagram3
|
||||
session->SendMsg(msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_Owner->GetIdentity ()->GetSigningKeyType () == i2p::data::SIGNING_KEY_TYPE_DSA_SHA1)
|
||||
case eDatagramV3:
|
||||
{
|
||||
uint8_t hash[32];
|
||||
SHA256(payload, len, hash);
|
||||
m_Owner->Sign (hash, 32, m_Signature.data ());
|
||||
constexpr uint8_t flags[] = { 0x00, 0x03 }; // datagram3, no options
|
||||
msg = CreateDataMessage ({{m_Owner->GetIdentity ()->GetIdentHash (), 32},
|
||||
{flags, 2}, {payload, len}}, fromPort, toPort, i2p::client::PROTOCOL_TYPE_DATAGRAM3, false); // datagram3
|
||||
break;
|
||||
}
|
||||
else
|
||||
m_Owner->Sign (payload, len, m_Signature.data ());
|
||||
case eDatagramV1:
|
||||
{
|
||||
if (m_Owner->GetIdentity ()->GetSigningKeyType () == i2p::data::SIGNING_KEY_TYPE_DSA_SHA1)
|
||||
{
|
||||
uint8_t hash[32];
|
||||
SHA256(payload, len, hash);
|
||||
m_Owner->Sign (hash, 32, m_Signature.data ());
|
||||
}
|
||||
else
|
||||
m_Owner->Sign (payload, len, m_Signature.data ());
|
||||
msg = CreateDataMessage ({{m_From.data (), m_From.size ()}, {m_Signature.data (), m_Signature.size ()}, {payload, len}},
|
||||
fromPort, toPort, i2p::client::PROTOCOL_TYPE_DATAGRAM, !session->IsRatchets ()); // datagram1
|
||||
break;
|
||||
}
|
||||
case eDatagramV2:
|
||||
{
|
||||
constexpr uint8_t flags[] = { 0x00, 0x02 }; // datagram2, no options
|
||||
// signature
|
||||
std::vector<uint8_t> signedData (len + 32 + 2);
|
||||
memcpy (signedData.data (), m_Owner->GetIdentity ()->GetIdentHash (), 32);
|
||||
memcpy (signedData.data () + 32, flags, 2);
|
||||
memcpy (signedData.data () + 34, payload, len);
|
||||
m_Owner->Sign (signedData.data (), signedData.size (), m_Signature.data ());
|
||||
// TODO: offline signatures and options
|
||||
msg = CreateDataMessage ({{m_From.data (), m_From.size ()}, {flags, 2}, {payload, len},
|
||||
{m_Signature.data (), m_Signature.size ()}}, fromPort, toPort, i2p::client::PROTOCOL_TYPE_DATAGRAM2, false); // datagram2
|
||||
|
||||
auto msg = CreateDataMessage ({{m_From.data (), m_From.size ()}, {m_Signature.data (), m_Signature.size ()}, {payload, len}},
|
||||
fromPort, toPort, i2p::client::PROTOCOL_TYPE_DATAGRAM, !session->IsRatchets ()); // datagram1
|
||||
session->SendMsg(msg);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LogPrint (eLogError, "Datagram: datagram type ", (int)session->GetVersion (), " is not supported");
|
||||
}
|
||||
if (msg) session->SendMsg(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <string>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <charconv>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include "Crypto.h"
|
||||
#include "ECIESX25519AEADRatchetSession.h"
|
||||
|
@ -93,10 +94,8 @@ namespace client
|
|||
}
|
||||
it = params->find (I2CP_PARAM_DONT_PUBLISH_LEASESET);
|
||||
if (it != params->end ())
|
||||
{
|
||||
// override isPublic
|
||||
m_IsPublic = (it->second != "true");
|
||||
}
|
||||
m_IsPublic = GetBoolParamValue (it->second);
|
||||
it = params->find (I2CP_PARAM_LEASESET_TYPE);
|
||||
if (it != params->end ())
|
||||
m_LeaseSetType = std::stoi(it->second);
|
||||
|
@ -188,6 +187,24 @@ namespace client
|
|||
CleanUp (); // GarlicDestination
|
||||
}
|
||||
|
||||
bool LeaseSetDestination::GetBoolParamValue (std::string_view value)
|
||||
{
|
||||
bool ret = false;
|
||||
if (value == "true")
|
||||
ret = true;
|
||||
else if (value == "false")
|
||||
ret = false;
|
||||
else
|
||||
{
|
||||
int v = 0;
|
||||
auto res = std::from_chars(value.data(), value.data() + value.size(), v);
|
||||
if (res.ec != std::errc())
|
||||
LogPrint (eLogError, "Destination: Unable to parse bool param value ", value, ": ", std::make_error_code (res.ec).message ());
|
||||
ret = v;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool LeaseSetDestination::Reconfigure(std::map<std::string, std::string> params)
|
||||
{
|
||||
auto itr = params.find("i2cp.dontPublishLeaseSet");
|
||||
|
@ -1010,9 +1027,9 @@ namespace client
|
|||
m_StreamingInboundSpeed (DEFAULT_MAX_INBOUND_SPEED),
|
||||
m_StreamingMaxConcurrentStreams (DEFAULT_MAX_CONCURRENT_STREAMS),
|
||||
m_StreamingMaxWindowSize (i2p::stream::MAX_WINDOW_SIZE),
|
||||
m_IsStreamingAnswerPings (DEFAULT_ANSWER_PINGS), m_LastPort (0),
|
||||
m_DatagramDestination (nullptr), m_RefCounter (0), m_LastPublishedTimestamp (0),
|
||||
m_ReadyChecker(service)
|
||||
m_IsStreamingAnswerPings (DEFAULT_ANSWER_PINGS), m_IsStreamingDontSign (DEFAULT_DONT_SIGN),
|
||||
m_LastPort (0), m_DatagramDestination (nullptr), m_RefCounter (0),
|
||||
m_LastPublishedTimestamp (0), m_ReadyChecker(service)
|
||||
{
|
||||
if (keys.IsOfflineSignature () && GetLeaseSetType () == i2p::data::NETDB_STORE_TYPE_LEASESET)
|
||||
SetLeaseSetType (i2p::data::NETDB_STORE_TYPE_STANDARD_LEASESET2); // offline keys can be published with LS2 only
|
||||
|
@ -1096,16 +1113,11 @@ namespace client
|
|||
}
|
||||
it = params->find (I2CP_PARAM_STREAMING_ANSWER_PINGS);
|
||||
if (it != params->end ())
|
||||
{
|
||||
LogPrint (eLogDebug, "Destination: Reading parameter ", I2CP_PARAM_STREAMING_ANSWER_PINGS, " value ", it->second);
|
||||
if (it->second == "true")
|
||||
m_IsStreamingAnswerPings = true;
|
||||
else if (it->second == "false")
|
||||
m_IsStreamingAnswerPings = false;
|
||||
else
|
||||
m_IsStreamingAnswerPings = std::stoi (it->second); // 1 for true
|
||||
}
|
||||
|
||||
m_IsStreamingAnswerPings = GetBoolParamValue (it->second);
|
||||
it = params->find (I2CP_PARAM_STREAMING_DONT_SIGN);
|
||||
if (it != params->end ())
|
||||
m_IsStreamingDontSign = GetBoolParamValue (it->second);
|
||||
|
||||
if (GetLeaseSetType () == i2p::data::NETDB_STORE_TYPE_ENCRYPTED_LEASESET2)
|
||||
{
|
||||
// authentication for encrypted LeaseSet
|
||||
|
|
|
@ -102,6 +102,8 @@ namespace client
|
|||
const char I2CP_PARAM_STREAMING_MAX_CONCURRENT_STREAMS[] = "i2p.streaming.maxConcurrentStreams";
|
||||
const int DEFAULT_MAX_CONCURRENT_STREAMS = 2048;
|
||||
const char I2CP_PARAM_STREAMING_MAX_WINDOW_SIZE[] = "i2p.streaming.maxWindowSize";
|
||||
const char I2CP_PARAM_STREAMING_DONT_SIGN[] = "i2p.streaming.dontSign";
|
||||
const int DEFAULT_DONT_SIGN = false;
|
||||
|
||||
typedef std::function<void (std::shared_ptr<i2p::stream::Stream> stream)> StreamRequestComplete;
|
||||
|
||||
|
@ -174,6 +176,7 @@ namespace client
|
|||
int GetLeaseSetType () const { return m_LeaseSetType; };
|
||||
void SetLeaseSetType (int leaseSetType) { m_LeaseSetType = leaseSetType; };
|
||||
int GetAuthType () const { return m_AuthType; };
|
||||
static bool GetBoolParamValue (std::string_view value);
|
||||
virtual void CleanupDestination () {}; // additional clean up in derived classes
|
||||
virtual i2p::data::CryptoKeyType GetPreferredCryptoType () const = 0;
|
||||
// I2CP
|
||||
|
@ -272,6 +275,7 @@ namespace client
|
|||
int GetStreamingInboundSpeed () const { return m_StreamingInboundSpeed; }
|
||||
int GetStreamingMaxConcurrentStreams () const { return m_StreamingMaxConcurrentStreams; }
|
||||
bool IsStreamingAnswerPings () const { return m_IsStreamingAnswerPings; }
|
||||
bool IsStreamingDontSign () const { return m_IsStreamingDontSign; }
|
||||
int GetStreamingMaxWindowSize () const { return m_StreamingMaxWindowSize; }
|
||||
|
||||
// datagram
|
||||
|
@ -314,7 +318,7 @@ namespace client
|
|||
i2p::data::CryptoKeyType m_PreferredCryptoType;
|
||||
|
||||
int m_StreamingAckDelay,m_StreamingOutboundSpeed, m_StreamingInboundSpeed, m_StreamingMaxConcurrentStreams, m_StreamingMaxWindowSize;
|
||||
bool m_IsStreamingAnswerPings;
|
||||
bool m_IsStreamingAnswerPings, m_IsStreamingDontSign;
|
||||
std::shared_ptr<i2p::stream::StreamingDestination> m_StreamingDestination; // default
|
||||
std::map<uint16_t, std::shared_ptr<i2p::stream::StreamingDestination> > m_StreamingDestinationsByPorts;
|
||||
std::shared_ptr<i2p::stream::StreamingDestination> m_LastStreamingDestination; uint16_t m_LastPort; // for server tunnels
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace data
|
|||
const int NETDB_MIN_ROUTERS = 90;
|
||||
const int NETDB_MIN_FLOODFILLS = 5;
|
||||
const int NETDB_MIN_TRANSPORTS = 10 ; // otherwise assume offline
|
||||
const int NETDB_NUM_FLOODFILLS_THRESHOLD = 1500;
|
||||
const int NETDB_NUM_FLOODFILLS_THRESHOLD = 1800;
|
||||
const int NETDB_NUM_ROUTERS_THRESHOLD = 4*NETDB_NUM_FLOODFILLS_THRESHOLD;
|
||||
const int NETDB_TUNNEL_CREATION_RATE_THRESHOLD = 10; // in %
|
||||
const int NETDB_CHECK_FOR_EXPIRATION_UPTIME = 600; // 10 minutes, in seconds
|
||||
|
|
|
@ -34,7 +34,11 @@ namespace transport
|
|||
const int SSU2_RESEND_CHECK_MORE_TIMEOUT_VARIANCE = 9; // in milliseconds
|
||||
const size_t SSU2_MAX_RESEND_PACKETS = 128; // packets to resend at the time
|
||||
const uint64_t SSU2_SOCKET_MIN_BUFFER_SIZE = 128 * 1024;
|
||||
#if defined(__OpenBSD__)
|
||||
const uint64_t SSU2_SOCKET_MAX_BUFFER_SIZE = 2 * 1024 * 1024;
|
||||
#else
|
||||
const uint64_t SSU2_SOCKET_MAX_BUFFER_SIZE = 4 * 1024 * 1024;
|
||||
#endif
|
||||
const size_t SSU2_MAX_NUM_INTRODUCERS = 3;
|
||||
const size_t SSU2_MIN_RECEIVED_PACKET_SIZE = 40; // 16 byte short header + 8 byte minimum payload + 16 byte MAC
|
||||
const size_t SSU2_MAX_RECEIVED_QUEUE_SIZE = 2500; // in packets
|
||||
|
|
|
@ -91,16 +91,18 @@ namespace stream
|
|||
m_IsResendNeeded (false), m_IsFirstRttSample (false), m_IsSendTime (true),
|
||||
m_IsWinDropped (true), m_IsChoking2 (false), m_IsClientChoked (false), m_IsClientChoked2 (false),
|
||||
m_IsTimeOutResend (false), m_IsImmediateAckRequested (false), m_IsRemoteLeaseChangeInProgress (false),
|
||||
m_IsBufferEmpty (false), m_IsJavaClient (false), m_LocalDestination (local),
|
||||
m_RemoteLeaseSet (remote), m_ReceiveTimer (m_Service), m_SendTimer (m_Service), m_ResendTimer (m_Service),
|
||||
m_AckSendTimer (m_Service), m_NumSentBytes (0), m_NumReceivedBytes (0), m_Port (port),
|
||||
m_RTT (INITIAL_RTT), m_MinRTT (INITIAL_RTT), m_SlowRTT (INITIAL_RTT), m_FastRTT (INITIAL_RTT),
|
||||
m_WindowSize (INITIAL_WINDOW_SIZE), m_MaxWindowSize (local.GetOwner ()->GetStreamingMaxWindowSize ()),
|
||||
m_LastWindowDropSize (0), m_WindowDropTargetSize (0), m_WindowIncCounter (0), m_RTO (INITIAL_RTO),
|
||||
m_IsBufferEmpty (false), m_IsJavaClient (false), m_DontSign (local.GetOwner ()->IsStreamingDontSign ()),
|
||||
m_LocalDestination (local), m_RemoteLeaseSet (remote), m_ReceiveTimer (m_Service),
|
||||
m_SendTimer (m_Service), m_ResendTimer (m_Service), m_AckSendTimer (m_Service), m_NumSentBytes (0),
|
||||
m_NumReceivedBytes (0), m_Port (port), m_RTT (INITIAL_RTT), m_MinRTT (INITIAL_RTT),
|
||||
m_SlowRTT (INITIAL_RTT), m_FastRTT (INITIAL_RTT), m_WindowSize (INITIAL_WINDOW_SIZE),
|
||||
m_MaxWindowSize (local.GetOwner ()->GetStreamingMaxWindowSize ()), m_LastWindowDropSize (0),
|
||||
m_WindowDropTargetSize (0), m_WindowIncCounter (0), m_RTO (INITIAL_RTO),
|
||||
m_AckDelay (local.GetOwner ()->GetStreamingAckDelay ()), m_PrevRTTSample (INITIAL_RTT),
|
||||
m_Jitter (0), m_MinPacingTime (0),
|
||||
m_PacingTime (INITIAL_PACING_TIME), m_PacingTimeRem (0), m_LastSendTime (0), m_LastACKRecieveTime (0), m_ACKRecieveInterval (local.GetOwner ()->GetStreamingAckDelay ()), m_RemoteLeaseChangeTime (0), m_LastWindowIncTime (0), m_LastACKRequestTime (0),
|
||||
m_LastACKSendTime (0), m_PacketACKInterval (1), m_PacketACKIntervalRem (0), // for limit inbound speed
|
||||
m_Jitter (0), m_MinPacingTime (0), m_PacingTime (INITIAL_PACING_TIME), m_PacingTimeRem (0),
|
||||
m_LastSendTime (0), m_LastACKRecieveTime (0), m_ACKRecieveInterval (local.GetOwner ()->GetStreamingAckDelay ()),
|
||||
m_RemoteLeaseChangeTime (0), m_LastWindowIncTime (0), m_LastACKRequestTime (0), m_LastACKSendTime (0),
|
||||
m_PacketACKInterval (1), m_PacketACKIntervalRem (0), // for limit inbound speed
|
||||
m_NumResendAttempts (0), m_NumPacketsToSend (0), m_JitterAccum (0), m_JitterDiv (1), m_MTU (STREAMING_MTU)
|
||||
{
|
||||
RAND_bytes ((uint8_t *)&m_RecvStreamID, 4);
|
||||
|
@ -122,14 +124,16 @@ namespace stream
|
|||
m_IsResendNeeded (false), m_IsFirstRttSample (false), m_IsSendTime (true),
|
||||
m_IsWinDropped (true), m_IsChoking2 (false), m_IsClientChoked (false), m_IsClientChoked2 (false),
|
||||
m_IsTimeOutResend (false), m_IsImmediateAckRequested (false), m_IsRemoteLeaseChangeInProgress (false),
|
||||
m_IsBufferEmpty (false), m_IsJavaClient (false), m_LocalDestination (local),
|
||||
m_ReceiveTimer (m_Service), m_SendTimer (m_Service), m_ResendTimer (m_Service), m_AckSendTimer (m_Service),
|
||||
m_NumSentBytes (0), m_NumReceivedBytes (0), m_Port (0), m_RTT (INITIAL_RTT), m_MinRTT (INITIAL_RTT), m_SlowRTT (INITIAL_RTT), m_FastRTT (INITIAL_RTT),
|
||||
m_IsBufferEmpty (false), m_IsJavaClient (false), m_DontSign (local.GetOwner ()->IsStreamingDontSign ()),
|
||||
m_LocalDestination (local),m_ReceiveTimer (m_Service), m_SendTimer (m_Service),
|
||||
m_ResendTimer (m_Service), m_AckSendTimer (m_Service),m_NumSentBytes (0), m_NumReceivedBytes (0),
|
||||
m_Port (0), m_RTT (INITIAL_RTT), m_MinRTT (INITIAL_RTT), m_SlowRTT (INITIAL_RTT), m_FastRTT (INITIAL_RTT),
|
||||
m_WindowSize (INITIAL_WINDOW_SIZE), m_MaxWindowSize (local.GetOwner ()->GetStreamingMaxWindowSize ()),
|
||||
m_LastWindowDropSize (0), m_WindowDropTargetSize (0), m_WindowIncCounter (0),
|
||||
m_RTO (INITIAL_RTO), m_AckDelay (local.GetOwner ()->GetStreamingAckDelay ()),
|
||||
m_PrevRTTSample (INITIAL_RTT), m_Jitter (0), m_MinPacingTime (0),
|
||||
m_PacingTime (INITIAL_PACING_TIME), m_PacingTimeRem (0), m_LastSendTime (0), m_LastACKRecieveTime (0), m_ACKRecieveInterval (local.GetOwner ()->GetStreamingAckDelay ()), m_RemoteLeaseChangeTime (0), m_LastWindowIncTime (0), m_LastACKRequestTime (0),
|
||||
m_LastWindowDropSize (0), m_WindowDropTargetSize (0), m_WindowIncCounter (0), m_RTO (INITIAL_RTO),
|
||||
m_AckDelay (local.GetOwner ()->GetStreamingAckDelay ()),m_PrevRTTSample (INITIAL_RTT), m_Jitter (0),
|
||||
m_MinPacingTime (0), m_PacingTime (INITIAL_PACING_TIME), m_PacingTimeRem (0), m_LastSendTime (0),
|
||||
m_LastACKRecieveTime (0), m_ACKRecieveInterval (local.GetOwner ()->GetStreamingAckDelay ()),
|
||||
m_RemoteLeaseChangeTime (0), m_LastWindowIncTime (0), m_LastACKRequestTime (0),
|
||||
m_LastACKSendTime (0), m_PacketACKInterval (1), m_PacketACKIntervalRem (0), // for limit inbound speed
|
||||
m_NumResendAttempts (0), m_NumPacketsToSend (0), m_JitterAccum (0), m_JitterDiv (1), m_MTU (STREAMING_MTU)
|
||||
{
|
||||
|
@ -457,9 +461,10 @@ namespace stream
|
|||
optionData += 2;
|
||||
}
|
||||
|
||||
bool sessionVerified = false;
|
||||
bool verified = true;
|
||||
if (flags & PACKET_FLAG_FROM_INCLUDED)
|
||||
{
|
||||
verified = false;
|
||||
if (m_RemoteLeaseSet) m_RemoteIdentity = m_RemoteLeaseSet->GetIdentity ();
|
||||
if (!m_RemoteIdentity)
|
||||
m_RemoteIdentity = std::make_shared<i2p::data::IdentityEx>(optionData, optionSize);
|
||||
|
@ -486,8 +491,10 @@ namespace stream
|
|||
m_RemoteIdentity->GetIdentHash ().ToBase32 ());
|
||||
return false;
|
||||
}
|
||||
sessionVerified = true;
|
||||
}
|
||||
verified = true;
|
||||
if (!(flags & PACKET_FLAG_SIGNATURE_INCLUDED))
|
||||
m_DontSign = true; // don't sign if the remote didn't sign
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & PACKET_FLAG_MAX_PACKET_SIZE_INCLUDED)
|
||||
|
@ -497,6 +504,30 @@ namespace stream
|
|||
optionData += 2;
|
||||
}
|
||||
|
||||
if (flags & (PACKET_FLAG_CLOSE | PACKET_FLAG_RESET))
|
||||
{
|
||||
verified = false;
|
||||
if (packet->from)
|
||||
{
|
||||
if (!m_RemoteLeaseSet && m_RemoteIdentity)
|
||||
m_RemoteLeaseSet = m_LocalDestination.GetOwner ()->FindLeaseSet (m_RemoteIdentity->GetIdentHash ());
|
||||
if (m_RemoteLeaseSet)
|
||||
{
|
||||
uint8_t staticKey[32];
|
||||
m_RemoteLeaseSet->Encrypt (nullptr, staticKey);
|
||||
if (memcmp (packet->from->GetRemoteStaticKey (), staticKey, 32))
|
||||
{
|
||||
LogPrint (eLogError, "Streaming: Remote LeaseSet static key mismatch for stream from ",
|
||||
m_RemoteIdentity->GetIdentHash ().ToBase32 ());
|
||||
return false;
|
||||
}
|
||||
verified = true;
|
||||
}
|
||||
else // invalid stream, safe to close
|
||||
verified = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & PACKET_FLAG_OFFLINE_SIGNATURE)
|
||||
{
|
||||
if (!m_RemoteIdentity)
|
||||
|
@ -504,7 +535,7 @@ namespace stream
|
|||
LogPrint (eLogInfo, "Streaming: offline signature without identity");
|
||||
return false;
|
||||
}
|
||||
if (sessionVerified)
|
||||
if (verified)
|
||||
{
|
||||
// skip offline signature
|
||||
optionData += 4; // timestamp
|
||||
|
@ -552,7 +583,6 @@ namespace stream
|
|||
LogPrint (eLogError, "Streaming: Signature too big, ", signatureLen, " bytes");
|
||||
return false;
|
||||
}
|
||||
bool verified = sessionVerified;
|
||||
if (!verified) // packet was not verified through session
|
||||
{
|
||||
// verify actual signature
|
||||
|
@ -585,8 +615,13 @@ namespace stream
|
|||
{
|
||||
LogPrint (eLogError, "Streaming: Signature verification failed, sSID=", m_SendStreamID, ", rSID=", m_RecvStreamID);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!verified)
|
||||
{
|
||||
LogPrint (eLogError, "Streaming: Missing signature, sSID=", m_SendStreamID, ", rSID=", m_RecvStreamID);
|
||||
return false;
|
||||
}
|
||||
if (immediateAckRequested)
|
||||
SendQuickAck ();
|
||||
return true;
|
||||
|
@ -942,8 +977,8 @@ namespace stream
|
|||
m_RoutingSession = m_LocalDestination.GetOwner ()->GetRoutingSession (m_RemoteLeaseSet, true, !m_IsIncoming);
|
||||
m_MTU = (m_RoutingSession && m_RoutingSession->IsRatchets ()) ? STREAMING_MTU_RATCHETS : STREAMING_MTU;
|
||||
}
|
||||
uint16_t flags = PACKET_FLAG_SYNCHRONIZE | PACKET_FLAG_FROM_INCLUDED |
|
||||
PACKET_FLAG_SIGNATURE_INCLUDED | PACKET_FLAG_MAX_PACKET_SIZE_INCLUDED;
|
||||
uint16_t flags = PACKET_FLAG_SYNCHRONIZE | PACKET_FLAG_FROM_INCLUDED | PACKET_FLAG_MAX_PACKET_SIZE_INCLUDED;
|
||||
if (!m_DontSign) flags |= PACKET_FLAG_SIGNATURE_INCLUDED;
|
||||
if (isNoAck) flags |= PACKET_FLAG_NO_ACK;
|
||||
bool isOfflineSignature = m_LocalDestination.GetOwner ()->GetPrivateKeys ().IsOfflineSignature ();
|
||||
if (isOfflineSignature) flags |= PACKET_FLAG_OFFLINE_SIGNATURE;
|
||||
|
@ -957,18 +992,26 @@ namespace stream
|
|||
size += identityLen; // from
|
||||
htobe16buf (packet + size, m_MTU);
|
||||
size += 2; // max packet size
|
||||
if (isOfflineSignature)
|
||||
if (m_DontSign)
|
||||
{
|
||||
const auto& offlineSignature = m_LocalDestination.GetOwner ()->GetPrivateKeys ().GetOfflineSignature ();
|
||||
memcpy (packet + size, offlineSignature.data (), offlineSignature.size ());
|
||||
size += offlineSignature.size (); // offline signature
|
||||
htobe16buf (optionsSize, packet + size - 2 - optionsSize); // actual options size
|
||||
size += m_SendBuffer.Get (packet + size, m_MTU); // payload
|
||||
}
|
||||
uint8_t * signature = packet + size; // set it later
|
||||
memset (signature, 0, signatureLen); // zeroes for now
|
||||
size += signatureLen; // signature
|
||||
htobe16buf (optionsSize, packet + size - 2 - optionsSize); // actual options size
|
||||
size += m_SendBuffer.Get (packet + size, m_MTU); // payload
|
||||
m_LocalDestination.GetOwner ()->Sign (packet, size, signature);
|
||||
else
|
||||
{
|
||||
if (isOfflineSignature)
|
||||
{
|
||||
const auto& offlineSignature = m_LocalDestination.GetOwner ()->GetPrivateKeys ().GetOfflineSignature ();
|
||||
memcpy (packet + size, offlineSignature.data (), offlineSignature.size ());
|
||||
size += offlineSignature.size (); // offline signature
|
||||
}
|
||||
uint8_t * signature = packet + size; // set it later
|
||||
memset (signature, 0, signatureLen); // zeroes for now
|
||||
size += signatureLen; // signature
|
||||
htobe16buf (optionsSize, packet + size - 2 - optionsSize); // actual options size
|
||||
size += m_SendBuffer.Get (packet + size, m_MTU); // payload
|
||||
m_LocalDestination.GetOwner ()->Sign (packet, size, signature);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1178,28 +1221,34 @@ namespace stream
|
|||
size += 4; // sendStreamID
|
||||
memset (packet + size, 0, 14);
|
||||
size += 14; // all zeroes
|
||||
uint16_t flags = PACKET_FLAG_ECHO | PACKET_FLAG_SIGNATURE_INCLUDED | PACKET_FLAG_FROM_INCLUDED;
|
||||
uint16_t flags = PACKET_FLAG_ECHO | PACKET_FLAG_FROM_INCLUDED;
|
||||
if (!m_DontSign) flags |= PACKET_FLAG_SIGNATURE_INCLUDED;
|
||||
bool isOfflineSignature = m_LocalDestination.GetOwner ()->GetPrivateKeys ().IsOfflineSignature ();
|
||||
if (isOfflineSignature) flags |= PACKET_FLAG_OFFLINE_SIGNATURE;
|
||||
htobe16buf (packet + size, flags);
|
||||
size += 2; // flags
|
||||
size_t identityLen = m_LocalDestination.GetOwner ()->GetIdentity ()->GetFullLen ();
|
||||
size_t signatureLen = m_LocalDestination.GetOwner ()->GetPrivateKeys ().GetSignatureLen ();
|
||||
uint8_t * optionsSize = packet + size; // set options size later
|
||||
size += 2; // options size
|
||||
m_LocalDestination.GetOwner ()->GetIdentity ()->ToBuffer (packet + size, identityLen);
|
||||
size += identityLen; // from
|
||||
if (isOfflineSignature)
|
||||
{
|
||||
const auto& offlineSignature = m_LocalDestination.GetOwner ()->GetPrivateKeys ().GetOfflineSignature ();
|
||||
memcpy (packet + size, offlineSignature.data (), offlineSignature.size ());
|
||||
size += offlineSignature.size (); // offline signature
|
||||
}
|
||||
uint8_t * signature = packet + size; // set it later
|
||||
memset (signature, 0, signatureLen); // zeroes for now
|
||||
size += signatureLen; // signature
|
||||
htobe16buf (optionsSize, packet + size - 2 - optionsSize); // actual options size
|
||||
m_LocalDestination.GetOwner ()->Sign (packet, size, signature);
|
||||
if (m_DontSign)
|
||||
htobe16buf (optionsSize, packet + size - 2 - optionsSize); // actual options size
|
||||
else
|
||||
{
|
||||
if (isOfflineSignature)
|
||||
{
|
||||
const auto& offlineSignature = m_LocalDestination.GetOwner ()->GetPrivateKeys ().GetOfflineSignature ();
|
||||
memcpy (packet + size, offlineSignature.data (), offlineSignature.size ());
|
||||
size += offlineSignature.size (); // offline signature
|
||||
}
|
||||
size_t signatureLen = m_LocalDestination.GetOwner ()->GetPrivateKeys ().GetSignatureLen ();
|
||||
uint8_t * signature = packet + size; // set it later
|
||||
memset (signature, 0, signatureLen); // zeroes for now
|
||||
size += signatureLen; // signature
|
||||
htobe16buf (optionsSize, packet + size - 2 - optionsSize); // actual options size
|
||||
m_LocalDestination.GetOwner ()->Sign (packet, size, signature);
|
||||
}
|
||||
p.len = size;
|
||||
SendPackets (std::vector<Packet *> { &p });
|
||||
LogPrint (eLogDebug, "Streaming: Ping of ", p.len, " bytes sent");
|
||||
|
@ -1253,15 +1302,33 @@ namespace stream
|
|||
size++; // NACK count
|
||||
packet[size] = 0;
|
||||
size++; // resend delay
|
||||
htobe16buf (packet + size, PACKET_FLAG_CLOSE | PACKET_FLAG_SIGNATURE_INCLUDED);
|
||||
uint16_t flags = PACKET_FLAG_CLOSE;
|
||||
if (!m_DontSign) flags |= PACKET_FLAG_SIGNATURE_INCLUDED;
|
||||
bool isOfflineSignature = m_LocalDestination.GetOwner ()->GetPrivateKeys ().IsOfflineSignature ();
|
||||
if (isOfflineSignature) flags |= PACKET_FLAG_OFFLINE_SIGNATURE;
|
||||
htobe16buf (packet + size, flags);
|
||||
size += 2; // flags
|
||||
size_t signatureLen = m_LocalDestination.GetOwner ()->GetPrivateKeys ().GetSignatureLen ();
|
||||
htobe16buf (packet + size, signatureLen); // signature only
|
||||
size += 2; // options size
|
||||
uint8_t * signature = packet + size;
|
||||
memset (packet + size, 0, signatureLen);
|
||||
size += signatureLen; // signature
|
||||
m_LocalDestination.GetOwner ()->Sign (packet, size, signature);
|
||||
if (m_DontSign)
|
||||
{
|
||||
memset (packet + size, 0, 2); // no options
|
||||
size += 2; // options size
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isOfflineSignature)
|
||||
{
|
||||
const auto& offlineSignature = m_LocalDestination.GetOwner ()->GetPrivateKeys ().GetOfflineSignature ();
|
||||
memcpy (packet + size, offlineSignature.data (), offlineSignature.size ());
|
||||
size += offlineSignature.size (); // offline signature
|
||||
}
|
||||
size_t signatureLen = m_LocalDestination.GetOwner ()->GetPrivateKeys ().GetSignatureLen ();
|
||||
htobe16buf (packet + size, signatureLen); // signature only
|
||||
size += 2; // options size
|
||||
uint8_t * signature = packet + size;
|
||||
memset (packet + size, 0, signatureLen);
|
||||
size += signatureLen; // signature
|
||||
m_LocalDestination.GetOwner ()->Sign (packet, size, signature);
|
||||
}
|
||||
|
||||
p->len = size;
|
||||
boost::asio::post (m_Service, std::bind (&Stream::SendPacket, shared_from_this (), p));
|
||||
|
|
|
@ -273,22 +273,10 @@ namespace stream
|
|||
int32_t m_PreviousReceivedSequenceNumber;
|
||||
int32_t m_LastConfirmedReceivedSequenceNumber; // for limit inbound speed
|
||||
StreamStatus m_Status;
|
||||
bool m_IsIncoming;
|
||||
bool m_IsAckSendScheduled;
|
||||
bool m_IsNAcked;
|
||||
bool m_IsFirstACK;
|
||||
bool m_IsResendNeeded;
|
||||
bool m_IsFirstRttSample;
|
||||
bool m_IsSendTime;
|
||||
bool m_IsWinDropped;
|
||||
bool m_IsChoking2;
|
||||
bool m_IsClientChoked;
|
||||
bool m_IsClientChoked2;
|
||||
bool m_IsTimeOutResend;
|
||||
bool m_IsImmediateAckRequested;
|
||||
bool m_IsRemoteLeaseChangeInProgress;
|
||||
bool m_IsBufferEmpty;
|
||||
bool m_IsJavaClient;
|
||||
bool m_IsIncoming, m_IsAckSendScheduled, m_IsNAcked, m_IsFirstACK, m_IsResendNeeded,
|
||||
m_IsFirstRttSample, m_IsSendTime, m_IsWinDropped, m_IsChoking2, m_IsClientChoked,
|
||||
m_IsClientChoked2, m_IsTimeOutResend, m_IsImmediateAckRequested,
|
||||
m_IsRemoteLeaseChangeInProgress, m_IsBufferEmpty, m_IsJavaClient, m_DontSign;
|
||||
StreamingDestination& m_LocalDestination;
|
||||
std::shared_ptr<const i2p::data::IdentityEx> m_RemoteIdentity;
|
||||
std::shared_ptr<const i2p::crypto::Verifier> m_TransientVerifier; // in case of offline key
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
|
@ -14,6 +14,7 @@
|
|||
#include <vector>
|
||||
#include <string>
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/asio/deadline_timer.hpp> // for boost 1.89
|
||||
|
||||
namespace i2p
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue