0
0
mirror of https://github.com/XTLS/REALITY.git synced 2025-08-29 18:05:32 +00:00

Apply target's time-out to hs.readClientFinished()

This commit is contained in:
RPRX 2023-03-09 20:51:17 +08:00 committed by GitHub
parent 6288e760a9
commit a7ae8b57f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 2 deletions

View File

@ -131,6 +131,8 @@ func (hs *serverHandshakeStateTLS13) handshake() error {
if _, err := c.flush(); err != nil { if _, err := c.flush(); err != nil {
return err return err
} }
return nil
if err := hs.readClientCertificate(); err != nil { if err := hs.readClientCertificate(); err != nil {
return err return err
} }

28
tls.go
View File

@ -32,6 +32,7 @@ import (
"runtime" "runtime"
"strings" "strings"
"sync" "sync"
"sync/atomic"
"time" "time"
"github.com/pires/go-proxyproto" "github.com/pires/go-proxyproto"
@ -354,13 +355,36 @@ func Server(ctx context.Context, conn net.Conn, config *Config) (*Conn, error) {
s2cSaved = s2cSaved[handshakeLen:] s2cSaved = s2cSaved[handshakeLen:]
handshakeLen = 0 handshakeLen = 0
} }
start := time.Now()
err = hs.handshake() err = hs.handshake()
if config.Show { if config.Show {
fmt.Printf("REALITY remoteAddr: %v\ths.handshake() err: %v\n", remoteAddr, err) fmt.Printf("REALITY remoteAddr: %v\ths.handshake() err: %v\n", remoteAddr, err)
} }
if err == nil { if err != nil {
handled = true break
} }
go func() { // TODO: Probe target's maxUselessRecords and some time-outs in advance.
if handshakeLen-len(s2cSaved) > 0 {
io.ReadFull(target, buf[:handshakeLen-len(s2cSaved)])
}
if n, err := target.Read(buf); !hs.c.handshakeComplete() {
if err != nil {
conn.Close()
}
if config.Show {
fmt.Printf("REALITY remoteAddr: %v\ttime.Since(start): %v\tn: %v\terr: %v\n", remoteAddr, time.Since(start), n, err)
}
}
}()
err = hs.readClientFinished()
if config.Show {
fmt.Printf("REALITY remoteAddr: %v\ths.readClientFinished() err: %v\n", remoteAddr, err)
}
if err != nil {
break
}
atomic.StoreUint32(&hs.c.handshakeStatus, 1)
handled = true
break break
} }
if done { if done {