2019-04-22 18:35:19 +00:00
|
|
|
#include <service/intro.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
|
|
|
{
|
2019-02-11 17:14:43 +00:00
|
|
|
util::StatusObject obj{{"router", router.ToHex()},
|
2020-02-25 17:05:13 +00:00
|
|
|
{"expiresAt", to_json(expiresAt)},
|
|
|
|
{"latency", to_json(latency)},
|
2019-02-11 17:14:43 +00:00
|
|
|
{"version", uint64_t(version)}};
|
|
|
|
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;
|
|
|
|
if(!BEncodeMaybeReadDictEntry("k", router, read, key, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeMaybeReadDictInt("l", latency, read, key, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeMaybeReadDictEntry("p", pathID, read, key, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeMaybeReadDictInt("v", version, read, key, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeMaybeReadDictInt("x", expiresAt, read, key, buf))
|
|
|
|
return false;
|
|
|
|
return read;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Introduction::BEncode(llarp_buffer_t* buf) const
|
|
|
|
{
|
|
|
|
if(!bencode_start_dict(buf))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(!BEncodeWriteDictEntry("k", router, buf))
|
|
|
|
return false;
|
2020-02-24 19:40:45 +00:00
|
|
|
if(latency > 0s)
|
2019-01-11 00:12:43 +00:00
|
|
|
{
|
2020-02-24 19:40:45 +00:00
|
|
|
if(!BEncodeWriteDictInt("l", latency.count(), buf))
|
2019-01-11 00:12:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if(!BEncodeWriteDictEntry("p", pathID, buf))
|
|
|
|
return false;
|
|
|
|
if(!BEncodeWriteDictInt("v", version, buf))
|
|
|
|
return false;
|
2020-02-24 19:40:45 +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-02-24 19:40:45 +00:00
|
|
|
latency = 0s;
|
|
|
|
expiresAt = 0s;
|
2019-01-11 00:12:43 +00:00
|
|
|
}
|
2019-02-24 23:46:37 +00:00
|
|
|
|
|
|
|
std::ostream&
|
|
|
|
Introduction::print(std::ostream& stream, int level, int spaces) const
|
|
|
|
{
|
|
|
|
Printer printer(stream, level, spaces);
|
2019-05-01 13:40:10 +00:00
|
|
|
printer.printAttribute("k", RouterID(router));
|
2020-02-24 19:40:45 +00:00
|
|
|
printer.printAttribute("l", latency.count());
|
2019-02-24 23:46:37 +00:00
|
|
|
printer.printAttribute("p", pathID);
|
|
|
|
printer.printAttribute("v", version);
|
2020-02-24 19:40:45 +00:00
|
|
|
printer.printAttribute("x", expiresAt.count());
|
2019-02-24 23:46:37 +00:00
|
|
|
|
|
|
|
return stream;
|
|
|
|
}
|
2019-01-17 14:02:50 +00:00
|
|
|
} // namespace service
|
|
|
|
} // namespace llarp
|