Skip to content

Commit c9a8e3a

Browse files
committed
Fix redundant code in LBStrategyWP2.getCandidate()
Remove unnecessary logic from getCandidate() since WP2 uses getWeightedCandidate() instead. The function now simply satisfies the LBStrategy interface requirement with minimal implementation.
1 parent 32c7290 commit c9a8e3a

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

dnscrypt-proxy/serversInfo.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,23 +128,12 @@ func (LBStrategyRandom) getActiveCount(serversCount int) int {
128128
type LBStrategyWP2 struct{}
129129

130130
func (LBStrategyWP2) getCandidate(serversCount int) int {
131+
// This function is not used for WP2 - getWeightedCandidate is used instead
132+
// But we need to implement it to satisfy the LBStrategy interface
131133
if serversCount <= 1 {
132134
return 0
133135
}
134-
if serversCount == 2 {
135-
return rand.Intn(2)
136-
}
137-
138-
// Select two random servers
139-
first := rand.Intn(serversCount)
140-
second := rand.Intn(serversCount)
141-
142-
// Ensure we have two different servers
143-
for second == first {
144-
second = rand.Intn(serversCount)
145-
}
146-
147-
return first // Will be refined in getWeightedCandidate
136+
return rand.Intn(serversCount)
148137
}
149138

150139
func (LBStrategyWP2) getActiveCount(serversCount int) int {

0 commit comments

Comments
 (0)