Skip to content

Commit 316fb36

Browse files
josephfuscoCopilot
andauthored
Update scripts/get-ports.js
Co-authored-by: Copilot <[email protected]>
1 parent 5236d39 commit 316fb36

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

scripts/get-ports.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,19 @@ const crypto = require('crypto');
1515
const path = require('path');
1616
const fs = require('fs');
1717

18+
// Port range constants for deterministic port assignment
19+
const PORT_RANGE = 900; // Number of ports to use
20+
const PORT_BASE = 100; // Starting port (skip first 100 ports)
21+
1822
/**
19-
* Simple hash function that converts a string to a number in range [0, 999]
23+
* Simple hash function that converts a string to a number in range [PORT_BASE, PORT_BASE + PORT_RANGE - 1]
2024
*/
2125
function hashToPort(str) {
2226
const hash = crypto.createHash('sha256').update(str).digest('hex');
23-
// Take first 8 hex chars and convert to decimal, then mod 900 + 100 to get range [100, 999]
24-
// This ensures we skip the first 100 ports to avoid conflicts with common services
27+
// Take first 8 hex chars and convert to decimal, then mod PORT_RANGE + PORT_BASE to get range [PORT_BASE, PORT_BASE + PORT_RANGE - 1]
28+
// This ensures we skip the first PORT_BASE ports to avoid conflicts with common services
2529
const num = parseInt(hash.substring(0, 8), 16);
26-
return (num % 900) + 100;
30+
return (num % PORT_RANGE) + PORT_BASE;
2731
}
2832

2933
/**

0 commit comments

Comments
 (0)