Changes in / [75a8d8f:b5df13d]


Ignore:
Files:
22 edited

Legend:

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

    r75a8d8f rb5df13d  
    222222                    String p = tok.nextToken().trim();
    223223                    if (p.length() > 0)
    224                         _proxyList.add(tok.nextToken().trim());
     224                        _proxyList.add(p);
    225225                }
    226226            }
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPServer.java

    r75a8d8f rb5df13d  
    55
    66import java.io.BufferedInputStream;
     7import java.io.EOFException;
    78import java.io.File;
    89import java.io.IOException;
     
    1213import java.net.Socket;
    1314import java.net.SocketException;
     15import java.net.SocketTimeoutException;
    1416import java.util.ArrayList;
    1517import java.util.HashMap;
     
    6466    private static final String X_POWERED_BY_HEADER = "X-Powered-By";
    6567    private static final String[] SERVER_SKIPHEADERS = {SERVER_HEADER, X_POWERED_BY_HEADER};
     68    /** timeout for first request line */
    6669    private static final long HEADER_TIMEOUT = 15*1000;
     70    /** total timeout for the request and all the headers */
    6771    private static final long TOTAL_HEADER_TIMEOUT = 2 * HEADER_TIMEOUT;
    6872    private static final long START_INTERVAL = (60 * 1000) * 3;
     73    private static final int MAX_LINE_LENGTH = 8*1024;
    6974    private long _startedOn = 0L;
    7075    private ConnThrottler _postThrottler;
     
    236241            // The headers _should_ be in the first packet, but
    237242            // may not be, depending on the client-side options
    238             socket.setReadTimeout(HEADER_TIMEOUT);
    239 
    240             InputStream in = socket.getInputStream();
    241243
    242244            StringBuilder command = new StringBuilder(128);
    243             Map<String, List<String>> headers = readHeaders(in, command,
     245            Map<String, List<String>> headers = readHeaders(socket, null, command,
    244246                CLIENT_SKIPHEADERS, getTunnel().getContext());
    245247            long afterHeaders = getTunnel().getContext().clock().now();
     
    465467                //Change headers to protect server identity
    466468                StringBuilder command = new StringBuilder(128);
    467                 Map<String, List<String>> headers = readHeaders(serverin, command,
     469                Map<String, List<String>> headers = readHeaders(null, serverin, command,
    468470                    SERVER_SKIPHEADERS, _ctx);
    469471                String modifiedHeaders = formatHeaders(headers, command);
     
    701703    }
    702704
    703     protected static Map<String, List<String>> readHeaders(InputStream in, StringBuilder command,
     705    /**
     706     *  From I2P to server: socket non-null, in null.
     707     *  From server to I2P: socket null, in non-null.
     708     *
     709     *  @param socket if null, use in as InputStream
     710     *  @param in if null, use socket.getInputStream() as InputStream
     711     *  @param command out parameter, first line
     712     *  @param command out parameter, first line
     713     *  @throws SocketTimeoutException if timeout is reached before newline
     714     *  @throws EOFException if EOF is reached before newline
     715     *  @throws LineTooLongException if too long
     716     *  @throws IOException on other errors in the underlying stream
     717     */
     718    private static Map<String, List<String>> readHeaders(I2PSocket socket, InputStream in, StringBuilder command,
    704719                                                           String[] skipHeaders, I2PAppContext ctx) throws IOException {
    705720        HashMap<String, List<String>> headers = new HashMap<String, List<String>>();
     
    708723        // slowloris / darkloris
    709724        long expire = ctx.clock().now() + TOTAL_HEADER_TIMEOUT;
    710         boolean ok = DataHelper.readLine(in, command);
    711         if (!ok) throw new IOException("EOF reached while reading the HTTP command [" + command.toString() + "]");
     725        if (socket != null) {
     726            readLine(socket, command, HEADER_TIMEOUT);
     727        } else {
     728             boolean ok = DataHelper.readLine(in, command);
     729             if (!ok)
     730                 throw new IOException("EOF reached before the end of the headers [" + buf.toString() + "]");
     731        }
    712732       
    713733        //if (_log.shouldLog(Log.DEBUG))
     
    733753                throw new IOException("Too many header lines - max " + MAX_HEADERS);
    734754            buf.setLength(0);
    735             ok = DataHelper.readLine(in, buf);
    736             if (!ok) throw new IOException("EOF reached before the end of the headers [" + buf.toString() + "]");
     755            if (socket != null) {
     756                readLine(socket, buf, expire - ctx.clock().now());
     757            } else {
     758                 boolean ok = DataHelper.readLine(in, buf);
     759                 if (!ok)
     760                     throw new IOException("EOF reached before the end of the headers [" + buf.toString() + "]");
     761            }
    737762            if ( (buf.length() == 0) ||
    738763                 ((buf.charAt(0) == '\n') || (buf.charAt(0) == '\r')) ) {
     
    740765                return headers;
    741766            } else {
    742                 if (ctx.clock().now() > expire)
     767                if (ctx.clock().now() >= expire)
    743768                    throw new IOException("Headers took too long [" + buf.toString() + "]");
    744769                int split = buf.indexOf(":");
     
    782807        }
    783808    }
     809
     810    /**
     811     *  Read a line teriminated by newline, with a total read timeout.
     812     *
     813     *  Warning - strips \n but not \r
     814     *  Warning - 8KB line length limit as of 0.7.13, @throws IOException if exceeded
     815     *  Warning - not UTF-8
     816     *
     817     *  @param buf output
     818     *  @param timeout throws SocketTimeoutException immediately if zero or negative
     819     *  @throws SocketTimeoutException if timeout is reached before newline
     820     *  @throws EOFException if EOF is reached before newline
     821     *  @throws LineTooLongException if too long
     822     *  @throws IOException on other errors in the underlying stream
     823     *  @since 0.9.19 modified from DataHelper
     824     */
     825    private static void readLine(I2PSocket socket, StringBuilder buf, long timeout) throws IOException {
     826        if (timeout <= 0)
     827            throw new SocketTimeoutException();
     828        long expires = System.currentTimeMillis() + timeout;
     829        InputStream in = socket.getInputStream();
     830        int c;
     831        int i = 0;
     832        socket.setReadTimeout(timeout);
     833        while ( (c = in.read()) != -1) {
     834            if (++i > MAX_LINE_LENGTH)
     835                throw new LineTooLongException("Line too long - max " + MAX_LINE_LENGTH);
     836            if (c == '\n')
     837                break;
     838            long newTimeout = expires - System.currentTimeMillis();
     839            if (newTimeout <= 0)
     840                throw new SocketTimeoutException();
     841            buf.append((char)c);
     842            if (newTimeout != timeout) {
     843                timeout = newTimeout;
     844                socket.setReadTimeout(timeout);
     845            }
     846        }
     847        if (c == -1) {
     848            if (System.currentTimeMillis() >= expires)
     849                throw new SocketTimeoutException();
     850            else
     851                throw new EOFException();
     852        }
     853    }
     854
     855    /**
     856     *  @since 0.9.19
     857     */
     858    private static class LineTooLongException extends IOException {
     859        public LineTooLongException(String s) {
     860            super(s);
     861        }
     862    }
    784863}
    785864
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelController.java

    r75a8d8f rb5df13d  
    581581    public void stopTunnel() {
    582582        synchronized (this) {
    583             if (_state != TunnelState.RUNNING)
     583            if (_state != TunnelState.STARTING && _state != TunnelState.RUNNING)
    584584                return;
    585585            changeState(TunnelState.STOPPING);
  • apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketOptions.java

    r75a8d8f rb5df13d  
    3838     * What is the longest we'll block on the input stream while waiting
    3939     * for more data.  If this value is exceeded, the read() throws
    40      * InterruptedIOException
     40     * InterruptedIOException - FIXME doesn't really, returns -1 or 0 instead.
    4141     *
    4242     * WARNING: Default -1 (unlimited), which is probably not what you want.
    4343     *
    44      * @return timeout in ms
     44     * @return timeout in ms, 0 for nonblocking, -1 for forever
    4545     */
    4646    public long getReadTimeout();
     
    4949     * What is the longest we'll block on the input stream while waiting
    5050     * for more data.  If this value is exceeded, the read() throws
    51      * InterruptedIOException
     51     * InterruptedIOException - FIXME doesn't really, returns -1 or 0 instead.
    5252     *
    5353     * WARNING: Default -1 (unlimited), which is probably not what you want.
    5454     *
    55      * @param ms timeout in ms
     55     * @param ms timeout in ms, 0 for nonblocking, -1 for forever
    5656     */
    5757    public void setReadTimeout(long ms);
  • apps/routerconsole/jsp/configreseed.jsp

    r75a8d8f rb5df13d  
    3131<p><%=intl._("Enter zip or su3 URL")%> :
    3232<input name="url" type="text" size="60" value="" />
    33 <br><%=intl._("The su3 format is preferred, as it will be verifed as signed by a trusted source.")%>
     33<br><%=intl._("The su3 format is preferred, as it will be verified as signed by a trusted source.")%>
    3434<%=intl._("The zip format is unsigned; use a zip file only from a source that you trust.")%>
    3535</p>
     
    4444<p><%=intl._("Select zip or su3 file")%> :
    4545<input name="file" type="file" value="" />
    46 <br><%=intl._("The su3 format is preferred, as it will be verifed as signed by a trusted source.")%>
     46<br><%=intl._("The su3 format is preferred, as it will be verified as signed by a trusted source.")%>
    4747<%=intl._("The zip format is unsigned; use a zip file only from a source that you trust.")%>
    4848</p>
  • apps/streaming/java/src/net/i2p/client/streaming/impl/I2PSocketFull.java

    r75a8d8f rb5df13d  
    5252        Connection c = _connection;
    5353        if (c == null) return;
     54        if (log.shouldLog(Log.INFO))
     55            log.info("close() called, connected? " + c.getIsConnected() + " : " + c);
    5456        if (c.getIsConnected()) {
    5557            MessageInputStream in = c.getInputStream();
     
    137139        if (c == null) return;
    138140       
     141        if (ms > Integer.MAX_VALUE)
     142            ms = Integer.MAX_VALUE;
    139143        c.getInputStream().setReadTimeout((int)ms);
    140144        c.getOptions().setReadTimeout(ms);
  • apps/streaming/java/src/net/i2p/client/streaming/impl/I2PSocketOptionsImpl.java

    r75a8d8f rb5df13d  
    145145     * What is the longest we'll block on the input stream while waiting
    146146     * for more data.  If this value is exceeded, the read() throws
    147      * InterruptedIOException
     147     * InterruptedIOException - FIXME doesn't really, returns -1 or 0 instead.
    148148     *
    149149     * WARNING: Default -1 (unlimited), which is probably not what you want.
     150     *
     151     * @return timeout in ms, 0 for nonblocking, -1 for forever
    150152     */
    151153    public long getReadTimeout() {
     
    156158     * What is the longest we'll block on the input stream while waiting
    157159     * for more data.  If this value is exceeded, the read() throws
    158      * InterruptedIOException
     160     * InterruptedIOException - FIXME doesn't really, returns -1 or 0 instead.
    159161     *
    160162     * WARNING: Default -1 (unlimited), which is probably not what you want.
     163     *
     164     * @param ms timeout in ms, 0 for nonblocking, -1 for forever
    161165     */
    162166    public void setReadTimeout(long ms) {
  • apps/streaming/java/src/net/i2p/client/streaming/impl/MessageInputStream.java

    r75a8d8f rb5df13d  
    171171     * how long a read() call should block (if less than 0, block indefinitely,
    172172     * but if it is 0, do not block at all)
    173      * @return how long read calls should block, 0 or less indefinitely block
     173     * @return how long read calls should block, 0 for nonblocking, negative to indefinitely block
    174174     */
    175175    public int getReadTimeout() { return _readTimeout; }
    176176
     177    /**
     178     * how long a read() call should block (if less than 0, block indefinitely,
     179     * but if it is 0, do not block at all)
     180     * @param timeout how long read calls should block, 0 for nonblocking, negative to indefinitely block
     181     */
    177182    public void setReadTimeout(int timeout) {
    178183        if (_log.shouldLog(Log.DEBUG))
     
    231236    public boolean messageReceived(long messageId, ByteArray payload) {
    232237        if (_log.shouldLog(Log.DEBUG))
    233             _log.debug("received " + messageId + " with " + (payload != null ? payload.getValid()+"" : "no payload"));
     238            _log.debug("received msg ID " + messageId + " with " +
     239                       (payload != null ? payload.getValid() + " bytes" : "no payload"));
    234240        synchronized (_dataLock) {
    235241            if (messageId <= _highestReadyBlockId) {
     
    262268                    _highestReadyBlockId++;
    263269                }
     270                                        // FIXME Javadocs for setReadTimeout() say we will throw
     271                                        // an InterruptedIOException.
     272                                        // Java throws a SocketTimeoutException.
     273                                        // We do neither.
    264274            } else {
    265275                if (_log.shouldLog(Log.INFO))
     
    276286    }
    277287   
     288    /**
     289     *  On a read timeout, this returns -1
     290     *  (doesn't throw SocketTimeoutException like Socket)
     291     *  (doesn't throw InterruptedIOException like our javadocs say)
     292     */
    278293    public int read() throws IOException {
    279294        int read = read(_oneByte, 0, 1);
    280         if (read < 0)
     295        if (read <= 0)
    281296            return -1;
    282297        return _oneByte[0] & 0xff;
    283298    }
    284299   
     300    /**
     301     *  On a read timeout, this returns 0
     302     *  (doesn't throw SocketTimeoutException like Socket)
     303     *  (doesn't throw InterruptedIOException like our javadocs say)
     304     */
    285305    @Override
    286306    public int read(byte target[]) throws IOException {
     
    288308    }
    289309   
     310    /**
     311     *  On a read timeout, this returns 0
     312     *  (doesn't throw SocketTimeoutException like Socket)
     313     *  (doesn't throw InterruptedIOException like our javadocs say)
     314     */
    290315    @Override
    291316    public int read(byte target[], int offset, int length) throws IOException {
    292         long expiration = -1;
    293         if (_readTimeout > 0)
    294             expiration = _readTimeout + System.currentTimeMillis();
     317        int readTimeout = _readTimeout;
     318        long expiration;
     319        if (readTimeout > 0)
     320            expiration = readTimeout + System.currentTimeMillis();
     321        else
     322            expiration = -1;
    295323        synchronized (_dataLock) {
    296324            if (_locallyClosed) throw new IOException("Already locally closed");
     
    311339                            return -1;
    312340                        } else {
    313                             if (_readTimeout < 0) {
     341                            if (readTimeout < 0) {
    314342                                if (_log.shouldLog(Log.DEBUG))
    315343                                    _log.debug("read(...," + offset+", " + length+ ")[" + i
    316                                                + ") with no timeout: " + toString());
     344                                               + "] with no timeout: " + toString());
    317345                                try {
    318346                                    _dataLock.wait();
     
    324352                                if (_log.shouldLog(Log.DEBUG))
    325353                                    _log.debug("read(...," + offset+", " + length+ ")[" + i
    326                                                + ") with no timeout complete: " + toString());
     354                                               + "] with no timeout complete: " + toString());
    327355                                throwAnyError();
    328                             } else if (_readTimeout > 0) {
     356                            } else if (readTimeout > 0) {
    329357                                if (_log.shouldLog(Log.DEBUG))
    330358                                    _log.debug("read(...," + offset+", " + length+ ")[" + i
    331                                                + ") with timeout: " + _readTimeout + ": " + toString());
     359                                               + "] with timeout: " + readTimeout + ": " + toString());
    332360                                try {
    333                                     _dataLock.wait(_readTimeout);
     361                                    _dataLock.wait(readTimeout);
    334362                                } catch (InterruptedException ie) {
    335363                                    IOException ioe2 = new InterruptedIOException("Interrupted read");
     
    339367                                if (_log.shouldLog(Log.DEBUG))
    340368                                    _log.debug("read(...," + offset+", " + length+ ")[" + i
    341                                                + ") with timeout complete: " + _readTimeout + ": " + toString());
     369                                               + "] with timeout complete: " + readTimeout + ": " + toString());
    342370                                throwAnyError();
    343371                            } else { // readTimeout == 0
     
    345373                                if (_log.shouldLog(Log.DEBUG))
    346374                                    _log.debug("read(...," + offset+", " + length+ ")[" + i
    347                                                + ") with nonblocking setup: " + toString());
     375                                               + "] with nonblocking setup: " + toString());
    348376                                return i;
    349377                            }
    350378                            if (_readyDataBlocks.isEmpty()) {
    351                                 if ( (_readTimeout > 0) && (expiration < System.currentTimeMillis()) ) {
    352                                     if (_log.shouldLog(Log.INFO))
    353                                         _log.info("read(...," + offset+", " + length+ ")[" + i
    354                                                    + ") expired: " + toString());
    355                                     return i;
     379                                if (readTimeout > 0) {
     380                                    long remaining = expiration - System.currentTimeMillis();
     381                                    if (remaining <= 0) {
     382                                        // FIXME Javadocs for setReadTimeout() say we will throw
     383                                        // an InterruptedIOException.
     384                                        // Java throws a SocketTimeoutException.
     385                                        // We do neither.
     386                                        if (_log.shouldLog(Log.INFO))
     387                                            _log.info("read(...," + offset+", " + length+ ")[" + i
     388                                                       + "] expired: " + toString());
     389                                        return i;
     390                                    } else {
     391                                        readTimeout = (int) remaining;
     392                                    }
    356393                                }
    357394                            }
  • apps/streaming/java/src/net/i2p/client/streaming/impl/StandardSocket.java

    r75a8d8f rb5df13d  
    194194        if (opts == null)
    195195            return 0;
    196         return (int) opts.getReadTimeout();
     196        long rv = opts.getReadTimeout();
     197        // Java Socket: 0 is forever, and we don't exactly have nonblocking
     198        if (rv > Integer.MAX_VALUE)
     199            rv = Integer.MAX_VALUE;
     200        else if (rv < 0)
     201            rv = 0;
     202        else if (rv == 0)
     203            rv = 1;
     204        return (int) rv;
    197205    }
    198206
     
    310318        if (opts == null)
    311319            throw new SocketException("No options");
     320        // Java Socket: 0 is forever
     321        if (timeout == 0)
     322            timeout = -1;
    312323        opts.setReadTimeout(timeout);
    313324    }
  • core/java/src/freenet/support/CPUInformation/IntelInfoImpl.java

    r75a8d8f rb5df13d  
    157157                    isCore2Compatible = true;
    158158                    isX64 = true;
    159                     if (extmodel >= 2)
    160                         isCoreiCompatible = true;
     159                }
     160                if (extmodel >= 2) {
     161                    isCoreiCompatible = true;
    161162                }
    162163                switch (model) {
     
    330331                    // Ivy Bridge 22 nm
    331332                    case 0x3a:
    332                         modelString = "Ivy Bridge";
     333                        modelString = "Ivy Bridge (22nm)";
    333334                        break;
    334335                    // Haswell 22 nm
    335336                    case 0x3c:
    336                         modelString = "Haswell";
     337                        modelString = "Haswell (22nm)";
    337338                        break;
    338339                    // Broadwell 14 nm
    339340                    case 0x3d:
    340                         modelString = "Broadwell";
    341                         break;
    342 
     341                        modelString = "Broadwell (14nm)";
     342                        break;
     343                    // Ivy Bridge 22 nm
     344                    case 0x3e:
     345                        modelString = "Xeon Ivy Bridge (22nm)";
     346                        break;
     347                       
     348                       
    343349                // following are for extended model == 4
    344350                // most flags are set above
    345351                // isCoreiCompatible = true is the default
    346 
     352               
    347353                    // Atom Silvermont / Bay Trail / Avoton 22 nm
    348354                    // Supports SSE 4.2
     
    352358                        break;
    353359
    354                 // others
    355 
     360                    // others
    356361                    default:
    357362                        modelString = "Intel model " + model;
     
    362367
    363368            case 7: {
    364                 // Flags TODO
    365369                modelString = "Intel Itanium model " + model;
    366370            }
    367371            break;
    368372
    369             // 15 + 0
    370373            case 15: {
    371374                isPentiumCompatible = true;
     
    400403            break;
    401404
    402             // 15 + 1
    403405            case 16: {
    404                 // Flags TODO
    405406                modelString = "Intel Itanium II model " + model;
    406407            }
  • core/java/src/net/i2p/crypto/SHA256Generator.java

    r75a8d8f rb5df13d  
    33import gnu.crypto.hash.Sha256Standalone;
    44
     5import java.security.DigestException;
    56import java.security.MessageDigest;
    67import java.security.NoSuchAlgorithmException;
     
    2122
    2223    private static final boolean _useGnu;
     24
    2325    static {
    2426        boolean useGnu = false;
     
    5456    /**
    5557     * Calculate the hash and cache the result.
     58     * @param source what to hash
    5659     */
    5760    public final Hash calculateHash(byte[] source, int start, int len) {
     
    6063        byte rv[] = digest.digest();
    6164        release(digest);
    62         //return new Hash(rv);
    6365        return Hash.create(rv);
    6466    }
     
    7274        MessageDigest digest = acquire();
    7375        digest.update(source, start, len);
    74         byte rv[] = digest.digest();
     76        try {
     77            digest.digest(out, outOffset, Hash.HASH_LENGTH);
     78        } catch (DigestException e) {
     79            throw new RuntimeException(e);
     80        }
    7581        release(digest);
    76         System.arraycopy(rv, 0, out, outOffset, rv.length);
    7782    }
    7883   
  • core/java/src/net/i2p/util/I2PSSLSocketFactory.java

    r75a8d8f rb5df13d  
    267267            // if we left SSLv3 in there, we don't support TLS,
    268268            // so we should't remove the SSL ciphers
    269             if (p.equals("SSLv3"))
     269            if (p[i].equals("SSLv3"))
    270270                return;
    271271        }
  • core/java/src/net/i2p/util/NativeBigInteger.java

    r75a8d8f rb5df13d  
    197197   
    198198    static {
    199         if (_isX86) // Don't try to resolve CPU type on non x86 hardware
     199        if (_isX86) {// Don't try to resolve CPU type on non x86 hardware
    200200            sCPUType = resolveCPUType();
    201         else if (_isArm)
     201        }
     202        else if (_isArm) {
    202203            sCPUType = JBIGI_OPTIMIZATION_ARM;
    203         else if (_isPPC && !_isMac)
    204             sCPUType = JBIGI_OPTIMIZATION_PPC;
    205         else
    206             sCPUType = null;
     204        } else if (_isPPC && !_isMac) {
     205                sCPUType = JBIGI_OPTIMIZATION_PPC;
     206        } else {
     207                sCPUType = null;
     208        }
    207209        loadNative();
    208210    }
  • core/java/src/net/metanotion/io/block/index/BSkipSpan.java

    r75a8d8f rb5df13d  
    7070
    7171        protected int prevPage;
    72         protected int nextPage;
     72        protected int nextPage = 0;
    7373        protected Serializer keySer;
    7474        protected Serializer valSer;
  • history.txt

    r75a8d8f rb5df13d  
     12015-04-04 zzz
     2 * i2ptunnel:
     3   - Better timeout handling when reading headers in HTTP server (ticket #723)
     4   - Fix NoSuchElementException processing proxyList caused by 03-31 checkin
     5 * Streaming:
     6   - Fix read timeout on input stream (ticket #723)
     7   - Fix read() returning 0 instead of -1 on read timeout (ticket #335)
     8
     92015-04-03 zzz
     10 * i2ptunnel: Fix stopping tunnel on bad args when starting
     11 * wrapper.config: Remove old mortbay Jetty parameters
     12
    1132015-04-01 zzz
    214 * I2CP: Allow larger client clock skew (ticket #1503)
  • installer/resources/portable/configs/wrapper.config

    r75a8d8f rb5df13d  
    1414# Numbers must be consecutive (except for stripquotes)
    1515wrapper.java.additional.1=-DloggerFilenameOverride=logs/log-router-@.txt
    16 wrapper.java.additional.2=-Dorg.mortbay.http.Version.paranoid=true
    17 wrapper.java.additional.3=-Dorg.mortbay.util.FileResource.checkAliases=false
    18 wrapper.java.additional.4=-Dorg.mortbay.xml.XmlParser.NotValidating=true
    19 wrapper.java.additional.5=-Di2p.dir.base=.
    20 wrapper.java.additional.5.stripquotes=TRUE
     16wrapper.java.additional.2=-Di2p.dir.base=.
     17wrapper.java.additional.2.stripquotes=TRUE
     18
     19# Prevent the JVM from exporting stats (and thereby causing hundreds of
     20# ms long pauses during GC)
     21# http://www.evanjones.ca/jvm-mmap-pause.html
     22#wrapper.java.additional.3=-XX:+PerfDisableSharedMem
     23
    2124# PORTABLE installation:
    2225# uncomment the following
    23 wrapper.java.additional.6=-Di2p.dir.pid=logs
    24 wrapper.java.additional.6.stripquotes=TRUE
    25 wrapper.java.additional.7=-Di2p.dir.temp=tmp
    26 wrapper.java.additional.7.stripquotes=TRUE
    27 wrapper.java.additional.8=-Di2p.dir.config=.
    28 wrapper.java.additional.8.stripquotes=TRUE
     26wrapper.java.additional.3=-Di2p.dir.pid=logs
     27wrapper.java.additional.3.stripquotes=TRUE
     28wrapper.java.additional.4=-Di2p.dir.temp=tmp
     29wrapper.java.additional.4.stripquotes=TRUE
     30wrapper.java.additional.5=-Di2p.dir.config=.
     31wrapper.java.additional.5.stripquotes=TRUE
    2932
    3033# Uncomment this for better performance.
  • installer/resources/small/wrapper.config

    r75a8d8f rb5df13d  
    5656# Java Additional Parameters
    5757wrapper.java.additional.1=-DloggerFilenameOverride=logs/log-router-@.txt
    58 wrapper.java.additional.2=-Dorg.mortbay.http.Version.paranoid=true
    59 wrapper.java.additional.3=-Dorg.mortbay.util.FileResource.checkAliases=false
    60 wrapper.java.additional.4=-Dorg.mortbay.xml.XmlParser.NotValidating=true
     58
     59# Prevent the JVM from exporting stats (and thereby causing hundreds of
     60# ms long pauses during GC)
     61# http://www.evanjones.ca/jvm-mmap-pause.html
     62#wrapper.java.additional.2=-XX:+PerfDisableSharedMem
    6163
    6264# Initial Java Heap Size (in MB)
  • installer/resources/wrapper.config

    r75a8d8f rb5df13d  
    7575# Numbers must be consecutive (except for stripquotes)
    7676wrapper.java.additional.1=-DloggerFilenameOverride=logs/log-router-@.txt
    77 wrapper.java.additional.2=-Dorg.mortbay.http.Version.paranoid=true
    78 wrapper.java.additional.3=-Dorg.mortbay.xml.XmlParser.NotValidating=true
    79 wrapper.java.additional.4=-Di2p.dir.base="$INSTALL_PATH"
    80 wrapper.java.additional.4.stripquotes=TRUE
     77wrapper.java.additional.2=-Di2p.dir.base="$INSTALL_PATH"
     78wrapper.java.additional.2.stripquotes=TRUE
     79
     80# Prevent the JVM from exporting stats (and thereby causing hundreds of
     81# ms long pauses during GC)
     82# http://www.evanjones.ca/jvm-mmap-pause.html
     83#wrapper.java.additional.3=-XX:+PerfDisableSharedMem
    8184
    8285# On some IPv6 enabled systems, I2P and other network-enabled java applications
     
    8689# 1) "echo 0 > /proc/sys/net/ipv6/bindv6only" as root; or
    8790# 2) uncomment the next two lines:
    88 #wrapper.java.additional.5=-Djava.net.preferIPv4Stack=true
    89 #wrapper.java.additional.6=-Djava.net.preferIPv6Addresses=false
     91#wrapper.java.additional.3=-Djava.net.preferIPv4Stack=true
     92#wrapper.java.additional.4=-Djava.net.preferIPv6Addresses=false
    9093
    9194# Jetty says this is a security risk
     
    9497# somehow - not sure exactly but here's a clue:
    9598# org.mortbay.util.FileResource.setCheckAliases(false)
    96 # wrapper.java.additional.7=-Dorg.mortbay.util.FileResource.checkAliases=false
     99# wrapper.java.additional.8=-Dorg.mortbay.util.FileResource.checkAliases=false
    97100# PORTABLE installation:
    98101# uncomment the following
    99 #wrapper.java.additional.7=-Di2p.dir.pid="$INSTALL_PATH"
    100 #wrapper.java.additional.7.stripquotes=TRUE
    101 #wrapper.java.additional.8=-Di2p.dir.temp="$INSTALL_PATH"
    102 #wrapper.java.additional.8.stripquotes=TRUE
    103 #wrapper.java.additional.9=-Di2p.dir.config="$INSTALL_PATH"
    104 #wrapper.java.additional.9.stripquotes=TRUE
     102#wrapper.java.additional.3=-Di2p.dir.pid="$INSTALL_PATH"
     103#wrapper.java.additional.3.stripquotes=TRUE
     104#wrapper.java.additional.4=-Di2p.dir.temp="$INSTALL_PATH"
     105#wrapper.java.additional.4.stripquotes=TRUE
     106#wrapper.java.additional.5=-Di2p.dir.config="$INSTALL_PATH"
     107#wrapper.java.additional.5.stripquotes=TRUE
    105108#
    106109# Uncomment this for better performance.
     
    108111# This may not be required if your machine is already "server-class".
    109112# See http://java.sun.com/j2se/1.5.0/docs/guide/vm/server-class.html
    110 #wrapper.java.additional.7=-server
     113#wrapper.java.additional.5=-server
    111114
    112115# Initial Java Heap Size (in MB)
  • router/java/src/net/i2p/data/i2np/I2NPMessageImpl.java

    r75a8d8f rb5df13d  
    3232    protected final I2PAppContext _context;
    3333    protected long _expiration;
    34     protected long _uniqueId;
    35    
     34    protected long _uniqueId = -1;
     35
    3636    public final static long DEFAULT_EXPIRATION_MS = 1*60*1000; // 1 minute by default
    3737    public final static int CHECKSUM_LENGTH = 1; //Hash.HASH_LENGTH;
    38    
     38
    3939    /** 16 */
    4040    public static final int HEADER_LENGTH = 1 // type
     
    4747    // We are stuck with the short header, can't change it now.
    4848    //private static final boolean RAW_FULL_SIZE = false;
    49    
     49
    5050    /** unused */
    5151    private static final Map<Integer, Builder> _builders = new ConcurrentHashMap<Integer, Builder>(1);
     
    5959        public I2NPMessage build(I2PAppContext ctx);
    6060    }
    61    
     61
    6262    public I2NPMessageImpl(I2PAppContext context) {
    6363        _context = context;
    6464        _log = context.logManager().getLog(I2NPMessageImpl.class);
    6565        _expiration = _context.clock().now() + DEFAULT_EXPIRATION_MS;
    66         // FIXME/TODO set only for outbound, or only on write, or something, to not waste entropy
    67         _uniqueId = _context.random().nextLong(MAX_ID_VALUE);
    6866        //_context.statManager().createRateStat("i2np.writeTime", "How long it takes to write an I2NP message", "I2NP", new long[] { 10*60*1000, 60*60*1000 });
    6967        //_context.statManager().createRateStat("i2np.readTime", "How long it takes to read an I2NP message", "I2NP", new long[] { 10*60*1000, 60*60*1000 });
    7068    }
    71    
     69
    7270    /**
    7371     *  Read the whole message but only if it's exactly 1024 bytes.
     
    125123                buffer = new byte[size];
    126124            }
    127            
     125
    128126            int cur = 0;
    129127            while (cur < size) {
     
    134132                cur += numRead;
    135133            }
    136            
     134
    137135            byte[] calc = SimpleByteCache.acquire(Hash.HASH_LENGTH);
    138136            _context.sha().calculateHash(buffer, 0, size, calc, 0);
     
    202200        int size = (int)DataHelper.fromLong(data, cur, 2);
    203201        cur += 2;
    204         //Hash h = new Hash();
    205         byte hdata[] = new byte[CHECKSUM_LENGTH];
    206         System.arraycopy(data, cur, hdata, 0, CHECKSUM_LENGTH);
    207         cur += CHECKSUM_LENGTH;
    208         //h.setData(hdata);
    209202
    210203        if (cur + size > data.length || headerSize + size > maxLen)
    211             throw new I2NPMessageException("Payload is too short [" 
     204            throw new I2NPMessageException("Payload is too short ["
    212205                                           + "data.len=" + data.length
    213206                                           + "maxLen=" + maxLen
    214207                                           + " offset=" + offset
    215                                            + " cur=" + cur 
     208                                           + " cur=" + cur
    216209                                           + " wanted=" + size + "]: " + getClass().getSimpleName());
    217210
    218211        int sz = Math.min(size, maxLen - headerSize);
    219212        byte[] calc = SimpleByteCache.acquire(Hash.HASH_LENGTH);
    220         _context.sha().calculateHash(data, cur, sz, calc, 0);
    221         boolean eq = DataHelper.eq(hdata, 0, calc, 0, CHECKSUM_LENGTH);
     213       
     214        // Compare the checksum in data to the checksum of the data after the checksum
     215        _context.sha().calculateHash(data, cur + CHECKSUM_LENGTH, sz, calc, 0);
     216        boolean eq = DataHelper.eq(data, cur, calc, 0, CHECKSUM_LENGTH);
     217        cur += CHECKSUM_LENGTH;
     218
    222219        SimpleByteCache.release(calc);
    223220        if (!eq)
     
    234231        return cur - offset;
    235232    }
    236    
     233
    237234    /**
    238235     *  Don't do this if you need a byte array - use toByteArray()
     
    248245        out.write(buf, 0, read);
    249246    }
    250    
     247
    251248    /**
    252249     * Replay resistant message Id
    253250     */
    254     public long getUniqueId() { return _uniqueId; }
     251    public long getUniqueId() {
     252        // Lazy initialization of value
     253        if (_uniqueId < 0) {
     254            _uniqueId = _context.random().nextLong(MAX_ID_VALUE);
     255        }
     256        return _uniqueId;
     257    }
    255258
    256259    /**
     
    258261     */
    259262    public void setUniqueId(long id) { _uniqueId = id; }
    260    
     263
    261264    /**
    262265     * Date after which the message should be dropped (and the associated uniqueId forgotten)
     
    269272     */
    270273    public void setMessageExpiration(long exp) { _expiration = exp; }
    271    
    272     public synchronized int getMessageSize() { 
     274
     275    public synchronized int getMessageSize() {
    273276        return calculateWrittenLength() + (15 + CHECKSUM_LENGTH); // 16 bytes in the header
    274277    }
     
    278281     *  Used by SSU only!
    279282     */
    280     public synchronized int getRawMessageSize() { 
    281         //if (RAW_FULL_SIZE) 
     283    public synchronized int getRawMessageSize() {
     284        //if (RAW_FULL_SIZE)
    282285        //    return getMessageSize();
    283286        //else
    284287            return calculateWrittenLength()+5;
    285288    }
    286    
     289
    287290    @Override
    288291    public byte[] toByteArray() {
     
    296299        return data;
    297300    }
    298    
     301
    299302    public int toByteArray(byte buffer[]) {
    300303        try {
     
    307310            DataHelper.toLong(buffer, off, 1, getType());
    308311            off += 1;
     312
     313            // Lazy initialization of value
     314            if (_uniqueId < 0) {
     315                _uniqueId = _context.random().nextLong(MAX_ID_VALUE);
     316            }
    309317            DataHelper.toLong(buffer, off, 4, _uniqueId);
     318
    310319            off += 4;
    311320            DataHelper.toLong(buffer, off, DataHelper.DATE_LENGTH, _expiration);
     
    316325            SimpleByteCache.release(h);
    317326
    318             return writtenLen;                     
     327            return writtenLen;
    319328        } catch (I2NPMessageException ime) {
    320329            _context.logManager().getLog(getClass()).log(Log.CRIT, "Error writing", ime);
     
    322331        }
    323332    }
    324    
     333
    325334    /** calculate the message body's length (not including the header and footer */
    326335    protected abstract int calculateWrittenLength();
    327336
    328     /** 
     337    /**
    329338     * write the message body to the output array, starting at the given index.
    330339     * @return the index into the array after the last byte written
     
    339348            curIndex += prefix[i].length;
    340349        }
    341        
     350
    342351        curIndex = writeMessageBody(out, curIndex);
    343        
     352
    344353        for (int i = 0; i < suffix.length; i++) {
    345354            System.arraycopy(suffix[i], 0, out, curIndex, suffix[i].length);
    346355            curIndex += suffix[i].length;
    347356        }
    348        
     357
    349358        return curIndex;
    350359    }
    351360     */
    352361
    353    
     362
    354363    /**
    355364     *  Write the message with a short 5-byte header.
     
    384393    }
    385394
    386    
     395
    387396/*****
    388397    public static I2NPMessage fromRawByteArray(I2PAppContext ctx, byte buffer[], int offset, int len) throws I2NPMessageException {
     
    400409        offset++;
    401410        I2NPMessageImpl msg = (I2NPMessageImpl)createMessage(ctx, type);
    402         if (msg == null) 
     411        if (msg == null)
    403412            throw new I2NPMessageException("Unknown message type: " + type);
    404413        //if (RAW_FULL_SIZE) {
  • router/java/src/net/i2p/router/JobQueue.java

    r75a8d8f rb5df13d  
    139139                                              "How many jobs do we drop due to insane overload?",
    140140                                              "JobQueue",
     141                                              new long[] { 60*1000l, 60*60*1000l, 24*60*60*1000l });
     142        _context.statManager().createRateStat("jobQueue.queuedJobs",
     143                                              "How many scheduled jobs are there?",
     144                                              "JobQueue",
    141145                                              new long[] { 60*1000l, 60*60*1000l, 24*60*60*1000l });
    142146        // following are for JobQueueRunner
     
    214218       
    215219        _context.statManager().addRateData("jobQueue.readyJobs", numReady);
     220        _context.statManager().addRateData("jobQueue.queuedJobs", _timedJobs.size());
    216221        if (dropped) {
    217222            _context.statManager().addRateData("jobQueue.droppedJobs", 1);
  • router/java/src/net/i2p/router/RouterLaunch.java

    r75a8d8f rb5df13d  
    88 *  Setup of wrapper.log file is moved to WorkingDir.java
    99 *  Until WorkingDir is called, the existing stdout / stderr will be used.
     10 *
     11 *  Not recommended for embedded use. Instantiate Router() yourself.
     12 *
    1013 */
    1114public class RouterLaunch {
  • router/java/src/net/i2p/router/RouterVersion.java

    r75a8d8f rb5df13d  
    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 = 17;
    2222
    2323    /** for example "-test" */
Note: See TracChangeset for help on using the changeset viewer.