Commit ebfbd83a authored by Katharina Fey's avatar Katharina Fey

qaul-hubd: adding more graceful upnp failures

parent a7fdb88a
......@@ -10,6 +10,8 @@ mod upnp;
use async_std::{future, task::Poll};
use state::State;
use tracing::error;
pub(crate) fn elog<S: Into<String>>(msg: S, code: u16) -> ! {
tracing::error!("{}", msg.into());
std::process::exit(code.into());
......@@ -21,13 +23,16 @@ async fn main() {
let app = cfg::cli();
let cfg = cfg::match_fold(app);
let _state = State::new(&cfg).await;
if upnp::open_port(cfg.port).is_none() {
error!("Failed to open UPNP port; your router probably doesn't support it...");
}
// let _state = State::new(&cfg).await;
// !no_upnp means upnp has _not_ been disabled
if !cfg.no_upnp {
upnp::open_port(cfg.port);
}
// if !cfg.no_upnp {
// }
// Never return the main thread or it all dies
let _: () = future::poll_fn(|_| Poll::Pending).await;
// // Never return the main thread or it all dies
// let _: () = future::poll_fn(|_| Poll::Pending).await;
}
......@@ -46,19 +46,20 @@ fn find_local_ip() -> Option<Ipv4Addr> {
})
}
pub(crate) fn open_port(port: u16) {
// let gw = search_gateway(Default::default()).unwrap();
pub(crate) fn open_port(port: u16) -> Option<()> {
let gw = search_gateway(Default::default()).ok()?;
// let ip = gw.get_external_ip().unwrap();
// trace!("Publicly accessible via: {}", ip);
let ip = gw.get_external_ip().ok()?;
trace!("Publicly accessible via: {}", ip);
// let local_ip =
// find_local_ip().unwrap_or_else(|| crate::elog("Couldn't find IP to bind to", 128));
// trace!("Local ip: {}", local_ip);
let local_ip =
find_local_ip().unwrap_or_else(|| crate::elog("Couldn't find IP to bind to", 128));
trace!("Local ip: {}", local_ip);
// let local_addr = SocketAddrV4::new(local_ip, 8080);
let local_addr = SocketAddrV4::new(local_ip, 8080);
// gw.add_port(Protocol::TCP, port, local_addr, 0, "qaul-hubd tcp driver")
// .unwrap_or_else(|e| crate::elog(format!("{:?}", e), 128));
// trace!("UPNP port {} opened with infinite lease!", port);
gw.add_port(Protocol::TCP, port, local_addr, 0, "qaul-hubd tcp driver")
.unwrap_or_else(|e| crate::elog(format!("{:?}", e), 128));
trace!("UPNP port {} opened with infinite lease!", port);
Some(())
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment