mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-09-01 09:34:02 +03:00
Add separate handshake timeout
This PR adds a new setting to the config: `network.timeout`. This setting defines a time period during which all handshake procedures and ceremonies must be completed. If not - connection is aborted. This should help in situations when connection is established but client cannot continue for some reason (for example, RST sent by some middle box).
This commit is contained in:
@@ -28,6 +28,7 @@ type Proxy struct {
|
||||
allowFallbackOnUnknownDC bool
|
||||
tolerateTimeSkewness time.Duration
|
||||
idleTimeout time.Duration
|
||||
handshakeTimeout time.Duration
|
||||
domainFrontingPort int
|
||||
domainFrontingIP string
|
||||
domainFrontingProxyProtocol bool
|
||||
@@ -66,6 +67,11 @@ func (p *Proxy) ServeConn(conn essentials.Conn) {
|
||||
ctx := newStreamContext(p.ctx, p.logger, conn)
|
||||
defer ctx.Close()
|
||||
|
||||
if err := ctx.clientConn.SetDeadline(time.Now().Add(p.handshakeTimeout)); err != nil {
|
||||
ctx.logger.WarningError("cannot set handshake timeout", err)
|
||||
return
|
||||
}
|
||||
|
||||
stop := context.AfterFunc(ctx, func() {
|
||||
ctx.Close()
|
||||
})
|
||||
@@ -97,6 +103,11 @@ func (p *Proxy) ServeConn(conn essentials.Conn) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := ctx.clientConn.SetDeadline(time.Time{}); err != nil {
|
||||
ctx.logger.WarningError("cannot set deadline", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := p.doTelegramCall(ctx); err != nil {
|
||||
ctx.logger.WarningError("cannot dial to telegram", err)
|
||||
return
|
||||
@@ -346,6 +357,7 @@ func NewProxy(opts ProxyOpts) (*Proxy, error) {
|
||||
domainFrontingIP: opts.DomainFrontingIP,
|
||||
tolerateTimeSkewness: opts.getTolerateTimeSkewness(),
|
||||
idleTimeout: opts.getIdleTimeout(),
|
||||
handshakeTimeout: opts.getHandshakeTimeout(),
|
||||
allowFallbackOnUnknownDC: opts.AllowFallbackOnUnknownDC,
|
||||
telegram: tg,
|
||||
doppelGanger: doppel.NewGanger(
|
||||
|
||||
Reference in New Issue
Block a user