mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2025-10-07 01:33:15 +08:00
update last commit
This commit is contained in:
@@ -21,8 +21,6 @@ import (
|
|||||||
|
|
||||||
const MTU = 1500
|
const MTU = 1500
|
||||||
|
|
||||||
var tcpConnections int64 = 0
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
version = "unknown version"
|
version = "unknown version"
|
||||||
description = "A tun2socks implementation written in Go."
|
description = "A tun2socks implementation written in Go."
|
||||||
|
@@ -17,9 +17,6 @@ func init() {
|
|||||||
args.UdpTimeout = flag.Duration("udpTimeout", 1*time.Minute, "UDP session timeout")
|
args.UdpTimeout = flag.Duration("udpTimeout", 1*time.Minute, "UDP session timeout")
|
||||||
|
|
||||||
registerHandlerCreator("socks", func() {
|
registerHandlerCreator("socks", func() {
|
||||||
//
|
|
||||||
socks.ActiveConnections = &tcpConnections
|
|
||||||
|
|
||||||
// Verify proxy server address.
|
// Verify proxy server address.
|
||||||
proxyAddr, err := net.ResolveTCPAddr("tcp", *args.ProxyServer)
|
proxyAddr, err := net.ResolveTCPAddr("tcp", *args.ProxyServer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -18,8 +18,6 @@ func init() {
|
|||||||
session.StatsAddr = *args.StatsAddr
|
session.StatsAddr = *args.StatsAddr
|
||||||
session.StatsVersion = version
|
session.StatsVersion = version
|
||||||
|
|
||||||
session.ActiveConnections = &tcpConnections
|
|
||||||
|
|
||||||
sessionStater = session.NewSimpleSessionStater()
|
sessionStater = session.NewSimpleSessionStater()
|
||||||
sessionStater.Start()
|
sessionStater.Start()
|
||||||
} else {
|
} else {
|
||||||
|
@@ -19,7 +19,7 @@ import (
|
|||||||
|
|
||||||
const maxCompletedSessions = 100
|
const maxCompletedSessions = 100
|
||||||
|
|
||||||
var ActiveConnections *int64
|
var ActiveTCPConnections *int64
|
||||||
|
|
||||||
var (
|
var (
|
||||||
StatsAddr = "localhost:6001"
|
StatsAddr = "localhost:6001"
|
||||||
@@ -86,7 +86,7 @@ func (s *simpleSessionStater) Start() error {
|
|||||||
}</style><title>Go-tun2socks Sessions</title></head>`)
|
}</style><title>Go-tun2socks Sessions</title></head>`)
|
||||||
_, _ = fmt.Fprintf(w, "<h2>Go-tun2socks %s</h2>", StatsVersion)
|
_, _ = fmt.Fprintf(w, "<h2>Go-tun2socks %s</h2>", StatsVersion)
|
||||||
_, _ = fmt.Fprintf(w, "<h3>Now: %s ; Uptime: %s</h3>", now(), uptime())
|
_, _ = fmt.Fprintf(w, "<h3>Now: %s ; Uptime: %s</h3>", now(), uptime())
|
||||||
_, _ = fmt.Fprintf(w, "<p>Active sessions %d (%d)</p>", len(sessions), atomic.LoadInt64(ActiveConnections))
|
_, _ = fmt.Fprintf(w, "<p>Active sessions %d (%d)</p>", len(sessions), atomic.LoadInt64(ActiveTCPConnections))
|
||||||
tablePrint(w, sessions)
|
tablePrint(w, sessions)
|
||||||
_, _ = fmt.Fprintf(w, "<br/><br/>")
|
_, _ = fmt.Fprintf(w, "<br/><br/>")
|
||||||
_, _ = fmt.Fprintf(w, "<p>Recently completed sessions %d</p>", len(s.completedSessions))
|
_, _ = fmt.Fprintf(w, "<p>Recently completed sessions %d</p>", len(s.completedSessions))
|
||||||
|
@@ -14,10 +14,15 @@ import (
|
|||||||
"github.com/xjasonlyu/tun2socks/common/log"
|
"github.com/xjasonlyu/tun2socks/common/log"
|
||||||
"github.com/xjasonlyu/tun2socks/common/lsof"
|
"github.com/xjasonlyu/tun2socks/common/lsof"
|
||||||
"github.com/xjasonlyu/tun2socks/common/stats"
|
"github.com/xjasonlyu/tun2socks/common/stats"
|
||||||
|
"github.com/xjasonlyu/tun2socks/common/stats/session"
|
||||||
"github.com/xjasonlyu/tun2socks/core"
|
"github.com/xjasonlyu/tun2socks/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ActiveConnections *int64
|
var activeTCPConnections int64
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
session.ActiveTCPConnections = &activeTCPConnections
|
||||||
|
}
|
||||||
|
|
||||||
type tcpHandler struct {
|
type tcpHandler struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
@@ -115,7 +120,7 @@ func (h *tcpHandler) relay(localConn, remoteConn net.Conn, sess *stats.Session)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add -1
|
// add -1
|
||||||
atomic.AddInt64(ActiveConnections, -1)
|
atomic.AddInt64(&activeTCPConnections, -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *tcpHandler) Handle(localConn net.Conn, target *net.TCPAddr) error {
|
func (h *tcpHandler) Handle(localConn net.Conn, target *net.TCPAddr) error {
|
||||||
@@ -170,7 +175,7 @@ func (h *tcpHandler) Handle(localConn net.Conn, target *net.TCPAddr) error {
|
|||||||
go h.relay(localConn, remoteConn, sess)
|
go h.relay(localConn, remoteConn, sess)
|
||||||
|
|
||||||
// add 1
|
// add 1
|
||||||
atomic.AddInt64(ActiveConnections, 1)
|
atomic.AddInt64(&activeTCPConnections, 1)
|
||||||
|
|
||||||
log.Access(process, "proxy", target.Network(), localConn.LocalAddr().String(), targetAddr)
|
log.Access(process, "proxy", target.Network(), localConn.LocalAddr().String(), targetAddr)
|
||||||
return nil
|
return nil
|
||||||
|
Reference in New Issue
Block a user