mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
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:
parent
eb13b2ff4b
commit
ad377cf3df
1 changed files with 11 additions and 6 deletions
|
@ -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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue