Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions server/internal/clients/ca.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -35,6 +36,8 @@ export class CertificateAuthority {
await ca.generateClientCertificate("server", "Drop Server");
}

logger.info("initialised the ca");

return ca;
}

Expand Down
4 changes: 2 additions & 2 deletions server/internal/library/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
});
Expand Down
12 changes: 12 additions & 0 deletions server/internal/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ export class Service<T> {

private uutils: T;

private readyPromise: Promise<void>;
private readyPromiseResolve: (() => void) | undefined;

constructor(
name: string,
executor: Executor,
Expand All @@ -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() {
Expand Down Expand Up @@ -124,6 +130,8 @@ export class Service<T> {
}
}
this.healthy = true;
if (this.readyPromiseResolve) this.readyPromiseResolve();
this.logger.info("service healthy");
}
}

Expand Down Expand Up @@ -157,6 +165,10 @@ export class Service<T> {
return this.healthy;
}

async waitServiceHealthy() {
await this.readyPromise;
}

utils() {
return this.uutils;
}
Expand Down
1 change: 1 addition & 0 deletions server/internal/services/torrential/droplet-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
18 changes: 11 additions & 7 deletions server/internal/services/torrential/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class TorrentialService extends Service<unknown> {
);
return spawn(
"cargo",
["run", "--manifest-path", "./torrential/Cargo.toml"],
["run", "--manifest-path", "./torrential/Cargo.toml", "--release"],
{},
);
} else {
Expand All @@ -74,14 +74,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;
Expand Down Expand Up @@ -129,6 +130,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,
Expand All @@ -146,6 +149,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);
Expand Down
Loading