mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-17 15:25:35 +00:00
ed6bd28a35
- redoing link_manager functions again to implement previously ignored review comments on several PRs - conceptually merging "whitelist_routers" and new "known_{rids,rcs}", s.t. we can completely eliminate white/red/gray/green/etc lists in favor of something that isn't dumb
83 lines
2.1 KiB
C++
83 lines
2.1 KiB
C++
#pragma once
|
|
|
|
#include "common.hpp"
|
|
|
|
namespace llarp
|
|
{
|
|
namespace FetchRCMessage
|
|
{
|
|
inline const auto INVALID_REQUEST =
|
|
messages::serialize_response({{messages::STATUS_KEY, "Invalid relay ID requested"}});
|
|
|
|
inline static std::string
|
|
serialize(
|
|
std::chrono::system_clock::time_point since, const std::vector<RouterID>& explicit_ids)
|
|
{
|
|
oxenc::bt_dict_producer btdp;
|
|
|
|
try
|
|
{
|
|
{
|
|
auto sublist = btdp.append_list("explicit_ids");
|
|
|
|
for (const auto& rid : explicit_ids)
|
|
sublist.append(rid.ToView());
|
|
}
|
|
|
|
btdp.append("since", since.time_since_epoch() / 1s);
|
|
}
|
|
catch (...)
|
|
{
|
|
log::error(link_cat, "Error: RCFetchMessage failed to bt encode contents!");
|
|
}
|
|
|
|
return std::move(btdp).str();
|
|
}
|
|
} // namespace FetchRCMessage
|
|
|
|
namespace BootstrapFetchMessage
|
|
{
|
|
inline static std::string
|
|
serialize(size_t quantity)
|
|
{
|
|
oxenc::bt_dict_producer btdp;
|
|
btdp.append("quantity", quantity);
|
|
return std::move(btdp).str();
|
|
}
|
|
|
|
inline static std::string
|
|
serialize_response(const std::vector<RouterID>& explicit_ids)
|
|
{
|
|
oxenc::bt_dict_producer btdp;
|
|
|
|
try
|
|
{
|
|
auto sublist = btdp.append_list("explicit_ids");
|
|
|
|
for (const auto& rid : explicit_ids)
|
|
sublist.append(rid.ToView());
|
|
}
|
|
catch (...)
|
|
{
|
|
log::error(link_cat, "Error: BootstrapFetchMessage failed to bt encode contents!");
|
|
}
|
|
|
|
return std::move(btdp).str();
|
|
}
|
|
} // namespace BootstrapFetchMessage
|
|
|
|
namespace FetchRIDMessage
|
|
{
|
|
inline constexpr auto INVALID_REQUEST = "Invalid relay ID requested to relay response from."sv;
|
|
|
|
inline static std::string
|
|
serialize(const RouterID& source)
|
|
{
|
|
// serialize_response is a bit weird here, and perhaps could have a sister function
|
|
// with the same purpose but as a request, but...it works.
|
|
return messages::serialize_response({{"source", source.ToView()}});
|
|
}
|
|
} // namespace FetchRIDMessage
|
|
|
|
} // namespace llarp
|