Skip to content

Commit c860040

Browse files
authored
Merge pull request #110 from matrix-org/hs/add-certfp-code
Support whois for certfp
2 parents 30840ff + c0701d8 commit c860040

File tree

5 files changed

+27
-10
lines changed

5 files changed

+27
-10
lines changed

changelog.d/110.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Include any certfp lines in a whois response.

src/codes.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ export const replyCodes = {
157157
name: 'rpl_globalusers',
158158
type: 'reply'
159159
},
160+
276: {
161+
name: 'rpl_whoiscertfp',
162+
type: 'reply',
163+
},
160164
300: {
161165
name: 'rpl_none',
162166
type: 'reply'

src/irc.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,8 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter<C
10521052
return this._addWhoisData(message.args[1], 'serverinfo', message.args[3]);
10531053
case 'rpl_whoisactually':
10541054
return this._addWhoisData(message.args[1], 'realHost', message.args[2]);
1055+
case 'rpl_whoiscertfp':
1056+
return this._addWhoisData(message.args[1], 'certfp', message.args[2]);
10551057
case 'rpl_whoisoperator':
10561058
return this._addWhoisData(message.args[1], 'operator', message.args[2]);
10571059
case 'rpl_whoisaccount':
@@ -1452,6 +1454,7 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter<C
14521454
* unmaps the client instance from the socket. The state will also need to be cleared up seperately.
14531455
*/
14541456
public destroy() {
1457+
util.log('Destroying connection');
14551458
(
14561459
['data', 'end', 'close', 'timeout', 'error'] as (keyof IrcConnectionEventsMap)[]
14571460
).forEach(evtType => {
@@ -1690,14 +1693,18 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter<C
16901693
return this.send('LIST', ...args);
16911694
}
16921695

1693-
private _addWhoisData(nick: string, key: keyof(WhoisResponse), value: string|string[], onlyIfExists = false) {
1694-
if (onlyIfExists && !this.state.whoisData.has(nick)) {return;}
1695-
const data: WhoisResponse = {
1696-
...this.state.whoisData.get(nick),
1697-
nick,
1698-
[key]: value,
1699-
};
1700-
this.state.whoisData.set(nick, data);
1696+
private _addWhoisData<
1697+
K extends keyof(WhoisResponse),
1698+
V extends WhoisResponse[K]>(nick: string, key: K, value: V, onlyIfExists = false) {
1699+
let data: WhoisResponse|undefined = this.state.whoisData.get(nick);
1700+
if (onlyIfExists && !data) {
1701+
return;
1702+
}
1703+
else if (!data) {
1704+
data = { nick };
1705+
this.state.whoisData.set(nick, data);
1706+
}
1707+
data[key] = value;
17011708
}
17021709

17031710
private _clearWhoisData(nick: string) {

src/state.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface WhoisResponse {
1414
account?: string;
1515
accountinfo?: string;
1616
realHost?: string;
17+
certfp?: string;
1718
}
1819

1920
export interface IrcSupported {

src/testing/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { randomUUID } from 'crypto';
2-
import { Client, ClientEvents, Message } from '..';
2+
import { Client, ClientEvents, IrcClientOpts, Message } from '..';
33

44
const DEFAULT_PORT = parseInt(process.env.IRC_TEST_PORT ?? '6667', 10);
55
const DEFAULT_ADDRESS = process.env.IRC_TEST_ADDRESS ?? "127.0.0.1";
@@ -75,7 +75,10 @@ export class TestIrcServer {
7575
}
7676

7777
public readonly clients: Record<string, TestClient> = {};
78-
constructor(public readonly address = DEFAULT_ADDRESS, public readonly port = DEFAULT_PORT) { }
78+
constructor(
79+
public readonly address = DEFAULT_ADDRESS, public readonly port = DEFAULT_PORT,
80+
public readonly customConfig: Partial<IrcClientOpts> = {}
81+
) { }
7982

8083
async setUp(clients = ['speaker', 'listener']) {
8184
const connections: Promise<void>[] = [];
@@ -86,6 +89,7 @@ export class TestIrcServer {
8689
autoConnect: false,
8790
connectionTimeout: 4000,
8891
debug: true,
92+
...this.customConfig,
8993
});
9094
this.clients[clientName] = client;
9195
// Make sure we load isupport before reporting readyness.

0 commit comments

Comments
 (0)