Represent NATTypeMeasurementInterval in time.Duration

Adopted the change in according to the recommendation from

https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/merge_requests/62#note_2761566
This commit is contained in:
Shelikhoo 2021-11-16 19:25:27 +00:00
parent c49f72eb0c
commit 0c62d806a4
No known key found for this signature in database
GPG key ID: C4D5E79D22B25316
2 changed files with 6 additions and 6 deletions

View file

@ -112,9 +112,9 @@ type SnowflakeProxy struct {
RelayURL string RelayURL string
// NATProbeURL is the URL of the probe service we use for NAT checks // NATProbeURL is the URL of the probe service we use for NAT checks
NATProbeURL string NATProbeURL string
// NATTypeMeasurementIntervalSecond is time in second before NAT type is retested // NATTypeMeasurementInterval is time before NAT type is retested
NATTypeMeasurementIntervalSecond uint NATTypeMeasurementInterval time.Duration
shutdown chan struct{} shutdown chan struct{}
} }
// Checks whether an IP address is a remote address for the client // Checks whether an IP address is a remote address for the client
@ -550,14 +550,14 @@ func (sf *SnowflakeProxy) Start() error {
log.Printf("NAT type: %s", currentNATTypeLoaded) log.Printf("NAT type: %s", currentNATTypeLoaded)
NatRetestTask := task.Periodic{ NatRetestTask := task.Periodic{
Interval: time.Second * time.Duration(sf.NATTypeMeasurementIntervalSecond), Interval: sf.NATTypeMeasurementInterval,
Execute: func() error { Execute: func() error {
sf.checkNATType(config, sf.NATProbeURL) sf.checkNATType(config, sf.NATProbeURL)
return nil return nil
}, },
} }
if sf.NATTypeMeasurementIntervalSecond != 0 { if sf.NATTypeMeasurementInterval != 0 {
NatRetestTask.Start() NatRetestTask.Start()
defer NatRetestTask.Close() defer NatRetestTask.Close()
} }

View file

@ -31,7 +31,7 @@ func main() {
KeepLocalAddresses: *keepLocalAddresses, KeepLocalAddresses: *keepLocalAddresses,
RelayURL: *relayURL, RelayURL: *relayURL,
NATTypeMeasurementIntervalSecond: uint(NATTypeMeasurementInterval.Seconds()), NATTypeMeasurementInterval: *NATTypeMeasurementInterval,
} }
var logOutput io.Writer = os.Stderr var logOutput io.Writer = os.Stderr