Sfoglia il codice sorgente

Add public method DomainFrontingAddress

tags/v2.0.0-rc1
9seconds 5 anni fa
parent
commit
75b05b9b14
1 ha cambiato i file con 10 aggiunte e 7 eliminazioni
  1. 10
    7
      mtglib/proxy.go

+ 10
- 7
mtglib/proxy.go Vedi File

@@ -24,7 +24,7 @@ type Proxy struct {
24 24
 
25 25
 	idleTimeout        time.Duration
26 26
 	bufferSize         int
27
-	domainFrontAddress string
27
+	domainFrontingPort int
28 28
 	workerPool         *ants.PoolWithFunc
29 29
 	telegram           *telegram.Telegram
30 30
 
@@ -37,6 +37,10 @@ type Proxy struct {
37 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 44
 func (p *Proxy) ServeConn(conn net.Conn) {
41 45
 	ctx := newStreamContext(p.ctx, p.logger, conn)
42 46
 	defer ctx.Close()
@@ -247,7 +251,7 @@ func (p *Proxy) doDomainFronting(ctx *streamContext, conn *connRewind) {
247 251
 
248 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 255
 	if err != nil {
252 256
 		p.logger.WarningError("cannot dial to the fronting domain", err)
253 257
 
@@ -324,11 +328,10 @@ func NewProxy(opts ProxyOpts) (*Proxy, error) { // nolint: cyclop, funlen
324 328
 		ipBlocklist:        opts.IPBlocklist,
325 329
 		eventStream:        opts.EventStream,
326 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 337
 	pool, err := ants.NewPoolWithFunc(int(concurrency), func(arg interface{}) {

Loading…
Annulla
Salva