[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [snowflake/master] Stop using OnIceComplete in server-webrtc



commit d7676d2b9e45c957bf39ea2d5662996aeab5b4de
Author: Arlo Breault <arlolra@xxxxxxxxx>
Date:   Tue May 14 16:36:27 2019 -0400

    Stop using OnIceComplete in server-webrtc
    
    Similar to c28c8ca for proxy-goc
---
 server-webrtc/snowflake.go | 40 +++++++++++++---------------------------
 1 file changed, 13 insertions(+), 27 deletions(-)

diff --git a/server-webrtc/snowflake.go b/server-webrtc/snowflake.go
index be9f012..5923d6b 100644
--- a/server-webrtc/snowflake.go
+++ b/server-webrtc/snowflake.go
@@ -113,9 +113,6 @@ func datachannelHandler(conn *webRTCConn) {
 // 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 struct{})
-
 	pc, err := webrtc.NewPeerConnection(config)
 	if err != nil {
 		return nil, fmt.Errorf("accept: NewPeerConnection: %s", err)
@@ -123,9 +120,6 @@ func makePeerConnectionFromOffer(sdp *webrtc.SessionDescription, config *webrtc.
 	pc.OnNegotiationNeeded = func() {
 		panic("OnNegotiationNeeded")
 	}
-	pc.OnIceComplete = func() {
-		answerChan <- struct{}{}
-	}
 	pc.OnDataChannel = func(dc *webrtc.DataChannel) {
 		log.Println("OnDataChannel")
 
@@ -164,30 +158,22 @@ func makePeerConnectionFromOffer(sdp *webrtc.SessionDescription, config *webrtc.
 	}
 	log.Println("sdp offer successfully received.")
 
-	go func() {
-		log.Println("Generating answer...")
-		answer, err := pc.CreateAnswer() // blocking
-		if err != nil {
-			errChan <- err
-			return
-		}
-		err = pc.SetLocalDescription(answer)
-		if err != nil {
-			errChan <- err
-			return
-		}
-	}()
+	log.Println("Generating answer...")
+	answer, err := pc.CreateAnswer()
+	if err != nil {
+		pc.Destroy()
+		return nil, err
+	}
+
+	if answer == nil {
+		pc.Destroy()
+		return nil, fmt.Errorf("Failed gathering ICE candidates.")
+	}
 
-	// Wait until answer is ready.
-	select {
-	case err = <-errChan:
+	err = pc.SetLocalDescription(answer)
+	if err != nil {
 		pc.Destroy()
 		return nil, err
-	case _, ok := <-answerChan:
-		if !ok {
-			pc.Destroy()
-			return nil, fmt.Errorf("Failed gathering ICE candidates.")
-		}
 	}
 
 	return pc, nil



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits