Browse Source

remove activeConnections

pull/15/head
Jason 5 years ago
parent
commit
b8614dddd3
  1. 4
      common/stats/session/session.go
  2. 14
      proxy/socks/tcp.go

4
common/stats/session/session.go

@ -19,8 +19,6 @@ import (
const maxCompletedSessions = 100
var ActiveTCPConnections *int64
var (
StatsAddr = "localhost:6001"
StatsPath = "/stats/session/plain"
@ -97,7 +95,7 @@ func (s *simpleSessionStater) Start() error {
}</style><title>Go-tun2socks Sessions</title></head>`)
_, _ = fmt.Fprintf(w, "<h2>Go-tun2socks %s</h2>", StatsVersion)
_, _ = fmt.Fprintf(w, "<h3>Now: %s ; Uptime: %s</h3>", now(), uptime())
_, _ = fmt.Fprintf(w, "<p>Active sessions %d (%d)</p>", len(activeSessions), atomic.LoadInt64(ActiveTCPConnections))
_, _ = fmt.Fprintf(w, "<p>Active sessions %d</p>", len(activeSessions))
tablePrint(w, activeSessions)
_, _ = fmt.Fprintf(w, "<br/><br/>")
_, _ = fmt.Fprintf(w, "<p>Recently completed sessions %d</p>", len(s.completedSessions))

14
proxy/socks/tcp.go

@ -5,7 +5,6 @@ import (
"net"
"strconv"
"sync"
"sync/atomic"
"time"
"golang.org/x/net/proxy"
@ -14,16 +13,9 @@ import (
"github.com/xjasonlyu/tun2socks/common/log"
"github.com/xjasonlyu/tun2socks/common/lsof"
"github.com/xjasonlyu/tun2socks/common/stats"
"github.com/xjasonlyu/tun2socks/common/stats/session"
"github.com/xjasonlyu/tun2socks/core"
)
var activeTCPConnections int64
func init() {
session.ActiveTCPConnections = &activeTCPConnections
}
type tcpHandler struct {
sync.Mutex
@ -65,9 +57,6 @@ func (h *tcpHandler) relay(localConn, remoteConn net.Conn) {
<-upCh // Wait for UpLink done.
// add -1
atomic.AddInt64(&activeTCPConnections, -1)
if h.sessionStater != nil {
h.sessionStater.RemoveSession(localConn)
}
@ -126,9 +115,6 @@ func (h *tcpHandler) Handle(localConn net.Conn, target *net.TCPAddr) error {
// relay connections
go h.relay(localConn, remoteConn)
// add 1
atomic.AddInt64(&activeTCPConnections, 1)
log.Access(process, "proxy", target.Network(), localConn.LocalAddr().String(), targetAddr)
return nil
}

Loading…
Cancel
Save