Changeset 036b777


Ignore:
Timestamp:
Jun 17, 2015 2:16:06 AM (5 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
8096e4f6
Parents:
bc85543
Message:

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

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/client/I2PSessionImpl.java

    rbc85543 r036b777  
    8282    private SessionId _sessionId;
    8383    /** currently granted lease set, or null */
    84     private volatile LeaseSet _leaseSet;
     84    protected volatile LeaseSet _leaseSet;
    8585
    8686    // subsession stuff
     
    131131
    132132    /** monitor for waiting until a lease set has been granted */
    133     private final Object _leaseSetWait = new Object();
     133    protected final Object _leaseSetWait = new Object();
    134134
    135135    /**
  • core/java/src/net/i2p/client/SubSession.java

    rbc85543 r036b777  
    102102            }
    103103        }
    104         _primary.connect();
    105         synchronized(_stateLock) {
    106             if (_state != State.OPEN) {
    107                 Thread notifier = new I2PAppThread(_availabilityNotifier, "ClientNotifier " + getPrefix(), true);
    108                 notifier.start();
    109                 _state = State.OPEN;
     104        boolean success = false;
     105        try {
     106            _primary.connect();
     107            // wait until we have created a lease set
     108            int waitcount = 0;
     109            while (_leaseSet == null) {
     110                if (waitcount++ > 5*60) {
     111                    throw new IOException("No tunnels built after waiting 5 minutes. Your network connection may be down, or there is severe network congestion.");
     112                }
     113                synchronized (_leaseSetWait) {
     114                    // InterruptedException caught below
     115                    _leaseSetWait.wait(1000);
     116                }
     117            }
     118            synchronized(_stateLock) {
     119                if (_state != State.OPEN) {
     120                    Thread notifier = new I2PAppThread(_availabilityNotifier, "ClientNotifier " + getPrefix(), true);
     121                    notifier.start();
     122                    _state = State.OPEN;
     123                }
     124            }
     125            success = true;
     126        } catch (InterruptedException ie) {
     127            throw new I2PSessionException("Interrupted", ie);
     128        } catch (IOException ioe) {
     129            throw new I2PSessionException(getPrefix() + "Cannot connect to the router on " + _hostname + ':' + _portNum, ioe);
     130        } finally {
     131            if (!success) {
     132                _availabilityNotifier.stopNotifying();
     133                changeState(State.CLOSED);
    110134            }
    111135        }
  • core/java/src/net/i2p/data/i2cp/I2CPMessageReader.java

    rbc85543 r036b777  
    159159
    160160        public void run() {
     161            try {
     162                run2();
     163            } catch (Exception e) {
     164                _log.log(Log.CRIT, "Uncaught I2CP error", e);
     165                _listener.readError(I2CPMessageReader.this, e);
     166                cancelRunner();
     167            }
     168        }
     169
     170        /**
     171         * Called by run()
     172         * @since 0.9.21
     173         */
     174        protected void run2() {
    161175            while (_stayAlive) {
    162176                while (_doRun) {
  • core/java/src/net/i2p/internal/QueuedI2CPMessageReader.java

    rbc85543 r036b777  
    4343         */
    4444        @Override
    45         public void run() {
     45        protected void run2() {
    4646            while (_stayAlive) {
    4747                while (_doRun) {
  • router/java/src/net/i2p/router/client/ClientConnectionRunner.java

    rbc85543 r036b777  
    229229     *  will be null if session not found
    230230     *  IS subsession aware.
     231     *  Returns null if id is null.
    231232     *  @since 0.9.21 added id param
    232233     */
    233234    public SessionConfig getConfig(SessionId id) {
     235        if (id == null)
     236            return null;
    234237        for (SessionParams sp : _sessions.values()) {
    235238            if (id.equals(sp.sessionId))
     
    318321     */
    319322    public Hash getDestHash(SessionId id) {
     323        if (id == null)
     324            return null;
    320325        for (Map.Entry<Hash, SessionParams> e : _sessions.entrySet()) {
    321326            if (id.equals(e.getValue().sessionId))
     
    331336     */
    332337    public Destination getDestination(SessionId id) {
     338        if (id == null)
     339            return null;
    333340        for (SessionParams sp : _sessions.values()) {
    334341            if (id.equals(sp.sessionId))
     
    392399        if (hash == null)
    393400            throw new IllegalStateException();
     401        if (id == null)
     402            throw new NullPointerException();
    394403        SessionParams sp = _sessions.get(hash);
    395404        if (sp == null || sp.sessionId != null)
     
    404413     */
    405414    void removeSession(SessionId id) {
     415        if (id == null)
     416            return;
    406417        boolean isPrimary = false;
    407418        for (Iterator<SessionParams> iter = _sessions.values().iterator(); iter.hasNext(); ) {
     
    814825            state = sp.leaseRequest;
    815826            if (state != null) {
    816                 if (_log.shouldLog(Log.DEBUG))
    817                     _log.debug("Already requesting " + state);
    818827                LeaseSet requested = state.getRequested();
    819828                LeaseSet granted = state.getGranted();
     
    822831                     ( (granted != null) && (granted.getEarliestLeaseDate() > ours) ) ) {
    823832                    // theirs is newer
     833                    if (_log.shouldLog(Log.DEBUG))
     834                        _log.debug("Already requesting, theirs newer, do nothing: " + state);
    824835                } else {
    825836                    // ours is newer, so wait a few secs and retry
    826837                    set.setDestination(dest);
    827838                    _context.simpleTimer2().addEvent(new Rerequest(set, expirationTime, onCreateJob, onFailedJob), 3*1000);
     839                    if (_log.shouldLog(Log.DEBUG))
     840                        _log.debug("Already requesting, ours newer, wait 3 sec: " + state);
    828841                }
    829842                // fire onCreated?
  • router/java/src/net/i2p/router/client/ClientMessageEventListener.java

    rbc85543 r036b777  
    8181     */
    8282    public void messageReceived(I2CPMessageReader reader, I2CPMessage message) {
    83         if (_runner.isDead()) return;
     83        if (_runner.isDead()) {
     84            if (_log.shouldLog(Log.WARN))
     85                _log.warn("Received but runner dead: \n" + message);
     86            return;
     87        }
    8488        if (_log.shouldLog(Log.DEBUG))
    8589            _log.debug("Message received: \n" + message);
     
    363367        if (cfg == null) {
    364368            if (_log.shouldLog(Log.ERROR))
    365                 _log.error("SendMessage w/o session");
    366             _runner.disconnectClient("SendMessage w/o session");
     369                _log.error("SendMessage w/o session: " + sid);
     370            _runner.disconnectClient("SendMessage w/o session: " + sid);
    367371            return;
    368372        }
     
    373377        long timeToDistribute = _context.clock().now() - beforeDistribute;
    374378        // TODO validate session id
    375         _runner.ackSendMessage(message.getSessionId(), id, message.getNonce());
     379        _runner.ackSendMessage(sid, id, message.getNonce());
    376380        _context.statManager().addRateData("client.distributeTime", timeToDistribute);
    377         if ( (timeToDistribute > 50) && (_log.shouldLog(Log.INFO)) )
    378             _log.info("Took too long to distribute the message (which holds up the ack): " + timeToDistribute);
     381        if ( (timeToDistribute > 50) && (_log.shouldLog(Log.DEBUG)) )
     382            _log.debug("Took too long to distribute the message (which holds up the ack): " + timeToDistribute);
    379383    }
    380384
     
    387391        if (_runner.isDead()) return;
    388392        if (_log.shouldLog(Log.DEBUG))
    389             _log.debug("Handling recieve begin: id = " + message.getMessageId());
     393            _log.debug("Handling receive begin: id = " + message.getMessageId());
    390394        MessagePayloadMessage msg = new MessagePayloadMessage();
    391395        msg.setMessageId(message.getMessageId());
     
    410414   
    411415    /**
    412      * The client told us that the message has been recieved completely.  This currently
     416     * The client told us that the message has been received completely.  This currently
    413417     * does not do any security checking prior to removing the message from the
    414418     * pending queue, though it should.
     
    444448        if (cfg == null) {
    445449            if (_log.shouldLog(Log.ERROR))
    446                 _log.error("CreateLeaseSet w/o session");
    447             _runner.disconnectClient("CreateLeaseSet w/o session");
     450                _log.error("CreateLeaseSet w/o session: " + id);
     451            _runner.disconnectClient("CreateLeaseSet w/o session: " + id);
    448452            return;
    449453        }
     
    534538        if (cfg == null) {
    535539            if (_log.shouldLog(Log.ERROR))
    536                 _log.error("ReconfigureSession w/o session");
     540                _log.error("ReconfigureSession w/o session: " + id);
    537541            //sendStatusMessage(id, SessionStatusMessage.STATUS_INVALID);
    538             _runner.disconnectClient("ReconfigureSession w/o session");
     542            _runner.disconnectClient("ReconfigureSession w/o session: " + id);
    539543            return;
    540544        }
Note: See TracChangeset for help on using the changeset viewer.