diff --git a/server/internal/clients/ca.ts b/server/internal/clients/ca.ts index 2e027d82..848032c8 100644 --- a/server/internal/clients/ca.ts +++ b/server/internal/clients/ca.ts @@ -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; } diff --git a/server/internal/library/index.ts b/server/internal/library/index.ts index da9bbcff..057f5ad6 100644 --- a/server/internal/library/index.ts +++ b/server/internal/library/index.ts @@ -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"], }); diff --git a/server/internal/services/index.ts b/server/internal/services/index.ts index e155182a..c019fe67 100644 --- a/server/internal/services/index.ts +++ b/server/internal/services/index.ts @@ -48,6 +48,9 @@ export class Service { private uutils: T; + private readyPromise: Promise; + private readyPromiseResolve: (() => void) | undefined; + constructor( name: string, executor: Executor, @@ -62,6 +65,9 @@ export class Service { 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 { } } this.healthy = true; + if (this.readyPromiseResolve) this.readyPromiseResolve(); + this.logger.info("service healthy"); } } @@ -157,6 +165,10 @@ export class Service { return this.healthy; } + async waitServiceHealthy() { + await this.readyPromise; + } + utils() { return this.uutils; } diff --git a/server/internal/services/torrential/droplet-interface.ts b/server/internal/services/torrential/droplet-interface.ts index a363f76a..8b8e5a2b 100644 --- a/server/internal/services/torrential/droplet-interface.ts +++ b/server/internal/services/torrential/droplet-interface.ts @@ -250,6 +250,7 @@ class DropletInterfaceManager { messageType: TorrentialBoundType, callbackType: KT, ): Promise["resolve"]>[0]> { + await TORRENTIAL_SERVICE.waitServiceHealthy(); const messageId = crypto.randomUUID(); await TORRENTIAL_SERVICE.writeMessage(messageId, { diff --git a/server/internal/services/torrential/index.ts b/server/internal/services/torrential/index.ts index a0b7211a..283d0c28 100644 --- a/server/internal/services/torrential/index.ts +++ b/server/internal/services/torrential/index.ts @@ -59,7 +59,12 @@ export class TorrentialService extends Service { ); 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 { return spawn("torrential", [], {}); }, async () => { - if (this.socket) return true; - this.socket = net.createConnection({ port: 33148, host: "127.0.0.1" }); - await new Promise((r) => - this.socket!.on("connect", () => { + const socket = net.createConnection({ port: 33148, host: "127.0.0.1" }); + await new Promise((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 { 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 { } 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);