diff --git a/I2NPProtocol.cpp b/I2NPProtocol.cpp index 2cd2b0b2..c31a4479 100644 --- a/I2NPProtocol.cpp +++ b/I2NPProtocol.cpp @@ -80,6 +80,15 @@ namespace i2p LogPrint (eLogError, "I2NP: message length ", len, " exceeds max length"); return msg; } + + std::shared_ptr CopyI2NPMessage (std::shared_ptr msg) + { + if (!msg) return nullptr; + auto newMsg = NewI2NPMessage (msg->len); + newMsg->offset = msg->offset; + *newMsg = *msg; + return newMsg; + } std::shared_ptr CreateDeliveryStatusMsg (uint32_t msgID) { diff --git a/I2NPProtocol.h b/I2NPProtocol.h index 898396d0..173b57fb 100644 --- a/I2NPProtocol.h +++ b/I2NPProtocol.h @@ -174,7 +174,7 @@ namespace tunnel from = other.from; return *this; } - + // for SSU only uint8_t * GetSSUHeader () { return buf + offset + I2NP_HEADER_SIZE - I2NP_SHORT_HEADER_SIZE; }; void FromSSU (uint32_t msgID) // we have received SSU message and convert it to regular @@ -215,7 +215,8 @@ namespace tunnel std::shared_ptr CreateI2NPMessage (I2NPMessageType msgType, const uint8_t * buf, size_t len, uint32_t replyMsgID = 0); std::shared_ptr CreateI2NPMessage (const uint8_t * buf, size_t len, std::shared_ptr from = nullptr); - + std::shared_ptr CopyI2NPMessage (std::shared_ptr msg); + std::shared_ptr CreateDeliveryStatusMsg (uint32_t msgID); std::shared_ptr CreateRouterInfoDatabaseLookupMsg (const uint8_t * key, const uint8_t * from, uint32_t replyTunnelID, bool exploratory = false, std::set * excludedPeers = nullptr); diff --git a/Tunnel.cpp b/Tunnel.cpp index 60030916..dbe87a2f 100644 --- a/Tunnel.cpp +++ b/Tunnel.cpp @@ -494,7 +494,7 @@ namespace tunnel if (IsRouterInfoMsg (msg) || typeID == eI2NPDatabaseSearchReply) // transit DatabaseStore my contain new/updated RI // or DatabaseSearchReply with new routers - i2p::data::netdb.PostI2NPMsg (msg); + i2p::data::netdb.PostI2NPMsg (CopyI2NPMessage (msg)); tunnel->SendTunnelDataMsg (msg); } diff --git a/TunnelEndpoint.cpp b/TunnelEndpoint.cpp index 0b730d35..a3907ce5 100644 --- a/TunnelEndpoint.cpp +++ b/TunnelEndpoint.cpp @@ -237,6 +237,11 @@ namespace tunnel } auto typeID = msg.data->GetTypeID (); LogPrint (eLogDebug, "TunnelMessage: handle fragment of ", msg.data->GetLength (), " bytes, msg type ", (int)typeID); + // catch RI or reply with new list of routers + if ((IsRouterInfoMsg (msg.data) || typeID == eI2NPDatabaseSearchReply) && + !m_IsInbound && msg.deliveryType != eDeliveryTypeLocal) + i2p::data::netdb.PostI2NPMsg (CopyI2NPMessage (msg.data)); + switch (msg.deliveryType) { case eDeliveryTypeLocal: @@ -257,10 +262,6 @@ namespace tunnel default: LogPrint (eLogError, "TunnelMessage: Unknown delivery type ", (int)msg.deliveryType); }; - // catch RI or reply with new list of routers - if ((IsRouterInfoMsg (msg.data) || typeID == eI2NPDatabaseSearchReply) && - !m_IsInbound && msg.deliveryType != eDeliveryTypeLocal) - i2p::data::netdb.PostI2NPMsg (msg.data); } } }