Skip to content

Commit

Permalink
Merge pull request #2240 from subspace/fix-random-port-fallback-udp
Browse files Browse the repository at this point in the history
Fix random port fallback for UDP
  • Loading branch information
nazar-pc authored Nov 17, 2023
2 parents 37472c9 + af684fa commit 21b1c75
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions crates/subspace-networking/src/constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,10 +573,24 @@ where

let addr_string = addr.to_string();
// Listen on random port if specified is already occupied
if let Some(Protocol::Tcp(_port)) = addr.pop() {
info!("Failed to listen on {addr_string} ({error}), falling back to random port");
addr.push(Protocol::Tcp(0));
swarm.listen_on(addr)?;
match addr.pop() {
Some(Protocol::Tcp(_port)) => {
info!(
"Failed to listen on {addr_string} ({error}), falling back to random port"
);
addr.push(Protocol::Tcp(0));
swarm.listen_on(addr)?;
}
Some(Protocol::Udp(_port)) => {
info!(
"Failed to listen on {addr_string} ({error}), falling back to random port"
);
addr.push(Protocol::Udp(0));
swarm.listen_on(addr)?;
}
_ => {
// Do not care about other protocols
}
}
}
}
Expand Down

0 comments on commit 21b1c75

Please sign in to comment.