* I2PTunnel:

- Try to fix locking to prevent duplicate destinations when using
    the new option new-dest-on-resume. Still not right for shared clients
    but should be better for non-shared.
This commit is contained in:
zzz
2009-05-01 12:43:19 +00:00
parent 4c396e5b95
commit a8a0e2a91c
4 changed files with 18 additions and 8 deletions

View File

@ -345,8 +345,10 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna
public I2PSocket createI2PSocket(Destination dest) throws I2PException, ConnectException, NoRouteToHostException, InterruptedIOException { public I2PSocket createI2PSocket(Destination dest) throws I2PException, ConnectException, NoRouteToHostException, InterruptedIOException {
if (sockMgr == null) { if (sockMgr == null) {
// we need this before getDefaultOptions() // we need this before getDefaultOptions()
synchronized(sockLock) {
sockMgr = getSocketManager(); sockMgr = getSocketManager();
} }
}
return createI2PSocket(dest, getDefaultOptions()); return createI2PSocket(dest, getDefaultOptions());
} }
@ -369,9 +371,12 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna
if (sockMgr == null) { if (sockMgr == null) {
// delayed open - call get instead of build because the locking is up there // delayed open - call get instead of build because the locking is up there
synchronized(sockLock) {
sockMgr = getSocketManager(); sockMgr = getSocketManager();
} else if (Boolean.valueOf(getTunnel().getClientOptions().getProperty("i2cp.newDestOnResume")).booleanValue()) { }
synchronized(sockMgr) { } else if (Boolean.valueOf(getTunnel().getClientOptions().getProperty("i2cp.closeOnIdle")).booleanValue() &&
Boolean.valueOf(getTunnel().getClientOptions().getProperty("i2cp.newDestOnResume")).booleanValue()) {
synchronized(sockLock) {
I2PSocketManager oldSockMgr = sockMgr; I2PSocketManager oldSockMgr = sockMgr;
// This will build a new socket manager and a new dest if the session is closed. // This will build a new socket manager and a new dest if the session is closed.
sockMgr = getSocketManager(); sockMgr = getSocketManager();

View File

@ -211,8 +211,11 @@ public class I2PTunnelHTTPClient extends I2PTunnelClientBase implements Runnable
if (!defaultOpts.contains("i2p.streaming.inactivityTimeout")) if (!defaultOpts.contains("i2p.streaming.inactivityTimeout"))
defaultOpts.setProperty("i2p.streaming.inactivityTimeout", ""+DEFAULT_READ_TIMEOUT); defaultOpts.setProperty("i2p.streaming.inactivityTimeout", ""+DEFAULT_READ_TIMEOUT);
// delayed start // delayed start
if (sockMgr == null) if (sockMgr == null) {
synchronized(sockLock) {
sockMgr = getSocketManager(); sockMgr = getSocketManager();
}
}
I2PSocketOptions opts = sockMgr.buildOptions(defaultOpts); I2PSocketOptions opts = sockMgr.buildOptions(defaultOpts);
if (!defaultOpts.containsKey(I2PSocketOptions.PROP_CONNECT_TIMEOUT)) if (!defaultOpts.containsKey(I2PSocketOptions.PROP_CONNECT_TIMEOUT))
opts.setConnectTimeout(DEFAULT_CONNECT_TIMEOUT); opts.setConnectTimeout(DEFAULT_CONNECT_TIMEOUT);

View File

@ -153,7 +153,9 @@ public class EditBean extends IndexBean {
} }
public boolean getNewDest(int tunnel) { public boolean getNewDest(int tunnel) {
return getBooleanProperty(tunnel, "i2cp.newDestOnResume"); return getBooleanProperty(tunnel, "i2cp.newDestOnResume") &&
getBooleanProperty(tunnel, "i2cp.closeOnIdle") &&
!getBooleanProperty(tunnel, "persistentClientKey");
} }
public boolean getPersistentClientKey(int tunnel) { public boolean getPersistentClientKey(int tunnel) {