hopr_transport/observer.rs
1//! Events the transport reports to an optional observer, such as the node's periodic state dump.
2//!
3//! The transport only reports what happened. It does not know who listens or what is done with the
4//! events, so it needs no dependency on the code that summarizes them.
5use std::sync::Arc;
6
7use hopr_api::{OffchainPublicKey, graph::ForwardAndReturnPath, types::internal::NodeId};
8
9/// Whether a path carries packets to a destination, or replies back from it.
10#[derive(Clone, Copy, Debug, PartialEq, Eq)]
11pub enum PathDirection {
12 Forward,
13 Return,
14}
15
16/// How many candidates one search phase returned, and how many of them were usable.
17#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
18pub struct PhaseCounts {
19 pub returned: u64,
20 pub eligible: u64,
21}
22
23/// One thing the transport observed.
24#[derive(Clone, Debug)]
25pub enum TransportEvent {
26 /// A path resolve finished, including one served from the cache.
27 PathResolved {
28 direction: PathDirection,
29 destination: NodeId,
30 succeeded: bool,
31 },
32 /// The selector searched the graph. `phase2` is `None` when the second phase did not run.
33 PathSearched {
34 direction: PathDirection,
35 destination: NodeId,
36 phase1: PhaseCounts,
37 phase2: Option<PhaseCounts>,
38 retained: u64,
39 },
40 /// SURBs minted for, or returned from, one destination over one pair of paths.
41 Surb {
42 destination: OffchainPublicKey,
43 paths: ForwardAndReturnPath,
44 minted: u64,
45 returned: u64,
46 },
47}
48
49/// Receives [`TransportEvent`]s. It is called on the packet path, so it must be cheap and must not
50/// block.
51pub type TransportObserver = Arc<dyn Fn(TransportEvent) + Send + Sync>;