mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
Remove for loop around broker.Negotiate
Instead of continuously polling the broker until the client receives a snowflake, fail back to the Connect() loop and try again to collect more peers after ReconnectTimeout.
This commit is contained in:
parent
ece43cbfcf
commit
665d76c5b0
1 changed files with 4 additions and 17 deletions
|
@ -112,7 +112,10 @@ func (c *WebRTCPeer) connect(config *webrtc.Configuration, broker *BrokerChannel
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
answer := exchangeSDP(broker, c.pc.LocalDescription())
|
answer, err := broker.Negotiate(c.pc.LocalDescription())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
log.Printf("Received Answer.\n")
|
log.Printf("Received Answer.\n")
|
||||||
err = c.pc.SetRemoteDescription(*answer)
|
err = c.pc.SetRemoteDescription(*answer)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
@ -217,22 +220,6 @@ func (c *WebRTCPeer) establishDataChannel() (*webrtc.DataChannel, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// exchangeSDP sends the local SDP offer to the Broker, awaits the SDP answer,
|
|
||||||
// and returns the answer.
|
|
||||||
func exchangeSDP(broker *BrokerChannel, offer *webrtc.SessionDescription) *webrtc.SessionDescription {
|
|
||||||
// Keep trying the same offer until a valid answer arrives.
|
|
||||||
for {
|
|
||||||
// Send offer to broker (blocks).
|
|
||||||
answer, err := broker.Negotiate(offer)
|
|
||||||
if err == nil {
|
|
||||||
return answer
|
|
||||||
}
|
|
||||||
log.Printf("BrokerChannel Error: %s", err)
|
|
||||||
log.Printf("Failed to retrieve answer. Retrying in %v", ReconnectTimeout)
|
|
||||||
<-time.After(ReconnectTimeout)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close all channels and transports
|
// Close all channels and transports
|
||||||
func (c *WebRTCPeer) cleanup() {
|
func (c *WebRTCPeer) cleanup() {
|
||||||
// Close this side of the SOCKS pipe.
|
// Close this side of the SOCKS pipe.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue