Fix dev torrential server (#349)
* fix: droplet interface not waiting for torrential * fix: lint
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { CertificateStore } from "./ca-store";
|
||||
import { dropletInterface } from "../services/torrential/droplet-interface";
|
||||
import { logger } from "../logging";
|
||||
|
||||
export type CertificateBundle = {
|
||||
priv: string;
|
||||
@@ -35,6 +36,8 @@ export class CertificateAuthority {
|
||||
await ca.generateClientCertificate("server", "Drop Server");
|
||||
}
|
||||
|
||||
logger.info("initialised the ca");
|
||||
|
||||
return ca;
|
||||
}
|
||||
|
||||
|
||||
@@ -493,8 +493,8 @@ class LibraryManager {
|
||||
|
||||
notificationSystem.systemPush({
|
||||
nonce: `version-create-${gameId}-${version}`,
|
||||
title: `'${game.mName}' ('${version}') finished importing.`,
|
||||
description: `Drop finished importing version ${version} for ${game.mName}.`,
|
||||
title: `'${game.mName}' ('${version.name}') finished importing.`,
|
||||
description: `Drop finished importing version ${version.name} for ${game.mName}.`,
|
||||
actions: [`View|/admin/library/${gameId}`],
|
||||
acls: ["system:import:version:read"],
|
||||
});
|
||||
|
||||
@@ -48,6 +48,9 @@ export class Service<T> {
|
||||
|
||||
private uutils: T;
|
||||
|
||||
private readyPromise: Promise<void>;
|
||||
private readyPromiseResolve: (() => void) | undefined;
|
||||
|
||||
constructor(
|
||||
name: string,
|
||||
executor: Executor,
|
||||
@@ -62,6 +65,9 @@ export class Service<T> {
|
||||
this.setup = setup;
|
||||
this.healthcheck = healthcheck;
|
||||
this.uutils = utils!;
|
||||
this.readyPromise = new Promise((r) => {
|
||||
this.readyPromiseResolve = r;
|
||||
});
|
||||
}
|
||||
|
||||
spin() {
|
||||
@@ -124,6 +130,8 @@ export class Service<T> {
|
||||
}
|
||||
}
|
||||
this.healthy = true;
|
||||
if (this.readyPromiseResolve) this.readyPromiseResolve();
|
||||
this.logger.info("service healthy");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,6 +165,10 @@ export class Service<T> {
|
||||
return this.healthy;
|
||||
}
|
||||
|
||||
async waitServiceHealthy() {
|
||||
await this.readyPromise;
|
||||
}
|
||||
|
||||
utils() {
|
||||
return this.uutils;
|
||||
}
|
||||
|
||||
@@ -250,6 +250,7 @@ class DropletInterfaceManager {
|
||||
messageType: TorrentialBoundType,
|
||||
callbackType: KT,
|
||||
): Promise<Parameters<Extract<K, { type: KT }>["resolve"]>[0]> {
|
||||
await TORRENTIAL_SERVICE.waitServiceHealthy();
|
||||
const messageId = crypto.randomUUID();
|
||||
|
||||
await TORRENTIAL_SERVICE.writeMessage(messageId, {
|
||||
|
||||
@@ -59,7 +59,12 @@ export class TorrentialService extends Service<unknown> {
|
||||
);
|
||||
return spawn(
|
||||
"cargo",
|
||||
["run", "--manifest-path", "./torrential/Cargo.toml"],
|
||||
[
|
||||
"run",
|
||||
"--manifest-path",
|
||||
"./torrential/Cargo.toml",
|
||||
"--release",
|
||||
],
|
||||
{},
|
||||
);
|
||||
} else {
|
||||
@@ -74,14 +79,15 @@ export class TorrentialService extends Service<unknown> {
|
||||
return spawn("torrential", [], {});
|
||||
},
|
||||
async () => {
|
||||
if (this.socket) return true;
|
||||
this.socket = net.createConnection({ port: 33148, host: "127.0.0.1" });
|
||||
await new Promise<void>((r) =>
|
||||
this.socket!.on("connect", () => {
|
||||
const socket = net.createConnection({ port: 33148, host: "127.0.0.1" });
|
||||
await new Promise<void>((r, j) => {
|
||||
socket.on("connect", () => {
|
||||
this.logger.info("connected to torrential socket");
|
||||
this.socket = socket;
|
||||
r();
|
||||
}),
|
||||
);
|
||||
});
|
||||
socket.on("error", (err) => j(err));
|
||||
});
|
||||
|
||||
this.setupRead();
|
||||
return true;
|
||||
@@ -129,6 +135,8 @@ export class TorrentialService extends Service<unknown> {
|
||||
data: T;
|
||||
},
|
||||
) {
|
||||
if (!this.socket) throw "Not connected to torrential";
|
||||
|
||||
const response = create(TorrentialBoundSchema, {
|
||||
messageId: messageId,
|
||||
type: value.type,
|
||||
@@ -146,6 +154,7 @@ export class TorrentialService extends Service<unknown> {
|
||||
}
|
||||
|
||||
private async queueRead() {
|
||||
if (!this.socket) throw "Not connected to torrential";
|
||||
if (this.readbuf.length < 8) return;
|
||||
const sizeBytes = this.readbuf.subarray(0, 8);
|
||||
const size = sizeBytes.readBigUInt64LE(0);
|
||||
|
||||
Reference in New Issue
Block a user