lokinet/llarp/service/endpoint_state.cpp

114 lines
3.1 KiB
C++
Raw Normal View History

#include <service/endpoint_state.hpp>
#include <exit/session.hpp>
#include <hook/shell.hpp>
2019-07-18 16:28:17 +00:00
#include <service/endpoint.hpp>
#include <service/outbound_context.hpp>
#include <util/str.hpp>
namespace llarp
{
namespace service
{
bool
2020-04-22 21:52:53 +00:00
EndpointState::Configure(EndpointConfig conf)
{
2020-04-22 20:04:47 +00:00
m_Keyfile = std::move(conf.m_keyfile);
m_Tag = std::move(conf.m_tag);
m_PrefetchTags = std::move(conf.m_prefetchTags);
m_PrefetchAddrs = std::move(conf.m_prefetchAddrs);
m_MinPathLatency = conf.m_minLatency;
m_BundleRC = conf.m_bundleRC;
2020-04-22 21:52:53 +00:00
// TODO: update EndpointConfig to treat these as RouterIDs and detect dupes
2020-04-22 20:04:47 +00:00
for (const auto& item : conf.m_snodeBlacklist)
{
RouterID snode;
2020-04-22 20:04:47 +00:00
if (not snode.FromString(item))
throw std::runtime_error(stringify("Invalide RouterID: ", item));
m_SnodeBlacklist.insert(snode);
}
2020-04-22 20:04:47 +00:00
// TODO:
/*
if (k == "on-up")
{
m_OnUp = hooks::ExecShellBackend(v);
if (m_OnUp)
LogInfo(name, " added on up script: ", v);
else
LogError(name, " failed to add on up script");
}
if (k == "on-down")
{
m_OnDown = hooks::ExecShellBackend(v);
if (m_OnDown)
LogInfo(name, " added on down script: ", v);
else
LogError(name, " failed to add on down script");
}
if (k == "on-ready")
{
m_OnReady = hooks::ExecShellBackend(v);
if (m_OnReady)
LogInfo(name, " added on ready script: ", v);
else
LogError(name, " failed to add on ready script");
}
2020-04-22 20:04:47 +00:00
*/
return true;
}
util::StatusObject
EndpointState::ExtractStatus(util::StatusObject& obj) const
{
obj["lastPublished"] = to_json(m_LastPublish);
obj["lastPublishAttempt"] = to_json(m_LastPublishAttempt);
obj["introset"] = m_IntroSet.ExtractStatus();
if (!m_Tag.IsZero())
{
obj["tag"] = m_Tag.ToString();
}
static auto getSecond = [](const auto& item) -> auto
{
return item.second->ExtractStatus();
};
std::transform(
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(),
std::back_inserter(obj["snodeSessions"]),
[](const auto& item) { return item.second.first->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