mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2025-10-23 16:53:25 +08:00
update register
This commit is contained in:
19
proxy/udp.go
19
proxy/udp.go
@@ -12,7 +12,6 @@ import (
|
||||
"github.com/xjasonlyu/tun2socks/core"
|
||||
"github.com/xjasonlyu/tun2socks/log"
|
||||
|
||||
D "github.com/xjasonlyu/tun2socks/component/fakedns"
|
||||
S "github.com/xjasonlyu/tun2socks/component/session"
|
||||
)
|
||||
|
||||
@@ -23,17 +22,12 @@ type udpHandler struct {
|
||||
|
||||
remoteAddrMap sync.Map
|
||||
remoteConnMap sync.Map
|
||||
|
||||
fakeDNS D.FakeDNS
|
||||
monitor S.Monitor
|
||||
}
|
||||
|
||||
func NewUDPHandler(proxyHost string, proxyPort int, timeout time.Duration, fakeDNS D.FakeDNS, monitor S.Monitor) core.UDPConnHandler {
|
||||
func NewUDPHandler(proxyHost string, proxyPort int, timeout time.Duration) core.UDPConnHandler {
|
||||
return &udpHandler{
|
||||
proxyHost: proxyHost,
|
||||
proxyPort: proxyPort,
|
||||
fakeDNS: fakeDNS,
|
||||
monitor: monitor,
|
||||
timeout: timeout,
|
||||
}
|
||||
}
|
||||
@@ -65,7 +59,7 @@ func (h *udpHandler) fetchUDPInput(conn core.UDPConn, input net.PacketConn, addr
|
||||
|
||||
func (h *udpHandler) Connect(conn core.UDPConn, target *net.UDPAddr) error {
|
||||
// Lookup fakeDNS host record
|
||||
targetHost, err := lookupHost(h.fakeDNS, target)
|
||||
targetHost, err := lookupHost(target)
|
||||
if err != nil {
|
||||
log.Warnf("lookup target host error: %v", err)
|
||||
return err
|
||||
@@ -82,7 +76,7 @@ func (h *udpHandler) Connect(conn core.UDPConn, target *net.UDPAddr) error {
|
||||
|
||||
// Get name of the process
|
||||
var process = lsof.GetProcessName(conn.LocalAddr())
|
||||
if h.monitor != nil {
|
||||
if monitor != nil {
|
||||
session := &S.Session{
|
||||
Process: process,
|
||||
Network: conn.LocalAddr().Network(),
|
||||
@@ -93,8 +87,7 @@ func (h *udpHandler) Connect(conn core.UDPConn, target *net.UDPAddr) error {
|
||||
DownloadBytes: 0,
|
||||
SessionStart: time.Now(),
|
||||
}
|
||||
h.monitor.AddSession(conn, session)
|
||||
|
||||
addSession(conn, session)
|
||||
remoteConn = &S.PacketConn{Session: session, PacketConn: remoteConn}
|
||||
}
|
||||
|
||||
@@ -152,7 +145,5 @@ func (h *udpHandler) Close(conn core.UDPConn) {
|
||||
conn.Close()
|
||||
|
||||
// Remove session
|
||||
if h.monitor != nil {
|
||||
h.monitor.RemoveSession(conn)
|
||||
}
|
||||
removeSession(conn)
|
||||
}
|
||||
|
Reference in New Issue
Block a user