Просмотр исходного кода

Use atomic.Int64 and format log as single line

- Replace int64 field with atomic.Int64 type directly
- Use Load() and Store() methods instead of atomic functions
- Format log warning as single line for better readability

Co-authored-by: Fangliding <[email protected]>
copilot-swe-agent[bot] 5 месяцев назад
Родитель
Сommit
c539be7fd1
1 измененных файлов с 4 добавлено и 10 удалено
  1. 4 10
      proxy/tun/handler.go

+ 4 - 10
proxy/tun/handler.go

@@ -29,7 +29,7 @@ import (
 )
 
 type udpConn struct {
-	lastActive int64
+	lastActive atomic.Int64
 	reader     buf.Reader
 	writer     buf.Writer
 	done       *done.Instance
@@ -68,7 +68,7 @@ func (t *Handler) cleanupUDP() error {
 	}
 	now := time.Now().Unix()
 	for src, conn := range t.udpConns {
-		if now-atomic.LoadInt64(&conn.lastActive) > 300 {
+		if now-conn.lastActive.Load() > 300 {
 			conn.cancel()
 			common.Must(conn.done.Close())
 			common.Must(common.Close(conn.writer))
@@ -124,7 +124,7 @@ func (t *Handler) HandleUDPPacket(id stack.TransportEndpointID, pkt *stack.Packe
 			t.dispatcher.DispatchLink(ctx, dest, link)
 		}()
 	} else {
-		atomic.StoreInt64(&conn.lastActive, time.Now().Unix())
+		conn.lastActive.Store(time.Now().Unix())
 		t.Unlock()
 	}
 
@@ -145,13 +145,7 @@ func (w *udpWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
 		// Validate return packet address matches expected destination
 		if b.UDP != nil {
 			if b.UDP.Address != w.dest.Address || b.UDP.Port != w.dest.Port {
-				errors.LogWarning(
-					context.Background(),
-					"UDP return packet address mismatch: expected ",
-					w.dest,
-					", got ",
-					b.UDP,
-				)
+				errors.LogWarning(context.Background(), "UDP return packet address mismatch: expected ", w.dest, ", got ", b.UDP)
 				b.Release()
 				continue
 			}