From 1b2f01f0f4302f42d0a9cbef0f6840286ac3b8e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Fri, 8 Oct 2021 15:50:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=8Atcp/udp=E7=9A=84=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E6=95=B0=E8=AE=B0=E4=B8=BA=E8=AE=BF=E9=97=AE=E9=87=8F=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0tcp=E5=9F=9F=E5=90=8D=E6=8E=92=E5=90=8D?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=EF=BC=88=E9=9C=80=E8=A6=81SNI=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/listener_tcp.go | 18 ++++++++++++++++++ internal/nodes/listener_udp.go | 4 ++++ internal/stats/traffic_stat_manager.go | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/internal/nodes/listener_tcp.go b/internal/nodes/listener_tcp.go index 38eeeed..ba2c46f 100644 --- a/internal/nodes/listener_tcp.go +++ b/internal/nodes/listener_tcp.go @@ -55,6 +55,24 @@ func (this *TCPListener) handleConn(conn net.Conn) error { if firstServer.ReverseProxy == nil { return errors.New("no ReverseProxy configured for the server") } + + // 记录域名排行 + tlsConn, ok := conn.(*tls.Conn) + var recordStat = false + if ok { + var serverName = tlsConn.ConnectionState().ServerName + if len(serverName) > 0 { + // 统计 + stats.SharedTrafficStatManager.Add(firstServer.Id, serverName, 0, 0, 1, 0, 0, 0) + recordStat = true + } + } + + // 统计 + if !recordStat { + stats.SharedTrafficStatManager.Add(firstServer.Id, "", 0, 0, 1, 0, 0, 0) + } + originConn, err := this.connectOrigin(firstServer.ReverseProxy, conn.RemoteAddr().String()) if err != nil { return err diff --git a/internal/nodes/listener_udp.go b/internal/nodes/listener_udp.go index 1c00a30..2644e7b 100644 --- a/internal/nodes/listener_udp.go +++ b/internal/nodes/listener_udp.go @@ -147,6 +147,10 @@ func NewUDPConn(serverId int64, addr net.Addr, proxyConn *net.UDPConn, serverCon activatedAt: time.Now().Unix(), isOk: true, } + + // 统计 + stats.SharedTrafficStatManager.Add(serverId, "", 0, 0, 1, 0, 0, 0) + go func() { buffer := bytePool32k.Get() defer func() { diff --git a/internal/stats/traffic_stat_manager.go b/internal/stats/traffic_stat_manager.go index 26fe2c4..dfdedc2 100644 --- a/internal/stats/traffic_stat_manager.go +++ b/internal/stats/traffic_stat_manager.go @@ -87,7 +87,7 @@ func (this *TrafficStatManager) Start(configFunc func() *nodeconfigs.NodeConfig) // Add 添加流量 func (this *TrafficStatManager) Add(serverId int64, domain string, bytes int64, cachedBytes int64, countRequests int64, countCachedRequests int64, countAttacks int64, attackBytes int64) { - if bytes == 0 { + if bytes == 0 && countRequests == 0 { return }