refactor: 获取远程目的从tunnel中剔除,移至tracker
This commit is contained in:
@ -59,6 +59,7 @@ 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()
|
||||
|
||||
t := &tcpTracker{
|
||||
Conn: conn,
|
||||
@ -116,6 +117,7 @@ func (ut *udpTracker) Close() error {
|
||||
|
||||
func NewUDPTracker(conn C.PacketConn, manager *Manager, metadata *C.Metadata, rule C.Rule) *udpTracker {
|
||||
uuid, _ := uuid.NewV4()
|
||||
metadata.RemoteDst = conn.RemoteDestination()
|
||||
|
||||
ut := &udpTracker{
|
||||
PacketConn: conn,
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@ -288,15 +287,6 @@ func handleUDPConn(packet *inbound.PacketAdapter) {
|
||||
}
|
||||
pCtx.InjectPacketConn(rawPc)
|
||||
|
||||
addr := rawPc.RemoteDestination()
|
||||
if dst, _, err := net.SplitHostPort(addr); err == nil {
|
||||
metadata.RemoteDst = dst
|
||||
} else {
|
||||
if addrError, ok := err.(*net.AddrError); ok && strings.Contains(addrError.Err, "missing port") {
|
||||
metadata.RemoteDst = addr
|
||||
}
|
||||
}
|
||||
|
||||
pc := statistic.NewUDPTracker(rawPc, statistic.DefaultManager, metadata, rule)
|
||||
|
||||
switch true {
|
||||
@ -359,10 +349,6 @@ func handleTCPConn(connCtx C.ConnContext) {
|
||||
return
|
||||
}
|
||||
|
||||
if tcpAddr, ok := remoteConn.RemoteAddr().(*net.TCPAddr); ok {
|
||||
metadata.RemoteDst = tcpAddr.IP.String()
|
||||
}
|
||||
|
||||
remoteConn = statistic.NewTCPTracker(remoteConn, statistic.DefaultManager, metadata, rule)
|
||||
defer func(remoteConn C.Conn) {
|
||||
_ = remoteConn.Close()
|
||||
|
Reference in New Issue
Block a user