Browse Source

send update local RouterInfo

pull/1769/head
orignal 2 years ago
parent
commit
3bef6383d9
  1. 4
      libi2pd/NTCP2.cpp
  2. 2
      libi2pd/NTCP2.h
  3. 23
      libi2pd/SSU2Session.cpp
  4. 1
      libi2pd/SSU2Session.h
  5. 4
      libi2pd/TransportSession.h

4
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 ())); m_Server.GetService ().post (std::bind (&NTCP2Session::SendRouterInfo, shared_from_this ()));
} }

2
libi2pd/NTCP2.h

@ -148,7 +148,7 @@ namespace transport
void ClientLogin (); // Alice void ClientLogin (); // Alice
void ServerLogin (); // Bob void ServerLogin (); // Bob
void SendLocalRouterInfo (); // after handshake void SendLocalRouterInfo (bool update); // after handshake or by update
void SendI2NPMessages (const std::vector<std::shared_ptr<I2NPMessage> >& msgs); void SendI2NPMessages (const std::vector<std::shared_ptr<I2NPMessage> >& msgs);
private: private:

23
libi2pd/SSU2Session.cpp

@ -161,6 +161,29 @@ namespace transport
m_Server.GetService ().post (std::bind (&SSU2Session::Terminate, shared_from_this ())); 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<std::shared_ptr<I2NPMessage> >& msgs) void SSU2Session::SendI2NPMessages (const std::vector<std::shared_ptr<I2NPMessage> >& msgs)
{ {
m_Server.GetService ().post (std::bind (&SSU2Session::PostI2NPMessages, shared_from_this (), msgs)); m_Server.GetService ().post (std::bind (&SSU2Session::PostI2NPMessages, shared_from_this (), msgs));

1
libi2pd/SSU2Session.h

@ -173,6 +173,7 @@ namespace transport
void CleanUp (uint64_t ts); void CleanUp (uint64_t ts);
void FlushData (); void FlushData ();
void Done () override; void Done () override;
void SendLocalRouterInfo (bool update) override;
void SendI2NPMessages (const std::vector<std::shared_ptr<I2NPMessage> >& msgs) override; void SendI2NPMessages (const std::vector<std::shared_ptr<I2NPMessage> >& msgs) override;
void Resend (uint64_t ts); void Resend (uint64_t ts);
bool IsEstablished () const { return m_State == eSSU2SessionStateEstablished; }; bool IsEstablished () const { return m_State == eSSU2SessionStateEstablished; };

4
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 * This file is part of Purple i2pd project and licensed under BSD3
* *
@ -96,7 +96,7 @@ namespace transport
bool IsTerminationTimeoutExpired (uint64_t ts) const bool IsTerminationTimeoutExpired (uint64_t ts) const
{ return ts >= m_LastActivityTimestamp + GetTerminationTimeout (); }; { return ts >= m_LastActivityTimestamp + GetTerminationTimeout (); };
virtual void SendLocalRouterInfo () { SendI2NPMessages ({ CreateDatabaseStoreMsg () }); }; virtual void SendLocalRouterInfo (bool update = false) { SendI2NPMessages ({ CreateDatabaseStoreMsg () }); };
virtual void SendI2NPMessages (const std::vector<std::shared_ptr<I2NPMessage> >& msgs) = 0; virtual void SendI2NPMessages (const std::vector<std::shared_ptr<I2NPMessage> >& msgs) = 0;
protected: protected:

Loading…
Cancel
Save