BOB ping command

This commit is contained in:
orignal 2025-08-19 15:21:44 -04:00
parent 1c42ba85ba
commit 39069e0bd6
5 changed files with 96 additions and 1 deletions

View file

@ -181,6 +181,7 @@ namespace garlic
{
if (!m_Destination) m_Destination.reset (new i2p::data::IdentHash (dest));
}
const i2p::data::IdentHash * GetDestinationPtr () const { return m_Destination ? m_Destination.get () : nullptr; }; // for pongs
bool CheckExpired (uint64_t ts); // true is expired
bool CanBeRestarted (uint64_t ts) const { return ts > m_SessionCreatedTimestamp + ECIESX25519_RESTART_TIMEOUT; }
bool IsInactive (uint64_t ts) const { return ts > m_LastActivityTimestamp + ECIESX25519_INACTIVITY_TIMEOUT && CanBeRestarted (ts); }

View file

@ -1991,6 +1991,7 @@ namespace stream
void StreamingDestination::Stop ()
{
ResetAcceptor ();
ResetPongHandler ();
m_PendingIncomingTimer.cancel ();
m_PendingIncomingStreams.clear ();
{
@ -2037,6 +2038,8 @@ namespace stream
{
// pong
LogPrint (eLogInfo, "Streaming: Pong received rSID=", packet->GetReceiveStreamID ());
if (m_PongHandler != nullptr)
m_PongHandler (packet->from ? packet->from->GetDestinationPtr () : nullptr);
DeletePacket (packet);
return;
}
@ -2216,6 +2219,16 @@ namespace stream
m_Acceptor = nullptr;
}
void StreamingDestination::SetPongHandler (const PongHandler& handler)
{
m_PongHandler = handler;
}
void StreamingDestination::ResetPongHandler ()
{
m_PongHandler = nullptr;
}
void StreamingDestination::AcceptOnce (const Acceptor& acceptor)
{
boost::asio::post (m_Owner->GetService (), [acceptor, this](void)

View file

@ -312,6 +312,7 @@ namespace stream
public:
typedef std::function<void (std::shared_ptr<Stream>)> Acceptor;
typedef std::function<void (const i2p::data::IdentHash *)> PongHandler;
StreamingDestination (std::shared_ptr<i2p::client::ClientDestination> owner, uint16_t localPort = 0, bool gzip = false);
~StreamingDestination ();
@ -330,7 +331,9 @@ namespace stream
void AcceptOnce (const Acceptor& acceptor);
void AcceptOnceAcceptor (std::shared_ptr<Stream> stream, Acceptor acceptor, Acceptor prev);
std::shared_ptr<Stream> AcceptStream (int timeout = 0); // sync
void SetPongHandler (const PongHandler& handler);
void ResetPongHandler ();
std::shared_ptr<i2p::client::ClientDestination> GetOwner () const { return m_Owner; };
void SetOwner (std::shared_ptr<i2p::client::ClientDestination> owner) { m_Owner = owner; };
uint16_t GetLocalPort () const { return m_LocalPort; };
@ -358,6 +361,7 @@ namespace stream
std::unordered_map<uint32_t, std::shared_ptr<Stream> > m_IncomingStreams; // receiveStreamID->stream
std::shared_ptr<Stream> m_LastStream;
Acceptor m_Acceptor;
PongHandler m_PongHandler;
std::list<std::shared_ptr<Stream> > m_PendingIncomingStreams;
boost::asio::deadline_timer m_PendingIncomingTimer;
std::unordered_map<uint32_t, std::list<Packet *> > m_SavedPackets; // receiveStreamID->packets, arrived before SYN