This is an automated email from the git hooks/post-receive script.
meskio pushed a change to branch main in repository pluggable-transports/snowflake.
from bd636a1 Introduce an unexported newBrokerChannelFromConfig new b265bd3 Make easier to extend the list of known proxy types new b73add1 Make the proxy type configurable for users of the library
The 2 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference.
Summary of changes: broker/ipc.go | 19 ++++++------- broker/metrics.go | 60 ++++++++++++++++------------------------- broker/snowflake-broker_test.go | 17 +++++++++--- common/messages/proxy.go | 21 +++++++-------- proxy/lib/proxy-go_test.go | 4 +-- proxy/lib/snowflake.go | 16 +++++++---- 6 files changed, 68 insertions(+), 69 deletions(-)
This is an automated email from the git hooks/post-receive script.
meskio pushed a commit to branch main in repository pluggable-transports/snowflake.
commit b265bd3092742bb0f71acffa52c0f5b7b8216a10 Author: meskio meskio@torproject.org AuthorDate: Fri Mar 11 14:32:35 2022 +0100
Make easier to extend the list of known proxy types
And include iptproxy as a valid proxy type. --- broker/ipc.go | 19 ++++++------- broker/metrics.go | 60 ++++++++++++++++------------------------- broker/snowflake-broker_test.go | 17 +++++++++--- common/messages/proxy.go | 21 +++++++-------- 4 files changed, 55 insertions(+), 62 deletions(-)
diff --git a/broker/ipc.go b/broker/ipc.go index 768c0b7..9b47b90 100644 --- a/broker/ipc.go +++ b/broker/ipc.go @@ -25,18 +25,15 @@ type IPC struct { }
func (i *IPC) Debug(_ interface{}, response *string) error { - var webexts, browsers, standalones, unknowns int + var unknowns int var natRestricted, natUnrestricted, natUnknown int + proxyTypes := make(map[string]int)
i.ctx.snowflakeLock.Lock() s := fmt.Sprintf("current snowflakes available: %d\n", len(i.ctx.idToSnowflake)) for _, snowflake := range i.ctx.idToSnowflake { - if snowflake.proxyType == "badge" { - browsers++ - } else if snowflake.proxyType == "webext" { - webexts++ - } else if snowflake.proxyType == "standalone" { - standalones++ + if messages.KnownProxyTypes[snowflake.proxyType] { + proxyTypes[snowflake.proxyType]++ } else { unknowns++ } @@ -53,10 +50,10 @@ func (i *IPC) Debug(_ interface{}, response *string) error { } i.ctx.snowflakeLock.Unlock()
- s += fmt.Sprintf("\tstandalone proxies: %d", standalones) - s += fmt.Sprintf("\n\tbrowser proxies: %d", browsers) - s += fmt.Sprintf("\n\twebext proxies: %d", webexts) - s += fmt.Sprintf("\n\tunknown proxies: %d", unknowns) + for pType, num := range proxyTypes { + s += fmt.Sprintf("\t%s proxies: %d\n", pType, num) + } + s += fmt.Sprintf("\tunknown proxies: %d", unknowns)
s += fmt.Sprintf("\nNAT Types available:") s += fmt.Sprintf("\n\trestricted: %d", natRestricted) diff --git a/broker/metrics.go b/broker/metrics.go index 8229e0f..c642045 100644 --- a/broker/metrics.go +++ b/broker/metrics.go @@ -14,6 +14,7 @@ import ( "sync" "time"
+ "git.torproject.org/pluggable-transports/snowflake.git/v2/common/messages" "github.com/prometheus/client_golang/prometheus" "gitlab.torproject.org/tpo/anti-censorship/geoip" ) @@ -24,10 +25,9 @@ const ( )
type CountryStats struct { - standalone map[string]bool - badge map[string]bool - webext map[string]bool - unknown map[string]bool + // map[proxyType][address]bool + proxies map[string]map[string]bool + unknown map[string]bool
natRestricted map[string]bool natUnrestricted map[string]bool @@ -96,22 +96,17 @@ func (m *Metrics) UpdateCountryStats(addr string, proxyType string, natType stri var country string var ok bool
- if proxyType == "standalone" { - if m.countryStats.standalone[addr] { - return - } - } else if proxyType == "badge" { - if m.countryStats.badge[addr] { - return - } - } else if proxyType == "webext" { - if m.countryStats.webext[addr] { + addresses, ok := m.countryStats.proxies[proxyType] + if !ok { + if m.countryStats.unknown[addr] { return } + m.countryStats.unknown[addr] = true } else { - if m.countryStats.unknown[addr] { + if addresses[addr] { return } + addresses[addr] = true }
ip := net.ParseIP(addr) @@ -122,18 +117,7 @@ func (m *Metrics) UpdateCountryStats(addr string, proxyType string, natType stri if !ok { country = "??" } - - //update map of unique ips and counts m.countryStats.counts[country]++ - if proxyType == "standalone" { - m.countryStats.standalone[addr] = true - } else if proxyType == "badge" { - m.countryStats.badge[addr] = true - } else if proxyType == "webext" { - m.countryStats.webext[addr] = true - } else { - m.countryStats.unknown[addr] = true - }
m.promMetrics.ProxyTotal.With(prometheus.Labels{ "nat": natType, @@ -166,14 +150,15 @@ func NewMetrics(metricsLogger *log.Logger) (*Metrics, error) {
m.countryStats = CountryStats{ counts: make(map[string]int), - standalone: make(map[string]bool), - badge: make(map[string]bool), - webext: make(map[string]bool), + proxies: make(map[string]map[string]bool), unknown: make(map[string]bool), natRestricted: make(map[string]bool), natUnrestricted: make(map[string]bool), natUnknown: make(map[string]bool), } + for pType := range messages.KnownProxyTypes { + m.countryStats.proxies[pType] = make(map[string]bool) + }
m.logger = metricsLogger m.promMetrics = initPrometheus() @@ -197,11 +182,12 @@ func (m *Metrics) printMetrics() { m.lock.Lock() m.logger.Println("snowflake-stats-end", time.Now().UTC().Format("2006-01-02 15:04:05"), fmt.Sprintf("(%d s)", int(metricsResolution.Seconds()))) m.logger.Println("snowflake-ips", m.countryStats.Display()) - m.logger.Println("snowflake-ips-total", len(m.countryStats.standalone)+ - len(m.countryStats.badge)+len(m.countryStats.webext)+len(m.countryStats.unknown)) - m.logger.Println("snowflake-ips-standalone", len(m.countryStats.standalone)) - m.logger.Println("snowflake-ips-badge", len(m.countryStats.badge)) - m.logger.Println("snowflake-ips-webext", len(m.countryStats.webext)) + total := len(m.countryStats.unknown) + for pType, addresses := range m.countryStats.proxies { + m.logger.Printf("snowflake-ips-%s %d\n", pType, len(addresses)) + total += len(addresses) + } + m.logger.Println("snowflake-ips-total", total) m.logger.Println("snowflake-idle-count", binCount(m.proxyIdleCount)) m.logger.Println("client-denied-count", binCount(m.clientDeniedCount)) m.logger.Println("client-restricted-denied-count", binCount(m.clientRestrictedDeniedCount)) @@ -221,9 +207,9 @@ func (m *Metrics) zeroMetrics() { m.clientUnrestrictedDeniedCount = 0 m.clientProxyMatchCount = 0 m.countryStats.counts = make(map[string]int) - m.countryStats.standalone = make(map[string]bool) - m.countryStats.badge = make(map[string]bool) - m.countryStats.webext = make(map[string]bool) + for pType := range m.countryStats.proxies { + m.countryStats.proxies[pType] = make(map[string]bool) + } m.countryStats.unknown = make(map[string]bool) m.countryStats.natRestricted = make(map[string]bool) m.countryStats.natUnrestricted = make(map[string]bool) diff --git a/broker/snowflake-broker_test.go b/broker/snowflake-broker_test.go index 9c975eb..f7850f8 100644 --- a/broker/snowflake-broker_test.go +++ b/broker/snowflake-broker_test.go @@ -549,8 +549,13 @@ func TestMetrics(t *testing.T) { p.offerChannel <- nil <-done ctx.metrics.printMetrics() - So(buf.String(), ShouldResemble, "snowflake-stats-end "+time.Now().UTC().Format("2006-01-02 15:04:05")+" (86400 s)\nsnowflake-ips CA=4\nsnowflake-ips-total 4\nsnowflake-ips-standalone 1\nsnowflake-ips-badge 1\nsnowflake-ips-webext 1\nsnowflake-idle-count 8\nclient-denied-count 0\nclient-restricted-denied-count 0\nclient-unrestricted-denied-count 0\nclient-snowflake-match-count 0\nsnowflake-ips-nat-restricted 0\nsnowflake-ips-nat-unrestricted 0\nsnowflake-ips-nat-unknown 1\n")
+ metricsStr := buf.String() + So(metricsStr, ShouldStartWith, "snowflake-stats-end "+time.Now().UTC().Format("2006-01-02 15:04:05")+" (86400 s)\nsnowflake-ips CA=4\n") + So(metricsStr, ShouldContainSubstring, "\nsnowflake-ips-standalone 1\n") + So(metricsStr, ShouldContainSubstring, "\nsnowflake-ips-badge 1\n") + So(metricsStr, ShouldContainSubstring, "\nsnowflake-ips-webext 1\n") + So(metricsStr, ShouldEndWith, "\nsnowflake-ips-total 4\nsnowflake-idle-count 8\nclient-denied-count 0\nclient-restricted-denied-count 0\nclient-unrestricted-denied-count 0\nclient-snowflake-match-count 0\nsnowflake-ips-nat-restricted 0\nsnowflake-ips-nat-unrestricted 0\nsnowflake-ips-nat-unknown 1\n") })
//Test addition of client failures @@ -570,7 +575,11 @@ func TestMetrics(t *testing.T) { buf.Reset() ctx.metrics.zeroMetrics() ctx.metrics.printMetrics() - So(buf.String(), ShouldContainSubstring, "snowflake-ips \nsnowflake-ips-total 0\nsnowflake-ips-standalone 0\nsnowflake-ips-badge 0\nsnowflake-ips-webext 0\nsnowflake-idle-count 0\nclient-denied-count 0\nclient-restricted-denied-count 0\nclient-unrestricted-denied-count 0\nclient-snowflake-match-count 0\nsnowflake-ips-nat-restricted 0\nsnowflake-ips-nat-unrestricted 0\nsnowflake-ips-nat-unknown 0\n") + So(buf.String(), ShouldContainSubstring, "\nsnowflake-ips \n") + So(buf.String(), ShouldContainSubstring, "\nsnowflake-ips-standalone 0\n") + So(buf.String(), ShouldContainSubstring, "\nsnowflake-ips-badge 0\n") + So(buf.String(), ShouldContainSubstring, "\nsnowflake-ips-webext 0\n") + So(buf.String(), ShouldContainSubstring, "\nsnowflake-ips-total 0\nsnowflake-idle-count 0\nclient-denied-count 0\nclient-restricted-denied-count 0\nclient-unrestricted-denied-count 0\nclient-snowflake-match-count 0\nsnowflake-ips-nat-restricted 0\nsnowflake-ips-nat-unrestricted 0\nsnowflake-ips-nat-unknown 0\n") }) //Test addition of client matches Convey("for client-proxy match", func() { @@ -690,7 +699,9 @@ func TestMetrics(t *testing.T) { <-done
ctx.metrics.printMetrics() - So(buf.String(), ShouldContainSubstring, "snowflake-ips CA=1\nsnowflake-ips-total 1") + metricsStr := buf.String() + So(metricsStr, ShouldContainSubstring, "snowflake-ips CA=1\n") + So(metricsStr, ShouldContainSubstring, "snowflake-ips-total 1\n") }) //Test NAT types Convey("proxy counts by NAT type", func() { diff --git a/common/messages/proxy.go b/common/messages/proxy.go index 64f139b..dcfe0ab 100644 --- a/common/messages/proxy.go +++ b/common/messages/proxy.go @@ -12,14 +12,17 @@ import ( )
const ( - version = "1.2" - - ProxyStandalone = "standalone" - ProxyWebext = "webext" - ProxyBadge = "badge" - ProxyUnknown = "unknown" + version = "1.2" + ProxyUnknown = "unknown" )
+var KnownProxyTypes = map[string]bool{ + "standalone": true, + "webext": true, + "badge": true, + "iptproxy": true, +} + /* Version 1.2 specification:
== ProxyPollRequest == @@ -138,11 +141,7 @@ func DecodeProxyPollRequest(data []byte) (sid string, proxyType string, natType
// we don't reject polls with an unknown proxy type because we encourage // projects that embed proxy code to include their own type - switch message.Type { - case ProxyStandalone: - case ProxyWebext: - case ProxyBadge: - default: + if !KnownProxyTypes[message.Type] { message.Type = ProxyUnknown }
This is an automated email from the git hooks/post-receive script.
meskio pushed a commit to branch main in repository pluggable-transports/snowflake.
commit b73add155074657cb763fcf12a3f7d2e9e22316d Author: meskio meskio@torproject.org AuthorDate: Fri Mar 11 16:42:05 2022 +0100
Make the proxy type configurable for users of the library
Closes: #40104 --- proxy/lib/proxy-go_test.go | 4 ++-- proxy/lib/snowflake.go | 16 +++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/proxy/lib/proxy-go_test.go b/proxy/lib/proxy-go_test.go index 86616c4..f4cbfbf 100644 --- a/proxy/lib/proxy-go_test.go +++ b/proxy/lib/proxy-go_test.go @@ -365,7 +365,7 @@ func TestBrokerInteractions(t *testing.T) { b, }
- sdp := broker.pollOffer(sampleOffer, nil) + sdp := broker.pollOffer(sampleOffer, DefaultProxyType, nil) expectedSDP, _ := strconv.Unquote(sampleSDP) So(sdp.SDP, ShouldResemble, expectedSDP) }) @@ -379,7 +379,7 @@ func TestBrokerInteractions(t *testing.T) { b, }
- sdp := broker.pollOffer(sampleOffer, nil) + sdp := broker.pollOffer(sampleOffer, DefaultProxyType, nil) So(sdp, ShouldBeNil) }) Convey("sends answer to broker", func() { diff --git a/proxy/lib/snowflake.go b/proxy/lib/snowflake.go index ae9d5bf..17f0126 100644 --- a/proxy/lib/snowflake.go +++ b/proxy/lib/snowflake.go @@ -56,6 +56,7 @@ const DefaultNATProbeURL = "https://snowflake-broker.torproject.net:8443/probe" const DefaultRelayURL = "wss://snowflake.bamsoftware.com/"
const DefaultSTUNURL = "stun:stun.stunprotocol.org:3478" +const DefaultProxyType = "standalone" const pollInterval = 5 * time.Second
const ( @@ -115,8 +116,10 @@ type SnowflakeProxy struct { NATProbeURL string // NATTypeMeasurementInterval is time before NAT type is retested NATTypeMeasurementInterval time.Duration - EventDispatcher event.SnowflakeEventDispatcher - shutdown chan struct{} + // ProxyType is the type reported to the broker, if not provided it "standalone" will be used + ProxyType string + EventDispatcher event.SnowflakeEventDispatcher + shutdown chan struct{} }
// Checks whether an IP address is a remote address for the client @@ -185,7 +188,7 @@ func (s *SignalingServer) Post(path string, payload io.Reader) ([]byte, error) { return limitedRead(resp.Body, readLimit) }
-func (s *SignalingServer) pollOffer(sid string, shutdown chan struct{}) *webrtc.SessionDescription { +func (s *SignalingServer) pollOffer(sid string, proxyType string, shutdown chan struct{}) *webrtc.SessionDescription { brokerPath := s.url.ResolveReference(&url.URL{Path: "proxy"})
ticker := time.NewTicker(pollInterval) @@ -199,7 +202,7 @@ func (s *SignalingServer) pollOffer(sid string, shutdown chan struct{}) *webrtc. default: numClients := int((tokens.count() / 8) * 8) // Round down to 8 currentNATTypeLoaded := getCurrentNATType() - body, err := messages.EncodeProxyPollRequest(sid, "standalone", currentNATTypeLoaded, numClients) + body, err := messages.EncodeProxyPollRequest(sid, proxyType, currentNATTypeLoaded, numClients) if err != nil { log.Printf("Error encoding poll message: %s", err.Error()) return nil @@ -467,7 +470,7 @@ func (sf *SnowflakeProxy) makeNewPeerConnection(config webrtc.Configuration, }
func (sf *SnowflakeProxy) runSession(sid string) { - offer := broker.pollOffer(sid, sf.shutdown) + offer := broker.pollOffer(sid, sf.ProxyType, sf.shutdown) if offer == nil { log.Printf("bad offer from broker") tokens.ret() @@ -525,6 +528,9 @@ func (sf *SnowflakeProxy) Start() error { if sf.NATProbeURL == "" { sf.NATProbeURL = DefaultNATProbeURL } + if sf.ProxyType == "" { + sf.ProxyType = DefaultProxyType + } if sf.EventDispatcher == nil { sf.EventDispatcher = event.NewSnowflakeEventDispatcher() }
tor-commits@lists.torproject.org