From 1907e5f5c8b173c66a9504b6cd88359bbc861427 Mon Sep 17 00:00:00 2001 From: Wiebe Cazemier Date: Wed, 24 Nov 2021 19:47:31 +0100 Subject: [PATCH] Don't save sessions from 'clean session' clients --- session.cpp | 10 ++++++++++ session.h | 2 ++ subscriptionstore.cpp | 5 +++++ 3 files changed, 17 insertions(+), 0 deletions(-) diff --git a/session.cpp b/session.cpp index 8d6f45e..0cb9756 100644 --- a/session.cpp +++ b/session.cpp @@ -282,3 +282,13 @@ void Session::removeOutgoingQoS2MessageId(u_int16_t packet_id) if (it != outgoingQoS2MessageIds.end()) outgoingQoS2MessageIds.erase(it); } + +bool Session::getCleanSession() const +{ + auto c = client.lock(); + + if (!c) + return false; + + return c->getCleanSession(); +} diff --git a/session.h b/session.h index 3f2baf5..366140e 100644 --- a/session.h +++ b/session.h @@ -82,6 +82,8 @@ public: void addOutgoingQoS2MessageId(uint16_t packet_id); void removeOutgoingQoS2MessageId(u_int16_t packet_id); + + bool getCleanSession() const; }; #endif // SESSION_H diff --git a/subscriptionstore.cpp b/subscriptionstore.cpp index 6bde727..a0a54ee 100644 --- a/subscriptionstore.cpp +++ b/subscriptionstore.cpp @@ -685,6 +685,11 @@ void SubscriptionStore::saveSessionsAndSubscriptions(const std::string &filePath for (const auto &pair : sessionsByIdConst) { const Session &org = *pair.second.get(); + + // Sessions created with clean session need to be destroyed when disconnecting, so no point in saving them. + if (org.getCleanSession()) + continue; + sessionCopies.push_back(org.getCopy()); } -- libgit2 0.21.4