lokinet/llarp/service/session.cpp

52 lines
1019 B
C++
Raw Normal View History

#include "session.hpp"
2023-10-03 20:00:23 +00:00
namespace llarp::service
{
2023-10-03 20:00:23 +00:00
util::StatusObject
Session::ExtractStatus() const
{
2023-10-03 20:00:23 +00:00
util::StatusObject obj{
{"lastSend", to_json(lastSend)},
{"lastRecv", to_json(lastRecv)},
{"replyIntro", replyIntro.ExtractStatus()},
{"remote", Addr().ToString()},
{"seqno", seqno},
{"tx", messagesSend},
{"rx", messagesRecv},
{"intro", intro.ExtractStatus()}};
return obj;
}
2023-10-03 20:00:23 +00:00
Address
Session::Addr() const
{
return remote.Addr();
}
2023-10-03 20:00:23 +00:00
bool
Session::IsExpired(llarp_time_t now, llarp_time_t lifetime) const
{
if (forever)
return false;
const auto lastUsed = std::max(lastSend, lastRecv);
if (lastUsed == 0s)
return intro.IsExpired(now);
return now >= lastUsed && (now - lastUsed > lifetime);
}
2023-10-03 20:00:23 +00:00
void
Session::TX()
{
messagesSend++;
lastSend = time_now_ms();
}
2023-10-03 20:00:23 +00:00
void
Session::RX()
{
messagesRecv++;
lastRecv = time_now_ms();
}
2023-10-03 20:00:23 +00:00
} // namespace llarp::service