authenticateConnection method

Future<bool> authenticateConnection(
  1. RelayConnectionKey key
)

Answers the challenge for key and completes once the relay accepted the AUTH event. Concurrent callers share a single AUTH.

Implementation

Future<bool> authenticateConnection(RelayConnectionKey key) {
  if (key.isAnonymous) {
    return Future.value(false);
  }
  if (_authenticatedConnections.contains(key)) {
    return Future.value(true);
  }
  final inFlight = _authenticating[key];
  if (inFlight != null) {
    return inFlight;
  }
  final attempt = _sendAuth(key, _generationOf(key));
  _authenticating[key] = attempt;
  return attempt.whenComplete(() {
    if (identical(_authenticating[key], attempt)) {
      _authenticating.remove(key);
    }
  });
}