Changeset 826d8ca


Ignore:
Timestamp:
Feb 18, 2018 1:53:50 PM (4 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
a5ca936
Parents:
acebd2e
Message:

i2ptunnel: Retry accept after router soft restart (ticket #2003)
This sends the router restart indication from I2CP router side
to client side to streaming to I2PTunnelServer via
a new streaming exception.

Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java

    racebd2e r826d8ca  
    3838import net.i2p.client.streaming.I2PSocketManager;
    3939import net.i2p.client.streaming.I2PSocketManagerFactory;
     40import net.i2p.client.streaming.RouterRestartException;
    4041import net.i2p.crypto.SigType;
    4142import net.i2p.data.Base64;
     
    555556                if (ci2pss == null)
    556557                    throw new I2PException("I2PServerSocket closed");
     558                // returns non-null as of 0.9.17
    557559                i2ps = ci2pss.accept();
    558                 if (i2ps == null) throw new I2PException("I2PServerSocket closed");
    559560                if (_usePool) {
    560561                    try {
     
    574575                    blockingHandle(i2ps);
    575576                }
     577            } catch (RouterRestartException rre) {
     578                // Delay and loop if router is soft restarting
     579                _log.logAlways(Log.WARN, "Waiting for router restart");
     580                if (i2ps != null) try { i2ps.close(); } catch (IOException ioe) {}
     581                try {
     582                    Thread.sleep(2*60*1000);
     583                } catch (InterruptedException ie) {}
     584                // This should be the same as before, but we have to call getServerSocket()
     585                // so sockMgr will call ConnectionManager.setAllowIncomingConnections(true) again
     586                i2pss = sockMgr.getServerSocket();
    576587            } catch (I2PException ipe) {
    577588                if (_log.shouldLog(Log.ERROR))
    578589                    _log.error("Error accepting - KILLING THE TUNNEL SERVER", ipe);
    579                 // TODO delay and loop if internal router is soft restarting?
    580590                open = false;
    581591                if (i2ps != null) try { i2ps.close(); } catch (IOException ioe) {}
  • apps/ministreaming/java/src/net/i2p/client/streaming/I2PServerSocket.java

    racebd2e r826d8ca  
    3030     * @throws I2PException if there is a problem with reading a new socket
    3131     *         from the data available (e.g. the I2PSession is closed)
     32     * @throws RouterRestartException (extends I2PException) if the router is apparently restarting, since 0.9.34
    3233     * @throws ConnectException if the I2PServerSocket is closed, or if interrupted.
    3334     *         Not actually thrown through 0.9.16; thrown as of 0.9.17
  • apps/streaming/java/src/net/i2p/client/streaming/impl/ConnectionHandler.java

    racebd2e r826d8ca  
    77
    88import net.i2p.I2PAppContext;
     9import net.i2p.client.streaming.RouterRestartException;
    910import net.i2p.data.Destination;
    1011import net.i2p.util.Log;
     
    2829    private volatile boolean _active;
    2930    private int _acceptTimeout;
     31    private boolean _restartPending;
    3032   
    3133    /** max time after receiveNewSyn() and before the matched accept() */
     
    4951    }
    5052   
     53    /**
     54     * The router told us it's going to restart.
     55     * Call instead of setActive(false).
     56     *
     57     * @since 0.9.34
     58     */
     59    public synchronized void setRestartPending() {
     60        _restartPending = true;
     61        setActive(false);
     62    }
     63
    5164    public synchronized void setActive(boolean active) {
    5265        // FIXME active=false this only kills for one thread in accept()
     
    5568            _log.warn("setActive(" + active + ") called, previously " + _active, new Exception("I did it"));
    5669        // if starting, clear any old poison
    57         if (active && !_active)
     70        if (active && !_active) {
     71            _restartPending = false;
    5872            _synQueue.clear();
     73        }
    5974        boolean wasActive = _active;
    6075        _active = active;
     
    117132     * @return connection received. Prior to 0.9.17, or null if there was a timeout or the
    118133     *                  handler was shut down. As of 0.9.17, never null.
     134     * @throws RouterRestartException (extends I2PException) if the router is apparently restarting, since 0.9.34
    119135     * @throws ConnectException since 0.9.17, returned null before;
    120136     *                  if the I2PServerSocket is closed, or if interrupted.
     
    122138     *                  if a timeout was previously set with setSoTimeout and the timeout has been reached.
    123139     */
    124     public Connection accept(long timeoutMs) throws ConnectException, SocketTimeoutException {
     140    public Connection accept(long timeoutMs) throws RouterRestartException, ConnectException, SocketTimeoutException {
    125141        if (_log.shouldLog(Log.DEBUG))
    126142            _log.debug("Accept("+ timeoutMs+") called");
     
    138154                    sendReset(packet);
    139155                }
     156                if (_restartPending)
     157                    throw new RouterRestartException();
    140158                throw new ConnectException("ServerSocket closed");
    141159            }
     
    175193
    176194            if (syn != null) {
    177                 if (syn.getOptionalDelay() == PoisonPacket.POISON_MAX_DELAY_REQUEST)
     195                if (syn.getOptionalDelay() == PoisonPacket.POISON_MAX_DELAY_REQUEST) {
     196                    if (_restartPending)
     197                        throw new RouterRestartException();
    178198                    throw new ConnectException("ServerSocket closed");
     199                }
    179200
    180201                // deal with forged / invalid syn packets in _manager.receiveConnection()
  • apps/streaming/java/src/net/i2p/client/streaming/impl/I2PServerSocketFull.java

    racebd2e r826d8ca  
    3131     * @throws I2PException if there is a problem with reading a new socket
    3232     *         from the data available (e.g. the I2PSession is closed)
     33     * @throws RouterRestartException (extends I2PException) if the router is apparently restarting, since 0.9.34
    3334     * @throws ConnectException if the I2PServerSocket is closed, or if interrupted.
    3435     *         Not actually thrown through 0.9.16; thrown as of 0.9.17
  • apps/streaming/java/src/net/i2p/client/streaming/impl/I2PSocketManagerFull.java

    racebd2e r826d8ca  
    351351     * @return connected I2PSocket, or null through 0.9.16, non-null as of 0.9.17
    352352     * @throws I2PException if session is closed
     353     * @throws RouterRestartException (extends I2PException) if the router is apparently restarting, since 0.9.34
    353354     * @throws ConnectException (since 0.9.17; I2PServerSocket interface always declared it)
    354355     * @throws SocketTimeoutException if a timeout was previously set with setSoTimeout and the timeout has been reached.
  • apps/streaming/java/src/net/i2p/client/streaming/impl/MessageHandler.java

    racebd2e r826d8ca  
    2323    private final Log _log;
    2424    private final Set<I2PSocketManager.DisconnectListener> _listeners;
     25    private boolean _restartPending;
    2526   
    2627    public MessageHandler(I2PAppContext ctx, ConnectionManager mgr) {
     
    105106        _manager.disconnectAllHard();
    106107        // kill anybody waiting in accept()
    107         _manager.getConnectionHandler().setActive(false);
     108        if (_restartPending) {
     109            _manager.getConnectionHandler().setRestartPending();
     110            _restartPending = false;
     111        } else {
     112            _manager.getConnectionHandler().setActive(false);
     113        }
    108114       
    109115        for (I2PSocketManager.DisconnectListener lsnr : _listeners) {
     
    121127     */
    122128    public void errorOccurred(I2PSession session, String message, Throwable error) {
     129        _restartPending = message.contains("restart");
    123130        if (_log.shouldLog(Log.WARN))
    124             _log.warn("error occurred: " + message + "- " + error.getMessage(), error);
     131            _log.warn("error occurred: " + message, error);
    125132        //_manager.disconnectAllHard();
    126133    }
  • core/java/src/net/i2p/client/impl/DisconnectMessageHandler.java

    racebd2e r826d8ca  
    3131            _log.debug("Handle message " + message);
    3232        String reason = ((DisconnectMessage)message).getReason();
    33         session.propogateError(reason, new I2PSessionException("Disconnect Message received"));
     33        session.propogateError(reason, new I2PSessionException("Disconnect Message received: " + reason));
    3434        session.destroySession(false);
    3535        if (reason.contains("restart")) {
     
    4848
    4949        public void run() {
    50             try { Thread.sleep(10*1000); } catch (InterruptedException ie) {}
     50            try { Thread.sleep(40*1000); } catch (InterruptedException ie) {}
    5151            _session.reconnect();
    5252        }
  • history.txt

    racebd2e r826d8ca  
     12018-02-18 zzz
     2 * i2ptunnel: Retry accept after router soft restart (ticket #2003)
     3
     42018-02-17 zzz
     5 * Console: Number formatting tweaks (ticket #1913)
     6 * i2psnark: folder.js cleanup (ticket #2168, PR #14)
     7 * i2ptunnel: Close sockets in finally{}
     8 * SusiMail: Fix mail save truncation
     9
    1102018-02-16 zzz
    211 * i2psnark: Fix NPE on torrent not found (ticket #2167)
  • router/java/src/net/i2p/router/RouterVersion.java

    racebd2e r826d8ca  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 6;
     21    public final static long BUILD = 7;
    2222
    2323    /** for example "-test" */
Note: See TracChangeset for help on using the changeset viewer.