Changeset d5990cc


Ignore:
Timestamp:
Dec 20, 2015 2:15:48 PM (4 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
e9146eb
Parents:
0b94d86
Message:

Transports: Add mayDisconnect() advisory which says we
don't expect more messages on this connection; use for BuildHandler?
Rename some dest arguments to peer for clarity
UDP: Display messages, not packets, sent/rcvd on /peers
Don't count duplicates in received message count
Count sent messages when sent, not acked
Move some PeerState? counters from longs to ints to save space

Location:
router/java/src/net/i2p/router
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/CommSystemFacade.java

    r0b94d86 rd5990cc  
    7171     * @deprecated use getStatus()
    7272     */
     73    @Deprecated
    7374    public short getReachabilityStatus() { return (short) getStatus().getCode(); }
    7475   
     
    8283     * @deprecated unused
    8384     */
     85    @Deprecated
    8486    public void recheckReachability() {}
    8587
    86     public boolean isBacklogged(Hash dest) { return false; }
    87     public boolean wasUnreachable(Hash dest) { return false; }
    88     public boolean isEstablished(Hash dest) { return false; }
     88    public boolean isBacklogged(Hash peer) { return false; }
     89    public boolean wasUnreachable(Hash peer) { return false; }
     90    public boolean isEstablished(Hash peer) { return false; }
    8991    public byte[] getIP(Hash dest) { return null; }
    9092    public void queueLookup(byte[] ip) {}
     93   
     94    /**
     95     * Tell the comm system that we may disconnect from this peer.
     96     * This is advisory only.
     97     *
     98     * @since 0.9.24
     99     */
     100    public void mayDisconnect(Hash peer) {}
    91101
    92102    /** @since 0.8.11 */
  • router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java

    r0b94d86 rd5990cc  
    156156   
    157157    @Override
    158     public boolean isBacklogged(Hash dest) {
    159         return _manager.isBacklogged(dest);
    160     }
    161    
    162     @Override
    163     public boolean isEstablished(Hash dest) {
    164         return _manager.isEstablished(dest);
    165     }
    166    
    167     @Override
    168     public boolean wasUnreachable(Hash dest) {
    169         return _manager.wasUnreachable(dest);
    170     }
    171    
    172     @Override
    173     public byte[] getIP(Hash dest) {
    174         return _manager.getIP(dest);
     158    public boolean isBacklogged(Hash peer) {
     159        return _manager.isBacklogged(peer);
     160    }
     161   
     162    @Override
     163    public boolean isEstablished(Hash peer) {
     164        return _manager.isEstablished(peer);
     165    }
     166   
     167    @Override
     168    public boolean wasUnreachable(Hash peer) {
     169        return _manager.wasUnreachable(peer);
     170    }
     171   
     172    @Override
     173    public byte[] getIP(Hash peer) {
     174        return _manager.getIP(peer);
     175    }
     176   
     177    /**
     178     * Tell the comm system that we may disconnect from this peer.
     179     * This is advisory only.
     180     *
     181     * @since 0.9.24
     182     */
     183    @Override
     184    public void mayDisconnect(Hash peer) {
     185        _manager.mayDisconnect(peer);
    175186    }
    176187   
     
    197208     */
    198209    @Override
     210    @Deprecated
    199211    public void recheckReachability() { _manager.recheckReachability(); }
    200212
  • router/java/src/net/i2p/router/transport/Transport.java

    r0b94d86 rd5990cc  
    172172    public boolean isUnreachable(Hash peer);
    173173    public boolean isEstablished(Hash peer);
     174
     175    /**
     176     * Tell the transport that we may disconnect from this peer.
     177     * This is advisory only.
     178     *
     179     * @since 0.9.24
     180     */
     181    public void mayDisconnect(Hash peer);
    174182}
  • router/java/src/net/i2p/router/transport/TransportImpl.java

    r0b94d86 rd5990cc  
    810810     * @deprecated unused
    811811     */
     812    @Deprecated
    812813    public void recheckReachability() {}
    813814
     
    819820    }
    820821
    821     public boolean isBacklogged(Hash dest) { return false; }
    822     public boolean isEstablished(Hash dest) { return false; }
     822    public boolean isBacklogged(Hash peer) { return false; }
     823    public boolean isEstablished(Hash peer) { return false; }
     824
     825    /**
     826     * Tell the transport that we may disconnect from this peer.
     827     * This is advisory only.
     828     *
     829     * @since 0.9.24
     830     */
     831    public void mayDisconnect(Hash peer) {}
    823832
    824833    public boolean isUnreachable(Hash peer) {
  • router/java/src/net/i2p/router/transport/TransportManager.java

    r0b94d86 rd5990cc  
    408408     * @deprecated unused
    409409     */
     410    @Deprecated
    410411    public void recheckReachability() {
    411412        for (Transport t : _transports.values())
     
    413414    }
    414415
    415     public boolean isBacklogged(Hash dest) {
    416         for (Transport t : _transports.values()) {
    417             if (t.isBacklogged(dest))
     416    public boolean isBacklogged(Hash peer) {
     417        for (Transport t : _transports.values()) {
     418            if (t.isBacklogged(peer))
    418419                return true;
    419420        }
     
    421422    }   
    422423   
    423     public boolean isEstablished(Hash dest) {
    424         for (Transport t : _transports.values()) {
    425             if (t.isEstablished(dest))
     424    public boolean isEstablished(Hash peer) {
     425        for (Transport t : _transports.values()) {
     426            if (t.isEstablished(peer))
    426427                return true;
    427428        }
    428429        return false;
    429430    }   
     431   
     432    /**
     433     * Tell the transports that we may disconnect from this peer.
     434     * This is advisory only.
     435     *
     436     * @since 0.9.24
     437     */
     438    public void mayDisconnect(Hash peer) {
     439        for (Transport t : _transports.values()) {
     440             t.mayDisconnect(peer);
     441        }
     442    }
    430443   
    431444    /**
     
    434447     * This is NOT reset if the peer contacts us.
    435448     */
    436     public boolean wasUnreachable(Hash dest) {
    437         for (Transport t : _transports.values()) {
    438             if (!t.wasUnreachable(dest))
     449    public boolean wasUnreachable(Hash peer) {
     450        for (Transport t : _transports.values()) {
     451            if (!t.wasUnreachable(peer))
    439452                return false;
    440453        }
     
    453466     * @return IPv4 or IPv6 or null
    454467     */
    455     public byte[] getIP(Hash dest) {
    456         return TransportImpl.getIP(dest);
     468    public byte[] getIP(Hash peer) {
     469        return TransportImpl.getIP(peer);
    457470    }   
    458471   
     
    746759                   "<b id=\"def.rto\">RTO</b>: ").append(_t("The retransmit timeout in milliseconds")).append("<br>\n" +
    747760                   "<b id=\"def.mtu\">MTU</b>: ").append(_t("Current maximum send packet size / estimated maximum receive packet size (bytes)")).append("<br>\n" +
    748                    "<b id=\"def.send\">").append(_t("TX")).append("</b>: ").append(_t("The total number of packets sent to the peer")).append("<br>\n" +
    749                    "<b id=\"def.recv\">").append(_t("RX")).append("</b>: ").append(_t("The total number of packets received from the peer")).append("<br>\n" +
     761                   "<b id=\"def.send\">").append(_t("TX")).append("</b>: ").append(_t("The total number of messages sent to the peer")).append("<br>\n" +
     762                   "<b id=\"def.recv\">").append(_t("RX")).append("</b>: ").append(_t("The total number of messages received from the peer")).append("<br>\n" +
    750763                   "<b id=\"def.resent\">").append(_t("Dup TX")).append("</b>: ").append(_t("The total number of packets retransmitted to the peer")).append("<br>\n" +
    751764                   "<b id=\"def.dupRecv\">").append(_t("Dup RX")).append("</b>: ").append(_t("The total number of duplicate packets received from the peer")).append("</p>" +
  • router/java/src/net/i2p/router/transport/ntcp/EventPumper.java

    r0b94d86 rd5990cc  
    8686    private static final long MIN_EXPIRE_IDLE_TIME = 120*1000l;
    8787    private static final long MAX_EXPIRE_IDLE_TIME = 11*60*1000l;
     88    private static final long MAY_DISCON_TIMEOUT = 10*1000;
    8889
    8990    /**
     
    222223
    223224                        // Increase allowed idle time if we are well under allowed connections, otherwise decrease
    224                         if (_transport.haveCapacity(33))
     225                        boolean haveCap = _transport.haveCapacity(33);
     226                        if (haveCap)
    225227                            _expireIdleWriteTime = Math.min(_expireIdleWriteTime + 1000, MAX_EXPIRE_IDLE_TIME);
    226228                        else
     
    271273                                }
    272274                               
    273                                 if ( con.getTimeSinceSend() > _expireIdleWriteTime &&
    274                                      con.getTimeSinceReceive() > _expireIdleWriteTime) {
     275                                final long expire;
     276                                if (!haveCap && con.getMayDisconnect() &&
     277                                    con.getMessagesReceived() <= 2 && con.getMessagesSent() <= 1) {
     278                                    expire = MAY_DISCON_TIMEOUT;
     279                                } else {
     280                                    expire = _expireIdleWriteTime;
     281                                }
     282
     283                                if ( con.getTimeSinceSend() > expire &&
     284                                     con.getTimeSinceReceive() > expire) {
    275285                                    // we haven't sent or received anything in a really long time, so lets just close 'er up
    276286                                    con.close();
  • router/java/src/net/i2p/router/transport/ntcp/NTCPConnection.java

    r0b94d86 rd5990cc  
    1414import java.util.concurrent.LinkedBlockingQueue;
    1515import java.util.concurrent.atomic.AtomicBoolean;
     16import java.util.concurrent.atomic.AtomicInteger;
    1617import java.util.concurrent.atomic.AtomicLong;
    1718import java.util.zip.Adler32;
     
    116117    /** current partially read I2NP message */
    117118    private final ReadState _curReadState;
    118     private final AtomicLong _messagesRead = new AtomicLong();
    119     private final AtomicLong _messagesWritten = new AtomicLong();
     119    private final AtomicInteger _messagesRead = new AtomicInteger();
     120    private final AtomicInteger _messagesWritten = new AtomicInteger();
    120121    private long _lastSendTime;
    121122    private long _lastReceiveTime;
     
    135136    //private int _consecutiveBacklog;
    136137    private long _nextInfoTime;
     138    private boolean _mayDisconnect;
    137139   
    138140    /*
     
    326328    }
    327329
    328     public long getMessagesSent() { return _messagesWritten.get(); }
    329 
    330     public long getMessagesReceived() { return _messagesRead.get(); }
    331 
    332     public long getOutboundQueueSize() {
     330    public int getMessagesSent() { return _messagesWritten.get(); }
     331
     332    public int getMessagesReceived() { return _messagesRead.get(); }
     333
     334    public int getOutboundQueueSize() {
    333335            int queued;
    334336            synchronized(_outbound) {
     
    360362     */
    361363    public long getCreated() { return _created; }
     364
     365    /**
     366     * Sets to true.
     367     * @since 0.9.24
     368     */
     369    public void setMayDisconnect() { _mayDisconnect = true; }
     370
     371    /**
     372     * @since 0.9.24
     373     */
     374    public boolean getMayDisconnect() { return _mayDisconnect; }
    362375
    363376    /**
  • router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java

    r0b94d86 rd5990cc  
    488488
    489489    /**
     490     * Tell the transport that we may disconnect from this peer.
     491     * This is advisory only.
     492     *
     493     * @since 0.9.24
     494     */
     495    @Override
     496    public void mayDisconnect(final Hash peer) {
     497        final NTCPConnection con = _conByIdent.get(peer);
     498        if (con != null && con.isEstablished() && con.isInbound() &&
     499            con.getMessagesReceived() <= 2 && con.getMessagesSent() <= 1) {
     500            con.setMayDisconnect();
     501        }
     502    }
     503
     504    /**
    490505     * @return usually the con passed in, but possibly a second connection with the same peer...
    491506     */
  • router/java/src/net/i2p/router/transport/udp/OutboundMessageState.java

    r0b94d86 rd5990cc  
    178178     * Note that we have pushed the message fragments.
    179179     * Increments push count (and max sends... why?)
    180      */
    181     public synchronized void push() {
     180     * @return true if this is the first push
     181     */
     182    public synchronized boolean push() {
     183        boolean rv = _pushCount == 0;
    182184        // these will never be different...
    183185        _pushCount++;
    184186        _maxSends = _pushCount;
     187        return rv;
    185188    }
    186189
  • router/java/src/net/i2p/router/transport/udp/PeerState.java

    r0b94d86 rd5990cc  
    199199    private int _packetsReceivedDuplicate;
    200200    private int _packetsReceived;
     201    private boolean _mayDisconnect;
    201202   
    202203    /** list of InboundMessageState for active message */
     
    448449     *  @deprecated unused, ECNs are never sent, always returns false
    449450     */
     451    @Deprecated
    450452    public boolean getCurrentSecondECNReceived() { return _currentSecondECNReceived; }
    451453
     
    543545     * @deprecated unused
    544546     */
     547    @Deprecated
    545548    public void setNextMACKey(SessionKey key) { _nextMACKey = key; }
    546549
     
    551554     * @deprecated unused
    552555     */
     556    @Deprecated
    553557    public void setNextCipherKey(SessionKey key) { _nextCipherKey = key; }
    554558
     
    570574     * @deprecated unused
    571575     */
     576    @Deprecated
    572577    public void setKeyEstablishedTime(long when) { _keyEstablishedTime = when; }
    573578
     
    772777    public void setIntroducerTime() { _lastIntroducerTime = _context.clock().now(); }
    773778   
    774     /** we received the message specified completely */
     779    /**
     780     *  We received the message specified completely.
     781     *  @param bytes if less than or equal to zero, message is a duplicate.
     782     */
    775783    public void messageFullyReceived(Long messageId, int bytes) { messageFullyReceived(messageId, bytes, false); }
    776784
    777     public synchronized void messageFullyReceived(Long messageId, int bytes, boolean isForACK) {
     785    /**
     786     *  We received the message specified completely.
     787     *  @param isForACK unused
     788     *  @param bytes if less than or equal to zero, message is a duplicate.
     789     */
     790    private synchronized void messageFullyReceived(Long messageId, int bytes, boolean isForACK) {
    778791        if (bytes > 0) {
    779792            _receiveBytes += bytes;
     
    804817            _wantACKSendSince = now;
    805818        _currentACKs.add(messageId);
    806         _messagesReceived++;
    807819    }
    808820   
     
    959971     * @deprecated unused
    960972     */
     973    @Deprecated
    961974    public List<ACKBitfield> retrieveACKBitfields() { return retrieveACKBitfields(true); }
    962975
     
    10281041            }
    10291042
    1030 
    1031 
    1032 
    1033 
    10341043        int partialIncluded = 0;
    10351044        if (bytesRemaining > 4) {
     
    12751284    public synchronized int getRTTDeviation() { return _rttDeviation; }
    12761285   
    1277     public synchronized int getMessagesSent() { return _messagesSent; }
     1286    /**
     1287     *  I2NP messages sent.
     1288     *  Does not include duplicates.
     1289     *  As of 0.9.24, incremented when bandwidth is allocated just before sending, not when acked.
     1290     */
     1291    public int getMessagesSent() {
     1292        synchronized (_outboundMessages) {
     1293            return _messagesSent;
     1294        }
     1295    }
     1296   
     1297    /**
     1298     *  I2NP messages received.
     1299     *  As of 0.9.24, does not include duplicates.
     1300     */
    12781301    public synchronized int getMessagesReceived() { return _messagesReceived; }
     1302
    12791303    public synchronized int getPacketsTransmitted() { return _packetsTransmitted; }
    12801304    public synchronized int getPacketsRetransmitted() { return _packetsRetransmitted; }
     
    13401364
    13411365    /** @deprecated unused */
     1366    @Deprecated
    13421367    public void setLastACKSend(long when) { _lastACKSend = when; }
    13431368
     
    14991524        return _outboundMessages.size() + _outboundQueue.size();
    15001525    }
     1526
     1527    /**
     1528     * Sets to true.
     1529     * @since 0.9.24
     1530     */
     1531    public void setMayDisconnect() { _mayDisconnect = true; }
     1532
     1533    /**
     1534     * @since 0.9.24
     1535     */
     1536    public boolean getMayDisconnect() { return _mayDisconnect; }
     1537
    15011538   
    15021539    /**
     
    17721809                    _retransmitter = state;
    17731810
    1774                 state.push();
     1811                if (state.push())
     1812                    _messagesSent++;
    17751813           
    17761814                int rto = getRTO();
     
    20632101        buf.append(" acwin: ").append(_sendWindowBytesRemaining);
    20642102        buf.append(" consecFail: ").append(_consecutiveFailedSends);
    2065         buf.append(" recv OK/Dup: ").append(_packetsReceived).append('/').append(_packetsReceivedDuplicate);
    2066         buf.append(" send OK/Dup: ").append(_packetsTransmitted).append('/').append(_packetsRetransmitted);
     2103        buf.append(" msgs rcvd: ").append(_messagesReceived);
     2104        buf.append(" msgs sent: ").append(_messagesSent);
     2105        buf.append(" pkts rcvd OK/Dup: ").append(_packetsReceived).append('/').append(_packetsReceivedDuplicate);
     2106        buf.append(" pkts sent OK/Dup: ").append(_packetsTransmitted).append('/').append(_packetsRetransmitted);
    20672107        buf.append(" IBM: ").append(_inboundMessages.size());
    20682108        buf.append(" OBQ: ").append(_outboundQueue.size());
  • router/java/src/net/i2p/router/transport/udp/UDPTransport.java

    r0b94d86 rd5990cc  
    24312431        PeerState peer =  _peersByIdent.get(dest);
    24322432        return peer != null && peer.isBacklogged();
     2433    }
     2434
     2435    /**
     2436     * Tell the transport that we may disconnect from this peer.
     2437     * This is advisory only.
     2438     *
     2439     * @since 0.9.24
     2440     */
     2441    @Override
     2442    public void mayDisconnect(final Hash peer) {
     2443        final PeerState ps =  _peersByIdent.get(peer);
     2444        if (ps != null && ps.isInbound() &&
     2445            ps.getMessagesReceived() <= 2 && ps.getMessagesSent() <= 1) {
     2446            ps.setMayDisconnect();
     2447        }
    24332448    }
    24342449
     
    26792694            buf.append("</td>");
    26802695       
    2681             long sent = peer.getPacketsTransmitted();
    2682             long recv = peer.getPacketsReceived();
     2696            long sent = peer.getMessagesSent();
     2697            long recv = peer.getMessagesReceived();
    26832698           
    26842699            buf.append("<td class=\"cells\" align=\"right\">");
     
    28212836        private static final long EXPIRE_INCREMENT = 15*1000;
    28222837        private static final long EXPIRE_DECREMENT = 45*1000;
     2838        private static final long MAY_DISCON_TIMEOUT = 10*1000;
    28232839
    28242840        public ExpirePeerEvent() {
     
    28302846        public void timeReached() {
    28312847            // Increase allowed idle time if we are well under allowed connections, otherwise decrease
    2832             if (haveCapacity(33)) {
     2848            boolean haveCap = haveCapacity(33);
     2849            if (haveCap) {
    28332850                long inc;
    28342851                // don't adjust too quickly if we are looping fast
     
    28492866            long shortInactivityCutoff = now - _expireTimeout;
    28502867            long longInactivityCutoff = now - EXPIRE_TIMEOUT;
     2868            final long mayDisconCutoff = now - MAY_DISCON_TIMEOUT;
    28512869            long pingCutoff = now - (2 * 60*60*1000);
    28522870            long pingFirewallCutoff = now - PING_FIREWALL_CUTOFF;
     
    28632881                    long inactivityCutoff;
    28642882                    // if we offered to introduce them, or we used them as introducer in last 2 hours
    2865                     if (peer.getWeRelayToThemAs() > 0 || peer.getIntroducerTime() > pingCutoff)
     2883                    if (peer.getWeRelayToThemAs() > 0 || peer.getIntroducerTime() > pingCutoff) {
    28662884                        inactivityCutoff = longInactivityCutoff;
    2867                     else
     2885                    } else if (!haveCap && peer.getMayDisconnect() &&
     2886                               peer.getMessagesReceived() <= 2 && peer.getMessagesSent() <= 1) {
     2887                        inactivityCutoff = mayDisconCutoff;
     2888                    } else {
    28682889                        inactivityCutoff = shortInactivityCutoff;
     2890                    }
    28692891                    if ( (peer.getLastReceiveTime() < inactivityCutoff) && (peer.getLastSendTime() < inactivityCutoff) ) {
    28702892                        _expireBuffer.add(peer);
  • router/java/src/net/i2p/router/tunnel/pool/BuildHandler.java

    r0b94d86 rd5990cc  
    639639            _context.statManager().addRateData("tunnel.rejectHostile", 1);
    640640            _log.error("Dropping build request, IBGW+OBEP");
     641            if (from != null)
     642                _context.commSystem().mayDisconnect(from);
    641643            return;
    642644        }
     
    650652            if (_log.shouldWarn())
    651653                _log.warn("Dropping build request, we are the next hop");
     654            if (from != null)
     655                _context.commSystem().mayDisconnect(from);
    652656            return;
    653657        }
     
    670674                if (_log.shouldLog(Log.WARN))
    671675                    _log.warn("Dropping build request with the same previous and next hop");
     676                _context.commSystem().mayDisconnect(from);
    672677                return;
    673678            }
     
    684689            if (_log.shouldLog(Log.WARN))
    685690                _log.warn("Dropping build request too old... replay attack? " + DataHelper.formatDuration(timeDiff));
     691            if (from != null)
     692                _context.commSystem().mayDisconnect(from);
    686693            return;
    687694        }
     
    690697            if (_log.shouldLog(Log.WARN))
    691698                _log.warn("Dropping build request too far in future " + DataHelper.formatDuration(0 - timeDiff));
     699            if (from != null)
     700                _context.commSystem().mayDisconnect(from);
    692701            return;
    693702        }
     
    845854                                                     recvDelay + " as " +
    846855                                                     (isOutEnd ? "outbound endpoint" : isInGW ? "inbound gw" : "participant"));
     856            if (from != null)
     857                _context.commSystem().mayDisconnect(from);
    847858            // Connection congestion control:
    848859            // If we rejected the request, are near our conn limits, and aren't connected to the next hop,
     
    857868                return;
    858869            }
     870        } else if (isInGW && from != null) {
     871            // we're the start of the tunnel, no use staying connected
     872            _context.commSystem().mayDisconnect(from);
    859873        }
    860874
Note: See TracChangeset for help on using the changeset viewer.