mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 04:04:16 +00:00
don't connect to NTCP2 only address using NTCP
This commit is contained in:
parent
5b83d4bef8
commit
9884a4336f
@ -84,6 +84,11 @@ namespace i2p
|
|||||||
routerInfo.AddSSUAddress (host.c_str(), port, routerInfo.GetIdentHash ());
|
routerInfo.AddSSUAddress (host.c_str(), port, routerInfo.GetIdentHash ());
|
||||||
routerInfo.AddNTCPAddress (host.c_str(), port);
|
routerInfo.AddNTCPAddress (host.c_str(), port);
|
||||||
}
|
}
|
||||||
|
if (ntcp2)
|
||||||
|
{
|
||||||
|
if (!m_NTCP2Keys) NewNTCP2Keys ();
|
||||||
|
routerInfo.AddNTCP2Address (m_NTCP2Keys->staticPublicKey, m_NTCP2Keys->iv);
|
||||||
|
}
|
||||||
|
|
||||||
routerInfo.SetCaps (i2p::data::RouterInfo::eReachable |
|
routerInfo.SetCaps (i2p::data::RouterInfo::eReachable |
|
||||||
i2p::data::RouterInfo::eSSUTesting | i2p::data::RouterInfo::eSSUIntroducer); // LR, BC
|
i2p::data::RouterInfo::eSSUTesting | i2p::data::RouterInfo::eSSUIntroducer); // LR, BC
|
||||||
@ -92,12 +97,6 @@ namespace i2p
|
|||||||
routerInfo.CreateBuffer (m_Keys);
|
routerInfo.CreateBuffer (m_Keys);
|
||||||
m_RouterInfo.SetRouterIdentity (GetIdentity ());
|
m_RouterInfo.SetRouterIdentity (GetIdentity ());
|
||||||
m_RouterInfo.Update (routerInfo.GetBuffer (), routerInfo.GetBufferLen ());
|
m_RouterInfo.Update (routerInfo.GetBuffer (), routerInfo.GetBufferLen ());
|
||||||
|
|
||||||
if (ntcp2) // TODO: should update routerInfo, but we ignore upublished NTCP2 addresses for now
|
|
||||||
{
|
|
||||||
if (!m_NTCP2Keys) NewNTCP2Keys ();
|
|
||||||
UpdateNTCP2Address (true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RouterContext::UpdateRouterInfo ()
|
void RouterContext::UpdateRouterInfo ()
|
||||||
|
@ -176,13 +176,13 @@ namespace data
|
|||||||
auto address = std::make_shared<Address>();
|
auto address = std::make_shared<Address>();
|
||||||
s.read ((char *)&address->cost, sizeof (address->cost));
|
s.read ((char *)&address->cost, sizeof (address->cost));
|
||||||
s.read ((char *)&address->date, sizeof (address->date));
|
s.read ((char *)&address->date, sizeof (address->date));
|
||||||
bool isNtcp2 = false;
|
bool isNTCP2Only = false;
|
||||||
char transportStyle[6];
|
char transportStyle[6];
|
||||||
auto transportStyleLen = ReadString (transportStyle, 6, s) - 1;
|
auto transportStyleLen = ReadString (transportStyle, 6, s) - 1;
|
||||||
if (!strncmp (transportStyle, "NTCP", 4)) // NTCP or NTCP2
|
if (!strncmp (transportStyle, "NTCP", 4)) // NTCP or NTCP2
|
||||||
{
|
{
|
||||||
address->transportStyle = eTransportNTCP;
|
address->transportStyle = eTransportNTCP;
|
||||||
if (transportStyleLen > 4 || transportStyle[4] == '2') isNtcp2= true;
|
if (transportStyleLen > 4 && transportStyle[4] == '2') isNTCP2Only= true;
|
||||||
}
|
}
|
||||||
else if (!strcmp (transportStyle, "SSU"))
|
else if (!strcmp (transportStyle, "SSU"))
|
||||||
{
|
{
|
||||||
@ -293,7 +293,8 @@ namespace data
|
|||||||
if (!s) return;
|
if (!s) return;
|
||||||
}
|
}
|
||||||
if (introducers) supportedTransports |= eSSUV4; // in case if host is not presented
|
if (introducers) supportedTransports |= eSSUV4; // in case if host is not presented
|
||||||
if (supportedTransports && (!isNtcp2 || address->IsPublishedNTCP2 ())) // we ignore unpublished NTCP2 only addresses
|
if (isNTCP2Only && address->ntcp2) address->ntcp2->isNTCP2Only = true;
|
||||||
|
if (supportedTransports)
|
||||||
{
|
{
|
||||||
addresses->push_back(address);
|
addresses->push_back(address);
|
||||||
m_SupportedTransports |= supportedTransports;
|
m_SupportedTransports |= supportedTransports;
|
||||||
@ -705,6 +706,7 @@ namespace data
|
|||||||
addr->cost = 14;
|
addr->cost = 14;
|
||||||
addr->date = 0;
|
addr->date = 0;
|
||||||
addr->ntcp2.reset (new NTCP2Ext ());
|
addr->ntcp2.reset (new NTCP2Ext ());
|
||||||
|
addr->ntcp2->isNTCP2Only = true; // NTCP2 only address
|
||||||
memcpy (addr->ntcp2->staticKey, staticKey, 32);
|
memcpy (addr->ntcp2->staticKey, staticKey, 32);
|
||||||
memcpy (addr->ntcp2->iv, iv, 16);
|
memcpy (addr->ntcp2->iv, iv, 16);
|
||||||
m_Addresses->push_back(std::move(addr));
|
m_Addresses->push_back(std::move(addr));
|
||||||
@ -863,7 +865,7 @@ namespace data
|
|||||||
return GetAddress (
|
return GetAddress (
|
||||||
[v4only](std::shared_ptr<const RouterInfo::Address> address)->bool
|
[v4only](std::shared_ptr<const RouterInfo::Address> address)->bool
|
||||||
{
|
{
|
||||||
return (address->transportStyle == eTransportNTCP) && (!v4only || address->host.is_v4 ());
|
return (address->transportStyle == eTransportNTCP) && !address->IsNTCP2Only () && (!v4only || address->host.is_v4 ());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,6 +95,7 @@ namespace data
|
|||||||
Tag<32> staticKey;
|
Tag<32> staticKey;
|
||||||
Tag<16> iv;
|
Tag<16> iv;
|
||||||
bool isPublished = false;
|
bool isPublished = false;
|
||||||
|
bool isNTCP2Only = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Address
|
struct Address
|
||||||
@ -126,6 +127,7 @@ namespace data
|
|||||||
|
|
||||||
bool IsNTCP2 () const { return (bool)ntcp2; };
|
bool IsNTCP2 () const { return (bool)ntcp2; };
|
||||||
bool IsPublishedNTCP2 () const { return IsNTCP2 () && ntcp2->isPublished; };
|
bool IsPublishedNTCP2 () const { return IsNTCP2 () && ntcp2->isPublished; };
|
||||||
|
bool IsNTCP2Only () const { return ntcp2 && ntcp2->isNTCP2Only; };
|
||||||
};
|
};
|
||||||
typedef std::list<std::shared_ptr<Address> > Addresses;
|
typedef std::list<std::shared_ptr<Address> > Addresses;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user