mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 11:11:30 -04:00
Make the proxy to report the number of clients to the broker
So the assignment of proxies is based on the load. The number of clients is ronded down to 8. Existing proxies that doesn't report the number of clients will be distributed equaly to new proxies until they get 8 clients, that is okish as the existing proxies do have a maximum capacity of 10. Fixes #40048
This commit is contained in:
parent
74bdb85b30
commit
7a1857c42f
9 changed files with 165 additions and 77 deletions
|
@ -32,7 +32,7 @@ func TestBroker(t *testing.T) {
|
|||
Convey("Adds Snowflake", func() {
|
||||
So(ctx.snowflakes.Len(), ShouldEqual, 0)
|
||||
So(len(ctx.idToSnowflake), ShouldEqual, 0)
|
||||
ctx.AddSnowflake("foo", "", NATUnrestricted)
|
||||
ctx.AddSnowflake("foo", "", NATUnrestricted, 0)
|
||||
So(ctx.snowflakes.Len(), ShouldEqual, 1)
|
||||
So(len(ctx.idToSnowflake), ShouldEqual, 1)
|
||||
})
|
||||
|
@ -59,7 +59,7 @@ func TestBroker(t *testing.T) {
|
|||
Convey("Request an offer from the Snowflake Heap", func() {
|
||||
done := make(chan *ClientOffer)
|
||||
go func() {
|
||||
offer := ctx.RequestOffer("test", "", NATUnrestricted)
|
||||
offer := ctx.RequestOffer("test", "", NATUnrestricted, 0)
|
||||
done <- offer
|
||||
}()
|
||||
request := <-ctx.proxyPolls
|
||||
|
@ -84,7 +84,7 @@ func TestBroker(t *testing.T) {
|
|||
Convey("with a proxy answer if available.", func() {
|
||||
done := make(chan bool)
|
||||
// Prepare a fake proxy to respond with.
|
||||
snowflake := ctx.AddSnowflake("fake", "", NATUnrestricted)
|
||||
snowflake := ctx.AddSnowflake("fake", "", NATUnrestricted, 0)
|
||||
go func() {
|
||||
clientOffers(ctx, w, r)
|
||||
done <- true
|
||||
|
@ -102,7 +102,7 @@ func TestBroker(t *testing.T) {
|
|||
return
|
||||
}
|
||||
done := make(chan bool)
|
||||
snowflake := ctx.AddSnowflake("fake", "", NATUnrestricted)
|
||||
snowflake := ctx.AddSnowflake("fake", "", NATUnrestricted, 0)
|
||||
go func() {
|
||||
clientOffers(ctx, w, r)
|
||||
// Takes a few seconds here...
|
||||
|
@ -132,7 +132,7 @@ func TestBroker(t *testing.T) {
|
|||
Convey("with a proxy answer if available.", func() {
|
||||
done := make(chan bool)
|
||||
// Prepare a fake proxy to respond with.
|
||||
snowflake := ctx.AddSnowflake("fake", "", NATUnrestricted)
|
||||
snowflake := ctx.AddSnowflake("fake", "", NATUnrestricted, 0)
|
||||
go func() {
|
||||
clientOffers(ctx, w, r)
|
||||
done <- true
|
||||
|
@ -150,7 +150,7 @@ func TestBroker(t *testing.T) {
|
|||
return
|
||||
}
|
||||
done := make(chan bool)
|
||||
snowflake := ctx.AddSnowflake("fake", "", NATUnrestricted)
|
||||
snowflake := ctx.AddSnowflake("fake", "", NATUnrestricted, 0)
|
||||
go func() {
|
||||
clientOffers(ctx, w, r)
|
||||
// Takes a few seconds here...
|
||||
|
@ -201,7 +201,7 @@ func TestBroker(t *testing.T) {
|
|||
})
|
||||
|
||||
Convey("Responds to proxy answers...", func() {
|
||||
s := ctx.AddSnowflake("test", "", NATUnrestricted)
|
||||
s := ctx.AddSnowflake("test", "", NATUnrestricted, 0)
|
||||
w := httptest.NewRecorder()
|
||||
data := bytes.NewReader([]byte(`{"Version":"1.0","Sid":"test","Answer":"test"}`))
|
||||
|
||||
|
@ -314,7 +314,7 @@ func TestBroker(t *testing.T) {
|
|||
// Manually do the Broker goroutine action here for full control.
|
||||
p := <-ctx.proxyPolls
|
||||
So(p.id, ShouldEqual, "ymbcCMto7KHNGYlp")
|
||||
s := ctx.AddSnowflake(p.id, "", NATUnrestricted)
|
||||
s := ctx.AddSnowflake(p.id, "", NATUnrestricted, 0)
|
||||
go func() {
|
||||
offer := <-s.offerChannel
|
||||
p.offerChannel <- offer
|
||||
|
@ -593,7 +593,7 @@ func TestMetrics(t *testing.T) {
|
|||
So(err, ShouldBeNil)
|
||||
|
||||
// Prepare a fake proxy to respond with.
|
||||
snowflake := ctx.AddSnowflake("fake", "", NATUnrestricted)
|
||||
snowflake := ctx.AddSnowflake("fake", "", NATUnrestricted, 0)
|
||||
go func() {
|
||||
clientOffers(ctx, w, r)
|
||||
done <- true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue