Browse Source

re-create local LeaseSet only if expired

pull/93/head
orignal 10 years ago
parent
commit
2f5967537a
  1. 6
      Garlic.cpp
  2. 4
      Garlic.h
  3. 9
      I2NPProtocol.cpp
  4. 2
      I2NPProtocol.h
  5. 1
      Identity.h
  6. 1
      RouterContext.h
  7. 44
      Streaming.cpp
  8. 9
      Streaming.h
  9. 1
      TunnelPool.cpp

6
Garlic.cpp

@ -56,7 +56,7 @@ namespace garlic
} }
} }
I2NPMessage * GarlicRoutingSession::WrapSingleMessage (I2NPMessage * msg, const I2NPMessage * leaseSet) I2NPMessage * GarlicRoutingSession::WrapSingleMessage (I2NPMessage * msg, I2NPMessage * leaseSet)
{ {
I2NPMessage * m = NewI2NPMessage (); I2NPMessage * m = NewI2NPMessage ();
size_t len = 0; size_t len = 0;
@ -122,6 +122,8 @@ namespace garlic
FillI2NPMessageHeader (m, eI2NPGarlic); FillI2NPMessageHeader (m, eI2NPGarlic);
if (msg) if (msg)
DeleteI2NPMessage (msg); DeleteI2NPMessage (msg);
if (leaseSet)
DeleteI2NPMessage (leaseSet);
return m; return m;
} }
@ -294,7 +296,7 @@ namespace garlic
} }
I2NPMessage * GarlicRouting::WrapMessage (const i2p::data::RoutingDestination& destination, I2NPMessage * GarlicRouting::WrapMessage (const i2p::data::RoutingDestination& destination,
I2NPMessage * msg, const I2NPMessage * leaseSet) I2NPMessage * msg, I2NPMessage * leaseSet)
{ {
auto it = m_Sessions.find (destination.GetIdentHash ()); auto it = m_Sessions.find (destination.GetIdentHash ());
GarlicRoutingSession * session = nullptr; GarlicRoutingSession * session = nullptr;

4
Garlic.h

@ -45,7 +45,7 @@ namespace garlic
GarlicRoutingSession (const i2p::data::RoutingDestination * destination, int numTags); GarlicRoutingSession (const i2p::data::RoutingDestination * destination, int numTags);
GarlicRoutingSession (const uint8_t * sessionKey, const SessionTag& sessionTag); // one time encryption GarlicRoutingSession (const uint8_t * sessionKey, const SessionTag& sessionTag); // one time encryption
~GarlicRoutingSession (); ~GarlicRoutingSession ();
I2NPMessage * WrapSingleMessage (I2NPMessage * msg, const I2NPMessage * leaseSet); I2NPMessage * WrapSingleMessage (I2NPMessage * msg, I2NPMessage * leaseSet);
int GetNextTag () const { return m_NextTag; }; int GetNextTag () const { return m_NextTag; };
uint32_t GetFirstMsgID () const { return m_FirstMsgID; }; uint32_t GetFirstMsgID () const { return m_FirstMsgID; };
@ -106,7 +106,7 @@ namespace garlic
I2NPMessage * WrapSingleMessage (const i2p::data::RoutingDestination& destination, I2NPMessage * msg); I2NPMessage * WrapSingleMessage (const i2p::data::RoutingDestination& destination, I2NPMessage * msg);
I2NPMessage * WrapMessage (const i2p::data::RoutingDestination& destination, I2NPMessage * WrapMessage (const i2p::data::RoutingDestination& destination,
I2NPMessage * msg, const I2NPMessage * leaseSet = nullptr); I2NPMessage * msg, I2NPMessage * leaseSet = nullptr);
private: private:

9
I2NPProtocol.cpp

@ -209,15 +209,16 @@ namespace i2p
return m; return m;
} }
I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::LeaseSet& leaseSet) I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::LeaseSet * leaseSet)
{ {
if (!leaseSet) return nullptr;
I2NPMessage * m = NewI2NPMessage (); I2NPMessage * m = NewI2NPMessage ();
I2NPDatabaseStoreMsg * msg = (I2NPDatabaseStoreMsg *)m->GetPayload (); I2NPDatabaseStoreMsg * msg = (I2NPDatabaseStoreMsg *)m->GetPayload ();
memcpy (msg->key, leaseSet.GetIdentHash (), 32); memcpy (msg->key, leaseSet->GetIdentHash (), 32);
msg->type = 1; // LeaseSet msg->type = 1; // LeaseSet
msg->replyToken = 0; msg->replyToken = 0;
memcpy (m->GetPayload () + sizeof (I2NPDatabaseStoreMsg), leaseSet.GetBuffer (), leaseSet.GetBufferLen ()); memcpy (m->GetPayload () + sizeof (I2NPDatabaseStoreMsg), leaseSet->GetBuffer (), leaseSet->GetBufferLen ());
m->len += leaseSet.GetBufferLen () + sizeof (I2NPDatabaseStoreMsg); m->len += leaseSet->GetBufferLen () + sizeof (I2NPDatabaseStoreMsg);
FillI2NPMessageHeader (m, eI2NPDatabaseStore); FillI2NPMessageHeader (m, eI2NPDatabaseStore);
return m; return m;
} }

