I2CP: Take 2 of fix, so a newly created session

isn't destroyed and immediately replaced by i2ptunnel,
which caused dup shared clients in a race at startup;
Clarify session exception text if not open
This commit is contained in:
zzz
2015-05-24 00:14:32 +00:00
parent 3d07e1a10b
commit 4ea99b8a10
6 changed files with 37 additions and 11 deletions

View File

@ -257,7 +257,7 @@ public interface I2PSession {
/**
* Have we closed the session?
*
* @return true if the session is closed
* @return true if the session is closed, OR connect() has not been called yet
*/
public boolean isClosed();

View File

@ -135,7 +135,7 @@ public abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2
CLOSED
}
private State _state = State.INIT;
protected State _state = State.INIT;
protected final Object _stateLock = new Object();
/**
@ -614,7 +614,12 @@ public abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2
* Report abuse with regards to the given messageId
*/
public void reportAbuse(int msgId, int severity) throws I2PSessionException {
if (isClosed()) throw new I2PSessionException(getPrefix() + "Already closed");
synchronized (_stateLock) {
if (_state == State.CLOSED)
throw new I2PSessionException("Already closed");
if (_state == State.INIT)
throw new I2PSessionException("Not open, must call connect() first");
}
_producer.reportAbuse(this, msgId, severity);
}

View File

@ -247,7 +247,12 @@ class I2PSessionImpl2 extends I2PSessionImpl {
public boolean sendMessage(Destination dest, byte[] payload, int offset, int size, SessionKey keyUsed, Set tagsSent, long expires)
throws I2PSessionException {
if (_log.shouldLog(Log.DEBUG)) _log.debug("sending message");
if (isClosed()) throw new I2PSessionException("Already closed");
synchronized (_stateLock) {
if (_state == State.CLOSED)
throw new I2PSessionException("Already closed");
if (_state == State.INIT)
throw new I2PSessionException("Not open, must call connect() first");
}
updateActivity();
// Sadly there is no way to send something completely uncompressed in a backward-compatible way,

View File

@ -256,7 +256,12 @@ class I2PSessionMuxedImpl extends I2PSessionImpl2 {
* @since 0.9.14
*/
private byte[] prepPayload(byte[] payload, int offset, int size, int proto, int fromPort, int toPort) throws I2PSessionException {
if (isClosed()) throw new I2PSessionException("Already closed");
synchronized (_stateLock) {
if (_state == State.CLOSED)
throw new I2PSessionException("Already closed");
if (_state == State.INIT)
throw new I2PSessionException("Not open, must call connect() first");
}
updateActivity();
if (shouldCompress(size))