Skip to content

Commit

Permalink
refactor(iroh-net): Remove PathState::recent_pong() (#2745)
Browse files Browse the repository at this point in the history
## Description

The field itself is also directly accessible with the same visibility
as this function.  Having two ways to get to this value is a bit
confusing.  And directly using the field makes it easier when checking
users by following the references from rust-analyzer.


## Breaking Changes

None

## Notes & open questions

None

## Change checklist

- [x] Self-review.
- ~~[ ] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.~~
- ~~[ ] Tests if relevant.~~
- ~~[ ] All breaking changes documented.~~
  • Loading branch information
flub authored Sep 23, 2024
1 parent 2262fd5 commit cafdc08
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
10 changes: 5 additions & 5 deletions iroh-net/src/magicsock/node_map/node_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,15 @@ impl NodeState {
.udp_paths
.paths
.iter()
.map(|(addr, endpoint_state)| DirectAddrInfo {
.map(|(addr, path_state)| DirectAddrInfo {
addr: SocketAddr::from(*addr),
latency: endpoint_state.recent_pong().map(|pong| pong.latency),
last_control: endpoint_state.last_control_msg(now),
last_payload: endpoint_state
latency: path_state.recent_pong.as_ref().map(|pong| pong.latency),
last_control: path_state.last_control_msg(now),
last_payload: path_state
.last_payload_msg
.as_ref()
.map(|instant| now.duration_since(*instant)),
last_alive: endpoint_state
last_alive: path_state
.last_alive()
.map(|instant| now.duration_since(instant)),
})
Expand Down
11 changes: 4 additions & 7 deletions iroh-net/src/magicsock/node_map/path_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ impl PathState {
/// - When the last payload transmission occurred.
/// - when the last ping from them was received.
pub(super) fn last_alive(&self) -> Option<Instant> {
self.recent_pong()
self.recent_pong
.as_ref()
.map(|pong| &pong.pong_at)
.into_iter()
.chain(self.last_payload_msg.as_ref())
Expand All @@ -173,7 +174,8 @@ impl PathState {
pub(super) fn last_control_msg(&self, now: Instant) -> Option<(Duration, ControlMsg)> {
// get every control message and assign it its kind
let last_pong = self
.recent_pong()
.recent_pong
.as_ref()
.map(|pong| (pong.pong_at, ControlMsg::Pong));
let last_call_me_maybe = self
.call_me_maybe_time
Expand All @@ -191,11 +193,6 @@ impl PathState {
.map(|(instant, kind)| (now.duration_since(instant), kind))
}

/// Returns the most recent pong if available.
pub(super) fn recent_pong(&self) -> Option<&PongReply> {
self.recent_pong.as_ref()
}

/// Returns the latency from the most recent pong, if available.
pub(super) fn latency(&self) -> Option<Duration> {
self.recent_pong.as_ref().map(|p| p.latency)
Expand Down
4 changes: 2 additions & 2 deletions iroh-net/src/magicsock/node_map/udp_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ impl NodeUdpPaths {
let best_latency = best_pong
.map(|p: &PongReply| p.latency)
.unwrap_or(MAX_LATENCY);
match state.recent_pong() {
match state.recent_pong {
// This pong is better if it has a lower latency, or if it has the same
// latency but on an IPv6 path.
Some(pong)
Some(ref pong)
if pong.latency < best_latency
|| (pong.latency == best_latency && ipp.ip().is_ipv6()) =>
{
Expand Down

0 comments on commit cafdc08

Please sign in to comment.