findSecondaryUrl method
Implementation
Future<String?> findSecondaryUrl(String atSign) async {
if (_rootDomain.startsWith("proxy:")) {
// In order to make it easy for clients to connect to a reverse proxy
// instead of doing a root lookup, we adopt the convention that:
// if the rootDomain starts with 'proxy:'
// then the secondary domain name will be deemed to be the portion of rootDomain after 'proxy:'
// and the secondary port will be deemed to be the rootPort
return '${_rootDomain.substring("proxy:".length)}:$_rootPort';
}
String? address;
for (int i = 0; i <= retryDelaysMillis.length; i++) {
try {
address = await _findSecondary(atSign);
return address;
} catch (e) {
if (i < retryDelaysMillis.length) {
_logger.info('AtLookup.findSecondary for $atSign failed with $e'
' : will retry in ${retryDelaysMillis[i]} milliseconds');
await Future.delayed(Duration(milliseconds: retryDelaysMillis[i]));
continue;
}
_logger.severe('AtLookup.findSecondary for $atSign failed with $e'
' : ${retryDelaysMillis.length + 1} failures, giving up');
if (e is RootServerConnectivityException) {
throw RootServerConnectivityException(
'Unable to establish connection with root server.'
' Please check your internet connection and try again');
}
}
}
throw AtConnectException('Could not fetch secondary address for $atSign :'
' ${retryDelaysMillis.length + 1} failures, giving up');
}