2021-03-09 23:24:35 +01:00
|
|
|
#include "endpoint_state.hpp"
|
2019-07-15 11:15:51 +02:00
|
|
|
|
2021-03-09 23:24:35 +01:00
|
|
|
#include <llarp/exit/session.hpp>
|
|
|
|
#include <llarp/hook/shell.hpp>
|
|
|
|
#include "endpoint.hpp"
|
|
|
|
#include "outbound_context.hpp"
|
|
|
|
#include <llarp/util/str.hpp>
|
2019-07-15 11:15:51 +02:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace service
|
|
|
|
{
|
|
|
|
bool
|
2020-05-01 00:11:05 +02:00
|
|
|
EndpointState::Configure(const NetworkConfig& conf)
|
2019-07-15 11:15:51 +02:00
|
|
|
{
|
2020-06-08 14:42:10 +02:00
|
|
|
if (conf.m_keyfile.has_value())
|
2020-06-13 00:03:05 +02:00
|
|
|
m_Keyfile = conf.m_keyfile->string();
|
2020-04-28 20:18:47 +02:00
|
|
|
m_SnodeBlacklist = conf.m_snodeBlacklist;
|
2020-06-03 13:41:28 +02:00
|
|
|
m_ExitEnabled = conf.m_AllowExit;
|
2020-08-31 22:07:17 +02:00
|
|
|
|
|
|
|
for (const auto& record : conf.m_SRVRecords)
|
|
|
|
{
|
|
|
|
m_IntroSet.SRVs.push_back(record.toTuple());
|
|
|
|
}
|
|
|
|
|
2020-04-22 22:04:47 +02:00
|
|
|
// TODO:
|
|
|
|
/*
|
2020-04-07 20:38:56 +02:00
|
|
|
if (k == "on-up")
|
2019-07-15 11:15:51 +02:00
|
|
|
{
|
|
|
|
m_OnUp = hooks::ExecShellBackend(v);
|
2020-04-07 20:38:56 +02:00
|
|
|
if (m_OnUp)
|
2019-07-15 11:15:51 +02:00
|
|
|
LogInfo(name, " added on up script: ", v);
|
|
|
|
else
|
|
|
|
LogError(name, " failed to add on up script");
|
|
|
|
}
|
2020-04-07 20:38:56 +02:00
|
|
|
if (k == "on-down")
|
2019-07-15 11:15:51 +02:00
|
|
|
{
|
|
|
|
m_OnDown = hooks::ExecShellBackend(v);
|
2020-04-07 20:38:56 +02:00
|
|
|
if (m_OnDown)
|
2019-07-15 11:15:51 +02:00
|
|
|
LogInfo(name, " added on down script: ", v);
|
|
|
|
else
|
|
|
|
LogError(name, " failed to add on down script");
|
|
|
|
}
|
2020-04-07 20:38:56 +02:00
|
|
|
if (k == "on-ready")
|
2019-07-15 11:15:51 +02:00
|
|
|
{
|
|
|
|
m_OnReady = hooks::ExecShellBackend(v);
|
2020-04-07 20:38:56 +02:00
|
|
|
if (m_OnReady)
|
2019-07-15 11:15:51 +02:00
|
|
|
LogInfo(name, " added on ready script: ", v);
|
|
|
|
else
|
|
|
|
LogError(name, " failed to add on ready script");
|
|
|
|
}
|
2020-04-22 22:04:47 +02:00
|
|
|
*/
|
2019-07-15 11:15:51 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
util::StatusObject
|
|
|
|
EndpointState::ExtractStatus(util::StatusObject& obj) const
|
|
|
|
{
|
2020-04-07 20:38:56 +02:00
|
|
|
obj["lastPublished"] = to_json(m_LastPublish);
|
2020-02-25 18:05:13 +01:00
|
|
|
obj["lastPublishAttempt"] = to_json(m_LastPublishAttempt);
|
2020-04-07 20:38:56 +02:00
|
|
|
obj["introset"] = m_IntroSet.ExtractStatus();
|
2019-08-19 11:33:26 +02:00
|
|
|
static auto getSecond = [](const auto& item) -> auto
|
|
|
|
{
|
|
|
|
return item.second->ExtractStatus();
|
2019-07-15 11:15:51 +02:00
|
|
|
};
|
2019-08-19 11:33:26 +02:00
|
|
|
|
|
|
|
std::transform(
|
2020-04-07 20:38:56 +02:00
|
|
|
m_DeadSessions.begin(),
|
|
|
|
m_DeadSessions.end(),
|
|
|
|
std::back_inserter(obj["deadSessions"]),
|
|
|
|
getSecond);
|
|
|
|
std::transform(
|
|
|
|
m_RemoteSessions.begin(),
|
|
|
|
m_RemoteSessions.end(),
|
|
|
|
std::back_inserter(obj["remoteSessions"]),
|
|
|
|
getSecond);
|
|
|
|
std::transform(
|
|
|
|
m_PendingLookups.begin(),
|
|
|
|
m_PendingLookups.end(),
|
|
|
|
std::back_inserter(obj["lookups"]),
|
|
|
|
getSecond);
|
|
|
|
std::transform(
|
|
|
|
m_SNodeSessions.begin(),
|
|
|
|
m_SNodeSessions.end(),
|
2019-08-19 11:33:26 +02:00
|
|
|
std::back_inserter(obj["snodeSessions"]),
|
2021-04-07 14:03:04 +02:00
|
|
|
[](const auto& item) { return item.second->ExtractStatus(); });
|
2019-07-15 11:15:51 +02:00
|
|
|
|
|
|
|
util::StatusObject sessionObj{};
|
|
|
|
|
2020-04-07 20:38:56 +02:00
|
|
|
for (const auto& item : m_Sessions)
|
2019-07-15 11:15:51 +02:00
|
|
|
{
|
|
|
|
std::string k = item.first.ToHex();
|
2019-08-19 11:33:26 +02:00
|
|
|
sessionObj[k] = item.second.ExtractStatus();
|
2019-07-15 11:15:51 +02:00
|
|
|
}
|
|
|
|
|
2019-08-19 11:33:26 +02:00
|
|
|
obj["converstations"] = sessionObj;
|
2019-07-15 11:15:51 +02:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
} // namespace service
|
|
|
|
} // namespace llarp
|