-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathking-config.ts
More file actions
45 lines (38 loc) · 1.53 KB
/
Copy pathking-config.ts
File metadata and controls
45 lines (38 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import assert from "assert";
import {KingArguments} from "../cmds/king-cmd.js";
export interface KingRatholeConfig {
ports: string;
bind_port: number;
}
export class KingConfig {
ratholes: KingRatholeConfig[] = [];
location: string;
host: string;
councilHost: string;
noisePrivateKey: string | null;
noisePublicKey: string | null;
constructor (args: KingArguments) {
this.location = args.location;
this.host = args.host;
this.councilHost = args.councilHost;
const hasPrivate = args.noisePrivateKey != null;
const hasPublic = args.noisePublicKey != null;
assert(hasPrivate === hasPublic, "--noise-private-key and --noise-public-key must both be set or both be omitted");
this.noisePrivateKey = args.noisePrivateKey ?? null;
this.noisePublicKey = args.noisePublicKey ?? null;
for (const ratholeArg of args.rathole ?? []) {
const pairs: {[key: string]: string} = {};
for (const pair of ratholeArg.split(" ")) {
const key = pair.split("=")[0];
pairs[key] = pair.split("=")[1];
}
assert(pairs["bind_port"] != null, "--rathole must have 'bind_port' field");
assert(pairs["ports"] != null, "--rathole must have 'name' field");
this.ratholes.push({
ports: pairs["ports"],
bind_port: Number(pairs["bind_port"]),
});
}
assert(this.ratholes.length > 0, "One --rathole must be specified");
}
}