Change node id generation to give fixed length values without '.'

This commit is contained in:
Nick O'Leary
2021-05-18 11:32:17 +01:00
parent 6b43a23c4b
commit 8bbed2c831
5 changed files with 16 additions and 9 deletions

View File

@@ -314,7 +314,7 @@ module.exports = function(RED) {
}
// Build options for passing to the MQTT.js API
this.options.clientId = this.clientid || 'mqtt_' + (1+Math.random()*4294967295).toString(16);
this.options.clientId = this.clientid || 'mqtt_' + RED.util.generateId();
this.options.username = this.username;
this.options.password = this.password;
this.options.keepalive = this.keepalive;

View File

@@ -62,14 +62,14 @@ module.exports = function(RED) {
if (process.env.HTTP_PROXY) { prox = process.env.HTTP_PROXY; }
if (process.env.no_proxy) { noprox = process.env.no_proxy.split(","); }
if (process.env.NO_PROXY) { noprox = process.env.NO_PROXY.split(","); }
var noproxy = false;
if (noprox) {
for (var i in noprox) {
if (node.path.indexOf(noprox[i].trim()) !== -1) { noproxy=true; }
}
}
var agent = undefined;
if (prox && !noproxy) {
agent = new HttpsProxyAgent(prox);
@@ -92,7 +92,7 @@ module.exports = function(RED) {
}
function handleConnection(/*socket*/socket) {
var id = (1+Math.random()*4294967295).toString(16);
var id = RED.util.generateId();
if (node.isServer) {
node._clients[id] = socket;
node.emit('opened',{count:Object.keys(node._clients).length,id:id});

View File

@@ -69,7 +69,7 @@ module.exports = function(RED) {
var setupTcpClient = function() {
node.log(RED._("tcpin.status.connecting",{host:node.host,port:node.port}));
node.status({fill:"grey",shape:"dot",text:"common.status.connecting"});
var id = (1+Math.random()*4294967295).toString(16);
var id = RED.util.generateId();
client = net.connect(node.port, node.host, function() {
buffer = (node.datatype == 'buffer') ? Buffer.alloc(0) : "";
node.connected = true;
@@ -153,7 +153,7 @@ module.exports = function(RED) {
var server = net.createServer(function (socket) {
socket.setKeepAlive(true,120000);
if (socketTimeout !== null) { socket.setTimeout(socketTimeout); }
var id = (1+Math.random()*4294967295).toString(16);
var id = RED.util.generateId();
var fromi;
var fromp;
connectionPool[id] = socket;