Skip to content

Commit

Permalink
Various temps to coax it into working
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Apr 12, 2022
1 parent 522df36 commit ac761ba
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 11 deletions.
3 changes: 2 additions & 1 deletion registration.sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ url: "http://localhost:9993" # This should match the bridge.port in your config
rate_limited: false

# If enabling encryption
de.sorunome.msc2409.push_ephemeral: true,
de.sorunome.msc2409.push_ephemeral: true
org.matrix.msc3202: true
5 changes: 5 additions & 0 deletions src/Bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ export class Bridge {
return this.onRoomJoin(roomId, event);
});

this.as.on("room.failed_decryption", (roomId, event, err) => {
log.warn(`Failed to decrypt event ${event.event_id} from ${roomId}: ${err.message}`);
Metrics.matrixAppserviceDecryptionFailed.inc();
});

this.queue.subscribe("response.matrix.message");
this.queue.subscribe("notifications.user.events");
this.queue.subscribe("github.*");
Expand Down
4 changes: 4 additions & 0 deletions src/Config/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,10 @@ export class BridgeConfig {
if (this.encryption && !this.queue.monolithic) {
throw new ConfigError("queue.monolithic", "Encryption is not supported in worker mode yet.");
}

if (this.encryption && !this.queue.port) {
throw new ConfigError("queue.port", "You must enable redis support for encryption to work.");
}
}

public async prefillMembershipCache(client: MatrixClient) {
Expand Down
1 change: 1 addition & 0 deletions src/Metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class Metrics {
private readonly matrixApiCallsFailed = new Counter({ name: "matrix_api_calls_failed", help: "The number of Matrix client API calls which failed", labelNames: ["method"], registers: [this.registry]});

public readonly matrixAppserviceEvents = new Counter({ name: "matrix_appservice_events", help: "The number of events sent over the AS API", labelNames: [], registers: [this.registry]});
public readonly matrixAppserviceDecryptionFailed = new Counter({ name: "matrix_appservice_decryption_failed", help: "The number of events sent over the AS API that failed to decrypt", registers: [this.registry]});

constructor(private registry: Registry = register) {
this.expressRouter.get('/metrics', this.metricsFunc.bind(this));
Expand Down
31 changes: 21 additions & 10 deletions src/Stores/RedisStorageProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Redis, default as redis } from "ioredis";
import LogWrapper from "../LogWrapper";

import { IBridgeStorageProvider } from "./StorageProvider";
import { IFilterInfo } from "matrix-bot-sdk";
import { IFilterInfo, IStorageProvider } from "matrix-bot-sdk";
import { ProvisionSession } from "matrix-appservice-bridge";

const BOT_SYNC_TOKEN_KEY = "bot.sync_token.";
Expand All @@ -25,15 +25,8 @@ const WIDGET_USER_TOKENS = "widgets.user-tokens.";

const log = new LogWrapper("RedisASProvider");

export class RedisStorageProvider implements IBridgeStorageProvider {
private redis: Redis;

constructor(host: string, port: number, private contextSuffix = '') {
this.redis = new redis(port, host);
this.redis.expire(COMPLETED_TRANSACTIONS_KEY, COMPLETED_TRANSACTIONS_EXPIRE_AFTER).catch((ex) => {
log.warn("Failed to set expiry time on as.completed_transactions", ex);
});
}
export class RedisStorageContextualProvider implements IStorageProvider {
constructor(protected readonly redis: Redis, protected readonly contextSuffix = "") { }

public setSyncToken(token: string|null){
if (token === null) {
Expand Down Expand Up @@ -64,6 +57,16 @@ export class RedisStorageProvider implements IBridgeStorageProvider {
return this.redis.get(`${BOT_VALUE_KEY}${this.contextSuffix}.${key}`);
}

}

export class RedisStorageProvider extends RedisStorageContextualProvider implements IBridgeStorageProvider {
constructor(host: string, port: number, contextSuffix = '') {
super(new redis(port, host), contextSuffix);
this.redis.expire(COMPLETED_TRANSACTIONS_KEY, COMPLETED_TRANSACTIONS_EXPIRE_AFTER).catch((ex) => {
log.warn("Failed to set expiry time on as.completed_transactions", ex);
});
}

public async addRegisteredUser(userId: string) {
this.redis.sadd(REGISTERED_USERS_KEY, [userId]);
}
Expand Down Expand Up @@ -155,4 +158,12 @@ export class RedisStorageProvider implements IBridgeStorageProvider {
token = await this.redis.spop(`${WIDGET_USER_TOKENS}${userId}`);
}
}

storageForUser(userId: string) {
const newContext = [userId];
if (this.contextSuffix) {
newContext.push(this.contextSuffix);
}
return new RedisStorageContextualProvider(this.redis, newContext.join("."));
}
}

0 comments on commit ac761ba

Please sign in to comment.