refactor(native-host): modularize host.js and holesail-manager.js
CI / Build & Test (push) Successful in 2m46s
CI / Build & Test (push) Successful in 2m46s
Split host.js (435 lines) into host/{paths,logger,startup,message-router}.js.
Split holesail-manager.js (698 lines) into holesail-manager/{state,settings,
connections,port-allocator,servers,virtual-hosts,service-tunnels,index}.js.
Top-level host.js and holesail-manager.js become thin shims so index.mjs
requires no changes. Deleted dev scratch file test-cp.mjs.
Updated CI with 12 new node --check lines for all sub-modules.
Updated docs/ARCHITECTURE.md with per-file tables for host/ and
holesail-manager/ sub-modules.
No functionality changed. No new dependencies.
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Port allocator for virtual host tunnel local ports.
|
||||
* Each virtual host gets a unique port on 127.0.0.1 starting at TUNNEL_PORT_BASE.
|
||||
* Released ports are recycled via a free list.
|
||||
*/
|
||||
|
||||
const TUNNEL_PORT_BASE = 19000;
|
||||
|
||||
let nextTunnelPortIndex = 0;
|
||||
const tunnelPortFreeList = [];
|
||||
|
||||
function allocateTunnelPort() {
|
||||
if (tunnelPortFreeList.length > 0) return tunnelPortFreeList.pop();
|
||||
return TUNNEL_PORT_BASE + (nextTunnelPortIndex++);
|
||||
}
|
||||
|
||||
function releaseTunnelPort(port) {
|
||||
if (typeof port === 'number' && port >= TUNNEL_PORT_BASE) {
|
||||
tunnelPortFreeList.push(port);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { TUNNEL_PORT_BASE, allocateTunnelPort, releaseTunnelPort };
|
||||
Reference in New Issue
Block a user