2
I2NPProtocol.h

@ -158,7 +158,7 @@ namespace tunnel
I2NPMessage * CreateDatabaseSearchReply (const i2p::data::IdentHash& ident, const i2p::data::RouterInfo * floodfill); I2NPMessage * CreateDatabaseSearchReply (const i2p::data::IdentHash& ident, const i2p::data::RouterInfo * floodfill);
I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::RouterInfo * router = nullptr); I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::RouterInfo * router = nullptr);
I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::LeaseSet& leaseSet); I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::LeaseSet * leaseSet);
I2NPBuildRequestRecordClearText CreateBuildRequestRecord ( I2NPBuildRequestRecordClearText CreateBuildRequestRecord (
const uint8_t * ourIdent, uint32_t receiveTunnelID, const uint8_t * ourIdent, uint32_t receiveTunnelID,

1
Identity.h

@ -156,7 +156,6 @@ namespace data
virtual const Identity& GetIdentity () const = 0; virtual const Identity& GetIdentity () const = 0;
virtual const uint8_t * GetEncryptionPrivateKey () const = 0; virtual const uint8_t * GetEncryptionPrivateKey () const = 0;
virtual const uint8_t * GetEncryptionPublicKey () const = 0; virtual const uint8_t * GetEncryptionPublicKey () const = 0;
virtual void UpdateLeaseSet () = 0; // LeaseSet must be updated
virtual void Sign (const uint8_t * buf, int len, uint8_t * signature) const = 0; virtual void Sign (const uint8_t * buf, int len, uint8_t * signature) const = 0;
}; };
} }

1
RouterContext.h

@ -28,7 +28,6 @@ namespace i2p
void UpdateAddress (const char * host); // called from SSU void UpdateAddress (const char * host); // called from SSU
// implements LocalDestination // implements LocalDestination
void UpdateLeaseSet () {};
const i2p::data::IdentHash& GetIdentHash () const { return m_RouterInfo.GetIdentHash (); }; const i2p::data::IdentHash& GetIdentHash () const { return m_RouterInfo.GetIdentHash (); };
const i2p::data::Identity& GetIdentity () const { return GetRouterIdentity (); }; const i2p::data::Identity& GetIdentity () const { return GetRouterIdentity (); };
const uint8_t * GetEncryptionPrivateKey () const { return GetPrivateKey (); }; const uint8_t * GetEncryptionPrivateKey () const { return GetPrivateKey (); };

44
Streaming.cpp

@ -281,11 +281,11 @@ namespace stream
bool Stream::SendPacket (const uint8_t * buf, size_t len) bool Stream::SendPacket (const uint8_t * buf, size_t len)
{ {
const I2NPMessage * leaseSet = nullptr; I2NPMessage * leaseSet = nullptr;
if (m_LeaseSetUpdated) if (m_LeaseSetUpdated)
{ {
leaseSet = m_LocalDestination->GetLeaseSet (); leaseSet = m_LocalDestination->GetLeaseSetMsg ();
m_LeaseSetUpdated = false; m_LeaseSetUpdated = false;
} }
@ -359,10 +359,9 @@ namespace stream
StreamingDestination::~StreamingDestination () StreamingDestination::~StreamingDestination ()
{ {
if (m_LeaseSet)
DeleteI2NPMessage (m_LeaseSet);
if (m_Pool) if (m_Pool)
i2p::tunnel::tunnels.DeleteTunnelPool (m_Pool); i2p::tunnel::tunnels.DeleteTunnelPool (m_Pool);
delete m_LeaseSet;
} }
void StreamingDestination::HandleNextPacket (Packet * packet) void StreamingDestination::HandleNextPacket (Packet * packet)
@ -403,33 +402,20 @@ namespace stream
} }
} }
void StreamingDestination::UpdateLeaseSet () I2NPMessage * StreamingDestination::GetLeaseSetMsg ()
{ {
auto newLeaseSet = CreateLeaseSet ();
// TODO: make it atomic
auto oldLeaseSet = m_LeaseSet;
m_LeaseSet = newLeaseSet;
if (oldLeaseSet)
DeleteI2NPMessage (oldLeaseSet);
for (auto it: m_Streams)
it.second->SetLeaseSetUpdated ();
}
const I2NPMessage * StreamingDestination::GetLeaseSet ()
{
if (!m_LeaseSet)
m_LeaseSet = CreateLeaseSet ();
else
RenewI2NPMessageHeader (m_LeaseSet);
return m_LeaseSet;
}
I2NPMessage * StreamingDestination::CreateLeaseSet () const
{
// TODO: should store actual LeaseSet rather than msg
if (!m_Pool) return nullptr; if (!m_Pool) return nullptr;
i2p::data::LeaseSet leaseSet(*m_Pool); if (!m_LeaseSet || m_LeaseSet->HasExpiredLeases ())
return CreateDatabaseStoreMsg (leaseSet); {
auto newLeaseSet = new i2p::data::LeaseSet (*m_Pool);
// TODO: make it atomic
auto oldLeaseSet = m_LeaseSet;
m_LeaseSet = newLeaseSet;
delete oldLeaseSet;
for (auto it: m_Streams)
it.second->SetLeaseSetUpdated ();
}
return CreateDatabaseStoreMsg (m_LeaseSet);
} }
void StreamingDestination::Sign (const uint8_t * buf, int len, uint8_t * signature) const void StreamingDestination::Sign (const uint8_t * buf, int len, uint8_t * signature) const

