From d3a9cc8fdea5a132e946f199397fd5f3990db0d3 Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 2 Jun 2022 15:04:35 -0400 Subject: [PATCH] check if session is established before sending peer test --- libi2pd/SSU2.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/libi2pd/SSU2.cpp b/libi2pd/SSU2.cpp index 0041b20a..5b37b51b 100644 --- a/libi2pd/SSU2.cpp +++ b/libi2pd/SSU2.cpp @@ -1590,7 +1590,7 @@ namespace transport size_t SSU2Session::CreatePeerTestBlock (uint8_t * buf, size_t len) { auto localAddress = FindLocalAddress (); - if (localAddress) return 0; + if (!localAddress) return 0; // signed data uint32_t nonce; RAND_bytes ((uint8_t *)&nonce, 4); @@ -2150,14 +2150,17 @@ namespace transport auto it = m_SessionsByRouterHash.find (router->GetIdentHash ()); if (it != m_SessionsByRouterHash.end ()) { - it->second->SendPeerTest (); - return true; + if (it->second->IsEstablished ()) + it->second->SendPeerTest (); + else + { + auto s = it->second; + s->SetOnEstablished ([s]() { s->SendPeerTest (); }); + } + return true; } auto s = std::make_shared (*this, router, addr); - s->SetOnEstablished ([s]() - { - s->SendPeerTest (); - }); + s->SetOnEstablished ([s]() {s->SendPeerTest (); }); s->Connect (); return true; }