rtci-shared 0.5.0

Shared types of a sans-I/O WebRTC stack: marshalling traits, transport context, replay detection, the stream transport interface
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
//! Happy Eyeballs (RFC 8305) for a sans-I/O engine: the order in which a server's addresses
//! are tried and when the next attempt starts. The driver resolves names
//! ([`StreamCommand::Resolve`](super::StreamCommand::Resolve)), answering both families at
//! once ([`StreamEvent::Resolved`](super::StreamEvent::Resolved)) or each as it arrives
//! ([`StreamEvent::ResolvedFamily`](super::StreamEvent::ResolvedFamily)); the engine sorts and
//! staggers the attempts with [`HappyEyeballs`] and keeps the first that succeeds. With answers
//! per family the race starts on the first one (RFC 8305 section 3): at once on IPv6, after the
//! Resolution Delay on IPv4 while IPv6 is outstanding, and a late answer joins the addresses
//! not yet tried.

use std::collections::{HashMap, HashSet, VecDeque};
use std::net::{IpAddr, SocketAddr};
use std::time::{Duration, Instant};

/// RFC 8305 section 8: the recommended Connection Attempt Delay.
pub const CONNECTION_ATTEMPT_DELAY: Duration = Duration::from_millis(250);
/// RFC 8305 section 5: an attempt never starts within 10 ms of the previous one.
pub const MIN_CONNECTION_ATTEMPT_DELAY: Duration = Duration::from_millis(10);
/// RFC 8305 section 5: the upper bound of the delay ("Maximum Connection Attempt Delay").
pub const MAX_CONNECTION_ATTEMPT_DELAY: Duration = Duration::from_secs(2);
/// RFC 8305 section 8: the recommended Resolution Delay, how long an IPv4 answer waits for the
/// IPv6 one before the race starts on it.
pub const RESOLUTION_DELAY: Duration = Duration::from_millis(50);

/// RFC 8305 section 4: addresses interleaved by family, the preferred family first ("First
/// Address Family Count" of one), each family keeping its own order. IPv6 is preferred, as
/// the RFC's default; duplicates are dropped.
pub fn sort_addresses(addresses: &[SocketAddr], prefer_ipv6: bool) -> Vec<SocketAddr> {
    sort_addresses_ranked(addresses, prefer_ipv6, |_| AddressRank::default())
}

/// What the history says of one address, for the order of the attempts
/// ([`AddressHistory::rank`]): lower first. The default (nothing known) sorts after an
/// address that answered and before one whose last attempt failed.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct AddressRank {
    /// The last attempt on the address failed (RFC 6724 rule 1, "Avoid unusable
    /// destinations").
    failed: bool,
    /// The time the last successful attempt took to its first answer; `Duration::MAX` for an
    /// address never used (RFC 8305 section 4: lower RTTs first, used addresses before unused
    /// ones).
    rtt: Duration,
}

impl Default for AddressRank {
    fn default() -> Self {
        Self {
            failed: false,
            rtt: Duration::MAX,
        }
    }
}

/// As [`sort_addresses`], each family ordered first by `rank` (lower first; the given order
/// among equal ranks).
pub fn sort_addresses_ranked(
    addresses: &[SocketAddr],
    prefer_ipv6: bool,
    rank: impl Fn(&SocketAddr) -> AddressRank,
) -> Vec<SocketAddr> {
    let mut ranked: Vec<SocketAddr> = vec![];
    for a in addresses {
        if !ranked.contains(a) {
            ranked.push(*a);
        }
    }
    ranked.sort_by_key(|a| rank(a));
    let mut first: VecDeque<SocketAddr> = VecDeque::new();
    let mut second: VecDeque<SocketAddr> = VecDeque::new();
    for a in &ranked {
        if first.contains(a) || second.contains(a) {
            continue;
        }
        if a.is_ipv6() == prefer_ipv6 {
            first.push_back(*a);
        } else {
            second.push_back(*a);
        }
    }
    let mut out = Vec::with_capacity(first.len() + second.len());
    loop {
        match (first.pop_front(), second.pop_front()) {
            (None, None) => break,
            (a, b) => {
                out.extend(a);
                out.extend(b);
            }
        }
    }
    out
}

/// What attempts on a server's addresses came to, for the order of later attempts (RFC 8305
/// section 4): "If the client is stateful and has a history of expected round-trip times
/// (RTTs) for the routes to access each address, it SHOULD add a Destination Address Selection
/// rule between rules 8 and 9 that prefers addresses with lower RTTs. If the client keeps
/// track of which addresses it used in the past, it SHOULD add another Destination Address
/// Selection rule between the RTT rule and rule 9, which prefers used addresses over unused
/// ones." An address whose last attempt failed goes last (RFC 6724 rule 1).
///
/// "This historical data MUST NOT be used across different network interfaces and SHOULD be
/// flushed whenever a device changes the network to which it is attached." Every outcome is
/// kept under the local address it was had from (the interface), and read back only for that
/// local address; [`interface`](Self::interface) flushes the history when a local address not
/// seen before appears once any is known.
#[derive(Debug, Clone, Default)]
pub struct AddressHistory {
    entries: HashMap<(IpAddr, SocketAddr), AddressRank>,
    interfaces: HashSet<IpAddr>,
}

impl AddressHistory {
    /// An attempt from `local` to `remote` was answered, `rtt` after it started.
    pub fn succeeded(&mut self, local: IpAddr, remote: SocketAddr, rtt: Duration) {
        self.entries.insert(
            (local, remote),
            AddressRank {
                failed: false,
                rtt: rtt.min(Duration::MAX - Duration::from_nanos(1)),
            },
        );
    }

    /// An attempt from `local` to `remote` failed (went unanswered, or its connection or
    /// handshake failed). What the address took when it last answered is kept.
    pub fn failed(&mut self, local: IpAddr, remote: SocketAddr) {
        self.entries.entry((local, remote)).or_default().failed = true;
    }

    /// The rank of `remote` for attempts from `local` (nothing known: the default).
    pub fn rank(&self, local: IpAddr, remote: SocketAddr) -> AddressRank {
        self.entries
            .get(&(local, remote))
            .copied()
            .unwrap_or_default()
    }

    /// A local address of a host interface the application gave: the first ones are noted;
    /// one not seen before once any is known means the device's network changed, and the
    /// history is flushed (RFC 8305 section 4).
    pub fn interface(&mut self, local: IpAddr) {
        if self.interfaces.contains(&local) {
            return;
        }
        if !self.interfaces.is_empty() {
            self.entries.clear();
        }
        self.interfaces.insert(local);
    }

    /// Whether nothing is known.
    pub fn is_empty(&self) -> bool {
        self.entries.is_empty()
    }
}

/// One Happy Eyeballs race over sorted addresses: [`next_attempt`](Self::next_attempt) says
/// which address to try when, a failure moves to the next at once, the first success ends it
/// (the attempts still running are to be cancelled, the rest ignored).
#[derive(Debug, Clone)]
pub struct HappyEyeballs {
    remaining: VecDeque<SocketAddr>,
    delay: Duration,
    last_start: Option<Instant>,
    running: usize,
    done: bool,
    /// Families still to answer (IPv6, IPv4); none for a race made from a complete list.
    awaiting: (bool, bool),
    /// Every address ever given, so a late answer adds only new ones.
    known: Vec<SocketAddr>,
    /// The race does not start before this (the Resolution Delay of an IPv4 answer).
    hold_until: Option<Instant>,
    /// Whether the last address tried was IPv6.
    last_ipv6: Option<bool>,
    /// The ranks of the addresses that arrived by [`Self::answer_ranked`].
    ranks: Vec<(SocketAddr, AddressRank)>,
    /// When each address tried was started.
    started: Vec<(SocketAddr, Instant)>,
}

impl HappyEyeballs {
    /// A race over `addresses` (already sorted, [`sort_addresses`]) with the Connection
    /// Attempt Delay `delay`, held between 10 ms and 2 s (RFC 8305 section 5).
    pub fn new(addresses: Vec<SocketAddr>, delay: Duration) -> Self {
        Self {
            known: addresses.clone(),
            remaining: addresses.into(),
            delay: delay.clamp(MIN_CONNECTION_ATTEMPT_DELAY, MAX_CONNECTION_ATTEMPT_DELAY),
            last_start: None,
            running: 0,
            done: false,
            awaiting: (false, false),
            hold_until: None,
            last_ipv6: None,
            ranks: vec![],
            started: vec![],
        }
    }

    /// A race whose addresses arrive per family ([`Self::answer`]): it is not lost while a
    /// family is outstanding.
    pub fn awaiting_answers(delay: Duration) -> Self {
        Self {
            awaiting: (true, true),
            ..Self::new(vec![], delay)
        }
    }

    /// The answer of one family at `now` (RFC 8305 section 3): the race starts on the first
    /// answer, at once for IPv6 and after [`RESOLUTION_DELAY`] for IPv4 while IPv6 is still
    /// outstanding; an answer that comes once the race has started is sorted into the
    /// addresses not yet tried, the families still alternating (`prefer_ipv6`: the family
    /// that goes first before any attempt).
    pub fn answer(
        &mut self,
        now: Instant,
        ipv6: bool,
        addresses: &[SocketAddr],
        prefer_ipv6: bool,
    ) {
        self.answer_ranked(now, ipv6, addresses, prefer_ipv6, |_| {
            AddressRank::default()
        });
    }