9
Streaming.h

@ -124,7 +124,7 @@ namespace stream
~StreamingDestination (); ~StreamingDestination ();
const i2p::data::PrivateKeys& GetKeys () const { return m_Keys; }; const i2p::data::PrivateKeys& GetKeys () const { return m_Keys; };
const I2NPMessage * GetLeaseSet (); I2NPMessage * GetLeaseSetMsg ();
i2p::tunnel::TunnelPool * GetTunnelPool () const { return m_Pool; }; i2p::tunnel::TunnelPool * GetTunnelPool () const { return m_Pool; };
Stream * CreateNewStream (boost::asio::io_service& service, const i2p::data::LeaseSet& remote); Stream * CreateNewStream (boost::asio::io_service& service, const i2p::data::LeaseSet& remote);
@ -132,17 +132,12 @@ namespace stream
void HandleNextPacket (Packet * packet); void HandleNextPacket (Packet * packet);
// implements LocalDestination // implements LocalDestination
void UpdateLeaseSet ();
const i2p::data::IdentHash& GetIdentHash () const { return m_IdentHash; }; const i2p::data::IdentHash& GetIdentHash () const { return m_IdentHash; };
const i2p::data::Identity& GetIdentity () const { return m_Keys.pub; }; const i2p::data::Identity& GetIdentity () const { return m_Keys.pub; };
const uint8_t * GetEncryptionPrivateKey () const { return m_EncryptionPrivateKey; }; const uint8_t * GetEncryptionPrivateKey () const { return m_EncryptionPrivateKey; };
const uint8_t * GetEncryptionPublicKey () const { return m_EncryptionPublicKey; }; const uint8_t * GetEncryptionPublicKey () const { return m_EncryptionPublicKey; };
void Sign (const uint8_t * buf, int len, uint8_t * signature) const; void Sign (const uint8_t * buf, int len, uint8_t * signature) const;
private:
I2NPMessage * CreateLeaseSet () const;
private: private:
std::map<uint32_t, Stream *> m_Streams; std::map<uint32_t, Stream *> m_Streams;
@ -151,7 +146,7 @@ namespace stream
uint8_t m_EncryptionPublicKey[256], m_EncryptionPrivateKey[256]; uint8_t m_EncryptionPublicKey[256], m_EncryptionPrivateKey[256];
i2p::tunnel::TunnelPool * m_Pool; i2p::tunnel::TunnelPool * m_Pool;
I2NPMessage * m_LeaseSet; i2p::data::LeaseSet * m_LeaseSet;
CryptoPP::DSA::PrivateKey m_SigningPrivateKey; CryptoPP::DSA::PrivateKey m_SigningPrivateKey;
}; };

1
TunnelPool.cpp

@ -38,7 +38,6 @@ namespace tunnel
if (it.second.second == expiredTunnel) it.second.second = nullptr; if (it.second.second == expiredTunnel) it.second.second = nullptr;
} }
m_LocalDestination.UpdateLeaseSet ();
} }
void TunnelPool::TunnelCreated (OutboundTunnel * createdTunnel) void TunnelPool::TunnelCreated (OutboundTunnel * createdTunnel)

Loading…
Cancel
Save