commit 2fb52c86399b343b296f985a3aa6d568b7b09c96 Author: David Fifield david@bamsoftware.com Date: Tue Dec 24 19:57:01 2019 -0700
Check for an invalid broker URL at a higher level.
Instead of returning nil from NewBrokerChannel and having WebRTCDialer.Catch check for nil, let NewBrokerChannel return an error and bail out before calling WebRTCDialer.Catch.
Suggested by cohosh. https://bugs.torproject.org/33040#comment:3 --- client/lib/rendezvous.go | 9 +++------ client/snowflake.go | 5 ++++- 2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/client/lib/rendezvous.go b/client/lib/rendezvous.go index 0b15f68..fef0eb5 100644 --- a/client/lib/rendezvous.go +++ b/client/lib/rendezvous.go @@ -48,10 +48,10 @@ func CreateBrokerTransport() http.RoundTripper { // Construct a new BrokerChannel, where: // |broker| is the full URL of the facilitating program which assigns proxies // to clients, and |front| is the option fronting domain. -func NewBrokerChannel(broker string, front string, transport http.RoundTripper) *BrokerChannel { +func NewBrokerChannel(broker string, front string, transport http.RoundTripper) (*BrokerChannel, error) { targetURL, err := url.Parse(broker) if err != nil { - return nil + return nil, err } log.Println("Rendezvous using Broker at:", broker) bc := new(BrokerChannel) @@ -63,7 +63,7 @@ func NewBrokerChannel(broker string, front string, transport http.RoundTripper) }
bc.transport = transport - return bc + return bc, nil }
func limitedRead(r io.Reader, limit int64) ([]byte, error) { @@ -141,9 +141,6 @@ func NewWebRTCDialer(broker *BrokerChannel, iceServers []webrtc.ICEServer) *WebR
// Initialize a WebRTC Connection by signaling through the broker. func (w WebRTCDialer) Catch() (Snowflake, error) { - if nil == w.BrokerChannel { - return nil, errors.New("cannot Dial WebRTC without a BrokerChannel") - } // TODO: [#3] Fetch ICE server information from Broker. // TODO: [#18] Consider TURN servers here too. connection := NewWebRTCPeer(w.webrtcConfig, w.BrokerChannel) diff --git a/client/snowflake.go b/client/snowflake.go index 1d7907b..7cb9451 100644 --- a/client/snowflake.go +++ b/client/snowflake.go @@ -130,7 +130,10 @@ func main() { snowflakes := sf.NewPeers(*max)
// Use potentially domain-fronting broker to rendezvous. - broker := sf.NewBrokerChannel(*brokerURL, *frontDomain, sf.CreateBrokerTransport()) + broker, err := sf.NewBrokerChannel(*brokerURL, *frontDomain, sf.CreateBrokerTransport()) + if err != nil { + log.Fatalf("parsing broker URL: %v", err) + } snowflakes.Tongue = sf.NewWebRTCDialer(broker, iceServers)
// Use a real logger to periodically output how much traffic is happening.