2023-11-30 21:53:41 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "common.hpp"
|
2023-12-11 21:45:35 +00:00
|
|
|
|
2023-12-11 20:06:16 +00:00
|
|
|
#include <llarp/util/logging/buffer.hpp>
|
2023-11-30 21:53:41 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
2024-02-01 12:43:43 +00:00
|
|
|
namespace GossipRCMessage
|
2023-12-15 16:43:58 +00:00
|
|
|
{
|
2024-02-01 12:43:43 +00:00
|
|
|
inline static std::string serialize(const RouterID& last_sender, const RemoteRC& rc)
|
|
|
|
{
|
|
|
|
oxenc::bt_dict_producer btdp;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
btdp.append_encoded("rc", rc.view());
|
|
|
|
btdp.append("sender", last_sender.ToView());
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
log::error(link_cat, "Error: GossipRCMessage failed to bt encode contents");
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::move(btdp).str();
|
|
|
|
}
|
|
|
|
} // namespace GossipRCMessage
|
|
|
|
|
|
|
|
namespace FetchRCMessage
|
2023-11-30 21:53:41 +00:00
|
|
|
{
|
2024-02-01 12:43:43 +00:00
|
|
|
inline const auto INVALID_REQUEST =
|
|
|
|
messages::serialize_response({{messages::STATUS_KEY, "Invalid relay ID requested"}});
|
2023-11-30 21:53:41 +00:00
|
|
|
|
2024-02-01 12:43:43 +00:00
|
|
|
inline static std::string serialize(
|
|
|
|
std::chrono::system_clock::time_point since, const std::vector<RouterID>& explicit_ids)
|
2023-11-30 21:53:41 +00:00
|
|
|
{
|
2024-02-01 12:43:43 +00:00
|
|
|
oxenc::bt_dict_producer btdp;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto sublist = btdp.append_list("explicit_ids");
|
|
|
|
|
|
|
|
for (const auto& rid : explicit_ids)
|
|
|
|
sublist.append(rid.ToView());
|
|
|
|
}
|
2023-11-30 21:53:41 +00:00
|
|
|
|
2024-02-01 12:43:43 +00:00
|
|
|
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();
|
2023-11-30 21:53:41 +00:00
|
|
|
}
|
2024-02-01 12:43:43 +00:00
|
|
|
} // namespace FetchRCMessage
|
2023-11-30 21:53:41 +00:00
|
|
|
|
2024-02-01 12:43:43 +00:00
|
|
|
namespace BootstrapFetchMessage
|
2023-11-30 21:53:41 +00:00
|
|
|
{
|
2024-02-01 12:43:43 +00:00
|
|
|
// the LocalRC is converted to a RemoteRC type to send to the bootstrap seed
|
|
|
|
inline static std::string serialize(std::optional<LocalRC> local_rc, size_t quantity)
|
|
|
|
{
|
|
|
|
oxenc::bt_dict_producer btdp;
|
2023-12-20 22:21:10 +00:00
|
|
|
|
2024-02-01 12:43:43 +00:00
|
|
|
if (local_rc)
|
|
|
|
{
|
|
|
|
log::critical(logcat, "Serializing localRC: {}", oxenc::to_hex(local_rc->view()));
|
|
|
|
btdp.append_encoded("local", oxen::quic::to_sv(local_rc->view()));
|
|
|
|
}
|
2023-12-20 22:21:10 +00:00
|
|
|
|
2024-02-01 12:43:43 +00:00
|
|
|
btdp.append("quantity", quantity);
|
2023-12-20 22:21:10 +00:00
|
|
|
|
2024-02-01 12:43:43 +00:00
|
|
|
return std::move(btdp).str();
|
|
|
|
}
|
2023-11-30 21:53:41 +00:00
|
|
|
|
2024-02-01 12:43:43 +00:00
|
|
|
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
|
2023-11-30 21:53:41 +00:00
|
|
|
{
|
2024-02-02 20:50:48 +00:00
|
|
|
inline constexpr auto INVALID_REQUEST = "Invalid relay ID requested to relay response from."sv;
|
2024-02-01 12:43:43 +00:00
|
|
|
|
|
|
|
inline static std::string serialize(const RouterID& source)
|
|
|
|
{
|
|
|
|
oxenc::bt_dict_producer btdp;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
btdp.append("source", source.ToView());
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
log::error(link_cat, "Error: FetchRIDMessage failed to bt encode contents!");
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::move(btdp).str();
|
|
|
|
}
|
|
|
|
} // namespace FetchRIDMessage
|
2023-11-30 21:53:41 +00:00
|
|
|
|
|
|
|
} // namespace llarp
|