Commit bae0bacb authored by Cecylia Bocovich's avatar Cecylia Bocovich
Browse files

Classify proxies with unknown NATs as restricted

parent 1b29ad7d
Pipeline #2319 failed with stage
in 10 minutes and 42 seconds
...@@ -144,10 +144,10 @@ func (ctx *BrokerContext) Broker() { ...@@ -144,10 +144,10 @@ func (ctx *BrokerContext) Broker() {
ctx.snowflakeLock.Lock() ctx.snowflakeLock.Lock()
defer ctx.snowflakeLock.Unlock() defer ctx.snowflakeLock.Unlock()
if snowflake.index != -1 { if snowflake.index != -1 {
if request.natType == NATRestricted { if request.natType == NATUnrestricted {
heap.Remove(ctx.restrictedSnowflakes, snowflake.index)
} else {
heap.Remove(ctx.snowflakes, snowflake.index) heap.Remove(ctx.snowflakes, snowflake.index)
} else {
heap.Remove(ctx.restrictedSnowflakes, snowflake.index)
} }
delete(ctx.idToSnowflake, snowflake.id) delete(ctx.idToSnowflake, snowflake.id)
close(request.offerChannel) close(request.offerChannel)
...@@ -169,10 +169,10 @@ func (ctx *BrokerContext) AddSnowflake(id string, proxyType string, natType stri ...@@ -169,10 +169,10 @@ func (ctx *BrokerContext) AddSnowflake(id string, proxyType string, natType stri
snowflake.offerChannel = make(chan *ClientOffer) snowflake.offerChannel = make(chan *ClientOffer)
snowflake.answerChannel = make(chan []byte) snowflake.answerChannel = make(chan []byte)
ctx.snowflakeLock.Lock() ctx.snowflakeLock.Lock()
if natType == NATRestricted { if natType == NATUnrestricted {
heap.Push(ctx.restrictedSnowflakes, snowflake)
} else {
heap.Push(ctx.snowflakes, snowflake) heap.Push(ctx.snowflakes, snowflake)
} else {
heap.Push(ctx.restrictedSnowflakes, snowflake)
} }
ctx.snowflakeLock.Unlock() ctx.snowflakeLock.Unlock()
ctx.idToSnowflake[id] = snowflake ctx.idToSnowflake[id] = snowflake
......
...@@ -29,7 +29,7 @@ func TestBroker(t *testing.T) { ...@@ -29,7 +29,7 @@ func TestBroker(t *testing.T) {
Convey("Adds Snowflake", func() { Convey("Adds Snowflake", func() {
So(ctx.snowflakes.Len(), ShouldEqual, 0) So(ctx.snowflakes.Len(), ShouldEqual, 0)
So(len(ctx.idToSnowflake), ShouldEqual, 0) So(len(ctx.idToSnowflake), ShouldEqual, 0)
ctx.AddSnowflake("foo", "", NATUnknown) ctx.AddSnowflake("foo", "", NATUnrestricted)
So(ctx.snowflakes.Len(), ShouldEqual, 1) So(ctx.snowflakes.Len(), ShouldEqual, 1)
So(len(ctx.idToSnowflake), ShouldEqual, 1) So(len(ctx.idToSnowflake), ShouldEqual, 1)
}) })
...@@ -37,6 +37,7 @@ func TestBroker(t *testing.T) { ...@@ -37,6 +37,7 @@ func TestBroker(t *testing.T) {
Convey("Broker goroutine matches clients with proxies", func() { Convey("Broker goroutine matches clients with proxies", func() {
p := new(ProxyPoll) p := new(ProxyPoll)
p.id = "test" p.id = "test"
p.natType = "unrestricted"
p.offerChannel = make(chan *ClientOffer) p.offerChannel = make(chan *ClientOffer)
go func(ctx *BrokerContext) { go func(ctx *BrokerContext) {
ctx.proxyPolls <- p ctx.proxyPolls <- p
...@@ -55,7 +56,7 @@ func TestBroker(t *testing.T) { ...@@ -55,7 +56,7 @@ func TestBroker(t *testing.T) {
Convey("Request an offer from the Snowflake Heap", func() { Convey("Request an offer from the Snowflake Heap", func() {
done := make(chan *ClientOffer) done := make(chan *ClientOffer)
go func() { go func() {
offer := ctx.RequestOffer("test", "", NATUnknown) offer := ctx.RequestOffer("test", "", NATUnrestricted)
done <- offer done <- offer
}() }()
request := <-ctx.proxyPolls request := <-ctx.proxyPolls
...@@ -79,7 +80,7 @@ func TestBroker(t *testing.T) { ...@@ -79,7 +80,7 @@ func TestBroker(t *testing.T) {
Convey("with a proxy answer if available.", func() { Convey("with a proxy answer if available.", func() {
done := make(chan bool) done := make(chan bool)
// Prepare a fake proxy to respond with. // Prepare a fake proxy to respond with.
snowflake := ctx.AddSnowflake("fake", "", NATUnknown) snowflake := ctx.AddSnowflake("fake", "", NATUnrestricted)
go func() { go func() {
clientOffers(ctx, w, r) clientOffers(ctx, w, r)
done <- true done <- true
...@@ -97,7 +98,7 @@ func TestBroker(t *testing.T) { ...@@ -97,7 +98,7 @@ func TestBroker(t *testing.T) {
return return
} }
done := make(chan bool) done := make(chan bool)
snowflake := ctx.AddSnowflake("fake", "", NATUnknown) snowflake := ctx.AddSnowflake("fake", "", NATUnrestricted)
go func() { go func() {
clientOffers(ctx, w, r) clientOffers(ctx, w, r)
// Takes a few seconds here... // Takes a few seconds here...
...@@ -147,7 +148,7 @@ func TestBroker(t *testing.T) { ...@@ -147,7 +148,7 @@ func TestBroker(t *testing.T) {
}) })
Convey("Responds to proxy answers...", func() { Convey("Responds to proxy answers...", func() {
s := ctx.AddSnowflake("test", "", NATUnknown) s := ctx.AddSnowflake("test", "", NATUnrestricted)
w := httptest.NewRecorder() w := httptest.NewRecorder()
data := bytes.NewReader([]byte(`{"Version":"1.0","Sid":"test","Answer":"test"}`)) data := bytes.NewReader([]byte(`{"Version":"1.0","Sid":"test","Answer":"test"}`))
...@@ -260,7 +261,7 @@ func TestBroker(t *testing.T) { ...@@ -260,7 +261,7 @@ func TestBroker(t *testing.T) {
// Manually do the Broker goroutine action here for full control. // Manually do the Broker goroutine action here for full control.
p := <-ctx.proxyPolls p := <-ctx.proxyPolls
So(p.id, ShouldEqual, "ymbcCMto7KHNGYlp") So(p.id, ShouldEqual, "ymbcCMto7KHNGYlp")
s := ctx.AddSnowflake(p.id, "", NATUnknown) s := ctx.AddSnowflake(p.id, "", NATUnrestricted)
go func() { go func() {
offer := <-s.offerChannel offer := <-s.offerChannel
p.offerChannel <- offer p.offerChannel <- offer
...@@ -437,7 +438,7 @@ func TestGeoip(t *testing.T) { ...@@ -437,7 +438,7 @@ func TestGeoip(t *testing.T) {
if err := ctx.metrics.LoadGeoipDatabases("invalid_filename", "invalid_filename6"); err != nil { if err := ctx.metrics.LoadGeoipDatabases("invalid_filename", "invalid_filename6"); err != nil {
log.Printf("loading geo ip databases returned error: %v", err) log.Printf("loading geo ip databases returned error: %v", err)
} }
ctx.metrics.UpdateCountryStats("127.0.0.1", "", NATUnknown) ctx.metrics.UpdateCountryStats("127.0.0.1", "", NATUnrestricted)
So(ctx.metrics.tablev4, ShouldEqual, nil) So(ctx.metrics.tablev4, ShouldEqual, nil)
}) })
...@@ -537,7 +538,7 @@ func TestMetrics(t *testing.T) { ...@@ -537,7 +538,7 @@ func TestMetrics(t *testing.T) {
So(err, ShouldBeNil) So(err, ShouldBeNil)
// Prepare a fake proxy to respond with. // Prepare a fake proxy to respond with.
snowflake := ctx.AddSnowflake("fake", "", NATUnknown) snowflake := ctx.AddSnowflake("fake", "", NATUnrestricted)
go func() { go func() {
clientOffers(ctx, w, r) clientOffers(ctx, w, r)
done <- true done <- true
......
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