From 067c02aba154ce86fea0ab9041f258c204efc748 Mon Sep 17 00:00:00 2001 From: Skyxim Date: Sat, 28 May 2022 20:00:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B0=83=E6=95=B4=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E8=BF=9C=E7=A8=8B=E7=9B=AE=E7=9A=84=E7=9A=84=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adapter/outbound/base.go | 11 +---------- tunnel/statistic/tracker.go | 8 +++++++- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/adapter/outbound/base.go b/adapter/outbound/base.go index 140a3546..0d86c2da 100644 --- a/adapter/outbound/base.go +++ b/adapter/outbound/base.go @@ -148,16 +148,7 @@ func (c *conn) AppendToChains(a C.ProxyAdapter) { } func NewConn(c net.Conn, a C.ProxyAdapter) C.Conn { - var remoteDestination string - if c != nil { - if tcpAddr, ok := c.RemoteAddr().(*net.TCPAddr); ok { - remoteDestination = tcpAddr.IP.String() - } else { - remoteDestination = parseRemoteDestination(a.Addr()) - } - } - - return &conn{c, []string{a.Name()}, remoteDestination} + return &conn{c, []string{a.Name()}, parseRemoteDestination(a.Addr())} } type packetConn struct { diff --git a/tunnel/statistic/tracker.go b/tunnel/statistic/tracker.go index d176bae7..fc627297 100644 --- a/tunnel/statistic/tracker.go +++ b/tunnel/statistic/tracker.go @@ -59,7 +59,13 @@ func (tt *tcpTracker) Close() error { func NewTCPTracker(conn C.Conn, manager *Manager, metadata *C.Metadata, rule C.Rule) *tcpTracker { uuid, _ := uuid.NewV4() - metadata.RemoteDst = conn.RemoteDestination() + if conn != nil { + if tcpAddr, ok := conn.RemoteAddr().(*net.TCPAddr); ok { + metadata.RemoteDst = tcpAddr.IP.String() + } else { + metadata.RemoteDst = conn.RemoteDestination() + } + } t := &tcpTracker{ Conn: conn,