Browse Source

don't connect to NTCP2 only address using NTCP

pull/1221/head
orignal 6 years ago
parent
commit
9884a4336f
  1. 11
      libi2pd/RouterContext.cpp
  2. 10
      libi2pd/RouterInfo.cpp
  3. 2
      libi2pd/RouterInfo.h

11
libi2pd/RouterContext.cpp

@ -84,6 +84,11 @@ namespace i2p @@ -84,6 +84,11 @@ namespace i2p
routerInfo.AddSSUAddress (host.c_str(), port, routerInfo.GetIdentHash ());
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 |
i2p::data::RouterInfo::eSSUTesting | i2p::data::RouterInfo::eSSUIntroducer); // LR, BC
@ -92,12 +97,6 @@ namespace i2p @@ -92,12 +97,6 @@ namespace i2p
routerInfo.CreateBuffer (m_Keys);
m_RouterInfo.SetRouterIdentity (GetIdentity ());
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 ()

10
libi2pd/RouterInfo.cpp

@ -176,13 +176,13 @@ namespace data @@ -176,13 +176,13 @@ namespace data
auto address = std::make_shared<Address>();
s.read ((char *)&address->cost, sizeof (address->cost));
s.read ((char *)&address->date, sizeof (address->date));
bool isNtcp2 = false;
bool isNTCP2Only = false;
char transportStyle[6];
auto transportStyleLen = ReadString (transportStyle, 6, s) - 1;
if (!strncmp (transportStyle, "NTCP", 4)) // NTCP or NTCP2
{
address->transportStyle = eTransportNTCP;
if (transportStyleLen > 4 || transportStyle[4] == '2') isNtcp2= true;
if (transportStyleLen > 4 && transportStyle[4] == '2') isNTCP2Only= true;
}
else if (!strcmp (transportStyle, "SSU"))
{
@ -293,7 +293,8 @@ namespace data @@ -293,7 +293,8 @@ namespace data
if (!s) return;
}
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);
m_SupportedTransports |= supportedTransports;
@ -705,6 +706,7 @@ namespace data @@ -705,6 +706,7 @@ namespace data
addr->cost = 14;
addr->date = 0;
addr->ntcp2.reset (new NTCP2Ext ());
addr->ntcp2->isNTCP2Only = true; // NTCP2 only address
memcpy (addr->ntcp2->staticKey, staticKey, 32);
memcpy (addr->ntcp2->iv, iv, 16);
m_Addresses->push_back(std::move(addr));
@ -863,7 +865,7 @@ namespace data @@ -863,7 +865,7 @@ namespace data
return GetAddress (
[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 ());
});
}

2
libi2pd/RouterInfo.h

@ -95,6 +95,7 @@ namespace data @@ -95,6 +95,7 @@ namespace data
Tag<32> staticKey;
Tag<16> iv;
bool isPublished = false;
bool isNTCP2Only = false;
};
struct Address
@ -126,6 +127,7 @@ namespace data @@ -126,6 +127,7 @@ namespace data
bool IsNTCP2 () const { return (bool)ntcp2; };
bool IsPublishedNTCP2 () const { return IsNTCP2 () && ntcp2->isPublished; };
bool IsNTCP2Only () const { return ntcp2 && ntcp2->isNTCP2Only; };
};
typedef std::list<std::shared_ptr<Address> > Addresses;

Loading…
Cancel
Save