mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 15:43:13 +09:00
Address review of host pairing
Revoking a host now unassigns its instances instead of being refused while it has any, and removes its system metrics. Approving and revoking no longer force a save. Hosts are saved by autosave and on exit like everything else, which also removes the approving state from pairing requests. The approval code and link are logged as warnings so they show up in the systemd service, which only prints warnings and above. The pairing limits are now the controller.host_pairing_timeout and controller.host_pairing_max_pending config values, 0 removes the limit. Subscribers take an optional permitted function, used for the pairing requests instead of overrides in a subclass.
This commit is contained in:
29 files changed
+356
-418
No files matched your search
@@ -1,19 +1,13 @@
|
||||
import * as lib from "@clusterio/lib";
|
||||
|
||||
/**
|
||||
* Subscriber for the requests from host installers waiting to be approved
|
||||
* Subscriber for the requests from hosts waiting to be approved
|
||||
*
|
||||
* Only accounts that may approve hosts can subscribe to the requests, so
|
||||
* this does not resubscribe on connect or account changes for other
|
||||
* accounts, which would fail with a permission error. The requests only
|
||||
* live in the controller's memory and it does not tell a new session about
|
||||
* requests removed before it started, so the requests are cleared when a
|
||||
* new session starts and fetched again. The same applies to requests removed
|
||||
* while nothing was subscribed, so they are also cleared when subscribing
|
||||
* again after the last handler unsubscribed.
|
||||
* The requests only live in the controller's memory and it does not tell
|
||||
* subscribers about requests removed while nothing was subscribed, so they
|
||||
* are cleared when subscribing again after the last handler unsubscribed.
|
||||
*/
|
||||
export class HostPairingSubscriber extends lib.MapSubscriber<lib.HostPairingUpdatesEvent> {
|
||||
private _permitted: () => boolean;
|
||||
private _handlers = 0;
|
||||
|
||||
/**
|
||||
@@ -21,31 +15,7 @@ export class HostPairingSubscriber extends lib.MapSubscriber<lib.HostPairingUpda
|
||||
* @param permitted - Returns true if the account may approve hosts.
|
||||
*/
|
||||
constructor(control: lib.Link, permitted: () => boolean) {
|
||||
super(lib.HostPairingUpdatesEvent, control);
|
||||
this._permitted = permitted;
|
||||
}
|
||||
|
||||
override handleConnectionEvent(event: "connect" | "drop" | "resume" | "close") {
|
||||
if (event === "connect") {
|
||||
this.values.clear();
|
||||
this.lastUpdatedMs = -1;
|
||||
}
|
||||
if (event === "connect" || event === "resume") {
|
||||
// The account of a new session is reported after the connect event.
|
||||
queueMicrotask(() => {
|
||||
if (this._permitted()) {
|
||||
super.handleConnectionEvent(event);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
super.handleConnectionEvent(event);
|
||||
}
|
||||
|
||||
override handleAccountEvent() {
|
||||
if (this._permitted()) {
|
||||
super.handleAccountEvent();
|
||||
}
|
||||
super(lib.HostPairingUpdatesEvent, control, undefined, permitted);
|
||||
}
|
||||
|
||||
override subscribe(handler: lib.EventSubscriberCallback<lib.HostPairingUpdatesEvent>) {
|
||||
|
||||
Reference in new issue
Block a user