2021-03-09 22:24:35 +00:00
|
|
|
#include "endpoint_state.hpp"
|
2019-07-15 09:15:51 +00:00
|
|
|
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/exit/session.hpp>
|
|
|
|
#include "endpoint.hpp"
|
|
|
|
#include "outbound_context.hpp"
|
|
|
|
#include <llarp/util/str.hpp>
|
2019-07-15 09:15:51 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace service
|
|
|
|
{
|
|
|
|
bool
|
2020-04-30 22:11:05 +00:00
|
|
|
EndpointState::Configure(const NetworkConfig& conf)
|
2019-07-15 09:15:51 +00:00
|
|
|
{
|
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;
|
2020-08-31 20:07:17 +00:00
|
|
|
|
|
|
|
for (const auto& record : conf.m_SRVRecords)
|
|
|
|
{
|
2023-10-03 20:00:23 +00:00
|
|
|
local_introset.SRVs.push_back(record.toTuple());
|
2020-08-31 20:07:17 +00:00
|
|
|
}
|
|
|
|
|
2019-07-15 09:15:51 +00:00
|
|
|
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();
|
2019-08-19 09:33:26 +00:00
|
|
|
static auto getSecond = [](const auto& item) -> auto
|
|
|
|
{
|
|
|
|
return item.second->ExtractStatus();
|
2019-07-15 09:15:51 +00:00
|
|
|
};
|
2019-08-19 09:33:26 +00:00
|
|
|
|
|
|
|
std::transform(
|
2023-10-03 20:00:23 +00:00
|
|
|
dead_sessions.begin(),
|
|
|
|
dead_sessions.end(),
|
2020-04-07 18:38:56 +00:00
|
|
|
std::back_inserter(obj["deadSessions"]),
|
|
|
|
getSecond);
|
|
|
|
std::transform(
|
2023-10-03 20:00:23 +00:00
|
|
|
remote_sessions.begin(),
|
|
|
|
remote_sessions.end(),
|
2020-04-07 18:38:56 +00:00
|
|
|
std::back_inserter(obj["remoteSessions"]),
|
|
|
|
getSecond);
|
|
|
|
std::transform(
|
2023-10-03 20:00:23 +00:00
|
|
|
pending_lookups.begin(),
|
|
|
|
pending_lookups.end(),
|
2020-04-07 18:38:56 +00:00
|
|
|
std::back_inserter(obj["lookups"]),
|
|
|
|
getSecond);
|
|
|
|
std::transform(
|
2023-10-03 20:00:23 +00:00
|
|
|
snode_sessions.begin(),
|
|
|
|
snode_sessions.end(),
|
2019-08-19 09:33:26 +00:00
|
|
|
std::back_inserter(obj["snodeSessions"]),
|
2021-04-07 12:03:04 +00:00
|
|
|
[](const auto& item) { return item.second->ExtractStatus(); });
|
2019-07-15 09:15:51 +00:00
|
|
|
|
|
|
|
util::StatusObject sessionObj{};
|
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
for (const auto& item : m_Sessions)
|
2019-07-15 09:15:51 +00:00
|
|
|
{
|
|
|
|
std::string k = item.first.ToHex();
|
2019-08-19 09:33:26 +00:00
|
|
|
sessionObj[k] = item.second.ExtractStatus();
|
2019-07-15 09:15:51 +00:00
|
|
|
}
|
|
|
|
|
2019-08-19 09:33:26 +00:00
|
|
|
obj["converstations"] = sessionObj;
|
2019-07-15 09:15:51 +00:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
} // namespace service
|
|
|
|
} // namespace llarp
|