Browse Source

set status OK after peer test msg 5

pull/1774/head
orignal 2 years ago
parent
commit
aa21748e9a
  1. 34
      libi2pd/SSU2Session.cpp
  2. 3
      libi2pd/SSU2Session.h

34
libi2pd/SSU2Session.cpp

@ -9,7 +9,6 @@
#include <string.h> #include <string.h>
#include <openssl/rand.h> #include <openssl/rand.h>
#include "Log.h" #include "Log.h"
#include "RouterContext.h"
#include "Transports.h" #include "Transports.h"
#include "Gzip.h" #include "Gzip.h"
#include "NetDb.hpp" #include "NetDb.hpp"
@ -1693,10 +1692,8 @@ namespace transport
} }
else else
{ {
if (m_Address->IsV4 () && i2p::context.GetStatus () == eRouterStatusTesting) if (GetRouterStatus () == eRouterStatusTesting)
i2p::context.SetStatusSSU2 (eRouterStatusFirewalled); SetRouterStatus (eRouterStatusFirewalled);
if (m_Address->IsV6 () && i2p::context.GetStatusV6 () == eRouterStatusTesting)
i2p::context.SetStatusV6SSU2 (eRouterStatusFirewalled);
} }
} }
else else
@ -1715,6 +1712,7 @@ namespace transport
else else
{ {
LogPrint (eLogInfo, "SSU2: Peer test 4 error code ", (int)buf[1]); LogPrint (eLogInfo, "SSU2: Peer test 4 error code ", (int)buf[1]);
SetRouterStatus (eRouterStatusUnknown);
it->second.first->Terminate (); it->second.first->Terminate ();
} }
m_PeerTests.erase (it); m_PeerTests.erase (it);
@ -1731,6 +1729,7 @@ namespace transport
else else
// we received msg 5 before msg 4 // we received msg 5 before msg 4
m_State = eSSU2SessionStatePeerTestReceived; m_State = eSSU2SessionStatePeerTestReceived;
SetRouterStatus (eRouterStatusOK);
} }
else else
LogPrint (eLogWarning, "SSU2: Peer test 5 nonce mismatch ", nonce, " connID=", m_SourceConnID); LogPrint (eLogWarning, "SSU2: Peer test 5 nonce mismatch ", nonce, " connID=", m_SourceConnID);
@ -1746,8 +1745,6 @@ namespace transport
m_Server.RemoveSession (htobe64 (((uint64_t)nonce << 32) | nonce)); m_Server.RemoveSession (htobe64 (((uint64_t)nonce << 32) | nonce));
if (m_Address->IsV6 ()) if (m_Address->IsV6 ())
i2p::context.SetStatusV6 (eRouterStatusOK); // set status OK for ipv6 even if from SSU2 i2p::context.SetStatusV6 (eRouterStatusOK); // set status OK for ipv6 even if from SSU2
else
i2p::context.SetStatusSSU2 (eRouterStatusOK);
break; break;
default: default:
LogPrint (eLogWarning, "SSU2: PeerTest unexpected msg num ", buf[0]); LogPrint (eLogWarning, "SSU2: PeerTest unexpected msg num ", buf[0]);
@ -1809,6 +1806,29 @@ namespace transport
return nullptr; return nullptr;
} }
RouterStatus SSU2Session::GetRouterStatus () const
{
if (m_Address)
{
if (m_Address->IsV4 ())
return i2p::context.GetStatus ();
if (m_Address->IsV6 ())
return i2p::context.GetStatusV6 ();
}
return eRouterStatusUnknown;
}
void SSU2Session::SetRouterStatus (RouterStatus status) const
{
if (m_Address)
{
if (m_Address->IsV4 ())
i2p::context.SetStatusSSU2 (status);
else if (m_Address->IsV6 ())
i2p::context.SetStatusV6SSU2 (status);
}
}
size_t SSU2Session::CreateAddressBlock (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& ep) size_t SSU2Session::CreateAddressBlock (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& ep)
{ {
if (len < 9) return 0; if (len < 9) return 0;

3
libi2pd/SSU2Session.h

@ -17,6 +17,7 @@
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include "Crypto.h" #include "Crypto.h"
#include "RouterInfo.h" #include "RouterInfo.h"
#include "RouterContext.h"
#include "TransportSession.h" #include "TransportSession.h"
namespace i2p namespace i2p
@ -238,6 +239,8 @@ namespace transport
bool ExtractEndpoint (const uint8_t * buf, size_t size, boost::asio::ip::udp::endpoint& ep); bool ExtractEndpoint (const uint8_t * buf, size_t size, boost::asio::ip::udp::endpoint& ep);
size_t CreateEndpoint (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& ep); size_t CreateEndpoint (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& ep);
std::shared_ptr<const i2p::data::RouterInfo::Address> FindLocalAddress () const; std::shared_ptr<const i2p::data::RouterInfo::Address> FindLocalAddress () const;
RouterStatus GetRouterStatus () const;
void SetRouterStatus (RouterStatus status) const;
std::shared_ptr<const i2p::data::RouterInfo> ExtractRouterInfo (const uint8_t * buf, size_t size); std::shared_ptr<const i2p::data::RouterInfo> ExtractRouterInfo (const uint8_t * buf, size_t size);
void CreateNonce (uint64_t seqn, uint8_t * nonce); void CreateNonce (uint64_t seqn, uint8_t * nonce);
bool UpdateReceivePacketNum (uint32_t packetNum); // for Ack, returns false if duplicate bool UpdateReceivePacketNum (uint32_t packetNum); // for Ack, returns false if duplicate

Loading…
Cancel
Save