2021-03-09 22:24:35 +00:00
|
|
|
#include "intro.hpp"
|
2022-07-16 00:41:14 +00:00
|
|
|
#include "util/time.hpp"
|
2019-01-11 00:12:43 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace service
|
|
|
|
{
|
2019-02-11 17:14:43 +00:00
|
|
|
util::StatusObject
|
|
|
|
Introduction::ExtractStatus() const
|
2019-02-08 19:43:25 +00:00
|
|
|
{
|
2021-03-05 17:31:52 +00:00
|
|
|
util::StatusObject obj{
|
|
|
|
{"router", router.ToHex()},
|
2021-06-02 19:52:13 +00:00
|
|
|
{"path", pathID.ToHex()},
|
2021-03-05 17:31:52 +00:00
|
|
|
{"expiresAt", to_json(expiresAt)},
|
|
|
|
{"latency", to_json(latency)},
|
|
|
|
{"version", uint64_t(version)}};
|
2019-02-11 17:14:43 +00:00
|
|
|
return obj;
|
2019-02-08 19:43:25 +00:00
|
|
|
}
|
|
|
|
|
2019-01-11 00:12:43 +00:00
|
|
|
bool
|
2019-02-05 00:41:33 +00:00
|
|
|
Introduction::DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf)
|
2019-01-11 00:12:43 +00:00
|
|
|
{
|
|
|
|
bool read = false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictEntry("k", router, read, key, buf))
|
2019-01-11 00:12:43 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictInt("l", latency, read, key, buf))
|
2019-01-11 00:12:43 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictEntry("p", pathID, read, key, buf))
|
2019-01-11 00:12:43 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictInt("v", version, read, key, buf))
|
2019-01-11 00:12:43 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeMaybeReadDictInt("x", expiresAt, read, key, buf))
|
2019-01-11 00:12:43 +00:00
|
|
|
return false;
|
|
|
|
return read;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Introduction::BEncode(llarp_buffer_t* buf) const
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!bencode_start_dict(buf))
|
2019-01-11 00:12:43 +00:00
|
|
|
return false;
|
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictEntry("k", router, buf))
|
2019-01-11 00:12:43 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (latency > 0s)
|
2019-01-11 00:12:43 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictInt("l", latency.count(), buf))
|
2019-01-11 00:12:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictEntry("p", pathID, buf))
|
2019-01-11 00:12:43 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictInt("v", version, buf))
|
2019-01-11 00:12:43 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!BEncodeWriteDictInt("x", expiresAt.count(), buf))
|
2019-01-11 00:12:43 +00:00
|
|
|
return false;
|
|
|
|
return bencode_end(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Introduction::Clear()
|
|
|
|
{
|
|
|
|
router.Zero();
|
|
|
|
pathID.Zero();
|
2020-04-07 18:38:56 +00:00
|
|
|
latency = 0s;
|
2020-02-24 19:40:45 +00:00
|
|
|
expiresAt = 0s;
|
2019-01-11 00:12:43 +00:00
|
|
|
}
|
2019-02-24 23:46:37 +00:00
|
|
|
|
2022-07-16 00:41:14 +00:00
|
|
|
std::string
|
|
|
|
Introduction::ToString() const
|
|
|
|
{
|
2022-07-18 17:56:09 +00:00
|
|
|
return fmt::format(
|
|
|
|
"[Intro k={} l={} p={} v={} x={}]",
|
|
|
|
RouterID{router},
|
|
|
|
latency.count(),
|
|
|
|
pathID,
|
|
|
|
version,
|
|
|
|
expiresAt.count());
|
2022-07-16 00:41:14 +00:00
|
|
|
}
|
|
|
|
|
2019-01-17 14:02:50 +00:00
|
|
|
} // namespace service
|
|
|
|
} // namespace llarp
|