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

Fix: don't skip proxy activity update when client counts change to 0

Rod Hynes 1 год назад
Родитель
Сommit
f3f82b1489
1 измененных файлов с 13 добавлено и 3 удалено
  1. 13 3
      psiphon/common/inproxy/proxy.go

+ 13 - 3
psiphon/common/inproxy/proxy.go

@@ -58,6 +58,8 @@ type Proxy struct {
 
 
 	config                *ProxyConfig
 	config                *ProxyConfig
 	activityUpdateWrapper *activityUpdateWrapper
 	activityUpdateWrapper *activityUpdateWrapper
+	lastConnectingClients int32
+	lastConnectedClients  int32
 
 
 	networkDiscoveryMutex     sync.Mutex
 	networkDiscoveryMutex     sync.Mutex
 	networkDiscoveryRunOnce   bool
 	networkDiscoveryRunOnce   bool
@@ -242,6 +244,9 @@ func (p *Proxy) Run(ctx context.Context) {
 	// for PeakUp/DownstreamBytesPerSecond. This is also a reasonable
 	// for PeakUp/DownstreamBytesPerSecond. This is also a reasonable
 	// frequency for invoking the ActivityUpdater and updating UI widgets.
 	// frequency for invoking the ActivityUpdater and updating UI widgets.
 
 
+	p.lastConnectingClients = 0
+	p.lastConnectedClients = 0
+
 	activityUpdatePeriod := 1 * time.Second
 	activityUpdatePeriod := 1 * time.Second
 	ticker := time.NewTicker(activityUpdatePeriod)
 	ticker := time.NewTicker(activityUpdatePeriod)
 	defer ticker.Stop()
 	defer ticker.Stop()
@@ -287,11 +292,16 @@ func (p *Proxy) activityUpdate(period time.Duration) {
 	greaterThanSwapInt64(&p.peakBytesUp, bytesUp)
 	greaterThanSwapInt64(&p.peakBytesUp, bytesUp)
 	greaterThanSwapInt64(&p.peakBytesDown, bytesDown)
 	greaterThanSwapInt64(&p.peakBytesDown, bytesDown)
 
 
-	if connectingClients == 0 &&
-		connectedClients == 0 &&
+	clientsChanged := connectingClients != p.lastConnectingClients ||
+		connectedClients != p.lastConnectedClients
+
+	p.lastConnectingClients = connectingClients
+	p.lastConnectedClients = connectedClients
+
+	if !clientsChanged &&
 		bytesUp == 0 &&
 		bytesUp == 0 &&
 		bytesDown == 0 {
 		bytesDown == 0 {
-		// Skip the activity callback on idle.
+		// Skip the activity callback on idle bytes or no change in client counts.
 		return
 		return
 	}
 	}