mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2025-10-17 06:10:49 +08:00
31
proxy/tcp.go
31
proxy/tcp.go
@@ -94,16 +94,22 @@ func (h *tcpHandler) Handle(conn net.Conn, target *net.TCPAddr) error {
|
||||
return err
|
||||
}
|
||||
|
||||
var session = &S.Session{
|
||||
Network: localConn.LocalAddr().Network(),
|
||||
DialerAddr: remoteConn.LocalAddr().String(),
|
||||
ClientAddr: localConn.LocalAddr().String(),
|
||||
TargetAddr: targetAddr,
|
||||
UploadBytes: 0,
|
||||
DownloadBytes: 0,
|
||||
SessionStart: time.Now(),
|
||||
// Get name of the process
|
||||
var process = lsof.GetProcessName(localConn.LocalAddr())
|
||||
if monitor != nil {
|
||||
session := &S.Session{
|
||||
Process: process,
|
||||
Network: localConn.LocalAddr().Network(),
|
||||
DialerAddr: remoteConn.LocalAddr().String(),
|
||||
ClientAddr: localConn.LocalAddr().String(),
|
||||
TargetAddr: targetAddr,
|
||||
UploadBytes: 0,
|
||||
DownloadBytes: 0,
|
||||
SessionStart: time.Now(),
|
||||
}
|
||||
addSession(localConn, session)
|
||||
remoteConn = &S.Conn{Session: session, Conn: remoteConn}
|
||||
}
|
||||
remoteConn = &S.Conn{Session: session, Conn: remoteConn}
|
||||
|
||||
// Set keepalive
|
||||
tcpKeepAlive(localConn)
|
||||
@@ -112,13 +118,6 @@ func (h *tcpHandler) Handle(conn net.Conn, target *net.TCPAddr) error {
|
||||
// Relay connections
|
||||
go h.relay(localConn, remoteConn)
|
||||
|
||||
// Get name of the process
|
||||
var process = lsof.GetProcessName(localConn.LocalAddr())
|
||||
if monitor != nil {
|
||||
session.Process = process
|
||||
addSession(localConn, session)
|
||||
}
|
||||
|
||||
log.Access(process, "proxy", "tcp", localConn.LocalAddr().String(), targetAddr)
|
||||
return nil
|
||||
}
|
||||
|
37
proxy/udp.go
37
proxy/udp.go
@@ -2,12 +2,12 @@ package proxy
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/xjasonlyu/tun2socks/common/lsof"
|
||||
"net"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/xjasonlyu/tun2socks/common/lsof"
|
||||
"github.com/xjasonlyu/tun2socks/common/pool"
|
||||
"github.com/xjasonlyu/tun2socks/core"
|
||||
"github.com/xjasonlyu/tun2socks/log"
|
||||
@@ -78,16 +78,22 @@ func (h *udpHandler) Connect(conn core.UDPConn, target *net.UDPAddr) error {
|
||||
return err
|
||||
}
|
||||
|
||||
var session = &S.Session{
|
||||
Network: conn.LocalAddr().Network(),
|
||||
DialerAddr: remoteConn.LocalAddr().String(),
|
||||
ClientAddr: conn.LocalAddr().String(),
|
||||
TargetAddr: targetAddr,
|
||||
UploadBytes: 0,
|
||||
DownloadBytes: 0,
|
||||
SessionStart: time.Now(),
|
||||
// Get name of the process
|
||||
var process = lsof.GetProcessName(conn.LocalAddr())
|
||||
if monitor != nil {
|
||||
session := &S.Session{
|
||||
Process: process,
|
||||
Network: conn.LocalAddr().Network(),
|
||||
DialerAddr: remoteConn.LocalAddr().String(),
|
||||
ClientAddr: conn.LocalAddr().String(),
|
||||
TargetAddr: targetAddr,
|
||||
UploadBytes: 0,
|
||||
DownloadBytes: 0,
|
||||
SessionStart: time.Now(),
|
||||
}
|
||||
addSession(conn, session)
|
||||
remoteConn = &S.PacketConn{Session: session, PacketConn: remoteConn}
|
||||
}
|
||||
remoteConn = &S.PacketConn{Session: session, PacketConn: remoteConn}
|
||||
|
||||
h.remoteMap.Store(conn, &udpElement{
|
||||
remoteAddr: remoteAddr,
|
||||
@@ -96,16 +102,7 @@ func (h *udpHandler) Connect(conn core.UDPConn, target *net.UDPAddr) error {
|
||||
|
||||
go h.fetchUDPInput(conn, remoteConn, target)
|
||||
|
||||
go func() {
|
||||
// Get name of the process
|
||||
var process = lsof.GetProcessName(conn.LocalAddr())
|
||||
if monitor != nil {
|
||||
session.Process = process
|
||||
addSession(conn, session)
|
||||
}
|
||||
log.Access(process, "proxy", "udp", conn.LocalAddr().String(), targetAddr)
|
||||
}()
|
||||
|
||||
log.Access(process, "proxy", "udp", conn.LocalAddr().String(), targetAddr)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user