Browse Source

wait for acknowledment before using garlic tags

pull/48/head
orignal 10 years ago
parent
commit
8d67c5ebcd
  1. 24
      Garlic.cpp
  2. 3
      Garlic.h

24
Garlic.cpp

@ -16,7 +16,7 @@ namespace garlic @@ -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 @@ -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 @@ -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 @@ -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

@ -35,7 +35,7 @@ namespace garlic @@ -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 @@ -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…
Cancel
Save