iroh/socket/remote_map/remote_state/
path_state.rs

1//! The state kept for each network path to a remote endpoint.
2
3use std::{
4    collections::{HashMap, HashSet, VecDeque},
5    sync::Arc,
6};
7
8use n0_error::e;
9use n0_future::time::Instant;
10use tokio::sync::oneshot;
11use tracing::trace;
12
13use super::{Source, TransportAddrInfo, TransportAddrUsage};
14use crate::{address_lookup::AddressLookupFailed, metrics::SocketMetrics, socket::transports};
15
16/// Maximum number of non-relay paths we keep around per endpoint.
17pub(super) const MAX_NON_RELAY_PATHS: usize = 30;
18
19/// Maximum number of inactive non-relay paths we keep around per endpoint.
20///
21/// These are paths that at one point been opened and are now closed.
22pub(super) const MAX_INACTIVE_NON_RELAY_PATHS: usize = 10;
23
24/// Map of all paths that we are aware of for a remote endpoint.
25///
26/// Also stores a list of resolve requests which are triggered once at least one path is known,
27/// or once this struct is notified of a failed Address Lookup run.
28#[derive(Debug)]
29pub(super) struct RemotePathState {
30    /// All possible paths we are aware of.
31    ///
32    /// These paths might be entirely impossible to use, since they are added by Address Lookup
33    /// mechanisms. The are only potentially usable.
34    paths: HashMap<transports::Addr, PathState>,
35    /// Pending resolve requests from [`Self::resolve_remote`].
36    pending_resolve_requests: VecDeque<oneshot::Sender<Result<(), AddressLookupFailed>>>,
37    metrics: Arc<SocketMetrics>,
38}
39
40/// Describes the usability of this path, i.e. whether it has ever been opened,
41/// when it was closed, or if it has never been usable.
42#[derive(Debug, Default)]
43pub(super) enum PathStatus {
44    /// This path is open and active.
45    Open,
46    /// This path was once opened, but was abandoned at the given [`Instant`].
47    Inactive(Instant),
48    /// This path was never usable (we attempted holepunching and it didn't work).
49    Unusable,
50    /// We have not yet attempted holepunching, or holepunching is currently in
51    /// progress, so we do not know the usability of this path.
52    #[default]
53    Unknown,
54}
55
56impl RemotePathState {
57    pub(super) fn new(metrics: Arc<SocketMetrics>) -> Self {
58        Self {
59            paths: Default::default(),
60            pending_resolve_requests: Default::default(),
61            metrics,
62        }
63    }
64
65    pub(super) fn to_remote_addrs(&self) -> Vec<TransportAddrInfo> {
66        self.paths
67            .iter()
68            .flat_map(|(addr, state)| {
69                let usage = match state.status {
70                    PathStatus::Open => TransportAddrUsage::Active,
71                    PathStatus::Inactive(_) | PathStatus::Unusable | PathStatus::Unknown => {
72                        TransportAddrUsage::Inactive
73                    }
74                };
75                Some(TransportAddrInfo {
76                    addr: addr.clone().into(),
77                    usage,
78                })
79            })
80            .collect()
81    }
82
83    /// Insert a new address of an open path into our list of paths.
84    ///
85    /// This will emit pending resolve requests and trigger pruning paths.
86    pub(super) fn insert_open_path(&mut self, addr: transports::Addr, source: Source) {
87        match addr {
88            transports::Addr::Ip(_) => self.metrics.transport_ip_paths_added.inc(),
89            transports::Addr::Relay(_, _) => self.metrics.transport_relay_paths_added.inc(),
90            transports::Addr::Custom(_) => self.metrics.transport_custom_paths_added.inc(),
91        };
92        let state = self.paths.entry(addr).or_default();
93        state.status = PathStatus::Open;
94        state.sources.insert(source.clone(), Instant::now());
95        self.emit_pending_resolve_requests(None);
96        self.prune_paths();
97    }
98
99    /// Mark a path as abandoned.
100    ///
101    /// If this path does not exist, it does nothing to the
102    /// `RemotePathState`
103    pub(super) fn abandoned_path(&mut self, addr: &transports::Addr) {
104        if let Some(state) = self.paths.get_mut(addr) {
105            if matches!(state.status, PathStatus::Open) {
106                match addr {
107                    transports::Addr::Ip(_) => self.metrics.transport_ip_paths_removed.inc(),
108                    transports::Addr::Relay(_, _) => {
109                        self.metrics.transport_relay_paths_removed.inc()
110                    }
111                    transports::Addr::Custom(_) => {
112                        self.metrics.transport_custom_paths_removed.inc()
113                    }
114                };
115            }
116            match state.status {
117                PathStatus::Open | PathStatus::Inactive(_) => {
118                    state.status = PathStatus::Inactive(Instant::now());
119                }
120                PathStatus::Unusable | PathStatus::Unknown => {
121                    state.status = PathStatus::Unusable;
122                }
123            }
124        }
125    }
126
127    /// Inserts multiple addresses of unknown status into our list of potential paths.
128    ///
129    /// If this caused the path set to transition from empty to non-empty, any
130    /// pending resolve requests are woken with `Ok(())`. Inserts that add no
131    /// new paths (empty iterator, or only duplicates) are a no-op: waking
132    /// pending requests while the path set is still empty would send a bogus
133    /// `AddressLookupFailed::NoResults` while an address lookup is in flight.
134    pub(super) fn insert_multiple(
135        &mut self,
136        addrs: impl Iterator<Item = transports::Addr>,
137        source: Source,
138    ) {
139        let now = Instant::now();
140        let was_empty = self.paths.is_empty();
141        for addr in addrs {
142            self.paths
143                .entry(addr)
144                .or_default()
145                .sources
146                .insert(source.clone(), now);
147        }
148        trace!("added addressing information");
149        if was_empty && !self.paths.is_empty() {
150            self.emit_pending_resolve_requests(None);
151        }
152        self.prune_paths();
153    }
154
155    /// Sends back on `tx` once a possible path to the remote is known.
156    ///
157    /// If there already is a known path, `Ok(())` is returned immediately. Otherwise an
158    /// address lookup is performed and the result is sent back once that
159    /// completes. [`AddressLookupFailed`] is sent if there are no known paths.
160    pub(super) fn resolve_remote(&mut self, tx: oneshot::Sender<Result<(), AddressLookupFailed>>) {
161        if !self.paths.is_empty() {
162            tx.send(Ok(())).ok();
163        } else {
164            self.pending_resolve_requests.push_back(tx);
165        }
166    }
167
168    /// Returns `true` if there are any queued resolve requests from [`Self::resolve_remote`].
169    pub(super) fn resolve_requests_is_empty(&self) -> bool {
170        self.pending_resolve_requests.is_empty()
171    }
172
173    /// Notifies that a Address Lookup run has finished.
174    ///
175    /// This will emit pending resolve requests.
176    pub(super) fn address_lookup_finished(&mut self, result: Result<(), AddressLookupFailed>) {
177        self.emit_pending_resolve_requests(result.err());
178    }
179
180    /// Returns an iterator over the addresses of all paths.
181    pub(super) fn addrs(&self) -> impl Iterator<Item = &transports::Addr> {
182        self.paths.keys()
183    }
184
185    /// Returns whether this stores any addresses.
186    pub(super) fn is_empty(&self) -> bool {
187        self.paths.is_empty()
188    }
189
190    /// Replies to all pending resolve requests.
191    ///
192    /// This is a no-op if no requests are queued. Replies `Ok` if we have any known paths,
193    /// otherwise with the provided `address_lookup_error` or with [`AddressLookupFailed::NoResults`].
194    fn emit_pending_resolve_requests(&mut self, address_lookup_error: Option<AddressLookupFailed>) {
195        if self.pending_resolve_requests.is_empty() {
196            return;
197        }
198        let result = match (self.paths.is_empty(), address_lookup_error) {
199            (false, _) => Ok(()),
200            (true, Some(err)) => Err(err),
201            (true, None) => Err(e!(AddressLookupFailed::NoResults { errors: Vec::new() })),
202        };
203        for tx in self.pending_resolve_requests.drain(..) {
204            tx.send(result.clone()).ok();
205        }
206    }
207
208    /// Prune paths.
209    ///
210    /// Should be invoked any time we insert a new path.
211    ///
212    /// We currently only prune non-relay paths. For more information on the
213    /// criteria for when and which paths we prune, look at the [`prune_non_relay_paths`] function.
214    pub(super) fn prune_paths(&mut self) {
215        prune_non_relay_paths(&mut self.paths);
216    }
217}
218
219/// The state of a single path to the remote endpoint.
220///
221/// Each path is identified by the destination [`transports::Addr`] and they are stored in
222/// the [`RemotePathState`] map in [`RemoteStateActor`].
223///
224/// [`RemoteStateActor`]: super::RemoteStateActor
225#[derive(Debug, Default)]
226pub(super) struct PathState {
227    /// How we learned about this path, and when.
228    ///
229    /// We keep track of only the latest [`Instant`] for each [`Source`], keeping the size
230    /// of the map of sources down to one entry per type of source.
231    pub(super) sources: HashMap<Source, Instant>,
232    /// The usability status of this path.
233    pub(super) status: PathStatus,
234}
235
236/// Prunes the non-relay paths in the paths HashMap.
237///
238/// Only prunes if the number of non-relay paths is above [`MAX_NON_RELAY_PATHS`].
239///
240/// Keeps paths that are open or of unknown status.
241///
242/// Always prunes paths that have unsuccessfully holepunched.
243///
244/// Keeps [`MAX_INACTIVE_NON_RELAY_PATHS`] of the most recently closed paths
245/// that are not currently being used but have successfully been
246/// holepunched previously.
247///
248/// This all ensures that:
249///
250/// - We do not have unbounded growth of paths.
251/// - If we have many paths for this remote, we prune the paths that cannot hole punch.
252/// - We do not prune holepunched paths that are currently not in use too quickly. For
253///   example, if a large number of untested paths are added at once, we will not
254///   immediately prune all of the unused, but valid, paths at once.
255fn prune_non_relay_paths(paths: &mut HashMap<transports::Addr, PathState>) {
256    // if the total number of paths is less than the max, bail early
257    if paths.len() < MAX_NON_RELAY_PATHS {
258        return;
259    }
260
261    let primary_paths: Vec<_> = paths.iter().filter(|(addr, _)| !addr.is_relay()).collect();
262
263    // if the total number of non-relay paths is less than the max, bail early
264    if primary_paths.len() < MAX_NON_RELAY_PATHS {
265        return;
266    }
267
268    // paths that were opened at one point but have previously been closed
269    let mut inactive = Vec::with_capacity(primary_paths.len());
270    // paths where we attempted hole punching but it not successful
271    let mut failed = Vec::with_capacity(primary_paths.len());
272
273    for (addr, state) in primary_paths {
274        match state.status {
275            PathStatus::Inactive(t) => {
276                // paths where holepunching succeeded at one point, but the path was closed.
277                inactive.push((addr.clone(), t));
278            }
279            PathStatus::Unusable => {
280                // paths where holepunching has been attempted and failed.
281                failed.push(addr.clone());
282            }
283            _ => {
284                // ignore paths that are open or the status is unknown
285            }
286        }
287    }
288
289    // All paths are bad, don't prune all of them.
290    //
291    // This implies that `inactive` is empty.
292    if failed.len() == paths.len() {
293        // leave the max number of non-relay paths
294        failed.truncate(paths.len().saturating_sub(MAX_NON_RELAY_PATHS));
295    }
296
297    // sort the potentially prunable from most recently closed to least recently closed
298    inactive.sort_by_key(|b| std::cmp::Reverse(b.1));
299
300    // Prune the "oldest" closed paths.
301    let old_inactive =
302        inactive.split_off(inactive.len().saturating_sub(MAX_INACTIVE_NON_RELAY_PATHS));
303
304    // collect all the paths that should be pruned
305    let must_prune: HashSet<_> = failed
306        .into_iter()
307        .chain(old_inactive.into_iter().map(|(addr, _)| addr))
308        .collect();
309
310    paths.retain(|addr, _| !must_prune.contains(addr));
311}
312
313#[cfg(test)]
314mod tests {
315    use std::{
316        net::{Ipv4Addr, SocketAddrV4},
317        time::Duration,
318    };
319
320    use iroh_base::{RelayUrl, SecretKey};
321    use rand::{RngExt, SeedableRng};
322
323    use super::*;
324
325    fn ip_addr(port: u16) -> transports::Addr {
326        transports::Addr::Ip(SocketAddrV4::new(Ipv4Addr::LOCALHOST, port).into())
327    }
328
329    fn path_state_inactive(closed: Instant) -> PathState {
330        PathState {
331            sources: HashMap::new(),
332            status: PathStatus::Inactive(closed),
333        }
334    }
335
336    fn path_state_unusable() -> PathState {
337        PathState {
338            sources: HashMap::new(),
339            status: PathStatus::Unusable,
340        }
341    }
342
343    #[test]
344    fn test_prune_under_max_paths() {
345        let mut paths = HashMap::default();
346        for i in 0..20 {
347            paths.insert(ip_addr(i), PathState::default());
348        }
349
350        prune_non_relay_paths(&mut paths);
351        assert_eq!(
352            20,
353            paths.len(),
354            "should not prune when under MAX_NON_RELAY_PATHS"
355        );
356    }
357
358    #[test]
359    fn test_prune_at_max_paths_no_prunable() {
360        let mut paths = HashMap::default();
361        // All paths are active (never abandoned), so none should be pruned
362        for i in 0..MAX_NON_RELAY_PATHS {
363            paths.insert(ip_addr(i as u16), PathState::default());
364        }
365
366        prune_non_relay_paths(&mut paths);
367        assert_eq!(
368            MAX_NON_RELAY_PATHS,
369            paths.len(),
370            "should not prune active paths"
371        );
372    }
373
374    #[test]
375    fn test_prune_failed_holepunch() {
376        let mut paths = HashMap::default();
377
378        // Add 20 active paths
379        for i in 0..20 {
380            paths.insert(ip_addr(i), PathState::default());
381        }
382
383        // Add 15 failed holepunch paths (must_prune)
384        for i in 20..35 {
385            paths.insert(ip_addr(i), path_state_unusable());
386        }
387
388        prune_non_relay_paths(&mut paths);
389
390        // All failed holepunch paths should be pruned
391        assert_eq!(20, paths.len());
392        for i in 0..20 {
393            assert!(paths.contains_key(&ip_addr(i)));
394        }
395        for i in 20..35 {
396            assert!(!paths.contains_key(&ip_addr(i)));
397        }
398    }
399
400    #[test]
401    fn test_prune_keeps_most_recent_inactive() {
402        let mut paths = HashMap::default();
403        let now = Instant::now();
404
405        // Add 15 active paths
406        for i in 0..15 {
407            paths.insert(ip_addr(i), PathState::default());
408        }
409
410        // Add 20 inactive paths with different abandon times
411        // Ports 15-34, with port 34 being most recently abandoned
412        for i in 0..20 {
413            let abandoned_time = now - Duration::from_secs((20 - i) as u64);
414            paths.insert(ip_addr(15 + i as u16), path_state_inactive(abandoned_time));
415        }
416
417        assert_eq!(35, paths.len());
418        prune_non_relay_paths(&mut paths);
419
420        // Should keep 15 active + 10 most recently abandoned
421        assert_eq!(25, paths.len());
422
423        // Active paths should remain
424        for i in 0..15 {
425            assert!(paths.contains_key(&ip_addr(i)));
426        }
427
428        // Most recently abandoned (ports 25-34) should remain
429        for i in 25..35 {
430            assert!(paths.contains_key(&ip_addr(i)), "port {} should be kept", i);
431        }
432
433        // Oldest abandoned (ports 15-24) should be pruned
434        for i in 15..25 {
435            assert!(
436                !paths.contains_key(&ip_addr(i)),
437                "port {} should be pruned",
438                i
439            );
440        }
441    }
442
443    #[test]
444    fn test_prune_mixed_must_and_can_prune() {
445        let mut paths = HashMap::default();
446        let now = Instant::now();
447
448        // Add 15 active paths
449        for i in 0..15 {
450            paths.insert(ip_addr(i), PathState::default());
451        }
452
453        // Add 5 failed holepunch paths
454        for i in 15..20 {
455            paths.insert(ip_addr(i), path_state_unusable());
456        }
457
458        // Add 15 usable but abandoned paths
459        for i in 0..15 {
460            let abandoned_time = now - Duration::from_secs((15 - i) as u64);
461            paths.insert(ip_addr(20 + i as u16), path_state_inactive(abandoned_time));
462        }
463
464        assert_eq!(35, paths.len());
465        prune_non_relay_paths(&mut paths);
466
467        // Remove all failed paths -> down to 30
468        // Keep MAX_INACTIVE_NON_RELAY_PATHS, eg remove 5 usable but abandoned paths -> down to 20
469        assert_eq!(20, paths.len());
470
471        // Active paths should remain
472        for i in 0..15 {
473            assert!(paths.contains_key(&ip_addr(i)));
474        }
475
476        // Failed holepunch should be pruned
477        for i in 15..20 {
478            assert!(!paths.contains_key(&ip_addr(i)));
479        }
480
481        // Most recently abandoned (ports 30-34) should remain
482        for i in 30..35 {
483            assert!(paths.contains_key(&ip_addr(i)), "port {} should be kept", i);
484        }
485    }
486
487    #[test]
488    fn test_prune_relay_paths_not_counted() {
489        let mut paths = HashMap::default();
490
491        // Add 25 IP paths (under MAX_NON_RELAY_PATHS)
492        for i in 0..25 {
493            paths.insert(ip_addr(i), path_state_unusable());
494        }
495
496        let mut rng = rand_chacha::ChaCha8Rng::seed_from_u64(0u64);
497        let relay_url: RelayUrl = url::Url::parse("https://localhost")
498            .expect("should be valid url")
499            .into();
500        // Add 10 relay addresses
501        for _ in 0..10 {
502            let id = SecretKey::from_bytes(&rng.random()).public();
503            let relay_addr = transports::Addr::Relay(relay_url.clone(), id);
504            paths.insert(relay_addr, PathState::default());
505        }
506
507        assert_eq!(35, paths.len()); // 25 IP + 10 relay
508        prune_non_relay_paths(&mut paths);
509
510        // Should not prune since non-relay paths < MAX_NON_RELAY_PATHS
511        assert_eq!(35, paths.len());
512    }
513
514    #[test]
515    fn test_prune_preserves_never_dialed() {
516        let mut paths = HashMap::default();
517
518        // Add 20 never-dialed paths (PathStatus::Unknown)
519        for i in 0..20 {
520            paths.insert(ip_addr(i), PathState::default());
521        }
522
523        // Add 15 failed paths to trigger pruning
524        for i in 20..35 {
525            paths.insert(ip_addr(i), path_state_unusable());
526        }
527
528        prune_non_relay_paths(&mut paths);
529
530        // Never-dialed paths should be preserved
531        for i in 0..20 {
532            assert!(paths.contains_key(&ip_addr(i)));
533        }
534    }
535
536    #[test]
537    fn test_prune_all_paths_failed() {
538        let mut paths = HashMap::default();
539
540        // Add 40 failed holepunch paths (all paths have failed)
541        for i in 0..40 {
542            paths.insert(ip_addr(i), path_state_unusable());
543        }
544
545        assert_eq!(40, paths.len());
546        prune_non_relay_paths(&mut paths);
547
548        // Should keep MAX_NON_RELAY_PATHS instead of pruning everything
549        // This prevents catastrophic loss of all path information
550        assert_eq!(
551            MAX_NON_RELAY_PATHS,
552            paths.len(),
553            "should keep MAX_NON_RELAY_PATHS when all paths failed"
554        );
555    }
556
557    #[test]
558    fn test_insert_open_path() {
559        let mut state = RemotePathState::new(Default::default());
560        let addr = ip_addr(1000);
561        let source = Source::Connection;
562
563        assert!(state.is_empty());
564
565        state.insert_open_path(addr.clone(), source.clone());
566
567        assert!(!state.is_empty());
568        assert!(state.paths.contains_key(&addr));
569        let path = &state.paths[&addr];
570        assert!(matches!(path.status, PathStatus::Open));
571        assert_eq!(path.sources.len(), 1);
572        assert!(path.sources.contains_key(&source));
573    }
574
575    #[test]
576    fn test_abandoned_path() {
577        let metrics = Arc::new(SocketMetrics::default());
578        let mut state = RemotePathState::new(metrics.clone());
579
580        // Test: Open goes to Inactive
581        let addr_open = ip_addr(1000);
582        state.insert_open_path(addr_open.clone(), Source::Connection);
583        assert!(matches!(state.paths[&addr_open].status, PathStatus::Open));
584        assert_eq!(metrics.transport_ip_paths_added.get(), 1);
585
586        state.abandoned_path(&addr_open);
587        assert!(matches!(
588            state.paths[&addr_open].status,
589            PathStatus::Inactive(_)
590        ));
591        assert_eq!(metrics.transport_ip_paths_added.get(), 1);
592        assert_eq!(metrics.transport_ip_paths_removed.get(), 1);
593
594        // Test: Inactive stays Inactive
595        state.abandoned_path(&addr_open);
596        assert!(matches!(
597            state.paths[&addr_open].status,
598            PathStatus::Inactive(_)
599        ));
600        assert_eq!(metrics.transport_ip_paths_added.get(), 1);
601        assert_eq!(metrics.transport_ip_paths_removed.get(), 1);
602
603        // Test: Unknown goes to Unusable
604        let addr_unknown = ip_addr(2000);
605        state.insert_multiple([addr_unknown.clone()].into_iter(), Source::Connection);
606        assert!(matches!(
607            state.paths[&addr_unknown].status,
608            PathStatus::Unknown
609        ));
610        assert_eq!(metrics.transport_ip_paths_added.get(), 1);
611        assert_eq!(metrics.transport_ip_paths_removed.get(), 1);
612
613        state.abandoned_path(&addr_unknown);
614        assert!(matches!(
615            state.paths[&addr_unknown].status,
616            PathStatus::Unusable
617        ));
618        assert_eq!(metrics.transport_ip_paths_added.get(), 1);
619        assert_eq!(metrics.transport_ip_paths_removed.get(), 1);
620
621        // Test: Unusable stays Unusable
622        state.abandoned_path(&addr_unknown);
623        assert!(matches!(
624            state.paths[&addr_unknown].status,
625            PathStatus::Unusable
626        ));
627        assert_eq!(metrics.transport_ip_paths_added.get(), 1);
628        assert_eq!(metrics.transport_ip_paths_removed.get(), 1);
629
630        // Test: Unusable can go to open
631        state.insert_open_path(addr_unknown.clone(), Source::Connection);
632        assert!(matches!(
633            state.paths[&addr_unknown].status,
634            PathStatus::Open
635        ));
636        assert_eq!(metrics.transport_ip_paths_added.get(), 2);
637        assert_eq!(metrics.transport_ip_paths_removed.get(), 1);
638    }
639
640    /// An empty `insert_multiple` must not drain pending resolve requests.
641    ///
642    /// This reproduces the race where multiple concurrent `connect_with_opts`
643    /// calls send `ResolveRemote` messages with empty addrs. The first pushes
644    /// a tx, then the second's `insert_multiple([])` used to drain that tx
645    /// with `NoResults { errors: [] }`, even though an address lookup was
646    /// still in flight and would shortly have resolved it.
647    #[test]
648    fn empty_insert_does_not_drain_pending() {
649        let metrics = Arc::new(SocketMetrics::default());
650        let mut state = RemotePathState::new(metrics);
651
652        let (tx, mut rx) = oneshot::channel();
653        state.resolve_remote(tx);
654
655        // Second concurrent resolve arrives with empty addrs (no app-provided
656        // addresses) while address lookup is still running.
657        state.insert_multiple(std::iter::empty(), Source::App);
658
659        assert!(
660            rx.try_recv().is_err(),
661            "pending tx must stay pending while paths are empty and lookup is in flight"
662        );
663
664        // When real addresses arrive, the tx resolves Ok.
665        state.insert_multiple([ip_addr(4242)].into_iter(), Source::App);
666        let resolved = rx.try_recv().expect("tx should have been woken");
667        assert!(resolved.is_ok(), "expected Ok once a path was added");
668    }
669
670    /// `address_lookup_finished(Ok(()))` drains pending requests with `NoResults` when no paths are known.
671    ///
672    /// This is the "lookup done but nothing was found" signal and it must
673    /// still reach callers.
674    #[test]
675    fn address_lookup_finished_empty_emits_no_results() {
676        let metrics = Arc::new(SocketMetrics::default());
677        let mut state = RemotePathState::new(metrics);
678
679        let (tx, mut rx) = oneshot::channel();
680        state.resolve_remote(tx);
681
682        state.address_lookup_finished(Ok(()));
683
684        let resolved = rx.try_recv().expect("tx should have been woken");
685        assert!(matches!(
686            resolved,
687            Err(AddressLookupFailed::NoResults { .. })
688        ));
689    }
690}