2019-07-15 09:15:51 +00:00
|
|
|
#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>
|
2019-07-15 09:15:51 +00:00
|
|
|
#include <service/outbound_context.hpp>
|
|
|
|
#include <util/str.hpp>
|
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace service
|
|
|
|
{
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
EndpointState::SetOption(const std::string& k, const std::string& v, Endpoint& ep)
|
2019-07-15 09:15:51 +00:00
|
|
|
{
|
2019-07-18 16:28:17 +00:00
|
|
|
const auto name = ep.Name();
|
2020-04-07 18:38:56 +00:00
|
|
|
if (k == "keyfile")
|
2019-07-15 09:15:51 +00:00
|
|
|
{
|
|
|
|
m_Keyfile = v;
|
|
|
|
}
|
2020-04-07 18:38:56 +00:00
|
|
|
if (k == "tag")
|
2019-07-15 09:15:51 +00:00
|
|
|
{
|
|
|
|
m_Tag = v;
|
|
|
|
LogInfo("Setting tag to ", v);
|
|
|
|
}
|
2020-04-07 18:38:56 +00:00
|
|
|
if (k == "prefetch-tag")
|
2019-07-15 09:15:51 +00:00
|
|
|
{
|
|
|
|
m_PrefetchTags.insert(v);
|
|
|
|
}
|
2020-04-07 18:38:56 +00:00
|
|
|
if (k == "prefetch-addr")
|
2019-07-15 09:15:51 +00:00
|
|
|
{
|
|
|
|
Address addr;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (addr.FromString(v))
|
2019-07-15 09:15:51 +00:00
|
|
|
m_PrefetchAddrs.insert(addr);
|
|
|
|
}
|
2020-04-07 18:38:56 +00:00
|
|
|
if (k == "min-latency")
|
2019-07-15 09:15:51 +00:00
|
|
|
{
|
2019-07-18 16:28:17 +00:00
|
|
|
const auto val = atoi(v.c_str());
|
2020-04-07 18:38:56 +00:00
|
|
|
if (val > 0)
|
2020-02-25 17:05:13 +00:00
|
|
|
m_MinPathLatency = std::chrono::milliseconds(val);
|
2019-07-15 09:15:51 +00:00
|
|
|
}
|
2020-04-07 18:38:56 +00:00
|
|
|
if (k == "paths")
|
2019-07-18 16:28:17 +00:00
|
|
|
{
|
|
|
|
const auto val = atoi(v.c_str());
|
2020-04-07 18:38:56 +00:00
|
|
|
if (val >= 1 && val <= static_cast<int>(path::PathSet::max_paths))
|
2019-07-18 16:28:17 +00:00
|
|
|
{
|
|
|
|
ep.numPaths = val;
|
2019-07-18 16:32:26 +00:00
|
|
|
LogInfo(name, " set number of paths to ", ep.numHops);
|
2019-07-18 16:28:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-18 16:32:26 +00:00
|
|
|
LogWarn(name, " invalid number of paths: ", v);
|
2019-07-18 16:28:17 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-07 18:38:56 +00:00
|
|
|
if (k == "hops")
|
2019-07-18 16:28:17 +00:00
|
|
|
{
|
|
|
|
const auto val = atoi(v.c_str());
|
2020-04-07 18:38:56 +00:00
|
|
|
if (val >= 1 && val <= static_cast<int>(path::max_len))
|
2019-07-18 16:28:17 +00:00
|
|
|
{
|
|
|
|
ep.numHops = val;
|
|
|
|
LogInfo(name, " set number of hops to ", ep.numHops);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LogWarn(name, " invalid number of hops: ", v);
|
|
|
|
}
|
|
|
|
}
|
2020-04-07 18:38:56 +00:00
|
|
|
if (k == "bundle-rc")
|
2019-07-15 09:15:51 +00:00
|
|
|
{
|
|
|
|
m_BundleRC = IsTrueValue(v.c_str());
|
|
|
|
}
|
2020-04-07 18:38:56 +00:00
|
|
|
if (k == "blacklist-snode")
|
2019-07-15 09:15:51 +00:00
|
|
|
{
|
|
|
|
RouterID snode;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!snode.FromString(v))
|
2019-07-15 09:15:51 +00:00
|
|
|
{
|
|
|
|
LogError(name, " invalid snode value: ", v);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const auto result = m_SnodeBlacklist.insert(snode);
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!result.second)
|
2019-07-15 09:15:51 +00:00
|
|
|
{
|
|
|
|
LogError(name, " duplicate blacklist-snode: ", snode.ToString());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
LogInfo(name, " adding ", snode.ToString(), " to blacklist");
|
|
|
|
}
|
2020-04-07 18:38:56 +00:00
|
|
|
if (k == "on-up")
|
2019-07-15 09:15:51 +00:00
|
|
|
{
|
|
|
|
m_OnUp = hooks::ExecShellBackend(v);
|
2020-04-07 18:38:56 +00:00
|
|
|
if (m_OnUp)
|
2019-07-15 09:15:51 +00:00
|
|
|
LogInfo(name, " added on up script: ", v);
|
|
|
|
else
|
|
|
|
LogError(name, " failed to add on up script");
|
|
|
|
}
|
2020-04-07 18:38:56 +00:00
|
|
|
if (k == "on-down")
|
2019-07-15 09:15:51 +00:00
|
|
|
{
|
|
|
|
m_OnDown = hooks::ExecShellBackend(v);
|
2020-04-07 18:38:56 +00:00
|
|
|
if (m_OnDown)
|
2019-07-15 09:15:51 +00:00
|
|
|
LogInfo(name, " added on down script: ", v);
|
|
|
|
else
|
|
|
|
LogError(name, " failed to add on down script");
|
|
|
|
}
|
2020-04-07 18:38:56 +00:00
|
|
|
if (k == "on-ready")
|
2019-07-15 09:15:51 +00:00
|
|
|
{
|
|
|
|
m_OnReady = hooks::ExecShellBackend(v);
|
2020-04-07 18:38:56 +00:00
|
|
|
if (m_OnReady)
|
2019-07-15 09:15:51 +00:00
|
|
|
LogInfo(name, " added on ready script: ", v);
|
|
|
|
else
|
|
|
|
LogError(name, " failed to add on ready script");
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
util::StatusObject
|
|
|
|
EndpointState::ExtractStatus(util::StatusObject& obj) const
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
obj["lastPublished"] = to_json(m_LastPublish);
|
2020-02-25 17:05:13 +00:00
|
|
|
obj["lastPublishAttempt"] = to_json(m_LastPublishAttempt);
|
2020-04-07 18:38:56 +00:00
|
|
|
obj["introset"] = m_IntroSet.ExtractStatus();
|
2019-07-15 09:15:51 +00:00
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!m_Tag.IsZero())
|
2019-07-15 09:15:51 +00:00
|
|
|
{
|
2019-08-19 09:33:26 +00:00
|
|
|
obj["tag"] = m_Tag.ToString();
|
|
|
|
}
|
|
|
|
|
|
|
|
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(
|
2020-04-07 18:38:56 +00: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 09:33:26 +00:00
|
|
|
std::back_inserter(obj["snodeSessions"]),
|
|
|
|
[](const auto& item) { return item.second.first->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
|