mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-08 22:13:48 +01:00
different tunnel build record size
This commit is contained in:
parent
59dd60f5cb
commit
d47bf1bada
2 changed files with 15 additions and 6 deletions
|
@ -42,10 +42,11 @@ namespace tunnel
|
||||||
void Tunnel::Build (uint32_t replyMsgID, std::shared_ptr<OutboundTunnel> outboundTunnel)
|
void Tunnel::Build (uint32_t replyMsgID, std::shared_ptr<OutboundTunnel> outboundTunnel)
|
||||||
{
|
{
|
||||||
auto numHops = m_Config->GetNumHops ();
|
auto numHops = m_Config->GetNumHops ();
|
||||||
int numRecords = numHops <= STANDARD_NUM_RECORDS ? STANDARD_NUM_RECORDS : MAX_NUM_RECORDS;
|
const int numRecords = numHops <= STANDARD_NUM_RECORDS ? STANDARD_NUM_RECORDS : MAX_NUM_RECORDS;
|
||||||
auto msg = numRecords <= STANDARD_NUM_RECORDS ? NewI2NPShortMessage () : NewI2NPMessage ();
|
auto msg = numRecords <= STANDARD_NUM_RECORDS ? NewI2NPShortMessage () : NewI2NPMessage ();
|
||||||
*msg->GetPayload () = numRecords;
|
*msg->GetPayload () = numRecords;
|
||||||
msg->len += numRecords*TUNNEL_BUILD_RECORD_SIZE + 1;
|
const size_t recordSize = m_Config->IsShort () ? SHORT_TUNNEL_BUILD_RECORD_SIZE : TUNNEL_BUILD_RECORD_SIZE;
|
||||||
|
msg->len += numRecords*recordSize + 1;
|
||||||
// shuffle records
|
// shuffle records
|
||||||
std::vector<int> recordIndicies;
|
std::vector<int> recordIndicies;
|
||||||
for (int i = 0; i < numRecords; i++) recordIndicies.push_back(i);
|
for (int i = 0; i < numRecords; i++) recordIndicies.push_back(i);
|
||||||
|
@ -70,7 +71,7 @@ namespace tunnel
|
||||||
for (int i = numHops; i < numRecords; i++)
|
for (int i = numHops; i < numRecords; i++)
|
||||||
{
|
{
|
||||||
int idx = recordIndicies[i];
|
int idx = recordIndicies[i];
|
||||||
RAND_bytes (records + idx*TUNNEL_BUILD_RECORD_SIZE, TUNNEL_BUILD_RECORD_SIZE);
|
RAND_bytes (records + idx*recordSize, recordSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
// decrypt real records
|
// decrypt real records
|
||||||
|
|
|
@ -115,6 +115,8 @@ namespace tunnel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsShort () const { return m_IsShort; }
|
||||||
|
|
||||||
TunnelHopConfig * GetFirstHop () const
|
TunnelHopConfig * GetFirstHop () const
|
||||||
{
|
{
|
||||||
return m_FirstHop;
|
return m_FirstHop;
|
||||||
|
@ -193,10 +195,15 @@ namespace tunnel
|
||||||
for (const auto& it: peers)
|
for (const auto& it: peers)
|
||||||
{
|
{
|
||||||
TunnelHopConfig * hop;
|
TunnelHopConfig * hop;
|
||||||
|
if (m_IsShort)
|
||||||
|
hop = new ShortECIESTunnelHopConfig (it);
|
||||||
|
else
|
||||||
|
{
|
||||||
if (it->GetCryptoKeyType () == i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD)
|
if (it->GetCryptoKeyType () == i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD)
|
||||||
hop = new LongECIESTunnelHopConfig (it);
|
hop = new LongECIESTunnelHopConfig (it);
|
||||||
else
|
else
|
||||||
hop = new ElGamalTunnelHopConfig (it);
|
hop = new ElGamalTunnelHopConfig (it);
|
||||||
|
}
|
||||||
if (prev)
|
if (prev)
|
||||||
prev->SetNext (hop);
|
prev->SetNext (hop);
|
||||||
else
|
else
|
||||||
|
@ -209,6 +216,7 @@ namespace tunnel
|
||||||
private:
|
private:
|
||||||
|
|
||||||
TunnelHopConfig * m_FirstHop, * m_LastHop;
|
TunnelHopConfig * m_FirstHop, * m_LastHop;
|
||||||
|
bool m_IsShort = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ZeroHopsTunnelConfig: public TunnelConfig
|
class ZeroHopsTunnelConfig: public TunnelConfig
|
||||||
|
|
Loading…
Add table
Reference in a new issue