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

[tor-commits] [snowflake/master] Move datachannel timeout to after sendAnswer return



commit 2e4383434f33a4f8e801974bbe70d8a4568b3d93
Author: Arlo Breault <arlolra@xxxxxxxxx>
Date:   Mon May 20 15:43:07 2019 -0400

    Move datachannel timeout to after sendAnswer return
---
 proxy-go/snowflake.go | 33 ++++++++++++++-------------------
 1 file changed, 14 insertions(+), 19 deletions(-)

diff --git a/proxy-go/snowflake.go b/proxy-go/snowflake.go
index 12190ac..858320b 100644
--- a/proxy-go/snowflake.go
+++ b/proxy-go/snowflake.go
@@ -263,9 +263,7 @@ func datachannelHandler(conn *webRTCConn, remoteAddr net.Addr) {
 // 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) {
-
-	dataChan := make(chan struct{})
+func makePeerConnectionFromOffer(sdp *webrtc.SessionDescription, config *webrtc.Configuration, dataChan chan struct{}) (*webrtc.PeerConnection, error) {
 	pc, err := webrtc.NewPeerConnection(config)
 	if err != nil {
 		return nil, fmt.Errorf("accept: NewPeerConnection: %s", err)
@@ -333,21 +331,6 @@ func makePeerConnectionFromOffer(sdp *webrtc.SessionDescription, config *webrtc.
 		return nil, err
 	}
 
-	// Set a timeout on peerconnection. If the connection state has not
-	// advanced to PeerConnectionStateConnected in this time,
-	// destroy the peer connection and return the token.
-	go func() {
-		select {
-		case <-dataChan:
-			log.Println("Connection successful.")
-		case <-time.After(dataChannelTimeout):
-			log.Println("Timed out waiting for client to open data channel.")
-			pc.Destroy()
-			retToken()
-		}
-
-	}()
-
 	return pc, nil
 }
 
@@ -358,7 +341,8 @@ func runSession(sid string) {
 		retToken()
 		return
 	}
-	pc, err := makePeerConnectionFromOffer(offer, config)
+	dataChan := make(chan struct{})
+	pc, err := makePeerConnectionFromOffer(offer, config, dataChan)
 	if err != nil {
 		log.Printf("error making WebRTC connection: %s", err)
 		retToken()
@@ -371,6 +355,17 @@ func runSession(sid string) {
 		retToken()
 		return
 	}
+	// Set a timeout on peerconnection. If the connection state has not
+	// advanced to PeerConnectionStateConnected in this time,
+	// destroy the peer connection and return the token.
+	select {
+	case <-dataChan:
+		log.Println("Connection successful.")
+	case <-time.After(dataChannelTimeout):
+		log.Println("Timed out waiting for client to open data channel.")
+		pc.Destroy()
+		retToken()
+	}
 }
 
 func main() {

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