Compare commits

..

No commits in common. "79e8ccbb5b2f4306208f8fe776dd09566963fbea" and "7461b640e32fdd8cabe42557051f59fae166c3b5" have entirely different histories.

3 changed files with 42 additions and 56 deletions

View file

@ -477,7 +477,7 @@ namespace transport
HandleReceivedPackets (std::move (receivedPackets)); HandleReceivedPackets (std::move (receivedPackets));
} }
bool SSU2Server::AddSession (std::shared_ptr<SSU2Session> session) void SSU2Server::AddSession (std::shared_ptr<SSU2Session> session)
{ {
if (session) if (session)
{ {
@ -485,10 +485,8 @@ namespace transport
{ {
if (session->GetState () != eSSU2SessionStatePeerTest) if (session->GetState () != eSSU2SessionStatePeerTest)
AddSessionByRouterHash (session); AddSessionByRouterHash (session);
return true;
} }
} }
return false;
} }
void SSU2Server::RemoveSession (uint64_t connID) void SSU2Server::RemoveSession (uint64_t connID)

View file

@ -85,7 +85,7 @@ namespace transport
bool IsSyncClockFromPeers () const { return m_IsSyncClockFromPeers; }; bool IsSyncClockFromPeers () const { return m_IsSyncClockFromPeers; };
void AdjustTimeOffset (int64_t offset, std::shared_ptr<const i2p::data::IdentityEx> from); void AdjustTimeOffset (int64_t offset, std::shared_ptr<const i2p::data::IdentityEx> from);
bool AddSession (std::shared_ptr<SSU2Session> session); void AddSession (std::shared_ptr<SSU2Session> session);
void RemoveSession (uint64_t connID); void RemoveSession (uint64_t connID);
void RequestRemoveSession (uint64_t connID); void RequestRemoveSession (uint64_t connID);
void AddSessionByRouterHash (std::shared_ptr<SSU2Session> session); void AddSessionByRouterHash (std::shared_ptr<SSU2Session> session);

View file

@ -1931,9 +1931,9 @@ namespace transport
return; return;
} }
auto mts = i2p::util::GetMillisecondsSinceEpoch (); auto mts = i2p::util::GetMillisecondsSinceEpoch ();
uint32_t nonce = bufbe32toh (buf + 1); session->m_RelaySessions.emplace (bufbe32toh (buf + 1), // nonce
if (session->m_RelaySessions.emplace (nonce, std::make_pair (shared_from_this (), mts/1000)).second) std::make_pair (shared_from_this (), mts/1000) );
{
// send relay intro to Charlie // send relay intro to Charlie
auto r = i2p::data::netdb.FindRouter (GetRemoteIdentity ()->GetIdentHash ()); // Alice's RI auto r = i2p::data::netdb.FindRouter (GetRemoteIdentity ()->GetIdentHash ()); // Alice's RI
if (r && (r->IsUnreachable () || !i2p::data::netdb.PopulateRouterInfoBuffer (r))) r = nullptr; if (r && (r->IsUnreachable () || !i2p::data::netdb.PopulateRouterInfoBuffer (r))) r = nullptr;
@ -1951,9 +1951,6 @@ namespace transport
// Charlie always responds with RelayResponse // Charlie always responds with RelayResponse
session->m_SentPackets.emplace (packetNum, packet); session->m_SentPackets.emplace (packetNum, packet);
} }
else
LogPrint (eLogInfo, "SSU2: Relay request nonce ", nonce, " already exists. Ignore");
}
void SSU2Session::HandleRelayIntro (const uint8_t * buf, size_t len, int attempts) void SSU2Session::HandleRelayIntro (const uint8_t * buf, size_t len, int attempts)
{ {
@ -2038,13 +2035,8 @@ namespace transport
{ {
// send HolePunch // send HolePunch
auto holePunchSession = std::make_shared<SSU2HolePunchSession>(m_Server, nonce, ep, addr); auto holePunchSession = std::make_shared<SSU2HolePunchSession>(m_Server, nonce, ep, addr);
if (m_Server.AddSession (holePunchSession)) m_Server.AddSession (holePunchSession);
holePunchSession->SendHolePunch (packet->payload, packet->payloadSize); // relay response block holePunchSession->SendHolePunch (packet->payload, packet->payloadSize); // relay response block
else
{
LogPrint (eLogInfo, "SSU2: Relay intro nonce ", nonce, " already exists. Ignore");
return;
}
} }
packet->payloadSize += CreatePaddingBlock (packet->payload + packet->payloadSize, m_MaxPayloadSize - packet->payloadSize); packet->payloadSize += CreatePaddingBlock (packet->payload + packet->payloadSize, m_MaxPayloadSize - packet->payloadSize);
uint32_t packetNum = SendData (packet->payload, packet->payloadSize); uint32_t packetNum = SendData (packet->payload, packet->payloadSize);
@ -2162,8 +2154,7 @@ namespace transport
GetRemoteIdentity ()->GetIdentHash ()); GetRemoteIdentity ()->GetIdentHash ());
if (session) // session with Charlie if (session) // session with Charlie
{ {
if (m_Server.AddPeerTest (nonce, shared_from_this (), ts/1000)) m_Server.AddPeerTest (nonce, shared_from_this (), ts/1000);
{
auto packet = m_Server.GetSentPacketsPool ().AcquireShared (); auto packet = m_Server.GetSentPacketsPool ().AcquireShared ();
// Alice's RouterInfo // Alice's RouterInfo
auto r = i2p::data::netdb.FindRouter (GetRemoteIdentity ()->GetIdentHash ()); auto r = i2p::data::netdb.FindRouter (GetRemoteIdentity ()->GetIdentHash ());
@ -2187,9 +2178,6 @@ namespace transport
packet->sendTime = ts; packet->sendTime = ts;
session->m_SentPackets.emplace (packetNum, packet); session->m_SentPackets.emplace (packetNum, packet);
} }
else
LogPrint (eLogInfo, "SSU2: Peer test 1 nonce ", nonce, " already exists. Ignored");
}
else else
{ {
// Charlie not found, send error back to Alice // Charlie not found, send error back to Alice
@ -3055,7 +3043,7 @@ namespace transport
{ {
if (ts > it->second.second + SSU2_RELAY_NONCE_EXPIRATION_TIMEOUT) if (ts > it->second.second + SSU2_RELAY_NONCE_EXPIRATION_TIMEOUT)
{ {
LogPrint (eLogInfo, "SSU2: Relay nonce ", it->first, " was not responded in ", SSU2_RELAY_NONCE_EXPIRATION_TIMEOUT, " seconds, deleted"); LogPrint (eLogWarning, "SSU2: Relay nonce ", it->first, " was not responded in ", SSU2_RELAY_NONCE_EXPIRATION_TIMEOUT, " seconds, deleted");
it = m_RelaySessions.erase (it); it = m_RelaySessions.erase (it);
} }
else else