mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
Move datachannel timeout to after sendAnswer return
This commit is contained in:
parent
dd927050d9
commit
2e4383434f
1 changed files with 14 additions and 19 deletions
|
@ -263,9 +263,7 @@ func datachannelHandler(conn *webRTCConn, remoteAddr net.Addr) {
|
||||||
// candidates is complete and the 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
|
// Installs an OnDataChannel callback that creates a webRTCConn and passes it to
|
||||||
// datachannelHandler.
|
// datachannelHandler.
|
||||||
func makePeerConnectionFromOffer(sdp *webrtc.SessionDescription, config *webrtc.Configuration) (*webrtc.PeerConnection, error) {
|
func makePeerConnectionFromOffer(sdp *webrtc.SessionDescription, config *webrtc.Configuration, dataChan chan struct{}) (*webrtc.PeerConnection, error) {
|
||||||
|
|
||||||
dataChan := make(chan struct{})
|
|
||||||
pc, err := webrtc.NewPeerConnection(config)
|
pc, err := webrtc.NewPeerConnection(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("accept: NewPeerConnection: %s", err)
|
return nil, fmt.Errorf("accept: NewPeerConnection: %s", err)
|
||||||
|
@ -333,21 +331,6 @@ func makePeerConnectionFromOffer(sdp *webrtc.SessionDescription, config *webrtc.
|
||||||
return nil, err
|
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
|
return pc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,7 +341,8 @@ func runSession(sid string) {
|
||||||
retToken()
|
retToken()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
pc, err := makePeerConnectionFromOffer(offer, config)
|
dataChan := make(chan struct{})
|
||||||
|
pc, err := makePeerConnectionFromOffer(offer, config, dataChan)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error making WebRTC connection: %s", err)
|
log.Printf("error making WebRTC connection: %s", err)
|
||||||
retToken()
|
retToken()
|
||||||
|
@ -371,6 +355,17 @@ func runSession(sid string) {
|
||||||
retToken()
|
retToken()
|
||||||
return
|
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() {
|
func main() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue