diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java index 3f10ff7bd02bc246b04672aec8fc11ca0ecfd99e..335833276a9637092a785cb7f598caff20a938a4 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java @@ -53,7 +53,7 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna protected boolean _ownDest; protected Destination dest; - private int localPort; + private volatile int localPort; private final String _handlerName; /** @@ -477,6 +477,9 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna * This will be fast if i2cp.delayOpen is true, but could take * a LONG TIME if it is false, as it connects to the router and builds tunnels. * + * Extending classes must check the value of boolean open after calling + * super.startRunning(), if false then something went wrong. + * */ public void startRunning() { boolean openNow = !Boolean.parseBoolean(getTunnel().getClientOptions().getProperty("i2cp.delayOpen")); diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelConnectClient.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelConnectClient.java index 8763218662b4327eff0c4d14abdb5ab789b568e7..29fca69692afe4793cb269fc6906c3e36a03967b 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelConnectClient.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelConnectClient.java @@ -120,7 +120,8 @@ public class I2PTunnelConnectClient extends I2PTunnelHTTPClientBase implements R @Override public void startRunning() { super.startRunning(); - _context.portMapper().register(PortMapper.SVC_HTTPS_PROXY, getLocalPort()); + if (open) + _context.portMapper().register(PortMapper.SVC_HTTPS_PROXY, getLocalPort()); } @Override diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java index 372648b4ee45f6003e233e71465fe2a80817ed9a..8c865ea85684ff770320ecb6952ed97ebad45201 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java @@ -293,9 +293,13 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn _context.statManager().createRateStat("i2ptunnel.httpCompressed", "compressed size transferred", "I2PTunnel", new long[] { 60*60*1000 }); _context.statManager().createRateStat("i2ptunnel.httpExpanded", "size transferred after expansion", "I2PTunnel", new long[] { 60*60*1000 }); super.startRunning(); - this.isr = new InternalSocketRunner(this); - this.isr.start(); - _context.portMapper().register(PortMapper.SVC_HTTP_PROXY, getLocalPort()); + if (open) { + this.isr = new InternalSocketRunner(this); + this.isr.start(); + int port = getLocalPort(); + _context.portMapper().register(PortMapper.SVC_HTTP_PROXY, port); + _context.portMapper().register(PortMapper.SVC_HTTPS_PROXY, port); + } } /** @@ -303,10 +307,15 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn */ @Override public boolean close(boolean forced) { + int port = getLocalPort(); int reg = _context.portMapper().getPort(PortMapper.SVC_HTTP_PROXY); - if(reg == getLocalPort()) { + if (reg == port) { _context.portMapper().unregister(PortMapper.SVC_HTTP_PROXY); } + reg = _context.portMapper().getPort(PortMapper.SVC_HTTPS_PROXY); + if (reg == port) { + _context.portMapper().unregister(PortMapper.SVC_HTTPS_PROXY); + } boolean rv = super.close(forced); if(this.isr != null) { this.isr.stopRunning(); diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelIRCClient.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelIRCClient.java index e8fac6812b3aded6253952d2fadc22d6eee48221..7f4c2c22ac45bbf279a814ac9bdffbbc6f51eec2 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelIRCClient.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelIRCClient.java @@ -198,7 +198,8 @@ public class I2PTunnelIRCClient extends I2PTunnelClientBase { @Override public void startRunning() { super.startRunning(); - _context.portMapper().register(PortMapper.SVC_IRC, getLocalPort()); + if (open) + _context.portMapper().register(PortMapper.SVC_IRC, getLocalPort()); } @Override