    /// As [`Self::answer`], each family of the addresses not yet tried ordered by `rank` first
    /// ([`sort_addresses_ranked`]; the ranks of earlier answers are kept).
    pub fn answer_ranked(
        &mut self,
        now: Instant,
        ipv6: bool,
        addresses: &[SocketAddr],
        prefer_ipv6: bool,
        rank: impl Fn(&SocketAddr) -> AddressRank,
    ) {
        for a in addresses {
            if !self.ranks.iter().any(|(r, _)| r == a) {
                self.ranks.push((*a, rank(a)));
            }
        }
        if ipv6 {
            self.awaiting.0 = false;
            // The IPv6 answer ends any wait for it.
            self.hold_until = None;
        } else {
            self.awaiting.1 = false;
            if self.awaiting.0 && self.last_start.is_none() && self.hold_until.is_none() {
                self.hold_until = Some(now + RESOLUTION_DELAY);
            }
        }
        if self.done {
            return;
        }
        let fresh: Vec<SocketAddr> = addresses
            .iter()
            .filter(|a| !self.known.contains(a))
            .copied()
            .collect();
        self.known.extend(&fresh);
        let mut pending: Vec<SocketAddr> = self.remaining.drain(..).collect();
        pending.extend(fresh);
        let first = self.last_ipv6.map_or(prefer_ipv6, |last| !last);
        let ranks = &self.ranks;
        self.remaining = sort_addresses_ranked(&pending, first, |a| {
            ranks
                .iter()
                .find(|(r, _)| r == a)
                .map_or_else(AddressRank::default, |(_, rank)| *rank)
        })
        .into();
    }

    /// Whether an attempt was started.
    pub fn started(&self) -> bool {
        self.last_start.is_some()
    }

    /// When the attempt on `address` was started, if it was.
    pub fn started_at(&self, address: SocketAddr) -> Option<Instant> {
        self.started
            .iter()
            .rev()
            .find(|(a, _)| *a == address)
            .map(|(_, at)| *at)
    }

    /// Whether a family has yet to answer.
    pub fn awaiting(&self) -> bool {
        self.awaiting.0 || self.awaiting.1
    }

    /// The address to try now, if one is due: the first at once; the next when the delay since
    /// the previous start has passed, or when nothing is running (the previous failed), but
    /// never within 10 ms of the previous start.
    pub fn next_attempt(&mut self, now: Instant) -> Option<SocketAddr> {
        if self.done || self.hold_until.is_some_and(|until| now < until) {
            return None;
        }
        let due = match self.last_start {
            None => true,
            Some(last) => {
                let since = now.saturating_duration_since(last);
                since >= self.delay || (self.running == 0 && since >= MIN_CONNECTION_ATTEMPT_DELAY)
            }
        };
        if !due {
            return None;
        }
        let address = self.remaining.pop_front()?;
        self.last_ipv6 = Some(address.is_ipv6());
        self.last_start = Some(now);
        self.started.push((address, now));
        self.running += 1;
        Some(address)
    }

    /// When [`next_attempt`](Self::next_attempt) will next have something, once an attempt
    /// has started (before that, at once).
    pub fn poll_timeout(&self) -> Option<Instant> {
        if self.done || self.remaining.is_empty() {
            return None;
        }
        if let Some(until) = self.hold_until
            && self.last_start.is_none()
        {
            return Some(until);
        }
        Some(match self.last_start {
            // Nothing started: the first attempt is due at once, on the next call.
            None => return None,
            Some(last) if self.running == 0 => last + MIN_CONNECTION_ATTEMPT_DELAY,
            Some(last) => last + self.delay,
        })
    }

    /// An attempt failed.
    pub fn failed(&mut self) {
        self.running = self.running.saturating_sub(1);
    }

    /// An attempt connected: the race is over.
    pub fn succeeded(&mut self) {
        self.done = true;
        self.remaining.clear();
    }

