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

Fix: invalid count comparison in a68e746

Rod Hynes 9 лет назад
Родитель
Сommit
026ed7060a
2 измененных файлов с 17 добавлено и 7 удалено
  1. 5 3
      psiphon/controller.go
  2. 12 4
      psiphon/dataStore.go

+ 5 - 3
psiphon/controller.go

@@ -696,9 +696,11 @@ func (controller *Controller) classifyImpairedProtocol(failedTunnel *Tunnel) {
 	//
 	//
 	// Note: with controller.config.TunnelProtocol set, this will always reset once
 	// Note: with controller.config.TunnelProtocol set, this will always reset once
 	// that protocol has reached IMPAIRED_PROTOCOL_CLASSIFICATION_THRESHOLD.
 	// that protocol has reached IMPAIRED_PROTOCOL_CLASSIFICATION_THRESHOLD.
-	if len(controller.getImpairedProtocols()) ==
-		CountSupportedProtocols(
-			controller.config.EgressRegion, controller.config.TunnelProtocol) {
+	if CountNonImpairedProtocols(
+		controller.config.EgressRegion,
+		controller.config.TunnelProtocol,
+		controller.getImpairedProtocols()) == 0 {
+
 		controller.impairedProtocolClassification = make(map[string]int)
 		controller.impairedProtocolClassification = make(map[string]int)
 	}
 	}
 }
 }

+ 12 - 4
psiphon/dataStore.go

@@ -636,9 +636,13 @@ func CountServerEntries(region, tunnelProtocol string) int {
 	return count
 	return count
 }
 }
 
 
-// CountSupportedProtocols returns the number of distinct tunnel
-// protocols supported by stored server entries.
-func CountSupportedProtocols(region, tunnelProtocol string) int {
+// CountNonImpairedProtocols returns the number of distinct tunnel
+// protocols supported by stored server entries, excluding the
+// specified impaired protocols.
+func CountNonImpairedProtocols(
+	region, tunnelProtocol string,
+	impairedProtocols []string) int {
+
 	checkInitDataStore()
 	checkInitDataStore()
 
 
 	distinctProtocols := make(map[string]bool)
 	distinctProtocols := make(map[string]bool)
@@ -661,8 +665,12 @@ func CountSupportedProtocols(region, tunnelProtocol string) int {
 		}
 		}
 	})
 	})
 
 
+	for _, protocol := range impairedProtocols {
+		delete(distinctProtocols, protocol)
+	}
+
 	if err != nil {
 	if err != nil {
-		NoticeAlert("CountSupportedProtocols failed: %s", err)
+		NoticeAlert("CountNonImpairedProtocols failed: %s", err)
 		return 0
 		return 0
 	}
 	}