selectProxy method
Selects a proxy from the given list
Implementation
@override
Proxy selectProxy(List<Proxy> proxies) {
if (proxies.isEmpty) {
throw Exception('No proxies available');
}
// Update the proxy list if it has changed
if (_proxies.isEmpty || _proxies.length != proxies.length) {
updateProxies(proxies);
}
// Apply time-based weight decay
_applyWeightDecay();
// Decide whether to explore or exploit
if (_random.nextDouble() < explorationRate) {
// Exploration: select a random proxy
final index = _random.nextInt(proxies.length);
_lastIndex = index;
final proxy = proxies[index];
// Record the time of use
_lastUsed[_getProxyKey(proxy)] = DateTime.now().millisecondsSinceEpoch;
return proxy;
} else {
// Exploitation: select the best proxy based on weights
return _selectBestProxy(proxies);
}
}