commit a2292ce35be6ba4b63e7c8dbac8b3c7bc220822a Author: David Fifield david@bamsoftware.com Date: Tue Dec 24 18:39:43 2019 -0700
Make timeout constants into time.Duration values.
This slightly changes some log messages. --- client/lib/snowflake.go | 5 +++-- client/lib/webrtc.go | 10 +++++----- client/snowflake.go | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/client/lib/snowflake.go b/client/lib/snowflake.go index 9ab6fc6..2065f73 100644 --- a/client/lib/snowflake.go +++ b/client/lib/snowflake.go @@ -6,11 +6,12 @@ import ( "log" "net" "sync" + "time" )
const ( - ReconnectTimeout = 10 - SnowflakeTimeout = 30 + ReconnectTimeout = 10 * time.Second + SnowflakeTimeout = 30 * time.Second )
// Given an accepted SOCKS connection, establish a WebRTC connection to the diff --git a/client/lib/webrtc.go b/client/lib/webrtc.go index 9d1ba37..8e06d98 100644 --- a/client/lib/webrtc.go +++ b/client/lib/webrtc.go @@ -117,9 +117,9 @@ func (c *WebRTCPeer) checkForStaleness() { if c.closed { return } - if time.Since(c.lastReceive).Seconds() > SnowflakeTimeout { - log.Println("WebRTC: No messages received for", SnowflakeTimeout, - "seconds -- closing stale connection.") + if time.Since(c.lastReceive) > SnowflakeTimeout { + log.Printf("WebRTC: No messages received for %v -- closing stale connection.", + SnowflakeTimeout) c.Close() return } @@ -314,8 +314,8 @@ func (c *WebRTCPeer) exchangeSDP() error { go c.sendOfferToBroker() answer, ok = <-c.answerChannel // Blocks... if !ok || nil == answer { - log.Printf("Failed to retrieve answer. Retrying in %d seconds", ReconnectTimeout) - <-time.After(time.Second * ReconnectTimeout) + log.Printf("Failed to retrieve answer. Retrying in %v", ReconnectTimeout) + <-time.After(ReconnectTimeout) answer = nil } } diff --git a/client/snowflake.go b/client/snowflake.go index af416be..edcbd4a 100644 --- a/client/snowflake.go +++ b/client/snowflake.go @@ -31,11 +31,11 @@ func ConnectLoop(snowflakes sf.SnowflakeCollector) { // Check if ending is necessary. _, err := snowflakes.Collect() if err != nil { - log.Printf("WebRTC: %v Retrying in %v seconds...", + log.Printf("WebRTC: %v Retrying in %v...", err, sf.ReconnectTimeout) } select { - case <-time.After(time.Second * sf.ReconnectTimeout): + case <-time.After(sf.ReconnectTimeout): continue case <-snowflakes.Melted(): log.Println("ConnectLoop: stopped.")
tor-commits@lists.torproject.org