From c59ebef8517d603c85125e0c1d9baa2a7eaf5c81 Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Sun, 24 Nov 2024 22:17:45 +0100 Subject: [PATCH] feat(federation): :sparkles: Add more debugging to inbox processing --- classes/database/user.ts | 2 +- classes/inbox/processor.ts | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/classes/database/user.ts b/classes/database/user.ts index 74ddbfb5..ce4f64a3 100644 --- a/classes/database/user.ts +++ b/classes/database/user.ts @@ -716,7 +716,7 @@ export class User extends BaseInterface { } public static async resolve(uri: string): Promise { - getLogger("federation").debug`Resolving user ${chalk.bold(uri)}`; + getLogger("federation").debug`Resolving user ${chalk.gray(uri)}`; // Check if user not already in database const foundUser = await User.fromSql(eq(Users.uri, uri)); diff --git a/classes/inbox/processor.ts b/classes/inbox/processor.ts index f70b5860..97f1786d 100644 --- a/classes/inbox/processor.ts +++ b/classes/inbox/processor.ts @@ -25,6 +25,7 @@ import { } from "@versia/kit/db"; import { Likes, Notes } from "@versia/kit/tables"; import type { SocketAddress } from "bun"; +import chalk from "chalk"; import { eq } from "drizzle-orm"; import type { StatusCode } from "hono/utils/http-status"; import { matches } from "ip-matching"; @@ -104,8 +105,9 @@ export class InboxProcessor { } if (config.debug.federation) { - this.logger - .debug`Sender public key: ${this.senderInstance.data.publicKey.key}`; + this.logger.debug`Sender public key: ${chalk.gray( + this.senderInstance.data.publicKey.key, + )}`; } const validator = await SignatureValidator.fromStringKey( @@ -199,6 +201,9 @@ export class InboxProcessor { * @returns {Promise} - HTTP response to send back. */ public async process(): Promise { + !this.senderInstance && + this.logger.debug`Processing request from potential bridge`; + if ( this.senderInstance && isDefederated(this.senderInstance.data.baseUrl) @@ -211,6 +216,10 @@ export class InboxProcessor { }); } + this.logger.debug`Instance ${chalk.gray( + this.senderInstance?.data.baseUrl, + )} is not defederated`; + const shouldCheckSignature = this.shouldCheckSignature(); if (shouldCheckSignature !== true && shouldCheckSignature !== false) { @@ -220,6 +229,10 @@ export class InboxProcessor { ); } + shouldCheckSignature + ? this.logger.debug`Checking signature` + : this.logger.debug`Skipping signature check`; + if (shouldCheckSignature) { const isValid = await this.isSignatureValid(); @@ -231,6 +244,8 @@ export class InboxProcessor { } } + shouldCheckSignature && this.logger.debug`Signature is valid`; + const validator = new EntityValidator(); const handler = new RequestParserHandler(this.body, validator);