diff --git a/src/client.rs b/src/client.rs index 69f5c6f..08e920c 100644 --- a/src/client.rs +++ b/src/client.rs @@ -5,7 +5,8 @@ use tokio::net::{TcpListener, TcpStream}; use anyhow::{anyhow, Result}; use futures::future::try_join; -use log::info; +use log::{error, info}; +use quinn::ConnectionError; use quinn::Endpoint; use structopt::{self, StructOpt}; @@ -115,7 +116,27 @@ async fn transfer( let new_conn = endpoint .connect(*remote, &host)? .await - .map_err(|e| anyhow!("failed to connect: {}", e))?; + .map_err(|e| { + if e == ConnectionError::TimedOut { + let socket = if cfg!(target_os = "windows") { + std::net::UdpSocket::bind("0.0.0.0:0").unwrap() + } else { + std::net::UdpSocket::bind("[::]:0").unwrap() + }; + let addr = socket.local_addr().unwrap(); + let ret = endpoint.rebind(socket); + match ret { + Ok(_) => { + info!("rebinding to: {}", addr); + } + Err(e) => { + error!("rebind fail: {:?}", e); + } + } + } + anyhow!("failed to connect: {:?}", e) + }) + .unwrap(); let quinn::NewConnection { connection: conn, ..