aboutsummaryrefslogtreecommitdiffstats
path: root/src/transport
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/identity.rs25
-rw-r--r--src/transport/paths.rs5
-rw-r--r--src/transport/stats.rs9
3 files changed, 37 insertions, 2 deletions
diff --git a/src/transport/identity.rs b/src/transport/identity.rs
index 303177a..886f601 100644
--- a/src/transport/identity.rs
+++ b/src/transport/identity.rs
@@ -187,6 +187,8 @@ impl Book {
}
IdentityStats {
proven,
+ // Asked of the transports outside this lock (`IdentityTransport::stats`).
+ relayed: std::collections::BTreeMap::new(),
hinted: self
.hints
.keys()
@@ -294,6 +296,22 @@ impl Shared {
}
impl Shared {
+ /// Of the nodes in `proven`, those each transport reaches only through a relay, by
+ /// transport (`IdentityStats::relayed`); asked of the transports, so not under the
+ /// book's lock.
+ fn relayed(
+ &self,
+ proven: &HashMap<String, Vec<String>>,
+ ) -> std::collections::BTreeMap<String, usize> {
+ let mut relayed = std::collections::BTreeMap::new();
+ for address in proven.values().flatten() {
+ if self.paths.connection(address) == Some(Connection::Relayed) {
+ *relayed.entry(scheme_of(address).to_owned()).or_insert(0) += 1;
+ }
+ }
+ relayed
+ }
+
fn lock(&self) -> MutexGuard<'_, Book> {
self.book.lock_or_recover()
}
@@ -581,8 +599,13 @@ impl Transport for IdentityTransport {
/// The identity layer's, and each transport's.
fn stats(&self) -> TransportStats {
let mut stats = self.shared.paths.stats();
+ let (mut identity, proven) = {
+ let books = self.shared.lock();
+ (books.stats(), books.proven.clone())
+ };
+ identity.relayed = self.shared.relayed(&proven);
stats.merge(TransportStats {
- identity: Some(self.shared.lock().stats()),
+ identity: Some(identity),
..TransportStats::default()
});
stats
diff --git a/src/transport/paths.rs b/src/transport/paths.rs
index a8c7c49..76d22b6 100644
--- a/src/transport/paths.rs
+++ b/src/transport/paths.rs
@@ -361,6 +361,7 @@ impl Table {
.and_then(|path| path.rtt)
.map(|rtt| rtt.as_secs_f64() * 1000.0),
down: path.is_some_and(|path| path.is_down(now)),
+ connection: None,
}
}
}
@@ -472,9 +473,11 @@ impl Paths {
self.located(infos)
}
- /// `infos` with where each path goes (`located`); asked outside the table's lock.
+ /// `infos` with where each path goes (`located`) and the transport's connection
+ /// there; asked outside the table's lock.
fn located(&self, mut infos: Vec<PathInfo>) -> Vec<PathInfo> {
for info in &mut infos {
+ info.connection = self.connection(&info.address);
info.address = self.location(&info.address);
}
infos
diff --git a/src/transport/stats.rs b/src/transport/stats.rs
index 398ffdf..ed8b247 100644
--- a/src/transport/stats.rs
+++ b/src/transport/stats.rs
@@ -6,6 +6,8 @@ use std::collections::BTreeMap;
use serde::Serialize;
+use super::Connection;
+
#[derive(Debug, Clone, Default, Serialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct TransportStats {
@@ -58,6 +60,10 @@ pub(crate) struct PathInfo {
/// Its PINGs went unanswered three times in a row, or a send there failed within a
/// minute: used only when no other path works.
pub(crate) down: bool,
+ /// The transport's connection there, if it has connections (libp2p: direct or
+ /// relayed; `Transport::connection`).
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub(crate) connection: Option<Connection>,
}
/// Counts since start.
@@ -82,6 +88,9 @@ pub(crate) struct IdentityStats {
/// Nodes proven at an address, by transport (scheme); a node on several counts on
/// each.
pub(crate) proven: BTreeMap<String, usize>,
+ /// Of those, the nodes the transport reaches only through a relay (no direct
+ /// connection at its address there), by transport; absent where none is.
+ pub(crate) relayed: BTreeMap<String, usize>,
/// Nodes known only from hints (the member list, HELLO_REPLYs), proven nowhere.
pub(crate) hinted: usize,
#[serde(flatten)]