mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Move pc.CreateOffer/pc.SetLocalDescription out of a goroutine.
This allows us to remove the internal errorChannel.
This commit is contained in:
parent
3520f4e8b9
commit
51bb49fa6f
1 changed files with 18 additions and 29 deletions
|
@ -28,7 +28,6 @@ type WebRTCPeer struct {
|
||||||
|
|
||||||
offerChannel chan *webrtc.SessionDescription
|
offerChannel chan *webrtc.SessionDescription
|
||||||
answerChannel chan *webrtc.SessionDescription
|
answerChannel chan *webrtc.SessionDescription
|
||||||
errorChannel chan error
|
|
||||||
recvPipe *io.PipeReader
|
recvPipe *io.PipeReader
|
||||||
writePipe *io.PipeWriter
|
writePipe *io.PipeWriter
|
||||||
lastReceive time.Time
|
lastReceive time.Time
|
||||||
|
@ -57,9 +56,6 @@ func NewWebRTCPeer(config *webrtc.Configuration,
|
||||||
connection.broker = broker
|
connection.broker = broker
|
||||||
connection.offerChannel = make(chan *webrtc.SessionDescription, 1)
|
connection.offerChannel = make(chan *webrtc.SessionDescription, 1)
|
||||||
connection.answerChannel = make(chan *webrtc.SessionDescription, 1)
|
connection.answerChannel = make(chan *webrtc.SessionDescription, 1)
|
||||||
// Error channel is mostly for reporting during the initial SDP offer
|
|
||||||
// creation & local description setting, which happens asynchronously.
|
|
||||||
connection.errorChannel = make(chan error, 1)
|
|
||||||
|
|
||||||
// Override with something that's not NullLogger to have real logging.
|
// Override with something that's not NullLogger to have real logging.
|
||||||
connection.BytesLogger = &BytesNullLogger{}
|
connection.BytesLogger = &BytesNullLogger{}
|
||||||
|
@ -167,21 +163,23 @@ func (c *WebRTCPeer) preparePeerConnection() error {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
c.pc = pc
|
c.pc = pc
|
||||||
go func() {
|
|
||||||
offer, err := pc.CreateOffer(nil)
|
offer, err := pc.CreateOffer(nil)
|
||||||
// TODO: Potentially timeout and retry if ICE isn't working.
|
// TODO: Potentially timeout and retry if ICE isn't working.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.errorChannel <- err
|
log.Println("Failed to prepare offer", err)
|
||||||
return
|
c.Close()
|
||||||
}
|
return err
|
||||||
log.Println("WebRTC: Created offer")
|
}
|
||||||
err = pc.SetLocalDescription(offer)
|
log.Println("WebRTC: Created offer")
|
||||||
if err != nil {
|
err = pc.SetLocalDescription(offer)
|
||||||
c.errorChannel <- err
|
if err != nil {
|
||||||
return
|
log.Println("Failed to prepare offer", err)
|
||||||
}
|
c.Close()
|
||||||
log.Println("WebRTC: Set local description")
|
return err
|
||||||
}()
|
}
|
||||||
|
log.Println("WebRTC: Set local description")
|
||||||
|
|
||||||
log.Println("WebRTC: PeerConnection created.")
|
log.Println("WebRTC: PeerConnection created.")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -276,13 +274,7 @@ func (c *WebRTCPeer) sendOfferToBroker() {
|
||||||
// exchangeSDP blocks until an SDP offer is available, sends it to the Broker,
|
// exchangeSDP blocks until an SDP offer is available, sends it to the Broker,
|
||||||
// then awaits the SDP answer.
|
// then awaits the SDP answer.
|
||||||
func (c *WebRTCPeer) exchangeSDP() error {
|
func (c *WebRTCPeer) exchangeSDP() error {
|
||||||
select {
|
<-c.offerChannel
|
||||||
case <-c.offerChannel:
|
|
||||||
case err := <-c.errorChannel:
|
|
||||||
log.Println("Failed to prepare offer", err)
|
|
||||||
c.Close()
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
// Keep trying the same offer until a valid answer arrives.
|
// Keep trying the same offer until a valid answer arrives.
|
||||||
var ok bool
|
var ok bool
|
||||||
var answer *webrtc.SessionDescription
|
var answer *webrtc.SessionDescription
|
||||||
|
@ -312,9 +304,6 @@ func (c *WebRTCPeer) cleanup() {
|
||||||
if nil != c.answerChannel {
|
if nil != c.answerChannel {
|
||||||
close(c.answerChannel)
|
close(c.answerChannel)
|
||||||
}
|
}
|
||||||
if nil != c.errorChannel {
|
|
||||||
close(c.errorChannel)
|
|
||||||
}
|
|
||||||
// Close this side of the SOCKS pipe.
|
// Close this side of the SOCKS pipe.
|
||||||
if nil != c.writePipe {
|
if nil != c.writePipe {
|
||||||
c.writePipe.Close()
|
c.writePipe.Close()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue