AutoRelayConfig constructor

AutoRelayConfig({
  1. Clock? clock,
  2. PeerSource? peerSourceCallback,
  3. List<AddrInfo>? staticRelays,
  4. Duration? minInterval,
  5. int? minCandidates,
  6. int? maxCandidates,
  7. Duration? bootDelay,
  8. Duration? backoff,
  9. int? desiredRelays,
  10. Duration? maxCandidateAge,
  11. MetricsTracer? metricsTracer,
})

Implementation

AutoRelayConfig({
  Clock? clock,
  this.peerSourceCallback,
  this.staticRelays,
  Duration? minInterval,
  int? minCandidates,
  int? maxCandidates,
  Duration? bootDelay,
  Duration? backoff,
  int? desiredRelays,
  Duration? maxCandidateAge,
  this.metricsTracer,
})  : clock = clock ?? const RealClock(),
      minInterval = minInterval ?? const Duration(seconds: 30),
      minCandidates = minCandidates ?? 4,
      maxCandidates = maxCandidates ?? 20,
      bootDelay = bootDelay ?? const Duration(minutes: 3),
      backoff = backoff ?? const Duration(hours: 1),
      desiredRelays = desiredRelays ?? 2,
      maxCandidateAge = maxCandidateAge ?? const Duration(minutes: 30),
      // Internal consistency checks
      setMinCandidatesFlag = minCandidates != null {
  if (peerSourceCallback != null && staticRelays != null) {
    throw ArgumentError(
        'Cannot provide both peerSourceCallback and staticRelays. They are mutually exclusive.');
  }
  if (this.minCandidates > this.maxCandidates) {
    throw ArgumentError(
        'minCandidates cannot be greater than maxCandidates. Got min: ${this.minCandidates}, max: ${this.maxCandidates}');
  }
  if (this.desiredRelays == 0 && (staticRelays == null || staticRelays!.isEmpty)) {
      // If desiredRelays is 0, it usually means it's derived from staticRelays.
      // If staticRelays is also empty/null, this might be an issue unless peerSource is very effective.
      // The Go code adjusts desiredRelays in WithStaticRelays.
  }
   if (staticRelays != null && staticRelays!.isNotEmpty) {
      // If static relays are provided, they often dictate min/max candidates and desired relays.
      // The Go WithStaticRelays option adjusts these.
      // Here, we assume if they are passed, they are the source of truth,
      // and the user should set other params accordingly or we use defaults that might be overridden
      // by a more specific factory method if we create one later.
      // For simplicity now, direct assignment.
   }
}