Browse Source

exclude already expired introducers

pull/1656/head
orignal 4 years ago
parent
commit
2cc9791bf2
  1. 15
      libi2pd/RouterInfo.cpp
  2. 2
      libi2pd/RouterInfo.h
  3. 12
      libi2pd/SSU.cpp
  4. 4
      libi2pd/SSU.h
  5. 2
      libi2pd/Transports.cpp

15
libi2pd/RouterInfo.cpp

@ -333,6 +333,21 @@ namespace data @@ -333,6 +333,21 @@ namespace data
}
else
supportedTransports |= eSSUV4; // in case if host or 6 caps is not preasented, we assume 4
if (address->ssu && !address->ssu->introducers.empty ())
{
// exclude invalid introducers
uint32_t ts = i2p::util::GetSecondsSinceEpoch ();
int numValid = 0;
for (auto& it: address->ssu->introducers)
{
if (ts <= it.iExp && it.iPort > 0 &&
((it.iHost.is_v4 () && address->IsV4 ()) || (it.iHost.is_v6 () && address->IsV6 ())))
numValid++;
else
it.iPort = 0;
}
if (!numValid) address->ssu->introducers.resize (0);
}
}
}
if (supportedTransports)

2
libi2pd/RouterInfo.h

@ -96,7 +96,7 @@ namespace data @@ -96,7 +96,7 @@ namespace data
typedef Tag<32> IntroKey; // should be castable to MacKey and AESKey
struct Introducer
{
Introducer (): iExp (0) {};
Introducer (): iPort (0), iExp (0) {};
boost::asio::ip::address iHost;
int iPort;
IntroKey iKey;

12
libi2pd/SSU.cpp

@ -431,16 +431,17 @@ namespace transport @@ -431,16 +431,17 @@ namespace transport
return nullptr;
}
void SSUServer::CreateSession (std::shared_ptr<const i2p::data::RouterInfo> router, bool peerTest, bool v4only)
bool SSUServer::CreateSession (std::shared_ptr<const i2p::data::RouterInfo> router, bool peerTest, bool v4only)
{
auto address = router->GetSSUAddress (v4only || !context.SupportsV6 ());
if (address)
CreateSession (router, address, peerTest);
return CreateSession (router, address, peerTest);
else
LogPrint (eLogWarning, "SSU: Router ", i2p::data::GetIdentHashAbbreviation (router->GetIdentHash ()), " doesn't have SSU address");
return false;
}
void SSUServer::CreateSession (std::shared_ptr<const i2p::data::RouterInfo> router,
bool SSUServer::CreateSession (std::shared_ptr<const i2p::data::RouterInfo> router,
std::shared_ptr<const i2p::data::RouterInfo::Address> address, bool peerTest)
{
if (router && address)
@ -449,10 +450,14 @@ namespace transport @@ -449,10 +450,14 @@ namespace transport
m_Service.post (std::bind (&SSUServer::CreateSessionThroughIntroducer, this, router, address, peerTest)); // always V4 thread
else
{
if (address->host.is_unspecified ()) return false;
boost::asio::ip::udp::endpoint remoteEndpoint (address->host, address->port);
m_Service.post (std::bind (&SSUServer::CreateDirectSession, this, router, remoteEndpoint, peerTest));
}
}
else
return false;
return true;
}
void SSUServer::CreateDirectSession (std::shared_ptr<const i2p::data::RouterInfo> router, boost::asio::ip::udp::endpoint remoteEndpoint, bool peerTest)
@ -511,6 +516,7 @@ namespace transport @@ -511,6 +516,7 @@ namespace transport
for (int i = 0; i < numIntroducers; i++)
{
auto intr = &(address->ssu->introducers[i]);
if (!intr->iPort) continue; // skip invalid introducer
if (intr->iExp > 0 && ts > intr->iExp) continue; // skip expired introducer
boost::asio::ip::udp::endpoint ep (intr->iHost, intr->iPort);
if (ep.address ().is_v4 () && address->IsV4 ()) // ipv4

4
libi2pd/SSU.h

@ -51,8 +51,8 @@ namespace transport @@ -51,8 +51,8 @@ namespace transport
~SSUServer ();
void Start ();
void Stop ();
void CreateSession (std::shared_ptr<const i2p::data::RouterInfo> router, bool peerTest = false, bool v4only = false);
void CreateSession (std::shared_ptr<const i2p::data::RouterInfo> router,
bool CreateSession (std::shared_ptr<const i2p::data::RouterInfo> router, bool peerTest = false, bool v4only = false);
bool CreateSession (std::shared_ptr<const i2p::data::RouterInfo> router,
std::shared_ptr<const i2p::data::RouterInfo::Address> address, bool peerTest = false);
void CreateDirectSession (std::shared_ptr<const i2p::data::RouterInfo> router, boost::asio::ip::udp::endpoint remoteEndpoint, bool peerTest);
std::shared_ptr<SSUSession> FindSession (std::shared_ptr<const i2p::data::RouterInfo> router) const;

2
libi2pd/Transports.cpp

@ -505,7 +505,7 @@ namespace transport @@ -505,7 +505,7 @@ namespace transport
}
if (address && address->IsReachableSSU ())
{
m_SSUServer->CreateSession (peer.router, address);
if (m_SSUServer->CreateSession (peer.router, address))
return true;
}
}

Loading…
Cancel
Save