mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-12 06:07:54 +00:00
wait for acknowledment before using garlic tags
This commit is contained in:
parent
17fcd0c38f
commit
8d67c5ebcd
24
Garlic.cpp
24
Garlic.cpp
@ -16,7 +16,7 @@ namespace garlic
|
||||
{
|
||||
GarlicRoutingSession::GarlicRoutingSession (const i2p::data::RoutingDestination& destination, int numTags):
|
||||
m_Destination (destination), m_FirstMsgID (0), m_IsAcknowledged (false),
|
||||
m_NumTags (numTags), m_NextTag (-1), m_SessionTags (0)
|
||||
m_NumTags (numTags), m_NextTag (-1), m_SessionTags (0), m_TagsCreationTime (0)
|
||||
{
|
||||
// create new session tags and session key
|
||||
m_Rnd.GenerateBlock (m_SessionKey, 32);
|
||||
@ -40,6 +40,8 @@ namespace garlic
|
||||
{
|
||||
for (int i = 0; i < m_NumTags; i++)
|
||||
m_Rnd.GenerateBlock (m_SessionTags + i*32, 32);
|
||||
m_TagsCreationTime = i2p::util::GetSecondsSinceEpoch ();
|
||||
SetAcknowledged (false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,6 +50,24 @@ namespace garlic
|
||||
I2NPMessage * m = NewI2NPMessage ();
|
||||
size_t len = 0;
|
||||
uint8_t * buf = m->GetPayload () + 4; // 4 bytes for length
|
||||
|
||||
// take care about tags
|
||||
if (m_NumTags > 0)
|
||||
{
|
||||
if (i2p::util::GetSecondsSinceEpoch () >= m_TagsCreationTime + TAGS_EXPIRATION_TIMEOUT)
|
||||
{
|
||||
// old tags expired create new set
|
||||
LogPrint ("Garlic tags expired");
|
||||
GenerateSessionTags ();
|
||||
m_NextTag = -1;
|
||||
}
|
||||
else if (!m_IsAcknowledged) // new set of tags was not acknowledged
|
||||
{
|
||||
LogPrint ("Previous garlic tags was not acknowledged. Use ElGamal");
|
||||
m_NextTag = -1; // have to use ElGamal
|
||||
}
|
||||
}
|
||||
// create message
|
||||
if (m_NextTag < 0 || !m_NumTags) // new session
|
||||
{
|
||||
// create ElGamal block
|
||||
@ -253,7 +273,7 @@ namespace garlic
|
||||
session = it->second;
|
||||
if (!session)
|
||||
{
|
||||
session = new GarlicRoutingSession (destination, 4); // TODO: change it later
|
||||
session = new GarlicRoutingSession (destination, 32);
|
||||
m_Sessions[destination.GetIdentHash ()] = session;
|
||||
}
|
||||
|
||||
|
3
Garlic.h
3
Garlic.h
@ -35,7 +35,7 @@ namespace garlic
|
||||
};
|
||||
#pragma pack()
|
||||
|
||||
|
||||
const int TAGS_EXPIRATION_TIMEOUT = 660; // 15 minutes
|
||||
class GarlicRoutingSession
|
||||
{
|
||||
public:
|
||||
@ -66,6 +66,7 @@ namespace garlic
|
||||
bool m_IsAcknowledged;
|
||||
int m_NumTags, m_NextTag;
|
||||
uint8_t * m_SessionTags; // m_NumTags*32 bytes
|
||||
uint32_t m_TagsCreationTime; // seconds since epoch
|
||||
|
||||
CryptoPP::CBC_Mode<CryptoPP::AES>::Encryption m_Encryption;
|
||||
CryptoPP::AutoSeededRandomPool m_Rnd;
|
||||
|
Loading…
Reference in New Issue
Block a user