2021-03-09 22:24:35 +00:00
|
|
|
#include "endpoint_state.hpp"
|
2019-07-15 09:15:51 +00:00
|
|
|
|
2023-10-19 11:49:46 +00:00
|
|
|
namespace llarp::service
|
2019-07-15 09:15:51 +00:00
|
|
|
{
|
2023-10-19 11:49:46 +00:00
|
|
|
bool
|
|
|
|
EndpointState::Configure(const NetworkConfig& conf)
|
2019-07-15 09:15:51 +00:00
|
|
|
{
|
2023-11-03 13:40:14 +00:00
|
|
|
if (conf.keyfile.has_value())
|
|
|
|
key_file = conf.keyfile->string();
|
|
|
|
snode_blacklist = conf.snode_blacklist;
|
|
|
|
is_exit_enabled = conf.allow_exit;
|
2020-08-31 20:07:17 +00:00
|
|
|
|
2023-11-03 13:40:14 +00:00
|
|
|
for (const auto& record : conf.srv_records)
|
2023-10-19 11:49:46 +00:00
|
|
|
{
|
|
|
|
local_introset.SRVs.push_back(record.toTuple());
|
2019-07-15 09:15:51 +00:00
|
|
|
}
|
|
|
|
|
2023-10-19 11:49:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-08-19 09:33:26 +00:00
|
|
|
|
2023-10-19 11:49:46 +00:00
|
|
|
util::StatusObject
|
|
|
|
EndpointState::ExtractStatus(util::StatusObject& obj) const
|
|
|
|
{
|
|
|
|
obj["lastPublished"] = to_json(last_publish);
|
|
|
|
obj["lastPublishAttempt"] = to_json(last_publish_attempt);
|
|
|
|
obj["introset"] = local_introset.ExtractStatus();
|
|
|
|
// static auto getSecond = [](const auto& item) -> auto
|
|
|
|
// {
|
|
|
|
// return item.second.ExtractStatus();
|
|
|
|
// };
|
2019-07-15 09:15:51 +00:00
|
|
|
|
2023-10-19 11:49:46 +00:00
|
|
|
// std::transform(
|
|
|
|
// dead_sessions.begin(),
|
|
|
|
// dead_sessions.end(),
|
|
|
|
// std::back_inserter(obj["deadSessions"]),
|
|
|
|
// getSecond);
|
|
|
|
// std::transform(
|
|
|
|
// remote_sessions.begin(),
|
|
|
|
// remote_sessions.end(),
|
|
|
|
// std::back_inserter(obj["remoteSessions"]),
|
|
|
|
// getSecond);
|
|
|
|
// std::transform(
|
|
|
|
// snode_sessions.begin(),
|
|
|
|
// snode_sessions.end(),
|
|
|
|
// std::back_inserter(obj["snodeSessions"]),
|
|
|
|
// [](const auto& item) { return item.second->ExtractStatus(); });
|
2019-07-15 09:15:51 +00:00
|
|
|
|
2023-10-19 11:49:46 +00:00
|
|
|
util::StatusObject sessionObj{};
|
2019-07-15 09:15:51 +00:00
|
|
|
|
2023-10-19 11:49:46 +00:00
|
|
|
// TODO:
|
|
|
|
// for (const auto& item : m_Sessions)
|
|
|
|
// {
|
|
|
|
// std::string k = item.first.ToHex();
|
|
|
|
// sessionObj[k] = item.second.ExtractStatus();
|
|
|
|
// }
|
|
|
|
|
|
|
|
obj["converstations"] = sessionObj;
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
} // namespace llarp::service
|