forked from I2P_Developers/i2p.i2p
Catch uncaught exceptions in ClientConnectionRunner and stop connection
Catch null SessionId in messages and stop connection instead of NPE Wait for LS in SubSession in connect() so we don't send data w/o a session ID and leaseset Log tweaks
This commit is contained in:
@ -81,7 +81,7 @@ public abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2
|
||||
/** this session's Id */
|
||||
private SessionId _sessionId;
|
||||
/** currently granted lease set, or null */
|
||||
private volatile LeaseSet _leaseSet;
|
||||
protected volatile LeaseSet _leaseSet;
|
||||
|
||||
// subsession stuff
|
||||
// registered subsessions
|
||||
@ -130,7 +130,7 @@ public abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2
|
||||
protected final I2PAppContext _context;
|
||||
|
||||
/** monitor for waiting until a lease set has been granted */
|
||||
private final Object _leaseSetWait = new Object();
|
||||
protected final Object _leaseSetWait = new Object();
|
||||
|
||||
/**
|
||||
* @since 0.9.8
|
||||
|
@ -101,12 +101,36 @@ class SubSession extends I2PSessionMuxedImpl {
|
||||
_state = State.OPENING;
|
||||
}
|
||||
}
|
||||
_primary.connect();
|
||||
synchronized(_stateLock) {
|
||||
if (_state != State.OPEN) {
|
||||
Thread notifier = new I2PAppThread(_availabilityNotifier, "ClientNotifier " + getPrefix(), true);
|
||||
notifier.start();
|
||||
_state = State.OPEN;
|
||||
boolean success = false;
|
||||
try {
|
||||
_primary.connect();
|
||||
// wait until we have created a lease set
|
||||
int waitcount = 0;
|
||||
while (_leaseSet == null) {
|
||||
if (waitcount++ > 5*60) {
|
||||
throw new IOException("No tunnels built after waiting 5 minutes. Your network connection may be down, or there is severe network congestion.");
|
||||
}
|
||||
synchronized (_leaseSetWait) {
|
||||
// InterruptedException caught below
|
||||
_leaseSetWait.wait(1000);
|
||||
}
|
||||
}
|
||||
synchronized(_stateLock) {
|
||||
if (_state != State.OPEN) {
|
||||
Thread notifier = new I2PAppThread(_availabilityNotifier, "ClientNotifier " + getPrefix(), true);
|
||||
notifier.start();
|
||||
_state = State.OPEN;
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
} catch (InterruptedException ie) {
|
||||
throw new I2PSessionException("Interrupted", ie);
|
||||
} catch (IOException ioe) {
|
||||
throw new I2PSessionException(getPrefix() + "Cannot connect to the router on " + _hostname + ':' + _portNum, ioe);
|
||||
} finally {
|
||||
if (!success) {
|
||||
_availabilityNotifier.stopNotifying();
|
||||
changeState(State.CLOSED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -158,6 +158,20 @@ public class I2CPMessageReader {
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
run2();
|
||||
} catch (Exception e) {
|
||||
_log.log(Log.CRIT, "Uncaught I2CP error", e);
|
||||
_listener.readError(I2CPMessageReader.this, e);
|
||||
cancelRunner();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by run()
|
||||
* @since 0.9.21
|
||||
*/
|
||||
protected void run2() {
|
||||
while (_stayAlive) {
|
||||
while (_doRun) {
|
||||
// do read
|
||||
|
@ -42,7 +42,7 @@ public class QueuedI2CPMessageReader extends I2CPMessageReader {
|
||||
* Pumps messages from the incoming message queue to the listener.
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
protected void run2() {
|
||||
while (_stayAlive) {
|
||||
while (_doRun) {
|
||||
// do read
|
||||
|
Reference in New Issue
Block a user