Changeset 278a814


Ignore:
Timestamp:
May 29, 2018 5:23:08 PM (2 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
884a42b
Parents:
277a161
Message:

NTCP: Cleanup, remove commented-out code in prep for NTCP2
Increase max RI size

Location:
router/java/src/net/i2p/router/transport/ntcp
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/transport/ntcp/EstablishState.java

    r277a161 r278a814  
    124124   
    125125    private static final int MIN_RI_SIZE = 387;
    126     private static final int MAX_RI_SIZE = 2048;
     126    private static final int MAX_RI_SIZE = 3072;
    127127
    128128    private static final int AES_SIZE = 16;
     
    257257            byte c = src.get();
    258258            _X[_received++] = c;
    259             //if (_log.shouldLog(Log.DEBUG)) _log.debug("recv x" + (int)c + " received=" + _received);
    260             //if (_received >= _X.length) {
    261             //    if (isCheckInfo(_context, _context.routerHash(), _X)) {
    262             //        _context.statManager().addRateData("ntcp.inboundCheckConnection", 1);
    263             //        fail("Incoming connection was a check connection");
    264             //        return;
    265             //    }
    266             //}
    267259            if (_received >= XY_SIZE)
    268260                changeState(State.IB_GOT_X);
     
    273265            byte c = src.get();
    274266            _hX_xor_bobIdentHash[i] = c;
    275             //if (_log.shouldLog(Log.DEBUG)) _log.debug("recv bih" + (int)c + " received=" + _received);
    276267            if (i >= HXY_SIZE - 1)
    277268                changeState(State.IB_GOT_HX);
     
    288279                _context.sha().calculateHash(_X, 0, XY_SIZE, realXor, 0);
    289280                xor32(_context.routerHash().getData(), realXor);
    290                 //if (_log.shouldLog(Log.DEBUG)) {
    291                     //_log.debug(prefix()+"_X = " + Base64.encode(_X));
    292                 //    _log.debug(prefix()+"hx = " + Base64.encode(hX.getData()));
    293                 //    _log.debug(prefix()+"bih=" + Base64.encode(_context.routerHash().getData()));
    294                 //    _log.debug(prefix()+"xor=" + Base64.encode(realXor));
    295                 //}
    296281                if (!DataHelper.eq(realXor, _hX_xor_bobIdentHash)) {
    297282                    SimpleByteCache.release(realXor);
     
    328313                    byte tsB[] = DataHelper.toLong(4, _tsB);
    329314                    System.arraycopy(tsB, 0, toEncrypt, HXY_SIZE, tsB.length);
    330                     //DataHelper.toLong(toEncrypt, hxy.getData().length, 4, _tsB);
    331315                    _context.random().nextBytes(toEncrypt, HXY_SIZE + 4, 12);
    332316                    if (_log.shouldLog(Log.DEBUG)) {
    333                         //_log.debug(prefix()+"Y="+Base64.encode(_Y));
    334                         //_log.debug(prefix()+"x+y="+Base64.encode(xy));
    335317                        _log.debug(prefix()+"h(x+y)="+Base64.encode(hxy));
    336318                        _log.debug(prefix() + "tsb = " + _tsB);
     
    365347                _state == State.IB_GOT_RI) && src.hasRemaining()) {
    366348
    367                 //if (_log.shouldLog(Log.DEBUG))
    368                 //    _log.debug(prefix()+"Encrypted bytes available (" + src.hasRemaining() + ")");
    369349                // Collect a 16-byte block
    370350                while (_curEncryptedOffset < AES_SIZE && src.hasRemaining()) {
     
    376356                    _context.aes().decrypt(_curEncrypted, 0, _curDecrypted, 0, _dh.getSessionKey(),
    377357                                           _prevEncrypted, 0, AES_SIZE);
    378                     //if (_log.shouldLog(Log.DEBUG))
    379                     //    _log.debug(prefix() + "full block read and decrypted: ");
    380358
    381359                    byte swap[] = _prevEncrypted;
     
    407385                        if (_log.shouldLog(Log.ERROR)) _log.error(prefix()+"Error writing to the baos?", ioe);
    408386                    }
    409                     //if (_log.shouldLog(Log.DEBUG))
    410                     //    _log.debug(prefix()+"subsequent block decrypted (" + _sz_aliceIdent_tsA_padding_aliceSig.size() + ")");
    411387
    412388                    if (_state == State.IB_GOT_RI_SIZE &&
     
    488464            byte c = src.get();
    489465            _Y[_received++] = c;
    490             //if (_log.shouldLog(Log.DEBUG)) _log.debug("recv x" + (int)c + " received=" + _received);
    491466            if (_received >= XY_SIZE) {
    492467                try {
     
    511486            byte c = src.get();
    512487            _e_hXY_tsB[i] = c;
    513             //if (_log.shouldLog(Log.DEBUG))
    514             //    _log.debug(prefix() + "recv _e_hXY_tsB " + (int)c + " received=" + _received);
    515488            if (i+1 >= HXY_TSB_PAD_SIZE) {
    516489                if (_log.shouldLog(Log.DEBUG)) _log.debug(prefix() + "received _e_hXY_tsB fully");
     
    522495                byte[] h = SimpleByteCache.acquire(HXY_SIZE);
    523496                _context.sha().calculateHash(XY, 0, XY_SIZE + XY_SIZE, h, 0);
    524                 //if (_log.shouldLog(Log.DEBUG))
    525                 //    _log.debug(prefix() + "h(XY)=" + h.toBase64());
    526497                if (!DataHelper.eq(h, 0, hXY_tsB, 0, HXY_SIZE)) {
    527498                    SimpleByteCache.release(h);
     
    577548                DataHelper.toLong(preSign, XY_SIZE + XY_SIZE + HXY_SIZE + 4, 4, _tsB);
    578549                // hXY_tsB has 12 bytes of padding (size=48, tsB=4 + hXY=32)
    579                 //System.arraycopy(hXY_tsB, hXY_tsB.length-12, preSign, _X.length+_Y.length+Hash.HASH_LENGTH+4+4, 12);
    580                 //byte sigPad[] = new byte[padSig];
    581                 //_context.random().nextBytes(sigPad);
    582                 //System.arraycopy(sigPad, 0, preSign, _X.length+_Y.length+Hash.HASH_LENGTH+4+4, padSig);
    583550                Signature sig = _context.dsa().sign(preSign, _context.keyManager().getSigningPrivateKey());
    584 
    585                 //if (_log.shouldLog(Log.DEBUG)) {
    586                 //    _log.debug(prefix()+"signing " + Base64.encode(preSign));
    587                 //}
    588551
    589552                byte ident[] = _context.router().getRouterInfo().getIdentity().toByteArray();
     
    606569                                       _hX_xor_bobIdentHash, _hX_xor_bobIdentHash.length-AES_SIZE, preEncrypt.length);
    607570
    608                 //if (_log.shouldLog(Log.DEBUG)) {
    609                     //_log.debug(prefix() + "unencrypted response to Bob: " + Base64.encode(preEncrypt));
    610                     //_log.debug(prefix() + "encrypted response to Bob: " + Base64.encode(_prevEncrypted));
    611                 //}
    612                 // send 'er off (when the bw limiter says, etc)
    613571                changeState(State.OB_SENT_RI);
    614572                _transport.getPumper().wantsWrite(_con, _prevEncrypted);
     
    642600            }
    643601            while (_state == State.OB_SENT_RI && src.hasRemaining()) {
    644                 //if (_log.shouldLog(Log.DEBUG)) _log.debug(prefix()+"recv bobSig received=" + _received);
    645602                _e_bobSig[off++] = src.get();
    646603                _received++;
     
    648605                if (off >= _e_bobSig.length) {
    649606                    changeState(State.OB_GOT_SIG);
    650                     //if (_log.shouldLog(Log.DEBUG))
    651                     //    _log.debug(prefix() + "received E(S(X+Y+Alice.identHash+tsA+tsB)+padding, sk, prev): " + Base64.encode(_e_bobSig));
    652607                    byte bobSig[] = new byte[_e_bobSig.length];
    653608                    _context.aes().decrypt(_e_bobSig, 0, bobSig, 0, _dh.getSessionKey(),
     
    760715    private void readAliceRouterIdentity() {
    761716        byte b[] = _sz_aliceIdent_tsA_padding_aliceSig.toByteArray();
    762         //if (_log.shouldLog(Log.DEBUG))
    763         //    _log.debug(prefix()+"decrypted sz(etc) data: " + Base64.encode(b));
    764717
    765718        try {
     
    826779
    827780            byte toVerify[] = baos.toByteArray();
    828             //if (_log.shouldLog(Log.DEBUG)) {
    829             //    _log.debug(prefix()+"checking " + Base64.encode(toVerify, 0, AES_SIZE));
    830             //    //_log.debug(prefix()+"check pad " + Base64.encode(b, 2+sz+4, 12));
    831             //}
    832781
    833782            // handle variable signature size
     
    10541003
    10551004    /**
    1056      * a check info connection will receive 256 bytes containing:
    1057      * - 32 bytes of uninterpreted, ignored data
    1058      * - 1 byte size
    1059      * - that many bytes making up the local router's IP address (as reached by the remote side)
    1060      * - 2 byte port number that the local router was reached on
    1061      * - 4 byte i2p network time as known by the remote side (seconds since the epoch)
    1062      * - uninterpreted padding data, up to byte 223
    1063      * - xor of the local router's identity hash and the SHA256 of bytes 32 through bytes 223
    1064      *
    1065      * @return should always be false since nobody ever sends a check info message
    1066      *
    1067      */
    1068 /*****
    1069     private static boolean isCheckInfo(I2PAppContext ctx, Hash us, byte first256[]) {
    1070         Log log = ctx.logManager().getLog(EstablishState.class);
    1071         int off = 32; // ignore the first 32 bytes
    1072 
    1073         byte[] xor = SimpleByteCache.acquire(Hash.HASH_LENGTH);
    1074         ctx.sha().calculateHash(first256, off, first256.length-32-off, xor, 0);
    1075         xor32(us.getData(), xor);
    1076         //if (log.shouldLog(Log.DEBUG))
    1077         //    log.debug("check hash: " + h.toBase64() + " xor: " + Base64.encode(xor));
    1078         if (DataHelper.eq(xor, 0, first256, first256.length-32, 32)) {
    1079             SimpleByteCache.release(xor);
    1080             // ok, data is as expected
    1081             // parse our IP/port/etc out of the first256
    1082             int ipSize = (int)DataHelper.fromLong(first256, off, 1);
    1083             off++;
    1084             byte ip[] = new byte[ipSize];
    1085             System.arraycopy(first256, off, ip, 0, ipSize);
    1086             try {
    1087                 InetAddress ourIP = InetAddress.getByAddress(ip);
    1088                 off += ipSize;
    1089                 int port = (int)DataHelper.fromLong(first256, off, 2);
    1090                 off += 2;
    1091                 long now = DataHelper.fromLong(first256, off, 4);
    1092                 off += 4;
    1093                 long skewSeconds = (ctx.clock().now()/1000)-now;
    1094                 if (log.shouldLog(Log.INFO))
    1095                     log.info("Check info received: our IP: " + ourIP + " our port: " + port
    1096                              + " skew: " + skewSeconds + " s");
    1097             } catch (UnknownHostException uhe) {
    1098                 // ipSize is invalid
    1099                 if (log.shouldLog(Log.WARN))
    1100                     log.warn("Invalid IP received on check connection (size: " + ipSize + ")");
    1101             }
    1102             return true;
    1103         } else {
    1104             SimpleByteCache.release(xor);
    1105             if (log.shouldLog(Log.DEBUG))
    1106                 log.debug("Not a checkInfo connection");
    1107             return false;
    1108         }
    1109     }
    1110 *****/
    1111 
    1112     /**
    11131005     *  @since 0.9.8
    11141006     */
     
    11451037        @Override public String toString() { return "FailedEstablishState: ";}
    11461038    }
    1147 
    1148     /** @deprecated unused */
    1149 /*********
    1150     public static void checkHost(String args[]) {
    1151         if (args.length != 3) {
    1152             System.err.println("Usage: EstablishState ipOrHostname portNum peerHashBase64");
    1153             return;
    1154         }
    1155         try {
    1156             I2PAppContext ctx = I2PAppContext.getGlobalContext();
    1157             String host = args[0];
    1158             int port = Integer.parseInt(args[1]);
    1159             byte peer[] = Base64.decode(args[2]);
    1160             Socket s = new Socket(host, port);
    1161             OutputStream out = s.getOutputStream();
    1162             byte toSend[] = new byte[256];
    1163             ctx.random().nextBytes(toSend);
    1164             int off = 32;
    1165             byte ip[] = s.getInetAddress().getAddress();
    1166             DataHelper.toLong(toSend, off, 1, ip.length);
    1167             off++;
    1168             System.arraycopy(ip, 0, toSend, off, ip.length);
    1169             off += ip.length;
    1170             DataHelper.toLong(toSend, off, 2, port);
    1171             off += 2;
    1172             long now = ctx.clock().now()/1000;
    1173             DataHelper.toLong(toSend, off, 4, now);
    1174             off += 4;
    1175             Hash h = ctx.sha().calculateHash(toSend, 32, toSend.length-32-32);
    1176             DataHelper.xor(peer, 0, h.getData(), 0, toSend, toSend.length-32, peer.length);
    1177             System.out.println("check hash: " + h.toBase64());
    1178 
    1179             out.write(toSend);
    1180             out.flush();
    1181             try { Thread.sleep(1000); } catch (InterruptedException ie) {}
    1182             s.close();
    1183         } catch (Exception e) {
    1184             e.printStackTrace();
    1185         }
    1186     }
    1187 *******/
    11881039
    11891040/*******
  • router/java/src/net/i2p/router/transport/ntcp/EventPumper.java

    r277a161 r278a814  
    182182
    183183                try {
    184                     //if (_log.shouldLog(Log.DEBUG))
    185                     //    _log.debug("before select...");
    186184                    int count = _selector.select(SELECTOR_LOOP_DELAY);
    187185                    if (count > 0) {
    188                         //if (_log.shouldLog(Log.DEBUG))
    189                         //    _log.debug("select returned " + count);
    190186                        Set<SelectionKey> selected = _selector.selectedKeys();
    191187                        //_context.statManager().addRateData("ntcp.pumperKeysPerLoop", selected.size());
     
    398394                }
    399395                if (read) {
    400                     //_context.statManager().addRateData("ntcp.read", 1, 0);
    401396                    processRead(key);
    402397                }
    403398                if (write) {
    404                     //_context.statManager().addRateData("ntcp.write", 1, 0);
    405399                    processWrite(key);
    406400                }
     
    430424            con.queuedWrite(buf, req);
    431425        } else {
    432             // fully allocated
    433             //if (_log.shouldLog(Log.INFO))
    434             //    _log.info("fully allocated write on " + con + " for " + data.length);
    435426            con.write(buf);
    436427        }
     
    476467                rv = ByteBuffer.allocate(BUF_SIZE);
    477468            _numBufs++;
    478             //if (_log.shouldLog(Log.DEBUG))
    479             //    _log.debug("creating a new read buffer " + System.identityHashCode(rv) + " with " + __liveBufs + " live: " + rv);           
    480             //_context.statManager().addRateData("ntcp.liveReadBufs", NUM_BUFS, 0);
    481         } else {
    482             //if (_log.shouldLog(Log.DEBUG))
    483             //    _log.debug("acquiring existing read buffer " + System.identityHashCode(rv) + " with " + __liveBufs + " live: " + rv);
    484469        }
    485470        return rv;
     
    492477     */
    493478    public static void releaseBuf(ByteBuffer buf) {
    494         //if (false) return;
    495         //if (_log.shouldLog(Log.DEBUG))
    496         //    _log.debug("releasing read buffer " + System.identityHashCode(buf) + " with " + __liveBufs + " live: " + buf);
    497 
    498479        // double check
    499480        if (buf.capacity() < BUF_SIZE) {
     
    517498            }
    518499        }
    519         //if (cached && _log.shouldLog(Log.DEBUG))
    520         //    _log.debug("read buffer " + System.identityHashCode(buf) + " cached with " + __liveBufs + " live");
    521500    }
    522501   
    523502    private void processAccept(SelectionKey key) {
    524         //if (_log.shouldLog(Log.DEBUG))
    525         //    _log.debug("processing accept");
    526503        ServerSocketChannel servChan = (ServerSocketChannel)key.attachment();
    527504        try {
     
    543520                if (_log.shouldLog(Log.WARN))
    544521                    _log.warn("Receive session request from blocklisted IP: " + chan.socket().getInetAddress());
    545                 // need to add this stat first
    546                 // _context.statManager().addRateData("ntcp.connectBlocklisted", 1, 0);
    547522                try { chan.close(); } catch (IOException ioe) { }
    548523                return;
     
    560535            }
    561536
    562             // BUGFIX for firewalls. --Sponge
    563537            if (shouldSetKeepAlive(chan))
    564538                chan.socket().setKeepAlive(true);
     
    566540            SelectionKey ckey = chan.register(_selector, SelectionKey.OP_READ);
    567541            new NTCPConnection(_context, _transport, chan, ckey);
    568             //if (_log.shouldLog(Log.DEBUG))
    569             //    _log.debug("new NTCP connection established: " +con);
    570542        } catch (IOException ioe) {
    571543            _log.error("Error accepting", ioe);
     
    581553                _log.debug("processing connect for " + con + ": connected? " + connected);
    582554            if (connected) {
    583                 // BUGFIX for firewalls. --Sponge
    584555                if (shouldSetKeepAlive(chan))
    585556                    chan.socket().setKeepAlive(true);
     
    596567                _log.info("Failed outbound " + con, ioe);
    597568            con.closeOnTimeout("connect failed", ioe);
    598             //_context.banlist().banlistRouter(con.getRemotePeer().calculateHash(), "Error connecting", NTCPTransport.STYLE);
    599569            _transport.markUnreachable(con.getRemotePeer().calculateHash());
    600570            _context.statManager().addRateData("ntcp.connectFailedTimeoutIOE", 1);
     
    631601            int read = con.getChannel().read(buf);
    632602            if (read < 0) {
    633                 //_context.statManager().addRateData("ntcp.readEOF", 1);
    634603                if (con.isInbound() && con.getMessagesReceived() <= 0) {
    635604                    InetAddress addr = con.getChannel().socket().getInetAddress();
     
    654623                releaseBuf(buf);
    655624            } else if (read == 0) {
    656                 //if (_log.shouldLog(Log.DEBUG))
    657                 //    _log.debug("nothing to read for " + con + ", but stay interested");
    658625                // stay interested
    659626                //key.interestOps(key.interestOps() | SelectionKey.OP_READ);
     
    680647                    // rare since we generally don't throttle inbound
    681648                    key.interestOps(key.interestOps() & ~SelectionKey.OP_READ);
    682                     //if (_log.shouldLog(Log.DEBUG))
    683                     //    _log.debug("bw throttled reading for " + con + ", so we don't want to read anymore");
    684649                    _context.statManager().addRateData("ntcp.queuedRecv", read);
    685650                    con.queuedRecv(buf, req);
    686651                } else {
    687                     // fully allocated
    688                     //if (_log.shouldLog(Log.DEBUG))
    689                     //    _log.debug("not bw throttled reading for " + con);
    690652                    // stay interested
    691653                    //key.interestOps(key.interestOps() | SelectionKey.OP_READ);
     
    748710     */
    749711    private void processWrite(SelectionKey key) {
    750         //int totalWritten = 0;
    751         //int buffers = 0;
    752         //long before = System.currentTimeMillis();
    753712        NTCPConnection con = (NTCPConnection)key.attachment();
    754713        try {
     
    756715                ByteBuffer buf = con.getNextWriteBuf();
    757716                if (buf != null) {
    758                     //if (_log.shouldLog(Log.DEBUG))
    759                     //    _log.debug("writing " + buf.remaining()+"...");
    760717                    if (buf.remaining() <= 0) {
    761                         //long beforeRem = System.currentTimeMillis();
    762718                        con.removeWriteBuf(buf);
    763                         //long afterRem = System.currentTimeMillis();
    764                         //if (_log.shouldLog(Log.DEBUG))
    765                         //    _log.debug("buffer was already fully written and removed after " + (afterRem-beforeRem) + "...");
    766                         //buffers++;
    767719                        continue;                   
    768720                    }
     
    771723                    if (written == 0) {
    772724                        if ( (buf.remaining() > 0) || (!con.isWriteBufEmpty()) ) {
    773                             //if (_log.shouldLog(Log.DEBUG)) _log.debug("done writing, but data remains...");
    774725                            // stay interested
    775726                            //key.interestOps(key.interestOps() | SelectionKey.OP_WRITE);
    776727                        } else {
    777                             //if (_log.shouldLog(Log.DEBUG)) _log.debug("done writing, no data remains...");
    778728                            key.interestOps(key.interestOps() & ~SelectionKey.OP_WRITE);
    779729                        }
    780730                        break;
    781731                    } else if (buf.remaining() > 0) {
    782                         //if (_log.shouldLog(Log.DEBUG)) _log.debug("buffer data remaining...");
    783732                        // stay interested
    784733                        //key.interestOps(key.interestOps() | SelectionKey.OP_WRITE);
    785734                        break;
    786735                    } else {
    787                         //long beforeRem = System.currentTimeMillis();
    788736                        con.removeWriteBuf(buf);
    789                         //long afterRem = System.currentTimeMillis();
    790                         //if (_log.shouldLog(Log.DEBUG))
    791                         //    _log.debug("buffer "+ buffers+"/"+written+"/"+totalWritten+" fully written after " +
    792                         //               (beforeRem-before) + ", then removed after " + (afterRem-beforeRem) + "...");
    793                         //releaseBuf(buf);
    794                         //buffers++;
    795737                        //if (buffer time is too much, add OP_WRITe to the interest ops and break?)
    796738                        // LOOP
     
    812754            con.close();
    813755        }
    814         //long after = System.currentTimeMillis();
    815         //if (_log.shouldLog(Log.INFO))
    816         //    _log.info("Wrote " + totalWritten + " in " + buffers + " buffers on " + con
    817         //              + " after " + (after-before));
    818756    }
    819757   
     
    901839                    if (connected) {
    902840                        // Never happens, we use nonblocking
    903                         //_context.statManager().addRateData("ntcp.connectImmediate", 1);
    904841                        key.interestOps(SelectionKey.OP_READ);
    905842                        processConnect(key);
     
    910847                    _context.statManager().addRateData("ntcp.connectFailedIOE", 1);
    911848                    _transport.markUnreachable(con.getRemotePeer().calculateHash());
    912                     //if (ntcpOnly(con)) {
    913                     //    _context.banlist().banlistRouter(con.getRemotePeer().calculateHash(), "unable to connect: " + ioe.getMessage());
    914                     //    con.close(false);
    915                     //} else {
    916                     //    _context.banlist().banlistRouter(con.getRemotePeer().calculateHash(), "unable to connect: " + ioe.getMessage(), NTCPTransport.STYLE);
    917                         con.close(true);
    918                     //}
     849                    con.close(true);
    919850                } catch (UnresolvedAddressException uae) {                   
    920851                    if (_log.shouldLog(Log.WARN)) _log.warn("unresolved address connecting", uae);
    921852                    _context.statManager().addRateData("ntcp.connectFailedUnresolved", 1);
    922853                    _transport.markUnreachable(con.getRemotePeer().calculateHash());
    923                     //if (ntcpOnly(con)) {
    924                     //    _context.banlist().banlistRouter(con.getRemotePeer().calculateHash(), "unable to connect/resolve: " + uae.getMessage());
    925                     //    con.close(false);
    926                     //} else {
    927                     //    _context.banlist().banlistRouter(con.getRemotePeer().calculateHash(), "unable to connect/resolve: " + uae.getMessage(), NTCPTransport.STYLE);
    928                         con.close(true);
    929                     //}
     854                    con.close(true);
    930855                } catch (CancelledKeyException cke) {
    931856                    con.close(false);
     
    942867        }
    943868    }
    944    
    945     /**
    946      * If the other peer only supports ntcp, we should banlist them when we can't reach 'em,
    947      * but if they support other transports (eg ssu) we should allow those transports to be
    948      * tried as well.
    949      */
    950 /****
    951     private boolean ntcpOnly(NTCPConnection con) {
    952         RouterIdentity ident = con.getRemotePeer();
    953         if (ident == null) return true;
    954         RouterInfo info = _context.netDb().lookupRouterInfoLocally(ident.calculateHash());
    955         if (info == null) return true;
    956         return info.getAddresses().size() == 1;
    957     }
    958 ****/
    959    
     869
    960870    private long _lastExpired;
    961871
  • router/java/src/net/i2p/router/transport/ntcp/NTCPConnection.java

    r277a161 r278a814  
    306306        _prevWriteEnd = prevWriteEnd;
    307307        System.arraycopy(prevReadEnd, prevReadEnd.length - BLOCK_SIZE, _prevReadBlock, 0, BLOCK_SIZE);
    308         //if (_log.shouldLog(Log.DEBUG))
    309         //    _log.debug("Inbound established, prevWriteEnd: " + Base64.encode(prevWriteEnd) + " prevReadEnd: " + Base64.encode(prevReadEnd));
    310308        _establishedOn = _context.clock().now();
    311309        NTCPConnection rv = _transport.inboundEstablished(this);
     
    469467     */
    470468    public void send(OutNetMessage msg) {
    471      /****
    472        always enqueue, let the queue do the dropping
    473 
    474         if (tooBacklogged()) {
    475             boolean allowRequeue = false; // if we are too backlogged in tcp, don't try ssu
    476             boolean successful = false;
    477             _consecutiveBacklog++;
    478             _transport.afterSend(msg, successful, allowRequeue, msg.getLifetime());
    479             if (_consecutiveBacklog > 10) { // waaay too backlogged
    480                 boolean wantsWrite = false;
    481                 try { wantsWrite = ( (_conKey.interestOps() & SelectionKey.OP_WRITE) != 0); } catch (RuntimeException e) {}
    482                 if (_log.shouldLog(Log.WARN)) {
    483                     int blocks = _writeBufs.size();
    484                     _log.warn("Too backlogged for too long (" + _consecutiveBacklog + " messages for " + DataHelper.formatDuration(queueTime()) + ", sched? " + wantsWrite + ", blocks: " + blocks + ") sending to " + _remotePeer.calculateHash());
    485                 }
    486                 _context.statManager().addRateData("ntcp.closeOnBacklog", getUptime());
    487                 close();
    488             }
    489             _context.statManager().addRateData("ntcp.dontSendOnBacklog", _consecutiveBacklog);
    490             return;
    491         }
    492         _consecutiveBacklog = 0;
    493      ****/
    494         //if (FAST_LARGE)
    495469        _outbound.offer(msg);
    496         //int enqueued = _outbound.size();
    497         // although stat description says ahead of this one, not including this one...
    498         //_context.statManager().addRateData("ntcp.sendQueueSize", enqueued);
    499470        boolean noOutbound = (getCurrentOutbound() == null);
    500         //if (_log.shouldLog(Log.DEBUG)) _log.debug("messages enqueued on " + toString() + ": " + enqueued + " new one: " + msg.getMessageId() + " of " + msg.getMessageType());
    501471        if (isEstablished() && noOutbound)
    502472            _transport.getWriter().wantsWrite(this, "enqueued");
    503473    }
    504 
    505 /****
    506     private long queueTime() {   
    507         OutNetMessage msg = _currentOutbound;
    508         if (msg == null) {
    509             msg = _outbound.peek();
    510             if (msg == null)
    511                 return 0;
    512         }
    513         return msg.getSendTime(); // does not include any of the pre-send(...) preparation
    514     }
    515 ****/
    516474
    517475    public boolean isBacklogged() { return _outbound.isBacklogged(); }
    518476     
    519477    public boolean tooBacklogged() {
    520         //long queueTime = queueTime();
    521         //if (queueTime <= 0) return false;
    522        
    523478        // perhaps we could take into account the size of the queued messages too, our
    524479        // current transmission rate, and how much time is left before the new message's expiration?
     
    526481        if (getUptime() < 10*1000) // allow some slack just after establishment
    527482            return false;
    528         //if (queueTime > 5*1000) { // bloody arbitrary.  well, its half the average message lifetime...
    529483        if (_outbound.isBacklogged()) { // bloody arbitrary.  well, its half the average message lifetime...
    530484            int size = _outbound.size();
     
    539493                } catch (RuntimeException e) {}  // java.nio.channels.CancelledKeyException
    540494            }
    541             //_context.statManager().addRateData("ntcp.sendBacklogTime", queueTime);
    542495            return true;
    543         //} else if (size > 32) { // another arbitrary limit.
    544         //    if (_log.shouldLog(Log.ERROR))
    545         //        _log.error("Too backlogged: queue size is " + size + " and the lifetime of the head is " + queueTime);
    546         //    return true;
    547496        } else {
    548497            return false;
     
    555504    public void enqueueInfoMessage() {
    556505        int priority = INFO_PRIORITY;
    557         //if (!_isInbound) {
    558             // Workaround for bug at Bob's end.
    559             // This probably isn't helpful because Bob puts the store on the job queue.
    560             // Prior to 0.9.12, Bob would only send his RI if he had our RI after
    561             // the first received message, so make sure it is first in our queue.
    562             // As of 0.9.12 this is fixed and Bob will always send his RI.
    563         //    RouterInfo target = _context.netDb().lookupRouterInfoLocally(_remotePeer.calculateHash());
    564         //    if (target != null) {
    565         //        String v = target.getOption("router.version");
    566         //        if (v == null || VersionComparator.comp(v, FIXED_RI_VERSION) < 0) {
    567         //            priority = OutNetMessage.PRIORITY_HIGHEST;
    568         //        }
    569         //    } else {
    570         //        priority = OutNetMessage.PRIORITY_HIGHEST;
    571         //    }
    572         //}
    573506        if (_log.shouldLog(Log.INFO))
    574507            _log.info("SENDING INFO message pri. " + priority + ": " + toString());
     
    578511        OutNetMessage infoMsg = new OutNetMessage(_context, dsm, _context.clock().now()+10*1000, priority, null);
    579512        infoMsg.beginSend();
    580         //_context.statManager().addRateData("ntcp.infoMessageEnqueued", 1);
    581513        send(infoMsg);
    582514    }
    583515
    584     //private static final int PEERS_TO_FLOOD = 3;
    585 
    586     /**
    587      * to prevent people from losing track of the floodfill peers completely, lets periodically
    588      * send those we are connected to references to the floodfill peers that we know
    589      *
    590      * Do we really need this anymore??? Peers shouldn't lose track anymore, and if they do,
    591      * FloodOnlyLookupJob should recover.
    592      * The bandwidth isn't so much, but it is a lot of extra data at connection startup, which
    593      * hurts latency of new connections.
    594      */
    595 /**********
    596     private void enqueueFloodfillMessage(RouterInfo target) {
    597         FloodfillNetworkDatabaseFacade fac = (FloodfillNetworkDatabaseFacade)_context.netDb();
    598         List peers = fac.getFloodfillPeers();
    599         Collections.shuffle(peers);
    600         for (int i = 0; i < peers.size() && i < PEERS_TO_FLOOD; i++) {
    601             Hash peer = (Hash)peers.get(i);
    602            
    603             // we already sent our own info, and no need to tell them about themselves
    604             if (peer.equals(_context.routerHash()) || peer.equals(target.calculateHash()))
    605                 continue;
    606            
    607             RouterInfo info = fac.lookupRouterInfoLocally(peer);
    608             if (info == null)
    609                 continue;
    610 
    611             OutNetMessage infoMsg = new OutNetMessage(_context);
    612             infoMsg.setExpiration(_context.clock().now()+10*1000);
    613             DatabaseStoreMessage dsm = new DatabaseStoreMessage(_context);
    614             dsm.setKey(peer);
    615             dsm.setRouterInfo(info);
    616             infoMsg.setMessage(dsm);
    617             infoMsg.setPriority(100);
    618             infoMsg.setTarget(target);
    619             infoMsg.beginSend();
    620             _context.statManager().addRateData("ntcp.floodInfoMessageEnqueued", 1, 0);
    621             send(infoMsg);
    622         }
    623     }
    624 ***********/
    625    
    626516    /**
    627517     * We are Alice.
     
    645535        _establishState = EstablishState.VERIFIED;
    646536        _transport.markReachable(getRemotePeer().calculateHash(), false);
    647         //_context.banlist().unbanlistRouter(getRemotePeer().calculateHash(), NTCPTransport.STYLE);
    648537        boolean msgs = !_outbound.isEmpty();
    649538        _nextMetaTime = _establishedOn + (META_FREQUENCY / 2) + _context.random().nextInt(META_FREQUENCY);
     
    654543   
    655544    /**
    656     // Time vs space tradeoff:
    657     // on slow GCing jvms, the mallocs in the following preparation can cause the
    658     // write to get congested, taking up a substantial portion of the Writer's
    659     // time (and hence, slowing down the transmission to the peer).  we could
    660     // however do the preparation (up to but not including the aes.encrypt)
    661     // as part of the .send(OutNetMessage) above, which runs on less congested
    662     // threads (whatever calls OutNetMessagePool.add, which can be the jobqueue,
    663     // tunnel builders, simpletimers, etc).  that would increase the Writer's
    664     // efficiency (speeding up the transmission to the peer) but would require
    665     // more memory to hold the serialized preparations of all queued messages, not
    666     // just the currently transmitting one.
    667     //
    668     // hmm.
    669      */
    670     private static final boolean FAST_LARGE = true; // otherwise, SLOW_SMALL
    671    
    672     /**
    673545     * prepare the next i2np message for transmission.  this should be run from
    674546     * the Writer thread pool.
     
    678550     */
    679551    synchronized void prepareNextWrite(PrepBuffer prep) {
    680         //if (FAST_LARGE)
    681552            prepareNextWriteFast(prep);
    682         //else
    683         //    prepareNextWriteSmall();
    684     }
    685 
    686 /**********  nobody's tried this one in years
    687     private void prepareNextWriteSmall() {
    688         if (_log.shouldLog(Log.DEBUG))
    689             _log.debug("prepare next write w/ isInbound? " + _isInbound + " established? " + _established);
    690         if (!_isInbound && !_established) {
    691             if (_establishState == null) {
    692                 _establishState = new EstablishState(_context, _transport, this);
    693                 _establishState.prepareOutbound();
    694             } else {
    695                 if (_log.shouldLog(Log.DEBUG))
    696                     _log.debug("prepare next write, but we have already prepared the first outbound and we are not yet established..." + toString());
    697             }
    698             return;
    699         }
    700        
    701         if (_nextMetaTime <= System.currentTimeMillis()) {
    702             sendMeta();
    703             _nextMetaTime = System.currentTimeMillis() + _context.random().nextInt(META_FREQUENCY);
    704         }
    705      
    706         OutNetMessage msg = null;
    707         synchronized (_outbound) {
    708             if (_currentOutbound != null) {
    709                 if (_log.shouldLog(Log.WARN))
    710                     _log.warn("attempt for multiple outbound messages with " + System.identityHashCode(_currentOutbound) + " already waiting and " + _outbound.size() + " queued");
    711                 return;
    712             }
    713                 //throw new RuntimeException("We should not be preparing a write while we still have one pending");
    714             if (!_outbound.isEmpty()) {
    715                 msg = (OutNetMessage)_outbound.remove(0);
    716                 _currentOutbound = msg;
    717             } else {
    718                 return;
    719             }
    720         }
    721        
    722         msg.beginTransmission();
    723         msg.beginPrepare();
    724         long begin = System.currentTimeMillis();
    725         // prepare the message as a binary array, then encrypt it w/ a checksum
    726         // and add it to the _writeBufs
    727         // E(sizeof(data)+data+pad+crc, sessionKey, prevEncrypted)
    728         I2NPMessage m = msg.getMessage();
    729         int sz = m.getMessageSize();
    730         int min = 2 + sz + 4;
    731         int rem = min % 16;
    732         int padding = 0;
    733         if (rem > 0)
    734             padding = 16 - rem;
    735        
    736         byte unencrypted[] = new byte[min+padding];
    737         byte base[] = m.toByteArray();
    738         DataHelper.toLong(unencrypted, 0, 2, sz);
    739         System.arraycopy(base, 0, unencrypted, 2, base.length);
    740         if (padding > 0) {
    741             byte pad[] = new byte[padding];
    742             _context.random().nextBytes(pad);
    743             System.arraycopy(pad, 0, unencrypted, 2+sz, padding);
    744         }
    745 
    746         long serialized = System.currentTimeMillis();
    747         Adler32 crc = new Adler32();
    748         crc.reset();
    749         crc.update(unencrypted, 0, unencrypted.length-4);
    750         long val = crc.getValue();
    751         DataHelper.toLong(unencrypted, unencrypted.length-4, 4, val);
    752        
    753         if (_log.shouldLog(Log.DEBUG))
    754             _log.debug("Outbound message " + _messagesWritten + " has crc " + val);
    755        
    756         long crced = System.currentTimeMillis();
    757         byte encrypted[] = new byte[unencrypted.length];
    758         _context.aes().encrypt(unencrypted, 0, encrypted, 0, _sessionKey, _prevWriteEnd, 0, unencrypted.length);
    759         System.arraycopy(encrypted, encrypted.length-16, _prevWriteEnd, 0, _prevWriteEnd.length);
    760         long encryptedTime = System.currentTimeMillis();
    761         msg.prepared();
    762         if (_log.shouldLog(Log.DEBUG)) {
    763             _log.debug("prepared outbound " + System.identityHashCode(msg)
    764                        + " serialize=" + (serialized-begin)
    765                        + " crc=" + (crced-serialized)
    766                        + " encrypted=" + (encryptedTime-crced)
    767                        + " prepared=" + (encryptedTime-begin));
    768         }
    769         //if (_log.shouldLog(Log.DEBUG))
    770         //    _log.debug("Encrypting " + msg + " [" + System.identityHashCode(msg) + "] crc=" + crc.getValue() + "\nas: "
    771         //               + Base64.encode(encrypted, 0, 16) + "...\ndecrypted: "
    772         //               + Base64.encode(unencrypted, 0, 16) + "..." + "\nIV=" + Base64.encode(_prevWriteEnd, 0, 16));
    773         _transport.getPumper().wantsWrite(this, encrypted);
    774 
    775         // for every 6-12 hours that we are connected to a peer, send them
    776         // our updated netDb info (they may not accept it and instead query
    777         // the floodfill netDb servers, but they may...)
    778         if (_nextInfoTime <= System.currentTimeMillis()) {
    779             enqueueInfoMessage();
    780             _nextInfoTime = System.currentTimeMillis() + (INFO_FREQUENCY / 2) + _context.random().nextInt(INFO_FREQUENCY);
    781         }
    782     }
    783 **********/
    784    
     553    }
     554
    785555    /**
    786556     * prepare the next i2np message for transmission.  this should be run from
     
    817587                return;
    818588            }
    819 /****
    820                 //throw new RuntimeException("We should not be preparing a write while we still have one pending");
    821             if (queueTime() > 3*1000) {  // don't stall low-priority messages
    822 ****/
    823589                msg = _outbound.poll();
    824590                if (msg == null)
    825591                    return;
    826 /****
    827             } else {
    828                 // FIXME
    829                 // This is a linear search to implement a priority queue, O(n**2)
    830                 // Also race with unsynchronized removal in close() above
    831                 // Either implement a real (concurrent?) priority queue or just comment out all of this,
    832                 // as it isn't clear how effective the priorities on a per-connection basis are.
    833                 int slot = 0;  // only for logging
    834                 Iterator<OutNetMessage> it = _outbound.iterator();
    835                 for (int i = 0; it.hasNext() && i < 75; i++) {  //arbitrary bound
    836                     OutNetMessage mmsg = it.next();
    837                     if (msg == null || mmsg.getPriority() > msg.getPriority()) {
    838                         msg = mmsg;
    839                         slot = i;
    840                     }
    841                 }
    842                 if (msg == null)
    843                     return;
    844                 // if (_outbound.indexOf(msg) > 0)
    845                 //     _log.debug("Priority message sent, pri = " + msg.getPriority() + " pos = " + _outbound.indexOf(msg) + "/" +_outbound.size());
    846                 if (_log.shouldLog(Log.INFO))
    847                     _log.info("Type " + msg.getMessage().getType() + " pri " + msg.getPriority() + " slot " + slot);
    848                 boolean removed = _outbound.remove(msg);
    849                 if ((!removed) && _log.shouldLog(Log.WARN))
    850                     _log.warn("Already removed??? " + msg.getMessage().getType());
    851             }
    852 ****/
    853592            _currentOutbound = msg;
    854593        }
    855594       
    856         //long begin = System.currentTimeMillis();
    857595        bufferedPrepare(msg,buf);
    858596        _context.aes().encrypt(buf.unencrypted, 0, buf.encrypted, 0, _sessionKey, _prevWriteEnd, 0, buf.unencryptedLength);
    859597        System.arraycopy(buf.encrypted, buf.encrypted.length-16, _prevWriteEnd, 0, _prevWriteEnd.length);
    860         //long encryptedTime = System.currentTimeMillis();
    861         //if (_log.shouldLog(Log.DEBUG))
    862         //    _log.debug("Encrypting " + msg + " [" + System.identityHashCode(msg) + "] crc=" + crc.getValue() + "\nas: "
    863         //               + Base64.encode(encrypted, 0, 16) + "...\ndecrypted: "
    864         //               + Base64.encode(unencrypted, 0, 16) + "..." + "\nIV=" + Base64.encode(_prevWriteEnd, 0, 16));
    865598        _transport.getPumper().wantsWrite(this, buf.encrypted);
    866         //long wantsTime = System.currentTimeMillis();
    867         //long releaseTime = System.currentTimeMillis();
    868         //if (_log.shouldLog(Log.DEBUG))
    869         //    _log.debug("prepared outbound " + System.identityHashCode(msg)
    870         //               + " encrypted=" + (encryptedTime-begin)
    871         //               + " wantsWrite=" + (wantsTime-encryptedTime)
    872         //               + " releaseBuf=" + (releaseTime-wantsTime));
    873599
    874600        // for every 6-12 hours that we are connected to a peer, send them
     
    890616     */
    891617    private void bufferedPrepare(OutNetMessage msg, PrepBuffer buf) {
    892         //if (!_isInbound && !_established)
    893         //    return;
    894         //long begin = System.currentTimeMillis();
    895         //long alloc = System.currentTimeMillis();
    896        
    897618        I2NPMessage m = msg.getMessage();
    898619        buf.baseLength = m.toByteArray(buf.base);
    899620        int sz = buf.baseLength;
    900         //int sz = m.getMessageSize();
    901621        int min = 2 + sz + 4;
    902622        int rem = min % 16;
     
    912632        }
    913633       
    914         //long serialized = System.currentTimeMillis();
    915634        buf.crc.update(buf.unencrypted, 0, buf.unencryptedLength-4);
    916635       
     
    927646        // 4) in EventPumper.processWrite(), release the byte buffer
    928647        buf.encrypted = new byte[buf.unencryptedLength];
    929        
    930         //long crced = System.currentTimeMillis();
    931         //if (_log.shouldLog(Log.DEBUG))
    932         //    _log.debug("Buffered prepare took " + (crced-begin) + ", alloc=" + (alloc-begin)
    933         //               + " serialize=" + (serialized-alloc) + " crc=" + (crced-serialized));
    934648    }
    935649
     
    985699            // throttled anymore, so we should resume being interested in reading
    986700            _transport.getPumper().wantsRead(NTCPConnection.this);
    987             //_transport.getReader().wantsRead(this);
    988701        }
    989702    }
     
    1047760    public void recv(ByteBuffer buf) {
    1048761        _bytesReceived += buf.remaining();
    1049             //buf.flip();
    1050762        _readBufs.offer(buf);
    1051763        _transport.getReader().wantsRead(this);
     
    1058770     */
    1059771    public void write(ByteBuffer buf) {
    1060         //if (_log.shouldLog(Log.DEBUG)) _log.debug("Before write(buf)");
    1061772        _writeBufs.offer(buf);
    1062         //if (_log.shouldLog(Log.DEBUG)) _log.debug("After write(buf)");
    1063773        _transport.getPumper().wantsWrite(this);
    1064774    }
     
    1123833            _transport.getWriter().wantsWrite(this, "write completed");
    1124834
    1125         // this is not necessary, EventPumper.processWrite() handles this
    1126         // and it just causes unnecessary selector.wakeup() and looping
    1127         //boolean bufsRemain = !_writeBufs.isEmpty();
    1128         //if (bufsRemain) // send asap
    1129         //    _transport.getPumper().wantsWrite(this);
    1130 
    1131835        updateStats();
    1132836    }
     
    1140844    private float _sendBps;
    1141845    private float _recvBps;
    1142     //private float _sendBps15s;
    1143     //private float _recvBps15s;
    1144846   
    1145847    public float getSendRate() { return _sendBps; }
     
    1166868            _sendBps = (0.9f)*_sendBps + (0.1f)*(sent*1000f)/time;
    1167869            _recvBps = (0.9f)*_recvBps + (0.1f)*((float)recv*1000)/time;
    1168 
    1169             // Maintain an approximate average with a 15-second halflife
    1170             // Weights (0.955 and 0.045) are tuned so that transition between two values (e.g. 0..10)
    1171             // would reach their midpoint (e.g. 5) in 15s
    1172             //_sendBps15s = (0.955f)*_sendBps15s + (0.045f)*((float)sent*1000f)/(float)time;
    1173             //_recvBps15s = (0.955f)*_recvBps15s + (0.045f)*((float)recv*1000)/(float)time;
    1174 
    1175             //if (_log.shouldLog(Log.DEBUG))
    1176             //    _log.debug("Rates updated to "
    1177             //               + _sendBps + '/' + _recvBps + "Bps in/out "
    1178             //               //+ _sendBps15s + "/" + _recvBps15s + "Bps in/out 15s after "
    1179             //               + sent + '/' + recv + " in " + DataHelper.formatDuration(time));
    1180870        }
    1181871    }
     
    1195885     */
    1196886    synchronized void recvEncryptedI2NP(ByteBuffer buf) {
    1197         //if (_log.shouldLog(Log.DEBUG))
    1198         //    _log.debug("receive encrypted i2np: " + buf.remaining());
    1199887        // hasArray() is false for direct buffers, at least on my system...
    1200888        if (_curReadBlockIndex == 0 && buf.hasArray()) {
     
    1213901                _curReadBlockIndex += want;
    1214902            }
    1215             //_curReadBlock[_curReadBlockIndex++] = buf.get();
    1216903            if (_curReadBlockIndex >= BLOCK_SIZE) {
    1217904                // cbc
    1218905                _context.aes().decryptBlock(_curReadBlock, 0, _sessionKey, _decryptBlockBuf, 0);
    1219                 //DataHelper.xor(_decryptBlockBuf, 0, _prevReadBlock, 0, _decryptBlockBuf, 0, BLOCK_SIZE);
    1220906                for (int i = 0; i < BLOCK_SIZE; i++) {
    1221907                    _decryptBlockBuf[i] ^= _prevReadBlock[i];
    1222908                }
    1223                 //if (_log.shouldLog(Log.DEBUG))
    1224                 //    _log.debug("parse decrypted i2np block (remaining: " + buf.remaining() + ")");
    1225909                boolean ok = recvUnencryptedI2NP();
    1226910                if (!ok) {
     
    1259943            _context.aes().decryptBlock(array, pos, _sessionKey, _decryptBlockBuf, 0);
    1260944            if (first) {
    1261                 // XOR with _prevReadBlock the first time...
    1262                 //DataHelper.xor(_decryptBlockBuf, 0, _prevReadBlock, 0, _decryptBlockBuf, 0, BLOCK_SIZE);
    1263945                for (int i = 0; i < BLOCK_SIZE; i++) {
    1264946                    _decryptBlockBuf[i] ^= _prevReadBlock[i];
     
    1266948                first = false;
    1267949            } else {
    1268                 //DataHelper.xor(_decryptBlockBuf, 0, array, pos - BLOCK_SIZE, _decryptBlockBuf, 0, BLOCK_SIZE);
    1269950                int start = pos - BLOCK_SIZE;
    1270951                for (int i = 0; i < BLOCK_SIZE; i++) {
     
    13721053        _sendingMeta = true;
    13731054        _transport.getPumper().wantsWrite(this, encrypted);
    1374         // enqueueInfoMessage(); // this often?
    13751055    }
    13761056   
     
    13921072        _i2npHandlers.offer(handler);
    13931073    }
    1394    
    1395    
    1396     //public long getReadTime() { return _curReadState.getReadTime(); }
    13971074   
    13981075    private static ByteArray acquireReadBuf() {
     
    14691146            }
    14701147        }
    1471 
    1472      /****
    1473         public long getReadTime() {
    1474             long now = System.currentTimeMillis();
    1475             long readTime = now - _stateBegin;
    1476             if (readTime >= now)
    1477                 return -1;
    1478             else
    1479                 return readTime;
    1480         }
    1481       ****/
    14821148
    14831149        /** @param buf 16 bytes */
     
    15191185            } else {
    15201186                _crc.update(buf);
    1521                 //if (_log.shouldLog(Log.DEBUG))
    1522                 //    _log.debug("update read state with another block (remaining: " + remaining + ")");
    15231187            }
    15241188        }
     
    15261190        /** @param buf 16 bytes */
    15271191        private void receiveLastBlock(byte buf[]) {
    1528             //if (_log.shouldLog(Log.DEBUG))
    1529             //    _log.debug("block remaining in the last block: " + (buf.length-blockUsed));
    1530 
    15311192            // on the last block
    15321193            _expectedCrc = DataHelper.fromLong(buf, buf.length-4, 4);
    15331194            _crc.update(buf, 0, buf.length-4);
    15341195            long val = _crc.getValue();
    1535             //if (_log.shouldLog(Log.DEBUG))
    1536             //    _log.debug("CRC value computed: " + val + " expected: " + _expectedCrc + " size: " + _size);
    15371196            if (val == _expectedCrc) {
    15381197                try {
     
    15701229                    }
    15711230                    _context.statManager().addRateData("ntcp.corruptI2NPIME", 1);
    1572                     // Don't close the con, possible attack vector, not necessarily the peer's fault,
    1573                     // and should be recoverable
    1574                     // handler and databuf are lost if we do this
    1575                     //close();
    1576                     //return;
    15771231                }
    15781232            } else {
     
    15801234                    _log.warn("CRC incorrect for message " + _messagesRead + " (calc=" + val + " expected=" + _expectedCrc + ") size=" + _size + " blocks " + _blocks);
    15811235                    _context.statManager().addRateData("ntcp.corruptI2NPCRC", 1);
    1582                 // This probably can't be spoofed from somebody else, but do we really need to close it?
    1583                 // This is rare.
    1584                 //close();
    1585                 // databuf is lost if we do this
    1586                 //return;
    15871236            }
    15881237            // get it ready for the next I2NP message
Note: See TracChangeset for help on using the changeset viewer.