lokinet/llarp/service/endpoint_state.cpp

73 lines
1.9 KiB
C++
Raw Normal View History

#include "endpoint_state.hpp"
#include <llarp/exit/session.hpp>
#include "endpoint.hpp"
#include "outbound_context.hpp"
#include <llarp/util/str.hpp>
namespace llarp
{
namespace service
{
bool
EndpointState::Configure(const NetworkConfig& conf)
{
2020-06-08 12:42:10 +00:00
if (conf.m_keyfile.has_value())
2023-10-03 20:00:23 +00:00
key_file = conf.m_keyfile->string();
snode_blacklist = conf.m_snodeBlacklist;
is_exit_enabled = conf.m_AllowExit;
for (const auto& record : conf.m_SRVRecords)
{
2023-10-03 20:00:23 +00:00
local_introset.SRVs.push_back(record.toTuple());
}
return true;
}
util::StatusObject
EndpointState::ExtractStatus(util::StatusObject& obj) const
{
2023-10-03 20:00:23 +00:00
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();
};
std::transform(
2023-10-03 20:00:23 +00:00
dead_sessions.begin(),
dead_sessions.end(),
std::back_inserter(obj["deadSessions"]),
getSecond);
std::transform(
2023-10-03 20:00:23 +00:00
remote_sessions.begin(),
remote_sessions.end(),
std::back_inserter(obj["remoteSessions"]),
getSecond);
std::transform(
2023-10-03 20:00:23 +00:00
pending_lookups.begin(),
pending_lookups.end(),
std::back_inserter(obj["lookups"]),
getSecond);
std::transform(
2023-10-03 20:00:23 +00:00
snode_sessions.begin(),
snode_sessions.end(),
std::back_inserter(obj["snodeSessions"]),
2021-04-07 12:03:04 +00:00
[](const auto& item) { return item.second->ExtractStatus(); });
util::StatusObject sessionObj{};
for (const auto& item : m_Sessions)
{
std::string k = item.first.ToHex();
sessionObj[k] = item.second.ExtractStatus();
}
obj["converstations"] = sessionObj;
return obj;
}
} // namespace service
} // namespace llarp