mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-23 09:14:13 +00:00
exclude already expired introducers
This commit is contained in:
parent
67b32005f6
commit
2cc9791bf2
@ -333,6 +333,21 @@ namespace data
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
supportedTransports |= eSSUV4; // in case if host or 6 caps is not preasented, we assume 4
|
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)
|
if (supportedTransports)
|
||||||
|
@ -96,7 +96,7 @@ namespace data
|
|||||||
typedef Tag<32> IntroKey; // should be castable to MacKey and AESKey
|
typedef Tag<32> IntroKey; // should be castable to MacKey and AESKey
|
||||||
struct Introducer
|
struct Introducer
|
||||||
{
|
{
|
||||||
Introducer (): iExp (0) {};
|
Introducer (): iPort (0), iExp (0) {};
|
||||||
boost::asio::ip::address iHost;
|
boost::asio::ip::address iHost;
|
||||||
int iPort;
|
int iPort;
|
||||||
IntroKey iKey;
|
IntroKey iKey;
|
||||||
|
@ -431,16 +431,17 @@ namespace transport
|
|||||||
return nullptr;
|
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 ());
|
auto address = router->GetSSUAddress (v4only || !context.SupportsV6 ());
|
||||||
if (address)
|
if (address)
|
||||||
CreateSession (router, address, peerTest);
|
return CreateSession (router, address, peerTest);
|
||||||
else
|
else
|
||||||
LogPrint (eLogWarning, "SSU: Router ", i2p::data::GetIdentHashAbbreviation (router->GetIdentHash ()), " doesn't have SSU address");
|
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)
|
std::shared_ptr<const i2p::data::RouterInfo::Address> address, bool peerTest)
|
||||||
{
|
{
|
||||||
if (router && address)
|
if (router && address)
|
||||||
@ -449,10 +450,14 @@ namespace transport
|
|||||||
m_Service.post (std::bind (&SSUServer::CreateSessionThroughIntroducer, this, router, address, peerTest)); // always V4 thread
|
m_Service.post (std::bind (&SSUServer::CreateSessionThroughIntroducer, this, router, address, peerTest)); // always V4 thread
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (address->host.is_unspecified ()) return false;
|
||||||
boost::asio::ip::udp::endpoint remoteEndpoint (address->host, address->port);
|
boost::asio::ip::udp::endpoint remoteEndpoint (address->host, address->port);
|
||||||
m_Service.post (std::bind (&SSUServer::CreateDirectSession, this, router, remoteEndpoint, peerTest));
|
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)
|
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
|
|||||||
for (int i = 0; i < numIntroducers; i++)
|
for (int i = 0; i < numIntroducers; i++)
|
||||||
{
|
{
|
||||||
auto intr = &(address->ssu->introducers[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
|
if (intr->iExp > 0 && ts > intr->iExp) continue; // skip expired introducer
|
||||||
boost::asio::ip::udp::endpoint ep (intr->iHost, intr->iPort);
|
boost::asio::ip::udp::endpoint ep (intr->iHost, intr->iPort);
|
||||||
if (ep.address ().is_v4 () && address->IsV4 ()) // ipv4
|
if (ep.address ().is_v4 () && address->IsV4 ()) // ipv4
|
||||||
|
@ -51,8 +51,8 @@ namespace transport
|
|||||||
~SSUServer ();
|
~SSUServer ();
|
||||||
void Start ();
|
void Start ();
|
||||||
void Stop ();
|
void Stop ();
|
||||||
void 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, 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,
|
||||||
std::shared_ptr<const i2p::data::RouterInfo::Address> address, bool peerTest = false);
|
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);
|
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;
|
std::shared_ptr<SSUSession> FindSession (std::shared_ptr<const i2p::data::RouterInfo> router) const;
|
||||||
|
@ -505,8 +505,8 @@ namespace transport
|
|||||||
}
|
}
|
||||||
if (address && address->IsReachableSSU ())
|
if (address && address->IsReachableSSU ())
|
||||||
{
|
{
|
||||||
m_SSUServer->CreateSession (peer.router, address);
|
if (m_SSUServer->CreateSession (peer.router, address))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user