Changeset 2eab528


Ignore:
Timestamp:
Jul 9, 2011 7:53:12 AM (9 years ago)
Author:
magma <magma@…>
Branches:
master
Children:
526c42b
Parents:
c4b3551 (diff), b41c5834 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge of 'f2281f98637dc74181e14a40f3b346436e95be88'

and 'f452317ba7735d99e285e2c580491a100bea305b'

Files:
2 added
1 deleted
33 edited

Legend:

Unmodified
Added
Removed
  • apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java

    rc4b3551 r2eab528  
    784784        } finally {
    785785            try {
    786                 if (out == null)
     786                if (out != null)
    787787                    out.close();
    788788            } catch (IOException ioe) {}
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelConnectClient.java

    rc4b3551 r2eab528  
    306306                response = SUCCESS_RESPONSE;
    307307            Runnable onTimeout = new OnTimeout(s, s.getOutputStream(), targetRequest, usingWWWProxy, currentProxy, requestId);
    308             I2PTunnelRunner runner = new I2PTunnelRunner(s, i2ps, sockLock, data, response, mySockets, onTimeout);
     308            // starts itself
     309            new I2PTunnelRunner(s, i2ps, sockLock, data, response, mySockets, onTimeout);
    309310        } catch (SocketException ex) {
    310311            _log.info(getPrefix(requestId) + "Error trying to connect", ex);
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java

    rc4b3551 r2eab528  
    11901190            try {
    11911191                filename = targetRequest.substring(LOCAL_SERVER.length() + 8, space); // "/themes/".length
    1192             } catch (IndexOutOfBoundsException ioobe) {}
     1192            } catch (IndexOutOfBoundsException ioobe) {
     1193                 return;
     1194            }
    11931195            // theme hack
    11941196            if (filename.startsWith("console/default/"))
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelIRCClient.java

    rc4b3551 r2eab528  
    126126    public static class IrcInboundFilter implements Runnable {
    127127       
    128         private Socket local;
    129         private I2PSocket remote;
    130         private StringBuffer expectedPong;
     128        private final Socket local;
     129        private final I2PSocket remote;
     130        private final StringBuffer expectedPong;
    131131        private final Log _log;
    132132               
     
    192192                _log.error("Error filtering inbound data", re);
    193193            } finally {
    194                 if (local != null) try { local.close(); } catch (IOException e) {}
     194                try { local.close(); } catch (IOException e) {}
    195195            }
    196196            if(_log.shouldLog(Log.DEBUG))
     
    205205        public static class IrcOutboundFilter implements Runnable {
    206206                   
    207             private Socket local;
    208             private I2PSocket remote;
    209             private StringBuffer expectedPong;
     207            private final Socket local;
     208            private final I2PSocket remote;
     209            private final StringBuffer expectedPong;
    210210            private final Log _log;
    211211               
     
    271271                    _log.error("Error filtering outbound data", re);
    272272                } finally {
    273                     if (remote != null) try { remote.close(); } catch (IOException e) {}
     273                    try { remote.close(); } catch (IOException e) {}
    274274                }
    275275                if (_log.shouldLog(Log.DEBUG))
  • apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketEepGet.java

    rc4b3551 r2eab528  
    164164        StringBuilder buf = new StringBuilder(2048);
    165165        URL url = new URL(_actualURL);
    166         String host = url.getHost();
     166        //String host = url.getHost();
    167167        String path = url.getPath();
    168168        String query = url.getQuery();
  • apps/routerconsole/java/src/net/i2p/router/web/NetDbRenderer.java

    rc4b3551 r2eab528  
    408408    private static int classifyTransports(RouterInfo info) {
    409409        int rv = 0;
    410         String hash = info.getIdentity().getHash().toBase64();
    411410        for (RouterAddress addr : info.getAddresses()) {
    412411            String style = addr.getTransportStyle();
  • apps/routerconsole/java/src/net/i2p/router/web/PluginUpdateChecker.java

    rc4b3551 r2eab528  
    129129            updateStatus("<b>" + _("Checking for update of plugin {0}", _appName) + "</b>");
    130130            // use the same settings as for updater
    131             boolean shouldProxy = Boolean.valueOf(_context.getProperty(ConfigUpdateHandler.PROP_SHOULD_PROXY, ConfigUpdateHandler.DEFAULT_SHOULD_PROXY)).booleanValue();
     131            // always proxy, or else FIXME
     132            //boolean shouldProxy = Boolean.valueOf(_context.getProperty(ConfigUpdateHandler.PROP_SHOULD_PROXY, ConfigUpdateHandler.DEFAULT_SHOULD_PROXY)).booleanValue();
    132133            String proxyHost = _context.getProperty(ConfigUpdateHandler.PROP_PROXY_HOST, ConfigUpdateHandler.DEFAULT_PROXY_HOST);
    133134            int proxyPort = _context.getProperty(ConfigUpdateHandler.PROP_PROXY_PORT, ConfigUpdateHandler.DEFAULT_PROXY_PORT_INT);
  • apps/streaming/java/src/net/i2p/client/streaming/Connection.java

    rc4b3551 r2eab528  
    348348
    349349            // schedules itself
    350             ResendPacketEvent rpe = new ResendPacketEvent(packet, timeout);
     350            new ResendPacketEvent(packet, timeout);
    351351        }
    352352
  • apps/susidns/src/java/src/i2p/susi/dns/AddressbookBean.java

    rc4b3551 r2eab528  
    301301                                                                boolean valid = true;
    302302                                                                try {
    303                                                                         Destination dest = new Destination(destination);
     303                                                                        // just to check validity
     304                                                                        new Destination(destination);
    304305                                                                } catch (DataFormatException dfe) {
    305306                                                                        valid = false;
  • apps/susidns/src/java/src/i2p/susi/dns/FormatDate.java

    rc4b3551 r2eab528  
    2626    public static String format(long date)
    2727    {
    28         return _dateFormat.format(new Date(date));
     28        synchronized(_dateFormat) {
     29                return _dateFormat.format(new Date(date));
     30        }
    2931    }
    3032}
  • apps/susidns/src/java/src/i2p/susi/dns/SubscriptionsBean.java

    rc4b3551 r2eab528  
    131131                                if (action.equals(_("Save"))) {
    132132                                        save();
     133                                /*******
    133134                                        String nonce = System.getProperty("addressbook.nonce");
    134                                 /*******
    135135                                        if (nonce != null) {   
    136136                                                // Yes this is a hack.
  • apps/systray/java/src/net/i2p/apps/systray/UrlLauncher.java

    rc4b3551 r2eab528  
    226226    private boolean validateUrlFormat(String urlString) {
    227227        try {
    228             URL url = new URL(urlString);
     228            // just to check validity
     229            new URL(urlString);
    229230        } catch (MalformedURLException e) {
    230231            return false;
  • core/java/src/gnu/crypto/hash/BaseHashStandalone.java

    rc4b3551 r2eab528  
    4747 * <p>A base abstract class to facilitate hash implementations.</p>
    4848 *
     49 * WARNING - DEPRECATED - Use SHA256Generator.getDigestInstance() to get a
     50 * MessageDigest that will be faster in almost all cases.
     51 * See SHA256Generator for more information.
     52 *
    4953 * @version $Revision: 1.1 $
    5054 */
  • core/java/src/gnu/crypto/hash/IMessageDigestStandalone.java

    rc4b3551 r2eab528  
    4949 * <p>A hash (or message digest) algorithm produces its output by iterating a
    5050 * basic compression function on blocks of data.</p>
     51 *
     52 * WARNING - DEPRECATED - Use SHA256Generator.getDigestInstance() to get a
     53 * MessageDigest that will be faster in almost all cases.
     54 * See SHA256Generator for more information.
    5155 *
    5256 * @version $Revision: 1.1 $
  • core/java/src/gnu/crypto/hash/Sha256Standalone.java

    rc4b3551 r2eab528  
    5959 * renamed from Sha256 to avoid conflicts with JVMs using gnu-crypto as their JCE
    6060 * provider.
     61 *
     62 * WARNING - DEPRECATED - Use SHA256Generator.getDigestInstance() to get a
     63 * MessageDigest that will be faster in almost all cases.
     64 * See SHA256Generator for more information.
    6165 *
    6266 * @version $Revision: 1.2 $
  • core/java/src/gnu/crypto/prng/AsyncFortunaStandalone.java

    rc4b3551 r2eab528  
    157157   
    158158    private void doFill(byte buf[]) {
    159         long start = System.currentTimeMillis();
     159        //long start = System.currentTimeMillis();
    160160        if (pool0Count >= MIN_POOL_SIZE
    161161            && System.currentTimeMillis() - lastReseed > 100)
  • core/java/src/gnu/crypto/prng/FortunaStandalone.java

    rc4b3551 r2eab528  
    4242package gnu.crypto.prng;
    4343
    44 import gnu.crypto.hash.Sha256Standalone;
    45 
    4644import java.io.IOException;
    4745import java.io.ObjectInputStream;
     
    4947import java.io.Serializable;
    5048import java.security.InvalidKeyException;
     49import java.security.MessageDigest;
    5150import java.util.Arrays;
    5251import java.util.HashMap;
     
    5554import net.i2p.crypto.CryptixAESKeyCache;
    5655import net.i2p.crypto.CryptixRijndael_Algorithm;
     56import net.i2p.crypto.SHA256Generator;
    5757
    5858/**
     
    9494 * gnu-crypto implementation, which has been imported into GNU/classpath
    9595 *
     96 * NOTE: As of 0.8.8, uses the java.security.MessageDigest instead of GNU Sha256Standalone
    9697 */
    9798public class FortunaStandalone extends BasePRNGStandalone implements Serializable, RandomEventListenerStandalone
     
    104105  static final int MIN_POOL_SIZE = 64;
    105106  final Generator generator;
    106   final Sha256Standalone[] pools;
     107  final MessageDigest[] pools;
    107108  long lastReseed;
    108109  int pool;
     
    118119    super("Fortuna i2p");
    119120    generator = new Generator();
    120     pools = new Sha256Standalone[NUM_POOLS];
     121    pools = new MessageDigest[NUM_POOLS];
    121122    for (int i = 0; i < NUM_POOLS; i++)
    122       pools[i] = new Sha256Standalone();
     123      pools[i] = SHA256Generator.getDigestInstance();
    123124    lastReseed = 0;
    124125    pool = 0;
     
    228229    private static final int LIMIT = 1 << 20;
    229230
    230     private final Sha256Standalone hash;
     231    private final MessageDigest hash;
    231232    private final byte[] counter;
    232233    private final byte[] key;
     
    239240    {
    240241      super("Fortuna.generator.i2p");
    241       this.hash = new Sha256Standalone();
     242      this.hash = SHA256Generator.getDigestInstance();
    242243      counter = new byte[16]; //cipher.defaultBlockSize()];
    243244      buffer = new byte[16]; //cipher.defaultBlockSize()];
  • core/java/src/net/i2p/I2PAppContext.java

    rc4b3551 r2eab528  
    149149   
    150150    /**
    151      * Lets root a brand new context
    152      *
     151     * Create a brand new context.
     152     * WARNING: In almost all cases, you should use getGlobalContext() instead,
     153     * to avoid creating additional contexts, which may spawn numerous
     154     * additional resources and threads, and may be the cause of logging
     155     * problems or hard-to-isolate bugs.
    153156     */
    154157    public I2PAppContext() {
     
    157160   
    158161    /**
    159      * Lets root a brand new context
    160      *
     162     * Create a brand new context.
     163     * WARNING: In almost all cases, you should use getGlobalContext() instead,
     164     * to avoid creating additional contexts, which may spawn numerous
     165     * additional resources and threads, and may be the cause of logging
     166     * problems or hard-to-isolate bugs.
    161167     */
    162168    public I2PAppContext(Properties envProps) {
     
    165171   
    166172    /**
     173     * Create a brand new context.
     174     * WARNING: In almost all cases, you should use getGlobalContext() instead,
     175     * to avoid creating additional contexts, which may spawn numerous
     176     * additional resources and threads, and may be the cause of logging
     177     * problems or hard-to-isolate bugs.
     178     *
    167179     * @param doInit should this context be used as the global one (if necessary)?
     180     *               Will only apply if there is no global context now.
    168181     */
    169182    private I2PAppContext(boolean doInit, Properties envProps) {
  • core/java/src/net/i2p/client/RequestLeaseSetMessageHandler.java

    rc4b3551 r2eab528  
    1010 */
    1111
    12 import java.util.HashMap;
    1312import java.util.Map;
     13import java.util.concurrent.ConcurrentHashMap;
    1414
    1515import net.i2p.I2PAppContext;
     
    3939    public RequestLeaseSetMessageHandler(I2PAppContext context) {
    4040        super(context, RequestLeaseSetMessage.MESSAGE_TYPE);
    41         _existingLeaseSets = new HashMap(32);
     41        // not clear why there would ever be more than one
     42        _existingLeaseSets = new ConcurrentHashMap(4);
    4243    }
    4344   
     
    5960
    6061        // reuse the old keys for the client
    61         LeaseInfo li = null;
    62         synchronized (_existingLeaseSets) {
    63             if (_existingLeaseSets.containsKey(session.getMyDestination()))
    64                 li = (LeaseInfo) _existingLeaseSets.get(session.getMyDestination());
    65         }
     62        LeaseInfo li = (LeaseInfo) _existingLeaseSets.get(session.getMyDestination());
    6663        if (li == null) {
    6764            li = new LeaseInfo(session.getMyDestination());
    68             synchronized (_existingLeaseSets) {
    69                 _existingLeaseSets.put(session.getMyDestination(), li);
    70             }
     65            _existingLeaseSets.put(session.getMyDestination(), li);
    7166            if (_log.shouldLog(Log.DEBUG))
    7267                _log.debug("Creating new leaseInfo keys for " 
  • core/java/src/net/i2p/crypto/SHA256Generator.java

    rc4b3551 r2eab528  
    9191    }
    9292   
    93     private static MessageDigest getDigestInstance() {
     93    /**
     94     *  Return a new MessageDigest from the system libs unless unavailable
     95     *  in this JVM, in that case return a wrapped GNU Sha256Standalone
     96     *  @since 0.8.7, public since 0.8.8 for FortunaStandalone
     97     */
     98    public static MessageDigest getDigestInstance() {
    9499        if (!_useGnu) {
    95100            try {
  • core/java/src/net/i2p/crypto/TrustedUpdate.java

    rc4b3551 r2eab528  
    130130    private static final String PROP_TRUSTED_KEYS   = "router.trustedUpdateKeys";
    131131
    132     private static I2PAppContext _context;
    133 
    134     private Log      _log;
    135     private Map<SigningPublicKey, String> _trustedKeys;
     132    private final I2PAppContext _context;
     133
     134    private final Log _log;
     135    private final Map<SigningPublicKey, String> _trustedKeys;
    136136    private String _newVersion;
    137137    /** 172 */
     
    156156        _log = _context.logManager().getLog(TrustedUpdate.class);
    157157        _trustedKeys = new HashMap(4);
    158         _newVersion = null;
    159158
    160159        String propertyTrustedKeys = context.getProperty(PROP_TRUSTED_KEYS);
     
    274273        FileOutputStream fileOutputStream = null;
    275274
    276         _context = I2PAppContext.getGlobalContext();
    277         try {
    278             Object signingKeypair[] = _context.keyGenerator().generateSigningKeypair();
     275        I2PAppContext context = I2PAppContext.getGlobalContext();
     276        try {
     277            Object signingKeypair[] = context.keyGenerator().generateSigningKeypair();
    279278            SigningPublicKey signingPublicKey = (SigningPublicKey) signingKeypair[0];
    280279            SigningPrivateKey signingPrivateKey = (SigningPrivateKey) signingKeypair[1];
  • core/java/src/net/i2p/data/DataHelper.java

    rc4b3551 r2eab528  
    2727import java.io.UnsupportedEncodingException;
    2828import java.math.BigInteger;
     29import java.security.MessageDigest;
    2930import java.text.DecimalFormat;
    3031import java.util.ArrayList;
     
    10111012     * Warning - not UTF-8
    10121013     */
    1013     public static String readLine(InputStream in) throws IOException { return readLine(in, (Sha256Standalone)null); }
     1014    public static String readLine(InputStream in) throws IOException { return readLine(in, (MessageDigest) null); }
    10141015
    10151016    /**
     
    10181019     * Warning - 8KB line length limit as of 0.7.13, @throws IOException if exceeded
    10191020     * Warning - not UTF-8
     1021     * @deprecated use MessageDigest version
    10201022     */
    10211023    public static String readLine(InputStream in, Sha256Standalone hash) throws IOException {
     
    10291031
    10301032    /**
     1033     * update the hash along the way
     1034     * Warning - strips \n but not \r
     1035     * Warning - 8KB line length limit as of 0.7.13, @throws IOException if exceeded
     1036     * Warning - not UTF-8
     1037     * @since 0.8.8
     1038     */
     1039    public static String readLine(InputStream in, MessageDigest hash) throws IOException {
     1040        StringBuilder buf = new StringBuilder(128);
     1041        boolean ok = readLine(in, buf, hash);
     1042        if (ok)
     1043            return buf.toString();
     1044        else
     1045            return null;
     1046    }
     1047
     1048    /**
    10311049     * Read in a line, placing it into the buffer (excluding the newline).
    10321050     * Warning - strips \n but not \r
     
    10511069     * Warning - 8KB line length limit as of 0.7.13, @throws IOException if exceeded
    10521070     * Warning - not UTF-8
    1053      * @deprecated use StringBuilder version
     1071     * @deprecated use StringBuilder / MessageDigest version
    10541072     */
    10551073    @Deprecated
     
    10811099     */
    10821100    public static boolean readLine(InputStream in, StringBuilder buf) throws IOException {
    1083         return readLine(in, buf, null);
     1101        return readLine(in, buf, (MessageDigest) null);
    10841102    }
    10851103
     
    10891107     * Warning - 8KB line length limit as of 0.7.13, @throws IOException if exceeded
    10901108     * Warning - not UTF-8
     1109     * @deprecated use MessageDigest version
    10911110     */
    10921111    public static boolean readLine(InputStream in, StringBuilder buf, Sha256Standalone hash) throws IOException {
     
    11041123    }
    11051124   
     1125    /**
     1126     * update the hash along the way
     1127     * Warning - strips \n but not \r
     1128     * Warning - 8KB line length limit as of 0.7.13, @throws IOException if exceeded
     1129     * Warning - not UTF-8
     1130     * @since 0.8.8
     1131     */
     1132    public static boolean readLine(InputStream in, StringBuilder buf, MessageDigest hash) throws IOException {
     1133        int c = -1;
     1134        int i = 0;
     1135        while ( (c = in.read()) != -1) {
     1136            if (++i > MAX_LINE_LENGTH)
     1137                throw new IOException("Line too long - max " + MAX_LINE_LENGTH);
     1138            if (hash != null) hash.update((byte)c);
     1139            if (c == '\n')
     1140                break;
     1141            buf.append((char)c);
     1142        }
     1143        return c != -1;
     1144    }
     1145   
     1146    /**
     1147     *  update the hash along the way
     1148     *  @deprecated use MessageDigest version
     1149     */
    11061150    public static void write(OutputStream out, byte data[], Sha256Standalone hash) throws IOException {
     1151        hash.update(data);
     1152        out.write(data);
     1153    }
     1154   
     1155    /**
     1156     *  update the hash along the way
     1157     *  @since 0.8.8
     1158     */
     1159    public static void write(OutputStream out, byte data[], MessageDigest hash) throws IOException {
    11071160        hash.update(data);
    11081161        out.write(data);
  • core/java/src/net/i2p/stat/Rate.java

    rc4b3551 r2eab528  
    219219            if (measuredPeriod < _period - SLACK) {
    220220                // no need to coalesce (assuming we only try to do so once per minute)
    221                 if (_log.shouldLog(Log.DEBUG))
    222                     _log.debug("not coalescing, measuredPeriod = " + measuredPeriod + " period = " + _period);
     221                //if (_log.shouldLog(Log.DEBUG))
     222                //    _log.debug("not coalescing, measuredPeriod = " + measuredPeriod + " period = " + _period);
    223223                return;
    224224            }
  • core/java/src/net/i2p/time/Timestamper.java

    rc4b3551 r2eab528  
    317317        System.setProperty(PROP_QUERY_FREQUENCY, "30000");
    318318        I2PAppContext ctx = I2PAppContext.getGlobalContext();
    319         long now = ctx.clock().now();
    320319        for (int i = 0; i < 5*60*1000; i += 61*1000) {
    321320            try { Thread.sleep(61*1000); } catch (InterruptedException ie) {}
  • history.txt

    rc4b3551 r2eab528  
     12011-07-08 zzz
     2  * Findbugs: Several fixes and cleanups
     3  * I2NP: Consolidate common code from TunnelBuildMessage and
     4          TunnelBuildReplyMessage into a common base class
     5  * NetDB, TestJob: Fix NPEs at startup (ticket #493)
     6  * Sha256Standalone:
     7    - Use system SHA-256 MessageDigest instead of Sha256Standalone in PRNG
     8    - Deprecate DataHelper functions using Sha256Standalone arguments;
     9      used only by Syndie
     10    - Note deprecation in javadocs
     11
    1122011-07-07 zzz
    213  * Blockfile:
  • router/java/src/net/i2p/data/i2np/TunnelBuildMessage.java

    rc4b3551 r2eab528  
    44
    55import net.i2p.I2PAppContext;
    6 import net.i2p.data.ByteArray;
    76
    87/**
    9  *
     8 *  The basic build message with 8 records.
    109 */
    11 public class TunnelBuildMessage extends I2NPMessageImpl {
    12     protected ByteArray _records[];
    13     protected int RECORD_COUNT;
    14     public static final int MAX_RECORD_COUNT = 8;
    15    
     10public class TunnelBuildMessage extends TunnelBuildMessageBase {
     11
    1612    public static final int MESSAGE_TYPE = 21;
    1713
    1814    public TunnelBuildMessage(I2PAppContext context) {
    19         this(context, MAX_RECORD_COUNT);
     15        super(context, MAX_RECORD_COUNT);
    2016    }
    2117
    2218    /** @since 0.7.12 */
    2319    protected TunnelBuildMessage(I2PAppContext context, int records) {
    24         super(context);
    25         if (records > 0) {
    26             RECORD_COUNT = records;
    27             _records = new ByteArray[records];
    28         }
    29         // else will be initialized by readMessage() in VTBM
     20        super(context, records);
    3021    }
    3122
    32     public void setRecord(int index, ByteArray record) { _records[index] = record; }
    33     public ByteArray getRecord(int index) { return _records[index]; }
    34     /** @since 0.7.12 */
    35     public int getRecordCount() { return RECORD_COUNT; }
    36    
    37     public static final int RECORD_SIZE = 512+16;
    38    
    39     protected int calculateWrittenLength() { return RECORD_SIZE * RECORD_COUNT; }
    4023    public int getType() { return MESSAGE_TYPE; }
    41     public void readMessage(byte[] data, int offset, int dataSize, int type) throws I2NPMessageException, IOException {
    42         if (type != MESSAGE_TYPE)
    43             throw new I2NPMessageException("Message type is incorrect for this message");
    44         if (dataSize != calculateWrittenLength())
    45             throw new I2NPMessageException("Wrong length (expects " + calculateWrittenLength() + ", recv " + dataSize + ")");
    46        
    47         for (int i = 0; i < RECORD_COUNT; i++) {
    48             int off = offset + (i * RECORD_SIZE);
    49             byte rec[] = new byte[RECORD_SIZE];
    50             System.arraycopy(data, off, rec, 0, RECORD_SIZE);
    51             setRecord(i, new ByteArray(rec)); //new ByteArray(data, off, len));
    52         }
    53     }
    54    
    55     protected int writeMessageBody(byte[] out, int curIndex) throws I2NPMessageException {
    56         int remaining = out.length - (curIndex + calculateWrittenLength());
    57         if (remaining < 0)
    58             throw new I2NPMessageException("Not large enough (too short by " + remaining + ")");
    59         for (int i = 0; i < RECORD_COUNT; i++) {
    60             System.arraycopy(_records[i].getData(), _records[i].getOffset(), out, curIndex, RECORD_SIZE);
    61             curIndex += RECORD_SIZE;
    62         }
    63         return curIndex;
    64     }
    6524
    6625    @Override
  • router/java/src/net/i2p/data/i2np/TunnelBuildReplyMessage.java

    rc4b3551 r2eab528  
    44
    55import net.i2p.I2PAppContext;
    6 import net.i2p.data.ByteArray;
    76
    87/**
     8 *  The basic build reply message with 8 records.
    99 * Transmitted from the new outbound endpoint to the creator through a
    1010 * reply tunnel
    1111 */
    12 public class TunnelBuildReplyMessage extends I2NPMessageImpl {
    13     protected ByteArray _records[];
    14     protected int RECORD_COUNT;
    15     public static final int MAX_RECORD_COUNT = TunnelBuildMessage.MAX_RECORD_COUNT;
    16    
     12public class TunnelBuildReplyMessage extends TunnelBuildMessageBase {
     13
    1714    public static final int MESSAGE_TYPE = 22;
    1815
    1916    public TunnelBuildReplyMessage(I2PAppContext context) {
    20         this(context, MAX_RECORD_COUNT);
     17        super(context, MAX_RECORD_COUNT);
    2118    }
    2219
    2320    /** @since 0.7.12 */
    2421    protected TunnelBuildReplyMessage(I2PAppContext context, int records) {
    25         super(context);
    26         if (records > 0) {
    27             RECORD_COUNT = records;
    28             _records = new ByteArray[records];
    29         }
    30         // else will be initialized by readMessage() in VTBRM
     22        super(context, records);
    3123    }
    3224
    33     public void setRecord(int index, ByteArray record) { _records[index] = record; }
    34     public ByteArray getRecord(int index) { return _records[index]; }
    35     /** @since 0.7.12 */
    36     public int getRecordCount() { return RECORD_COUNT; }
    37    
    38     public static final int RECORD_SIZE = TunnelBuildMessage.RECORD_SIZE;
    39    
    40     protected int calculateWrittenLength() { return RECORD_SIZE * RECORD_COUNT; }
    4125    public int getType() { return MESSAGE_TYPE; }
    42     public void readMessage(byte[] data, int offset, int dataSize, int type) throws I2NPMessageException, IOException {
    43         if (type != MESSAGE_TYPE)
    44             throw new I2NPMessageException("Message type is incorrect for this message");
    45         if (dataSize != calculateWrittenLength())
    46             throw new I2NPMessageException("Wrong length (expects " + calculateWrittenLength() + ", recv " + dataSize + ")");
    47        
    48         for (int i = 0; i < RECORD_COUNT; i++) {
    49             int off = offset + (i * RECORD_SIZE);
    50             int len = RECORD_SIZE;
    51             byte rec[] = new byte[RECORD_SIZE];
    52             System.arraycopy(data, off, rec, 0, RECORD_SIZE);
    53             setRecord(i, new ByteArray(rec));
    54             //setRecord(i, new ByteArray(data, off, len));
    55         }
    56     }
    57    
    58     protected int writeMessageBody(byte[] out, int curIndex) throws I2NPMessageException {
    59         int remaining = out.length - (curIndex + calculateWrittenLength());
    60         if (remaining < 0)
    61             throw new I2NPMessageException("Not large enough (too short by " + remaining + ")");
    62         for (int i = 0; i < RECORD_COUNT; i++) {
    63             System.arraycopy(_records[i].getData(), _records[i].getOffset(), out, curIndex, RECORD_SIZE);
    64             curIndex += RECORD_SIZE;
    65         }
    66         return curIndex;
    67     }
    6826
    6927    @Override
  • router/java/src/net/i2p/data/i2np/VariableTunnelBuildMessage.java

    rc4b3551 r2eab528  
    88
    99/**
     10 * Variable number of records.
     11 *
    1012 * @since 0.7.12
    1113 */
     
    3032    @Override
    3133    public void readMessage(byte[] data, int offset, int dataSize, int type) throws I2NPMessageException, IOException {
    32         if (type != MESSAGE_TYPE)
    33             throw new I2NPMessageException("Message type is incorrect for this message");
     34        // message type will be checked in super()
    3435        int r = (int)DataHelper.fromLong(data, offset, 1);
    3536        if (r <= 0 || r > MAX_RECORD_COUNT)
     
    3940            throw new I2NPMessageException("Wrong length (expects " + calculateWrittenLength() + ", recv " + dataSize + ")");
    4041        _records = new ByteArray[RECORD_COUNT];
    41         super.readMessage(data, offset + 1, dataSize, TunnelBuildMessage.MESSAGE_TYPE);
     42        super.readMessage(data, offset + 1, dataSize, type);
    4243    }
    4344   
  • router/java/src/net/i2p/data/i2np/VariableTunnelBuildReplyMessage.java

    rc4b3551 r2eab528  
    99/**
    1010 * Transmitted from the new outbound endpoint to the creator through a
    11  * reply tunnel
     11 * reply tunnel.
     12 * Variable number of records.
    1213 *
    1314 * @since 0.7.12
     
    3132    public int getType() { return MESSAGE_TYPE; }
    3233
     34    @Override
    3335    public void readMessage(byte[] data, int offset, int dataSize, int type) throws I2NPMessageException, IOException {
    34         if (type != MESSAGE_TYPE)
    35             throw new I2NPMessageException("Message type is incorrect for this message");
     36        // message type will be checked in super()
    3637        int r = (int)DataHelper.fromLong(data, offset, 1);
    3738        if (r <= 0 || r > MAX_RECORD_COUNT)
     
    4142            throw new I2NPMessageException("Wrong length (expects " + calculateWrittenLength() + ", recv " + dataSize + ")");
    4243        _records = new ByteArray[RECORD_COUNT];
    43         super.readMessage(data, offset + 1, dataSize, TunnelBuildReplyMessage.MESSAGE_TYPE);
     44        super.readMessage(data, offset + 1, dataSize, type);
    4445    }
    4546   
     47    @Override
    4648    protected int writeMessageBody(byte[] out, int curIndex) throws I2NPMessageException {
    4749        int remaining = out.length - (curIndex + calculateWrittenLength());
  • router/java/src/net/i2p/router/RouterVersion.java

    rc4b3551 r2eab528  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 6;
     21    public final static long BUILD = 8;
    2222
    2323    /** for example "-test" */
  • router/java/src/net/i2p/router/networkdb/kademlia/FloodfillPeerSelector.java

    rc4b3551 r2eab528  
    2323import net.i2p.router.util.RandomIterator;
    2424import net.i2p.stat.Rate;
     25import net.i2p.stat.RateStat;
    2526import net.i2p.util.Log;
    2627
     
    202203                PeerProfile prof = _context.profileOrganizer().getProfile(entry);
    203204                double maxGoodRespTime = MAX_GOOD_RESP_TIME;
    204                 Rate tunnelTestTime = _context.statManager().getRate("tunnel.testSuccessTime").getRate(10*60*1000);
    205                 if (tunnelTestTime != null && tunnelTestTime.getAverageValue() > 500)
    206                     maxGoodRespTime = 2 * tunnelTestTime.getAverageValue();
     205                RateStat ttst = _context.statManager().getRate("tunnel.testSuccessTime");
     206                if (ttst != null) {
     207                    Rate tunnelTestTime = ttst.getRate(10*60*1000);
     208                    if (tunnelTestTime != null && tunnelTestTime.getAverageValue() > 500)
     209                        maxGoodRespTime = 2 * tunnelTestTime.getAverageValue();
     210                }
    207211                if (prof != null && prof.getDBHistory() != null
    208212                    && prof.getDbResponseTime().getRate(10*60*1000).getAverageValue() < maxGoodRespTime
  • router/java/src/net/i2p/router/networkdb/kademlia/KBucketImpl.java

    rc4b3551 r2eab528  
    380380   
    381381    private static void testRand() {
    382         StringBuilder buf = new StringBuilder(2048);
     382        //StringBuilder buf = new StringBuilder(2048);
    383383        int low = 1;
    384384        int high = 3;
  • router/java/src/net/i2p/router/tunnel/pool/TestJob.java

    rc4b3551 r2eab528  
    2020import net.i2p.router.message.GarlicMessageBuilder;
    2121import net.i2p.router.message.PayloadGarlicConfig;
     22import net.i2p.stat.Rate;
     23import net.i2p.stat.RateStat;
    2224import net.i2p.util.Log;
    2325
     
    220222        // Try to prevent congestion collapse (failing all our tunnels and then clogging our outbound
    221223        // with new tunnel build requests) by adding in three times the average outbound delay.
    222         int delay = 3 * (int) getContext().statManager().getRate("transport.sendProcessingTime").getRate(60*1000).getAverageValue();
    223         return delay + (2500 * (_outTunnel.getLength() + _replyTunnel.getLength()));
     224        RateStat tspt = getContext().statManager().getRate("transport.sendProcessingTime");
     225        if (tspt != null) {
     226            Rate r = tspt.getRate(60*1000);
     227            if (r != null) {
     228                int delay = 3 * (int) r.getAverageValue();
     229                return delay + (2500 * (_outTunnel.getLength() + _replyTunnel.getLength()));
     230            }
     231        }
     232        return 15*1000;
    224233    }
    225234
Note: See TracChangeset for help on using the changeset viewer.