Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
matheus23 committed Jan 13, 2025
1 parent 1ae8dad commit 9882320
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions iroh/src/magicsock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,13 +545,16 @@ impl MagicSock {
.map(|err| err.kind() == io::ErrorKind::WouldBlock)
.unwrap_or_default();

let udp_path = udp_addr.is_some();
let relay_path = relay_url.is_some();
let has_path = udp_path || relay_path;
let would_block = match (&udp_addr, &relay_url) {
(Some(_udp), Some(_relay)) => udp_pending && relay_pending,
(Some(_udp), None) => udp_pending,
(None, Some(_relay)) => relay_pending,
(None, None) => false,
};

if (udp_pending || !udp_path) && (relay_pending || !relay_path) && has_path {
if would_block {
// Handle backpressure.
inc!(MagicsockMetrics, send_pending);
inc!(MagicsockMetrics, send_would_block);
Err(io::Error::new(io::ErrorKind::WouldBlock, "pending"))
} else {
if relay_sent || udp_sent {
Expand Down
4 changes: 2 additions & 2 deletions iroh/src/magicsock/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct Metrics {
// Data packets (non-disco)
pub send_data: Counter,
pub send_data_network_down: Counter,
pub send_pending: Counter,
pub send_would_block: Counter,
pub recv_data_relay: Counter,
pub recv_data_ipv4: Counter,
pub recv_data_ipv6: Counter,
Expand Down Expand Up @@ -100,7 +100,7 @@ impl Default for Metrics {
// Data packets (non-disco)
send_data: Counter::new("send_data"),
send_data_network_down: Counter::new("send_data_network_down"),
send_pending: Counter::new("send_data"),
send_would_block: Counter::new("send_data"),
recv_data_relay: Counter::new("recv_data_relay"),
recv_data_ipv4: Counter::new("recv_data_ipv4"),
recv_data_ipv6: Counter::new("recv_data_ipv6"),
Expand Down

0 comments on commit 9882320

Please sign in to comment.