mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Simplify WebRTCPeer.exchangeSDP.
No need to run sendOfferToBroker in a goroutine.
This commit is contained in:
parent
8caa737700
commit
5787d5b8b0
1 changed files with 14 additions and 31 deletions
|
@ -25,7 +25,6 @@ type WebRTCPeer struct {
|
|||
broker *BrokerChannel
|
||||
|
||||
offerChannel chan *webrtc.SessionDescription
|
||||
answerChannel chan *webrtc.SessionDescription
|
||||
recvPipe *io.PipeReader
|
||||
writePipe *io.PipeWriter
|
||||
lastReceive time.Time
|
||||
|
@ -53,7 +52,6 @@ func NewWebRTCPeer(config *webrtc.Configuration,
|
|||
connection.config = config
|
||||
connection.broker = broker
|
||||
connection.offerChannel = make(chan *webrtc.SessionDescription, 1)
|
||||
connection.answerChannel = make(chan *webrtc.SessionDescription, 1)
|
||||
|
||||
// Override with something that's not NullLogger to have real logging.
|
||||
connection.BytesLogger = &BytesNullLogger{}
|
||||
|
@ -256,34 +254,22 @@ func (c *WebRTCPeer) establishDataChannel() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *WebRTCPeer) sendOfferToBroker() {
|
||||
if nil == c.broker {
|
||||
return
|
||||
}
|
||||
offer := c.pc.LocalDescription()
|
||||
answer, err := c.broker.Negotiate(offer)
|
||||
if nil != err || nil == answer {
|
||||
log.Printf("BrokerChannel Error: %s", err)
|
||||
answer = nil
|
||||
}
|
||||
c.answerChannel <- answer
|
||||
}
|
||||
|
||||
// exchangeSDP blocks until an SDP offer is available, sends it to the Broker,
|
||||
// then awaits the SDP answer.
|
||||
func (c *WebRTCPeer) exchangeSDP() error {
|
||||
<-c.offerChannel
|
||||
// Keep trying the same offer until a valid answer arrives.
|
||||
var ok bool
|
||||
var answer *webrtc.SessionDescription
|
||||
for nil == answer {
|
||||
go c.sendOfferToBroker()
|
||||
answer, ok = <-c.answerChannel // Blocks...
|
||||
if !ok || nil == answer {
|
||||
for {
|
||||
var err error
|
||||
// Send offer to broker (blocks).
|
||||
answer, err = c.broker.Negotiate(c.pc.LocalDescription())
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
log.Printf("BrokerChannel Error: %s", err)
|
||||
log.Printf("Failed to retrieve answer. Retrying in %v", ReconnectTimeout)
|
||||
<-time.After(ReconnectTimeout)
|
||||
answer = nil
|
||||
}
|
||||
}
|
||||
log.Printf("Received Answer.\n")
|
||||
err := c.pc.SetRemoteDescription(*answer)
|
||||
|
@ -299,9 +285,6 @@ func (c *WebRTCPeer) cleanup() {
|
|||
if nil != c.offerChannel {
|
||||
close(c.offerChannel)
|
||||
}
|
||||
if nil != c.answerChannel {
|
||||
close(c.answerChannel)
|
||||
}
|
||||
// Close this side of the SOCKS pipe.
|
||||
if nil != c.writePipe {
|
||||
c.writePipe.Close()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue