2023-09-29 21:00:13 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "common.hpp"
|
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
2023-10-03 20:00:23 +00:00
|
|
|
namespace FindIntroMessage
|
|
|
|
{
|
2023-10-04 13:25:25 +00:00
|
|
|
inline auto NOT_FOUND = "NOT FOUND"sv;
|
|
|
|
inline auto INVALID_ORDER = "INVALID ORDER"sv;
|
|
|
|
inline auto INSUFFICIENT_NODES = "INSUFFICIENT NODES"sv;
|
2023-10-03 20:00:23 +00:00
|
|
|
|
|
|
|
inline static std::string
|
2023-10-11 21:17:00 +00:00
|
|
|
serialize(const dht::Key_t& location, bool is_relayed, uint64_t order)
|
2023-09-29 21:00:13 +00:00
|
|
|
{
|
|
|
|
oxenc::bt_dict_producer btdp;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2023-10-03 20:00:23 +00:00
|
|
|
btdp.append("O", order);
|
|
|
|
btdp.append("R", is_relayed ? 1 : 0);
|
|
|
|
btdp.append("S", location.ToView());
|
2023-09-29 21:00:13 +00:00
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
2023-10-03 20:00:23 +00:00
|
|
|
log::error(link_cat, "Error: FindIntroMessage failed to bt encode contents!");
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::move(btdp).str();
|
|
|
|
}
|
|
|
|
} // namespace FindIntroMessage
|
|
|
|
|
|
|
|
namespace FindNameMessage
|
|
|
|
{
|
2023-10-04 13:25:25 +00:00
|
|
|
inline auto NOT_FOUND = "NOT FOUND"sv;
|
2023-10-03 20:00:23 +00:00
|
|
|
|
2023-11-28 12:55:01 +00:00
|
|
|
// NOT USED
|
2023-10-03 20:00:23 +00:00
|
|
|
inline static std::string
|
2023-10-10 20:49:53 +00:00
|
|
|
serialize(dht::Key_t name_hash)
|
2023-10-03 20:00:23 +00:00
|
|
|
{
|
|
|
|
oxenc::bt_dict_producer btdp;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
btdp.append("H", name_hash.ToView());
|
2023-10-10 20:49:53 +00:00
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
log::error(link_cat, "Error: FindNameMessage failed to bt encode contents!");
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::move(btdp).str();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static std::string
|
|
|
|
serialize(std::string name_hash)
|
|
|
|
{
|
|
|
|
oxenc::bt_dict_producer btdp;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
btdp.append("H", std::move(name_hash));
|
2023-10-03 20:00:23 +00:00
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
log::error(link_cat, "Error: FindNameMessage failed to bt encode contents!");
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::move(btdp).str();
|
|
|
|
}
|
|
|
|
} // namespace FindNameMessage
|
|
|
|
|
|
|
|
namespace PublishIntroMessage
|
|
|
|
{
|
2023-10-04 13:25:25 +00:00
|
|
|
inline auto INVALID_INTROSET = "INVALID INTROSET"sv;
|
|
|
|
inline auto EXPIRED = "EXPIRED INTROSET"sv;
|
|
|
|
inline auto INSUFFICIENT = "INSUFFICIENT NODES"sv;
|
|
|
|
inline auto INVALID_ORDER = "INVALID ORDER"sv;
|
2023-10-03 20:00:23 +00:00
|
|
|
|
|
|
|
inline static std::string
|
2023-10-10 20:49:53 +00:00
|
|
|
serialize(std::string introset, uint64_t relay_order, uint64_t is_relayed)
|
2023-10-03 20:00:23 +00:00
|
|
|
{
|
|
|
|
oxenc::bt_dict_producer btdp;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
btdp.append("I", introset);
|
|
|
|
btdp.append("O", relay_order);
|
|
|
|
btdp.append("R", is_relayed);
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
log::error(link_cat, "Error: FindNameMessage failed to bt encode contents!");
|
2023-09-29 21:00:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return std::move(btdp).str();
|
|
|
|
}
|
2023-10-03 20:00:23 +00:00
|
|
|
} // namespace PublishIntroMessage
|
2023-09-29 21:00:13 +00:00
|
|
|
} // namespace llarp
|