Commit a2292ce3 authored by David Fifield's avatar David Fifield
Browse files

Make timeout constants into time.Duration values.

This slightly changes some log messages.
parent dfb83c66
...@@ -6,11 +6,12 @@ import ( ...@@ -6,11 +6,12 @@ import (
"log" "log"
"net" "net"
"sync" "sync"
"time"
) )
const ( const (
ReconnectTimeout = 10 ReconnectTimeout = 10 * time.Second
SnowflakeTimeout = 30 SnowflakeTimeout = 30 * time.Second
) )
// Given an accepted SOCKS connection, establish a WebRTC connection to the // Given an accepted SOCKS connection, establish a WebRTC connection to the
......
...@@ -117,9 +117,9 @@ func (c *WebRTCPeer) checkForStaleness() { ...@@ -117,9 +117,9 @@ func (c *WebRTCPeer) checkForStaleness() {
if c.closed { if c.closed {
return return
} }
if time.Since(c.lastReceive).Seconds() > SnowflakeTimeout { if time.Since(c.lastReceive) > SnowflakeTimeout {
log.Println("WebRTC: No messages received for", SnowflakeTimeout, log.Printf("WebRTC: No messages received for %v -- closing stale connection.",
"seconds -- closing stale connection.") SnowflakeTimeout)
c.Close() c.Close()
return return
} }
...@@ -314,8 +314,8 @@ func (c *WebRTCPeer) exchangeSDP() error { ...@@ -314,8 +314,8 @@ func (c *WebRTCPeer) exchangeSDP() error {
go c.sendOfferToBroker() go c.sendOfferToBroker()
answer, ok = <-c.answerChannel // Blocks... answer, ok = <-c.answerChannel // Blocks...
if !ok || nil == answer { if !ok || nil == answer {
log.Printf("Failed to retrieve answer. Retrying in %d seconds", ReconnectTimeout) log.Printf("Failed to retrieve answer. Retrying in %v", ReconnectTimeout)
<-time.After(time.Second * ReconnectTimeout) <-time.After(ReconnectTimeout)
answer = nil answer = nil
} }
} }
......
...@@ -31,11 +31,11 @@ func ConnectLoop(snowflakes sf.SnowflakeCollector) { ...@@ -31,11 +31,11 @@ func ConnectLoop(snowflakes sf.SnowflakeCollector) {
// Check if ending is necessary. // Check if ending is necessary.
_, err := snowflakes.Collect() _, err := snowflakes.Collect()
if err != nil { if err != nil {
log.Printf("WebRTC: %v Retrying in %v seconds...", log.Printf("WebRTC: %v Retrying in %v...",
err, sf.ReconnectTimeout) err, sf.ReconnectTimeout)
} }
select { select {
case <-time.After(time.Second * sf.ReconnectTimeout): case <-time.After(sf.ReconnectTimeout):
continue continue
case <-snowflakes.Melted(): case <-snowflakes.Melted():
log.Println("ConnectLoop: stopped.") log.Println("ConnectLoop: stopped.")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment