Skip to content

Commit

Permalink
use shared_ptr for local LeaseSet
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Apr 7, 2015
1 parent 3a26383 commit 8c47bf9
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 18 deletions.
14 changes: 3 additions & 11 deletions Destination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace client
ClientDestination::ClientDestination (const i2p::data::PrivateKeys& keys, bool isPublic,
const std::map<std::string, std::string> * params):
m_IsRunning (false), m_Thread (nullptr), m_Work (m_Service),
m_Keys (keys), m_LeaseSet (nullptr), m_IsPublic (isPublic), m_PublishReplyToken (0),
m_Keys (keys), m_IsPublic (isPublic), m_PublishReplyToken (0),
m_DatagramDestination (nullptr), m_PublishConfirmationTimer (m_Service), m_CleanupTimer (m_Service)
{
i2p::crypto::GenerateElGamalKeyPair(i2p::context.GetRandomNumberGenerator (), m_EncryptionPrivateKey, m_EncryptionPublicKey);
Expand Down Expand Up @@ -148,7 +148,7 @@ namespace client
return nullptr;
}

const i2p::data::LeaseSet * ClientDestination::GetLeaseSet ()
std::shared_ptr<const i2p::data::LeaseSet> ClientDestination::GetLeaseSet ()
{
if (!m_Pool) return nullptr;
if (!m_LeaseSet)
Expand All @@ -158,15 +158,7 @@ namespace client

void ClientDestination::UpdateLeaseSet ()
{
auto newLeaseSet = new i2p::data::LeaseSet (*m_Pool);
if (!m_LeaseSet)
m_LeaseSet = newLeaseSet;
else
{
// TODO: implement it better
*m_LeaseSet = *newLeaseSet;
delete newLeaseSet;
}
m_LeaseSet.reset (new i2p::data::LeaseSet (*m_Pool));
}

bool ClientDestination::SubmitSessionKey (const uint8_t * key, const uint8_t * tag)
Expand Down
4 changes: 2 additions & 2 deletions Destination.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ namespace client
const uint8_t * GetEncryptionPublicKey () const { return m_EncryptionPublicKey; };

// implements GarlicDestination
const i2p::data::LeaseSet * GetLeaseSet ();
std::shared_ptr<const i2p::data::LeaseSet> GetLeaseSet ();
std::shared_ptr<i2p::tunnel::TunnelPool> GetTunnelPool () const { return m_Pool; }
void HandleI2NPMessage (const uint8_t * buf, size_t len, std::shared_ptr<i2p::tunnel::InboundTunnel> from);

Expand Down Expand Up @@ -129,7 +129,7 @@ namespace client
std::map<i2p::data::IdentHash, LeaseSetRequest *> m_LeaseSetRequests;

std::shared_ptr<i2p::tunnel::TunnelPool> m_Pool;
i2p::data::LeaseSet * m_LeaseSet;
std::shared_ptr<i2p::data::LeaseSet> m_LeaseSet;
bool m_IsPublic;
uint32_t m_PublishReplyToken;
std::set<i2p::data::IdentHash> m_ExcludedFloodfills; // for publishing
Expand Down
2 changes: 1 addition & 1 deletion Garlic.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ namespace garlic
virtual void ProcessDeliveryStatusMessage (I2NPMessage * msg);
virtual void SetLeaseSetUpdated ();

virtual const i2p::data::LeaseSet * GetLeaseSet () = 0; // TODO
virtual std::shared_ptr<const i2p::data::LeaseSet> GetLeaseSet () = 0; // TODO
virtual std::shared_ptr<i2p::tunnel::TunnelPool> GetTunnelPool () const = 0;
virtual void HandleI2NPMessage (const uint8_t * buf, size_t len, std::shared_ptr<i2p::tunnel::InboundTunnel> from) = 0;

Expand Down
2 changes: 1 addition & 1 deletion I2NPProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ namespace i2p
return m;
}

I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::LeaseSet * leaseSet, uint32_t replyToken)
I2NPMessage * CreateDatabaseStoreMsg (std::shared_ptr<const i2p::data::LeaseSet> leaseSet, uint32_t replyToken)
{
if (!leaseSet) return nullptr;
I2NPMessage * m = NewI2NPShortMessage ();
Expand Down
2 changes: 1 addition & 1 deletion I2NPProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ namespace tunnel
I2NPMessage * CreateDatabaseSearchReply (const i2p::data::IdentHash& ident, std::vector<i2p::data::IdentHash> routers);

I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::RouterInfo * router = nullptr, uint32_t replyToken = 0);
I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::LeaseSet * leaseSet, uint32_t replyToken = 0);
I2NPMessage * CreateDatabaseStoreMsg (std::shared_ptr<const i2p::data::LeaseSet> leaseSet, uint32_t replyToken = 0);

bool HandleBuildRequestRecords (int num, uint8_t * records, uint8_t * clearText);
void HandleVariableTunnelBuildMsg (uint32_t replyMsgID, uint8_t * buf, size_t len);
Expand Down
2 changes: 1 addition & 1 deletion NetDb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ namespace data
if (leaseSet) // we don't send back our LeaseSets
{
LogPrint ("Requested LeaseSet ", key, " found");
replyMsg = CreateDatabaseStoreMsg (leaseSet.get ());
replyMsg = CreateDatabaseStoreMsg (leaseSet);
}
}
if (!replyMsg)
Expand Down
2 changes: 1 addition & 1 deletion RouterContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace i2p
void SetLeaseSetUpdated () {};

// implements GarlicDestination
const i2p::data::LeaseSet * GetLeaseSet () { return nullptr; };
std::shared_ptr<const i2p::data::LeaseSet> GetLeaseSet () { return nullptr; };
std::shared_ptr<i2p::tunnel::TunnelPool> GetTunnelPool () const;
void HandleI2NPMessage (const uint8_t * buf, size_t len, std::shared_ptr<i2p::tunnel::InboundTunnel> from);

Expand Down

0 comments on commit 8c47bf9

Please sign in to comment.