From 17072e89f647aba908b60504172401aa849e38ce Mon Sep 17 00:00:00 2001 From: Oskar Eichler Date: Thu, 27 Aug 2026 22:36:01 +0300 Subject: [PATCH] refactor(server): simplify proxy config writes and remove unused state --- .../server/outline_shadowsocks_server.ts | 51 +++++++------------ 1 file changed, 19 insertions(+), 32 deletions(-) diff --git a/src/shadowbox/server/outline_shadowsocks_server.ts b/src/shadowbox/server/outline_shadowsocks_server.ts index 6380cd16..2530c936 100644 --- a/src/shadowbox/server/outline_shadowsocks_server.ts +++ b/src/shadowbox/server/outline_shadowsocks_server.ts @@ -28,7 +28,6 @@ export class OutlineShadowsocksServer implements ShadowsocksServer { private restartDelayMs = 1000; private ipCountryFilename?: string; private ipAsnFilename?: string; - private isAsnMetricsEnabled = false; private isReplayProtectionEnabled = false; /** @@ -70,40 +69,28 @@ export class OutlineShadowsocksServer implements ShadowsocksServer { // Promise is resolved after the outline-ss-config config is updated and the SIGHUP sent. // Keys may not be active yet. // TODO(fortuna): Make promise resolve when keys are ready. - update(keys: ShadowsocksAccessKey[]): Promise { - return this.writeConfigFile(keys).then(() => { - if (!this.ssProcess) { - this.start(); - return Promise.resolve(); - } else { - this.ssProcess.kill('SIGHUP'); - } - }); + async update(keys: ShadowsocksAccessKey[]): Promise { + await this.writeConfigFile(keys); + if (this.ssProcess) { + this.ssProcess.kill('SIGHUP'); + } else { + this.start(); + } } - private writeConfigFile(keys: ShadowsocksAccessKey[]): Promise { - return new Promise((resolve, reject) => { - const keysJson = {keys: [] as ShadowsocksAccessKey[]}; - for (const key of keys) { - if (!isAeadCipher(key.cipher)) { - logging.error( - `Cipher ${key.cipher} for access key ${key.id} is not supported: use an AEAD cipher instead.` - ); - continue; - } - - keysJson.keys.push(key); + private async writeConfigFile(keys: ShadowsocksAccessKey[]): Promise { + const keysJson = {keys: [] as ShadowsocksAccessKey[]}; + for (const key of keys) { + if (!isAeadCipher(key.cipher)) { + logging.error( + `Cipher ${key.cipher} for access key ${key.id} is not supported: use an AEAD cipher instead.` + ); + continue; } - - fs.mkdirSync(path.dirname(this.configFilename), {recursive: true}); - - try { - file.atomicWriteFileSync(this.configFilename, jsyaml.safeDump(keysJson, {sortKeys: true})); - resolve(); - } catch (error) { - reject(error); - } - }); + keysJson.keys.push(key); + } + fs.mkdirSync(path.dirname(this.configFilename), {recursive: true}); + file.atomicWriteFileSync(this.configFilename, jsyaml.safeDump(keysJson, {sortKeys: true})); } private start() {