mirror of
https://github.com/wownero/i2p-zero.git
synced 2026-10-17 15:21:40 +02:00
removed startup race condition. shutdown and exit now triggered on off switch toggled
This commit is contained in:
@@ -74,6 +74,7 @@ public class Controller {
|
||||
|
||||
DecimalFormat format2dp = new DecimalFormat("0.00");
|
||||
private boolean masterState = true;
|
||||
private boolean shuttingDown = false;
|
||||
private final ObservableList<Tunnel> tunnelTableList = FXCollections.observableArrayList();
|
||||
private boolean eepSiteTabInitialized = false;
|
||||
|
||||
@@ -235,37 +236,29 @@ public class Controller {
|
||||
});
|
||||
|
||||
masterToggle.setOnMouseClicked(e->{
|
||||
if(shuttingDown) return;
|
||||
masterState = !masterState;
|
||||
bandwidthDisabledOverlay.setVisible(!masterState);
|
||||
|
||||
if(masterState) {
|
||||
masterToggle.setImage(new Image("org/getmonero/i2p/zero/gui/toggle-on.png"));
|
||||
statusLabel.setVisible(true);
|
||||
routerWrapper.start();
|
||||
listenForTunnelChanges();
|
||||
tunnelAddButton.setDisable(false);
|
||||
}
|
||||
else {
|
||||
shuttingDown = true;
|
||||
masterToggle.setImage(new Image("org/getmonero/i2p/zero/gui/toggle-off.png"));
|
||||
statusLabel.setVisible(false);
|
||||
routerWrapper.stop(false);
|
||||
tunnelTableList.clear();
|
||||
tunnelAddButton.setDisable(true);
|
||||
statusLabel.setText("Shutting down...");
|
||||
routerWrapper.stop(true);
|
||||
}
|
||||
});
|
||||
|
||||
startRouter();
|
||||
|
||||
new Thread(()->{
|
||||
while(getRouterWrapper()==null || getRouterWrapper().getTunnelControl()==null) {
|
||||
try { Thread.sleep(100); } catch (InterruptedException e) {}
|
||||
}
|
||||
var tunnelList = getRouterWrapper().getTunnelControl().getTunnelList();
|
||||
tunnelList.addChangeListener(tunnels->{
|
||||
tunnelTableList.clear();
|
||||
tunnels.stream().filter(Tunnel::getEnabled).forEach(tunnelTableList::add);
|
||||
});
|
||||
}).start();
|
||||
|
||||
listenForTunnelChanges();
|
||||
|
||||
var bandwidthUpdateThread = new Thread(()->{
|
||||
while(!Gui.instance.isStopping()) {
|
||||
@@ -293,6 +286,20 @@ public class Controller {
|
||||
|
||||
}
|
||||
|
||||
private void listenForTunnelChanges() {
|
||||
new Thread(()->{
|
||||
while(getRouterWrapper()==null || getRouterWrapper().getTunnelControl()==null) {
|
||||
try { Thread.sleep(100); } catch (InterruptedException e) {}
|
||||
}
|
||||
var tunnelList = getRouterWrapper().getTunnelControl().getTunnelList();
|
||||
tunnelList.addChangeListener(tunnels->{
|
||||
tunnelTableList.clear();
|
||||
tunnels.stream().filter(Tunnel::getEnabled).forEach(tunnelTableList::add);
|
||||
});
|
||||
getRouterWrapper().getTunnelControl().getTunnelList().fireChangeEvent();
|
||||
}).start();
|
||||
}
|
||||
|
||||
public RouterWrapper getRouterWrapper() {
|
||||
return routerWrapper;
|
||||
}
|
||||
|
||||
@@ -98,14 +98,15 @@ public class RouterWrapper {
|
||||
|
||||
}
|
||||
|
||||
public void stop(boolean fastStop) {
|
||||
public void stop(boolean fastStopAndShutDown) {
|
||||
if(!started) return;
|
||||
started = false;
|
||||
tunnelControl.stop(fastStop);
|
||||
tunnelControl.stop(fastStopAndShutDown);
|
||||
tunnelControl = null;
|
||||
System.out.println("I2P router will shut down gracefully");
|
||||
router.shutdownGracefully();
|
||||
|
||||
if(fastStop) {
|
||||
if(fastStopAndShutDown) {
|
||||
// don't wait more than 2 seconds for shutdown. If tunnels are still opening, they can pause for up to 20 seconds, which is too long
|
||||
new Thread(() -> {
|
||||
try { Thread.sleep(2000); } catch (InterruptedException e) {}
|
||||
|
||||
Reference in New Issue
Block a user