mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2025-10-07 09:41:09 +08:00
update
This commit is contained in:
@@ -16,7 +16,7 @@ import (
|
||||
"github.com/xjasonlyu/tun2socks/common/stats"
|
||||
"github.com/xjasonlyu/tun2socks/core"
|
||||
"github.com/xjasonlyu/tun2socks/filter"
|
||||
"github.com/xjasonlyu/tun2socks/proxy/socks"
|
||||
"github.com/xjasonlyu/tun2socks/proxy"
|
||||
"github.com/xjasonlyu/tun2socks/tun"
|
||||
|
||||
// init logger
|
||||
@@ -149,8 +149,8 @@ func main() {
|
||||
}
|
||||
proxyHost := proxyAddr.IP.String()
|
||||
proxyPort := uint16(proxyAddr.Port)
|
||||
core.RegisterTCPConnHandler(socks.NewTCPHandler(proxyHost, proxyPort, fakeDns, sessionStater))
|
||||
core.RegisterUDPConnHandler(socks.NewUDPHandler(proxyHost, proxyPort, *args.UdpTimeout, fakeDns, sessionStater))
|
||||
core.RegisterTCPConnHandler(proxy.NewTCPHandler(proxyHost, proxyPort, fakeDns, sessionStater))
|
||||
core.RegisterUDPConnHandler(proxy.NewUDPHandler(proxyHost, proxyPort, *args.UdpTimeout, fakeDns, sessionStater))
|
||||
|
||||
// Register an output callback to write packets output from lwip stack to tun
|
||||
// device, output function should be set before input any packets.
|
||||
|
@@ -1,7 +1,7 @@
|
||||
// Code in this file are grabbed from https://github.com/nadoo/glider, which
|
||||
// is also referencing another repo: https://github.com/shadowsocks/go-shadowsocks2
|
||||
|
||||
package socks
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"errors"
|
@@ -1,4 +1,4 @@
|
||||
package socks
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"net"
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"github.com/xjasonlyu/tun2socks/common/lsof"
|
||||
"github.com/xjasonlyu/tun2socks/common/stats"
|
||||
"github.com/xjasonlyu/tun2socks/core"
|
||||
. "github.com/xjasonlyu/tun2socks/proxy"
|
||||
)
|
||||
|
||||
type tcpHandler struct {
|
||||
@@ -71,12 +70,12 @@ func (h *tcpHandler) Handle(localConn net.Conn, target *net.TCPAddr) error {
|
||||
}
|
||||
|
||||
// set keepalive
|
||||
TCPKeepAlive(localConn)
|
||||
TCPKeepAlive(remoteConn)
|
||||
tcpKeepAlive(localConn)
|
||||
tcpKeepAlive(remoteConn)
|
||||
|
||||
go func() {
|
||||
// relay connections
|
||||
TCPRelay(localConn, remoteConn)
|
||||
tcpRelay(localConn, remoteConn)
|
||||
|
||||
// remove session
|
||||
if h.sessionStater != nil {
|
@@ -1,4 +1,4 @@
|
||||
package socks
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"bytes"
|
@@ -15,26 +15,26 @@ type duplexConn interface {
|
||||
CloseWrite() error
|
||||
}
|
||||
|
||||
func TCPCloseRead(conn net.Conn) {
|
||||
func tcpCloseRead(conn net.Conn) {
|
||||
if c, ok := conn.(duplexConn); ok {
|
||||
c.CloseRead()
|
||||
}
|
||||
}
|
||||
|
||||
func TCPCloseWrite(conn net.Conn) {
|
||||
func tcpCloseWrite(conn net.Conn) {
|
||||
if c, ok := conn.(duplexConn); ok {
|
||||
c.CloseWrite()
|
||||
}
|
||||
}
|
||||
|
||||
func TCPKeepAlive(conn net.Conn) {
|
||||
func tcpKeepAlive(conn net.Conn) {
|
||||
if tcp, ok := conn.(*net.TCPConn); ok {
|
||||
tcp.SetKeepAlive(true)
|
||||
tcp.SetKeepAlivePeriod(30 * time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
func TCPRelay(localConn, remoteConn net.Conn) {
|
||||
func tcpRelay(localConn, remoteConn net.Conn) {
|
||||
var once sync.Once
|
||||
closeOnce := func() {
|
||||
once.Do(func() {
|
||||
@@ -59,7 +59,7 @@ func TCPRelay(localConn, remoteConn net.Conn) {
|
||||
} else {
|
||||
localConn.SetDeadline(time.Now())
|
||||
remoteConn.SetDeadline(time.Now())
|
||||
TCPCloseRead(remoteConn)
|
||||
tcpCloseRead(remoteConn)
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
@@ -71,7 +71,7 @@ func TCPRelay(localConn, remoteConn net.Conn) {
|
||||
} else {
|
||||
localConn.SetDeadline(time.Now())
|
||||
remoteConn.SetDeadline(time.Now())
|
||||
TCPCloseRead(localConn)
|
||||
tcpCloseRead(localConn)
|
||||
}
|
||||
pool.BufPool.Put(buf[:cap(buf)])
|
||||
|
Reference in New Issue
Block a user