|
|
@@ -262,50 +262,12 @@ func (p *Proxy) doDomainFronting(ctx *streamContext, conn *connRewind) {
|
|
262
|
262
|
}
|
|
263
|
263
|
}
|
|
264
|
264
|
|
|
265
|
|
-func NewProxy(opts ProxyOpts) (*Proxy, error) { // nolint: cyclop, funlen
|
|
266
|
|
- switch {
|
|
267
|
|
- case opts.Network == nil:
|
|
268
|
|
- return nil, ErrNetworkIsNotDefined
|
|
269
|
|
- case opts.AntiReplayCache == nil:
|
|
270
|
|
- return nil, ErrAntiReplayCacheIsNotDefined
|
|
271
|
|
- case opts.IPBlocklist == nil:
|
|
272
|
|
- return nil, ErrIPBlocklistIsNotDefined
|
|
273
|
|
- case opts.EventStream == nil:
|
|
274
|
|
- return nil, ErrEventStreamIsNotDefined
|
|
275
|
|
- case opts.TimeAttackDetector == nil:
|
|
276
|
|
- return nil, ErrTimeAttackDetectorIsNotDefined
|
|
277
|
|
- case opts.Logger == nil:
|
|
278
|
|
- return nil, ErrLoggerIsNotDefined
|
|
279
|
|
- case !opts.Secret.Valid():
|
|
280
|
|
- return nil, ErrSecretInvalid
|
|
|
265
|
+func NewProxy(opts ProxyOpts) (*Proxy, error) {
|
|
|
266
|
+ if err := opts.valid(); err != nil {
|
|
|
267
|
+ return nil, fmt.Errorf("invalid settings: %w", err)
|
|
281
|
268
|
}
|
|
282
|
269
|
|
|
283
|
|
- preferIP := opts.PreferIP
|
|
284
|
|
- if preferIP == "" {
|
|
285
|
|
- preferIP = DefaultPreferIP
|
|
286
|
|
- }
|
|
287
|
|
-
|
|
288
|
|
- concurrency := opts.Concurrency
|
|
289
|
|
- if concurrency == 0 {
|
|
290
|
|
- concurrency = DefaultConcurrency
|
|
291
|
|
- }
|
|
292
|
|
-
|
|
293
|
|
- idleTimeout := opts.IdleTimeout
|
|
294
|
|
- if idleTimeout < 1 {
|
|
295
|
|
- idleTimeout = DefaultIdleTimeout
|
|
296
|
|
- }
|
|
297
|
|
-
|
|
298
|
|
- bufferSize := opts.BufferSize
|
|
299
|
|
- if bufferSize < 1 {
|
|
300
|
|
- bufferSize = DefaultBufferSize
|
|
301
|
|
- }
|
|
302
|
|
-
|
|
303
|
|
- domainFrontingPort := int(opts.DomainFrontingPort)
|
|
304
|
|
- if domainFrontingPort == 0 {
|
|
305
|
|
- domainFrontingPort = DefaultDomainFrontingPort
|
|
306
|
|
- }
|
|
307
|
|
-
|
|
308
|
|
- tg, err := telegram.New(opts.Network, preferIP)
|
|
|
270
|
+ tg, err := telegram.New(opts.Network, opts.getPreferIP())
|
|
309
|
271
|
if err != nil {
|
|
310
|
272
|
return nil, fmt.Errorf("cannot build telegram dialer: %w", err)
|
|
311
|
273
|
}
|
|
|
@@ -320,17 +282,18 @@ func NewProxy(opts ProxyOpts) (*Proxy, error) { // nolint: cyclop, funlen
|
|
320
|
282
|
timeAttackDetector: opts.TimeAttackDetector,
|
|
321
|
283
|
ipBlocklist: opts.IPBlocklist,
|
|
322
|
284
|
eventStream: opts.EventStream,
|
|
323
|
|
- logger: opts.Logger.Named("proxy"),
|
|
324
|
|
- domainFrontingPort: domainFrontingPort,
|
|
325
|
|
- idleTimeout: idleTimeout,
|
|
326
|
|
- bufferSize: int(bufferSize),
|
|
|
285
|
+ logger: opts.getLogger("proxy"),
|
|
|
286
|
+ domainFrontingPort: opts.getDomainFrontingPort(),
|
|
|
287
|
+ idleTimeout: opts.getIdleTimeout(),
|
|
|
288
|
+ bufferSize: opts.getBufferSize(),
|
|
327
|
289
|
telegram: tg,
|
|
328
|
290
|
}
|
|
329
|
291
|
|
|
330
|
|
- pool, err := ants.NewPoolWithFunc(int(concurrency), func(arg interface{}) {
|
|
331
|
|
- proxy.ServeConn(arg.(net.Conn))
|
|
332
|
|
- },
|
|
333
|
|
- ants.WithLogger(opts.Logger.Named("ants")),
|
|
|
292
|
+ pool, err := ants.NewPoolWithFunc(opts.getConcurrency(),
|
|
|
293
|
+ func(arg interface{}) {
|
|
|
294
|
+ proxy.ServeConn(arg.(net.Conn))
|
|
|
295
|
+ },
|
|
|
296
|
+ ants.WithLogger(opts.getLogger("ants")),
|
|
334
|
297
|
ants.WithNonblocking(true))
|
|
335
|
298
|
if err != nil {
|
|
336
|
299
|
panic(err)
|