Просмотр исходного кода

Add short delay to immediate status request

Rod Hynes 10 лет назад
Родитель
Сommit
9ac183f7a8
2 измененных файлов с 9 добавлено и 2 удалено
  1. 2 0
      psiphon/config.go
  2. 7 2
      psiphon/tunnel.go

+ 2 - 0
psiphon/config.go

@@ -56,6 +56,8 @@ const (
 	PSIPHON_API_SHUTDOWN_SERVER_TIMEOUT            = 1 * time.Second
 	PSIPHON_API_STATUS_REQUEST_PERIOD_MIN          = 5 * time.Minute
 	PSIPHON_API_STATUS_REQUEST_PERIOD_MAX          = 10 * time.Minute
+	PSIPHON_API_STATUS_REQUEST_SHORT_PERIOD_MIN    = 5 * time.Second
+	PSIPHON_API_STATUS_REQUEST_SHORT_PERIOD_MAX    = 10 * time.Second
 	PSIPHON_API_STATUS_REQUEST_PADDING_MAX_BYTES   = 256
 	PSIPHON_API_CONNECTED_REQUEST_PERIOD           = 24 * time.Hour
 	PSIPHON_API_CONNECTED_REQUEST_RETRY_PERIOD     = 5 * time.Second

+ 7 - 2
psiphon/tunnel.go

@@ -580,11 +580,16 @@ func (tunnel *Tunnel) operateTunnel(tunnelOwner TunnelOwner) {
 	// tunnelDurations.
 	// Note: this may not be effective when there's an outstanding
 	// asynchronous untunneled final status request is holding the
-	// tunnel duration records.
+	// tunnel duration records. It may also conflict with other
+	// tunnel candidates which attempt to send an immediate request
+	// before being discarded. For now, we mitigate this with a short,
+	// random delay.
 	unreported := CountUnreportedTunnelDurations()
 	if unreported > 0 {
 		NoticeInfo("Unreported tunnel durations: %d", unreported)
-		statsTimer.Reset(0)
+		statsTimer.Reset(MakeRandomPeriod(
+			PSIPHON_API_STATUS_REQUEST_SHORT_PERIOD_MIN,
+			PSIPHON_API_STATUS_REQUEST_SHORT_PERIOD_MAX))
 	}
 
 	nextSshKeepAlivePeriod := func() time.Duration {