Skip to content

Commit c7511f9

Browse files
committed
Revert "refactor(server): use the new service config format (#1628)"
This reverts commit 13f6239.
1 parent 7e6ce56 commit c7511f9

File tree

1 file changed

+7
-38
lines changed

1 file changed

+7
-38
lines changed

src/shadowbox/server/outline_shadowsocks_server.ts

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,12 @@ import * as file from '../infrastructure/file';
2121
import * as logging from '../infrastructure/logging';
2222
import {ShadowsocksAccessKey, ShadowsocksServer} from '../model/shadowsocks_server';
2323

24-
/** Represents an outline-ss-server configuration with multiple services. */
25-
export interface OutlineSSServerConfig {
26-
services: {
27-
listeners: {
28-
type: string;
29-
address: string;
30-
}[];
31-
keys: {
32-
id: string;
33-
cipher: string;
34-
secret: string;
35-
}[];
36-
}[];
37-
}
38-
3924
// Runs outline-ss-server.
4025
export class OutlineShadowsocksServer implements ShadowsocksServer {
4126
private ssProcess: child_process.ChildProcess;
4227
private ipCountryFilename?: string;
4328
private ipAsnFilename?: string;
29+
private isAsnMetricsEnabled = false;
4430
private isReplayProtectionEnabled = false;
4531

4632
/**
@@ -95,39 +81,22 @@ export class OutlineShadowsocksServer implements ShadowsocksServer {
9581

9682
private writeConfigFile(keys: ShadowsocksAccessKey[]): Promise<void> {
9783
return new Promise((resolve, reject) => {
98-
const validKeys: ShadowsocksAccessKey[] = keys.filter((key) => {
84+
const keysJson = {keys: [] as ShadowsocksAccessKey[]};
85+
for (const key of keys) {
9986
if (!isAeadCipher(key.cipher)) {
10087
logging.error(
10188
`Cipher ${key.cipher} for access key ${key.id} is not supported: use an AEAD cipher instead.`
10289
);
103-
return false;
90+
continue;
10491
}
105-
return true;
106-
});
10792

108-
const config: OutlineSSServerConfig = {services: []};
109-
const keysByPort: Record<number, ShadowsocksAccessKey[]> = {};
110-
for (const key of validKeys) {
111-
(keysByPort[key.port] ??= []).push(key);
112-
}
113-
for (const port in keysByPort) {
114-
const service = {
115-
listeners: [
116-
{type: 'tcp', address: `[::]:${port}`},
117-
{type: 'udp', address: `[::]:${port}`},
118-
],
119-
keys: keysByPort[port].map((key) => ({
120-
id: key.id,
121-
cipher: key.cipher,
122-
secret: key.secret,
123-
})),
124-
};
125-
config.services.push(service);
93+
keysJson.keys.push(key);
12694
}
12795

12896
mkdirp.sync(path.dirname(this.configFilename));
97+
12998
try {
130-
file.atomicWriteFileSync(this.configFilename, jsyaml.safeDump(config, {sortKeys: true}));
99+
file.atomicWriteFileSync(this.configFilename, jsyaml.safeDump(keysJson, {sortKeys: true}));
131100
resolve();
132101
} catch (error) {
133102
reject(error);

0 commit comments

Comments
 (0)