[tor-commits] [snowflake/master] Use chan struct{} instead

arlo at torproject.org arlo at torproject.org
Tue Jan 19 21:41:49 UTC 2016


commit dcb901e4086636b3ed3248096021f23bb4363cda
Author: Arlo Breault <arlolra at gmail.com>
Date:   Tue Jan 19 13:41:19 2016 -0800

    Use chan struct{} instead
    
     * Similar to a77ae6b771e5550b3a5370f7b1f2c0e434f4e9eb.
---
 server/snowflake.go |   12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/server/snowflake.go b/server/snowflake.go
index 88eecca..1da419f 100644
--- a/server/snowflake.go
+++ b/server/snowflake.go
@@ -100,12 +100,12 @@ func datachannelHandler(conn *webRTCConn) {
 }
 
 // Create a PeerConnection from an SDP offer. Blocks until the gathering of ICE
-// candidates is complete and and answer is available in LocalDescription.
+// candidates is complete and the answer is available in LocalDescription.
 // Installs an OnDataChannel callback that creates a webRTCConn and passes it to
 // datachannelHandler.
 func makePeerConnectionFromOffer(sdp *webrtc.SessionDescription, config *webrtc.Configuration) (*webrtc.PeerConnection, error) {
 	errChan := make(chan error)
-	answerChan := make(chan *webrtc.SessionDescription)
+	answerChan := make(chan struct{})
 
 	pc, err := webrtc.NewPeerConnection(config)
 	if err != nil {
@@ -115,7 +115,7 @@ func makePeerConnectionFromOffer(sdp *webrtc.SessionDescription, config *webrtc.
 		panic("OnNegotiationNeeded")
 	}
 	pc.OnIceComplete = func() {
-		answerChan <- pc.LocalDescription()
+		answerChan <- struct{}{}
 	}
 	pc.OnDataChannel = func(dc *data.Channel) {
 		log.Println("OnDataChannel")
@@ -170,7 +170,11 @@ func makePeerConnectionFromOffer(sdp *webrtc.SessionDescription, config *webrtc.
 	case err = <-errChan:
 		pc.Close()
 		return nil, err
-	case <-answerChan:
+	case _, ok := <-answerChan:
+		if !ok {
+			pc.Close()
+			return nil, fmt.Errorf("Failed gathering ICE candidates.")
+		}
 	}
 
 	return pc, nil



More information about the tor-commits mailing list