MCPcopy Create free account
hub / github.com/MCSManager/MCSManager / allocatePort

Method allocatePort

daemon/src/entity/instance/instance.ts:286–307  ·  view source on GitHub ↗
(cfg: InstanceConfig)

Source from the content-addressed store, hash-verified

284 }
285
286 allocatePort(cfg: InstanceConfig) {
287 const globalCfg = globalConfiguration.config;
288 const [minPort, maxPort] = globalCfg.allocatablePortRange;
289
290 cfg.basePort = globalCfg.currentAllocatablePort;
291 globalCfg.currentAllocatablePort += globalCfg.portAssignInterval;
292
293 if (globalCfg.currentAllocatablePort > maxPort) {
294 globalCfg.currentAllocatablePort = minPort;
295 }
296
297 // Avoid port overlap with Daemon.
298 if (
299 cfg.basePort <= globalCfg.port &&
300 cfg.basePort + globalCfg.portAssignInterval >= globalCfg.port
301 ) {
302 cfg.basePort = globalCfg.port + 1;
303 globalCfg.currentAllocatablePort = cfg.basePort + globalCfg.portAssignInterval;
304 }
305
306 globalConfiguration.store();
307 }
308
309 resetConfigWithoutDocker() {
310 const newDockerCfg: IGlobalInstanceConfig["docker"] = JSON.parse(

Callers 1

parametersMethod · 0.95

Calls 1

storeMethod · 0.65

Tested by

no test coverage detected