Skip to content

Commit

Permalink
Added additional logging, add additional parameter tcid into the requ…
Browse files Browse the repository at this point in the history
…est.
  • Loading branch information
XHunter74 committed Aug 12, 2024
1 parent f43f993 commit 2422cb6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,19 @@ class Connection extends EventEmitter {
i: key === defaultKey ? 1 : 0,
t: 'pack',
uid: 0,
tcid: payload.mac,
pack: encrypt(payload, key)
};

this.logger.debug(`Request: ${JSON.stringify(request)}`);

const messageHandler = (msg, rinfo) => {
const message = JSON.parse(msg.toString());
let response;

// Check device address data
if (rinfo.address !== address || rinfo.port !== port) {
this.logger.error(`Received message from unexpected address ${rinfo.address}:${rinfo.port}`);
return;
}

Expand All @@ -83,10 +87,12 @@ class Connection extends EventEmitter {
}

if (response.t !== commandsMap[payload.t]) {
this.logger.error(`Response command type ${response.t} does not match expected ${commandsMap[payload.t]}`);
return;
}

if (response.mac !== payload.mac) {
this.logger.error(`Response mac ${response.mac} does not match expected ${payload.mac}`);
return;
}

Expand Down
3 changes: 2 additions & 1 deletion lib/device_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ class DeviceManager extends EventEmitter {
this.logger.info(`New device bound: ${device.name} (${device.address}:${device.port})`);

return device;
} catch {
} catch(error) {
this.logger.error(`Failed to bind device ${deviceId}: ${error.message}`);
return null;
}
}
Expand Down

0 comments on commit 2422cb6

Please sign in to comment.