mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
4 tags for LeaseSet request
This commit is contained in:
parent
250af7f247
commit
be301dc090
23
Garlic.cpp
23
Garlic.cpp
@ -15,9 +15,9 @@ namespace i2p
|
|||||||
namespace garlic
|
namespace garlic
|
||||||
{
|
{
|
||||||
GarlicRoutingSession::GarlicRoutingSession (GarlicDestination * owner,
|
GarlicRoutingSession::GarlicRoutingSession (GarlicDestination * owner,
|
||||||
std::shared_ptr<const i2p::data::RoutingDestination> destination, int numTags):
|
std::shared_ptr<const i2p::data::RoutingDestination> destination, int numTags, bool attachLeaseSet):
|
||||||
m_Owner (owner), m_Destination (destination), m_NumTags (numTags),
|
m_Owner (owner), m_Destination (destination), m_NumTags (numTags),
|
||||||
m_LeaseSetUpdateStatus (numTags > 0 ? eLeaseSetUpdated : eLeaseSetUpToDate)
|
m_LeaseSetUpdateStatus (attachLeaseSet ? eLeaseSetUpdated : eLeaseSetDoNotSend)
|
||||||
{
|
{
|
||||||
// create new session tags and session key
|
// create new session tags and session key
|
||||||
m_Rnd.GenerateBlock (m_SessionKey, 32);
|
m_Rnd.GenerateBlock (m_SessionKey, 32);
|
||||||
@ -25,7 +25,7 @@ namespace garlic
|
|||||||
}
|
}
|
||||||
|
|
||||||
GarlicRoutingSession::GarlicRoutingSession (const uint8_t * sessionKey, const SessionTag& sessionTag):
|
GarlicRoutingSession::GarlicRoutingSession (const uint8_t * sessionKey, const SessionTag& sessionTag):
|
||||||
m_Owner (nullptr), m_Destination (nullptr), m_NumTags (1), m_LeaseSetUpdateStatus (eLeaseSetUpToDate)
|
m_Owner (nullptr), m_Destination (nullptr), m_NumTags (1), m_LeaseSetUpdateStatus (eLeaseSetDoNotSend)
|
||||||
{
|
{
|
||||||
memcpy (m_SessionKey, sessionKey, 32);
|
memcpy (m_SessionKey, sessionKey, 32);
|
||||||
m_Encryption.SetKey (m_SessionKey);
|
m_Encryption.SetKey (m_SessionKey);
|
||||||
@ -524,20 +524,12 @@ namespace garlic
|
|||||||
I2NPMessage * GarlicDestination::WrapMessage (std::shared_ptr<const i2p::data::RoutingDestination> destination,
|
I2NPMessage * GarlicDestination::WrapMessage (std::shared_ptr<const i2p::data::RoutingDestination> destination,
|
||||||
I2NPMessage * msg, bool attachLeaseSet)
|
I2NPMessage * msg, bool attachLeaseSet)
|
||||||
{
|
{
|
||||||
if (attachLeaseSet) // we should maintain this session
|
auto session = GetRoutingSession (destination, attachLeaseSet); // 32 tags by default
|
||||||
{
|
return session->WrapSingleMessage (msg);
|
||||||
auto session = GetRoutingSession (destination, 32); // 32 tags by default
|
|
||||||
return session->WrapSingleMessage (msg);
|
|
||||||
}
|
|
||||||
else // one time session
|
|
||||||
{
|
|
||||||
GarlicRoutingSession session (this, destination, 0); // don't use tag if no LeaseSet
|
|
||||||
return session.WrapSingleMessage (msg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<GarlicRoutingSession> GarlicDestination::GetRoutingSession (
|
std::shared_ptr<GarlicRoutingSession> GarlicDestination::GetRoutingSession (
|
||||||
std::shared_ptr<const i2p::data::RoutingDestination> destination, int numTags)
|
std::shared_ptr<const i2p::data::RoutingDestination> destination, bool attachLeaseSet)
|
||||||
{
|
{
|
||||||
auto it = m_Sessions.find (destination->GetIdentHash ());
|
auto it = m_Sessions.find (destination->GetIdentHash ());
|
||||||
std::shared_ptr<GarlicRoutingSession> session;
|
std::shared_ptr<GarlicRoutingSession> session;
|
||||||
@ -545,7 +537,8 @@ namespace garlic
|
|||||||
session = it->second;
|
session = it->second;
|
||||||
if (!session)
|
if (!session)
|
||||||
{
|
{
|
||||||
session = std::make_shared<GarlicRoutingSession> (this, destination, numTags);
|
session = std::make_shared<GarlicRoutingSession> (this, destination,
|
||||||
|
attachLeaseSet ? 40 : 4, attachLeaseSet); // 40 tags for connections and 4 for LS requests
|
||||||
std::unique_lock<std::mutex> l(m_SessionsMutex);
|
std::unique_lock<std::mutex> l(m_SessionsMutex);
|
||||||
m_Sessions[destination->GetIdentHash ()] = session;
|
m_Sessions[destination->GetIdentHash ()] = session;
|
||||||
}
|
}
|
||||||
|
13
Garlic.h
13
Garlic.h
@ -61,7 +61,8 @@ namespace garlic
|
|||||||
{
|
{
|
||||||
eLeaseSetUpToDate = 0,
|
eLeaseSetUpToDate = 0,
|
||||||
eLeaseSetUpdated,
|
eLeaseSetUpdated,
|
||||||
eLeaseSetSubmitted
|
eLeaseSetSubmitted,
|
||||||
|
eLeaseSetDoNotSend
|
||||||
};
|
};
|
||||||
|
|
||||||
struct UnconfirmedTags
|
struct UnconfirmedTags
|
||||||
@ -75,14 +76,18 @@ namespace garlic
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
GarlicRoutingSession (GarlicDestination * owner, std::shared_ptr<const i2p::data::RoutingDestination> destination, int numTags);
|
GarlicRoutingSession (GarlicDestination * owner, std::shared_ptr<const i2p::data::RoutingDestination> destination,
|
||||||
|
int numTags, bool attachLeaseSet);
|
||||||
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);
|
I2NPMessage * WrapSingleMessage (I2NPMessage * msg);
|
||||||
void MessageConfirmed (uint32_t msgID);
|
void MessageConfirmed (uint32_t msgID);
|
||||||
bool CleanupExpiredTags (); // returns true if something left
|
bool CleanupExpiredTags (); // returns true if something left
|
||||||
|
|
||||||
void SetLeaseSetUpdated () { m_LeaseSetUpdateStatus = eLeaseSetUpdated; };
|
void SetLeaseSetUpdated ()
|
||||||
|
{
|
||||||
|
if (m_LeaseSetUpdateStatus != eLeaseSetDoNotSend) m_LeaseSetUpdateStatus = eLeaseSetUpdated;
|
||||||
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@ -118,7 +123,7 @@ namespace garlic
|
|||||||
GarlicDestination (): m_LastTagsCleanupTime (0) {};
|
GarlicDestination (): m_LastTagsCleanupTime (0) {};
|
||||||
~GarlicDestination ();
|
~GarlicDestination ();
|
||||||
|
|
||||||
std::shared_ptr<GarlicRoutingSession> GetRoutingSession (std::shared_ptr<const i2p::data::RoutingDestination> destination, int numTags);
|
std::shared_ptr<GarlicRoutingSession> GetRoutingSession (std::shared_ptr<const i2p::data::RoutingDestination> destination, bool attachLeaseSet);
|
||||||
void CleanupRoutingSessions ();
|
void CleanupRoutingSessions ();
|
||||||
void RemoveCreatedSession (uint32_t msgID);
|
void RemoveCreatedSession (uint32_t msgID);
|
||||||
I2NPMessage * WrapMessage (std::shared_ptr<const i2p::data::RoutingDestination> destination,
|
I2NPMessage * WrapMessage (std::shared_ptr<const i2p::data::RoutingDestination> destination,
|
||||||
|
Loading…
Reference in New Issue
Block a user