mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-26 02:21:28 +00:00
Improve shadowtls server
This commit is contained in:
parent
468778f67f
commit
89913dfa8c
|
@ -132,7 +132,7 @@ func (s *ShadowTLS) copyUntilHandshakeFinished(dst io.Writer, src io.Reader) err
|
||||||
func (s *ShadowTLS) copyUntilHandshakeFinishedV2(dst net.Conn, src io.Reader, hash *shadowtls.HashWriteConn) (*buf.Buffer, error) {
|
func (s *ShadowTLS) copyUntilHandshakeFinishedV2(dst net.Conn, src io.Reader, hash *shadowtls.HashWriteConn) (*buf.Buffer, error) {
|
||||||
const applicationData = 0x17
|
const applicationData = 0x17
|
||||||
var tlsHdr [5]byte
|
var tlsHdr [5]byte
|
||||||
var applicationDataCount int
|
var doFallback bool
|
||||||
for {
|
for {
|
||||||
_, err := io.ReadFull(src, tlsHdr[:])
|
_, err := io.ReadFull(src, tlsHdr[:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -152,14 +152,13 @@ func (s *ShadowTLS) copyUntilHandshakeFinishedV2(dst net.Conn, src io.Reader, ha
|
||||||
}
|
}
|
||||||
_, err = io.Copy(dst, io.MultiReader(bytes.NewReader(tlsHdr[:]), data))
|
_, err = io.Copy(dst, io.MultiReader(bytes.NewReader(tlsHdr[:]), data))
|
||||||
data.Release()
|
data.Release()
|
||||||
applicationDataCount++
|
doFallback = true
|
||||||
} else {
|
} else {
|
||||||
_, err = io.Copy(dst, io.MultiReader(bytes.NewReader(tlsHdr[:]), io.LimitReader(src, int64(length))))
|
_, err = io.Copy(dst, io.MultiReader(bytes.NewReader(tlsHdr[:]), io.LimitReader(src, int64(length))))
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
} else if doFallback {
|
||||||
if applicationDataCount > 3 {
|
|
||||||
return nil, os.ErrPermission
|
return nil, os.ErrPermission
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue