diff --git a/common/stats/session/session.go b/common/stats/session/session.go index 10fb514..3c11967 100644 --- a/common/stats/session/session.go +++ b/common/stats/session/session.go @@ -56,17 +56,18 @@ func (s *simpleSessionStater) Start() error { }) _, _ = fmt.Fprintf(w, "") - _, _ = fmt.Fprintf(w, "") + _, _ = fmt.Fprintf(w, "") sort.Slice(sessions, func(i, j int) bool { return sessions[i].SessionStart.After(sessions[j].SessionStart) }) for _, sess := range sessions { - _, _ = fmt.Fprintf(w, "", + _, _ = fmt.Fprintf(w, "", sess.ProcessName, sess.Network, time.Now().Sub(sess.SessionStart).Round(time.Second), - sess.LocalAddr, - sess.RemoteAddr, + sess.DialerAddr, + sess.ClientAddr, + sess.TargetAddr, p.Sprintf("%d", atomic.LoadInt64(&sess.UploadBytes)), p.Sprintf("%d", atomic.LoadInt64(&sess.DownloadBytes)), ) diff --git a/common/stats/stats.go b/common/stats/stats.go index a7d1ac3..e2c44a1 100644 --- a/common/stats/stats.go +++ b/common/stats/stats.go @@ -16,8 +16,9 @@ type SessionStater interface { type Session struct { ProcessName string Network string - LocalAddr string - RemoteAddr string + DialerAddr string + ClientAddr string + TargetAddr string UploadBytes int64 DownloadBytes int64 SessionStart time.Time diff --git a/proxy/socks/tcp.go b/proxy/socks/tcp.go index 5256c98..2cb4e56 100644 --- a/proxy/socks/tcp.go +++ b/proxy/socks/tcp.go @@ -86,7 +86,7 @@ func (h *tcpHandler) relay(localConn, remoteConn net.Conn, sess *stats.Session) remoteConn.Close() }() - // Uplink + // UpLink go func() { var err error if h.sessionStater != nil && sess != nil { @@ -98,7 +98,7 @@ func (h *tcpHandler) relay(localConn, remoteConn net.Conn, sess *stats.Session) upCh <- err }() - // Downlink + // DownLink if h.sessionStater != nil && sess != nil { statsCopy(localConn, remoteConn, sess, dirDownlink) } else { @@ -147,8 +147,9 @@ func (h *tcpHandler) Handle(localConn net.Conn, target *net.TCPAddr) error { sess = &stats.Session{ ProcessName: process, Network: target.Network(), - LocalAddr: localConn.LocalAddr().String(), - RemoteAddr: targetAddr, + DialerAddr: remoteConn.LocalAddr().String(), + ClientAddr: localConn.LocalAddr().String(), + TargetAddr: targetAddr, UploadBytes: 0, DownloadBytes: 0, SessionStart: time.Now(), diff --git a/proxy/socks/udp.go b/proxy/socks/udp.go index f454f71..8cdb30d 100644 --- a/proxy/socks/udp.go +++ b/proxy/socks/udp.go @@ -118,31 +118,31 @@ func (h *udpHandler) Connect(conn core.UDPConn, target *net.UDPAddr) error { } func (h *udpHandler) connectInternal(conn core.UDPConn, targetAddr string) error { - c, err := net.DialTimeout("tcp", core.ParseTCPAddr(h.proxyHost, h.proxyPort).String(), 4*time.Second) + remoteConn, err := net.DialTimeout("tcp", core.ParseTCPAddr(h.proxyHost, h.proxyPort).String(), 4*time.Second) if err != nil { return err } - _ = c.SetDeadline(time.Now().Add(4 * time.Second)) + _ = remoteConn.SetDeadline(time.Now().Add(4 * time.Second)) // send VER, NMETHODS, METHODS - _, _ = c.Write([]byte{5, 1, 0}) + _, _ = remoteConn.Write([]byte{5, 1, 0}) buf := make([]byte, MaxAddrLen) // read VER METHOD - if _, err := io.ReadFull(c, buf[:2]); err != nil { + if _, err := io.ReadFull(remoteConn, buf[:2]); err != nil { return err } if len(targetAddr) != 0 { targetAddr := ParseAddr(targetAddr) // write VER CMD RSV ATYP DST.ADDR DST.PORT - _, _ = c.Write(append([]byte{5, socks5UDPAssociate, 0}, targetAddr...)) + _, _ = remoteConn.Write(append([]byte{5, socks5UDPAssociate, 0}, targetAddr...)) } else { - _, _ = c.Write(append([]byte{5, socks5UDPAssociate, 0}, []byte{1, 0, 0, 0, 0, 0, 0}...)) + _, _ = remoteConn.Write(append([]byte{5, socks5UDPAssociate, 0}, []byte{1, 0, 0, 0, 0, 0, 0}...)) } // read VER REP RSV ATYP BND.ADDR BND.PORT - if _, err := io.ReadFull(c, buf[:3]); err != nil { + if _, err := io.ReadFull(remoteConn, buf[:3]); err != nil { return err } @@ -151,7 +151,7 @@ func (h *udpHandler) connectInternal(conn core.UDPConn, targetAddr string) error return errors.New("SOCKS handshake failed") } - remoteAddr, err := readAddr(c, buf) + remoteAddr, err := readAddr(remoteConn, buf) if err != nil { return err } @@ -161,20 +161,20 @@ func (h *udpHandler) connectInternal(conn core.UDPConn, targetAddr string) error return errors.New("failed to resolve remote address") } - go h.handleTCP(conn, c) + go h.handleTCP(conn, remoteConn) - pc, err := net.ListenPacket("udp", "") + remoteUDPConn, err := net.ListenPacket("udp", "") if err != nil { return err } h.Lock() - h.tcpConns[conn] = c - h.udpConns[conn] = pc + h.tcpConns[conn] = remoteConn + h.udpConns[conn] = remoteUDPConn h.remoteAddrs[conn] = resolvedRemoteAddr h.Unlock() - go h.fetchUDPInput(conn, pc) + go h.fetchUDPInput(conn, remoteUDPConn) if len(targetAddr) != 0 { var process string @@ -190,8 +190,9 @@ func (h *udpHandler) connectInternal(conn core.UDPConn, targetAddr string) error sess := &stats.Session{ ProcessName: process, Network: conn.LocalAddr().Network(), - LocalAddr: conn.LocalAddr().String(), - RemoteAddr: targetAddr, + DialerAddr: remoteConn.LocalAddr().String(), + ClientAddr: conn.LocalAddr().String(), + TargetAddr: targetAddr, UploadBytes: 0, DownloadBytes: 0, SessionStart: time.Now(),
Process NameNetworkDurationLocal AddrRemote AddrUpload BytesDownload Bytes
Process NameNetworkDurationDialer AddrClient AddrTarget AddrUpload BytesDownload Bytes
%v%v%v%v%v%v%v
%v%v%v%v%v%v%v%v