1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00
lokinet/llarp/service/session.cpp

55 lines
1.1 KiB
C++
Raw Normal View History

#include "session.hpp"
namespace llarp
{
namespace service
{
util::StatusObject
Session::ExtractStatus() const
{
2021-03-05 18:31:52 +01:00
util::StatusObject obj{
{"lastSend", to_json(lastSend)},
{"lastRecv", to_json(lastRecv)},
2021-03-05 18:31:52 +01:00
{"replyIntro", replyIntro.ExtractStatus()},
{"remote", Addr().ToString()},
2021-03-05 18:31:52 +01:00
{"seqno", seqno},
{"tx", messagesSend},
{"rx", messagesRecv},
2021-03-05 18:31:52 +01:00
{"intro", intro.ExtractStatus()}};
return obj;
2019-04-26 01:21:19 +02:00
}
Address
Session::Addr() const
{
return remote.Addr();
}
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);
2021-05-03 21:16:23 +02:00
return now >= lastUsed && (now - lastUsed > lifetime);
}
void
Session::TX()
{
messagesSend++;
lastSend = time_now_ms();
}
void
Session::RX()
{
messagesRecv++;
lastRecv = time_now_ms();
}
} // namespace service
} // namespace llarp