commit 0767a637c1f07dab71708762dd975adaa35b0bd9
Author: Cecylia Bocovich <[email protected]>
Date:   Fri Jun 14 17:00:31 2019 -0400

    Changed variable names/types to be more reasonable
    
    Also moved the geoip check to occur after we've make sure the proxy IP
    hasn't yet been recorded. This is will cut down on unecessary
    computation.
---
 broker/metrics.go | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/broker/metrics.go b/broker/metrics.go
index cca716f..f37ec8a 100644
--- a/broker/metrics.go
+++ b/broker/metrics.go
@@ -49,10 +49,10 @@ var (
        once sync.Once
 )
 
-const metricsResolution = 86400 * time.Second
+const metricsResolution = 60 * 60 * 24 * time.Second //86400 seconds
 
 type CountryStats struct {
-       ips    map[string]bool
+       addrs  map[string]bool
        counts map[string]int
 }
 
@@ -64,9 +64,9 @@ type Metrics struct {
 
        countryStats            CountryStats
        clientRoundtripEstimate time.Duration
-       proxyIdleCount          int
-       clientDeniedCount       int
-       clientProxyMatchCount   int
+       proxyIdleCount          uint
+       clientDeniedCount       uint
+       clientProxyMatchCount   uint
 }
 
 func (s CountryStats) Display() string {
@@ -82,6 +82,10 @@ func (m *Metrics) UpdateCountryStats(addr string) {
        var country string
        var ok bool
 
+       if m.countryStats.addrs[addr] {
+               return
+       }
+
        ip := net.ParseIP(addr)
        if ip.To4() != nil {
                //This is an IPv4 address
@@ -102,10 +106,8 @@ func (m *Metrics) UpdateCountryStats(addr string) {
        }
 
        //update map of unique ips and counts
-       if !m.countryStats.ips[addr] {
-               m.countryStats.counts[country]++
-               m.countryStats.ips[addr] = true
-       }
+       m.countryStats.counts[country]++
+       m.countryStats.addrs[addr] = true
 
        return
 }
@@ -140,7 +142,7 @@ func NewMetrics(metricsLogger *log.Logger) (*Metrics, 
error) {
 
        m.countryStats = CountryStats{
                counts: make(map[string]int),
-               ips:    make(map[string]bool),
+               addrs:  make(map[string]bool),
        }
 
        m.logger = metricsLogger
@@ -174,10 +176,10 @@ func (m *Metrics) zeroMetrics() {
        m.clientDeniedCount = 0
        m.clientProxyMatchCount = 0
        m.countryStats.counts = make(map[string]int)
-       m.countryStats.ips = make(map[string]bool)
+       m.countryStats.addrs = make(map[string]bool)
 }
 
 // Rounds up a count to the nearest multiple of 8.
-func binCount(count int) int {
-       return int((math.Ceil(float64(count) / 8)) * 8)
+func binCount(count uint) uint {
+       return uint((math.Ceil(float64(count) / 8)) * 8)
 }



_______________________________________________
tor-commits mailing list
[email protected]
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits

Reply via email to