mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
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
This commit is contained in:
parent
c782ebdcea
commit
25f059f4c4
2 changed files with 17 additions and 11 deletions
|
@ -149,6 +149,15 @@ func proxyPolls(ctx *BrokerContext, w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Println("Received snowflake: ", id)
|
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.
|
// Wait for a client to avail an offer to the snowflake, or timeout if nil.
|
||||||
offer := ctx.RequestOffer(id)
|
offer := ctx.RequestOffer(id)
|
||||||
if nil == offer {
|
if nil == offer {
|
||||||
|
@ -224,15 +233,6 @@ func proxyAnswers(ctx *BrokerContext, w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
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.")
|
log.Println("Received answer.")
|
||||||
snowflake.answerChannel <- body
|
snowflake.answerChannel <- body
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ var (
|
||||||
const metricsResolution = 86400 * time.Second
|
const metricsResolution = 86400 * time.Second
|
||||||
|
|
||||||
type CountryStats struct {
|
type CountryStats struct {
|
||||||
|
ips map[string]bool
|
||||||
counts map[string]int
|
counts map[string]int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,8 +66,11 @@ func (m *Metrics) UpdateCountryStats(addr string) {
|
||||||
log.Println("Unknown geoip")
|
log.Println("Unknown geoip")
|
||||||
}
|
}
|
||||||
|
|
||||||
//update map of countries and counts
|
//update map of unique ips and counts
|
||||||
m.countryStats.counts[country]++
|
if !m.countryStats.ips[addr] {
|
||||||
|
m.countryStats.counts[country]++
|
||||||
|
m.countryStats.ips[addr] = true
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -101,6 +105,7 @@ func NewMetrics(metricsLogger *log.Logger) (*Metrics, error) {
|
||||||
|
|
||||||
m.countryStats = CountryStats{
|
m.countryStats = CountryStats{
|
||||||
counts: make(map[string]int),
|
counts: make(map[string]int),
|
||||||
|
ips: make(map[string]bool),
|
||||||
}
|
}
|
||||||
|
|
||||||
m.logger = metricsLogger
|
m.logger = metricsLogger
|
||||||
|
@ -126,6 +131,7 @@ func (m *Metrics) logMetrics() {
|
||||||
m.clientDeniedCount = 0
|
m.clientDeniedCount = 0
|
||||||
m.clientProxyMatchCount = 0
|
m.clientProxyMatchCount = 0
|
||||||
m.countryStats.counts = make(map[string]int)
|
m.countryStats.counts = make(map[string]int)
|
||||||
|
m.countryStats.ips = make(map[string]bool)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue