Changeset 074c5aa1


Ignore:
Timestamp:
Dec 20, 2015 9:07:16 PM (4 years ago)
Author:
z3r0fox <z3r0fox@…>
Branches:
master
Children:
3bce2f5
Parents:
b6bd497 (diff), 879b706 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge of '22cebc21c21e3a101e03165f26a5e9fddc3648da'

and 'e210f94f3d17359b39a6b24f2a5e1221a86abfd0'

Files:
20 edited

Legend:

Unmodified
Added
Removed
  • apps/routerconsole/java/src/net/i2p/router/web/ConfigServiceHandler.java

    rb6bd497 r074c5aa1  
    156156    /**
    157157     *  Register a handler for signals,
    158      *  so we can handle HUP from the wrapper (non-Windows only, wrapper 3.2.0 or higher)
     158     *  so we can handle HUP from the wrapper (wrapper 3.2.0 or higher)
    159159     *
    160160     *  @since 0.8.13
  • apps/routerconsole/java/src/net/i2p/router/web/SybilRenderer.java

    rb6bd497 r074c5aa1  
    6565    private static final double PAIR_DISTANCE_FACTOR = 2.0;
    6666    private static final double OUR_KEY_FACTOR = 4.0;
    67     private static final double MIN_DISPLAY_POINTS = 3.0;
     67    private static final double MIN_DISPLAY_POINTS = 5.0;
    6868    private static final double VERSION_FACTOR = 1.0;
     69    private static final double POINTS_BAD_VERSION = 50.0;
     70    private static final double POINTS_UNREACHABLE = 4.0;
     71    private static final double POINTS_NEW = 4.0;
    6972
    7073    public SybilRenderer(RouterContext ctx) {
     
    617620                    long age = Math.max(now - heard, 1);
    618621                    if (age < 2 * DAY) {
    619                         // .125 point for every hour under 48, max 6 points
    620                         double point = Math.min(6.0d, (2 * DAY - age) / (2 * DAY / 6.0d));
     622                        // (POINTS_NEW / 48) for every hour under 48, max POINTS_NEW
     623                        double point = Math.min(POINTS_NEW, (2 * DAY - age) / (2 * DAY / POINTS_NEW));
    621624                        addPoints(points, h, point,
    622625                                  "First heard about: " + _t("{0} ago", DataHelper.formatDuration2(age)));
     
    657660        for (RouterInfo info : ris) {
    658661            Hash h = info.getHash();
     662            String caps = info.getCapabilities();
     663            if (!caps.contains("R"))
     664                addPoints(points, h, POINTS_UNREACHABLE, "Unreachable: " + DataHelper.escapeHTML(caps));
    659665            String hisFullVer = info.getVersion();
    660666            if (!hisFullVer.startsWith("0.9.")) {
    661                 addPoints(points, h, 50.0, "Strange version " + DataHelper.escapeHTML(hisFullVer));
     667                addPoints(points, h, POINTS_BAD_VERSION, "Strange version " + DataHelper.escapeHTML(hisFullVer));
    662668                continue;
    663669            }
  • core/java/src/net/i2p/crypto/CertUtil.java

    rb6bd497 r074c5aa1  
    99import java.io.PrintWriter;
    1010import java.security.GeneralSecurityException;
     11import java.security.InvalidKeyException;
     12import java.security.PrivateKey;
    1113import java.security.PublicKey;
    1214import java.security.cert.Certificate;
     
    3739
    3840    /**
    39      *  Modified from:
    40      *  http://www.exampledepot.com/egs/java.security.cert/ExportCert.html
    41      *
    42      *  This method writes a certificate to a file in base64 format.
     41     *  Write a certificate to a file in base64 format.
    4342     *
    4443     *  @return success
     
    4746    public static boolean saveCert(Certificate cert, File file) {
    4847        OutputStream os = null;
    49         PrintWriter wr = null;
    5048        try {
    51            // Get the encoded form which is suitable for exporting
    52            byte[] buf = cert.getEncoded();
    5349           os = new SecureFileOutputStream(file);
    54            wr = new PrintWriter(new OutputStreamWriter(os, "UTF-8"));
    55            wr.println("-----BEGIN CERTIFICATE-----");
    56            String b64 = Base64.encode(buf, true);     // true = use standard alphabet
    57            for (int i = 0; i < b64.length(); i += LINE_LENGTH) {
    58                wr.println(b64.substring(i, Math.min(i + LINE_LENGTH, b64.length())));
    59            }
    60            wr.println("-----END CERTIFICATE-----");
    61            wr.flush();
    62            if (wr.checkError())
    63                throw new IOException("Failed write to " + file);
     50           exportCert(cert, os);
    6451           return true;
    6552        } catch (CertificateEncodingException cee) {
     
    7259            try { if (os != null) os.close(); } catch (IOException foo) {}
    7360        }
     61    }
     62
     63    /**
     64     *  Writes the private key and all certs in base64 format.
     65     *  Does NOT close the stream. Throws on all errors.
     66     *
     67     *  @param pk non-null
     68     *  @param certs certificate chain, null or empty to export pk only
     69     *  @throws InvalidKeyException if the key does not support encoding
     70     *  @throws CertificateEncodingException if a cert does not support encoding
     71     *  @since 0.9.24
     72     */
     73    public static void exportPrivateKey(PrivateKey pk, Certificate[] certs, OutputStream out)
     74                                                throws IOException, GeneralSecurityException {
     75        exportPrivateKey(pk, out);
     76        if (certs == null)
     77            return;
     78        for (int i = 0; i < certs.length; i++) {
     79            exportCert(certs[i], out);
     80        }
     81    }
     82
     83    /**
     84     *  Modified from:
     85     *  http://www.exampledepot.com/egs/java.security.cert/ExportCert.html
     86     *
     87     *  Writes a certificate in base64 format.
     88     *  Does NOT close the stream. Throws on all errors.
     89     *
     90     *  @since 0.9.24, pulled out of saveCert()
     91     */
     92    private static void exportCert(Certificate cert, OutputStream out)
     93                                                throws IOException, CertificateEncodingException {
     94        // Get the encoded form which is suitable for exporting
     95        byte[] buf = cert.getEncoded();
     96        PrintWriter wr = new PrintWriter(new OutputStreamWriter(out, "UTF-8"));
     97        wr.println("-----BEGIN CERTIFICATE-----");
     98        String b64 = Base64.encode(buf, true);     // true = use standard alphabet
     99        for (int i = 0; i < b64.length(); i += LINE_LENGTH) {
     100            wr.println(b64.substring(i, Math.min(i + LINE_LENGTH, b64.length())));
     101        }
     102        wr.println("-----END CERTIFICATE-----");
     103        wr.flush();
     104        if (wr.checkError())
     105            throw new IOException("Failed write to " + out);
     106    }
     107
     108    /**
     109     *  Modified from:
     110     *  http://www.exampledepot.com/egs/java.security.cert/ExportCert.html
     111     *
     112     *  Writes a private key in base64 format.
     113     *  Does NOT close the stream. Throws on all errors.
     114     *
     115     *  @throws InvalidKeyException if the key does not support encoding
     116     *  @since 0.9.24
     117     */
     118    private static void exportPrivateKey(PrivateKey pk, OutputStream out)
     119                                                throws IOException, InvalidKeyException {
     120        // Get the encoded form which is suitable for exporting
     121        byte[] buf = pk.getEncoded();
     122        if (buf == null)
     123            throw new InvalidKeyException("encoding unsupported for this key");
     124        PrintWriter wr = new PrintWriter(new OutputStreamWriter(out, "UTF-8"));
     125        wr.println("-----BEGIN PRIVATE KEY-----");
     126        String b64 = Base64.encode(buf, true);     // true = use standard alphabet
     127        for (int i = 0; i < b64.length(); i += LINE_LENGTH) {
     128            wr.println(b64.substring(i, Math.min(i + LINE_LENGTH, b64.length())));
     129        }
     130        wr.println("-----END PRIVATE KEY-----");
     131        wr.flush();
     132        if (wr.checkError())
     133            throw new IOException("Failed write to " + out);
    74134    }
    75135
  • history.txt

    rb6bd497 r074c5aa1  
     12015-12-20 zzz
     2 * BuildHandler: Additional fixes (ticket #1738)
     3 * CertUtil: Add methods to export private keys
     4 * Console: Sybil tool enhancementsrivate keys
     5 * Transports:
     6   - Disconnect faster when first message is a
     7     tunnel build request which we reject
     8   - Display SSU sent/received messages, not packets,
     9     on /peers to be consistent with NTCP
     10
    1112015-12-18 zzz
    212 * BuildHandler: Fix NPE (ticket #1738)
  • router/java/src/net/i2p/router/CommSystemFacade.java

    rb6bd497 r074c5aa1  
    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/InNetMessagePool.java

    rb6bd497 r074c5aa1  
    9595     * @throws AIOOBE if i2npMessageType is greater than MAX_I2NP_MESSAGE_TYPE
    9696     */
    97     public HandlerJobBuilder registerHandlerJobBuilder(int i2npMessageType, HandlerJobBuilder builder) {
     97    public synchronized HandlerJobBuilder registerHandlerJobBuilder(int i2npMessageType, HandlerJobBuilder builder) {
    9898        HandlerJobBuilder old = _handlerJobBuilders[i2npMessageType];
    9999        _handlerJobBuilders[i2npMessageType] = builder;
     
    104104     * @return previous builder for this message type, or null
    105105     * @throws AIOOBE if i2npMessageType is greater than MAX_I2NP_MESSAGE_TYPE
     106     * @deprecated unused
    106107     */
    107     public HandlerJobBuilder unregisterHandlerJobBuilder(int i2npMessageType) {
     108    @Deprecated
     109    public synchronized HandlerJobBuilder unregisterHandlerJobBuilder(int i2npMessageType) {
    108110        HandlerJobBuilder old = _handlerJobBuilders[i2npMessageType];
    109111        _handlerJobBuilders[i2npMessageType] = null;
  • router/java/src/net/i2p/router/RouterVersion.java

    rb6bd497 r074c5aa1  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 15;
     21    public final static long BUILD = 16;
    2222
    2323    /** for example "-test" */
  • router/java/src/net/i2p/router/StatisticsManager.java

    rb6bd497 r074c5aa1  
    196196                    // copy over the pubkey and signature
    197197                    key = oldRI.getOption(FamilyKeyCrypto.OPT_KEY);
    198                     if (key != null)
    199                         stats.setProperty(FamilyKeyCrypto.OPT_KEY, key);
    200                     sig = oldRI.getOption(FamilyKeyCrypto.OPT_SIG);
    201                     if (sig != null)
    202                         stats.setProperty(FamilyKeyCrypto.OPT_SIG, sig);
     198                    if (key != null) {
     199                        if (key.contains(";")) {
     200                            // we changed the separator from ';' to ':'
     201                            key = null;
     202                        } else {
     203                            stats.setProperty(FamilyKeyCrypto.OPT_KEY, key);
     204                            sig = oldRI.getOption(FamilyKeyCrypto.OPT_SIG);
     205                            if (sig != null)
     206                                stats.setProperty(FamilyKeyCrypto.OPT_SIG, sig);
     207                        }
     208                    }
    203209                }
    204210            }
  • router/java/src/net/i2p/router/crypto/FamilyKeyCrypto.java

    rb6bd497 r074c5aa1  
    135135        Map<String, String> rv = new HashMap<String, String>(3);
    136136        rv.put(OPT_NAME, family);
    137         rv.put(OPT_KEY, _pubkey.getType().getCode() + ";" + _pubkey.toBase64());
     137        rv.put(OPT_KEY, _pubkey.getType().getCode() + ":" + _pubkey.toBase64());
    138138        rv.put(OPT_SIG, sig.toBase64());
    139139        return rv;
     
    175175                String skey = ri.getOption(OPT_KEY);
    176176                if (skey != null) {
    177                     int semi = skey.indexOf(";");
    178                     if (semi > 0) {
     177                    int colon = skey.indexOf(':');
     178                    // switched from ';' to ':' during dev, remove this later
     179                    if (colon < 0)
     180                        colon = skey.indexOf(';');
     181                    if (colon > 0) {
    179182                        try {
    180                             int code = Integer.parseInt(skey.substring(0, semi));
     183                            int code = Integer.parseInt(skey.substring(0, colon));
    181184                            SigType type = SigType.getByCode(code);
    182185                            if (type != null) {
    183                                 byte[] bkey = Base64.decode(skey.substring(semi + 1));
     186                                byte[] bkey = Base64.decode(skey.substring(colon + 1));
    184187                                if (bkey != null) {
    185188                                    spk = new SigningPublicKey(type, bkey);
  • router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java

    rb6bd497 r074c5aa1  
    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

    rb6bd497 r074c5aa1  
    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

    rb6bd497 r074c5aa1  
    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

    rb6bd497 r074c5aa1  
    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

    rb6bd497 r074c5aa1  
    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

    rb6bd497 r074c5aa1  
    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

    rb6bd497 r074c5aa1  
    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

    rb6bd497 r074c5aa1  
    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

    rb6bd497 r074c5aa1  
    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;
    780793            //if (isForACK)
    781794            //    _receiveACKBytes += bytes;
     795            _messagesReceived++;
    782796        } else {
    783797            //if (true || _retransmissionPeriodStart + 1000 < _context.clock().now()) {
     
    804818            _wantACKSendSince = now;
    805819        _currentACKs.add(messageId);
    806         _messagesReceived++;
    807820    }
    808821   
     
    959972     * @deprecated unused
    960973     */
     974    @Deprecated
    961975    public List<ACKBitfield> retrieveACKBitfields() { return retrieveACKBitfields(true); }
    962976
     
    10281042            }
    10291043
    1030 
    1031 
    1032 
    1033 
    10341044        int partialIncluded = 0;
    10351045        if (bytesRemaining > 4) {
     
    12751285    public synchronized int getRTTDeviation() { return _rttDeviation; }
    12761286   
    1277     public synchronized int getMessagesSent() { return _messagesSent; }
     1287    /**
     1288     *  I2NP messages sent.
     1289     *  Does not include duplicates.
     1290     *  As of 0.9.24, incremented when bandwidth is allocated just before sending, not when acked.
     1291     */
     1292    public int getMessagesSent() {
     1293        synchronized (_outboundMessages) {
     1294            return _messagesSent;
     1295        }
     1296    }
     1297   
     1298    /**
     1299     *  I2NP messages received.
     1300     *  As of 0.9.24, does not include duplicates.
     1301     */
    12781302    public synchronized int getMessagesReceived() { return _messagesReceived; }
     1303
    12791304    public synchronized int getPacketsTransmitted() { return _packetsTransmitted; }
    12801305    public synchronized int getPacketsRetransmitted() { return _packetsRetransmitted; }
     
    13401365
    13411366    /** @deprecated unused */
     1367    @Deprecated
    13421368    public void setLastACKSend(long when) { _lastACKSend = when; }
    13431369
     
    14991525        return _outboundMessages.size() + _outboundQueue.size();
    15001526    }
     1527
     1528    /**
     1529     * Sets to true.
     1530     * @since 0.9.24
     1531     */
     1532    public void setMayDisconnect() { _mayDisconnect = true; }
     1533
     1534    /**
     1535     * @since 0.9.24
     1536     */
     1537    public boolean getMayDisconnect() { return _mayDisconnect; }
     1538
    15011539   
    15021540    /**
     
    17721810                    _retransmitter = state;
    17731811
    1774                 state.push();
     1812                if (state.push())
     1813                    _messagesSent++;
    17751814           
    17761815                int rto = getRTO();
     
    20632102        buf.append(" acwin: ").append(_sendWindowBytesRemaining);
    20642103        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);
     2104        buf.append(" msgs rcvd: ").append(_messagesReceived);
     2105        buf.append(" msgs sent: ").append(_messagesSent);
     2106        buf.append(" pkts rcvd OK/Dup: ").append(_packetsReceived).append('/').append(_packetsReceivedDuplicate);
     2107        buf.append(" pkts sent OK/Dup: ").append(_packetsTransmitted).append('/').append(_packetsRetransmitted);
    20672108        buf.append(" IBM: ").append(_inboundMessages.size());
    20682109        buf.append(" OBQ: ").append(_outboundQueue.size());
  • router/java/src/net/i2p/router/transport/udp/UDPTransport.java

    rb6bd497 r074c5aa1  
    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

    rb6bd497 r074c5aa1  
    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.