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.
This commit is contained in:
WofWca 2025-03-03 00:28:47 +04:00
parent eb13b2ff4b
commit ad377cf3df

View file

@ -635,7 +635,11 @@ func (sf *SnowflakeProxy) makeNewPeerConnection(
return pc, nil return pc, nil
} }
func (sf *SnowflakeProxy) runSession(sid string) { func (sf *SnowflakeProxy) runSession(
offer *webrtc.SessionDescription,
relayURL string,
sid string,
) {
connectedToClient := false connectedToClient := false
defer func() { defer func() {
if !connectedToClient { if !connectedToClient {
@ -644,10 +648,6 @@ func (sf *SnowflakeProxy) runSession(sid string) {
// Otherwise we'll `tokens.ret()` when the connection finishes. // 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")) log.Printf("Received Offer From Broker: \n\t%s", strings.ReplaceAll(offer.SDP, "\n", "\n\t"))
if relayURL != "" { if relayURL != "" {
@ -844,7 +844,12 @@ func (sf *SnowflakeProxy) Start() error {
default: default:
tokens.get() tokens.get()
sessionID := genSessionID() 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 return nil