feat(federation): Add more debugging to inbox processing

This commit is contained in:
Jesse Wierzbinski 2024-11-24 22:17:45 +01:00
parent be69407c01
commit c59ebef851
No known key found for this signature in database
2 changed files with 18 additions and 3 deletions

View file

@ -716,7 +716,7 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
} }
public static async resolve(uri: string): Promise<User | null> { public static async resolve(uri: string): Promise<User | null> {
getLogger("federation").debug`Resolving user ${chalk.bold(uri)}`; getLogger("federation").debug`Resolving user ${chalk.gray(uri)}`;
// Check if user not already in database // Check if user not already in database
const foundUser = await User.fromSql(eq(Users.uri, uri)); const foundUser = await User.fromSql(eq(Users.uri, uri));

View file

@ -25,6 +25,7 @@ import {
} from "@versia/kit/db"; } from "@versia/kit/db";
import { Likes, Notes } from "@versia/kit/tables"; import { Likes, Notes } from "@versia/kit/tables";
import type { SocketAddress } from "bun"; import type { SocketAddress } from "bun";
import chalk from "chalk";
import { eq } from "drizzle-orm"; import { eq } from "drizzle-orm";
import type { StatusCode } from "hono/utils/http-status"; import type { StatusCode } from "hono/utils/http-status";
import { matches } from "ip-matching"; import { matches } from "ip-matching";
@ -104,8 +105,9 @@ export class InboxProcessor {
} }
if (config.debug.federation) { if (config.debug.federation) {
this.logger this.logger.debug`Sender public key: ${chalk.gray(
.debug`Sender public key: ${this.senderInstance.data.publicKey.key}`; this.senderInstance.data.publicKey.key,
)}`;
} }
const validator = await SignatureValidator.fromStringKey( const validator = await SignatureValidator.fromStringKey(
@ -199,6 +201,9 @@ export class InboxProcessor {
* @returns {Promise<Response>} - HTTP response to send back. * @returns {Promise<Response>} - HTTP response to send back.
*/ */
public async process(): Promise<Response> { public async process(): Promise<Response> {
!this.senderInstance &&
this.logger.debug`Processing request from potential bridge`;
if ( if (
this.senderInstance && this.senderInstance &&
isDefederated(this.senderInstance.data.baseUrl) 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(); const shouldCheckSignature = this.shouldCheckSignature();
if (shouldCheckSignature !== true && shouldCheckSignature !== false) { 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) { if (shouldCheckSignature) {
const isValid = await this.isSignatureValid(); const isValid = await this.isSignatureValid();
@ -231,6 +244,8 @@ export class InboxProcessor {
} }
} }
shouldCheckSignature && this.logger.debug`Signature is valid`;
const validator = new EntityValidator(); const validator = new EntityValidator();
const handler = new RequestParserHandler(this.body, validator); const handler = new RequestParserHandler(this.body, validator);