diff --git a/src/client/webapp/auto-verifier-with-args.ts b/src/client/webapp/auto-verifier-with-args.ts index c222a5d..49f1bcc 100644 --- a/src/client/webapp/auto-verifier-with-args.ts +++ b/src/client/webapp/auto-verifier-with-args.ts @@ -27,6 +27,7 @@ export class AutoVerifierWithArg { private primaryFunc: (query: K) => Promise, private trustedFunc: (query: K) => Promise, private verifyFunc: (query: K, primaryResult: T | null, trustedResult: T | null) => Promise, + private name: string | null = null, // for debugging purposes ) {} static createStandardPartialMessageListAutoVerifier & { id: string }>( @@ -37,6 +38,7 @@ export class AutoVerifierWithArg { changesType: AutoVerifierChangesType, changes: Changes, ) => Promise, + name: string | null = null, ) { return new AutoVerifierWithArg( query => `ch#${query.channelId} mo#${query.messageOrderId}->${query.number}`, @@ -57,6 +59,7 @@ export class AutoVerifierWithArg { const changesType = AutoVerifier.getListChangesType(primaryResult, trustedResult, changes); return await changesFunc(query, changesType, changes); }, + name, ); } @@ -69,6 +72,7 @@ export class AutoVerifierWithArg { primaryResult: T | null, trustedResult: T | null, ) => Promise, + name: string | null = null, ) { return new AutoVerifierWithArg( query => `id#${query.id}`, @@ -78,6 +82,7 @@ export class AutoVerifierWithArg { const changesType = AutoVerifier.getSingleChangesType(primaryResult, trustedResult); return await changesFunc(query, changesType, primaryResult, trustedResult); }, + name, ); } @@ -117,6 +122,7 @@ export class AutoVerifierWithArg { async () => await this.trustedFunc(query), async (primaryResult: T | null, trustedResult: T | null) => await this.verifyFunc(query, primaryResult, trustedResult), + `${this.name}::${token.slice(0, 8)}` ); this.tokenAutoVerifiers.set(token, autoVerifier); } diff --git a/src/client/webapp/auto-verifier.ts b/src/client/webapp/auto-verifier.ts index 391c006..e89b71d 100644 --- a/src/client/webapp/auto-verifier.ts +++ b/src/client/webapp/auto-verifier.ts @@ -254,7 +254,7 @@ export class AutoVerifier { // we've been invalidated while we were waiting for the trusted result! // TODO: This happens when a socket fetch is sent before the socket is connected to. console.warn( - 'RARE ALERT: we got unverified while trying to fetch a trusted promise for verification!', + `RARE ALERT: ${this.name || 'we'} got unverified while trying to fetch a trusted promise for verification!`, new Error(), ); if (this.trustedPromise === null) { @@ -281,8 +281,6 @@ export class AutoVerifier { this.trustedPromise = null; } } else { - // this actually could be quite common - //console.warn('RARE ALERT: we got unverified during verification!'); // ** complexity: // if primaryUpToDate is false or we got unverified during verification, this path will still return // the trustedResult that was passed to the verify function @@ -320,7 +318,7 @@ export class AutoVerifier { if (this.trustedPromise !== origTrustedPromise) { // we've been invalidated while we were waiting for the trusted result! console.warn( - 'ULTRA RARE ALERT: we got unverified while awaiting a trusted promise another path was verifying!', + `ULTRA RARE ALERT: ${this.name || 'we'} got unverified while awaiting a trusted promise another path was verifying!`, ); await tryResolveTrustedPromise(); return; @@ -330,7 +328,7 @@ export class AutoVerifier { if (this.trustedPromise !== origTrustedPromise) { // we've been invalidated while we were waiting for the verify! console.warn( - 'ULTRA RARE ALERT: we got unverified while awaiting a verify promise another path was calling!', + `ULTRA RARE ALERT: ${this.name || 'we'} got unverified while awaiting a verify promise another path was calling!`, ); // ** complexity: // if primaryUpToDate is false or we got unverified during verification, this path will still return diff --git a/src/client/webapp/fetchable-pair-verifier.ts b/src/client/webapp/fetchable-pair-verifier.ts index 19b670b..650575b 100644 --- a/src/client/webapp/fetchable-pair-verifier.ts +++ b/src/client/webapp/fetchable-pair-verifier.ts @@ -4,13 +4,13 @@ import Logger from '../../logger/logger'; const LOG = Logger.create(__filename, electronConsole); import { Changes, Channel, GuildMetadata, Member, Message, Resource, Token } from './data-types'; -import { AsyncFetchable, Fetchable, Lackable, Conflictable, Ensurable } from './guild-types'; +import { AsyncFetchable, Fetchable, Lackable, Conflictable } from './guild-types'; import { AutoVerifier, AutoVerifierChangesType } from './auto-verifier'; import { AutoVerifierWithArg, PartialMessageListQuery, IDQuery } from './auto-verifier-with-args'; import { EventEmitter } from 'tsee'; /** uses a primary fetchable and trusted fetchable and verifys the results. Can be chained together with itself as a trusted fetchable! */ -export default class PairVerifierFetchable extends EventEmitter implements AsyncFetchable, Ensurable { +export default class PairVerifierFetchable extends EventEmitter implements AsyncFetchable { private readonly fetchMetadataVerifier: AutoVerifier; private readonly fetchMembersVerifier: AutoVerifier; private readonly fetchChannelsVerifier: AutoVerifier; @@ -22,7 +22,7 @@ export default class PairVerifierFetchable extends EventEmitter im public readonly fetchMessagesBeforeVerifier: AutoVerifierWithArg; public readonly fetchMessagesAfterVerifier: AutoVerifierWithArg; - constructor(private primary: Fetchable & Lackable, private trusted: Fetchable & Ensurable, private name: string | null = null) { + constructor(private primary: Fetchable & Lackable, private trusted: Fetchable, private name: string | null = null) { super(); if (trusted instanceof PairVerifierFetchable) { @@ -39,18 +39,21 @@ export default class PairVerifierFetchable extends EventEmitter im async () => await this.primary.fetchMetadata(), async () => await this.trusted.fetchMetadata(), this.handleMetadataConflict.bind(this), + `${this.name}#fetchMetadata`, ); this.fetchMembersVerifier = AutoVerifier.createStandardListAutoVerifier( async () => await this.primary.fetchMembers(), async () => await this.trusted.fetchMembers(), this.handleMembersConflict.bind(this), + `${this.name}#fetchMembers`, ); this.fetchChannelsVerifier = AutoVerifier.createStandardListAutoVerifier( async () => await this.primary.fetchChannels(), async () => await this.trusted.fetchChannels(), this.handleChannelsConflict.bind(this), + `${this.name}#fetchChannels`, ); this.fetchTokensVerifier = AutoVerifier.createStandardListAutoVerifier( @@ -59,12 +62,14 @@ export default class PairVerifierFetchable extends EventEmitter im async () => await this.primary.fetchTokens(), async () => await this.trusted.fetchTokens(), this.handleTokensConflict.bind(this), + `${this.name}#fetchTokens`, ); this.fetchResourceVerifier = AutoVerifierWithArg.createStandardIDQueriedSingleAutoVerifier( async (query: IDQuery) => await this.primary.fetchResource(query.id), async (query: IDQuery) => await this.trusted.fetchResource(query.id), this.handleResourceConflict.bind(this), + `${this.name}#fetchResource`, ); this.fetchMessagesRecentVerifier = AutoVerifierWithArg.createStandardPartialMessageListAutoVerifier( @@ -73,6 +78,7 @@ export default class PairVerifierFetchable extends EventEmitter im async (query: PartialMessageListQuery) => await this.trusted.fetchMessagesRecent(query.channelId, query.number), this.handleMessagesConflict.bind(this), + `${this.name}#fetchMessagesRecent`, ); this.fetchMessagesBeforeVerifier = AutoVerifierWithArg.createStandardPartialMessageListAutoVerifier( @@ -81,6 +87,7 @@ export default class PairVerifierFetchable extends EventEmitter im async (query: PartialMessageListQuery) => await this.trusted.fetchMessagesBefore(query.channelId, query.messageOrderId as string, query.number), this.handleMessagesConflict.bind(this), + `${this.name}#fetchMessagesBefore`, ); this.fetchMessagesAfterVerifier = AutoVerifierWithArg.createStandardPartialMessageListAutoVerifier( @@ -89,13 +96,10 @@ export default class PairVerifierFetchable extends EventEmitter im async (query: PartialMessageListQuery) => await this.trusted.fetchMessagesAfter(query.channelId, query.messageOrderId as string, query.number), this.handleMessagesConflict.bind(this), + `${this.name}#fetchMessagesAfter`, ); } - async ensureVerified(): Promise { - /* do nothing */ - } - async handleMetadataConflict( changesType: AutoVerifierChangesType, primaryMetadata: GuildMetadata | null, diff --git a/src/client/webapp/guild-combined.ts b/src/client/webapp/guild-combined.ts index 7a9a786..a4d31b8 100644 --- a/src/client/webapp/guild-combined.ts +++ b/src/client/webapp/guild-combined.ts @@ -59,8 +59,8 @@ export default class CombinedGuild this.personalDBGuild = new PersonalDBGuild(personalDB, this.id, this.memberId); this.socketGuild = new SocketGuild(socket, socketVerifier); - const diskSocket = new PairVerifierFetchable(this.personalDBGuild, this.socketGuild, 'Disk -> Socket'); - const ramDiskSocket = new PairVerifierFetchable(this.ramGuild, diskSocket, 'RAM -> Disk'); + const diskSocket = new PairVerifierFetchable(this.personalDBGuild, this.socketGuild, 'disk-socket'); + const ramDiskSocket = new PairVerifierFetchable(this.ramGuild, diskSocket, 'ram-disk'); // TODO: I think this unverify is causing the RARE ALERTs // do we need to unverify on connect? or just disconnect? diff --git a/src/client/webapp/guild-personal-db.ts b/src/client/webapp/guild-personal-db.ts index ab24580..0b1fb0b 100644 --- a/src/client/webapp/guild-personal-db.ts +++ b/src/client/webapp/guild-personal-db.ts @@ -1,4 +1,4 @@ -import { AsyncFetchable, AsyncLackable, Ensurable } from './guild-types'; +import { AsyncFetchable, AsyncLackable } from './guild-types'; import { Channel, GuildMetadata, @@ -14,7 +14,7 @@ import PersonalDB from './personal-db'; import { AutoVerifierWithArg, PartialMessageListQuery } from './auto-verifier-with-args'; /** a guild connected to a local Sqlite database */ -export default class PersonalDBGuild implements AsyncFetchable, AsyncLackable, Ensurable { +export default class PersonalDBGuild implements AsyncFetchable, AsyncLackable { constructor( private readonly db: PersonalDB, private readonly guildId: number, @@ -59,10 +59,6 @@ export default class PersonalDBGuild implements AsyncFetchable, AsyncLackable, E return null; // personal db currently does not handle tokens } - async ensureVerified(): Promise { - /* do nothing, we are always ready */ - } - // lacking Methods (resolving differences) async handleMetadataChanged(changedMetaData: GuildMetadata): Promise { diff --git a/src/client/webapp/guild-socket.ts b/src/client/webapp/guild-socket.ts index 019957f..3b01fc6 100644 --- a/src/client/webapp/guild-socket.ts +++ b/src/client/webapp/guild-socket.ts @@ -7,7 +7,7 @@ const LOG = Logger.create(__filename, electronConsole); import * as socketio from 'socket.io-client'; import { Channel, GuildMetadata, Member, Message, Resource, Token } from './data-types'; import Globals from './globals'; -import { Connectable, AsyncRequestable, AsyncGuaranteedFetchable, Ensurable } from './guild-types'; +import { Connectable, AsyncRequestable, AsyncGuaranteedFetchable } from './guild-types'; import DedupAwaiter from './dedup-awaiter'; import Util from './util'; import SocketVerifier from './socket-verifier'; @@ -17,7 +17,7 @@ import { EventEmitter } from 'tsee'; /** a guild connected to a socket.io socket server */ export default class SocketGuild extends EventEmitter - implements AsyncGuaranteedFetchable, AsyncRequestable, Ensurable + implements AsyncGuaranteedFetchable, AsyncRequestable { private queryDedups = new Map>(); @@ -89,10 +89,6 @@ export default class SocketGuild this.socket.disconnect(); } - public async ensureVerified(): Promise { - await this.verifier.ensureVerified(); - } - // server helper functions private async _query(timeout: number, endpoint: string, ...args: any[]): Promise { diff --git a/src/client/webapp/guild-types.ts b/src/client/webapp/guild-types.ts index d1db2a7..3a3ca4d 100644 --- a/src/client/webapp/guild-types.ts +++ b/src/client/webapp/guild-types.ts @@ -26,10 +26,6 @@ export interface AsyncFetchable { } export type Fetchable = SyncFetchable | AsyncFetchable; -export interface Ensurable { - ensureVerified: () => Promise; -} - export interface AsyncGuaranteedFetchable { fetchMetadata(): Promise; fetchMembers(): Promise;