Browse Source

SSU2 introducers

pull/1752/head
orignal 3 years ago
parent
commit
eb6437050f
  1. 38
      libi2pd/RouterInfo.cpp
  2. 2
      libi2pd/RouterInfo.h

38
libi2pd/RouterInfo.cpp

@ -330,7 +330,7 @@ namespace data
introducer.iPort = boost::lexical_cast<int>(value); introducer.iPort = boost::lexical_cast<int>(value);
else if (!strcmp (key, "itag")) else if (!strcmp (key, "itag"))
introducer.iTag = boost::lexical_cast<uint32_t>(value); introducer.iTag = boost::lexical_cast<uint32_t>(value);
else if (!strcmp (key, "ikey")) else if (!strcmp (key, "ikey") || !strcmp (key, "ih"))
Base64ToByteStream (value, strlen (value), introducer.iKey, 32); Base64ToByteStream (value, strlen (value), introducer.iKey, 32);
else if (!strcmp (key, "iexp")) else if (!strcmp (key, "iexp"))
introducer.iExp = boost::lexical_cast<uint32_t>(value); introducer.iExp = boost::lexical_cast<uint32_t>(value);
@ -425,6 +425,9 @@ namespace data
ssu2addr->date = address->date; ssu2addr->caps = address->caps; ssu2addr->date = address->date; ssu2addr->caps = address->caps;
ssu2addr->published = address->published; ssu2addr->published = address->published;
ssu2addr->ssu.reset (new SSUExt ()); ssu2addr->ssu->mtu = address->ssu->mtu; ssu2addr->ssu.reset (new SSUExt ()); ssu2addr->ssu->mtu = address->ssu->mtu;
for (const auto& introducer: address->ssu->introducers)
if (!introducer.iPort) // SSU2
ssu2addr->ssu->introducers.push_back (introducer);
addresses->push_back(ssu2addr); addresses->push_back(ssu2addr);
} }
} }
@ -1227,7 +1230,14 @@ namespace data
WriteString (address.host.to_string (), properties); WriteString (address.host.to_string (), properties);
properties << ';'; properties << ';';
} }
if (address.transportStyle == eTransportSSU) if ((address.IsNTCP2 () && isPublished) || address.IsSSU2 ())
{
// publish i for NTCP2 or SSU2
WriteString ("i", properties); properties << '=';
size_t len = address.IsSSU2 () ? 32 : 16;
WriteString (address.i.ToBase64 (len), properties); properties << ';';
}
if (address.transportStyle == eTransportSSU || address.IsSSU2 ())
{ {
// write introducers if any // write introducers if any
if (!address.ssu->introducers.empty()) if (!address.ssu->introducers.empty())
@ -1244,6 +1254,8 @@ namespace data
} }
i++; i++;
} }
if (address.transportStyle == eTransportSSU)
{
i = 0; i = 0;
for (const auto& introducer: address.ssu->introducers) for (const auto& introducer: address.ssu->introducers)
{ {
@ -1253,9 +1265,13 @@ namespace data
properties << ';'; properties << ';';
i++; i++;
} }
}
i = 0; i = 0;
for (const auto& introducer: address.ssu->introducers) for (const auto& introducer: address.ssu->introducers)
{ {
if (address.IsSSU2 ())
WriteString ("ih" + boost::lexical_cast<std::string>(i), properties);
else
WriteString ("ikey" + boost::lexical_cast<std::string>(i), properties); WriteString ("ikey" + boost::lexical_cast<std::string>(i), properties);
properties << '='; properties << '=';
char value[64]; char value[64];
@ -1265,6 +1281,8 @@ namespace data
properties << ';'; properties << ';';
i++; i++;
} }
if (address.transportStyle == eTransportSSU)
{
i = 0; i = 0;
for (const auto& introducer: address.ssu->introducers) for (const auto& introducer: address.ssu->introducers)
{ {
@ -1274,6 +1292,7 @@ namespace data
properties << ';'; properties << ';';
i++; i++;
} }
}
i = 0; i = 0;
for (const auto& introducer: address.ssu->introducers) for (const auto& introducer: address.ssu->introducers)
{ {
@ -1284,6 +1303,9 @@ namespace data
i++; i++;
} }
} }
}
if (address.transportStyle == eTransportSSU)
{
// write intro key // write intro key
WriteString ("key", properties); WriteString ("key", properties);
properties << '='; properties << '=';
@ -1292,6 +1314,9 @@ namespace data
value[l] = 0; value[l] = 0;
WriteString (value, properties); WriteString (value, properties);
properties << ';'; properties << ';';
}
if (address.transportStyle == eTransportSSU || address.IsSSU2 ())
{
// write mtu // write mtu
if (address.ssu->mtu) if (address.ssu->mtu)
{ {
@ -1301,15 +1326,6 @@ namespace data
properties << ';'; properties << ';';
} }
} }
if ((address.IsNTCP2 () && isPublished) || address.IsSSU2 ())
{
// publish i for NTCP2 or SSU2
WriteString ("i", properties); properties << '=';
size_t len = address.IsSSU2 () ? 32 : 16;
WriteString (address.i.ToBase64 (len), properties); properties << ';';
}
if (isPublished || (address.ssu && !address.IsSSU2 ())) if (isPublished || (address.ssu && !address.IsSSU2 ()))
{ {
WriteString ("port", properties); WriteString ("port", properties);

2
libi2pd/RouterInfo.h

@ -107,7 +107,7 @@ namespace data
Introducer (): iPort (0), 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; // or ih for SSU2
uint32_t iTag; uint32_t iTag;
uint32_t iExp; uint32_t iExp;
}; };

Loading…
Cancel
Save