From 7035ead9e774406c45ff7c286a3a71ff1e3b8e5f Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 25 May 2016 12:55:58 -0400 Subject: [PATCH] provide reply tunnel expcilitly for LeaseSet --- Destination.cpp | 8 +++++++- I2NPProtocol.cpp | 11 +++++------ I2NPProtocol.h | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Destination.cpp b/Destination.cpp index c5a3beff..f64fe208 100644 --- a/Destination.cpp +++ b/Destination.cpp @@ -407,6 +407,12 @@ namespace client LogPrint (eLogError, "Destination: Can't publish LeaseSet. No outbound tunnels"); return; } + auto inbound = m_Pool->GetNextInboundTunnel (); + if (!inbound) + { + LogPrint (eLogError, "Destination: Can't publish LeaseSet. No inbound tunnels"); + return; + } auto floodfill = i2p::data::netdb.GetClosestFloodfill (m_LeaseSet->GetIdentHash (), m_ExcludedFloodfills); if (!floodfill) { @@ -417,7 +423,7 @@ namespace client m_ExcludedFloodfills.insert (floodfill->GetIdentHash ()); LogPrint (eLogDebug, "Destination: Publish LeaseSet of ", GetIdentHash ().ToBase32 ()); RAND_bytes ((uint8_t *)&m_PublishReplyToken, 4); - auto msg = WrapMessage (floodfill, i2p::CreateDatabaseStoreMsg (m_LeaseSet, m_PublishReplyToken)); + auto msg = WrapMessage (floodfill, i2p::CreateDatabaseStoreMsg (m_LeaseSet, m_PublishReplyToken, inbound)); m_PublishConfirmationTimer.expires_from_now (boost::posix_time::seconds(PUBLISH_CONFIRMATION_TIMEOUT)); m_PublishConfirmationTimer.async_wait (std::bind (&LeaseSetDestination::HandlePublishConfirmationTimer, shared_from_this (), std::placeholders::_1)); diff --git a/I2NPProtocol.cpp b/I2NPProtocol.cpp index e2451f68..1f1caab7 100644 --- a/I2NPProtocol.cpp +++ b/I2NPProtocol.cpp @@ -249,7 +249,7 @@ namespace i2p return m; } - std::shared_ptr CreateDatabaseStoreMsg (std::shared_ptr leaseSet, uint32_t replyToken) + std::shared_ptr CreateDatabaseStoreMsg (std::shared_ptr leaseSet, uint32_t replyToken, std::shared_ptr replyTunnel) { if (!leaseSet) return nullptr; auto m = NewI2NPShortMessage (); @@ -258,14 +258,13 @@ namespace i2p payload[DATABASE_STORE_TYPE_OFFSET] = 1; // LeaseSet htobe32buf (payload + DATABASE_STORE_REPLY_TOKEN_OFFSET, replyToken); size_t size = DATABASE_STORE_HEADER_SIZE; - if (replyToken) + if (replyToken && replyTunnel) { - auto leases = leaseSet->GetNonExpiredLeases (); - if (leases.size () > 0) + if (replyTunnel) { - htobe32buf (payload + size, leases[0]->tunnelID); + htobe32buf (payload + size, replyTunnel->GetNextTunnelID ()); size += 4; // reply tunnelID - memcpy (payload + size, leases[0]->tunnelGateway, 32); + memcpy (payload + size, replyTunnel->GetNextIdentHash (), 32); size += 32; // reply tunnel gateway } else diff --git a/I2NPProtocol.h b/I2NPProtocol.h index 113e8eb8..1eff8c16 100644 --- a/I2NPProtocol.h +++ b/I2NPProtocol.h @@ -224,7 +224,7 @@ namespace tunnel std::shared_ptr CreateDatabaseSearchReply (const i2p::data::IdentHash& ident, std::vector routers); std::shared_ptr CreateDatabaseStoreMsg (std::shared_ptr router = nullptr, uint32_t replyToken = 0); - std::shared_ptr CreateDatabaseStoreMsg (std::shared_ptr leaseSet, uint32_t replyToken = 0); + std::shared_ptr CreateDatabaseStoreMsg (std::shared_ptr leaseSet, uint32_t replyToken = 0, std::shared_ptr replyTunnel = nullptr); bool IsRouterInfoMsg (std::shared_ptr msg); bool HandleBuildRequestRecords (int num, uint8_t * records, uint8_t * clearText);