correctly handle listener add fail

This commit is contained in:
sijie.sun 2024-05-11 22:49:48 +08:00 committed by Sijie.Sun
parent 1b1d76de99
commit 29d8d4ba87
3 changed files with 16 additions and 3 deletions

View File

@ -27,7 +27,8 @@ pub enum GlobalCtxEvent {
PeerConnRemoved(PeerConnInfo),
ListenerAdded(url::Url),
ConnectionAccepted(String, String), // (local url, remote url)
ListenerAddFailed(url::Url, String), // (url, error message)
ConnectionAccepted(String, String), // (local url, remote url)
ConnectionError(String, String, String), // (local url, remote url, error message)
Connecting(url::Url),

View File

@ -374,6 +374,13 @@ pub async fn async_main(cli: Cli) {
));
}
GlobalCtxEvent::ListenerAddFailed(p, msg) => {
print_event(format!(
"listener add failed. listener: {}, msg: {}",
p, msg
));
}
GlobalCtxEvent::ListenerAdded(p) => {
if p.scheme() == "ring" {
continue;

View File

@ -45,7 +45,7 @@ pub fn get_listener_by_url(
Box::new(WSTunnelListener::new(l.clone()))
}
_ => {
unreachable!("unsupported listener uri");
return Err(Error::InvalidUrl(l.to_string()));
}
})
}
@ -101,7 +101,12 @@ impl<H: TunnelHandlerForListener + Send + Sync + 'static + Debug> ListenerManage
.await?;
for l in self.global_ctx.config.get_listener_uris().iter() {
let lis = get_listener_by_url(l, self.global_ctx.clone())?;
let Ok(lis) = get_listener_by_url(l, self.global_ctx.clone()) else {
let msg = format!("failed to get listener by url: {}, maybe not supported", l);
self.global_ctx
.issue_event(GlobalCtxEvent::ListenerAddFailed(l.clone(), msg));
continue;
};
self.add_listener(lis, true).await?;
}