mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Extract function getCurrentNATType()
Adopted the change in according to the recommendation from https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/merge_requests/62#note_2759900
This commit is contained in:
parent
a6a53ff8ce
commit
2547883cf9
1 changed files with 9 additions and 9 deletions
|
@ -80,6 +80,12 @@ var currentNATTypeAccess = &sync.RWMutex{}
|
|||
// Obtain currentNATTypeAccess before access.
|
||||
var currentNATType = NATUnknown
|
||||
|
||||
func getCurrentNATType() string {
|
||||
currentNATTypeAccess.RLock()
|
||||
defer currentNATTypeAccess.RUnlock()
|
||||
return currentNATType
|
||||
}
|
||||
|
||||
const (
|
||||
sessionIDLength = 16
|
||||
)
|
||||
|
@ -190,9 +196,7 @@ func (s *SignalingServer) pollOffer(sid string, shutdown chan struct{}) *webrtc.
|
|||
return nil
|
||||
default:
|
||||
numClients := int((tokens.count() / 8) * 8) // Round down to 8
|
||||
currentNATTypeAccess.RLock()
|
||||
currentNATTypeLoaded := currentNATType
|
||||
currentNATTypeAccess.RUnlock()
|
||||
currentNATTypeLoaded := getCurrentNATType()
|
||||
body, err := messages.EncodePollRequest(sid, "standalone", currentNATTypeLoaded, numClients)
|
||||
if err != nil {
|
||||
log.Printf("Error encoding poll message: %s", err.Error())
|
||||
|
@ -541,9 +545,7 @@ func (sf *SnowflakeProxy) Start() error {
|
|||
// use probetest to determine NAT compatability
|
||||
sf.checkNATType(config, sf.NATProbeURL)
|
||||
|
||||
currentNATTypeAccess.RLock()
|
||||
currentNATTypeLoaded := currentNATType
|
||||
currentNATTypeAccess.RUnlock()
|
||||
currentNATTypeLoaded := getCurrentNATType()
|
||||
|
||||
log.Printf("NAT type: %s", currentNATTypeLoaded)
|
||||
|
||||
|
@ -632,9 +634,7 @@ func (sf *SnowflakeProxy) checkNATType(config webrtc.Configuration, probeURL str
|
|||
return
|
||||
}
|
||||
|
||||
currentNATTypeAccess.RLock()
|
||||
currentNATTypeLoaded := currentNATType
|
||||
currentNATTypeAccess.RUnlock()
|
||||
currentNATTypeLoaded := getCurrentNATType()
|
||||
|
||||
currentNATTypeTestResult := NATUnknown
|
||||
select {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue