fix(cli): elect managed service by port bind (#37572) · argszero/opencode@6ea8247 · GitHub
Skip to content

Commit 6ea8247

Browse files
fix(cli): elect managed service by port bind (anomalyco#37572)
Co-authored-by: Dax Raad <thdxr@users.noreply.github.com>
1 parent 987242b commit 6ea8247

6 files changed

Lines changed: 232 additions & 39 deletions

File tree

packages/cli/src/server-process.ts

Lines changed: 58 additions & 20 deletions

packages/cli/src/services/service-config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ export function filename(channel = InstallationChannel) {
3030
return `service-${Hash.fast(channel)}.json`
3131
}
3232

33+
export function defaultPort(channel = InstallationChannel) {
34+
if (channel === "latest") return 0xc0de
35+
if (channel === "local") return 0xc0df
36+
return 10_000 + (Number.parseInt(Hash.fast(channel).slice(0, 8), 16) % 50_000)
37+
}
38+
3339
export function versionBelongsToChannel(
3440
version: string | undefined,
3541
channel = InstallationChannel,

packages/cli/test/service.test.ts

Lines changed: 136 additions & 7 deletions

0 commit comments

Comments
 (0)