@@ -8,6 +8,7 @@ import type {
8
8
MulticastSocketInfo ,
9
9
SocketHostRow ,
10
10
RemoteInfo ,
11
+ FDQN ,
11
12
} from './types' ;
12
13
import type {
13
14
CachableResourceRecord ,
@@ -57,10 +58,10 @@ class MDNS {
57
58
58
59
protected localRecordCache : ResourceRecordCache ;
59
60
protected localRecordCacheDirty = true ;
60
- protected _localServices : Map < Hostname , Service > = new Map ( ) ;
61
+ protected _localServices : Map < FDQN , Service > = new Map ( ) ;
61
62
62
63
protected networkRecordCache : ResourceRecordCache ;
63
- protected _networkServices : Map < Hostname , Service > = new Map ( ) ;
64
+ protected _networkServices : Map < FDQN , Service > = new Map ( ) ;
64
65
protected sockets : Array < dgram . Socket > = [ ] ;
65
66
protected socketMap : WeakMap < dgram . Socket , SocketInfo > = new WeakMap ( ) ;
66
67
protected socketHostTable : Table < SocketHostRow > = new Table (
@@ -140,7 +141,7 @@ class MDNS {
140
141
* The Key is a FDQN.
141
142
*/
142
143
@ready ( new errors . ErrorMDNSNotRunning ( ) )
143
- public get localServices ( ) : ReadonlyMap < Hostname , Service > {
144
+ public get localServices ( ) : ReadonlyMap < FDQN , Service > {
144
145
return this . _localServices ;
145
146
}
146
147
@@ -149,7 +150,7 @@ class MDNS {
149
150
* The Key is a FDQN.
150
151
*/
151
152
@ready ( new errors . ErrorMDNSNotRunning ( ) )
152
- public get networkServices ( ) : ReadonlyMap < Hostname , Service > {
153
+ public get networkServices ( ) : ReadonlyMap < FDQN , Service > {
153
154
return this . _networkServices ;
154
155
}
155
156
@@ -1003,22 +1004,22 @@ class MDNS {
1003
1004
1004
1005
protected extractRelatedFdqns (
1005
1006
resourceRecords : ResourceRecord | Array < ResourceRecord > ,
1006
- ) : Array < Hostname > {
1007
+ ) : Array < FDQN > {
1007
1008
if ( ! Array . isArray ( resourceRecords ) ) {
1008
1009
return this . extractRelatedFdqns ( [ resourceRecords ] ) ;
1009
1010
}
1010
- const relatedFdqns : Array < Hostname > = [ ] ;
1011
+ const relatedFdqns : Array < FDQN > = [ ] ;
1011
1012
for ( const resourceRecord of resourceRecords ) {
1012
1013
if (
1013
1014
resourceRecord . type === RType . SRV ||
1014
1015
resourceRecord . type === RType . TXT
1015
1016
) {
1016
- relatedFdqns . push ( resourceRecord . name as Hostname ) ;
1017
+ relatedFdqns . push ( resourceRecord . name as FDQN ) ;
1017
1018
} else if (
1018
1019
resourceRecord . type === RType . PTR &&
1019
1020
resourceRecord . name !== '_services._dns-sd._udp.local'
1020
1021
) {
1021
- relatedFdqns . push ( resourceRecord . data as Hostname ) ;
1022
+ relatedFdqns . push ( resourceRecord . data as FDQN ) ;
1022
1023
} else if (
1023
1024
resourceRecord . type === RType . A ||
1024
1025
resourceRecord . type === RType . AAAA
@@ -1029,7 +1030,7 @@ class MDNS {
1029
1030
) ;
1030
1031
for ( const relatedResourceRecord of relatedResourceRecords ) {
1031
1032
if ( relatedResourceRecord . type === RType . SRV ) {
1032
- relatedFdqns . push ( relatedResourceRecord . name as Hostname ) ;
1033
+ relatedFdqns . push ( relatedResourceRecord . name as FDQN ) ;
1033
1034
}
1034
1035
}
1035
1036
}
@@ -1160,9 +1161,7 @@ class MDNS {
1160
1161
hostname : this . _hostname ,
1161
1162
hosts : [ ] ,
1162
1163
} ;
1163
- const serviceDomain =
1164
- `_${ service . type } ._${ service . protocol } .local` as Hostname ;
1165
- const fdqn = `${ service . name } .${ serviceDomain } ` as Hostname ;
1164
+ const fdqn = utils . toFdqn ( service ) ;
1166
1165
1167
1166
this . _localServices . set ( fdqn , service ) ;
1168
1167
this . localRecordCacheDirty = true ;
@@ -1200,8 +1199,11 @@ class MDNS {
1200
1199
type : string ;
1201
1200
protocol : 'udp' | 'tcp' ;
1202
1201
} ) {
1203
- const serviceDomain = `_${ type } ._${ protocol } .local` as Hostname ;
1204
- const fdqn = `${ name } .${ serviceDomain } ` as Hostname ;
1202
+ const fdqn = utils . toFdqn ( {
1203
+ name,
1204
+ type,
1205
+ protocol,
1206
+ } ) ;
1205
1207
1206
1208
const foundService = this . _localServices . get ( fdqn ) ;
1207
1209
if ( foundService == null ) return ;
@@ -1248,7 +1250,10 @@ class MDNS {
1248
1250
minDelay ?: number ;
1249
1251
maxDelay ?: number ;
1250
1252
} ) {
1251
- const serviceDomain = `_${ type } ._${ protocol } .local` as Hostname ;
1253
+ const serviceDomain = utils . toServiceDomain ( {
1254
+ type,
1255
+ protocol,
1256
+ } ) ;
1252
1257
const questionRecord : QuestionRecord = {
1253
1258
name : serviceDomain ,
1254
1259
type : QType . PTR ,
@@ -1329,7 +1334,10 @@ class MDNS {
1329
1334
type : string ;
1330
1335
protocol : 'udp' | 'tcp' ;
1331
1336
} ) {
1332
- const serviceDomain = `_${ type } ._${ protocol } .local` ;
1337
+ const serviceDomain = utils . toServiceDomain ( {
1338
+ type,
1339
+ protocol,
1340
+ } ) ;
1333
1341
this . queries . get ( serviceDomain ) ?. cancel ( ) ;
1334
1342
}
1335
1343
}
0 commit comments