2021-03-09 22:24:35 +00:00
|
|
|
#include "intro_set.hpp"
|
|
|
|
#include <llarp/crypto/crypto.hpp>
|
|
|
|
#include <llarp/path/path.hpp>
|
2019-01-11 00:12:43 +00:00
|
|
|
|
2022-02-17 18:44:31 +00:00
|
|
|
#include <oxenc/bt_serialize.h>
|
2020-08-31 20:07:17 +00:00
|
|
|
|
2021-02-02 14:35:40 +00:00
|
|
|
namespace llarp::service
|
2019-01-11 00:12:43 +00:00
|
|
|
{
|
2021-02-02 14:35:40 +00:00
|
|
|
util::StatusObject
|
|
|
|
EncryptedIntroSet::ExtractStatus() const
|
2019-01-11 00:12:43 +00:00
|
|
|
{
|
2021-02-02 14:35:40 +00:00
|
|
|
const auto sz = introsetPayload.size();
|
|
|
|
return {
|
|
|
|
{"location", derivedSigningKey.ToString()}, {"signedAt", to_json(signedAt)}, {"size", sz}};
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
EncryptedIntroSet::BEncode(llarp_buffer_t* buf) const
|
|
|
|
{
|
|
|
|
if (not bencode_start_dict(buf))
|
|
|
|
return false;
|
|
|
|
if (not BEncodeWriteDictEntry("d", derivedSigningKey, buf))
|
|
|
|
return false;
|
|
|
|
if (not BEncodeWriteDictEntry("n", nounce, buf))
|
|
|
|
return false;
|
|
|
|
if (not BEncodeWriteDictInt("s", signedAt.count(), buf))
|
|
|
|
return false;
|
|
|
|
if (not bencode_write_bytestring(buf, "x", 1))
|
|
|
|
return false;
|
|
|
|
if (not bencode_write_bytestring(buf, introsetPayload.data(), introsetPayload.size()))
|
|
|
|
return false;
|
|
|
|
if (not BEncodeWriteDictEntry("z", sig, buf))
|
|
|
|
return false;
|
|
|
|
return bencode_end(buf);
|
|
|
|
}
|
2020-01-27 21:30:41 +00:00
|
|
|
|
2021-02-02 14:35:40 +00:00
|
|
|
bool
|
|
|
|
EncryptedIntroSet::DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf)
|
|
|
|
{
|
|
|
|
bool read = false;
|
2022-09-09 21:48:38 +00:00
|
|
|
if (key.startswith("x"))
|
2020-01-27 21:30:41 +00:00
|
|
|
{
|
2021-02-02 14:35:40 +00:00
|
|
|
llarp_buffer_t strbuf;
|
|
|
|
if (not bencode_read_string(buf, &strbuf))
|
2020-01-27 21:30:41 +00:00
|
|
|
return false;
|
2021-02-02 14:35:40 +00:00
|
|
|
if (strbuf.sz > MAX_INTROSET_SIZE)
|
2020-01-27 21:30:41 +00:00
|
|
|
return false;
|
2021-02-02 14:35:40 +00:00
|
|
|
introsetPayload.resize(strbuf.sz);
|
|
|
|
std::copy_n(strbuf.base, strbuf.sz, introsetPayload.data());
|
|
|
|
return true;
|
2020-01-27 21:30:41 +00:00
|
|
|
}
|
2021-02-02 14:35:40 +00:00
|
|
|
if (not BEncodeMaybeReadDictEntry("d", derivedSigningKey, read, key, buf))
|
|
|
|
return false;
|
2020-01-27 21:30:41 +00:00
|
|
|
|
2021-02-02 14:35:40 +00:00
|
|
|
if (not BEncodeMaybeReadDictEntry("n", nounce, read, key, buf))
|
|
|
|
return false;
|
2020-01-27 21:30:41 +00:00
|
|
|
|
2021-02-02 14:35:40 +00:00
|
|
|
if (not BEncodeMaybeReadDictInt("s", signedAt, read, key, buf))
|
|
|
|
return false;
|
2020-01-27 21:30:41 +00:00
|
|
|
|
2021-02-02 14:35:40 +00:00
|
|
|
if (not BEncodeMaybeReadDictEntry("z", sig, read, key, buf))
|
|
|
|
return false;
|
|
|
|
return read;
|
|
|
|
}
|
2020-01-27 21:30:41 +00:00
|
|
|
|
2021-02-02 14:35:40 +00:00
|
|
|
bool
|
|
|
|
EncryptedIntroSet::OtherIsNewer(const EncryptedIntroSet& other) const
|
|
|
|
{
|
|
|
|
return signedAt < other.signedAt;
|
|
|
|
}
|
2020-01-27 21:30:41 +00:00
|
|
|
|
2022-07-16 00:41:14 +00:00
|
|
|
std::string
|
|
|
|
EncryptedIntroSet::ToString() const
|
|
|
|
{
|
2022-07-18 17:56:09 +00:00
|
|
|
return fmt::format(
|
|
|
|
"[EncIntroSet d={} n={} s={} x=[{} bytes] z={}]",
|
|
|
|
derivedSigningKey,
|
|
|
|
nounce,
|
|
|
|
signedAt.count(),
|
|
|
|
introsetPayload.size(),
|
|
|
|
sig);
|
2022-07-16 00:41:14 +00:00
|
|
|
}
|
|
|
|
|
2021-02-02 14:35:40 +00:00
|
|
|
std::optional<IntroSet>
|
|
|
|
EncryptedIntroSet::MaybeDecrypt(const PubKey& root) const
|
|
|
|
{
|
|
|
|
SharedSecret k(root);
|
|
|
|
IntroSet i;
|
|
|
|
std::vector<byte_t> payload = introsetPayload;
|
|
|
|
llarp_buffer_t buf(payload);
|
|
|
|
CryptoManager::instance()->xchacha20(buf, k, nounce);
|
|
|
|
if (not i.BDecode(&buf))
|
2021-04-14 15:07:06 +00:00
|
|
|
return {};
|
2021-02-02 14:35:40 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
EncryptedIntroSet::IsExpired(llarp_time_t now) const
|
|
|
|
{
|
|
|
|
return now >= signedAt + path::default_lifetime;
|
|
|
|
}
|
2020-01-27 21:30:41 +00:00
|
|
|
|
2021-02-02 14:35:40 +00:00
|
|
|
bool
|
|
|
|
EncryptedIntroSet::Sign(const PrivateKey& k)
|
|
|
|
{
|
|
|
|
signedAt = llarp::time_now_ms();
|
|
|
|
if (not k.toPublic(derivedSigningKey))
|
|
|
|
return false;
|
|
|
|
sig.Zero();
|
|
|
|
std::array<byte_t, MAX_INTROSET_SIZE + 128> tmp;
|
|
|
|
llarp_buffer_t buf(tmp);
|
|
|
|
if (not BEncode(&buf))
|
|
|
|
return false;
|
|
|
|
buf.sz = buf.cur - buf.base;
|
|
|
|
buf.cur = buf.base;
|
|
|
|
if (not CryptoManager::instance()->sign(sig, k, buf))
|
|
|
|
return false;
|
|
|
|
LogDebug("signed encrypted introset: ", *this);
|
|
|
|
return true;
|
|
|
|
}
|
2020-01-27 21:30:41 +00:00
|
|
|
|
2021-02-02 14:35:40 +00:00
|
|
|
bool
|
|
|
|
EncryptedIntroSet::Verify(llarp_time_t now) const
|
|
|
|
{
|
|
|
|
if (IsExpired(now))
|
|
|
|
return false;
|
|
|
|
std::array<byte_t, MAX_INTROSET_SIZE + 128> tmp;
|
|
|
|
llarp_buffer_t buf(tmp);
|
|
|
|
EncryptedIntroSet copy(*this);
|
|
|
|
copy.sig.Zero();
|
|
|
|
if (not copy.BEncode(&buf))
|
|
|
|
return false;
|
|
|
|
LogDebug("verify encrypted introset: ", copy, " sig = ", sig);
|
|
|
|
buf.sz = buf.cur - buf.base;
|
|
|
|
buf.cur = buf.base;
|
|
|
|
return CryptoManager::instance()->verify(derivedSigningKey, buf, sig);
|
|
|
|
}
|
|
|
|
|
|
|
|
util::StatusObject
|
|
|
|
IntroSet::ExtractStatus() const
|
|
|
|
{
|
2021-04-14 15:07:06 +00:00
|
|
|
util::StatusObject obj{{"published", to_json(timestampSignedAt)}};
|
2021-02-02 14:35:40 +00:00
|
|
|
std::vector<util::StatusObject> introsObjs;
|
|
|
|
std::transform(
|
2021-04-14 15:07:06 +00:00
|
|
|
intros.begin(),
|
|
|
|
intros.end(),
|
2021-02-02 14:35:40 +00:00
|
|
|
std::back_inserter(introsObjs),
|
|
|
|
[](const auto& intro) -> util::StatusObject { return intro.ExtractStatus(); });
|
|
|
|
obj["intros"] = introsObjs;
|
|
|
|
if (!topic.IsZero())
|
|
|
|
obj["topic"] = topic.ToString();
|
2021-04-14 15:07:06 +00:00
|
|
|
|
|
|
|
std::vector<util::StatusObject> protocols;
|
|
|
|
std::transform(
|
|
|
|
supportedProtocols.begin(),
|
|
|
|
supportedProtocols.end(),
|
|
|
|
std::back_inserter(protocols),
|
2022-07-16 00:41:14 +00:00
|
|
|
[](const auto& proto) -> util::StatusObject { return service::ToString(proto); });
|
2021-04-14 15:07:06 +00:00
|
|
|
obj["protos"] = protocols;
|
|
|
|
std::vector<util::StatusObject> ranges;
|
|
|
|
std::transform(
|
|
|
|
ownedRanges.begin(),
|
|
|
|
ownedRanges.end(),
|
|
|
|
std::back_inserter(ranges),
|
|
|
|
[](const auto& range) -> util::StatusObject { return range.ToString(); });
|
|
|
|
|
|
|
|
obj["advertisedRanges"] = ranges;
|
|
|
|
if (exitTrafficPolicy)
|
|
|
|
obj["exitPolicy"] = exitTrafficPolicy->ExtractStatus();
|
|
|
|
|
2021-02-02 14:35:40 +00:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IntroSet::DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf)
|
|
|
|
{
|
|
|
|
bool read = false;
|
2021-04-14 15:07:06 +00:00
|
|
|
if (!BEncodeMaybeReadDictEntry("a", addressKeys, read, key, buf))
|
2021-02-02 14:35:40 +00:00
|
|
|
return false;
|
2020-01-27 21:30:41 +00:00
|
|
|
|
2022-09-09 21:48:38 +00:00
|
|
|
if (key.startswith("e"))
|
2021-04-14 15:07:06 +00:00
|
|
|
{
|
|
|
|
net::TrafficPolicy policy;
|
|
|
|
if (not policy.BDecode(buf))
|
|
|
|
return false;
|
|
|
|
exitTrafficPolicy = policy;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-09-09 21:48:38 +00:00
|
|
|
if (key.startswith("i"))
|
2020-01-27 21:30:41 +00:00
|
|
|
{
|
2021-04-14 15:07:06 +00:00
|
|
|
return BEncodeReadList(intros, buf);
|
2020-01-27 21:30:41 +00:00
|
|
|
}
|
2021-04-14 15:07:06 +00:00
|
|
|
if (!BEncodeMaybeReadDictEntry("k", sntrupKey, read, key, buf))
|
2021-02-02 14:35:40 +00:00
|
|
|
return false;
|
2020-01-27 21:30:41 +00:00
|
|
|
|
2021-02-02 14:35:40 +00:00
|
|
|
if (!BEncodeMaybeReadDictEntry("n", topic, read, key, buf))
|
|
|
|
return false;
|
2020-01-27 21:30:41 +00:00
|
|
|
|
2022-09-09 21:48:38 +00:00
|
|
|
if (key.startswith("p"))
|
2021-04-14 15:07:06 +00:00
|
|
|
{
|
|
|
|
return bencode_read_list(
|
|
|
|
[&](llarp_buffer_t* buf, bool more) {
|
|
|
|
if (more)
|
|
|
|
{
|
|
|
|
uint64_t protoval;
|
|
|
|
if (not bencode_read_integer(buf, &protoval))
|
|
|
|
return false;
|
|
|
|
supportedProtocols.emplace_back(static_cast<ProtocolType>(protoval));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
buf);
|
|
|
|
}
|
|
|
|
|
2022-09-09 21:48:38 +00:00
|
|
|
if (key.startswith("r"))
|
2021-04-14 15:07:06 +00:00
|
|
|
{
|
2021-04-14 19:40:57 +00:00
|
|
|
return BEncodeReadSet(ownedRanges, buf);
|
2021-04-14 15:07:06 +00:00
|
|
|
}
|
|
|
|
|
2022-09-09 21:48:38 +00:00
|
|
|
if (key.startswith("s"))
|
2020-01-27 21:30:41 +00:00
|
|
|
{
|
2021-02-02 14:35:40 +00:00
|
|
|
byte_t* begin = buf->cur;
|
|
|
|
if (not bencode_discard(buf))
|
2020-01-27 21:30:41 +00:00
|
|
|
return false;
|
|
|
|
|
2021-02-02 14:35:40 +00:00
|
|
|
byte_t* end = buf->cur;
|
2019-02-08 19:43:25 +00:00
|
|
|
|
2021-04-14 15:07:06 +00:00
|
|
|
std::string_view srvString(
|
|
|
|
reinterpret_cast<const char*>(begin), static_cast<size_t>(end - begin));
|
2019-01-11 00:12:43 +00:00
|
|
|
|
2021-02-02 14:35:40 +00:00
|
|
|
try
|
2019-01-11 00:12:43 +00:00
|
|
|
{
|
2022-02-17 18:44:31 +00:00
|
|
|
oxenc::bt_deserialize(srvString, SRVs);
|
2019-01-11 00:12:43 +00:00
|
|
|
}
|
2022-02-17 18:44:31 +00:00
|
|
|
catch (const oxenc::bt_deserialize_invalid& err)
|
2021-02-02 14:35:40 +00:00
|
|
|
{
|
|
|
|
LogError("Error decoding SRV records from IntroSet: ", err.what());
|
2019-01-11 00:12:43 +00:00
|
|
|
return false;
|
2021-02-02 14:35:40 +00:00
|
|
|
}
|
|
|
|
read = true;
|
|
|
|
}
|
2019-01-11 00:12:43 +00:00
|
|
|
|
2021-04-14 15:07:06 +00:00
|
|
|
if (!BEncodeMaybeReadDictInt("t", timestampSignedAt, read, key, buf))
|
2021-02-02 14:35:40 +00:00
|
|
|
return false;
|
2019-01-11 00:12:43 +00:00
|
|
|
|
2021-02-02 14:35:40 +00:00
|
|
|
if (!BEncodeMaybeReadDictInt("v", version, read, key, buf))
|
|
|
|
return false;
|
2020-08-31 20:07:17 +00:00
|
|
|
|
2021-04-14 15:07:06 +00:00
|
|
|
if (!BEncodeMaybeReadDictEntry("z", signature, read, key, buf))
|
2021-02-02 14:35:40 +00:00
|
|
|
return false;
|
2020-08-31 20:07:17 +00:00
|
|
|
|
2021-04-14 15:07:06 +00:00
|
|
|
return read or bencode_discard(buf);
|
2021-02-02 14:35:40 +00:00
|
|
|
}
|
2019-01-11 00:12:43 +00:00
|
|
|
|
2021-02-02 14:35:40 +00:00
|
|
|
bool
|
|
|
|
IntroSet::BEncode(llarp_buffer_t* buf) const
|
|
|
|
{
|
2021-04-14 15:07:06 +00:00
|
|
|
if (not bencode_start_dict(buf))
|
2021-02-02 14:35:40 +00:00
|
|
|
return false;
|
2021-04-14 15:07:06 +00:00
|
|
|
if (not BEncodeWriteDictEntry("a", addressKeys, buf))
|
2021-02-02 14:35:40 +00:00
|
|
|
return false;
|
2021-04-14 15:07:06 +00:00
|
|
|
|
|
|
|
// exit policy if applicable
|
|
|
|
if (exitTrafficPolicy)
|
|
|
|
{
|
|
|
|
if (not BEncodeWriteDictEntry("e", *exitTrafficPolicy, buf))
|
|
|
|
return false;
|
|
|
|
}
|
2021-02-02 14:35:40 +00:00
|
|
|
// start introduction list
|
2021-04-14 15:07:06 +00:00
|
|
|
if (not bencode_write_bytestring(buf, "i", 1))
|
2021-02-02 14:35:40 +00:00
|
|
|
return false;
|
2021-04-14 15:07:06 +00:00
|
|
|
if (not BEncodeWriteList(intros.begin(), intros.end(), buf))
|
2021-02-02 14:35:40 +00:00
|
|
|
return false;
|
|
|
|
// end introduction list
|
2019-01-11 00:12:43 +00:00
|
|
|
|
2021-02-02 14:35:40 +00:00
|
|
|
// pq pubkey
|
2021-04-14 15:07:06 +00:00
|
|
|
if (not BEncodeWriteDictEntry("k", sntrupKey, buf))
|
2021-02-02 14:35:40 +00:00
|
|
|
return false;
|
2019-01-11 00:12:43 +00:00
|
|
|
|
2021-02-02 14:35:40 +00:00
|
|
|
// topic tag
|
2021-04-14 15:07:06 +00:00
|
|
|
if (not topic.ToString().empty())
|
|
|
|
{
|
|
|
|
if (not BEncodeWriteDictEntry("n", topic, buf))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// supported ethertypes
|
|
|
|
if (not supportedProtocols.empty())
|
2021-02-02 14:35:40 +00:00
|
|
|
{
|
2021-04-14 15:07:06 +00:00
|
|
|
if (not bencode_write_bytestring(buf, "p", 1))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (not bencode_start_list(buf))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (const auto& proto : supportedProtocols)
|
|
|
|
{
|
|
|
|
if (not bencode_write_uint64(buf, static_cast<uint64_t>(proto)))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (not bencode_end(buf))
|
2019-01-11 00:12:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-04-14 19:40:57 +00:00
|
|
|
// owned ranges
|
|
|
|
if (not ownedRanges.empty())
|
|
|
|
{
|
|
|
|
if (not bencode_write_bytestring(buf, "r", 1))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (not BEncodeWriteSet(ownedRanges, buf))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-04-14 15:07:06 +00:00
|
|
|
// srv records
|
|
|
|
if (not SRVs.empty())
|
2019-01-11 00:12:43 +00:00
|
|
|
{
|
2022-02-17 18:44:31 +00:00
|
|
|
std::string serial = oxenc::bt_serialize(SRVs);
|
2021-02-02 14:35:40 +00:00
|
|
|
if (!bencode_write_bytestring(buf, "s", 1))
|
2019-01-11 00:12:43 +00:00
|
|
|
return false;
|
2021-02-02 14:35:40 +00:00
|
|
|
if (!buf->write(serial.begin(), serial.end()))
|
2019-01-11 00:12:43 +00:00
|
|
|
return false;
|
2021-02-02 14:35:40 +00:00
|
|
|
}
|
|
|
|
|
2021-04-14 15:07:06 +00:00
|
|
|
// timestamp
|
|
|
|
if (!BEncodeWriteDictInt("t", timestampSignedAt.count(), buf))
|
2021-02-02 14:35:40 +00:00
|
|
|
return false;
|
2019-01-11 00:12:43 +00:00
|
|
|
|
2021-02-02 14:35:40 +00:00
|
|
|
// write version
|
|
|
|
if (!BEncodeWriteDictInt("v", version, buf))
|
|
|
|
return false;
|
2021-04-14 15:07:06 +00:00
|
|
|
|
|
|
|
if (!BEncodeWriteDictEntry("z", signature, buf))
|
2021-02-02 14:35:40 +00:00
|
|
|
return false;
|
2019-01-11 00:12:43 +00:00
|
|
|
|
2021-02-02 14:35:40 +00:00
|
|
|
return bencode_end(buf);
|
|
|
|
}
|
2020-08-31 20:07:17 +00:00
|
|
|
|
2021-02-02 14:35:40 +00:00
|
|
|
bool
|
|
|
|
IntroSet::HasExpiredIntros(llarp_time_t now) const
|
|
|
|
{
|
2021-04-14 15:07:06 +00:00
|
|
|
for (const auto& intro : intros)
|
|
|
|
if (now >= intro.expiresAt)
|
2021-02-02 14:35:40 +00:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
2020-08-31 20:07:17 +00:00
|
|
|
|
2021-06-02 19:52:13 +00:00
|
|
|
bool
|
|
|
|
IntroSet::HasStaleIntros(llarp_time_t now, llarp_time_t delta) const
|
|
|
|
{
|
|
|
|
for (const auto& intro : intros)
|
|
|
|
if (intro.ExpiresSoon(now, delta))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-02-02 14:35:40 +00:00
|
|
|
bool
|
|
|
|
IntroSet::IsExpired(llarp_time_t now) const
|
|
|
|
{
|
|
|
|
return GetNewestIntroExpiration() < now;
|
|
|
|
}
|
2019-01-11 00:12:43 +00:00
|
|
|
|
2021-02-02 14:35:40 +00:00
|
|
|
std::vector<llarp::dns::SRVData>
|
|
|
|
IntroSet::GetMatchingSRVRecords(std::string_view service_proto) const
|
|
|
|
{
|
|
|
|
std::vector<llarp::dns::SRVData> records;
|
|
|
|
|
|
|
|
for (const auto& tuple : SRVs)
|
|
|
|
{
|
|
|
|
if (std::get<0>(tuple) == service_proto)
|
2019-01-11 00:12:43 +00:00
|
|
|
{
|
2021-02-02 14:35:40 +00:00
|
|
|
records.push_back(llarp::dns::SRVData::fromTuple(tuple));
|
2019-01-11 00:12:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-02 14:35:40 +00:00
|
|
|
return records;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IntroSet::Verify(llarp_time_t now) const
|
|
|
|
{
|
|
|
|
std::array<byte_t, MAX_INTROSET_SIZE> tmp;
|
2021-04-14 15:07:06 +00:00
|
|
|
llarp_buffer_t buf{tmp};
|
2021-02-02 14:35:40 +00:00
|
|
|
IntroSet copy;
|
|
|
|
copy = *this;
|
2021-04-14 15:07:06 +00:00
|
|
|
copy.signature.Zero();
|
2021-02-02 14:35:40 +00:00
|
|
|
if (!copy.BEncode(&buf))
|
2019-01-11 00:12:43 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2021-02-02 14:35:40 +00:00
|
|
|
// rewind and resize buffer
|
|
|
|
buf.sz = buf.cur - buf.base;
|
|
|
|
buf.cur = buf.base;
|
2021-04-14 15:07:06 +00:00
|
|
|
if (!addressKeys.Verify(buf, signature))
|
2020-08-31 23:25:58 +00:00
|
|
|
{
|
2021-02-02 14:35:40 +00:00
|
|
|
return false;
|
2020-08-31 23:25:58 +00:00
|
|
|
}
|
2021-02-02 14:35:40 +00:00
|
|
|
// valid timestamps
|
|
|
|
// add max clock skew
|
|
|
|
now += MAX_INTROSET_TIME_DELTA;
|
2021-04-14 15:07:06 +00:00
|
|
|
for (const auto& intro : intros)
|
2019-01-11 00:12:43 +00:00
|
|
|
{
|
2021-02-02 14:35:40 +00:00
|
|
|
if (intro.expiresAt > now && intro.expiresAt - now > path::default_lifetime)
|
2019-01-26 12:33:34 +00:00
|
|
|
{
|
2021-04-14 15:07:06 +00:00
|
|
|
return false;
|
2019-01-11 00:12:43 +00:00
|
|
|
}
|
|
|
|
}
|
2021-04-14 15:07:06 +00:00
|
|
|
return not IsExpired(now);
|
2021-02-02 14:35:40 +00:00
|
|
|
}
|
2019-02-24 23:46:37 +00:00
|
|
|
|
2021-02-02 14:35:40 +00:00
|
|
|
llarp_time_t
|
|
|
|
IntroSet::GetNewestIntroExpiration() const
|
|
|
|
{
|
2021-04-14 15:07:06 +00:00
|
|
|
llarp_time_t maxTime = 0s;
|
|
|
|
for (const auto& intro : intros)
|
|
|
|
maxTime = std::max(intro.expiresAt, maxTime);
|
|
|
|
return maxTime;
|
2021-02-02 14:35:40 +00:00
|
|
|
}
|
|
|
|
|
2022-07-16 00:41:14 +00:00
|
|
|
std::string
|
|
|
|
IntroSet::ToString() const
|
|
|
|
{
|
2022-07-18 17:56:09 +00:00
|
|
|
return fmt::format(
|
|
|
|
"[IntroSet addressKeys={} intros={{{}}} sntrupKey={} topic={} signedAt={} v={} sig={}]",
|
|
|
|
addressKeys,
|
|
|
|
fmt::format("{}", fmt::join(intros, ",")),
|
|
|
|
sntrupKey,
|
|
|
|
topic,
|
|
|
|
timestampSignedAt.count(),
|
|
|
|
version,
|
|
|
|
signature);
|
2022-07-16 00:41:14 +00:00
|
|
|
}
|
2021-02-02 14:35:40 +00:00
|
|
|
} // namespace llarp::service
|