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:
commit
01b5fc4d49
@ -210,8 +210,11 @@ RED.nodes = (function() {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
function getID() {
|
function getID() {
|
||||||
// return Math.floor(Math.random()*15728640 + 1048576).toString(16)
|
var bytes = [];
|
||||||
return (1+Math.random()*4294967295).toString(16);
|
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) {
|
function parseNodePropertyTypeString(typeString) {
|
||||||
|
@ -314,7 +314,7 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Build options for passing to the MQTT.js API
|
// 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.username = this.username;
|
||||||
this.options.password = this.password;
|
this.options.password = this.password;
|
||||||
this.options.keepalive = this.keepalive;
|
this.options.keepalive = this.keepalive;
|
||||||
|
@ -92,7 +92,7 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleConnection(/*socket*/socket) {
|
function handleConnection(/*socket*/socket) {
|
||||||
var id = (1+Math.random()*4294967295).toString(16);
|
var id = RED.util.generateId();
|
||||||
if (node.isServer) {
|
if (node.isServer) {
|
||||||
node._clients[id] = socket;
|
node._clients[id] = socket;
|
||||||
node.emit('opened',{count:Object.keys(node._clients).length,id:id});
|
node.emit('opened',{count:Object.keys(node._clients).length,id:id});
|
||||||
|
@ -69,7 +69,7 @@ module.exports = function(RED) {
|
|||||||
var setupTcpClient = function() {
|
var setupTcpClient = function() {
|
||||||
node.log(RED._("tcpin.status.connecting",{host:node.host,port:node.port}));
|
node.log(RED._("tcpin.status.connecting",{host:node.host,port:node.port}));
|
||||||
node.status({fill:"grey",shape:"dot",text:"common.status.connecting"});
|
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() {
|
client = net.connect(node.port, node.host, function() {
|
||||||
buffer = (node.datatype == 'buffer') ? Buffer.alloc(0) : "";
|
buffer = (node.datatype == 'buffer') ? Buffer.alloc(0) : "";
|
||||||
node.connected = true;
|
node.connected = true;
|
||||||
@ -153,7 +153,7 @@ module.exports = function(RED) {
|
|||||||
var server = net.createServer(function (socket) {
|
var server = net.createServer(function (socket) {
|
||||||
socket.setKeepAlive(true,120000);
|
socket.setKeepAlive(true,120000);
|
||||||
if (socketTimeout !== null) { socket.setTimeout(socketTimeout); }
|
if (socketTimeout !== null) { socket.setTimeout(socketTimeout); }
|
||||||
var id = (1+Math.random()*4294967295).toString(16);
|
var id = RED.util.generateId();
|
||||||
var fromi;
|
var fromi;
|
||||||
var fromp;
|
var fromp;
|
||||||
connectionPool[id] = socket;
|
connectionPool[id] = socket;
|
||||||
|
@ -31,7 +31,11 @@ const util = require("util");
|
|||||||
* @memberof @node-red/util_util
|
* @memberof @node-red/util_util
|
||||||
*/
|
*/
|
||||||
function generateId() {
|
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("");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user