Browse Source

Add public method DomainFrontingAddress

tags/v2.0.0-rc1
9seconds 5 years ago
parent
commit
75b05b9b14
1 changed files with 10 additions and 7 deletions
  1. 10
    7
      mtglib/proxy.go

+ 10
- 7
mtglib/proxy.go View File

24
 
24
 
25
 	idleTimeout        time.Duration
25
 	idleTimeout        time.Duration
26
 	bufferSize         int
26
 	bufferSize         int
27
-	domainFrontAddress string
27
+	domainFrontingPort int
28
 	workerPool         *ants.PoolWithFunc
28
 	workerPool         *ants.PoolWithFunc
29
 	telegram           *telegram.Telegram
29
 	telegram           *telegram.Telegram
30
 
30
 
37
 	logger             Logger
37
 	logger             Logger
38
 }
38
 }
39
 
39
 
40
+func (p *Proxy) DomainFrontingAddress() string {
41
+	return net.JoinHostPort(p.secret.Host, strconv.Itoa(p.domainFrontingPort))
42
+}
43
+
40
 func (p *Proxy) ServeConn(conn net.Conn) {
44
 func (p *Proxy) ServeConn(conn net.Conn) {
41
 	ctx := newStreamContext(p.ctx, p.logger, conn)
45
 	ctx := newStreamContext(p.ctx, p.logger, conn)
42
 	defer ctx.Close()
46
 	defer ctx.Close()
247
 
251
 
248
 	conn.Rewind()
252
 	conn.Rewind()
249
 
253
 
250
-	frontConn, err := p.network.DialContext(ctx, "tcp", p.domainFrontAddress)
254
+	frontConn, err := p.network.DialContext(ctx, "tcp", p.DomainFrontingAddress())
251
 	if err != nil {
255
 	if err != nil {
252
 		p.logger.WarningError("cannot dial to the fronting domain", err)
256
 		p.logger.WarningError("cannot dial to the fronting domain", err)
253
 
257
 
324
 		ipBlocklist:        opts.IPBlocklist,
328
 		ipBlocklist:        opts.IPBlocklist,
325
 		eventStream:        opts.EventStream,
329
 		eventStream:        opts.EventStream,
326
 		logger:             opts.Logger.Named("proxy"),
330
 		logger:             opts.Logger.Named("proxy"),
327
-		domainFrontAddress: net.JoinHostPort(opts.Secret.Host,
328
-			strconv.Itoa(domainFrontingPort)),
329
-		idleTimeout: idleTimeout,
330
-		bufferSize:  int(bufferSize),
331
-		telegram:    tg,
331
+		domainFrontingPort: int(domainFrontingPort),
332
+		idleTimeout:        idleTimeout,
333
+		bufferSize:         int(bufferSize),
334
+		telegram:           tg,
332
 	}
335
 	}
333
 
336
 
334
 	pool, err := ants.NewPoolWithFunc(int(concurrency), func(arg interface{}) {
337
 	pool, err := ants.NewPoolWithFunc(int(concurrency), func(arg interface{}) {

Loading…
Cancel
Save