chore: cleaned up some confusing code

This commit is contained in:
wwqgtxx 2024-11-05 10:03:21 +08:00
parent d4478dbfa2
commit ce52c3438b

View File

@ -117,24 +117,19 @@ func (tt *tcpTracker) Upstream() any {
} }
func parseRemoteDestination(addr net.Addr, conn C.Connection) string { func parseRemoteDestination(addr net.Addr, conn C.Connection) string {
if addr == nil && conn != nil { if addr != nil {
return conn.RemoteDestination() if addrPort, err := netip.ParseAddrPort(addr.String()); err == nil && addrPort.Addr().IsValid() {
} return addrPort.Addr().String()
if addrPort, err := netip.ParseAddrPort(addr.String()); err == nil && addrPort.Addr().IsValid() {
return addrPort.Addr().String()
} else {
if conn != nil {
return conn.RemoteDestination()
} else {
return ""
} }
} }
if conn != nil {
return conn.RemoteDestination()
}
return ""
} }
func NewTCPTracker(conn C.Conn, manager *Manager, metadata *C.Metadata, rule C.Rule, uploadTotal int64, downloadTotal int64, pushToManager bool) *tcpTracker { func NewTCPTracker(conn C.Conn, manager *Manager, metadata *C.Metadata, rule C.Rule, uploadTotal int64, downloadTotal int64, pushToManager bool) *tcpTracker {
if conn != nil { metadata.RemoteDst = parseRemoteDestination(conn.RemoteAddr(), conn)
metadata.RemoteDst = parseRemoteDestination(conn.RemoteAddr(), conn)
}
t := &tcpTracker{ t := &tcpTracker{
Conn: conn, Conn: conn,