calculateRelaySet method

Future<RelaySet> calculateRelaySet({
  1. required String name,
  2. required String ownerPubKey,
  3. required List<String> pubKeys,
  4. required RelayDirection direction,
  5. required int relayMinCountPerPubKey,
  6. dynamic onProgress(
    1. String,
    2. int,
    3. int
    )?,
})

relay -> list of pubKey mappings

Implementation

Future<RelaySet> calculateRelaySet(
    {required String name,
    required String ownerPubKey,
    required List<String> pubKeys,
    required RelayDirection direction,
    required int relayMinCountPerPubKey,
    Function(String, int, int)? onProgress}) async {
  RelaySet byScore = await _relaysByPopularity(
      name: name,
      ownerPubKey: ownerPubKey,
      pubKeys: pubKeys,
      direction: direction,
      relayMinCountPerPubKey: relayMinCountPerPubKey,
      onProgress: onProgress);

  /// try by score
  if (byScore.relaysMap.isNotEmpty) {
    return byScore;
  }

  /// if everything fails just return a map of all currently registered connected relays for each pubKeys
  return RelaySet(
      name: name,
      pubKey: ownerPubKey,
      relayMinCountPerPubkey: relayMinCountPerPubKey,
      direction: direction,
      relaysMap: _relayManager.allConnectedRelays(pubKeys),
      notCoveredPubkeys: []);
}