0
0
mirror of https://github.com/XTLS/REALITY.git synced 2025-08-29 09:55: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 {
return err
}
return nil
if err := hs.readClientCertificate(); err != nil {
return err
}

28
tls.go
View File

@ -32,6 +32,7 @@ import (
"runtime"
"strings"
"sync"
"sync/atomic"
"time"
"github.com/pires/go-proxyproto"
@ -354,13 +355,36 @@ func Server(ctx context.Context, conn net.Conn, config *Config) (*Conn, error) {
s2cSaved = s2cSaved[handshakeLen:]
handshakeLen = 0
}
start := time.Now()
err = hs.handshake()
if config.Show {
fmt.Printf("REALITY remoteAddr: %v\ths.handshake() err: %v\n", remoteAddr, err)
}
if err == nil {
handled = true
if err != nil {
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
}
if done {