Skip to content

Commit

Permalink
Revert network unreachable detection
Browse files Browse the repository at this point in the history
  • Loading branch information
umgefahren committed Jun 16, 2024
1 parent ff806a3 commit 75a86c2
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 31 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions protocols/autonat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ rand = "0.8"
rand_core = { version = "0.6", optional = true }
thiserror = { version = "1.0.52", optional = true }
void = { version = "1", optional = true }
libc = { version = "0.2", optional = true }

[dev-dependencies]
tokio = { version = "1", features = ["macros", "rt", "sync"]}
Expand All @@ -44,8 +43,7 @@ libp2p-swarm = { workspace = true, features = ["macros"]}
[features]
default = ["v1", "v2"]
v1 = ["dep:libp2p-request-response"]
v2 = ["dep:bytes", "dep:either", "dep:futures-bounded", "dep:thiserror", "dep:void",
"dep:rand_core", "dep:libc"]
v2 = ["dep:bytes", "dep:either", "dep:futures-bounded", "dep:thiserror", "dep:void", "dep:rand_core"]

[lints]
workspace = true
Expand Down
29 changes: 2 additions & 27 deletions protocols/autonat/src/v2/server/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,11 @@ where
}

fn on_swarm_event(&mut self, event: FromSwarm) {
if let FromSwarm::DialFailure(DialFailure {
connection_id,
error,
..
}) = event
{
if let FromSwarm::DialFailure(DialFailure { connection_id, .. }) = event {
if let Some(DialBackCommand { back_channel, .. }) =
self.dialing_dial_back.remove(&connection_id)
{
let dial_back_status = if let DialError::Transport(errors) = error {
if errors.iter().any(|(_, e)| matches!(e, TransportError::Other(ie) if is_network_unreachable(ie))) {
DialBackStatus::Unreachable
} else {
DialBackStatus::DialErr
}
} else {
DialBackStatus::DialErr
};
let dial_back_status = DialBackStatus::DialErr;
let _ = back_channel.send(Err(dial_back_status));
}
}
Expand Down Expand Up @@ -170,15 +157,3 @@ pub struct Event {
/// The result of the test.
pub result: Result<(), io::Error>,
}

#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
fn is_network_unreachable(err: &io::Error) -> bool {
err.raw_os_error()
.map(|e| e == libc::ENETUNREACH)
.unwrap_or(false)
}

#[cfg(all(target_family = "wasm", target_os = "unknown"))]
fn is_network_unreachable(_err: &io::Error) -> bool {
false
}

0 comments on commit 75a86c2

Please sign in to comment.