mirror of
https://github.com/XTLS/REALITY.git
synced 2025-08-24 07:28:36 +00:00
0
This commit is contained in:
parent
d405a94c95
commit
931974b633
16
tls.go
16
tls.go
@ -124,6 +124,10 @@ func NewRatelimitedConn(conn net.Conn, limit *LimitFallback) net.Conn {
|
|||||||
burstBytesPerSec := limit.BurstBytesPerSec
|
burstBytesPerSec := limit.BurstBytesPerSec
|
||||||
afterBytes := limit.AfterBytes
|
afterBytes := limit.AfterBytes
|
||||||
|
|
||||||
|
if bytesPerSec == 0 {
|
||||||
|
return conn
|
||||||
|
}
|
||||||
|
|
||||||
if burstBytesPerSec < bytesPerSec {
|
if burstBytesPerSec < bytesPerSec {
|
||||||
burstBytesPerSec = bytesPerSec
|
burstBytesPerSec = bytesPerSec
|
||||||
}
|
}
|
||||||
@ -263,13 +267,9 @@ func Server(ctx context.Context, conn net.Conn, config *Config) (*Conn, error) {
|
|||||||
if config.Show && hs.clientHello != nil {
|
if config.Show && hs.clientHello != nil {
|
||||||
fmt.Printf("REALITY remoteAddr: %v\tforwarded SNI: %v\n", remoteAddr, hs.clientHello.serverName)
|
fmt.Printf("REALITY remoteAddr: %v\tforwarded SNI: %v\n", remoteAddr, hs.clientHello.serverName)
|
||||||
}
|
}
|
||||||
if config.LimitFallbackUpload.BytesPerSec == 0 {
|
|
||||||
io.Copy(target, underlying)
|
|
||||||
} else {
|
|
||||||
// Limit upload speed for fallback connection
|
// Limit upload speed for fallback connection
|
||||||
io.Copy(target, NewRatelimitedConn(underlying, &config.LimitFallbackUpload))
|
io.Copy(target, NewRatelimitedConn(underlying, &config.LimitFallbackUpload))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
waitGroup.Done()
|
waitGroup.Done()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -399,22 +399,14 @@ func Server(ctx context.Context, conn net.Conn, config *Config) (*Conn, error) {
|
|||||||
if hs.c.conn == conn { // if we processed the Client Hello successfully but the target did not
|
if hs.c.conn == conn { // if we processed the Client Hello successfully but the target did not
|
||||||
waitGroup.Add(1)
|
waitGroup.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
if config.LimitFallbackUpload.BytesPerSec == 0 {
|
|
||||||
io.Copy(target, underlying)
|
|
||||||
} else {
|
|
||||||
// Limit upload speed for fallback connection (handshake ok but hello failed)
|
// Limit upload speed for fallback connection (handshake ok but hello failed)
|
||||||
io.Copy(target, NewRatelimitedConn(underlying, &config.LimitFallbackUpload))
|
io.Copy(target, NewRatelimitedConn(underlying, &config.LimitFallbackUpload))
|
||||||
}
|
|
||||||
waitGroup.Done()
|
waitGroup.Done()
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
conn.Write(s2cSaved)
|
conn.Write(s2cSaved)
|
||||||
if config.LimitFallbackDownload.BytesPerSec == 0 {
|
|
||||||
io.Copy(underlying, target)
|
|
||||||
} else {
|
|
||||||
// Limit download speed for fallback connection
|
// Limit download speed for fallback connection
|
||||||
io.Copy(underlying, NewRatelimitedConn(target, &config.LimitFallbackDownload))
|
io.Copy(underlying, NewRatelimitedConn(target, &config.LimitFallbackDownload))
|
||||||
}
|
|
||||||
// Here is bidirectional direct forwarding:
|
// Here is bidirectional direct forwarding:
|
||||||
// client ---underlying--- server ---target--- dest
|
// client ---underlying--- server ---target--- dest
|
||||||
// Call `underlying.CloseWrite()` once `io.Copy()` returned
|
// Call `underlying.CloseWrite()` once `io.Copy()` returned
|
||||||
|
Loading…
Reference in New Issue
Block a user