mirror of
https://github.com/XTLS/REALITY.git
synced 2025-08-23 06:58:39 +00:00
ok
This commit is contained in:
parent
39d54e1d67
commit
fda134e780
16
tls.go
16
tls.go
@ -119,10 +119,10 @@ func (c *RatelimitedConn) Read(b []byte) (int, error) {
|
|||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRatelimitedConn(con net.Conn, config *Config) *RatelimitedConn {
|
func NewRatelimitedConn(con net.Conn, limit *LimitFallback) *RatelimitedConn {
|
||||||
bytesPerSec := config.LimitFallbackUpload.BytesPerSec
|
bytesPerSec := limit.BytesPerSec
|
||||||
burstBytesPerSec := config.LimitFallbackUpload.BurstBytesPerSec
|
burstBytesPerSec := limit.BurstBytesPerSec
|
||||||
afterBytes := config.LimitFallbackUpload.AfterBytes
|
afterBytes := limit.AfterBytes
|
||||||
|
|
||||||
if burstBytesPerSec < bytesPerSec {
|
if burstBytesPerSec < bytesPerSec {
|
||||||
burstBytesPerSec = bytesPerSec
|
burstBytesPerSec = bytesPerSec
|
||||||
@ -131,7 +131,7 @@ func NewRatelimitedConn(con net.Conn, config *Config) *RatelimitedConn {
|
|||||||
return &RatelimitedConn{
|
return &RatelimitedConn{
|
||||||
Conn: con,
|
Conn: con,
|
||||||
Bucket: ratelimit.NewBucketWithRate(float64(bytesPerSec), int64(burstBytesPerSec)),
|
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)
|
io.Copy(target, underlying)
|
||||||
} else {
|
} else {
|
||||||
// Limit upload speed for fallback connection
|
// Limit upload speed for fallback connection
|
||||||
io.Copy(target, NewRatelimitedConn(underlying, config))
|
io.Copy(target, NewRatelimitedConn(underlying, &config.LimitFallbackUpload))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
waitGroup.Done()
|
waitGroup.Done()
|
||||||
@ -403,7 +403,7 @@ func Server(ctx context.Context, conn net.Conn, config *Config) (*Conn, error) {
|
|||||||
io.Copy(target, underlying)
|
io.Copy(target, underlying)
|
||||||
} else {
|
} 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))
|
io.Copy(target, NewRatelimitedConn(underlying, &config.LimitFallbackUpload))
|
||||||
}
|
}
|
||||||
waitGroup.Done()
|
waitGroup.Done()
|
||||||
}()
|
}()
|
||||||
@ -413,7 +413,7 @@ func Server(ctx context.Context, conn net.Conn, config *Config) (*Conn, error) {
|
|||||||
io.Copy(underlying, target)
|
io.Copy(underlying, target)
|
||||||
} else {
|
} else {
|
||||||
// Limit download speed for fallback connection
|
// Limit download speed for fallback connection
|
||||||
io.Copy(underlying, NewRatelimitedConn(target, config))
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user