Skip to content

Commit 8faf961

Browse files
committed
Merge branch 'develop'
2 parents a583f59 + 3fc309c commit 8faf961

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

changelog.d/1559.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Include the bridge version and homeserver in the `CTCP VERSION` response body.

src/irc/BridgedClient.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@ export class BridgedClient extends EventEmitter {
250250
this.server.getIpv6Prefix() ? this.clientConfig.getIpv6Address() : undefined
251251
),
252252
encodingFallback: this.encodingFallback,
253-
}, (inst: ConnectionInstance) => {
253+
},
254+
this.server.homeserverDomain,
255+
(inst: ConnectionInstance) => {
254256
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
255257
this.onConnectionCreated(inst, nameInfo, identResolver!);
256258
});

src/irc/ConnectionInstance.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import * as logging from "../logging";
2121
import Bluebird from "bluebird";
2222
import { Defer } from "../promiseutil";
2323
import { IrcServer } from "./IrcServer";
24+
import { getBridgeVersion } from "matrix-appservice-bridge";
2425

2526
const log = logging.get("client-connection");
2627

@@ -42,7 +43,8 @@ const FLOOD_PROTECTION_DELAY_MS = 700;
4243
const THROTTLE_WAIT_MS = 20 * 1000;
4344

4445
// String reply of any CTCP Version requests
45-
const CTCP_VERSION = 'matrix-appservice-irc, part of the Matrix.org Network';
46+
const CTCP_VERSION =
47+
(homeserverName: string) => `matrix-appservice-irc ${getBridgeVersion()} bridged via ${homeserverName}`;
4648

4749
const CONN_LIMIT_MESSAGES = [
4850
"too many host connections", // ircd-seven
@@ -83,18 +85,20 @@ export class ConnectionInstance {
8385
private connectDefer: Defer<ConnectionInstance>;
8486
public onDisconnect?: (reason: string) => void;
8587
/**
86-
* Create an IRC connection instance. Wraps the node-irc library to handle
88+
* Create an IRC connection instance. Wraps the matrix-org-irc library to handle
8789
* connections correctly.
8890
* @constructor
89-
* @param {IrcClient} ircClient The new IRC client.
90-
* @param {string} domain The domain (for logging purposes)
91-
* @param {string} nick The nick (for logging purposes)
91+
* @param client The new IRC client.
92+
* @param domain The domain (for logging purposes)
93+
* @param nick The nick (for logging purposes)
94+
* @param pingOpts Options for automatic pings to the IRCd.
95+
* @param homeserverDomain The homeserver's domain, for the CTCP version string.
9296
*/
9397
constructor (public readonly client: Client, private readonly domain: string, private nick: string,
9498
private pingOpts: {
9599
pingRateMs: number;
96100
pingTimeoutMs: number;
97-
}) {
101+
}, private readonly homeserverDomain: string) {
98102
this.listenForErrors();
99103
this.listenForPings();
100104
this.listenForCTCPVersions();
@@ -329,7 +333,7 @@ export class ConnectionInstance {
329333
private listenForCTCPVersions() {
330334
this.client.addListener("ctcp-version", (from: string) => {
331335
if (from) { // Ensure the sender is valid before we try to respond
332-
this.client.ctcp(from, 'reply', `VERSION ${CTCP_VERSION}`);
336+
this.client.ctcp(from, 'reply', `VERSION ${CTCP_VERSION(this.homeserverDomain)}`);
333337
}
334338
});
335339
}
@@ -359,10 +363,13 @@ export class ConnectionInstance {
359363
* @param {string} opts.realname The real name of the user.
360364
* @param {string} opts.password The password to give NickServ.
361365
* @param {string} opts.localAddress The local address to bind to when connecting.
366+
* @param {string} homeserverDomain Domain of the homeserver bridging requests.
362367
* @param {Function} onCreatedCallback Called with the client when created.
363368
* @return {Promise} Resolves to an ConnectionInstance or rejects.
364369
*/
365-
public static async create (server: IrcServer, opts: ConnectionOpts,
370+
public static async create (server: IrcServer,
371+
opts: ConnectionOpts,
372+
homeserverDomain: string,
366373
onCreatedCallback?: (inst: ConnectionInstance) => void): Promise<ConnectionInstance> {
367374
if (!opts.nick || !server) {
368375
throw new Error("Bad inputs. Nick: " + opts.nick);
@@ -396,7 +403,8 @@ export class ConnectionInstance {
396403
nodeClient, server.domain, opts.nick, {
397404
pingRateMs: server.pingRateMs,
398405
pingTimeoutMs: server.pingTimeout,
399-
}
406+
},
407+
homeserverDomain,
400408
);
401409
if (onCreatedCallback) {
402410
onCreatedCallback(inst);

src/irc/IrcServer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export class IrcServer {
174174
* will never expire.
175175
*/
176176
constructor(public domain: string, public config: IrcServerConfig,
177-
private homeserverDomain: string, private expiryTimeSeconds: number = 0) {
177+
public readonly homeserverDomain: string, private expiryTimeSeconds: number = 0) {
178178
this.reconfigure(config, expiryTimeSeconds);
179179
}
180180

0 commit comments

Comments
 (0)