lokinet/llarp/messages/dht.hpp

100 lines
2.3 KiB
C++
Raw Normal View History

#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
serialize(const dht::Key_t& location, bool is_relayed, uint64_t order)
{
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());
}
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
// NOT USED
2023-10-03 20:00:23 +00:00
inline static std::string
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());
}
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
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!");
}
return std::move(btdp).str();
}
2023-10-03 20:00:23 +00:00
} // namespace PublishIntroMessage
} // namespace llarp