Skip to content

Commit

Permalink
improvement: reduce workload or proxy
Browse files Browse the repository at this point in the history
...to be comparable to browser-based proxies.
Otherwise the proxy polls every 5 seconds, which is 12x as frequent
as browser-based proxies do.
See
- https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/issues/40373
- guardianproject/orbot#1105
  • Loading branch information
WofWca authored and syphyr committed Oct 21, 2024
1 parent a345094 commit ecb789b
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion IPtProxy.go/IPtProxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ type SnowflakeClientConnected interface {

// StartSnowflakeProxy - Start the Snowflake proxy.
//
// @param pollIntervalMs how often to ask the broker for a new client, in milliseconds. Keep in mind that asking for a client will not always result in getting one. Minumum value is 2000 milliseconds. If set to 0, will default to 120 000ms, i.e. twice the interval that browser-based Snowflake proxies have
//
// @param capacity the maximum number of clients a Snowflake will serve. If set to 0, the proxy will accept an unlimited number of clients.
//
// @param broker Broker URL. OPTIONAL. Defaults to https://snowflake-broker.torproject.net/, if empty.
Expand All @@ -307,16 +309,33 @@ type SnowflakeClientConnected interface {
// if you want to do UI stuff!! OPTIONAL
//
//goland:noinspection GoUnusedExportedFunction
func StartSnowflakeProxy(capacity int, broker, relay, stun, natProbe, logFile string, keepLocalAddresses, unsafeLogging bool, clientConnected SnowflakeClientConnected) {
func StartSnowflakeProxy(pollIntervalMs int, capacity int, broker, relay, stun, natProbe, logFile string, keepLocalAddresses, unsafeLogging bool, clientConnected SnowflakeClientConnected) {
if snowflakeProxy != nil {
return
}

// Same min interval as imposed by Snowflake proxy CLI
// https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/blob/f4db64612c500be635dc7eb231505e88552e6a07/proxy/main.go#L20
if pollIntervalMs < 2000 {
if pollIntervalMs == 0 {
// Twice the interval that browser-based Snowflake proxies have:
// https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake-webext/-/blob/3649063755f6b7dc8104f64ef4c25cbba8ba9de8/config.js#L24
// so that mobile devices (that use IPtProxy) experience less load
// than PCs running the extension. See
// https://github.com/guardianproject/orbot/issues/1105
// https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/issues/40373
pollIntervalMs = 120 * 1000
} else {
log.Fatalf("pollIntervalMs must be >= 2000 milliseconds (or 0 for default). The provided value was %v", pollIntervalMs)
}
}

if capacity < 1 {
capacity = 0
}

snowflakeProxy = &sfp.SnowflakeProxy{
PollInterval: time.Duration(pollIntervalMs) * time.Millisecond,
Capacity: uint(capacity),
STUNURL: stun,
BrokerURL: broker,
Expand Down

0 comments on commit ecb789b

Please sign in to comment.