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())
|
2020-06-12 22:03:05 +00:00
|
|
|
m_Keyfile = conf.m_keyfile->string();
|
2020-04-28 18:18:47 +00:00
|
|
|
m_SnodeBlacklist = conf.m_snodeBlacklist;
|
2020-06-03 11:41:28 +00:00
|
|
|
m_ExitEnabled = conf.m_AllowExit;
|
2020-08-31 20:07:17 +00:00
|
|
|
|
|
|
|
for (const auto& record : conf.m_SRVRecords)
|
|
|
|
{
|
|
|
|
m_IntroSet.SRVs.push_back(record.toTuple());
|
|
|
|
}
|
|
|
|
|
2019-07-15 09:15:51 +00:00
|
|
|
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-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(
|
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"]),
|
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
|