Skip to content

Commit

Permalink
chore: cleaned up some confusing code
Browse files Browse the repository at this point in the history
  • Loading branch information
wwqgtxx committed Nov 5, 2024
1 parent d4478db commit ce52c34
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions tunnel/statistic/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ce52c34

Please sign in to comment.