mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2025-10-08 10:10:12 +08:00
add utils.go to socks
This commit is contained in:
@@ -42,6 +42,9 @@ func (h *tcpHandler) relay(localConn, remoteConn net.Conn) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close
|
||||||
|
defer closeOnce()
|
||||||
|
|
||||||
// WaitGroup
|
// WaitGroup
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
@@ -56,7 +59,6 @@ func (h *tcpHandler) relay(localConn, remoteConn net.Conn) {
|
|||||||
// Down Link
|
// Down Link
|
||||||
io.Copy(localConn, remoteConn)
|
io.Copy(localConn, remoteConn)
|
||||||
tcpCloseRead(localConn)
|
tcpCloseRead(localConn)
|
||||||
defer closeOnce()
|
|
||||||
|
|
||||||
wg.Wait() // Wait for Up Link done
|
wg.Wait() // Wait for Up Link done
|
||||||
|
|
||||||
@@ -120,17 +122,3 @@ func (h *tcpHandler) Handle(localConn net.Conn, target *net.TCPAddr) error {
|
|||||||
log.Access(process, "proxy", target.Network(), localConn.LocalAddr().String(), targetAddr)
|
log.Access(process, "proxy", target.Network(), localConn.LocalAddr().String(), targetAddr)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func tcpKeepAlive(conn net.Conn) {
|
|
||||||
if tcp, ok := conn.(*net.TCPConn); ok {
|
|
||||||
tcp.SetKeepAlive(true)
|
|
||||||
tcp.SetKeepAlivePeriod(30 * time.Second)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func tcpCloseRead(conn net.Conn) {
|
|
||||||
if c, ok := conn.(interface{ CloseRead() error }); ok {
|
|
||||||
log.Warnf("ok!")
|
|
||||||
c.CloseRead()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
28
proxy/socks/utils.go
Normal file
28
proxy/socks/utils.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package socks
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/xjasonlyu/tun2socks/common/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
type duplexConn interface {
|
||||||
|
net.Conn
|
||||||
|
CloseRead() error
|
||||||
|
CloseWrite() error
|
||||||
|
}
|
||||||
|
|
||||||
|
func tcpCloseRead(conn net.Conn) {
|
||||||
|
if c, ok := conn.(duplexConn); ok {
|
||||||
|
log.Warnf("ok!----")
|
||||||
|
c.CloseRead()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func tcpKeepAlive(conn net.Conn) {
|
||||||
|
if tcp, ok := conn.(*net.TCPConn); ok {
|
||||||
|
tcp.SetKeepAlive(true)
|
||||||
|
tcp.SetKeepAlivePeriod(30 * time.Second)
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user