File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed
Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -15,15 +15,19 @@ const crypto = require('crypto');
1515const path = require ( 'path' ) ;
1616const 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 */
2125function 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/**
You can’t perform that action at this time.
0 commit comments