    /// Every address was tried and nothing is running or left: the race is lost.
    pub fn exhausted(&self) -> bool {
        !self.done && self.running == 0 && self.remaining.is_empty() && !self.awaiting()
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    fn a(s: &str) -> SocketAddr {
        s.parse().unwrap()
    }

    #[test]
    fn families_interleave_preferred_first_each_in_its_order() {
        let list = [
            a("192.0.2.1:3478"),
            a("192.0.2.2:3478"),
            a("192.0.2.3:3478"),
            a("[2001:db8::1]:3478"),
            a("[2001:db8::2]:3478"),
            a("192.0.2.1:3478"),
        ];
        assert_eq!(
            sort_addresses(&list, true),
            vec![
                a("[2001:db8::1]:3478"),
                a("192.0.2.1:3478"),
                a("[2001:db8::2]:3478"),
                a("192.0.2.2:3478"),
                a("192.0.2.3:3478"),
            ]
        );
        assert_eq!(sort_addresses(&list, false)[0], a("192.0.2.1:3478"));
        assert_eq!(sort_addresses(&[], true), vec![]);
    }

    /// RFC 8305 section 4: within each family, an address that answered goes first (the
    /// faster first), an unknown one next, one whose last attempt failed last; the families
    /// still alternate, the preferred one first. History is read back only for the local
    /// address it was had from, and a new interface flushes it.
    #[test]
    fn history_orders_each_family_and_stays_with_its_interface() {
        let base = a("10.0.0.1:0").ip();
        let other = a("10.0.1.1:0").ip();
        let list = [
            a("192.0.2.1:3478"),
            a("192.0.2.2:3478"),
            a("192.0.2.3:3478"),
            a("192.0.2.4:3478"),
            a("[2001:db8::1]:3478"),
            a("[2001:db8::2]:3478"),
        ];
        let mut h = AddressHistory::default();
        h.interface(base);
        h.interface(other);
        h.failed(base, a("192.0.2.1:3478"));
        h.succeeded(base, a("192.0.2.3:3478"), Duration::from_millis(80));
        h.succeeded(base, a("192.0.2.4:3478"), Duration::from_millis(20));
        h.succeeded(base, a("[2001:db8::2]:3478"), Duration::from_millis(30));
        assert_eq!(
            sort_addresses_ranked(&list, true, |r| h.rank(base, *r)),
            vec![
                a("[2001:db8::2]:3478"),
                a("192.0.2.4:3478"),
                a("[2001:db8::1]:3478"),
                a("192.0.2.3:3478"),
                a("192.0.2.2:3478"),
                a("192.0.2.1:3478"),
            ]
        );
        // Another interface: nothing of `base`'s history.
        assert_eq!(
            sort_addresses_ranked(&list, true, |r| h.rank(other, *r)),
            sort_addresses(&list, true)
        );
        // A failure after a success: last again.
        h.failed(base, a("192.0.2.4:3478"));
        assert_eq!(
            sort_addresses_ranked(&list, false, |r| h.rank(base, *r))[..2],
            [a("192.0.2.3:3478"), a("[2001:db8::2]:3478")]
        );
        // A new interface: the network changed, the history is gone.
        h.interface(a("10.0.2.1:0").ip());
        assert!(h.is_empty());
    }

    /// Answers per family keep the ranks: a late IPv4 answer is ranked into the addresses not
    /// yet tried, and the start of each attempt is remembered.
    #[test]
    fn answers_are_ranked_and_starts_remembered() {
        let t0 = Instant::now();
        let mut race = HappyEyeballs::awaiting_answers(CONNECTION_ATTEMPT_DELAY);
        let bad = a("192.0.2.1:1");
        let good = a("192.0.2.2:1");
        let rank = |r: &SocketAddr| {
            let mut h = AddressHistory::default();
            h.failed(a("10.0.0.1:0").ip(), bad);
            h.rank(a("10.0.0.1:0").ip(), *r)
        };
        race.answer_ranked(t0, true, &[], true, rank);
        race.answer_ranked(t0, false, &[bad, good], true, rank);
        assert_eq!(race.next_attempt(t0), Some(good));
        assert_eq!(race.started_at(good), Some(t0));
        assert_eq!(race.started_at(bad), None);
    }

    #[test]
    fn attempts_are_staggered_by_the_delay_and_a_failure_moves_on_at_once() {
        let t0 = Instant::now();
        let mut race = HappyEyeballs::new(
            vec![a("[2001:db8::1]:1"), a("192.0.2.1:1"), a("192.0.2.2:1")],
            CONNECTION_ATTEMPT_DELAY,
        );
        assert_eq!(race.next_attempt(t0), Some(a("[2001:db8::1]:1")));
        assert_eq!(race.next_attempt(t0 + Duration::from_millis(100)), None);
        assert_eq!(race.poll_timeout(), Some(t0 + CONNECTION_ATTEMPT_DELAY));
        assert_eq!(
            race.next_attempt(t0 + CONNECTION_ATTEMPT_DELAY),
            Some(a("192.0.2.1:1"))
        );
        // Both fail: the next starts at once, though not within 10 ms of the last start.
        race.failed();
        race.failed();
        let t1 = t0 + CONNECTION_ATTEMPT_DELAY;
        assert_eq!(race.next_attempt(t1 + Duration::from_millis(5)), None);
        assert_eq!(
            race.next_attempt(t1 + Duration::from_millis(10)),
            Some(a("192.0.2.2:1"))
        );
        race.failed();
        assert!(race.exhausted());
    }

    #[test]
    fn the_first_success_ends_the_race() {
        let t0 = Instant::now();
        let mut race = HappyEyeballs::new(
            vec![a("[2001:db8::1]:1"), a("192.0.2.1:1")],
            Duration::from_millis(1),
        );
        assert!(race.next_attempt(t0).is_some());
        race.succeeded();
        assert_eq!(race.next_attempt(t0 + Duration::from_secs(1)), None);
        assert_eq!(race.poll_timeout(), None);
        assert!(!race.exhausted());
    }

    #[test]
    fn an_ipv6_answer_starts_the_race_at_once_and_a_late_ipv4_answer_joins_it() {
        let t0 = Instant::now();
        let mut race = HappyEyeballs::awaiting_answers(CONNECTION_ATTEMPT_DELAY);
        assert_eq!(
            race.next_attempt(t0),
            None,
            "nothing to try before an answer"
        );
        assert!(
            !race.exhausted(),
            "not lost while both families are outstanding"
        );
        race.answer(
            t0,
            true,
            &[a("[2001:db8::1]:3478"), a("[2001:db8::2]:3478")],
            true,
        );
        assert_eq!(
            race.next_attempt(t0),
            Some(a("[2001:db8::1]:3478")),
            "RFC 8305 section 3: no wait for the A answer"
        );
        // The A answer arrives while the race runs: it is interleaved with what is left.
        race.answer(
            t0 + Duration::from_millis(5),
            false,
            &[a("192.0.2.1:3478")],
            true,
        );
        let t1 = t0 + CONNECTION_ATTEMPT_DELAY;
        assert_eq!(race.next_attempt(t1), Some(a("192.0.2.1:3478")));
        let t2 = t1 + CONNECTION_ATTEMPT_DELAY;
        assert_eq!(race.next_attempt(t2), Some(a("[2001:db8::2]:3478")));
    }

    #[test]
    fn an_ipv4_answer_first_waits_the_resolution_delay_for_ipv6() {
        let t0 = Instant::now();
        let mut race = HappyEyeballs::awaiting_answers(CONNECTION_ATTEMPT_DELAY);
        race.answer(t0, false, &[a("192.0.2.1:3478")], true);
        assert_eq!(race.next_attempt(t0), None, "held for the AAAA answer");
        assert_eq!(race.poll_timeout(), Some(t0 + RESOLUTION_DELAY));
        assert_eq!(
            race.next_attempt(t0 + RESOLUTION_DELAY),
            Some(a("192.0.2.1:3478")),
            "the AAAA answer did not come in time: IPv4 goes"
        );

        // An IPv6 answer within the delay goes first.
        let mut race = HappyEyeballs::awaiting_answers(CONNECTION_ATTEMPT_DELAY);
        race.answer(t0, false, &[a("192.0.2.1:3478")], true);
        let t1 = t0 + Duration::from_millis(20);
        race.answer(t1, true, &[a("[2001:db8::1]:3478")], true);
        assert_eq!(race.next_attempt(t1), Some(a("[2001:db8::1]:3478")));
        // Both families answered and every attempt failed: the race is lost.
        race.failed();
        let t2 = t1 + MIN_CONNECTION_ATTEMPT_DELAY;
        assert_eq!(race.next_attempt(t2), Some(a("192.0.2.1:3478")));
        race.failed();
        assert!(race.exhausted());
    }

    #[test]
    fn the_delay_is_held_between_ten_milliseconds_and_two_seconds() {
        let t0 = Instant::now();
        let mut race = HappyEyeballs::new(vec![a("192.0.2.1:1"), a("192.0.2.2:1")], Duration::ZERO);
        race.next_attempt(t0);
        assert_eq!(race.next_attempt(t0 + Duration::from_millis(9)), None);
        assert!(race.next_attempt(t0 + Duration::from_millis(10)).is_some());
        let slow = HappyEyeballs::new(vec![a("192.0.2.1:1")], Duration::from_secs(60));
        assert_eq!(slow.delay, MAX_CONNECTION_ATTEMPT_DELAY);
    }
}