Browse Source

update last commit

pull/15/head
Jason 5 years ago
parent
commit
1f9c20f6fa
  1. 2
      cmd/tun2socks/main.go
  2. 3
      cmd/tun2socks/main_socks.go
  3. 2
      cmd/tun2socks/main_stats.go
  4. 4
      common/stats/session/session.go
  5. 11
      proxy/socks/tcp.go

2
cmd/tun2socks/main.go

@ -21,8 +21,6 @@ import (
const MTU = 1500
var tcpConnections int64 = 0
var (
version = "unknown version"
description = "A tun2socks implementation written in Go."

3
cmd/tun2socks/main_socks.go

@ -17,9 +17,6 @@ func init() {
args.UdpTimeout = flag.Duration("udpTimeout", 1*time.Minute, "UDP session timeout")
registerHandlerCreator("socks", func() {
//
socks.ActiveConnections = &tcpConnections
// Verify proxy server address.
proxyAddr, err := net.ResolveTCPAddr("tcp", *args.ProxyServer)
if err != nil {

2
cmd/tun2socks/main_stats.go

@ -18,8 +18,6 @@ func init() {
session.StatsAddr = *args.StatsAddr
session.StatsVersion = version
session.ActiveConnections = &tcpConnections
sessionStater = session.NewSimpleSessionStater()
sessionStater.Start()
} else {

4
common/stats/session/session.go

@ -19,7 +19,7 @@ import (
const maxCompletedSessions = 100
var ActiveConnections *int64
var ActiveTCPConnections *int64
var (
StatsAddr = "localhost:6001"
@ -86,7 +86,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(sessions), atomic.LoadInt64(ActiveConnections))
_, _ = fmt.Fprintf(w, "<p>Active sessions %d (%d)</p>", len(sessions), atomic.LoadInt64(ActiveTCPConnections))
tablePrint(w, sessions)
_, _ = fmt.Fprintf(w, "<br/><br/>")
_, _ = fmt.Fprintf(w, "<p>Recently completed sessions %d</p>", len(s.completedSessions))

11
proxy/socks/tcp.go

@ -14,10 +14,15 @@ 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 ActiveConnections *int64
var activeTCPConnections int64
func init() {
session.ActiveTCPConnections = &activeTCPConnections
}
type tcpHandler struct {
sync.Mutex
@ -115,7 +120,7 @@ func (h *tcpHandler) relay(localConn, remoteConn net.Conn, sess *stats.Session)
}
// add -1
atomic.AddInt64(ActiveConnections, -1)
atomic.AddInt64(&activeTCPConnections, -1)
}
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)
// add 1
atomic.AddInt64(ActiveConnections, 1)
atomic.AddInt64(&activeTCPConnections, 1)
log.Access(process, "proxy", target.Network(), localConn.LocalAddr().String(), targetAddr)
return nil

Loading…
Cancel
Save