getNextProxy method
Proxy
getNextProxy({
- bool validated = true,
- bool useScoring = false,
- RotationStrategyType strategyType = RotationStrategyType.roundRobin,
Gets the next proxy in the rotation
validated
determines whether to use validated proxies
useScoring
determines whether to use the scoring system for selection
strategyType
determines the rotation strategy to use
Implementation
Proxy getNextProxy({
bool validated = true,
bool useScoring = false,
RotationStrategyType strategyType = RotationStrategyType.roundRobin,
}) {
final proxies = validated ? _validatedProxies : _proxies;
if (proxies.isEmpty) {
throw NoValidProxiesException();
}
if (useScoring) {
// Use weighted selection based on proxy scores
final proxyModels = proxies.whereType<ProxyModel>().toList();
if (proxyModels.isEmpty) {
// Fall back to the specified strategy if no models with scores are available
_rotationStrategy = RotationStrategyFactory.createStrategy(
type: strategyType,
proxies: proxies,
);
return _rotationStrategy.selectProxy(proxies);
}
// Use weighted strategy for scoring
_rotationStrategy = RotationStrategyFactory.createStrategy(
type: RotationStrategyType.weighted,
proxies: proxyModels,
);
return _rotationStrategy.selectProxy(proxyModels);
} else {
// Use the specified strategy
_rotationStrategy = RotationStrategyFactory.createStrategy(
type: strategyType,
proxies: proxies,
);
return _rotationStrategy.selectProxy(proxies);
}
}