|
@ -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() |
|
|