| github: goldfire |
+19
-10
@@ -7,3 +7,3 @@ /** | ||
| const shortid = require('shortid'); | ||
| const {customAlphabet} = require('nanoid'); | ||
| const dgram = require('dgram'); | ||
@@ -16,2 +16,5 @@ const {EventEmitter} = require('events'); | ||
| // Match original shortid usage for generating unique IDs. | ||
| const nanoid = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz', 10); | ||
| /** | ||
@@ -39,3 +42,3 @@ * Setup the base Democracy class that handles all of the methods. | ||
| weight: options.weight || Math.random() * Date.now(), | ||
| id: options.id || shortid.generate(), | ||
| id: options.id || nanoid(), | ||
| channels: options.channels || [], | ||
@@ -154,3 +157,3 @@ }; | ||
| const count = Math.ceil(str.length / chunkSize); | ||
| const packetId = shortid.generate(); | ||
| const packetId = nanoid(); | ||
@@ -393,7 +396,7 @@ for (let i = 0; i < count; i += 1) { | ||
| // Count the number of voters that haven't been marked for election. | ||
| for (let i = 0; i < this._nodes.length; i += 1) { | ||
| if (this._nodes[i] && !this._nodes[i].voters.length) { | ||
| Object.keys(this._nodes).forEach((id) => { | ||
| if (this._nodes[id] && !this._nodes[id].voters.length && this._nodes[id].state != 'removed') { | ||
| numVoters += 1; | ||
| } | ||
| } | ||
| }); | ||
@@ -442,8 +445,14 @@ // If we have concensus, remove this node from the list. | ||
| // Elect a new leader based on highest weight. | ||
| // Elect a new leader based on highest weight (and ID as tie-breaker). | ||
| // Each server should always elect the same leader. | ||
| Object.keys(nodes).forEach((id) => { | ||
| if (nodes[id] && nodes[id].weight > highestWeight && nodes[id].state !== 'removed') { | ||
| highestWeight = nodes[id].weight; | ||
| newLeader = id; | ||
| const node = nodes[id]; | ||
| if (node && node.state !== 'removed') { | ||
| if ( | ||
| node.weight > highestWeight || | ||
| (node.weight === highestWeight && id > newLeader) | ||
| ) { | ||
| highestWeight = node.weight; | ||
| newLeader = id; | ||
| } | ||
| } | ||
@@ -450,0 +459,0 @@ }); |
+3
-3
| { | ||
| "name": "democracy", | ||
| "version": "3.1.3", | ||
| "version": "4.0.0", | ||
| "description": "Node.js unicast discovery, master-slave elections and pub/sub.", | ||
@@ -28,3 +28,3 @@ "homepage": "https://github.com/goldfire/democracy.js", | ||
| "dependencies": { | ||
| "shortid": "2.2.14" | ||
| "nanoid": "3.3.7" | ||
| }, | ||
@@ -37,4 +37,4 @@ "devDependencies": { | ||
| "engines": [ | ||
| "node >= 6.4.0" | ||
| "node >= 16.0.0" | ||
| ] | ||
| } |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
22843
1.41%8
14.29%521
1.56%+ Added
+ Added
- Removed
- Removed
- Removed