From 82f8367c4018695ff630453e3fbf37e4274b9799 Mon Sep 17 00:00:00 2001 From: Meo597 <197331664+Meo597@users.noreply.github.com> Date: Sun, 8 Jun 2025 18:58:39 +0800 Subject: [PATCH] read --- tls.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tls.go b/tls.go index 0038fed..d0eaba4 100644 --- a/tls.go +++ b/tls.go @@ -108,8 +108,8 @@ type RatelimitedConn struct { LimitAfter int64 } -func (c *RatelimitedConn) Write(b []byte) (int, error) { - n, err := c.Conn.Write(b) +func (c *RatelimitedConn) Read(b []byte) (int, error) { + n, err := c.Conn.Read(b) if n != 0 { if c.LimitAfter <= 0 { c.Bucket.Wait(int64(n)) @@ -266,11 +266,11 @@ 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(&RatelimitedConn{ - Conn: target, + io.Copy(target, &RatelimitedConn{ + Conn: underlying, Bucket: NewBucketWithRate(config.LimitFallbackUpload.BytesPerSec, config.LimitFallbackUpload.BurstBytesPerSec), LimitAfter: ToInt64(config.LimitFallbackUpload.AfterBytes) - ToInt64(config.LimitFallbackUpload.BurstBytesPerSec), - }, underlying) + }) } } waitGroup.Done() @@ -406,11 +406,11 @@ 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(&RatelimitedConn{ - Conn: target, + io.Copy(target, &RatelimitedConn{ + Conn: underlying, Bucket: NewBucketWithRate(config.LimitFallbackUpload.BytesPerSec, config.LimitFallbackUpload.BurstBytesPerSec), LimitAfter: ToInt64(config.LimitFallbackUpload.AfterBytes) - ToInt64(config.LimitFallbackUpload.BurstBytesPerSec), - }, underlying) + }) } waitGroup.Done() }() @@ -420,11 +420,11 @@ 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(&RatelimitedConn{ - Conn: underlying, + io.Copy(underlying, &RatelimitedConn{ + Conn: target, Bucket: NewBucketWithRate(config.LimitFallbackDownload.BytesPerSec, config.LimitFallbackDownload.BurstBytesPerSec), LimitAfter: ToInt64(config.LimitFallbackDownload.AfterBytes) - ToInt64(config.LimitFallbackDownload.BurstBytesPerSec), - }, target) + }) } // Here is bidirectional direct forwarding: // client ---underlying--- server ---target--- dest