diff options
Diffstat (limited to 'src/transport/mod.rs')
| -rw-r--r-- | src/transport/mod.rs | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/transport/mod.rs b/src/transport/mod.rs index 839476b..7cd976b 100644 --- a/src/transport/mod.rs +++ b/src/transport/mod.rs @@ -570,6 +570,17 @@ pub(crate) type HandlerFn = dyn Fn(String, ParsedMessage, usize) -> Pin<Box<dyn + 'static; pub(crate) type MessageHandler = Box<HandlerFn>; +/// A transport identity (or location) as an address, `<scheme>:<it>`, the way paths and +/// the identity layer show it: for a transport's own log lines, so that a peer reads the +/// same in every one. +pub(crate) struct Addressed<T>(pub(crate) &'static str, pub(crate) T); + +impl<T: std::fmt::Display> std::fmt::Display for Addressed<T> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}:{}", self.0, self.1) + } +} + /// Whether `message` is a PING or PONG. The paths layer times them, so a transport's /// consumer hands them on as soon as they are read (`hand_on_probe`), not after the /// messages read before them are handled (which can take a while: sync). @@ -577,8 +588,10 @@ pub(crate) fn is_probe(message: &ParsedMessage) -> bool { matches!(message, ParsedMessage::Ping(_) | ParsedMessage::Pong(_)) } -/// Hands a PING or PONG (`is_probe`) to `handler` in a task of its own. +/// Hands a PING or PONG (`is_probe`) to `handler` in a task of its own; `scheme` is the +/// transport's, for the log. pub(crate) fn hand_on_probe( + scheme: &'static str, handler: &std::sync::Arc<HandlerFn>, sender: String, message: ParsedMessage, @@ -587,7 +600,7 @@ pub(crate) fn hand_on_probe( let handler = std::sync::Arc::clone(handler); tokio::spawn(async move { if let Err(error) = handler(sender.clone(), message, payload_len).await { - tracing::warn!(peer = %sender, error = %format!("{error:#}"), "Failed to process inbound message"); + tracing::warn!(peer = %Addressed(scheme, &sender), error = %format!("{error:#}"), "Failed to process inbound message"); } }); } @@ -628,6 +641,13 @@ pub(crate) trait Transport: Send + Sync { vec![target.to_owned()] } + /// For a transport under the identity layer: the addresses (`<scheme>:<transport + /// identity>`, as paths keep them) `peer` proved itself at or is said to be at; this + /// node's own, for its own node ID. By default its identity. + fn identities_of(&self, peer: &str) -> Vec<String> { + vec![peer.to_owned()] + } + /// Where `peer` can be reached, as far as this node knows: passed on to others (in /// a HELLO_REPLY). By default its identity, as for `local_addresses`. fn addresses_of(&self, peer: &str) -> Vec<String> { |
