AutoRelayConfig constructor
AutoRelayConfig({})
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.
}
}