mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2025-10-07 09:41:09 +08:00
add connections track
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"net"
|
||||
"strconv"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/proxy"
|
||||
@@ -16,6 +17,8 @@ import (
|
||||
"github.com/xjasonlyu/tun2socks/core"
|
||||
)
|
||||
|
||||
var ActiveConnections *int64
|
||||
|
||||
type tcpHandler struct {
|
||||
sync.Mutex
|
||||
|
||||
@@ -110,6 +113,9 @@ func (h *tcpHandler) relay(localConn, remoteConn net.Conn, sess *stats.Session)
|
||||
if h.sessionStater != nil {
|
||||
h.sessionStater.RemoveSession(localConn)
|
||||
}
|
||||
|
||||
// add -1
|
||||
atomic.AddInt64(ActiveConnections, -1)
|
||||
}
|
||||
|
||||
func (h *tcpHandler) Handle(localConn net.Conn, target *net.TCPAddr) error {
|
||||
@@ -163,6 +169,9 @@ func (h *tcpHandler) Handle(localConn net.Conn, target *net.TCPAddr) error {
|
||||
// relay connections
|
||||
go h.relay(localConn, remoteConn, sess)
|
||||
|
||||
// add 1
|
||||
atomic.AddInt64(ActiveConnections, 1)
|
||||
|
||||
log.Access(process, "proxy", target.Network(), localConn.LocalAddr().String(), targetAddr)
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user