From ad377cf3df5efc8405d89acb36e6e0719ec72a7d Mon Sep 17 00:00:00 2001 From: WofWca Date: Mon, 3 Mar 2025 00:28:47 +0400 Subject: [PATCH] refactor(proxy): move `pollBroker()` to `Start()` ...from `runSession()`. `runSession()` sounds like it should only be called when we actually get a client. This slightly modifies the behavior of the proxy: now it will not wait for the client connection to succeed / fail before polling the broker another time. This might make the verbose logs a little more messy. But the poll interval is still respected. --- proxy/lib/snowflake.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/proxy/lib/snowflake.go b/proxy/lib/snowflake.go index 18a321a..e635cb7 100644 --- a/proxy/lib/snowflake.go +++ b/proxy/lib/snowflake.go @@ -635,7 +635,11 @@ func (sf *SnowflakeProxy) makeNewPeerConnection( return pc, nil } -func (sf *SnowflakeProxy) runSession(sid string) { +func (sf *SnowflakeProxy) runSession( + offer *webrtc.SessionDescription, + relayURL string, + sid string, +) { connectedToClient := false defer func() { if !connectedToClient { @@ -644,10 +648,6 @@ func (sf *SnowflakeProxy) runSession(sid string) { // Otherwise we'll `tokens.ret()` when the connection finishes. }() - offer, relayURL := broker.pollOffer(sid, sf.ProxyType, sf.RelayDomainNamePattern) - if offer == nil { - return - } log.Printf("Received Offer From Broker: \n\t%s", strings.ReplaceAll(offer.SDP, "\n", "\n\t")) if relayURL != "" { @@ -844,7 +844,12 @@ func (sf *SnowflakeProxy) Start() error { default: tokens.get() sessionID := genSessionID() - sf.runSession(sessionID) + offer, relayURL := broker.pollOffer(sessionID, sf.ProxyType, sf.RelayDomainNamePattern) + if offer == nil { + tokens.ret() + continue + } + go sf.runSession(offer, relayURL, sessionID) } } return nil