mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05: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.
|
// Obtain currentNATTypeAccess before access.
|
||||||
var currentNATType = NATUnknown
|
var currentNATType = NATUnknown
|
||||||
|
|
||||||
|
func getCurrentNATType() string {
|
||||||
|
currentNATTypeAccess.RLock()
|
||||||
|
defer currentNATTypeAccess.RUnlock()
|
||||||
|
return currentNATType
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
sessionIDLength = 16
|
sessionIDLength = 16
|
||||||
)
|
)
|
||||||
|
@ -190,9 +196,7 @@ func (s *SignalingServer) pollOffer(sid string, shutdown chan struct{}) *webrtc.
|
||||||
return nil
|
return nil
|
||||||
default:
|
default:
|
||||||
numClients := int((tokens.count() / 8) * 8) // Round down to 8
|
numClients := int((tokens.count() / 8) * 8) // Round down to 8
|
||||||
currentNATTypeAccess.RLock()
|
currentNATTypeLoaded := getCurrentNATType()
|
||||||
currentNATTypeLoaded := currentNATType
|
|
||||||
currentNATTypeAccess.RUnlock()
|
|
||||||
body, err := messages.EncodePollRequest(sid, "standalone", currentNATTypeLoaded, numClients)
|
body, err := messages.EncodePollRequest(sid, "standalone", currentNATTypeLoaded, numClients)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error encoding poll message: %s", err.Error())
|
log.Printf("Error encoding poll message: %s", err.Error())
|
||||||
|
@ -541,9 +545,7 @@ func (sf *SnowflakeProxy) Start() error {
|
||||||
// use probetest to determine NAT compatability
|
// use probetest to determine NAT compatability
|
||||||
sf.checkNATType(config, sf.NATProbeURL)
|
sf.checkNATType(config, sf.NATProbeURL)
|
||||||
|
|
||||||
currentNATTypeAccess.RLock()
|
currentNATTypeLoaded := getCurrentNATType()
|
||||||
currentNATTypeLoaded := currentNATType
|
|
||||||
currentNATTypeAccess.RUnlock()
|
|
||||||
|
|
||||||
log.Printf("NAT type: %s", currentNATTypeLoaded)
|
log.Printf("NAT type: %s", currentNATTypeLoaded)
|
||||||
|
|
||||||
|
@ -632,9 +634,7 @@ func (sf *SnowflakeProxy) checkNATType(config webrtc.Configuration, probeURL str
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
currentNATTypeAccess.RLock()
|
currentNATTypeLoaded := getCurrentNATType()
|
||||||
currentNATTypeLoaded := currentNATType
|
|
||||||
currentNATTypeAccess.RUnlock()
|
|
||||||
|
|
||||||
currentNATTypeTestResult := NATUnknown
|
currentNATTypeTestResult := NATUnknown
|
||||||
select {
|
select {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue