1
1
import { randomUUID } from 'node:crypto' ;
2
+ import { customAlphabet } from 'nanoid' ;
2
3
3
4
import { Injectable } from '@nestjs/common' ;
4
5
import { QueryBus } from '@nestjs/cqrs' ;
@@ -24,7 +25,11 @@ import { IFormattedHost } from './interfaces/formatted-hosts.interface';
24
25
25
26
@Injectable ( )
26
27
export class FormatHostsService {
27
- constructor ( private readonly queryBus : QueryBus ) { }
28
+ private readonly nanoid : ReturnType < typeof customAlphabet > ;
29
+
30
+ constructor ( private readonly queryBus : QueryBus ) {
31
+ this . nanoid = customAlphabet ( '0123456789abcdefghjkmnopqrstuvwxyz' , 10 ) ;
32
+ }
28
33
29
34
public async generateFormattedHosts (
30
35
config : XRayConfig ,
@@ -99,7 +104,13 @@ export class FormatHostsService {
99
104
100
105
const remark = TemplateEngine . formarWithUser ( inputHost . remark , user ) ;
101
106
102
- const address = inputHost . address ;
107
+ let address = inputHost . address ;
108
+
109
+ if ( address . includes ( ',' ) ) {
110
+ const addressList = address . split ( ',' ) ;
111
+ address = addressList [ Math . floor ( Math . random ( ) * addressList . length ) ] . trim ( ) ;
112
+ }
113
+
103
114
const port = inputHost . port ;
104
115
let network = inbound . streamSettings ?. network || 'tcp' ;
105
116
@@ -177,7 +188,6 @@ export class FormatHostsService {
177
188
const realitySettings = inbound . streamSettings ?. realitySettings ;
178
189
sniFromConfig = realitySettings ?. serverNames ?. [ 0 ] ;
179
190
fingerprintFromConfig = realitySettings ?. fingerprint ;
180
- // publicKeyFromConfig = realitySettings?.publicKey || realitySettings?.password;
181
191
182
192
publicKeyFromConfig = publicKeyMap . get ( inbound . tag ) ;
183
193
@@ -234,6 +244,10 @@ export class FormatHostsService {
234
244
sni = inputHost . address ;
235
245
}
236
246
247
+ if ( sni . includes ( '*.' ) ) {
248
+ sni = sni . replace ( '*' , this . nanoid ( ) ) ;
249
+ }
250
+
237
251
// Fingerprint
238
252
const fp = inputHost . fingerprint || fingerprintFromConfig || '' ;
239
253
0 commit comments