Browse Source

take LeaseSet from GarlicDestination

pull/102/head
orignal 10 years ago
parent
commit
fccadb752f
  1. 4
      Destination.h
  2. 26
      Garlic.cpp
  3. 13
      Garlic.h
  4. 3
      RouterContext.h
  5. 11
      Streaming.cpp

4
Destination.h

@ -23,7 +23,6 @@ namespace stream @@ -23,7 +23,6 @@ namespace stream
StreamingDestination (boost::asio::io_service& service, const i2p::data::PrivateKeys& keys, bool isPublic);
~StreamingDestination ();
const i2p::data::LeaseSet * GetLeaseSet ();
i2p::tunnel::TunnelPool * GetTunnelPool () const { return m_Pool; };
Stream * CreateNewOutgoingStream (const i2p::data::LeaseSet& remote);
@ -44,6 +43,9 @@ namespace stream @@ -44,6 +43,9 @@ namespace stream
const uint8_t * GetEncryptionPublicKey () const { return m_EncryptionPublicKey; };
void SetLeaseSetUpdated ();
// implements GarlicDestination
const i2p::data::LeaseSet * GetLeaseSet ();
private:
Stream * CreateNewIncomingStream ();

26
Garlic.cpp

@ -14,9 +14,10 @@ namespace i2p @@ -14,9 +14,10 @@ namespace i2p
{
namespace garlic
{
GarlicRoutingSession::GarlicRoutingSession (const i2p::data::RoutingDestination * destination, int numTags):
m_Destination (destination), m_IsAcknowledged (false), m_NumTags (numTags),
m_NextTag (-1), m_SessionTags (0), m_TagsCreationTime (0), m_LocalLeaseSet (nullptr)
GarlicRoutingSession::GarlicRoutingSession (GarlicDestination * owner,
const i2p::data::RoutingDestination * destination, int numTags):
m_Owner (owner), m_Destination (destination), m_IsAcknowledged (false),
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);
@ -31,8 +32,8 @@ namespace garlic @@ -31,8 +32,8 @@ namespace garlic
}
GarlicRoutingSession::GarlicRoutingSession (const uint8_t * sessionKey, const SessionTag& sessionTag):
m_Destination (nullptr), m_IsAcknowledged (true), m_NumTags (1), m_NextTag (0),
m_LocalLeaseSet (nullptr)
m_Owner (nullptr), m_Destination (nullptr), m_IsAcknowledged (true), m_NumTags (1),
m_NextTag (0)
{
memcpy (m_SessionKey, sessionKey, 32);
m_Encryption.SetKey (m_SessionKey);
@ -57,9 +58,8 @@ namespace garlic @@ -57,9 +58,8 @@ namespace garlic
}
}
I2NPMessage * GarlicRoutingSession::WrapSingleMessage (I2NPMessage * msg, const i2p::data::LeaseSet * leaseSet)
I2NPMessage * GarlicRoutingSession::WrapSingleMessage (I2NPMessage * msg, bool attachLeaseSet)
{
if (leaseSet) m_LocalLeaseSet = leaseSet;
I2NPMessage * m = NewI2NPMessage ();
size_t len = 0;
uint8_t * buf = m->GetPayload () + 4; // 4 bytes for length
@ -117,7 +117,7 @@ namespace garlic @@ -117,7 +117,7 @@ namespace garlic
}
}
// AES block
len += CreateAESBlock (buf, msg, leaseSet);
len += CreateAESBlock (buf, msg, attachLeaseSet);
m_NextTag++;
*(uint32_t *)(m->GetPayload ()) = htobe32 (len);
m->len += len + 4;
@ -166,7 +166,7 @@ namespace garlic @@ -166,7 +166,7 @@ namespace garlic
*numCloves = 0;
size++;
if (m_LocalLeaseSet)
if (m_Owner)
{
if (m_NextTag < 0) // new session
{
@ -183,7 +183,7 @@ namespace garlic @@ -183,7 +183,7 @@ namespace garlic
if (attachLeaseSet)
{
// clove if our leaseSet must be attached
auto leaseSet = CreateDatabaseStoreMsg (m_LocalLeaseSet);
auto leaseSet = CreateDatabaseStoreMsg (m_Owner->GetLeaseSet ());
size += CreateGarlicClove (payload + size, leaseSet, false);
DeleteI2NPMessage (leaseSet);
(*numCloves)++;
@ -235,9 +235,9 @@ namespace garlic @@ -235,9 +235,9 @@ namespace garlic
size_t GarlicRoutingSession::CreateDeliveryStatusClove (uint8_t * buf, uint32_t msgID)
{
size_t size = 0;
if (m_LocalLeaseSet)
if (m_Owner)
{
auto leases = m_LocalLeaseSet->GetNonExpiredLeases ();
auto leases = m_Owner->GetLeaseSet ()->GetNonExpiredLeases ();
if (!leases.empty ())
{
buf[size] = eGarlicDeliveryTypeTunnel << 5; // delivery instructions flag tunnel
@ -443,7 +443,7 @@ namespace garlic @@ -443,7 +443,7 @@ namespace garlic
session = it->second;
if (!session)
{
session = new GarlicRoutingSession (&destination, numTags);
session = new GarlicRoutingSession (this, &destination, numTags);
std::unique_lock<std::mutex> l(m_SessionsMutex);
m_Sessions[destination.GetIdentHash ()] = session;
}

13
Garlic.h

@ -39,15 +39,16 @@ namespace garlic @@ -39,15 +39,16 @@ namespace garlic
const int TAGS_EXPIRATION_TIMEOUT = 900; // 15 minutes
typedef i2p::data::Tag<32> SessionTag;
typedef i2p::data::Tag<32> SessionTag;
class GarlicDestination;
class GarlicRoutingSession
{
public:
GarlicRoutingSession (const i2p::data::RoutingDestination * destination, int numTags);
GarlicRoutingSession (GarlicDestination * owner, const i2p::data::RoutingDestination * destination, int numTags);
GarlicRoutingSession (const uint8_t * sessionKey, const SessionTag& sessionTag); // one time encryption
~GarlicRoutingSession ();
I2NPMessage * WrapSingleMessage (I2NPMessage * msg, const i2p::data::LeaseSet * leaseSet);
I2NPMessage * WrapSingleMessage (I2NPMessage * msg, bool attachLeaseSet = false);
int GetNextTag () const { return m_NextTag; };
bool IsAcknowledged () const { return m_IsAcknowledged; };
@ -64,13 +65,13 @@ namespace garlic @@ -64,13 +65,13 @@ namespace garlic
private:
GarlicDestination * m_Owner;
const i2p::data::RoutingDestination * m_Destination;
uint8_t m_SessionKey[32];
bool m_IsAcknowledged;
int m_NumTags, m_NextTag;
SessionTag * m_SessionTags; // m_NumTags*32 bytes
uint32_t m_TagsCreationTime; // seconds since epoch
const i2p::data::LeaseSet * m_LocalLeaseSet;
uint32_t m_TagsCreationTime; // seconds since epoch
i2p::crypto::CBCEncryption m_Encryption;
CryptoPP::AutoSeededRandomPool m_Rnd;
@ -90,6 +91,8 @@ namespace garlic @@ -90,6 +91,8 @@ namespace garlic
void AddSessionKey (const uint8_t * key, const uint8_t * tag); // one tag
void HandleGarlicMessage (I2NPMessage * msg);
virtual const i2p::data::LeaseSet * GetLeaseSet () = 0; // TODO
private:
void HandleAESBlock (uint8_t * buf, size_t len, std::shared_ptr<i2p::crypto::CBCDecryption> decryption,

3
RouterContext.h

@ -42,6 +42,9 @@ namespace i2p @@ -42,6 +42,9 @@ namespace i2p
const uint8_t * GetEncryptionPublicKey () const { return GetIdentity ().GetStandardIdentity ().publicKey; };
void SetLeaseSetUpdated () {};
void HandleDataMessage (const uint8_t * buf, size_t len) {};
// implements GarlicDestination
const i2p::data::LeaseSet * GetLeaseSet () { return nullptr; };
private:

11
Streaming.cpp

@ -410,13 +410,6 @@ namespace stream @@ -410,13 +410,6 @@ namespace stream
}
}
const i2p::data::LeaseSet * leaseSet = nullptr;
if (m_LeaseSetUpdated)
{
leaseSet = m_LocalDestination.GetLeaseSet ();
m_LeaseSetUpdated = false;
}
auto ts = i2p::util::GetMillisecondsSinceEpoch ();
if (ts >= m_CurrentRemoteLease.endDate)
UpdateCurrentRemoteLease ();
@ -427,14 +420,14 @@ namespace stream @@ -427,14 +420,14 @@ namespace stream
{
auto msg = m_RoutingSession->WrapSingleMessage (
m_LocalDestination.CreateDataMessage (it->GetBuffer (), it->GetLength ()),
leaseSet);
m_LeaseSetUpdated);
msgs.push_back (i2p::tunnel::TunnelMessageBlock
{
i2p::tunnel::eDeliveryTypeTunnel,
m_CurrentRemoteLease.tunnelGateway, m_CurrentRemoteLease.tunnelID,
msg
});
leaseSet = nullptr; // send leaseSet only one time
m_LeaseSetUpdated = false; // send leaseSet only one time
}
m_LocalDestination.SendTunnelDataMsgs (msgs);
}

Loading…
Cancel
Save