i2ptunnel: Don't register port mapper in clients overriding startRunning()

if super.startRunning() failed
Register as HTTPS proxy also in HTTP client
This commit is contained in:
zzz
2015-04-24 21:16:45 +00:00
parent 08e96109a7
commit e475c161cb
4 changed files with 21 additions and 7 deletions

View File

@@ -53,7 +53,7 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna
protected boolean _ownDest; protected boolean _ownDest;
protected Destination dest; protected Destination dest;
private int localPort; private volatile int localPort;
private final String _handlerName; 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 * 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. * 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() { public void startRunning() {
boolean openNow = !Boolean.parseBoolean(getTunnel().getClientOptions().getProperty("i2cp.delayOpen")); boolean openNow = !Boolean.parseBoolean(getTunnel().getClientOptions().getProperty("i2cp.delayOpen"));

View File

@@ -120,7 +120,8 @@ public class I2PTunnelConnectClient extends I2PTunnelHTTPClientBase implements R
@Override @Override
public void startRunning() { public void startRunning() {
super.startRunning(); super.startRunning();
_context.portMapper().register(PortMapper.SVC_HTTPS_PROXY, getLocalPort()); if (open)
_context.portMapper().register(PortMapper.SVC_HTTPS_PROXY, getLocalPort());
} }
@Override @Override

View File

@@ -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.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 }); _context.statManager().createRateStat("i2ptunnel.httpExpanded", "size transferred after expansion", "I2PTunnel", new long[] { 60*60*1000 });
super.startRunning(); super.startRunning();
this.isr = new InternalSocketRunner(this); if (open) {
this.isr.start(); this.isr = new InternalSocketRunner(this);
_context.portMapper().register(PortMapper.SVC_HTTP_PROXY, getLocalPort()); 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 @Override
public boolean close(boolean forced) { public boolean close(boolean forced) {
int port = getLocalPort();
int reg = _context.portMapper().getPort(PortMapper.SVC_HTTP_PROXY); int reg = _context.portMapper().getPort(PortMapper.SVC_HTTP_PROXY);
if(reg == getLocalPort()) { if (reg == port) {
_context.portMapper().unregister(PortMapper.SVC_HTTP_PROXY); _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); boolean rv = super.close(forced);
if(this.isr != null) { if(this.isr != null) {
this.isr.stopRunning(); this.isr.stopRunning();

View File

@@ -198,7 +198,8 @@ public class I2PTunnelIRCClient extends I2PTunnelClientBase {
@Override @Override
public void startRunning() { public void startRunning() {
super.startRunning(); super.startRunning();
_context.portMapper().register(PortMapper.SVC_IRC, getLocalPort()); if (open)
_context.portMapper().register(PortMapper.SVC_IRC, getLocalPort());
} }
@Override @Override