That was completely wrong
Look the whole point of the ports in the config is to have them enabled *even if the server doesn't show them to you.* The other behavior was just completely wrong in that respect.
This commit is contained in:
parent
8f12945d83
commit
0ad0fb1a56
1 changed files with 16 additions and 29 deletions
|
|
@ -78,7 +78,6 @@ pub enum State {
|
||||||
Enabled,
|
Enabled,
|
||||||
Broken,
|
Broken,
|
||||||
Disabled,
|
Disabled,
|
||||||
Configured,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
|
|
@ -109,7 +108,11 @@ impl Listener {
|
||||||
|
|
||||||
pub fn from_config(config: PortConfig) -> Self {
|
pub fn from_config(config: PortConfig) -> Self {
|
||||||
Listener {
|
Listener {
|
||||||
state: State::Configured.boxed(),
|
state: if config.enabled {
|
||||||
|
State::Enabled.boxed()
|
||||||
|
} else {
|
||||||
|
State::Disabled.boxed()
|
||||||
|
},
|
||||||
config: Some(config),
|
config: Some(config),
|
||||||
stop: None,
|
stop: None,
|
||||||
desc: None,
|
desc: None,
|
||||||
|
|
@ -146,13 +149,6 @@ impl Listener {
|
||||||
// If we're just sitting idle and the port comes in from the remote
|
// If we're just sitting idle and the port comes in from the remote
|
||||||
// server then we should become enabled. Otherwise we should become
|
// server then we should become enabled. Otherwise we should become
|
||||||
// real, but disabled.
|
// real, but disabled.
|
||||||
if self.state() == State::Configured {
|
|
||||||
if self.config.as_ref().unwrap().enabled {
|
|
||||||
self.state = State::Enabled.boxed();
|
|
||||||
} else {
|
|
||||||
self.state = State::Disabled.boxed();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.desc = Some(desc);
|
self.desc = Some(desc);
|
||||||
self.start(socks_port);
|
self.start(socks_port);
|
||||||
}
|
}
|
||||||
|
|
@ -160,13 +156,6 @@ impl Listener {
|
||||||
pub fn disconnect(&mut self) {
|
pub fn disconnect(&mut self) {
|
||||||
self.desc = None;
|
self.desc = None;
|
||||||
self.stop = None;
|
self.stop = None;
|
||||||
|
|
||||||
// When we get disconnected, but we're present in the configuration,
|
|
||||||
// we go back to being merely 'Configured'. If the port shows up
|
|
||||||
// again, our auto-enable behavior will depend on the configuration.
|
|
||||||
if self.config.is_some() {
|
|
||||||
self.state = State::Configured.boxed();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start(&mut self, socks_port: Option<u16>) {
|
pub fn start(&mut self, socks_port: Option<u16>) {
|
||||||
|
|
@ -323,9 +312,7 @@ impl UI {
|
||||||
let (symbol, style) = match listener.state() {
|
let (symbol, style) = match listener.state() {
|
||||||
State::Enabled => (" ✓ ", enabled_port_style),
|
State::Enabled => (" ✓ ", enabled_port_style),
|
||||||
State::Broken => (" ✗ ", broken_port_style),
|
State::Broken => (" ✗ ", broken_port_style),
|
||||||
State::Disabled | State::Configured => {
|
State::Disabled => ("", disabled_port_style),
|
||||||
("", disabled_port_style)
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
rows.push(
|
rows.push(
|
||||||
Row::new(vec![
|
Row::new(vec![
|
||||||
|
|
@ -1037,7 +1024,7 @@ mod tests {
|
||||||
|
|
||||||
// But there should still be ports, man.
|
// But there should still be ports, man.
|
||||||
let listener = ui.ports.get(&8080).unwrap();
|
let listener = ui.ports.get(&8080).unwrap();
|
||||||
assert_eq!(listener.state(), State::Configured);
|
assert_eq!(listener.state(), State::Disabled);
|
||||||
assert_eq!(listener.description(), "override");
|
assert_eq!(listener.description(), "override");
|
||||||
|
|
||||||
drop(sender);
|
drop(sender);
|
||||||
|
|
@ -1052,17 +1039,17 @@ mod tests {
|
||||||
|
|
||||||
let mut ui = UI::new(receiver, config);
|
let mut ui = UI::new(receiver, config);
|
||||||
|
|
||||||
// No ports have been received, make sure everything's "configured"
|
// No ports have been received, make sure everything's in its default state.
|
||||||
assert_eq!(ui.ports.get(&8080).unwrap().state(), State::Configured);
|
assert_eq!(ui.ports.get(&8080).unwrap().state(), State::Disabled);
|
||||||
assert_eq!(ui.ports.get(&8081).unwrap().state(), State::Configured);
|
assert_eq!(ui.ports.get(&8081).unwrap().state(), State::Enabled);
|
||||||
|
|
||||||
// 8080 shows up.... not configured as enabled so it becomes "disabled"
|
// 8080 shows up.... doesn't affect anything.
|
||||||
ui.handle_internal_event(Some(UIEvent::Ports(vec![PortDesc {
|
ui.handle_internal_event(Some(UIEvent::Ports(vec![PortDesc {
|
||||||
port: 8080,
|
port: 8080,
|
||||||
desc: "python3".to_string(),
|
desc: "python3".to_string(),
|
||||||
}])));
|
}])));
|
||||||
assert_eq!(ui.ports.get(&8080).unwrap().state(), State::Disabled);
|
assert_eq!(ui.ports.get(&8080).unwrap().state(), State::Disabled);
|
||||||
assert_eq!(ui.ports.get(&8081).unwrap().state(), State::Configured);
|
assert_eq!(ui.ports.get(&8081).unwrap().state(), State::Enabled);
|
||||||
|
|
||||||
// 8081 shows up.... configured as enabled so it becomes "enabled"
|
// 8081 shows up.... configured as enabled so it becomes "enabled"
|
||||||
ui.handle_internal_event(Some(UIEvent::Ports(vec![
|
ui.handle_internal_event(Some(UIEvent::Ports(vec![
|
||||||
|
|
@ -1082,19 +1069,19 @@ mod tests {
|
||||||
assert_eq!(ui.ports.get(&8081).unwrap().state(), State::Enabled);
|
assert_eq!(ui.ports.get(&8081).unwrap().state(), State::Enabled);
|
||||||
assert_eq!(ui.ports.get(&8082).unwrap().state(), State::Enabled);
|
assert_eq!(ui.ports.get(&8082).unwrap().state(), State::Enabled);
|
||||||
|
|
||||||
// 8081 goes away.... back to configured.
|
// 8081 goes away....
|
||||||
ui.handle_internal_event(Some(UIEvent::Ports(vec![
|
ui.handle_internal_event(Some(UIEvent::Ports(vec![
|
||||||
PortDesc { port: 8080, desc: "python3".to_string() },
|
PortDesc { port: 8080, desc: "python3".to_string() },
|
||||||
PortDesc { port: 8082, desc: "python3".to_string() },
|
PortDesc { port: 8082, desc: "python3".to_string() },
|
||||||
])));
|
])));
|
||||||
assert_eq!(ui.ports.get(&8080).unwrap().state(), State::Disabled);
|
assert_eq!(ui.ports.get(&8080).unwrap().state(), State::Disabled);
|
||||||
assert_eq!(ui.ports.get(&8081).unwrap().state(), State::Configured);
|
assert_eq!(ui.ports.get(&8081).unwrap().state(), State::Enabled);
|
||||||
assert_eq!(ui.ports.get(&8082).unwrap().state(), State::Enabled);
|
assert_eq!(ui.ports.get(&8082).unwrap().state(), State::Enabled);
|
||||||
|
|
||||||
// All gone, state resets itself.
|
// All gone, state resets itself.
|
||||||
ui.handle_internal_event(Some(UIEvent::Ports(vec![])));
|
ui.handle_internal_event(Some(UIEvent::Ports(vec![])));
|
||||||
assert_eq!(ui.ports.get(&8080).unwrap().state(), State::Configured);
|
assert_eq!(ui.ports.get(&8080).unwrap().state(), State::Disabled);
|
||||||
assert_eq!(ui.ports.get(&8081).unwrap().state(), State::Configured);
|
assert_eq!(ui.ports.get(&8081).unwrap().state(), State::Enabled);
|
||||||
assert!(!ui.ports.contains_key(&8082));
|
assert!(!ui.ports.contains_key(&8082));
|
||||||
|
|
||||||
drop(sender);
|
drop(sender);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue