Skip to content

Commit

Permalink
Set keepalive after auth, save mem if auth fails
Browse files Browse the repository at this point in the history
  • Loading branch information
gnought committed Jul 25, 2019
1 parent a45d913 commit b567a24
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions lib/handlers/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function ClientPacketStatus (client, packet) {

var connectActions = [
authenticate,
setKeepAlive,
fetchSubs,
restoreSubs,
storeWill,
Expand Down Expand Up @@ -47,14 +48,6 @@ function handleConnect (client, packet, done) {
clearTimeout(client._connectTimer)
client._connectTimer = null

if (packet.keepalive > 0) {
client._keepaliveInterval = (packet.keepalive * 1500) + 1
client._keepaliveTimer = retimer(function keepaliveTimeout () {
client.broker.emit('keepaliveTimeout', client)
client.emit('error', new Error('keep alive timeout'))
}, client._keepaliveInterval)
}

client.broker._series(
new ClientPacketStatus(client, packet),
connectActions, {}, function (err) {
Expand Down Expand Up @@ -110,6 +103,19 @@ function authenticate (arg, done) {
}
}

function setKeepAlive (arg, done) {
if (this.packet.keepalive > 0) {
var client = this.client
// [MQTT-3.1.2-24]
client._keepaliveInterval = (this.packet.keepalive * 1500) + 1
client._keepaliveTimer = retimer(function keepaliveTimeout () {
client.broker.emit('keepaliveTimeout', client)
client.emit('error', new Error('keep alive timeout'))
}, client._keepaliveInterval)
}
done()
}

function fetchSubs (arg, done) {
if (!this.packet.clean) {
this.client.broker.persistence.subscriptionsByClient({
Expand Down

0 comments on commit b567a24

Please sign in to comment.