commit 07291a0136b8a01bd8761a14a51876f08ca0d578
Author: David Fifield <[email protected]>
Date:   Wed Mar 21 22:52:30 2018 -0700

    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.
---
 proxy-go/snowflake.go | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/proxy-go/snowflake.go b/proxy-go/snowflake.go
index 5a5925e..7bb435c 100644
--- a/proxy-go/snowflake.go
+++ b/proxy-go/snowflake.go
@@ -25,6 +25,7 @@ import (
 const defaultBrokerURL = "https://snowflake-reg.appspot.com/";
 const defaultRelayURL = "wss://snowflake.bamsoftware.com/"
 const defaultSTUNURL = "stun:stun.l.google.com:19302"
+const pollInterval = 5 * time.Second
 
 var brokerURL *url.URL
 var relayURL string
@@ -133,7 +134,19 @@ func genSessionID() string {
 
 func pollOffer(sid string) *webrtc.SessionDescription {
        broker := brokerURL.ResolveReference(&url.URL{Path: "proxy"})
+       timeOfNextPoll := time.Now()
        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.Header.Set("X-Session-ID", sid)
                resp, err := client.Do(req)

_______________________________________________
tor-commits mailing list
[email protected]
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits

Reply via email to