mosca icon indicating copy to clipboard operation
mosca copied to clipboard

connack sessionPresent flag is not send

Open mazhack opened this issue 11 years ago • 2 comments

client's cleansession flag is false and session was stored, but sessionPresent is not send, paho client always set sessionPresent false, i review the client.js code and i dont find the sessionPresent flag...

  that.server.restoreClientSubscriptions(that, function() {
      client.connack({
        returnCode: 0
      });

      that.logger.info("client connected");
      that.server.emit("clientConnected", that);
      that.server.forwardOfflinePackets(that);
  });

connack never send sessionPresent flag... i can make a patch, but is necesary change the callback and persistence code, some like this:

  that.server.restoreClientSubscriptions(that, function(session_present) {  
       client.connack({
        returnCode: 0,
       // maybe session_present is null, custom old persistence engine
       // or not persistence defined
        sessionPresent: session_present ? true : false
      });

      that.logger.info("client connected");
      that.server.emit("clientConnected", that);
      that.server.forwardOfflinePackets(that);
  });

in persistence/abstract.js

 server.restoreClientSubscriptions = function restoreClientSubscriptions(client, done) {
    that.lookupSubscriptions(client, function(err, subscriptions) {
      if (err) {
        client.emit("error", err);
        return;
      }

      var subs = Object.keys(subscriptions);
      async.each(subs, function(topic, inCb) {
        client.logger.debug({ topic: topic, qos: subscriptions[topic].qos }, "restoring subscription");
        client.handleAuthorizeSubscribe(
          null, true, {
          topic: topic,
          qos: subscriptions[topic].qos
        }, inCb);
      }, function(){ done(subs.length === 0 ? false : true) });
    });
  };

what do you think about this?

mazhack avatar Mar 31 '15 22:03 mazhack

If you could send a PR it would be awesome! I knew about this problem, but I did not have enough bandwidth to get this sorted soonish.

mcollina avatar Apr 01 '15 18:04 mcollina

I make the patch, but test it is too hard... I am still working on that

mazhack avatar Apr 02 '15 03:04 mazhack