mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 13:27:17 +01:00
handle 'reservedrange' param properly
This commit is contained in:
parent
2ad26dd4c9
commit
ca9782dd0d
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2013-2023, The PurpleI2P Project
|
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||||
*
|
*
|
||||||
* This file is part of Purple i2pd project and licensed under BSD3
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
|
@ -298,12 +298,10 @@ namespace util
|
||||||
|
|
||||||
bool ntcp2; i2p::config::GetOption("ntcp2.enabled", ntcp2);
|
bool ntcp2; i2p::config::GetOption("ntcp2.enabled", ntcp2);
|
||||||
bool ssu2; i2p::config::GetOption("ssu2.enabled", ssu2);
|
bool ssu2; i2p::config::GetOption("ssu2.enabled", ssu2);
|
||||||
bool checkInReserved; i2p::config::GetOption("reservedrange", checkInReserved);
|
|
||||||
LogPrint(eLogInfo, "Daemon: Starting Transports");
|
LogPrint(eLogInfo, "Daemon: Starting Transports");
|
||||||
if(!ssu2) LogPrint(eLogInfo, "Daemon: SSU2 disabled");
|
if(!ssu2) LogPrint(eLogInfo, "Daemon: SSU2 disabled");
|
||||||
if(!ntcp2) LogPrint(eLogInfo, "Daemon: NTCP2 disabled");
|
if(!ntcp2) LogPrint(eLogInfo, "Daemon: NTCP2 disabled");
|
||||||
|
|
||||||
i2p::transport::transports.SetCheckReserved(checkInReserved);
|
|
||||||
i2p::transport::transports.Start(ntcp2, ssu2);
|
i2p::transport::transports.Start(ntcp2, ssu2);
|
||||||
if (i2p::transport::transports.IsBoundSSU2() || i2p::transport::transports.IsBoundNTCP2())
|
if (i2p::transport::transports.IsBoundSSU2() || i2p::transport::transports.IsBoundNTCP2())
|
||||||
LogPrint(eLogInfo, "Daemon: Transports started");
|
LogPrint(eLogInfo, "Daemon: Transports started");
|
||||||
|
|
|
@ -1490,7 +1490,7 @@ namespace transport
|
||||||
if (!ec)
|
if (!ec)
|
||||||
{
|
{
|
||||||
LogPrint (eLogDebug, "NTCP2: Connected from ", ep);
|
LogPrint (eLogDebug, "NTCP2: Connected from ", ep);
|
||||||
if (!i2p::util::net::IsInReservedRange(ep.address ()))
|
if (!i2p::transport::transports.IsInReservedRange(ep.address ()))
|
||||||
{
|
{
|
||||||
if (m_PendingIncomingSessions.emplace (ep.address (), conn).second)
|
if (m_PendingIncomingSessions.emplace (ep.address (), conn).second)
|
||||||
{
|
{
|
||||||
|
@ -1537,7 +1537,7 @@ namespace transport
|
||||||
if (!ec)
|
if (!ec)
|
||||||
{
|
{
|
||||||
LogPrint (eLogDebug, "NTCP2: Connected from ", ep);
|
LogPrint (eLogDebug, "NTCP2: Connected from ", ep);
|
||||||
if (!i2p::util::net::IsInReservedRange(ep.address ()) ||
|
if (!i2p::transport::transports.IsInReservedRange(ep.address ()) ||
|
||||||
i2p::util::net::IsYggdrasilAddress (ep.address ()))
|
i2p::util::net::IsYggdrasilAddress (ep.address ()))
|
||||||
{
|
{
|
||||||
if (m_PendingIncomingSessions.emplace (ep.address (), conn).second)
|
if (m_PendingIncomingSessions.emplace (ep.address (), conn).second)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2013-2023, The PurpleI2P Project
|
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||||
*
|
*
|
||||||
* This file is part of Purple i2pd project and licensed under BSD3
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
|
@ -687,18 +687,16 @@ namespace data
|
||||||
while (it != end)
|
while (it != end)
|
||||||
{
|
{
|
||||||
boost::asio::ip::tcp::endpoint ep = *it;
|
boost::asio::ip::tcp::endpoint ep = *it;
|
||||||
if (
|
bool supported = false;
|
||||||
(
|
if (!ep.address ().is_unspecified ())
|
||||||
!i2p::util::net::IsInReservedRange(ep.address ()) && (
|
{
|
||||||
(ep.address ().is_v4 () && i2p::context.SupportsV4 ()) ||
|
if (ep.address ().is_v4 ())
|
||||||
(ep.address ().is_v6 () && i2p::context.SupportsV6 ())
|
supported = i2p::context.SupportsV4 ();
|
||||||
)
|
else if (ep.address ().is_v6 ())
|
||||||
) ||
|
supported = i2p::util::net::IsYggdrasilAddress (ep.address ()) ?
|
||||||
(
|
i2p::context.SupportsMesh () : i2p::context.SupportsV6 ();
|
||||||
i2p::util::net::IsYggdrasilAddress (ep.address ()) &&
|
}
|
||||||
i2p::context.SupportsMesh ()
|
if (supported)
|
||||||
)
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
s.lowest_layer().connect (ep, ecode);
|
s.lowest_layer().connect (ep, ecode);
|
||||||
if (!ecode)
|
if (!ecode)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2013-2023, The PurpleI2P Project
|
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||||
*
|
*
|
||||||
* This file is part of Purple i2pd project and licensed under BSD3
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
|
@ -21,6 +21,7 @@
|
||||||
#include "Base.h"
|
#include "Base.h"
|
||||||
#include "Timestamp.h"
|
#include "Timestamp.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
#include "Transports.h"
|
||||||
#include "NetDb.hpp"
|
#include "NetDb.hpp"
|
||||||
#include "RouterContext.h"
|
#include "RouterContext.h"
|
||||||
#include "RouterInfo.h"
|
#include "RouterInfo.h"
|
||||||
|
@ -253,7 +254,7 @@ namespace data
|
||||||
address->host = boost::asio::ip::address::from_string (value, ecode);
|
address->host = boost::asio::ip::address::from_string (value, ecode);
|
||||||
if (!ecode && !address->host.is_unspecified ())
|
if (!ecode && !address->host.is_unspecified ())
|
||||||
{
|
{
|
||||||
if (!i2p::util::net::IsInReservedRange (address->host) ||
|
if (!i2p::transport::transports.IsInReservedRange (address->host) ||
|
||||||
i2p::util::net::IsYggdrasilAddress (address->host))
|
i2p::util::net::IsYggdrasilAddress (address->host))
|
||||||
isHost = true;
|
isHost = true;
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2022-2023, The PurpleI2P Project
|
* Copyright (c) 2022-2024, The PurpleI2P Project
|
||||||
*
|
*
|
||||||
* This file is part of Purple i2pd project and licensed under BSD3
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
|
@ -566,7 +566,7 @@ namespace transport
|
||||||
else
|
else
|
||||||
it1->second->ProcessRetry (buf, len);
|
it1->second->ProcessRetry (buf, len);
|
||||||
}
|
}
|
||||||
else if (!i2p::util::net::IsInReservedRange(senderEndpoint.address ()) && senderEndpoint.port ())
|
else if (!i2p::transport::transports.IsInReservedRange(senderEndpoint.address ()) && senderEndpoint.port ())
|
||||||
{
|
{
|
||||||
// assume new incoming session
|
// assume new incoming session
|
||||||
auto session = std::make_shared<SSU2Session> (*this);
|
auto session = std::make_shared<SSU2Session> (*this);
|
||||||
|
@ -666,7 +666,7 @@ namespace transport
|
||||||
bool isValidEndpoint = !address->host.is_unspecified () && address->port;
|
bool isValidEndpoint = !address->host.is_unspecified () && address->port;
|
||||||
if (isValidEndpoint)
|
if (isValidEndpoint)
|
||||||
{
|
{
|
||||||
if (i2p::util::net::IsInReservedRange(address->host)) return false;
|
if (i2p::transport::transports.IsInReservedRange(address->host)) return false;
|
||||||
auto s = FindPendingOutgoingSession (boost::asio::ip::udp::endpoint (address->host, address->port));
|
auto s = FindPendingOutgoingSession (boost::asio::ip::udp::endpoint (address->host, address->port));
|
||||||
if (s)
|
if (s)
|
||||||
{
|
{
|
||||||
|
@ -753,7 +753,7 @@ namespace transport
|
||||||
if (addr)
|
if (addr)
|
||||||
{
|
{
|
||||||
bool isValidEndpoint = !addr->host.is_unspecified () && addr->port &&
|
bool isValidEndpoint = !addr->host.is_unspecified () && addr->port &&
|
||||||
!i2p::util::net::IsInReservedRange(addr->host);
|
!i2p::transport::transports.IsInReservedRange(addr->host);
|
||||||
if (isValidEndpoint)
|
if (isValidEndpoint)
|
||||||
{
|
{
|
||||||
auto s = FindPendingOutgoingSession (boost::asio::ip::udp::endpoint (addr->host, addr->port));
|
auto s = FindPendingOutgoingSession (boost::asio::ip::udp::endpoint (addr->host, addr->port));
|
||||||
|
|
|
@ -1471,7 +1471,7 @@ namespace transport
|
||||||
ResendHandshakePacket (); // assume we receive
|
ResendHandshakePacket (); // assume we receive
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (from != m_RemoteEndpoint && !i2p::util::net::IsInReservedRange (from.address ()))
|
if (from != m_RemoteEndpoint && !i2p::transport::transports.IsInReservedRange (from.address ()))
|
||||||
{
|
{
|
||||||
LogPrint (eLogInfo, "SSU2: Remote endpoint update ", m_RemoteEndpoint, "->", from);
|
LogPrint (eLogInfo, "SSU2: Remote endpoint update ", m_RemoteEndpoint, "->", from);
|
||||||
m_RemoteEndpoint = from;
|
m_RemoteEndpoint = from;
|
||||||
|
@ -1753,7 +1753,7 @@ namespace transport
|
||||||
if (ExtractEndpoint (buf, len, ep))
|
if (ExtractEndpoint (buf, len, ep))
|
||||||
{
|
{
|
||||||
LogPrint (eLogInfo, "SSU2: Our external address is ", ep);
|
LogPrint (eLogInfo, "SSU2: Our external address is ", ep);
|
||||||
if (!i2p::util::net::IsInReservedRange (ep.address ()))
|
if (!i2p::transport::transports.IsInReservedRange (ep.address ()))
|
||||||
{
|
{
|
||||||
i2p::context.UpdateAddress (ep.address ());
|
i2p::context.UpdateAddress (ep.address ());
|
||||||
// check our port
|
// check our port
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2013-2023, The PurpleI2P Project
|
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||||
*
|
*
|
||||||
* This file is part of Purple i2pd project and licensed under BSD3
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
|
@ -505,7 +505,7 @@ namespace transport
|
||||||
if (!m_NTCP2Server) continue;
|
if (!m_NTCP2Server) continue;
|
||||||
std::shared_ptr<const RouterInfo::Address> address = (tr == i2p::data::RouterInfo::eNTCP2V6) ?
|
std::shared_ptr<const RouterInfo::Address> address = (tr == i2p::data::RouterInfo::eNTCP2V6) ?
|
||||||
peer.router->GetPublishedNTCP2V6Address () : peer.router->GetPublishedNTCP2V4Address ();
|
peer.router->GetPublishedNTCP2V6Address () : peer.router->GetPublishedNTCP2V4Address ();
|
||||||
if (address && m_CheckReserved && i2p::util::net::IsInReservedRange(address->host))
|
if (address && IsInReservedRange(address->host))
|
||||||
address = nullptr;
|
address = nullptr;
|
||||||
if (address)
|
if (address)
|
||||||
{
|
{
|
||||||
|
@ -524,7 +524,7 @@ namespace transport
|
||||||
if (!m_SSU2Server) continue;
|
if (!m_SSU2Server) continue;
|
||||||
std::shared_ptr<const RouterInfo::Address> address = (tr == i2p::data::RouterInfo::eSSU2V6) ?
|
std::shared_ptr<const RouterInfo::Address> address = (tr == i2p::data::RouterInfo::eSSU2V6) ?
|
||||||
peer.router->GetSSU2V6Address () : peer.router->GetSSU2V4Address ();
|
peer.router->GetSSU2V6Address () : peer.router->GetSSU2V4Address ();
|
||||||
if (address && m_CheckReserved && i2p::util::net::IsInReservedRange(address->host))
|
if (address && IsInReservedRange(address->host))
|
||||||
address = nullptr;
|
address = nullptr;
|
||||||
if (address && address->IsReachableSSU ())
|
if (address && address->IsReachableSSU ())
|
||||||
{
|
{
|
||||||
|
@ -1084,6 +1084,11 @@ namespace transport
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Transports::IsInReservedRange (const boost::asio::ip::address& host) const
|
||||||
|
{
|
||||||
|
return IsCheckReserved () && i2p::util::net::IsInReservedRange (host);
|
||||||
|
}
|
||||||
|
|
||||||
void InitAddressFromIface ()
|
void InitAddressFromIface ()
|
||||||
{
|
{
|
||||||
bool ipv6; i2p::config::GetOption("ipv6", ipv6);
|
bool ipv6; i2p::config::GetOption("ipv6", ipv6);
|
||||||
|
@ -1196,6 +1201,8 @@ namespace transport
|
||||||
i2p::context.PublishSSU2Address (ssu2port, false, ipv4, ipv6); // unpublish
|
i2p::context.PublishSSU2Address (ssu2port, false, ipv4, ipv6); // unpublish
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool checkReserved; i2p::config::GetOption("reservedrange", checkReserved);
|
||||||
|
transports.SetCheckReserved (checkReserved);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2013-2023, The PurpleI2P Project
|
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||||
*
|
*
|
||||||
* This file is part of Purple i2pd project and licensed under BSD3
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
|
@ -167,7 +167,8 @@ namespace transport
|
||||||
void PeerTest (bool ipv4 = true, bool ipv6 = true);
|
void PeerTest (bool ipv4 = true, bool ipv6 = true);
|
||||||
|
|
||||||
void SetCheckReserved (bool check) { m_CheckReserved = check; };
|
void SetCheckReserved (bool check) { m_CheckReserved = check; };
|
||||||
bool IsCheckReserved () { return m_CheckReserved; };
|
bool IsCheckReserved () const { return m_CheckReserved; };
|
||||||
|
bool IsInReservedRange (const boost::asio::ip::address& host) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue