Commit 1907e5f5c8b173c66a9504b6cd88359bbc861427

Authored by Wiebe Cazemier
1 parent 1ee96e98

Don't save sessions from 'clean session' clients

session.cpp
@@ -282,3 +282,13 @@ void Session::removeOutgoingQoS2MessageId(u_int16_t packet_id) @@ -282,3 +282,13 @@ void Session::removeOutgoingQoS2MessageId(u_int16_t packet_id)
282 if (it != outgoingQoS2MessageIds.end()) 282 if (it != outgoingQoS2MessageIds.end())
283 outgoingQoS2MessageIds.erase(it); 283 outgoingQoS2MessageIds.erase(it);
284 } 284 }
  285 +
  286 +bool Session::getCleanSession() const
  287 +{
  288 + auto c = client.lock();
  289 +
  290 + if (!c)
  291 + return false;
  292 +
  293 + return c->getCleanSession();
  294 +}
session.h
@@ -82,6 +82,8 @@ public: @@ -82,6 +82,8 @@ public:
82 82
83 void addOutgoingQoS2MessageId(uint16_t packet_id); 83 void addOutgoingQoS2MessageId(uint16_t packet_id);
84 void removeOutgoingQoS2MessageId(u_int16_t packet_id); 84 void removeOutgoingQoS2MessageId(u_int16_t packet_id);
  85 +
  86 + bool getCleanSession() const;
85 }; 87 };
86 88
87 #endif // SESSION_H 89 #endif // SESSION_H
subscriptionstore.cpp
@@ -685,6 +685,11 @@ void SubscriptionStore::saveSessionsAndSubscriptions(const std::string &filePath @@ -685,6 +685,11 @@ void SubscriptionStore::saveSessionsAndSubscriptions(const std::string &filePath
685 for (const auto &pair : sessionsByIdConst) 685 for (const auto &pair : sessionsByIdConst)
686 { 686 {
687 const Session &org = *pair.second.get(); 687 const Session &org = *pair.second.get();
  688 +
  689 + // Sessions created with clean session need to be destroyed when disconnecting, so no point in saving them.
  690 + if (org.getCleanSession())
  691 + continue;
  692 +
688 sessionCopies.push_back(org.getCopy()); 693 sessionCopies.push_back(org.getCopy());
689 } 694 }
690 695