Make single port driven by rollout

This commit is contained in:
fortuna 2018-12-13 17:38:42 -05:00
parent 5eda24d0b9
commit 2ae5b49071
2 changed files with 9 additions and 1 deletions

View file

@ -176,6 +176,9 @@ async function main() {
const accessKeyRepository = new ServerAccessKeyRepository(
portProvider, proxyHostname, accessKeyConfig, shadowsocksServer);
if (createRolloutTracker(serverConfig).isRolloutEnabled('single-port', 0)) {
accessKeyRepository.enableSinglePort();
}
const prometheusClient = new PrometheusClient(`http://${prometheusLocation}`);
const metricsReader = new PrometheusUsageMetrics(prometheusClient);

View file

@ -63,6 +63,7 @@ function makeAccessKey(hostname: string, accessKeyJson: AccessKeyConfig): Access
export class ServerAccessKeyRepository implements AccessKeyRepository {
// This is the max id + 1 among all access keys. Used to generate unique ids for new access keys.
private NEW_USER_ENCRYPTION_METHOD = 'chacha20-ietf-poly1305';
private singlePortEnabled = false;
constructor(
private portProvider: PortProvider, private proxyHostname: string,
@ -77,8 +78,12 @@ export class ServerAccessKeyRepository implements AccessKeyRepository {
this.updateServer();
}
enableSinglePort() {
this.singlePortEnabled = true;
}
async createNewAccessKey(): Promise<AccessKey> {
const port = await this.getDefaultPort();
const port = await (this.singlePortEnabled ? this.getDefaultPort() : this.portProvider.reserveNewPort());
const id = this.keyConfig.data().nextId.toString();
this.keyConfig.data().nextId += 1;
const metricsId = uuidv4();