getReachability method

  1. @override
Future<Result> getReachability(
  1. List<Request> requests
)
override

Check reachability for the given addresses

Implementation

@override
Future<Result> getReachability(List<Request> requests) async {
  // Check if addresses are public
  if (!allowPrivateAddrs) {
    for (final request in requests) {
      if (!request.addr.isPublic()) {
        throw Exception('Private address cannot be verified by autonatv2: ${request.addr}');
      }
    }
  }

  // Get a random peer that supports AutoNAT v2
  final peerId = _peers.getRandom();
  if (peerId == null) {
    throw ClientErrors.noValidPeers;
  }

  try {
    // Get reachability from the peer
    final result = await client.getReachability(peerId, requests);
    _log.fine('Reachability check with $peerId successful');
    return result;
  } catch (e) {
    _log.fine('Reachability check with $peerId failed, err: $e');
    throw Exception('Reachability check with $peerId failed: $e');
  }
}