0
0
mirror of https://github.com/XTLS/REALITY.git synced 2025-08-22 14:38:35 +00:00
This commit is contained in:
Meo597 2025-06-08 19:37:22 +08:00
parent 39d54e1d67
commit fda134e780

16
tls.go
View File

@ -119,10 +119,10 @@ func (c *RatelimitedConn) Read(b []byte) (int, error) {
return n, err
}
func NewRatelimitedConn(con net.Conn, config *Config) *RatelimitedConn {
bytesPerSec := config.LimitFallbackUpload.BytesPerSec
burstBytesPerSec := config.LimitFallbackUpload.BurstBytesPerSec
afterBytes := config.LimitFallbackUpload.AfterBytes
func NewRatelimitedConn(con net.Conn, limit *LimitFallback) *RatelimitedConn {
bytesPerSec := limit.BytesPerSec
burstBytesPerSec := limit.BurstBytesPerSec
afterBytes := limit.AfterBytes
if burstBytesPerSec < bytesPerSec {
burstBytesPerSec = bytesPerSec
@ -131,7 +131,7 @@ func NewRatelimitedConn(con net.Conn, config *Config) *RatelimitedConn {
return &RatelimitedConn{
Conn: con,
Bucket: ratelimit.NewBucketWithRate(float64(bytesPerSec), int64(burstBytesPerSec)),
LimitAfter: int64(afterBytes) - int64(burstBytesPerSec),
LimitAfter: int64(afterBytes),
}
}
@ -267,7 +267,7 @@ func Server(ctx context.Context, conn net.Conn, config *Config) (*Conn, error) {
io.Copy(target, underlying)
} else {
// Limit upload speed for fallback connection
io.Copy(target, NewRatelimitedConn(underlying, config))
io.Copy(target, NewRatelimitedConn(underlying, &config.LimitFallbackUpload))
}
}
waitGroup.Done()
@ -403,7 +403,7 @@ func Server(ctx context.Context, conn net.Conn, config *Config) (*Conn, error) {
io.Copy(target, underlying)
} else {
// Limit upload speed for fallback connection (handshake ok but hello failed)
io.Copy(target, NewRatelimitedConn(underlying, config))
io.Copy(target, NewRatelimitedConn(underlying, &config.LimitFallbackUpload))
}
waitGroup.Done()
}()
@ -413,7 +413,7 @@ func Server(ctx context.Context, conn net.Conn, config *Config) (*Conn, error) {
io.Copy(underlying, target)
} else {
// Limit download speed for fallback connection
io.Copy(underlying, NewRatelimitedConn(target, config))
io.Copy(underlying, NewRatelimitedConn(target, &config.LimitFallbackDownload))
}
// Here is bidirectional direct forwarding:
// client ---underlying--- server ---target--- dest