2021-03-09 22:24:35 +00:00
|
|
|
#include "session.hpp"
|
2019-04-21 18:38:30 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace service
|
|
|
|
{
|
|
|
|
util::StatusObject
|
|
|
|
Session::ExtractStatus() const
|
|
|
|
{
|
2021-03-05 17:31:52 +00:00
|
|
|
util::StatusObject obj{
|
2021-04-02 15:10:37 +00:00
|
|
|
{"lastSend", to_json(lastSend)},
|
|
|
|
{"lastRecv", to_json(lastRecv)},
|
2021-03-05 17:31:52 +00:00
|
|
|
{"replyIntro", replyIntro.ExtractStatus()},
|
2021-06-03 12:21:15 +00:00
|
|
|
{"remote", Addr().ToString()},
|
2021-03-05 17:31:52 +00:00
|
|
|
{"seqno", seqno},
|
2021-04-02 15:10:37 +00:00
|
|
|
{"tx", messagesSend},
|
|
|
|
{"rx", messagesRecv},
|
2021-03-05 17:31:52 +00:00
|
|
|
{"intro", intro.ExtractStatus()}};
|
2019-04-21 18:38:30 +00:00
|
|
|
return obj;
|
2019-04-25 23:21:19 +00:00
|
|
|
}
|
2019-06-14 12:49:45 +00:00
|
|
|
|
2021-06-03 12:21:15 +00:00
|
|
|
Address
|
|
|
|
Session::Addr() const
|
|
|
|
{
|
|
|
|
return remote.Addr();
|
|
|
|
}
|
|
|
|
|
2019-06-14 12:49:45 +00:00
|
|
|
bool
|
|
|
|
Session::IsExpired(llarp_time_t now, llarp_time_t lifetime) const
|
|
|
|
{
|
2021-03-31 17:09:34 +00:00
|
|
|
if (forever)
|
|
|
|
return false;
|
2021-04-02 15:10:37 +00:00
|
|
|
const auto lastUsed = std::max(lastSend, lastRecv);
|
2021-04-03 12:19:46 +00:00
|
|
|
if (lastUsed == 0s)
|
2021-04-02 16:32:07 +00:00
|
|
|
return intro.IsExpired(now);
|
2021-05-03 19:16:23 +00:00
|
|
|
return now >= lastUsed && (now - lastUsed > lifetime);
|
2019-06-14 12:49:45 +00:00
|
|
|
}
|
|
|
|
|
2021-04-02 15:10:37 +00:00
|
|
|
void
|
|
|
|
Session::TX()
|
|
|
|
{
|
|
|
|
messagesSend++;
|
|
|
|
lastSend = time_now_ms();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Session::RX()
|
|
|
|
{
|
|
|
|
messagesRecv++;
|
|
|
|
lastRecv = time_now_ms();
|
|
|
|
}
|
|
|
|
|
2019-04-21 18:38:30 +00:00
|
|
|
} // namespace service
|
|
|
|
} // namespace llarp
|