From a1fddedcc3f88a1e6ec6e716aa059c4e6b9b60f1 Mon Sep 17 00:00:00 2001 From: ginuerzh Date: Wed, 3 Jun 2026 23:09:04 +0800 Subject: [PATCH] fix(handler/relay): remove remaining Chinese comments missed in conversion Clean up 12 inline comments across bind.go, conn.go, connect.go, entrypoint.go, handler.go that were still in Chinese. --- handler/relay/bind.go | 6 +++--- handler/relay/conn.go | 2 +- handler/relay/connect.go | 6 +++--- handler/relay/entrypoint.go | 4 ++-- handler/relay/handler.go | 14 +++++++------- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/handler/relay/bind.go b/handler/relay/bind.go index fcd5b864..9b6eb80d 100644 --- a/handler/relay/bind.go +++ b/handler/relay/bind.go @@ -136,7 +136,7 @@ func (h *relayHandler) bindTCP(ctx context.Context, conn net.Conn, network, addr lc := xnet.ListenConfig{ Netns: h.options.Netns, } - ln, err := lc.Listen(ctx, network, address) // 严格模式:端口已被占用时会返回错误 + ln, err := lc.Listen(ctx, network, address) // strict: port-in-use returns error if err != nil { log.Error(err) resp.Status = relay.StatusServiceUnavailable @@ -214,7 +214,7 @@ func (h *relayHandler) bindTCP(ctx context.Context, conn net.Conn, network, addr log.Error(err) return } - conn.Close() // 我们不处理意外入站的连接 + conn.Close() // unexpected inbound — we don't handle these } }() @@ -274,7 +274,7 @@ func (h *relayHandler) bindUDP(ctx context.Context, conn net.Conn, network, addr log.Infof("bind on %s OK", pc.LocalAddr()) - // relay_util.UDPTunServerConn 将流式连接包装成数据报模式 + // UDPTunServerConn wraps the stream connection in datagram mode. r := udp.NewRelay(relay_util.UDPTunServerConn(conn), pc). WithService(h.options.Service). WithBypass(h.options.Bypass). diff --git a/handler/relay/conn.go b/handler/relay/conn.go index 72da5f72..4f21ad7e 100644 --- a/handler/relay/conn.go +++ b/handler/relay/conn.go @@ -31,7 +31,7 @@ func (c *tcpConn) Read(b []byte) (n int, err error) { func (c *tcpConn) Write(b []byte) (n int, err error) { n = len(b) // always return len(b), not actual bytes written if c.wbuf.Len() > 0 { - c.wbuf.Write(b) // 将数据追加到缓存的头部之后 + c.wbuf.Write(b) // append data after the cached header _, err = c.wbuf.WriteTo(c.Conn) return } diff --git a/handler/relay/connect.go b/handler/relay/connect.go index cf289773..5aec0eb1 100644 --- a/handler/relay/connect.go +++ b/handler/relay/connect.go @@ -176,7 +176,7 @@ func (h *relayHandler) handleConnect(ctx context.Context, conn net.Conn, network Conn: conn, } if !h.md.noDelay { - // 缓存响应头,与第一个数据包合并发送 + // Buffer the response header, merged with the first data packet. if _, err := resp.WriteTo(&rc.wbuf); err != nil { return err } @@ -187,7 +187,7 @@ func (h *relayHandler) handleConnect(ctx context.Context, conn net.Conn, network rc := &tcpConn{ Conn: conn, } - // 缓存响应头,与第一个数据包合并发送 + // Buffer the response header, merged with the first data packet. if _, err := resp.WriteTo(&rc.wbuf); err != nil { return err } @@ -251,7 +251,7 @@ func (h *relayHandler) handleConnect(ctx context.Context, conn net.Conn, network } } - // --- 双向数据拷贝 --- + // --- Bidirectional data copy --- t := time.Now() log.Infof("%s <-> %s", conn.RemoteAddr(), address) xnet.Pipe(ctx, conn, cc) diff --git a/handler/relay/entrypoint.go b/handler/relay/entrypoint.go index bda34eea..c3372fa2 100644 --- a/handler/relay/entrypoint.go +++ b/handler/relay/entrypoint.go @@ -115,7 +115,7 @@ func (h *tcpHandler) Handle(ctx context.Context, conn net.Conn, opts ...handler. }).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr()) }() - // 从 mux 会话获取一个流 + // Get a stream from the mux session. cc, err := h.session.GetConn() if err != nil { log.Error(err) @@ -123,7 +123,7 @@ func (h *tcpHandler) Handle(ctx context.Context, conn net.Conn, opts ...handler. } defer cc.Close() - // 将入站连接地址编码为 AddrFeature,通过 relay 帧发送给客户端 + // Encode the peer address as an AddrFeature sent to the client through relay. af := &relay.AddrFeature{} af.ParseFrom(conn.RemoteAddr().String()) resp := relay.Response{ diff --git a/handler/relay/handler.go b/handler/relay/handler.go index 84c7eb45..dd6e29f2 100644 --- a/handler/relay/handler.go +++ b/handler/relay/handler.go @@ -95,14 +95,14 @@ func NewHandler(opts ...handler.Option) handler.Handler { } } -// Init 初始化 relay handler。在 handler 被注册到 service 后调用。 +// Init initialises the relay handler. Called after the handler is registered with a service. // -// 初始化流程: -// 1. 解析元数据配置(超时、嗅探、mux、MITM 等) -// 2. 如果配置了 Observer,创建 stats 统计器并启动后台轮询协程 -// 3. 如果配置了 TrafficLimiter,创建带缓存的流量限制器 -// 4. 从 Recorders 列表中选取 ServiceHandler 类型的 recorder -// 5. 如果配置了 MITM 证书,创建内存证书池 +// Initialisation flow: +// 1. Parse metadata config (timeouts, sniffing, mux, MITM, etc.) +// 2. If an Observer is configured, create a stats counter and start the background polling goroutine. +// 3. If a TrafficLimiter is configured, create a cached traffic limiter. +// 4. Pick the ServiceHandler recorder from the recorder list. +// 5. If MITM certificates are configured, create an in-memory cert pool. func (h *relayHandler) Init(md md.Metadata) (err error) { if err := h.parseMetadata(md); err != nil { return err