# Relay sets

low level

# Example

final ndk = Ndk(NdkConfig(
  eventVerifier: MockEventVerifier(),
  cache: MemCacheManager(),
  engine: NdkEngine.RELAY_SETS,
  bootstrapRelays: [relay1.url, relay2.url, relay3.url, relay4.url],
));

ndk.accounts
    .loginPrivateKey(pubkey: key1.publicKey, privkey: key1.privateKey!);

/// query text notes for all keys, should discover where each key keeps its notes (according to nip65) and return all notes
/// only relay 1,2 & 4 should be used, since relay 3 keys are all also kept on relay 1 so should not be needed
RelaySet relaySet = await ndk.relaySets.calculateRelaySet(
    name: "feed",
    ownerPubKey: "ownerPubKey",
    pubKeys: [
      key1.publicKey,
      key2.publicKey,
      key3.publicKey,
      key4.publicKey
    ],
    direction: RelayDirection.outbox,
    relayMinCountPerPubKey: 1,
    onProgress: (stepName, count, total) {
      if (count % 100 == 0 || (total - count) < 10) {
        print("[PROGRESS] $stepName: $count/$total");
      }
    });
print("BEST ${relaySet.relaysMap.length} RELAYS:");
relaySet.relaysMap.forEach((url, pubKeyMappings) {
  print("  ${relayNames[url]} => has ${pubKeyMappings.length} follows");
});

# When to use

Calculates the best relays for a given set of pubkeys. It's used by inbox/outbox.
This allows for granular control in the relaySets engine.
E.g. calculating the best relays for a thread view.