mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -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
44
proxy/tokens.go
Normal file
44
proxy/tokens.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
type tokens_t struct {
|
||||
ch chan struct{}
|
||||
capacity uint
|
||||
clients int64
|
||||
}
|
||||
|
||||
func newTokens(capacity uint) *tokens_t {
|
||||
var ch chan struct{}
|
||||
if capacity != 0 {
|
||||
ch = make(chan struct{}, capacity)
|
||||
}
|
||||
|
||||
return &tokens_t{
|
||||
ch: ch,
|
||||
capacity: capacity,
|
||||
clients: 0,
|
||||
}
|
||||
}
|
||||
|
||||
func (t *tokens_t) get() {
|
||||
atomic.AddInt64(&t.clients, 1)
|
||||
|
||||
if t.capacity != 0 {
|
||||
t.ch <- struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
func (t *tokens_t) ret() {
|
||||
atomic.AddInt64(&t.clients, -1)
|
||||
|
||||
if t.capacity != 0 {
|
||||
<-t.ch
|
||||
}
|
||||
}
|
||||
|
||||
func (t tokens_t) count() int64 {
|
||||
return atomic.LoadInt64(&t.clients)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue