Commit 97554e03 authored by Cecylia Bocovich's avatar Cecylia Bocovich
Browse files

Updated proxyType variable name for readability

parent 981abffb
......@@ -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++
......
......@@ -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
......
......@@ -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
......
......@@ -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,
})
}
......
......@@ -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)
})
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment