-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathking-syncer.ts
More file actions
39 lines (33 loc) · 1.26 KB
/
Copy pathking-syncer.ts
File metadata and controls
39 lines (33 loc) · 1.26 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
import got from "got";
import {Ticker} from "../ticker.js";
import {KingContext} from "../contexts/king-context.js";
import {to} from "../utils.js";
export class KingSyncer extends Ticker {
private readonly context;
constructor (context: KingContext) {
super({interval: 1000, tick: async () => this.sync()});
this.context = context;
}
private async sync () {
const config = this.context.config;
const logger = this.context.logger;
const [err, response] = await to(got(`${config.councilHost}/king`, {
method: "PUT",
json: {
host: config.host,
shutting_down: this.context.shuttingDown,
ratholes: this.context.config.ratholes,
ready_service_ids: this.context.readyServiceIds,
location: this.context.config.location,
noise_public_key: this.context.config.noisePublicKey,
},
}));
if (err || response.statusCode !== 200) {
logger.error("Failed to sync with council", {
"error.message": err?.response?.body?.slice(4096) ?? err.message,
"error.stack_trace": err?.stack,
"service.type": "ratking",
});
}
}
}