commit d6467ff5854627dcaefbef89bdd348bfe461da12 Author: David Fifield david@bamsoftware.com Date: Tue Dec 24 18:01:17 2019 -0700
Formatting improvements. --- client/lib/interfaces.go | 1 - client/lib/peers.go | 9 ++++----- client/lib/rendezvous.go | 8 +++----- client/snowflake.go | 22 +++++++++++----------- server/server.go | 4 ++-- 5 files changed, 20 insertions(+), 24 deletions(-)
diff --git a/client/lib/interfaces.go b/client/lib/interfaces.go index 609e610..f6e8240 100644 --- a/client/lib/interfaces.go +++ b/client/lib/interfaces.go @@ -30,7 +30,6 @@ type Tongue interface { // Interface for collecting some number of Snowflakes, for passing along // ultimately to the SOCKS handler. type SnowflakeCollector interface { - // Add a Snowflake to the collection. // Implementation should decide how to connect and maintain the webRTCConn. Collect() (Snowflake, error) diff --git a/client/lib/peers.go b/client/lib/peers.go index 5493bfd..12213e1 100644 --- a/client/lib/peers.go +++ b/client/lib/peers.go @@ -44,8 +44,7 @@ func (p *Peers) Collect() (Snowflake, error) { cnt := p.Count() s := fmt.Sprintf("Currently at [%d/%d]", cnt, p.capacity) if cnt >= p.capacity { - s = fmt.Sprintf("At capacity [%d/%d]", cnt, p.capacity) - return nil, errors.New(s) + return nil, fmt.Errorf("At capacity [%d/%d]", cnt, p.capacity) } log.Println("WebRTC: Collecting a new Snowflake.", s) // Engage the Snowflake Catching interface, which must be available. @@ -68,12 +67,12 @@ func (p *Peers) Pop() Snowflake { // Blocks until an available, valid snowflake appears. var snowflake Snowflake var ok bool - for nil == snowflake { + for snowflake == nil { snowflake, ok = <-p.snowflakeChan - conn := snowflake.(*WebRTCPeer) if !ok { return nil } + conn := snowflake.(*WebRTCPeer) if conn.closed { snowflake = nil } @@ -120,5 +119,5 @@ func (p *Peers) End() { p.activePeers.Remove(e) e = next } - log.Println("WebRTC: melted all", cnt, "snowflakes.") + log.Printf("WebRTC: melted all %d snowflakes.", cnt) } diff --git a/client/lib/rendezvous.go b/client/lib/rendezvous.go index 0c7225b..0b15f68 100644 --- a/client/lib/rendezvous.go +++ b/client/lib/rendezvous.go @@ -50,13 +50,13 @@ func CreateBrokerTransport() http.RoundTripper { // to clients, and |front| is the option fronting domain. func NewBrokerChannel(broker string, front string, transport http.RoundTripper) *BrokerChannel { targetURL, err := url.Parse(broker) - if nil != err { + if err != nil { return nil } log.Println("Rendezvous using Broker at:", broker) bc := new(BrokerChannel) bc.url = targetURL - if "" != front { // Optional front domain. + if front != "" { // Optional front domain. log.Println("Domain fronting using:", front) bc.Host = bc.url.Host bc.url.Host = front @@ -109,7 +109,6 @@ func (bc *BrokerChannel) Negotiate(offer *webrtc.SessionDescription) ( } answer := deserializeSessionDescription(string(body)) return answer, nil - case http.StatusServiceUnavailable: return nil, errors.New(BrokerError503) case http.StatusBadRequest: @@ -125,8 +124,7 @@ type WebRTCDialer struct { webrtcConfig *webrtc.Configuration }
-func NewWebRTCDialer( - broker *BrokerChannel, iceServers []webrtc.ICEServer) *WebRTCDialer { +func NewWebRTCDialer(broker *BrokerChannel, iceServers []webrtc.ICEServer) *WebRTCDialer { var config webrtc.Configuration if iceServers != nil { config = webrtc.Configuration{ diff --git a/client/snowflake.go b/client/snowflake.go index 28bf7e9..bd53f65 100644 --- a/client/snowflake.go +++ b/client/snowflake.go @@ -30,9 +30,9 @@ func ConnectLoop(snowflakes sf.SnowflakeCollector) { for { // Check if ending is necessary. _, err := snowflakes.Collect() - if nil != err { - log.Println("WebRTC:", err, - " Retrying in", sf.ReconnectTimeout, "seconds...") + if err != nil { + log.Printf("WebRTC: %v Retrying in %v seconds...", + err, sf.ReconnectTimeout) } select { case <-time.After(time.Second * sf.ReconnectTimeout): @@ -52,7 +52,7 @@ func socksAcceptLoop(ln *pt.SocksListener, snowflakes sf.SnowflakeCollector) { log.Println("SOCKS listening...") conn, err := ln.AcceptSocks() if err != nil { - if e, ok := err.(net.Error); ok && e.Temporary() { + if err, ok := err.(net.Error); ok && err.Temporary() { continue } log.Printf("SOCKS accept error: %s", err) @@ -66,7 +66,7 @@ func socksAcceptLoop(ln *pt.SocksListener, snowflakes sf.SnowflakeCollector) { } }
-//s is a comma-separated list of ICE server URLs +// s is a comma-separated list of ICE server URLs. func parseIceServers(s string) []webrtc.ICEServer { var servers []webrtc.ICEServer log.Println(s) @@ -98,9 +98,9 @@ func main() {
log.SetFlags(log.LstdFlags | log.LUTC)
- // Don't write to stderr; versions of tor earlier than about - // 0.3.5.6 do not read from the pipe, and eventually we will - // deadlock because the buffer is full. + // Don't write to stderr; versions of tor earlier than about 0.3.5.6 do + // not read from the pipe, and eventually we will deadlock because the + // buffer is full. // https://bugs.torproject.org/26360 // https://bugs.torproject.org/25600#comment:14 var logOutput = ioutil.Discard @@ -120,7 +120,7 @@ func main() { defer logFile.Close() logOutput = logFile } - //We want to send the log output through our scrubber first + // We want to send the log output through our scrubber first log.SetOutput(&safelog.LogScrubber{Output: logOutput})
log.Println("\n\n\n --- Starting Snowflake Client ---") @@ -194,10 +194,10 @@ func main() { }() }
- // wait for a signal + // Wait for a signal. <-sigChan
- // signal received, shut down + // Signal received, shut down. for _, ln := range listeners { ln.Close() } diff --git a/server/server.go b/server/server.go index 785b545..5ed56d3 100644 --- a/server/server.go +++ b/server/server.go @@ -345,10 +345,10 @@ func main() { }() }
- // wait for a signal + // Wait for a signal. sig := <-sigChan
- // signal received, shut down + // Signal received, shut down. log.Printf("caught signal %q, exiting", sig) for _, server := range servers { server.Close()
tor-commits@lists.torproject.org