diff options
author | Cecylia Bocovich <cohosh@torproject.org> | 2020-11-13 15:08:00 -0500 |
---|---|---|
committer | Cecylia Bocovich <cohosh@torproject.org> | 2020-11-23 12:10:59 -0500 |
commit | 665d76c5b04c4e470d85a826ea617a2404ed4a1d (patch) | |
tree | 97a04a2dd103011a3a446df736a4f2e57e11f7c8 | |
parent | ece43cbfcfc328bf0d45ee1ce5998ea295035af4 (diff) | |
download | snowflake-665d76c5b04c4e470d85a826ea617a2404ed4a1d.tar.gz snowflake-665d76c5b04c4e470d85a826ea617a2404ed4a1d.zip |
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.
-rw-r--r-- | client/lib/webrtc.go | 21 |
1 files changed, 4 insertions, 17 deletions
diff --git a/client/lib/webrtc.go b/client/lib/webrtc.go index af5a45a..3a23ffc 100644 --- a/client/lib/webrtc.go +++ b/client/lib/webrtc.go @@ -112,7 +112,10 @@ func (c *WebRTCPeer) connect(config *webrtc.Configuration, broker *BrokerChannel if err != nil { 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") err = c.pc.SetRemoteDescription(*answer) 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 func (c *WebRTCPeer) cleanup() { // Close this side of the SOCKS pipe. |