Added option to retry creating tunnels
This commit is contained in:
parent
15f382b654
commit
d944efc24a
|
@ -116,6 +116,18 @@ impl Handler {
|
||||||
warn!("User not set");
|
warn!("User not set");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Input::Char('r') => {
|
||||||
|
let Some(selected) = self.selected else {
|
||||||
|
return Ok(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
let Some(tunnel) = self.tunnels.get_mut(selected) else {
|
||||||
|
warn!("Trying to retry invalid tunnel");
|
||||||
|
return Ok(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
*tunnel = self.all_tunnels.retry_tunnel(tunnel.clone()).await;
|
||||||
|
}
|
||||||
Input::Delete => {
|
Input::Delete => {
|
||||||
let Some(selected) = self.selected else {
|
let Some(selected) = self.selected else {
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
|
@ -285,7 +297,7 @@ impl russh::server::Handler for Handler {
|
||||||
|
|
||||||
let tunnel = self
|
let tunnel = self
|
||||||
.all_tunnels
|
.all_tunnels
|
||||||
.add_tunnel(session.handle(), address, *port, user)
|
.create_tunnel(session.handle(), address, *port, user)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
self.tunnels.push(tunnel);
|
self.tunnels.push(tunnel);
|
||||||
|
|
|
@ -42,11 +42,12 @@ impl Renderer {
|
||||||
command("esc", "deselect"),
|
command("esc", "deselect"),
|
||||||
command("↓/j", "move down"),
|
command("↓/j", "move down"),
|
||||||
command("↑/k", "move up"),
|
command("↑/k", "move up"),
|
||||||
command("del", "close tunnel"),
|
|
||||||
vec![],
|
vec![],
|
||||||
command("p", "make private"),
|
command("p", "make private"),
|
||||||
command("ctrl-p", "make protected"),
|
command("ctrl-p", "make protected"),
|
||||||
command("shift-p", "make public"),
|
command("shift-p", "make public"),
|
||||||
|
command("del", "remove"),
|
||||||
|
command("r", "retry"),
|
||||||
]
|
]
|
||||||
} else {
|
} else {
|
||||||
vec![
|
vec![
|
||||||
|
|
|
@ -85,7 +85,7 @@ impl Tunnels {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn add_tunnel(
|
pub async fn create_tunnel(
|
||||||
&mut self,
|
&mut self,
|
||||||
handle: Handle,
|
handle: Handle,
|
||||||
name: impl Into<String>,
|
name: impl Into<String>,
|
||||||
|
@ -117,8 +117,12 @@ impl Tunnels {
|
||||||
trace!(tunnel = tunnel.name, "Already in use, picking new name");
|
trace!(tunnel = tunnel.name, "Already in use, picking new name");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let address = tunnel.get_address().expect("domain is set");
|
|
||||||
|
|
||||||
|
self.add_tunnel(tunnel).await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn add_tunnel(&mut self, mut tunnel: Tunnel) -> Tunnel {
|
||||||
|
let address = tunnel.get_address().expect("domain is set");
|
||||||
if let Entry::Vacant(e) = self.tunnels.write().await.entry(address) {
|
if let Entry::Vacant(e) = self.tunnels.write().await.entry(address) {
|
||||||
trace!(tunnel = tunnel.name, "Adding tunnel");
|
trace!(tunnel = tunnel.name, "Adding tunnel");
|
||||||
e.insert(tunnel.clone());
|
e.insert(tunnel.clone());
|
||||||
|
@ -130,12 +134,21 @@ impl Tunnels {
|
||||||
tunnel
|
tunnel
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn remove_tunnel(&mut self, tunnel: Tunnel) {
|
pub async fn remove_tunnel(&mut self, mut tunnel: Tunnel) -> Tunnel {
|
||||||
let mut all_tunnels = self.tunnels.write().await;
|
let mut all_tunnels = self.tunnels.write().await;
|
||||||
if let Some(address) = tunnel.get_address() {
|
if let Some(address) = tunnel.get_address() {
|
||||||
trace!(tunnel.name, "Removing tunnel");
|
trace!(tunnel.name, "Removing tunnel");
|
||||||
all_tunnels.remove(&address);
|
all_tunnels.remove(&address);
|
||||||
}
|
}
|
||||||
|
tunnel.domain = None;
|
||||||
|
tunnel
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn retry_tunnel(&mut self, tunnel: Tunnel) -> Tunnel {
|
||||||
|
let mut tunnel = self.remove_tunnel(tunnel).await;
|
||||||
|
tunnel.domain = Some(self.domain.clone());
|
||||||
|
|
||||||
|
self.add_tunnel(tunnel).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user