Changeset c1d77dfe


Ignore:
Timestamp:
Nov 5, 2015 9:18:01 PM (5 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
d5e2def
Parents:
eca234c
Message:

I2CP: Fix additional connections getting rejected during tunnel open (ticket #1650)
State change cleanups
State checking consolidation

Location:
core/java/src/net/i2p/client/impl
Files:
6 edited

Legend:

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

    reca234c rc1d77dfe  
    103103        msg.setSessionConfig(cfg);
    104104        if (_log.shouldLog(Log.DEBUG)) _log.debug("config loaded into message");
    105         session.sendMessage(msg);
     105        session.sendMessage_unchecked(msg);
    106106        if (_log.shouldLog(Log.DEBUG)) _log.debug("config message sent");
    107107    }
     
    115115        DestroySessionMessage dmsg = new DestroySessionMessage();
    116116        dmsg.setSessionId(session.getSessionId());
    117         session.sendMessage(dmsg);
     117        session.sendMessage_unchecked(dmsg);
    118118        // use DisconnectMessage only if we fail and drop connection...
    119119        // todo: update the code to fire off DisconnectMessage on socket error
     
    372372        }
    373373        msg.setSessionId(sid);
    374         session.sendMessage(msg);
     374        session.sendMessage_unchecked(msg);
    375375    }
    376376
  • core/java/src/net/i2p/client/impl/I2PSessionImpl.java

    reca234c rc1d77dfe  
    210210        synchronized (_stateLock) {
    211211            if (_state == State.OPENING) {
    212                 _state = State.GOTDATE;
    213                 _stateLock.notifyAll();
     212                changeState(State.GOTDATE);
    214213            }
    215214        }
     
    636635                auth.setProperty(PROP_PW, _options.getProperty(PROP_PW));
    637636            }
    638             sendMessage(new GetDateMessage(CoreVersion.VERSION, auth));
     637            sendMessage_unchecked(new GetDateMessage(CoreVersion.VERSION, auth));
    639638            waitForDate();
    640639
     
    738737     */
    739738    public void reportAbuse(int msgId, int severity) throws I2PSessionException {
    740         synchronized (_stateLock) {
    741             if (_state == State.CLOSED)
    742                 throw new I2PSessionException("Already closed");
    743             if (_state == State.INIT)
    744                 throw new I2PSessionException("Not open, must call connect() first");
    745             if (_state == State.OPENING) // not before GOTDATE
    746                 throw new I2PSessionException("Session not open yet");
    747         }
     739        verifyOpen();
    748740        _producer.reportAbuse(this, msgId, severity);
    749741    }
     
    10361028
    10371029    /**
     1030     *  Throws I2PSessionException if uninitialized, closed or closing.
     1031     *  Blocks if opening.
     1032     *
     1033     *  @since 0.9.23
     1034     */
     1035    protected void verifyOpen() throws I2PSessionException {
     1036        synchronized (_stateLock) {
     1037            while (true) {
     1038                switch (_state) {
     1039                    case INIT:
     1040                        throw new I2PSessionException("Not open, must call connect() first");
     1041
     1042                    case OPENING:  // fall thru
     1043                    case GOTDATE:
     1044                        try {
     1045                            _stateLock.wait(5*1000);
     1046                            continue;
     1047                        } catch (InterruptedException ie) {
     1048                            throw new I2PSessionException("Interrupted", ie);
     1049                        }
     1050
     1051                    case OPEN:
     1052                        return;
     1053
     1054                    case CLOSING:  // fall thru
     1055                    case CLOSED:
     1056                        throw new I2PSessionException("Already closed");
     1057                }
     1058            }
     1059        }
     1060    }
     1061
     1062    /**
    10381063     * Deliver an I2CP message to the router
    10391064     * As of 0.9.3, may block for several seconds if the write queue to the router is full
     
    10421067     */
    10431068    void sendMessage(I2CPMessage message) throws I2PSessionException {
    1044         synchronized (_stateLock) {
    1045             if (_state == State.CLOSED)
    1046                 throw new I2PSessionException("Already closed");
    1047             if (_state == State.INIT)
    1048                 throw new I2PSessionException("Not open, must call connect() first");
    1049         }
     1069        verifyOpen();
     1070        sendMessage_unchecked(message);
     1071    }
     1072
     1073    /**
     1074     * Deliver an I2CP message to the router.
     1075     * Does NOT check state. Call only from connect() or other methods that need to
     1076     * send messages when not in OPEN state.
     1077     *
     1078     * @throws I2PSessionException if the message is malformed or there is an error writing it out
     1079     * @since 0.9.23
     1080     */
     1081    void sendMessage_unchecked(I2CPMessage message) throws I2PSessionException {
    10501082        if (_queue != null) {
    10511083            // internal
     
    10561088                throw new I2PSessionException("Interrupted", ie);
    10571089            }
    1058         } else if (_writer == null) {
    1059             // race here
    1060             throw new I2PSessionException("Already closed or not open");
    10611090        } else {
    1062             _writer.addMessage(message);
     1091            ClientWriterRunner writer = _writer;
     1092            if (writer == null) {
     1093                throw new I2PSessionException("Already closed or not open");
     1094            } else {
     1095                writer.addMessage(message);
     1096            }
    10631097        }
    10641098    }
     
    14421476                if (id == null)
    14431477                    id = new SessionId(65535);
    1444                 sendMessage(new HostLookupMessage(id, h, nonce, maxWait));
     1478                sendMessage_unchecked(new HostLookupMessage(id, h, nonce, maxWait));
    14451479            } else {
    14461480                if (_log.shouldLog(Log.INFO))
    14471481                    _log.info("Sending DestLookup for " + h);
    1448                 sendMessage(new DestLookupMessage(h));
     1482                sendMessage_unchecked(new DestLookupMessage(h));
    14491483            }
    14501484            try {
     
    15341568            if (id == null)
    15351569                id = new SessionId(65535);
    1536             sendMessage(new HostLookupMessage(id, name, nonce, maxWait));
     1570            sendMessage_unchecked(new HostLookupMessage(id, name, nonce, maxWait));
    15371571            try {
    15381572                synchronized (waiter) {
     
    15681602            }
    15691603        }
    1570         sendMessage(new GetBandwidthLimitsMessage());
     1604        sendMessage_unchecked(new GetBandwidthLimitsMessage());
    15711605        try {
    15721606            synchronized (_bwReceivedLock) {
  • core/java/src/net/i2p/client/impl/I2PSessionImpl2.java

    reca234c rc1d77dfe  
    277277                   throws I2PSessionException {
    278278        if (_log.shouldLog(Log.DEBUG)) _log.debug("sending message");
    279         synchronized (_stateLock) {
    280             if (_state == State.CLOSED)
    281                 throw new I2PSessionException("Already closed");
    282             if (_state == State.INIT)
    283                 throw new I2PSessionException("Not open, must call connect() first");
    284             if (_state == State.OPENING || _state == State.GOTDATE) // not before GOTDATE or session
    285                 throw new I2PSessionException("Session not open yet");
    286         }
     279        verifyOpen();
    287280        updateActivity();
    288281
  • core/java/src/net/i2p/client/impl/I2PSessionMuxedImpl.java

    reca234c rc1d77dfe  
    281281     */
    282282    private byte[] prepPayload(byte[] payload, int offset, int size, int proto, int fromPort, int toPort) throws I2PSessionException {
    283         synchronized (_stateLock) {
    284             if (_state == State.CLOSED)
    285                 throw new I2PSessionException("Already closed");
    286             if (_state == State.INIT)
    287                 throw new I2PSessionException("Not open, must call connect() first");
    288             if (_state == State.OPENING || _state == State.GOTDATE) // not before GOTDATE or session
    289                 throw new I2PSessionException("Session not open yet");
    290         }
     283        verifyOpen();
    291284        updateActivity();
    292285
  • core/java/src/net/i2p/client/impl/I2PSimpleSession.java

    reca234c rc1d77dfe  
    123123                    auth.setProperty(PROP_USER, opts.getProperty(PROP_USER));
    124124                    auth.setProperty(PROP_PW, opts.getProperty(PROP_PW));
    125                     sendMessage(new GetDateMessage(CoreVersion.VERSION, auth));
     125                    sendMessage_unchecked(new GetDateMessage(CoreVersion.VERSION, auth));
    126126                } else {
    127127                    // we must now send a GetDate even in SimpleSession, or we won't know
    128128                    // what version we are talking with and cannot use HostLookup
    129                     sendMessage(new GetDateMessage(CoreVersion.VERSION));
     129                    sendMessage_unchecked(new GetDateMessage(CoreVersion.VERSION));
    130130                }
    131131                waitForDate();
  • core/java/src/net/i2p/client/impl/SubSession.java

    reca234c rc1d77dfe  
    101101        synchronized(_stateLock) {
    102102            if (_state != State.OPEN) {
    103                 _state = State.OPENING;
     103                changeState(State.OPENING);
    104104            }
    105105        }
     
    122122                    Thread notifier = new I2PAppThread(_availabilityNotifier, "ClientNotifier " + getPrefix(), true);
    123123                    notifier.start();
    124                     _state = State.OPEN;
     124                    changeState(State.OPEN);
    125125                }
    126126            }
     
    162162            message.getType() != CreateLeaseSetMessage.MESSAGE_TYPE)
    163163            throw new I2PSessionException("Already closed");
    164         _primary.sendMessage(message);
     164        _primary.sendMessage_unchecked(message);
     165    }
     166
     167    /**
     168     * Deliver an I2CP message to the router.
     169     * Does NOT check state. Call only from connect() or other methods that need to
     170     * send messages when not in OPEN state.
     171     *
     172     * @throws I2PSessionException if the message is malformed or there is an error writing it out
     173     * @since 0.9.23
     174     */
     175    @Override
     176    void sendMessage_unchecked(I2CPMessage message) throws I2PSessionException {
     177        _primary.sendMessage_unchecked(message);
    165178    }
    166179
Note: See TracChangeset for help on using the changeset viewer.