@matterbridge/dgram 3.10.12-dev-20260927-5bb5023 → 3.10.12-dev-20260929-3d70112
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/coap.d.ts +2 -1
- package/dist/dgram.d.ts +3 -3
- package/dist/dgram.js +7 -7
- package/dist/mdns.d.ts +64 -5
- package/dist/mdns.js +104 -35
- package/dist/multicast.d.ts +2 -1
- package/dist/unicast.d.ts +2 -2
- package/package.json +2 -2
package/dist/coap.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type dgram from 'node:dgram';
|
|
2
|
+
import type { SocketType } from 'node:dgram';
|
|
2
3
|
import { Multicast } from './multicast.js';
|
|
3
4
|
export interface CoapMessage {
|
|
4
5
|
version: number;
|
|
@@ -21,7 +22,7 @@ export declare const COIOT_OPTION_SERIAL = 3420;
|
|
|
21
22
|
export declare const COIOT_REQUEST_STATUS_ID = 56831;
|
|
22
23
|
export declare const COIOT_REQUEST_DESCRIPTION_ID = 56832;
|
|
23
24
|
export declare class Coap extends Multicast {
|
|
24
|
-
constructor(name: string, multicastAddress: string, multicastPort: number, socketType:
|
|
25
|
+
constructor(name: string, multicastAddress: string, multicastPort: number, socketType: SocketType, reuseAddr?: boolean | undefined, interfaceName?: string, interfaceAddress?: string);
|
|
25
26
|
onCoapMessage(message: CoapMessage, rinfo: dgram.RemoteInfo): void;
|
|
26
27
|
onMessage(msg: Buffer, rinfo: dgram.RemoteInfo): void;
|
|
27
28
|
decodeCoapMessage(msg: Buffer): CoapMessage;
|
package/dist/dgram.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import dgram from 'node:dgram';
|
|
1
|
+
import dgram, { type SocketType } from 'node:dgram';
|
|
2
2
|
import EventEmitter from 'node:events';
|
|
3
3
|
import type { AddressInfo } from 'node:net';
|
|
4
4
|
import { AnsiLogger } from 'node-ansi-logger';
|
|
@@ -19,12 +19,12 @@ export declare class Dgram extends EventEmitter<DgramEvents> {
|
|
|
19
19
|
log: AnsiLogger;
|
|
20
20
|
socket: dgram.Socket;
|
|
21
21
|
bound: boolean;
|
|
22
|
-
socketType:
|
|
22
|
+
socketType: SocketType;
|
|
23
23
|
interfaceName?: string;
|
|
24
24
|
interfaceAddress?: string;
|
|
25
25
|
interfaceNetmask?: string;
|
|
26
26
|
excludedInterfaceNamePattern: RegExp;
|
|
27
|
-
constructor(name: string, socketType:
|
|
27
|
+
constructor(name: string, socketType: SocketType, reuseAddr?: boolean | undefined, interfaceName?: string, interfaceAddress?: string);
|
|
28
28
|
send(msg: Buffer, serverAddress: string, serverPort: number): void;
|
|
29
29
|
onError(error: Error): void;
|
|
30
30
|
onClose(): void;
|
package/dist/dgram.js
CHANGED
|
@@ -40,7 +40,7 @@ export class Dgram extends EventEmitter {
|
|
|
40
40
|
this.onClose();
|
|
41
41
|
});
|
|
42
42
|
this.socket.on('connect', () => {
|
|
43
|
-
this.log.
|
|
43
|
+
this.log.debug('Socket connected');
|
|
44
44
|
this.emit('connect');
|
|
45
45
|
this.onConnect();
|
|
46
46
|
});
|
|
@@ -75,23 +75,23 @@ export class Dgram extends EventEmitter {
|
|
|
75
75
|
this.log.error(`Socket error: ${getErrorMessage(error)}`);
|
|
76
76
|
}
|
|
77
77
|
onClose() {
|
|
78
|
-
this.log.
|
|
78
|
+
this.log.debug(`Socket closed`);
|
|
79
79
|
}
|
|
80
80
|
onConnect() {
|
|
81
|
-
this.log.
|
|
81
|
+
this.log.debug(`Socket connected`);
|
|
82
82
|
}
|
|
83
83
|
onSent(msg, serverAddress, serverPort) {
|
|
84
|
-
this.log.
|
|
84
|
+
this.log.debug(`Socket sent a message to ${BLUE}${serverAddress}${db}:${BLUE}${serverPort}${db}`);
|
|
85
85
|
}
|
|
86
86
|
onMessage(msg, rinfo) {
|
|
87
|
-
this.log.
|
|
87
|
+
this.log.debug(`Socket received a message from ${BLUE}${rinfo.family}${nf} ${BLUE}${rinfo.address}${nf}:${BLUE}${rinfo.port}${nf}`);
|
|
88
88
|
}
|
|
89
89
|
onListening(address) {
|
|
90
|
-
this.log.
|
|
90
|
+
this.log.debug(`Socket listening on ${BLUE}${address.family}${nf} ${BLUE}${address.address}${nf}:${BLUE}${address.port}${nf}`);
|
|
91
91
|
this.onReady(address);
|
|
92
92
|
}
|
|
93
93
|
onReady(address) {
|
|
94
|
-
this.log.
|
|
94
|
+
this.log.debug(`Socket ready on ${BLUE}${address.family}${nf} ${BLUE}${address.address}${nf}:${BLUE}${address.port}${nf}`);
|
|
95
95
|
this.emit('ready', address);
|
|
96
96
|
}
|
|
97
97
|
getIpv4InterfaceAddress(networkInterface) {
|
package/dist/mdns.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import dgram, { type SocketType } from 'node:dgram';
|
|
2
2
|
import { type AnsiLogger } from 'node-ansi-logger';
|
|
3
3
|
import { Multicast } from './multicast.js';
|
|
4
|
+
export declare const MDNS_MAX_MESSAGE_LENGTH: number;
|
|
5
|
+
export declare const MDNS_MAX_RESOURCE_RECORD_LENGTH: number;
|
|
4
6
|
export declare enum DnsRecordType {
|
|
5
7
|
A = 1,
|
|
6
8
|
NS = 2,
|
|
@@ -103,6 +105,18 @@ export declare enum DnsClassFlag {
|
|
|
103
105
|
FLUSH = 32768,
|
|
104
106
|
QU = 32768
|
|
105
107
|
}
|
|
108
|
+
export declare enum DnsHeaderFlag {
|
|
109
|
+
QR = 32768,
|
|
110
|
+
OPCODE = 30720,
|
|
111
|
+
AA = 1024,
|
|
112
|
+
TC = 512,
|
|
113
|
+
RD = 256,
|
|
114
|
+
RA = 128,
|
|
115
|
+
Z = 64,
|
|
116
|
+
AD = 32,
|
|
117
|
+
CD = 16,
|
|
118
|
+
RCODE = 15
|
|
119
|
+
}
|
|
106
120
|
export interface MdnsMessage {
|
|
107
121
|
id: number;
|
|
108
122
|
qr: number;
|
|
@@ -124,8 +138,8 @@ export interface MdnsMessage {
|
|
|
124
138
|
}
|
|
125
139
|
interface DnsQuestion {
|
|
126
140
|
name: string;
|
|
127
|
-
type:
|
|
128
|
-
class:
|
|
141
|
+
type: DnsRecordType;
|
|
142
|
+
class: DnsClass;
|
|
129
143
|
}
|
|
130
144
|
interface MdnsRecord {
|
|
131
145
|
name: string;
|
|
@@ -137,6 +151,7 @@ interface MdnsRecord {
|
|
|
137
151
|
export declare function isMdns(message: Buffer): boolean;
|
|
138
152
|
export declare function isMdnsQuery(message: Buffer): boolean;
|
|
139
153
|
export declare function isMdnsResponse(message: Buffer): boolean;
|
|
154
|
+
export declare function isFirstOnPort(socketType: SocketType, port?: number): Promise<boolean>;
|
|
140
155
|
export declare class Mdns extends Multicast {
|
|
141
156
|
deviceQueries: Map<string, {
|
|
142
157
|
rinfo: dgram.RemoteInfo;
|
|
@@ -149,7 +164,7 @@ export declare class Mdns extends Multicast {
|
|
|
149
164
|
}>;
|
|
150
165
|
filters: string[];
|
|
151
166
|
ipFilters: string[];
|
|
152
|
-
constructor(name: string, multicastAddress: string, multicastPort: number, socketType:
|
|
167
|
+
constructor(name: string, multicastAddress: string, multicastPort: number, socketType: SocketType, reuseAddr?: boolean | undefined, interfaceName?: string, interfaceAddress?: string, outgoingInterfaceAddress?: string);
|
|
153
168
|
onQuery(rinfo: dgram.RemoteInfo, _query: MdnsMessage): void;
|
|
154
169
|
onResponse(rinfo: dgram.RemoteInfo, _response: MdnsMessage): void;
|
|
155
170
|
onMessage(msg: Buffer, rinfo: dgram.RemoteInfo): void;
|
|
@@ -158,11 +173,19 @@ export declare class Mdns extends Multicast {
|
|
|
158
173
|
name: string;
|
|
159
174
|
newOffset: number;
|
|
160
175
|
};
|
|
161
|
-
encodeDnsName(name: string): Buffer;
|
|
176
|
+
encodeDnsName(name: string, compression?: Map<string, number>, offset?: number): Buffer;
|
|
162
177
|
encodeTxtRdata(txt: string[]): Buffer;
|
|
163
178
|
encodeSrvRdata(priority: number, weight: number, port: number, target: string): Buffer;
|
|
164
179
|
encodeA(ipv4: string): Buffer;
|
|
165
180
|
encodeAAAA(ipv6WithOptionalScope: string): Buffer;
|
|
181
|
+
encodeResourceRecord({ name, rtype, rclass, flush, ttl, rdata }: {
|
|
182
|
+
name: string;
|
|
183
|
+
rtype: number;
|
|
184
|
+
rclass: number;
|
|
185
|
+
flush?: boolean;
|
|
186
|
+
ttl: number;
|
|
187
|
+
rdata: Buffer;
|
|
188
|
+
}, compression?: Map<string, number>, offset?: number): Buffer;
|
|
166
189
|
decodeResourceRecord(msg: Buffer, offset: number): {
|
|
167
190
|
record: MdnsRecord;
|
|
168
191
|
newOffset: number;
|
|
@@ -172,11 +195,47 @@ export declare class Mdns extends Multicast {
|
|
|
172
195
|
type: number;
|
|
173
196
|
class: number;
|
|
174
197
|
unicastResponse?: boolean;
|
|
198
|
+
}[], answers?: {
|
|
199
|
+
name: string;
|
|
200
|
+
rtype: number;
|
|
201
|
+
rclass: number;
|
|
202
|
+
flush?: boolean;
|
|
203
|
+
ttl: number;
|
|
204
|
+
rdata: Buffer;
|
|
205
|
+
}[], authorities?: {
|
|
206
|
+
name: string;
|
|
207
|
+
rtype: number;
|
|
208
|
+
rclass: number;
|
|
209
|
+
flush?: boolean;
|
|
210
|
+
ttl: number;
|
|
211
|
+
rdata: Buffer;
|
|
212
|
+
}[], additionals?: {
|
|
213
|
+
name: string;
|
|
214
|
+
rtype: number;
|
|
215
|
+
rclass: number;
|
|
216
|
+
flush?: boolean;
|
|
217
|
+
ttl: number;
|
|
218
|
+
rdata: Buffer;
|
|
175
219
|
}[]): Buffer<ArrayBuffer>;
|
|
176
220
|
sendResponse(answers: {
|
|
177
221
|
name: string;
|
|
178
222
|
rtype: number;
|
|
179
223
|
rclass: number;
|
|
224
|
+
flush?: boolean;
|
|
225
|
+
ttl: number;
|
|
226
|
+
rdata: Buffer;
|
|
227
|
+
}[], authorities?: {
|
|
228
|
+
name: string;
|
|
229
|
+
rtype: number;
|
|
230
|
+
rclass: number;
|
|
231
|
+
flush?: boolean;
|
|
232
|
+
ttl: number;
|
|
233
|
+
rdata: Buffer;
|
|
234
|
+
}[], additionals?: {
|
|
235
|
+
name: string;
|
|
236
|
+
rtype: number;
|
|
237
|
+
rclass: number;
|
|
238
|
+
flush?: boolean;
|
|
180
239
|
ttl: number;
|
|
181
240
|
rdata: Buffer;
|
|
182
241
|
}[]): Buffer<ArrayBuffer>;
|
package/dist/mdns.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import dgram from 'node:dgram';
|
|
1
2
|
import { hasParameter } from '@matterbridge/utils/cli';
|
|
2
3
|
import { getErrorMessage } from '@matterbridge/utils/error';
|
|
3
4
|
import { BLUE, CYAN, db, GREEN, idn, MAGENTA, nf, rs } from 'node-ansi-logger';
|
|
4
|
-
import { Multicast } from './multicast.js';
|
|
5
|
+
import { MDNS_MULTICAST_PORT, Multicast } from './multicast.js';
|
|
6
|
+
export const MDNS_MAX_MESSAGE_LENGTH = 1500 - 40 - 8;
|
|
7
|
+
export const MDNS_MAX_RESOURCE_RECORD_LENGTH = MDNS_MAX_MESSAGE_LENGTH - 12;
|
|
5
8
|
export var DnsRecordType;
|
|
6
9
|
(function (DnsRecordType) {
|
|
7
10
|
DnsRecordType[DnsRecordType["A"] = 1] = "A";
|
|
@@ -107,6 +110,19 @@ export var DnsClassFlag;
|
|
|
107
110
|
DnsClassFlag[DnsClassFlag["FLUSH"] = 32768] = "FLUSH";
|
|
108
111
|
DnsClassFlag[DnsClassFlag["QU"] = 32768] = "QU";
|
|
109
112
|
})(DnsClassFlag || (DnsClassFlag = {}));
|
|
113
|
+
export var DnsHeaderFlag;
|
|
114
|
+
(function (DnsHeaderFlag) {
|
|
115
|
+
DnsHeaderFlag[DnsHeaderFlag["QR"] = 32768] = "QR";
|
|
116
|
+
DnsHeaderFlag[DnsHeaderFlag["OPCODE"] = 30720] = "OPCODE";
|
|
117
|
+
DnsHeaderFlag[DnsHeaderFlag["AA"] = 1024] = "AA";
|
|
118
|
+
DnsHeaderFlag[DnsHeaderFlag["TC"] = 512] = "TC";
|
|
119
|
+
DnsHeaderFlag[DnsHeaderFlag["RD"] = 256] = "RD";
|
|
120
|
+
DnsHeaderFlag[DnsHeaderFlag["RA"] = 128] = "RA";
|
|
121
|
+
DnsHeaderFlag[DnsHeaderFlag["Z"] = 64] = "Z";
|
|
122
|
+
DnsHeaderFlag[DnsHeaderFlag["AD"] = 32] = "AD";
|
|
123
|
+
DnsHeaderFlag[DnsHeaderFlag["CD"] = 16] = "CD";
|
|
124
|
+
DnsHeaderFlag[DnsHeaderFlag["RCODE"] = 15] = "RCODE";
|
|
125
|
+
})(DnsHeaderFlag || (DnsHeaderFlag = {}));
|
|
110
126
|
export function isMdns(message) {
|
|
111
127
|
if (!message || message.length < 12)
|
|
112
128
|
return false;
|
|
@@ -118,7 +134,7 @@ export function isMdnsQuery(message) {
|
|
|
118
134
|
return false;
|
|
119
135
|
const id = message.readUInt16BE(0);
|
|
120
136
|
const flags = message.readUInt16BE(2);
|
|
121
|
-
const qr = (flags &
|
|
137
|
+
const qr = (flags & DnsHeaderFlag.QR) >> 15;
|
|
122
138
|
return id == 0 && qr === 0;
|
|
123
139
|
}
|
|
124
140
|
export function isMdnsResponse(message) {
|
|
@@ -126,9 +142,22 @@ export function isMdnsResponse(message) {
|
|
|
126
142
|
return false;
|
|
127
143
|
const id = message.readUInt16BE(0);
|
|
128
144
|
const flags = message.readUInt16BE(2);
|
|
129
|
-
const qr = (flags &
|
|
145
|
+
const qr = (flags & DnsHeaderFlag.QR) >> 15;
|
|
130
146
|
return id == 0 && qr === 1;
|
|
131
147
|
}
|
|
148
|
+
export async function isFirstOnPort(socketType, port = MDNS_MULTICAST_PORT) {
|
|
149
|
+
return new Promise((resolve) => {
|
|
150
|
+
const probe = dgram.createSocket({ type: socketType, reuseAddr: false });
|
|
151
|
+
probe.once('error', () => {
|
|
152
|
+
probe.close();
|
|
153
|
+
resolve(false);
|
|
154
|
+
});
|
|
155
|
+
probe.bind(port, socketType === 'udp4' ? '0.0.0.0' : '::', () => {
|
|
156
|
+
probe.close();
|
|
157
|
+
resolve(true);
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
}
|
|
132
161
|
export class Mdns extends Multicast {
|
|
133
162
|
deviceQueries = new Map();
|
|
134
163
|
deviceResponses = new Map();
|
|
@@ -196,14 +225,14 @@ export class Mdns extends Multicast {
|
|
|
196
225
|
}
|
|
197
226
|
const id = msg.readUInt16BE(0);
|
|
198
227
|
const flags = msg.readUInt16BE(2);
|
|
199
|
-
const qr = (flags &
|
|
200
|
-
const opcode = (flags &
|
|
201
|
-
const aa = Boolean(flags &
|
|
202
|
-
const tc = Boolean(flags &
|
|
203
|
-
const rd = Boolean(flags &
|
|
204
|
-
const ra = Boolean(flags &
|
|
205
|
-
const z = (flags &
|
|
206
|
-
const rcode = flags &
|
|
228
|
+
const qr = (flags & DnsHeaderFlag.QR) >> 15;
|
|
229
|
+
const opcode = (flags & DnsHeaderFlag.OPCODE) >> 11;
|
|
230
|
+
const aa = Boolean(flags & DnsHeaderFlag.AA);
|
|
231
|
+
const tc = Boolean(flags & DnsHeaderFlag.TC);
|
|
232
|
+
const rd = Boolean(flags & DnsHeaderFlag.RD);
|
|
233
|
+
const ra = Boolean(flags & DnsHeaderFlag.RA);
|
|
234
|
+
const z = (flags & (DnsHeaderFlag.Z | DnsHeaderFlag.AD | DnsHeaderFlag.CD)) >> 4;
|
|
235
|
+
const rcode = flags & DnsHeaderFlag.RCODE;
|
|
207
236
|
const qdCount = msg.readUInt16BE(4);
|
|
208
237
|
const anCount = msg.readUInt16BE(6);
|
|
209
238
|
const nsCount = msg.readUInt16BE(8);
|
|
@@ -293,13 +322,25 @@ export class Mdns extends Multicast {
|
|
|
293
322
|
}
|
|
294
323
|
return { name: labels.join('.'), newOffset: jumped ? originalOffset : offset };
|
|
295
324
|
}
|
|
296
|
-
encodeDnsName(name) {
|
|
325
|
+
encodeDnsName(name, compression, offset = 0) {
|
|
297
326
|
const labels = name.split('.');
|
|
298
|
-
const buffers =
|
|
327
|
+
const buffers = [];
|
|
328
|
+
let length = 0;
|
|
329
|
+
for (const [index, label] of labels.entries()) {
|
|
330
|
+
if (compression && label !== '') {
|
|
331
|
+
const suffix = labels.slice(index).join('.');
|
|
332
|
+
const pointer = compression.get(suffix);
|
|
333
|
+
if (pointer !== undefined)
|
|
334
|
+
return Buffer.concat([...buffers, Buffer.from([0xc0 | (pointer >> 8), pointer & 0xff])]);
|
|
335
|
+
if (offset + length < 0x4000)
|
|
336
|
+
compression.set(suffix, offset + length);
|
|
337
|
+
}
|
|
338
|
+
const labelBuf = Buffer.from(label, 'utf8');
|
|
299
339
|
const lenBuf = Buffer.alloc(1);
|
|
300
|
-
lenBuf.writeUInt8(
|
|
301
|
-
|
|
302
|
-
|
|
340
|
+
lenBuf.writeUInt8(labelBuf.length, 0);
|
|
341
|
+
buffers.push(lenBuf, labelBuf);
|
|
342
|
+
length += 1 + labelBuf.length;
|
|
343
|
+
}
|
|
303
344
|
return Buffer.concat([...buffers, Buffer.from([0])]);
|
|
304
345
|
}
|
|
305
346
|
encodeTxtRdata(txt) {
|
|
@@ -355,6 +396,28 @@ export class Mdns extends Multicast {
|
|
|
355
396
|
return [(word >> 8) & 0xff, word & 0xff];
|
|
356
397
|
}));
|
|
357
398
|
}
|
|
399
|
+
encodeResourceRecord({ name, rtype, rclass, flush = false, ttl, rdata }, compression, offset = 0) {
|
|
400
|
+
const rname = this.encodeDnsName(name, compression, offset);
|
|
401
|
+
const nameStart = rtype === DnsRecordType.PTR ? 0 : rtype === DnsRecordType.SRV ? 6 : -1;
|
|
402
|
+
if (compression && nameStart >= 0) {
|
|
403
|
+
let rdataName;
|
|
404
|
+
try {
|
|
405
|
+
rdataName = this.decodeDnsName(rdata, nameStart).name;
|
|
406
|
+
}
|
|
407
|
+
catch {
|
|
408
|
+
rdataName = undefined;
|
|
409
|
+
}
|
|
410
|
+
if (rdataName !== undefined && this.encodeDnsName(rdataName).equals(rdata.subarray(nameStart))) {
|
|
411
|
+
rdata = Buffer.concat([rdata.subarray(0, nameStart), this.encodeDnsName(rdataName, compression, offset + rname.length + 10 + nameStart)]);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
const recordFixed = Buffer.alloc(10);
|
|
415
|
+
recordFixed.writeUInt16BE(rtype, 0);
|
|
416
|
+
recordFixed.writeUInt16BE(flush ? rclass | DnsClassFlag.FLUSH : rclass, 2);
|
|
417
|
+
recordFixed.writeUInt32BE(ttl, 4);
|
|
418
|
+
recordFixed.writeUInt16BE(rdata.length, 8);
|
|
419
|
+
return Buffer.concat([rname, recordFixed, rdata]);
|
|
420
|
+
}
|
|
358
421
|
decodeResourceRecord(msg, offset) {
|
|
359
422
|
const nameResult = this.decodeDnsName(msg, offset);
|
|
360
423
|
const name = nameResult.name;
|
|
@@ -451,22 +514,30 @@ export class Mdns extends Multicast {
|
|
|
451
514
|
newOffset: offset,
|
|
452
515
|
};
|
|
453
516
|
}
|
|
454
|
-
sendQuery(questions) {
|
|
517
|
+
sendQuery(questions, answers = [], authorities = [], additionals = []) {
|
|
455
518
|
const header = Buffer.alloc(12);
|
|
456
519
|
header.writeUInt16BE(0, 0);
|
|
457
520
|
header.writeUInt16BE(0, 2);
|
|
458
521
|
header.writeUInt16BE(questions.length, 4);
|
|
459
|
-
header.writeUInt16BE(
|
|
460
|
-
header.writeUInt16BE(
|
|
461
|
-
header.writeUInt16BE(
|
|
522
|
+
header.writeUInt16BE(answers.length, 6);
|
|
523
|
+
header.writeUInt16BE(authorities.length, 8);
|
|
524
|
+
header.writeUInt16BE(additionals.length, 10);
|
|
525
|
+
const compression = new Map();
|
|
526
|
+
let offset = 12;
|
|
462
527
|
const questionBuffers = questions.map(({ name, type: qtype, class: qclass, unicastResponse = false }) => {
|
|
463
|
-
const qname = this.encodeDnsName(name);
|
|
528
|
+
const qname = this.encodeDnsName(name, compression, offset);
|
|
464
529
|
const qfields = Buffer.alloc(4);
|
|
465
530
|
qfields.writeUInt16BE(qtype, 0);
|
|
466
531
|
qfields.writeUInt16BE(unicastResponse ? qclass | DnsClassFlag.QU : qclass, 2);
|
|
532
|
+
offset += qname.length + 4;
|
|
467
533
|
return Buffer.concat([qname, qfields]);
|
|
468
534
|
});
|
|
469
|
-
const
|
|
535
|
+
const recordBuffers = [...answers, ...authorities, ...additionals].map((record) => {
|
|
536
|
+
const recordBuffer = this.encodeResourceRecord(record, compression, offset);
|
|
537
|
+
offset += recordBuffer.length;
|
|
538
|
+
return recordBuffer;
|
|
539
|
+
});
|
|
540
|
+
const query = Buffer.concat([header, ...questionBuffers, ...recordBuffers]);
|
|
470
541
|
if (hasParameter('v') || hasParameter('verbose')) {
|
|
471
542
|
const decoded = this.decodeMdnsMessage(query);
|
|
472
543
|
this.logMdnsMessage(decoded, undefined, `Sending query mDNS message (${query.length} bytes)`);
|
|
@@ -483,27 +554,25 @@ export class Mdns extends Multicast {
|
|
|
483
554
|
});
|
|
484
555
|
return query;
|
|
485
556
|
}
|
|
486
|
-
sendResponse(answers) {
|
|
557
|
+
sendResponse(answers, authorities = [], additionals = []) {
|
|
487
558
|
if (!Array.isArray(answers) || answers.length === 0) {
|
|
488
559
|
throw new Error('sendResponse requires a non-empty answers array');
|
|
489
560
|
}
|
|
490
561
|
const header = Buffer.alloc(12);
|
|
491
562
|
header.writeUInt16BE(0, 0);
|
|
492
|
-
header.writeUInt16BE(
|
|
563
|
+
header.writeUInt16BE(DnsHeaderFlag.QR | DnsHeaderFlag.AA, 2);
|
|
493
564
|
header.writeUInt16BE(0, 4);
|
|
494
565
|
header.writeUInt16BE(answers.length, 6);
|
|
495
|
-
header.writeUInt16BE(
|
|
496
|
-
header.writeUInt16BE(
|
|
497
|
-
const
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
answerFixed.writeUInt16BE(rdata.length, 8);
|
|
504
|
-
return Buffer.concat([aname, answerFixed, rdata]);
|
|
566
|
+
header.writeUInt16BE(authorities.length, 8);
|
|
567
|
+
header.writeUInt16BE(additionals.length, 10);
|
|
568
|
+
const compression = new Map();
|
|
569
|
+
let offset = 12;
|
|
570
|
+
const recordBuffers = [...answers, ...authorities, ...additionals].map((record) => {
|
|
571
|
+
const recordBuffer = this.encodeResourceRecord(record, compression, offset);
|
|
572
|
+
offset += recordBuffer.length;
|
|
573
|
+
return recordBuffer;
|
|
505
574
|
});
|
|
506
|
-
const response = Buffer.concat([header, ...
|
|
575
|
+
const response = Buffer.concat([header, ...recordBuffers]);
|
|
507
576
|
if (hasParameter('v') || hasParameter('verbose')) {
|
|
508
577
|
const decoded = this.decodeMdnsMessage(response);
|
|
509
578
|
this.logMdnsMessage(decoded, undefined, `Sending response mDNS message (${response.length} bytes)`);
|
package/dist/multicast.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SocketType } from 'node:dgram';
|
|
1
2
|
import type { AddressInfo } from 'node:net';
|
|
2
3
|
import { Dgram } from './dgram.js';
|
|
3
4
|
export declare const MDNS_MULTICAST_IPV4_ADDRESS = "224.0.0.251";
|
|
@@ -11,7 +12,7 @@ export declare class Multicast extends Dgram {
|
|
|
11
12
|
multicastPort: number;
|
|
12
13
|
outgoingInterfaceAddress: string | undefined;
|
|
13
14
|
joinedInterfaces: string[];
|
|
14
|
-
constructor(name: string, multicastAddress: string, multicastPort: number, socketType:
|
|
15
|
+
constructor(name: string, multicastAddress: string, multicastPort: number, socketType: SocketType, reuseAddr?: boolean | undefined, interfaceName?: string, interfaceAddress?: string, outgoingInterfaceAddress?: string);
|
|
15
16
|
start(): void;
|
|
16
17
|
onListening(address: AddressInfo): void;
|
|
17
18
|
stop(): void;
|
package/dist/unicast.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { RemoteInfo } from 'node:dgram';
|
|
1
|
+
import type { RemoteInfo, SocketType } from 'node:dgram';
|
|
2
2
|
import type { AddressInfo } from 'node:net';
|
|
3
3
|
import { Dgram } from './dgram.js';
|
|
4
4
|
export declare class Unicast extends Dgram {
|
|
5
5
|
port: number | undefined;
|
|
6
|
-
constructor(name: string, socketType:
|
|
6
|
+
constructor(name: string, socketType: SocketType, reuseAddr?: boolean | undefined, interfaceName?: string, interfaceAddress?: string, port?: number);
|
|
7
7
|
start(): void;
|
|
8
8
|
onListening(address: AddressInfo): void;
|
|
9
9
|
onMessage(msg: Buffer, rinfo: RemoteInfo): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@matterbridge/dgram",
|
|
3
|
-
"version": "3.10.12-dev-
|
|
3
|
+
"version": "3.10.12-dev-20260929-3d70112",
|
|
4
4
|
"description": "Matterbridge dgram library",
|
|
5
5
|
"author": "https://github.com/Luligu",
|
|
6
6
|
"homepage": "https://matterbridge.io/",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"skipTsconfig": true
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@matterbridge/utils": "3.10.12-dev-
|
|
70
|
+
"@matterbridge/utils": "3.10.12-dev-20260929-3d70112",
|
|
71
71
|
"node-ansi-logger": "3.3.1"
|
|
72
72
|
}
|
|
73
73
|
}
|