1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Merge pull request #2987 from node-red/clean-ids

Change node id generation to give fixed length values without '.'
This commit is contained in:
Nick O'Leary 2021-05-27 12:18:38 +01:00 committed by GitHub
commit 01b5fc4d49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 9 deletions

View File

@ -210,8 +210,11 @@ RED.nodes = (function() {
})();
function getID() {
// return Math.floor(Math.random()*15728640 + 1048576).toString(16)
return (1+Math.random()*4294967295).toString(16);
var bytes = [];
for (var i=0;i<8;i++) {
bytes.push(Math.round(0xff*Math.random()).toString(16).padStart(2,'0'));
}
return bytes.join("");
}
function parseNodePropertyTypeString(typeString) {

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

@ -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;

View File

@ -31,7 +31,11 @@ const util = require("util");
* @memberof @node-red/util_util
*/
function generateId() {
return (1+Math.random()*4294967295).toString(16);
var bytes = [];
for (var i=0;i<8;i++) {
bytes.push(Math.round(0xff*Math.random()).toString(16).padStart(2,'0'));
}
return bytes.join("");
}
/**