commit 97554e03e4081cecb7609721e43ad4d4ce408dd4
Author: Cecylia Bocovich <[email protected]>
Date:   Tue Nov 26 10:36:27 2019 -0500

    Updated proxyType variable name for readability
---
 broker/broker.go              | 24 ++++++++++++------------
 broker/metrics.go             | 14 +++++++-------
 broker/snowflake-heap.go      |  2 +-
 common/messages/proxy.go      |  4 ++--
 common/messages/proxy_test.go | 16 ++++++++--------
 5 files changed, 30 insertions(+), 30 deletions(-)

diff --git a/broker/broker.go b/broker/broker.go
index e897ffd..c166f1a 100644
--- a/broker/broker.go
+++ b/broker/broker.go
@@ -97,16 +97,16 @@ func (mh MetricsHandler) ServeHTTP(w http.ResponseWriter, r 
*http.Request) {
 // Proxies may poll for client offers concurrently.
 type ProxyPoll struct {
        id           string
-       ptype        string
+       proxyType    string
        offerChannel chan []byte
 }
 
 // Registers a Snowflake and waits for some Client to send an offer,
 // as part of the polling logic of the proxy handler.
-func (ctx *BrokerContext) RequestOffer(id string, ptype string) []byte {
+func (ctx *BrokerContext) RequestOffer(id string, proxyType string) []byte {
        request := new(ProxyPoll)
        request.id = id
-       request.ptype = ptype
+       request.proxyType = proxyType
        request.offerChannel = make(chan []byte)
        ctx.proxyPolls <- request
        // Block until an offer is available, or timeout which sends a nil 
offer.
@@ -119,7 +119,7 @@ func (ctx *BrokerContext) RequestOffer(id string, ptype 
string) []byte {
 // client offer or nil on timeout / none are available.
 func (ctx *BrokerContext) Broker() {
        for request := range ctx.proxyPolls {
-               snowflake := ctx.AddSnowflake(request.id, request.ptype)
+               snowflake := ctx.AddSnowflake(request.id, request.proxyType)
                // Wait for a client to avail an offer to the snowflake.
                go func(request *ProxyPoll) {
                        select {
@@ -139,11 +139,11 @@ func (ctx *BrokerContext) Broker() {
 // Create and add a Snowflake to the heap.
 // Required to keep track of proxies between providing them
 // with an offer and awaiting their second POST with an answer.
-func (ctx *BrokerContext) AddSnowflake(id string, ptype string) *Snowflake {
+func (ctx *BrokerContext) AddSnowflake(id string, proxyType string) *Snowflake 
{
        snowflake := new(Snowflake)
        snowflake.id = id
        snowflake.clients = 0
-       snowflake.ptype = ptype
+       snowflake.proxyType = proxyType
        snowflake.offerChannel = make(chan []byte)
        snowflake.answerChannel = make(chan []byte)
        heap.Push(ctx.snowflakes, snowflake)
@@ -162,7 +162,7 @@ func proxyPolls(ctx *BrokerContext, w http.ResponseWriter, 
r *http.Request) {
                return
        }
 
-       sid, ptype, err := messages.DecodePollRequest(body)
+       sid, proxyType, err := messages.DecodePollRequest(body)
        if err != nil {
                w.WriteHeader(http.StatusBadRequest)
                return
@@ -173,11 +173,11 @@ func proxyPolls(ctx *BrokerContext, w 
http.ResponseWriter, r *http.Request) {
        if err != nil {
                log.Println("Error processing proxy IP: ", err.Error())
        } else {
-               ctx.metrics.UpdateCountryStats(remoteIP, ptype)
+               ctx.metrics.UpdateCountryStats(remoteIP, proxyType)
        }
 
        // Wait for a client to avail an offer to the snowflake, or timeout if 
nil.
-       offer := ctx.RequestOffer(sid, ptype)
+       offer := ctx.RequestOffer(sid, proxyType)
        var b []byte
        if nil == offer {
                ctx.metrics.proxyIdleCount++
@@ -291,11 +291,11 @@ func debugHandler(ctx *BrokerContext, w 
http.ResponseWriter, r *http.Request) {
 
        var webexts, browsers, standalones, unknowns int
        for _, snowflake := range ctx.idToSnowflake {
-               if snowflake.ptype == "badge" {
+               if snowflake.proxyType == "badge" {
                        browsers++
-               } else if snowflake.ptype == "webext" {
+               } else if snowflake.proxyType == "webext" {
                        webexts++
-               } else if snowflake.ptype == "standalone" {
+               } else if snowflake.proxyType == "standalone" {
                        standalones++
                } else {
                        unknowns++
diff --git a/broker/metrics.go b/broker/metrics.go
index b5c423c..c23a170 100644
--- a/broker/metrics.go
+++ b/broker/metrics.go
@@ -110,20 +110,20 @@ func (s CountryStats) Display() string {
        return output
 }
 
-func (m *Metrics) UpdateCountryStats(addr string, ptype string) {
+func (m *Metrics) UpdateCountryStats(addr string, proxyType string) {
 
        var country string
        var ok bool
 
-       if ptype == "standalone" {
+       if proxyType == "standalone" {
                if m.countryStats.standalone[addr] {
                        return
                }
-       } else if ptype == "badge" {
+       } else if proxyType == "badge" {
                if m.countryStats.badge[addr] {
                        return
                }
-       } else if ptype == "webext" {
+       } else if proxyType == "webext" {
                if m.countryStats.webext[addr] {
                        return
                }
@@ -153,11 +153,11 @@ func (m *Metrics) UpdateCountryStats(addr string, ptype 
string) {
 
        //update map of unique ips and counts
        m.countryStats.counts[country]++
-       if ptype == "standalone" {
+       if proxyType == "standalone" {
                m.countryStats.standalone[addr] = true
-       } else if ptype == "badge" {
+       } else if proxyType == "badge" {
                m.countryStats.badge[addr] = true
-       } else if ptype == "webext" {
+       } else if proxyType == "webext" {
                m.countryStats.webext[addr] = true
        } else {
                m.countryStats.unknown[addr] = true
diff --git a/broker/snowflake-heap.go b/broker/snowflake-heap.go
index cf209ec..19a64b2 100644
--- a/broker/snowflake-heap.go
+++ b/broker/snowflake-heap.go
@@ -10,7 +10,7 @@ over the offer and answer channels.
 */
 type Snowflake struct {
        id            string
-       ptype         string
+       proxyType     string
        offerChannel  chan []byte
        answerChannel chan []byte
        clients       int
diff --git a/common/messages/proxy.go b/common/messages/proxy.go
index 7ebab1d..d57af1e 100644
--- a/common/messages/proxy.go
+++ b/common/messages/proxy.go
@@ -78,11 +78,11 @@ type ProxyPollRequest struct {
        Type    string
 }
 
-func EncodePollRequest(sid string, ptype string) ([]byte, error) {
+func EncodePollRequest(sid string, proxyType string) ([]byte, error) {
        return json.Marshal(ProxyPollRequest{
                Sid:     sid,
                Version: version,
-               Type:    ptype,
+               Type:    proxyType,
        })
 }
 
diff --git a/common/messages/proxy_test.go b/common/messages/proxy_test.go
index 83553a0..6783874 100644
--- a/common/messages/proxy_test.go
+++ b/common/messages/proxy_test.go
@@ -11,10 +11,10 @@ import (
 func TestDecodeProxyPollRequest(t *testing.T) {
        Convey("Context", t, func() {
                for _, test := range []struct {
-                       sid   string
-                       ptype string
-                       data  string
-                       err   error
+                       sid       string
+                       proxyType string
+                       data      string
+                       err       error
                }{
                        {
                                //Version 1.0 proxy message
@@ -62,9 +62,9 @@ func TestDecodeProxyPollRequest(t *testing.T) {
                                fmt.Errorf(""),
                        },
                } {
-                       sid, ptype, err := DecodePollRequest([]byte(test.data))
+                       sid, proxyType, err := 
DecodePollRequest([]byte(test.data))
                        So(sid, ShouldResemble, test.sid)
-                       So(ptype, ShouldResemble, test.ptype)
+                       So(proxyType, ShouldResemble, test.proxyType)
                        So(err, ShouldHaveSameTypeAs, test.err)
                }
 
@@ -75,9 +75,9 @@ func TestEncodeProxyPollRequests(t *testing.T) {
        Convey("Context", t, func() {
                b, err := EncodePollRequest("ymbcCMto7KHNGYlp", "standalone")
                So(err, ShouldEqual, nil)
-               sid, ptype, err := DecodePollRequest(b)
+               sid, proxyType, err := DecodePollRequest(b)
                So(sid, ShouldEqual, "ymbcCMto7KHNGYlp")
-               So(ptype, ShouldEqual, "standalone")
+               So(proxyType, ShouldEqual, "standalone")
                So(err, ShouldEqual, nil)
        })
 }



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

Reply via email to