[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [snowflake/master] Log geoip stats of proxies by unique IP
commit 25f059f4c4adf98a6ae9bdeae731e3f8ff3d609e
Author: Cecylia Bocovich <cohosh@xxxxxxxxxxxxxx>
Date: Tue Jun 11 15:43:59 2019 -0400
Log geoip stats of proxies by unique IP
Change it so that we log the geoip country code of proxies if they poll
within the current metrics epoch. We make sure we log by unique IP
address
---
broker/broker.go | 18 +++++++++---------
broker/metrics.go | 10 ++++++++--
2 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/broker/broker.go b/broker/broker.go
index 3795f2b..26fc450 100644
--- a/broker/broker.go
+++ b/broker/broker.go
@@ -149,6 +149,15 @@ func proxyPolls(ctx *BrokerContext, w http.ResponseWriter, r *http.Request) {
return
}
log.Println("Received snowflake: ", id)
+
+ // Log geoip stats
+ remoteIP, _, err := net.SplitHostPort(r.RemoteAddr)
+ if err != nil {
+ log.Println("Error processing proxy IP: ", err.Error())
+ } else {
+ ctx.metrics.UpdateCountryStats(remoteIP)
+ }
+
// Wait for a client to avail an offer to the snowflake, or timeout if nil.
offer := ctx.RequestOffer(id)
if nil == offer {
@@ -224,15 +233,6 @@ func proxyAnswers(ctx *BrokerContext, w http.ResponseWriter, r *http.Request) {
return
}
- // Get proxy country stats
- remoteIP, _, err := net.SplitHostPort(r.RemoteAddr)
- if err != nil {
- log.Println("Error processing proxy IP: ", err.Error())
- } else {
-
- ctx.metrics.UpdateCountryStats(remoteIP)
- }
-
log.Println("Received answer.")
snowflake.answerChannel <- body
}
diff --git a/broker/metrics.go b/broker/metrics.go
index a7f077a..b03c6db 100644
--- a/broker/metrics.go
+++ b/broker/metrics.go
@@ -17,6 +17,7 @@ var (
const metricsResolution = 86400 * time.Second
type CountryStats struct {
+ ips map[string]bool
counts map[string]int
}
@@ -65,8 +66,11 @@ func (m *Metrics) UpdateCountryStats(addr string) {
log.Println("Unknown geoip")
}
- //update map of countries and counts
- m.countryStats.counts[country]++
+ //update map of unique ips and counts
+ if !m.countryStats.ips[addr] {
+ m.countryStats.counts[country]++
+ m.countryStats.ips[addr] = true
+ }
return
}
@@ -101,6 +105,7 @@ func NewMetrics(metricsLogger *log.Logger) (*Metrics, error) {
m.countryStats = CountryStats{
counts: make(map[string]int),
+ ips: make(map[string]bool),
}
m.logger = metricsLogger
@@ -126,6 +131,7 @@ func (m *Metrics) logMetrics() {
m.clientDeniedCount = 0
m.clientProxyMatchCount = 0
m.countryStats.counts = make(map[string]int)
+ m.countryStats.ips = make(map[string]bool)
}
}
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits