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.
This commit is contained in:
@@ -136,7 +136,7 @@ func (h *relayHandler) bindTCP(ctx context.Context, conn net.Conn, network, addr
|
|||||||
lc := xnet.ListenConfig{
|
lc := xnet.ListenConfig{
|
||||||
Netns: h.options.Netns,
|
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 {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
resp.Status = relay.StatusServiceUnavailable
|
resp.Status = relay.StatusServiceUnavailable
|
||||||
@@ -214,7 +214,7 @@ func (h *relayHandler) bindTCP(ctx context.Context, conn net.Conn, network, addr
|
|||||||
log.Error(err)
|
log.Error(err)
|
||||||
return
|
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())
|
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).
|
r := udp.NewRelay(relay_util.UDPTunServerConn(conn), pc).
|
||||||
WithService(h.options.Service).
|
WithService(h.options.Service).
|
||||||
WithBypass(h.options.Bypass).
|
WithBypass(h.options.Bypass).
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ func (c *tcpConn) Read(b []byte) (n int, err error) {
|
|||||||
func (c *tcpConn) Write(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
|
n = len(b) // always return len(b), not actual bytes written
|
||||||
if c.wbuf.Len() > 0 {
|
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)
|
_, err = c.wbuf.WriteTo(c.Conn)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ func (h *relayHandler) handleConnect(ctx context.Context, conn net.Conn, network
|
|||||||
Conn: conn,
|
Conn: conn,
|
||||||
}
|
}
|
||||||
if !h.md.noDelay {
|
if !h.md.noDelay {
|
||||||
// 缓存响应头,与第一个数据包合并发送
|
// Buffer the response header, merged with the first data packet.
|
||||||
if _, err := resp.WriteTo(&rc.wbuf); err != nil {
|
if _, err := resp.WriteTo(&rc.wbuf); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -187,7 +187,7 @@ func (h *relayHandler) handleConnect(ctx context.Context, conn net.Conn, network
|
|||||||
rc := &tcpConn{
|
rc := &tcpConn{
|
||||||
Conn: conn,
|
Conn: conn,
|
||||||
}
|
}
|
||||||
// 缓存响应头,与第一个数据包合并发送
|
// Buffer the response header, merged with the first data packet.
|
||||||
if _, err := resp.WriteTo(&rc.wbuf); err != nil {
|
if _, err := resp.WriteTo(&rc.wbuf); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -251,7 +251,7 @@ func (h *relayHandler) handleConnect(ctx context.Context, conn net.Conn, network
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- 双向数据拷贝 ---
|
// --- Bidirectional data copy ---
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Infof("%s <-> %s", conn.RemoteAddr(), address)
|
log.Infof("%s <-> %s", conn.RemoteAddr(), address)
|
||||||
xnet.Pipe(ctx, conn, cc)
|
xnet.Pipe(ctx, conn, cc)
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ func (h *tcpHandler) Handle(ctx context.Context, conn net.Conn, opts ...handler.
|
|||||||
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
}).Infof("%s >< %s", conn.RemoteAddr(), conn.LocalAddr())
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// 从 mux 会话获取一个流
|
// Get a stream from the mux session.
|
||||||
cc, err := h.session.GetConn()
|
cc, err := h.session.GetConn()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
@@ -123,7 +123,7 @@ func (h *tcpHandler) Handle(ctx context.Context, conn net.Conn, opts ...handler.
|
|||||||
}
|
}
|
||||||
defer cc.Close()
|
defer cc.Close()
|
||||||
|
|
||||||
// 将入站连接地址编码为 AddrFeature,通过 relay 帧发送给客户端
|
// Encode the peer address as an AddrFeature sent to the client through relay.
|
||||||
af := &relay.AddrFeature{}
|
af := &relay.AddrFeature{}
|
||||||
af.ParseFrom(conn.RemoteAddr().String())
|
af.ParseFrom(conn.RemoteAddr().String())
|
||||||
resp := relay.Response{
|
resp := relay.Response{
|
||||||
|
|||||||
@@ -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.
|
||||||
//
|
//
|
||||||
// 初始化流程:
|
// Initialisation flow:
|
||||||
// 1. 解析元数据配置(超时、嗅探、mux、MITM 等)
|
// 1. Parse metadata config (timeouts, sniffing, mux, MITM, etc.)
|
||||||
// 2. 如果配置了 Observer,创建 stats 统计器并启动后台轮询协程
|
// 2. If an Observer is configured, create a stats counter and start the background polling goroutine.
|
||||||
// 3. 如果配置了 TrafficLimiter,创建带缓存的流量限制器
|
// 3. If a TrafficLimiter is configured, create a cached traffic limiter.
|
||||||
// 4. 从 Recorders 列表中选取 ServiceHandler 类型的 recorder
|
// 4. Pick the ServiceHandler recorder from the recorder list.
|
||||||
// 5. 如果配置了 MITM 证书,创建内存证书池
|
// 5. If MITM certificates are configured, create an in-memory cert pool.
|
||||||
func (h *relayHandler) Init(md md.Metadata) (err error) {
|
func (h *relayHandler) Init(md md.Metadata) (err error) {
|
||||||
if err := h.parseMetadata(md); err != nil {
|
if err := h.parseMetadata(md); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user