mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Add a 5s delay between polls in proxy-go.
https://bugs.torproject.org/25344 5s matches DEFAULT_BROKER_POLL_INTERVAL in the JavaScript proxy. This is set up so as long as the actual HTTPS requests take less time than pollInterval, there will a steady one poll per pollInterval. If the HTTPS requests take longer than that, there will be no delay between polls.
This commit is contained in:
parent
019e2cea23
commit
07291a0136
1 changed files with 13 additions and 0 deletions
|
@ -25,6 +25,7 @@ import (
|
||||||
const defaultBrokerURL = "https://snowflake-reg.appspot.com/"
|
const defaultBrokerURL = "https://snowflake-reg.appspot.com/"
|
||||||
const defaultRelayURL = "wss://snowflake.bamsoftware.com/"
|
const defaultRelayURL = "wss://snowflake.bamsoftware.com/"
|
||||||
const defaultSTUNURL = "stun:stun.l.google.com:19302"
|
const defaultSTUNURL = "stun:stun.l.google.com:19302"
|
||||||
|
const pollInterval = 5 * time.Second
|
||||||
|
|
||||||
var brokerURL *url.URL
|
var brokerURL *url.URL
|
||||||
var relayURL string
|
var relayURL string
|
||||||
|
@ -133,7 +134,19 @@ func genSessionID() string {
|
||||||
|
|
||||||
func pollOffer(sid string) *webrtc.SessionDescription {
|
func pollOffer(sid string) *webrtc.SessionDescription {
|
||||||
broker := brokerURL.ResolveReference(&url.URL{Path: "proxy"})
|
broker := brokerURL.ResolveReference(&url.URL{Path: "proxy"})
|
||||||
|
timeOfNextPoll := time.Now()
|
||||||
for {
|
for {
|
||||||
|
// Sleep until we're scheduled to poll again.
|
||||||
|
now := time.Now()
|
||||||
|
time.Sleep(timeOfNextPoll.Sub(now))
|
||||||
|
// Compute the next time to poll -- if it's in the past, that
|
||||||
|
// means that the POST took longer than pollInterval, so we're
|
||||||
|
// allowed to do another one immediately.
|
||||||
|
timeOfNextPoll = timeOfNextPoll.Add(pollInterval)
|
||||||
|
if timeOfNextPoll.Before(now) {
|
||||||
|
timeOfNextPoll = now
|
||||||
|
}
|
||||||
|
|
||||||
req, _ := http.NewRequest("POST", broker.String(), bytes.NewBuffer([]byte(sid)))
|
req, _ := http.NewRequest("POST", broker.String(), bytes.NewBuffer([]byte(sid)))
|
||||||
req.Header.Set("X-Session-ID", sid)
|
req.Header.Set("X-Session-ID", sid)
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue