chore: cleaned up some confusing code
Some checks failed
Trigger CMFA Update / trigger-CMFA-update (push) Failing after 11s

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 {
if addr == nil && conn != nil {
return conn.RemoteDestination()
}
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 addr != nil {
if addrPort, err := netip.ParseAddrPort(addr.String()); err == nil && addrPort.Addr().IsValid() {
return addrPort.Addr().String()
}
}
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 {
if conn != nil {
metadata.RemoteDst = parseRemoteDestination(conn.RemoteAddr(), conn)
}
metadata.RemoteDst = parseRemoteDestination(conn.RemoteAddr(), conn)
t := &tcpTracker{
Conn: conn,