Skip to content

Commit

Permalink
update to 1.6.3
Browse files Browse the repository at this point in the history
  • Loading branch information
seriousme committed Jan 31, 2025
1 parent 151caaa commit 88ae329
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@seriousme/opifex",
"version": "1.6.2",
"version": "1.6.3",
"license": "MIT",
"exports": {
"./server": "./server/mod.ts",
Expand Down
1 change: 1 addition & 0 deletions dist/persistence/memory/memoryPersistence.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Trie, } from "../deps.js";
import { assert } from "../../utils/mod.js";
const maxPacketId = 0xffff;
export class MemoryStore {
existingSession = false;
clientId;
packetId;
pendingIncoming;
Expand Down
51 changes: 30 additions & 21 deletions dist/server/handlers/handleConnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,36 @@ function validateConnect(ctx, packet) {
* @param ctx - The connection context
* @param clientId - The client ID
*/
function processValidatedConnect(packet, ctx, clientId) {
if (packet.will) {
ctx.will = {
type: PacketType.publish,
qos: packet.will.qos,
retain: packet.will.retain,
topic: packet.will.topic,
payload: packet.will.payload,
};
}
ctx.connect(clientId, packet.clean || false);
const keepAlive = packet.keepAlive || 0;
if (keepAlive > 0) {
logger.debug(`Setting keepalive to ${keepAlive * 1500} ms`);
ctx.timer = new Timer(() => {
ctx.close();
}, Math.floor(keepAlive * 1500));
function processValidatedConnect(returnCode, packet, ctx, clientId) {
if (returnCode === AuthenticationResult.ok) {
if (packet.will) {
ctx.will = {
type: PacketType.publish,
qos: packet.will.qos,
retain: packet.will.retain,
topic: packet.will.topic,
payload: packet.will.payload,
};
}
ctx.connect(clientId, packet.clean || false);
const keepAlive = packet.keepAlive || 0;
if (keepAlive > 0) {
logger.debug(`Setting keepalive to ${keepAlive * 1500} ms`);
ctx.timer = new Timer(() => {
ctx.close();
}, Math.floor(keepAlive * 1500));
}
// is this a new session?
// either because its the first time for the client
// or it specifically asked for a clean one
const previousSession = ctx.store?.existingSession;
// client now has a history
if (!previousSession && ctx.store) {
ctx.store.existingSession = true;
}
return previousSession || false;
}
return false;
}
/**
* Handles the MQTT CONNECT packet
Expand All @@ -56,10 +68,7 @@ function processValidatedConnect(packet, ctx, clientId) {
export function handleConnect(ctx, packet) {
const clientId = packet.clientId || `Opifex-${crypto.randomUUID()}`;
const returnCode = validateConnect(ctx, packet);
if (returnCode === AuthenticationResult.ok) {
processValidatedConnect(packet, ctx, clientId);
}
const sessionPresent = false;
const sessionPresent = processValidatedConnect(returnCode, packet, ctx, clientId);
ctx.send({
type: PacketType.connack,
sessionPresent,
Expand Down

0 comments on commit 88ae329

Please sign in to comment.