mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-03 23:15:52 +00:00
49 lines
1.1 KiB
C++
49 lines
1.1 KiB
C++
#include "session.hpp"
|
|
|
|
namespace llarp
|
|
{
|
|
namespace service
|
|
{
|
|
util::StatusObject
|
|
Session::ExtractStatus() const
|
|
{
|
|
util::StatusObject obj{
|
|
{"lastSend", to_json(lastSend)},
|
|
{"lastRecv", to_json(lastRecv)},
|
|
{"replyIntro", replyIntro.ExtractStatus()},
|
|
{"remote", remote.Addr().ToString()},
|
|
{"seqno", seqno},
|
|
{"tx", messagesSend},
|
|
{"rx", messagesRecv},
|
|
{"intro", intro.ExtractStatus()}};
|
|
return obj;
|
|
}
|
|
|
|
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 || intro.IsExpired(now));
|
|
}
|
|
|
|
void
|
|
Session::TX()
|
|
{
|
|
messagesSend++;
|
|
lastSend = time_now_ms();
|
|
}
|
|
|
|
void
|
|
Session::RX()
|
|
{
|
|
messagesRecv++;
|
|
lastRecv = time_now_ms();
|
|
}
|
|
|
|
} // namespace service
|
|
} // namespace llarp
|