Dont duplicate interfaces on port change 3.0
This commit is contained in:
+20
-19
@@ -5,15 +5,19 @@ import {
|
||||
defaultStratumPort,
|
||||
defaultStratumTlsPort,
|
||||
stratumHostId,
|
||||
stratumInternalPort,
|
||||
stratumTlsHostId,
|
||||
stratumTlsInternalPort,
|
||||
uiHostId,
|
||||
uiPort,
|
||||
} from './utils'
|
||||
|
||||
export const setInterfaces = sdk.setupInterfaces(async ({ effects }) => {
|
||||
// Stratum ports are user config. Read reactively so changing them in the
|
||||
// Configure action re-runs this and rebinds the interfaces — the same
|
||||
// mechanism that adds/removes the TLS interface when TLS is toggled.
|
||||
// The user's stratum ports are EXTERNAL ports only. Read reactively so
|
||||
// changing them in the Configure action re-runs this and updates the
|
||||
// binding — the same mechanism that adds/removes the TLS interface when TLS
|
||||
// is toggled. The in-container ports stay fixed (see utils.ts), so each
|
||||
// change updates the existing binding rather than orphaning it.
|
||||
const ports = await storeJson
|
||||
.read((s) => ({
|
||||
stratum: s.stratumPort,
|
||||
@@ -22,8 +26,8 @@ export const setInterfaces = sdk.setupInterfaces(async ({ effects }) => {
|
||||
}))
|
||||
.const(effects)
|
||||
|
||||
const stratumPort = ports?.stratum ?? defaultStratumPort
|
||||
const stratumTlsPort = ports?.stratumTls ?? defaultStratumTlsPort
|
||||
const externalStratumPort = ports?.stratum ?? defaultStratumPort
|
||||
const externalStratumTlsPort = ports?.stratumTls ?? defaultStratumTlsPort
|
||||
|
||||
// Web dashboard
|
||||
const uiMulti = sdk.MultiHost.of(effects, uiHostId)
|
||||
@@ -50,9 +54,9 @@ export const setInterfaces = sdk.setupInterfaces(async ({ effects }) => {
|
||||
// forwards raw TCP on the LAN, so miners connect directly to the host at
|
||||
// the assigned external port; no router forward or simpleproxy needed.
|
||||
const stratumMulti = sdk.MultiHost.of(effects, stratumHostId)
|
||||
const stratumOrigin = await stratumMulti.bindPort(stratumPort, {
|
||||
const stratumOrigin = await stratumMulti.bindPort(stratumInternalPort, {
|
||||
protocol: null,
|
||||
preferredExternalPort: stratumPort,
|
||||
preferredExternalPort: externalStratumPort,
|
||||
addSsl: null,
|
||||
secure: { ssl: false },
|
||||
})
|
||||
@@ -77,9 +81,9 @@ export const setInterfaces = sdk.setupInterfaces(async ({ effects }) => {
|
||||
// the noSsl scheme is deliberately stratum+ssl.
|
||||
if (ports?.tlsEnabled) {
|
||||
const tlsMulti = sdk.MultiHost.of(effects, stratumTlsHostId)
|
||||
const tlsOrigin = await tlsMulti.bindPort(stratumTlsPort, {
|
||||
const tlsOrigin = await tlsMulti.bindPort(stratumTlsInternalPort, {
|
||||
protocol: null,
|
||||
preferredExternalPort: stratumTlsPort,
|
||||
preferredExternalPort: externalStratumTlsPort,
|
||||
addSsl: null,
|
||||
secure: { ssl: false },
|
||||
})
|
||||
@@ -99,20 +103,17 @@ export const setInterfaces = sdk.setupInterfaces(async ({ effects }) => {
|
||||
receipts.push(await tlsOrigin.export([stratumTls]))
|
||||
}
|
||||
|
||||
// Drop bindings we no longer use. `bindPort` registers a binding per
|
||||
// (hostId, internalPort) and nothing removes the old one when the user
|
||||
// changes a port in Configure — the stale binding lingers and the OS lists
|
||||
// its interface again, so the UI shows two identical "Stratum" entries (and
|
||||
// keeps a forward open on the abandoned port). Packages with fixed ports
|
||||
// never hit this; ours has user-configurable ports, so it must clean up
|
||||
// after itself. Runs last, after the current bindings exist, so the `except`
|
||||
// list is exactly what we just bound.
|
||||
// Drop bindings we no longer use — primarily the stratum-tls binding after
|
||||
// the user disables TLS. With fixed internal ports this no longer has to
|
||||
// clean up after port changes (the whole point of keeping them fixed), but
|
||||
// it still matters for the TLS toggle, and it clears orphans left by older
|
||||
// versions of this package that did move the internal port.
|
||||
await sdk.clearBindings(effects, {
|
||||
except: [
|
||||
{ id: uiHostId, internalPort: uiPort },
|
||||
{ id: stratumHostId, internalPort: stratumPort },
|
||||
{ id: stratumHostId, internalPort: stratumInternalPort },
|
||||
...(ports?.tlsEnabled
|
||||
? [{ id: stratumTlsHostId, internalPort: stratumTlsPort }]
|
||||
? [{ id: stratumTlsHostId, internalPort: stratumTlsInternalPort }]
|
||||
: []),
|
||||
],
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user