From 3bef6383d9785be785acd489916113208a57d209 Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 13 Jun 2022 14:02:36 -0400 Subject: [PATCH] send update local RouterInfo --- libi2pd/NTCP2.cpp | 4 ++-- libi2pd/NTCP2.h | 2 +- libi2pd/SSU2Session.cpp | 23 +++++++++++++++++++++++ libi2pd/SSU2Session.h | 1 + libi2pd/TransportSession.h | 4 ++-- 5 files changed, 29 insertions(+), 5 deletions(-) diff --git a/libi2pd/NTCP2.cpp b/libi2pd/NTCP2.cpp index 0b20c964..8a2d6c7c 100644 --- a/libi2pd/NTCP2.cpp +++ b/libi2pd/NTCP2.cpp @@ -1169,9 +1169,9 @@ namespace transport } } - void NTCP2Session::SendLocalRouterInfo () + void NTCP2Session::SendLocalRouterInfo (bool update) { - if (!IsOutgoing ()) // we send it in SessionConfirmed + if (update || !IsOutgoing ()) // we send it in SessionConfirmed for ougoing session m_Server.GetService ().post (std::bind (&NTCP2Session::SendRouterInfo, shared_from_this ())); } diff --git a/libi2pd/NTCP2.h b/libi2pd/NTCP2.h index 46c47756..754f5a6d 100644 --- a/libi2pd/NTCP2.h +++ b/libi2pd/NTCP2.h @@ -148,7 +148,7 @@ namespace transport void ClientLogin (); // Alice void ServerLogin (); // Bob - void SendLocalRouterInfo (); // after handshake + void SendLocalRouterInfo (bool update); // after handshake or by update void SendI2NPMessages (const std::vector >& msgs); private: diff --git a/libi2pd/SSU2Session.cpp b/libi2pd/SSU2Session.cpp index 8cad9626..613b4163 100644 --- a/libi2pd/SSU2Session.cpp +++ b/libi2pd/SSU2Session.cpp @@ -161,6 +161,29 @@ namespace transport m_Server.GetService ().post (std::bind (&SSU2Session::Terminate, shared_from_this ())); } + void SSU2Session::SendLocalRouterInfo (bool update) + { + if (update || !IsOutgoing ()) + { + auto s = shared_from_this (); + m_Server.GetService ().post ([s]() + { + if (!s->IsEstablished ()) return; + uint8_t payload[SSU2_MAX_PAYLOAD_SIZE]; + size_t payloadSize = s->CreateRouterInfoBlock (payload, SSU2_MAX_PAYLOAD_SIZE - 32, i2p::context.GetSharedRouterInfo ()); + if (payloadSize) + { + if (payloadSize < SSU2_MAX_PAYLOAD_SIZE) + payloadSize += s->CreatePaddingBlock (payload + payloadSize, SSU2_MAX_PAYLOAD_SIZE - payloadSize); + s->SendData (payload, payloadSize); + } + else + s->SendFragmentedMessage (CreateDatabaseStoreMsg ()); + }); + } + + } + void SSU2Session::SendI2NPMessages (const std::vector >& msgs) { m_Server.GetService ().post (std::bind (&SSU2Session::PostI2NPMessages, shared_from_this (), msgs)); diff --git a/libi2pd/SSU2Session.h b/libi2pd/SSU2Session.h index d68e0733..bb8c48d0 100644 --- a/libi2pd/SSU2Session.h +++ b/libi2pd/SSU2Session.h @@ -173,6 +173,7 @@ namespace transport void CleanUp (uint64_t ts); void FlushData (); void Done () override; + void SendLocalRouterInfo (bool update) override; void SendI2NPMessages (const std::vector >& msgs) override; void Resend (uint64_t ts); bool IsEstablished () const { return m_State == eSSU2SessionStateEstablished; }; diff --git a/libi2pd/TransportSession.h b/libi2pd/TransportSession.h index 12d4894b..8370c1d5 100644 --- a/libi2pd/TransportSession.h +++ b/libi2pd/TransportSession.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2013-2020, The PurpleI2P Project +* Copyright (c) 2013-2022, The PurpleI2P Project * * This file is part of Purple i2pd project and licensed under BSD3 * @@ -96,7 +96,7 @@ namespace transport bool IsTerminationTimeoutExpired (uint64_t ts) const { return ts >= m_LastActivityTimestamp + GetTerminationTimeout (); }; - virtual void SendLocalRouterInfo () { SendI2NPMessages ({ CreateDatabaseStoreMsg () }); }; + virtual void SendLocalRouterInfo (bool update = false) { SendI2NPMessages ({ CreateDatabaseStoreMsg () }); }; virtual void SendI2NPMessages (const std::vector >& msgs) = 0; protected: