Browse Source

debug only

pull/15/head
Jason 5 years ago
parent
commit
a0c52c0d37
  1. 8
      common/stats/stats.go
  2. 1
      proxy/socks/tcp.go

8
common/stats/stats.go

@ -4,6 +4,8 @@ import (
"net" "net"
"sync/atomic" "sync/atomic"
"time" "time"
"github.com/xjasonlyu/tun2socks/common/log"
) )
type SessionStater interface { type SessionStater interface {
@ -26,6 +28,7 @@ type Session struct {
SessionClose time.Time SessionClose time.Time
} }
// Track SessionConn
type SessionConn struct { type SessionConn struct {
net.Conn net.Conn
*Session *Session
@ -55,12 +58,15 @@ func (c *SessionConn) Write(b []byte) (n int, err error) {
} }
func (c *SessionConn) Close() error { func (c *SessionConn) Close() error {
log.Warnf("sessionConn close")
if c.SessionClose.IsZero() { if c.SessionClose.IsZero() {
log.Warnf("set close time")
c.SessionClose = time.Now() c.SessionClose = time.Now()
} }
return c.Conn.Close() return c.Conn.Close()
} }
// Track SessionPacketConn
type SessionPacketConn struct { type SessionPacketConn struct {
net.PacketConn net.PacketConn
*Session *Session
@ -90,7 +96,9 @@ func (c *SessionPacketConn) WriteTo(b []byte, addr net.Addr) (n int, err error)
} }
func (c *SessionPacketConn) Close() error { func (c *SessionPacketConn) Close() error {
log.Warnf("sessionConn close")
if c.SessionClose.IsZero() { if c.SessionClose.IsZero() {
log.Warnf("set close time")
c.SessionClose = time.Now() c.SessionClose = time.Now()
} }
return c.PacketConn.Close() return c.PacketConn.Close()

1
proxy/socks/tcp.go

@ -40,6 +40,7 @@ func (h *tcpHandler) relay(localConn, remoteConn net.Conn) {
// Close // Close
defer func() { defer func() {
log.Warnf("relay close")
localConn.Close() localConn.Close()
remoteConn.Close() remoteConn.Close()
}() }()

Loading…
Cancel
Save