propagate from branch 'i2p.i2p' (head bd037c8b542fe0f6125aa16fb3bff5d257b4e955)

to branch 'i2p.i2p.str4d.ui' (head 9bd4080121d8ef662d6a2e4dfe7fae1079b32646)
This commit is contained in:
str4d
2017-02-10 16:43:25 +00:00
224 changed files with 4915 additions and 596 deletions

View File

@@ -104,7 +104,7 @@ public interface IRandomStandalone extends Cloneable {
*
* @param attributes a set of name-value pairs that describe the desired
* future instance behaviour.
* @exception IllegalArgumentException if at least one of the defined name/
* @throws IllegalArgumentException if at least one of the defined name/
* value pairs contains invalid data.
*/
void init(Map<String, byte[]> attributes);
@@ -113,8 +113,8 @@ public interface IRandomStandalone extends Cloneable {
* <p>Returns the next 8 bits of random data generated from this instance.</p>
*
* @return the next 8 bits of random data generated from this instance.
* @exception IllegalStateException if the instance is not yet initialised.
* @exception LimLimitReachedExceptionStandalone this instance has reached its
* @throws IllegalStateException if the instance is not yet initialised.
* @throws LimitReachedExceptionStandalone this instance has reached its
* theoretical limit for generating non-repetitive pseudo-random data.
*/
byte nextByte() throws IllegalStateException, LimitReachedExceptionStandalone;
@@ -130,8 +130,8 @@ public interface IRandomStandalone extends Cloneable {
* <code>out.length</code>.
* @param length the maximum number of required random bytes. This method
* does nothing if this parameter is less than <code>1</code>.
* @exception IllegalStateException if the instance is not yet initialised.
* @exception LimitLimitReachedExceptionStandalonehis instance has reached its
* @throws IllegalStateException if the instance is not yet initialised.
* @throws LimitReachedExceptionStandalone this instance has reached its
* theoretical limit for generating non-repetitive pseudo-random data.
*/
void nextBytes(byte[] out, int offset, int length)
@@ -172,7 +172,7 @@ public interface IRandomStandalone extends Cloneable {
* @param in The buffer of new random bytes to add.
* @param offset The offset from whence to begin reading random bytes.
* @param length The number of random bytes to add.
* @exception IndexOutOfBoundsException If <i>offset</i>, <i>length</i>,
* @throws IndexOutOfBoundsException If <i>offset</i>, <i>length</i>,
* or <i>offset</i>+<i>length</i> is out of bounds.
*/
void addRandomBytes(byte[] in, int offset, int length);

View File

@@ -336,7 +336,7 @@ import java.text.MessageFormat;
* break;
* }
* //
* for (int i = g.getOptind(); i < argv.length ; i++)
* for (int i = g.getOptind(); i &lt; argv.length ; i++)
* System.out.println("Non option argv element: " + argv[i] + "\n");
* </pre>
* <p>

View File

@@ -117,7 +117,7 @@ private ResourceBundle _messages = ResourceBundle.getBundle(
* @param flag If non-null, this is a location to store the value of "val" when this option is encountered, otherwise "val" is treated as the equivalent short option character.
* @param val The value to return for this long option, or the equivalent single letter option to emulate if flag is null.
*
* @exception IllegalArgumentException If the has_arg param is not one of NO_ARGUMENT, REQUIRED_ARGUMENT or OPTIONAL_ARGUMENT.
* @throws IllegalArgumentException If the has_arg param is not one of NO_ARGUMENT, REQUIRED_ARGUMENT or OPTIONAL_ARGUMENT.
*/
public
LongOpt(String name, int has_arg,

View File

@@ -47,7 +47,7 @@ public interface I2PClient {
public static final SigType DEFAULT_SIGTYPE = SigType.DSA_SHA1;
/**
* For router->client payloads.
* For router-&gt;client payloads.
*
* If false, the router will send the MessageStatus,
* the client must respond with a ReceiveMessageBegin,

View File

@@ -73,7 +73,7 @@ public interface I2PSession {
* End-to-End Crypto is disabled, tags and keys are ignored!
*
* Like sendMessage above, except the key used and the tags sent are exposed to the
* application. <p />
* application. <p>
*
* If some application layer message delivery confirmation is used,
* rather than i2p's (slow) built in confirmation via guaranteed delivery mode, the
@@ -331,7 +331,7 @@ public interface I2PSession {
* Suggested implementation:
*
*<pre>
* if (name.length() == 60 && name.toLowerCase(Locale.US).endsWith(".b32.i2p")) {
* if (name.length() == 60 &amp;&amp; name.toLowerCase(Locale.US).endsWith(".b32.i2p")) {
* if (session != null)
* return session.lookup(Hash.create(Base32.decode(name.toLowerCase(Locale.US).substring(0, 52))));
* else

View File

@@ -31,6 +31,7 @@ import net.i2p.util.Log;
public final class I2PDatagramDissector {
private static final int DGRAM_BUFSIZE = 32768;
private static final int MIN_DGRAM_SIZE = 387 + 40;
private final DSAEngine dsaEng = DSAEngine.getInstance();
private final SHA256Generator hashGen = SHA256Generator.getInstance();
@@ -68,9 +69,12 @@ public final class I2PDatagramDissector {
* @throws DataFormatException If there's an error in the datagram format
*/
public void loadI2PDatagram(byte[] dgram) throws DataFormatException {
ByteArrayInputStream dgStream = new ByteArrayInputStream(dgram);
// set invalid(very important!)
this.valid = false;
if (dgram.length < MIN_DGRAM_SIZE)
throw new DataFormatException("repliable datagram too small: " + dgram.length);
ByteArrayInputStream dgStream = new ByteArrayInputStream(dgram);
try {
// read destination
@@ -96,8 +100,9 @@ public final class I2PDatagramDissector {
rxHash = null;
}
} catch (IOException e) {
Log log = I2PAppContext.getGlobalContext().logManager().getLog(I2PDatagramDissector.class);
log.error("Error loading datagram", e);
// let the application do the logging
//Log log = I2PAppContext.getGlobalContext().logManager().getLog(I2PDatagramDissector.class);
//log.error("Error loading datagram", e);
throw new DataFormatException("Error loading datagram", e);
//} catch(AssertionError e) {
// Log log = I2PAppContext.getGlobalContext().logManager().getLog(I2PDatagramDissector.class);

View File

@@ -27,7 +27,7 @@ import net.i2p.data.i2cp.SetDateMessage;
* @author jrandom
*/
class I2PClientMessageHandlerMap {
/** map of message type id --> I2CPMessageHandler */
/** map of message type id --&gt; I2CPMessageHandler */
protected I2CPMessageHandler _handlers[];
/** for extension */

View File

@@ -124,7 +124,7 @@ public abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2
/** class that generates new messages */
protected final I2CPMessageProducer _producer;
/** map of Long --> MessagePayloadMessage */
/** map of Long --&gt; MessagePayloadMessage */
protected Map<Long, MessagePayloadMessage> _availableMessages;
/** hashes of lookups we are waiting for */

View File

@@ -34,17 +34,17 @@ import net.i2p.util.Log;
* Therefore the compatibility situation is as follows:
*
* Compatibility:
* old streaming -> new streaming: sends proto anything, rcvs proto anything
* new streaming -> old streaming: sends PROTO_STREAMING, ignores rcvd proto
* old datagram -> new datagram: sends proto anything, rcvs proto anything
* new datagram -> old datagram: sends PROTO_DATAGRAM, ignores rcvd proto
* old streaming -&gt; new streaming: sends proto anything, rcvs proto anything
* new streaming -&gt; old streaming: sends PROTO_STREAMING, ignores rcvd proto
* old datagram -&gt; new datagram: sends proto anything, rcvs proto anything
* new datagram -&gt; old datagram: sends PROTO_DATAGRAM, ignores rcvd proto
* In all the above cases, streaming and datagram receive traffic for the other
* protocol, same as before.
*
* old datagram -> new muxed: doesn't work because the old sends proto 0 but the udp side
* old datagram -&gt; new muxed: doesn't work because the old sends proto 0 but the udp side
* of the mux registers with PROTO_DATAGRAM, so the datagrams
* go to the streaming side, same as before.
* old streaming -> new muxed: works
* old streaming -&gt; new muxed: works
*
* Typical Usage:
* Streaming + datagrams:
@@ -421,7 +421,7 @@ class I2PSessionMuxedImpl extends I2PSessionImpl2 {
/**
* No, we couldn't put any protocol byte in front of everything and
* keep backward compatibility. But there are several bytes that
* are unused AND unchecked in the gzip header in releases <= 0.7.
* are unused AND unchecked in the gzip header in releases &lt;= 0.7.
* So let's use 5 of them for a protocol and two 2-byte ports.
*
* Following are all the methods to hide the

View File

@@ -534,7 +534,7 @@ public abstract class NamingService {
* See also lookup(Hash, int).
*
* @param hostname must be {52 chars}.b32.i2p
* @param timeout in seconds; <= 0 means use router default
* @param timeout in seconds; &lt;= 0 means use router default
* @return dest or null
* @since 0.8.7
*/
@@ -546,7 +546,7 @@ public abstract class NamingService {
* Same as lookupBase32() but with the SHA256 Hash precalculated
* This implementation returns null.
*
* @param timeout in seconds; <= 0 means use router default
* @param timeout in seconds; &lt;= 0 means use router default
* @return dest or null
* @since 0.8.7
*/

View File

@@ -371,7 +371,7 @@ public final class CryptixRijndael_Algorithm // implicit no-argument constructor
* session key, assuming Rijndael's default block size (128-bit).
*
* @param k The 128/192/256-bit user-key to use.
* @exception InvalidKeyException If the key is invalid.
* @throws InvalidKeyException If the key is invalid.
*/
public static final Object makeKey(byte[] k) throws InvalidKeyException {
return makeKey(k, _BLOCK_SIZE);
@@ -550,7 +550,7 @@ public final class CryptixRijndael_Algorithm // implicit no-argument constructor
*
* @param k The 128/192/256-bit user-key to use.
* @param blockSize The block size in bytes of this Rijndael.
* @exception InvalidKeyException If the key is invalid.
* @throws InvalidKeyException If the key is invalid.
*/
public static final/* synchronized */Object makeKey(byte[] k, int blockSize) throws InvalidKeyException {
return makeKey(k, blockSize, null);

View File

@@ -5,7 +5,8 @@ import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
/**
* Moved from CryptixAESEngine and net.i2p.router.tasks.CryptoChecker
* Moved from CryptixAESEngine and net.i2p.router.tasks.CryptoChecker.
* This class does not do any logging. See CryptoChecker for the logging.
*
* @since 0.9.23
*/
@@ -28,6 +29,33 @@ public class CryptoCheck {
unlimited = true;
} catch (GeneralSecurityException gse) {
}
} catch (ExceptionInInitializerError eiie) {
// Java 9 b134 bug
// > java -jar build/i2p.jar cryptocheck
// Exception in thread "main" java.lang.ExceptionInInitializerError
// at javax.crypto.JceSecurityManager.<clinit>(java.base@9-Ubuntu/JceSecurityManager.java:65)
// at javax.crypto.Cipher.getConfiguredPermission(java.base@9-Ubuntu/Cipher.java:2595)
// at javax.crypto.Cipher.getMaxAllowedKeyLength(java.base@9-Ubuntu/Cipher.java:2619)
// at net.i2p.crypto.CryptoCheck.<clinit>(CryptoCheck.java:19)
// at java.lang.Class.forName0(java.base@9-Ubuntu/Native Method)
// at java.lang.Class.forName(java.base@9-Ubuntu/Class.java:374)
// at net.i2p.util.CommandLine.exec(CommandLine.java:66)
// at net.i2p.util.CommandLine.main(CommandLine.java:51)
// Caused by: java.lang.SecurityException: Can not initialize cryptographic mechanism
// at javax.crypto.JceSecurity.<clinit>(java.base@9-Ubuntu/JceSecurity.java:91)
// ... 8 more
// Caused by: java.lang.NullPointerException
// at sun.nio.fs.UnixPath.normalizeAndCheck(java.base@9-Ubuntu/UnixPath.java:75)
// at sun.nio.fs.UnixPath.<init>(java.base@9-Ubuntu/UnixPath.java:69)
// at sun.nio.fs.UnixFileSystem.getPath(java.base@9-Ubuntu/UnixFileSystem.java:280)
// at java.nio.file.Paths.get(java.base@9-Ubuntu/Paths.java:84)
// at javax.crypto.JceSecurity.setupJurisdictionPolicies(java.base@9-Ubuntu/JceSecurity.java:254)
// at javax.crypto.JceSecurity.access$000(java.base@9-Ubuntu/JceSecurity.java:49)
// at javax.crypto.JceSecurity$1.run(java.base@9-Ubuntu/JceSecurity.java:82)
// at javax.crypto.JceSecurity$1.run(java.base@9-Ubuntu/JceSecurity.java:79)
// at java.security.AccessController.doPrivileged(java.base@9-Ubuntu/Native Method)
// at javax.crypto.JceSecurity.<clinit>(java.base@9-Ubuntu/JceSecurity.java:78)
// ... 8 more
}
_isUnlimited = unlimited;
}

View File

@@ -429,11 +429,11 @@ public final class ElGamalAESEngine {
*
* In the router, we always use garlic messages. A garlic message with a single
* clove and zero data is about 84 bytes, so that's 123 bytes minimum. So any paddingSize
* <= 128 is a no-op as every message will be at least 128 bytes
* &lt;= 128 is a no-op as every message will be at least 128 bytes
* (Streaming, if used, adds more overhead).
*
* Outside the router, with a client using its own message format, the minimum size
* is 48, so any paddingSize <= 48 is a no-op.
* is 48, so any paddingSize &lt;= 48 is a no-op.
*
* Not included in the minimum is a 32-byte session tag for an existing session,
* or a 514-byte ElGamal block and several 32-byte session tags for a new session.

View File

@@ -28,8 +28,8 @@ import net.i2p.util.SystemVersion;
*
* <p>The FIPS PUB 180-2 standard specifies four secure hash algorithms (SHA-1,
* SHA-256, SHA-384 and SHA-512) for computing a condensed representation of
* electronic data (message). When a message of any length < 2^^64 bits (for
* SHA-1 and SHA-256) or < 2^^128 bits (for SHA-384 and SHA-512) is input to
* electronic data (message). When a message of any length &lt; 2^^64 bits (for
* SHA-1 and SHA-256) or &lt; 2^^128 bits (for SHA-384 and SHA-512) is input to
* an algorithm, the result is an output called a message digest. The message
* digests range in length from 160 to 512 bits, depending on the algorithm.
* Secure hash algorithms are typically used with other cryptographic
@@ -62,7 +62,7 @@ import net.i2p.util.SystemVersion;
* http://www.itl.nist.gov/div897/pubs/fip180-1.htm</a></li>
* <li> Bruce Schneier, "Section 18.7 Secure Hash Algorithm (SHA)",
* <cite>Applied Cryptography, 2nd edition</cite>, <br>
* John Wiley & Sons, 1996</li>
* John Wiley &amp; Sons, 1996</li>
* </ol>
*/
public final class SHA1 extends MessageDigest implements Cloneable {

View File

@@ -435,7 +435,7 @@ public final class EdDSAEngine extends Signature {
}
/**
* @deprecated replaced with <a href="#engineSetParameter(java.security.spec.AlgorithmParameterSpec)">
* @deprecated replaced with <a href="#engineSetParameter(java.security.spec.AlgorithmParameterSpec)">this</a>
*/
@Override
protected void engineSetParameter(String param, Object value) {

View File

@@ -33,6 +33,7 @@ public class GroupElement implements Serializable {
* <li>P1P1: Completed representation ((X:Z), (Y:T)) satisfying x=X/Z, y=Y/T.
* <li>PRECOMP: Precomputed representation (y+x, y-x, 2dxy).
* <li>CACHED: Cached representation (Y+X, Y-X, Z, 2dT)
* </ul>
*/
public enum Representation {
/** Projective (P^2): (X:Y:Z) satisfying x=X/Z, y=Y/Z */
@@ -220,6 +221,7 @@ public class GroupElement implements Serializable {
* <li>If v * β = -u multiply β with i=sqrt(-1).
* <li>Set x := β.
* <li>If sign(x) != bit 255 of s then negate x.
* </ul>
*
* @param curve The curve.
* @param s The encoded point.
@@ -860,7 +862,7 @@ public class GroupElement implements Serializable {
* Constant time.
* <p>
* Preconditions: (TODO: Check this applies here)
* a[31] <= 127
* a[31] &lt;= 127
* @param a = a[0]+256*a[1]+...+256^31 a[31]
* @return the GroupElement
*/

View File

@@ -58,6 +58,7 @@ public class Ed25519FieldElement extends FieldElement {
* Postconditions:
* <p><ul>
* <li>|h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
* </ul>
*
* @param val The field element to add.
* @return The field element this + val.
@@ -86,6 +87,7 @@ public class Ed25519FieldElement extends FieldElement {
* Postconditions:
* <p><ul>
* <li>|h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
* </ul>
*
* @param val The field element to subtract.
* @return The field element this - val.
@@ -111,6 +113,7 @@ public class Ed25519FieldElement extends FieldElement {
* Postconditions:
* <p><ul>
* <li>|h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
* </ul>
*
* @return The field element (-1) * this.
*/

View File

@@ -18,22 +18,22 @@ public class Ed25519LittleEndianEncoding extends Encoding {
* Assumption:
* <p><ul>
* <li>p = 2^255 - 19
* <li>h = h0 + 2^25 * h1 + 2^(26+25) * h2 + ... + 2^230 * h9 where 0 <= |hi| < 2^27 for all i=0,...,9.
* <li>h congruent r modulo p, i.e. h = r + q * p for some suitable 0 <= r < p and an integer q.
* <li>h = h0 + 2^25 * h1 + 2^(26+25) * h2 + ... + 2^230 * h9 where 0 &lt;= |hi| &lt; 2^27 for all i=0,...,9.
* <li>h congruent r modulo p, i.e. h = r + q * p for some suitable 0 &lt;= r &lt; p and an integer q.
* </ul><p>
* Then q = [2^-255 * (h + 19 * 2^-25 * h9 + 1/2)] where [x] = floor(x).
* <p>
* Proof:
* <p>
* We begin with some very raw estimation for the bounds of some expressions:
* <pre>|h| < 2^230 * 2^30 = 2^260 ==> |r + q * p| < 2^260 ==> |q| < 2^10.
* ==> -1/4 <= a := 19^2 * 2^-255 * q < 1/4.
* |h - 2^230 * h9| = |h0 + ... + 2^204 * h8| < 2^204 * 2^30 = 2^234.
* ==> -1/4 <= b := 19 * 2^-255 * (h - 2^230 * h9) < 1/4</pre>
* Therefore 0 < 1/2 - a - b < 1.
* <pre>|h| &lt; 2^230 * 2^30 = 2^260 ==&gt; |r + q * p| &lt; 2^260 ==&gt; |q| &lt; 2^10.
* ==&gt; -1/4 &lt;= a := 19^2 * 2^-255 * q &lt; 1/4.
* |h - 2^230 * h9| = |h0 + ... + 2^204 * h8| &lt; 2^204 * 2^30 = 2^234.
* ==&gt; -1/4 &lt;= b := 19 * 2^-255 * (h - 2^230 * h9) &lt; 1/4</pre>
* Therefore 0 &lt; 1/2 - a - b &lt; 1.
* <p>
* Set x := r + 19 * 2^-255 * r + 1/2 - a - b then
* 0 <= x < 255 - 20 + 19 + 1 = 2^255 ==> 0 <= 2^-255 * x < 1. Since q is an integer we have
* 0 &lt;= x &lt; 255 - 20 + 19 + 1 = 2^255 ==&gt; 0 &lt;= 2^-255 * x &lt; 1. Since q is an integer we have
*
* <pre>[q + 2^-255 * x] = q (1)</pre>
* <p>
@@ -213,6 +213,7 @@ public class Ed25519LittleEndianEncoding extends Encoding {
* Preconditions:
* <p><ul>
* <li>|x| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
* </ul>
*
* @return true if x is in {1,3,5,...,q-2}, false otherwise.
*/

View File

@@ -147,7 +147,7 @@ public final class ElGamalSigEngine extends Signature {
}
/**
* @deprecated replaced with <a href="#engineSetParameter(java.security.spec.AlgorithmParameterSpec)">
* @deprecated replaced with <a href="#engineSetParameter(java.security.spec.AlgorithmParameterSpec)">this</a>
*/
@Override
protected void engineSetParameter(String param, Object value) {

View File

@@ -116,7 +116,7 @@ public class Certificate extends DataStructureImpl {
}
/**
* @throws IllegalArgumentException if type < 0
* @throws IllegalArgumentException if type &lt; 0
*/
public Certificate(int type, byte[] payload) {
if (type < 0)
@@ -131,7 +131,7 @@ public class Certificate extends DataStructureImpl {
}
/**
* @throws IllegalArgumentException if type < 0
* @throws IllegalArgumentException if type &lt; 0
* @throws IllegalStateException if already set
*/
public void setCertificateType(int type) {

View File

@@ -736,7 +736,7 @@ public class DataHelper {
* @param src if null returns 0
* @param numBytes 1-8
* @return non-negative
* @throws AIOOBE
* @throws ArrayIndexOutOfBoundsException
* @throws IllegalArgumentException if negative (only possible if numBytes = 8)
*/
public static long fromLong(byte src[], int offset, int numBytes) {
@@ -760,7 +760,7 @@ public class DataHelper {
*
* @param numBytes 1-8
* @return non-negative
* @throws AIOOBE
* @throws ArrayIndexOutOfBoundsException
* @throws IllegalArgumentException if negative (only possible if numBytes = 8)
* @since 0.8.12
*/
@@ -1006,7 +1006,7 @@ public class DataHelper {
/**
* Helper util to compare two objects, including null handling.
* <p />
* <p>
*
* This treats (null == null) as true, and (null == (!null)) as false.
*/
@@ -1021,10 +1021,10 @@ public class DataHelper {
/**
* Run a deep comparison across the two collections.
* <p />
* <p>
*
* This treats (null == null) as true, (null == (!null)) as false, and then
* comparing each element via eq(object, object). <p />
* comparing each element via eq(object, object). <p>
*
* If the size of the collections are not equal, the comparison returns false.
* The collection order should be consistent, as this simply iterates across both and compares
@@ -1043,7 +1043,7 @@ public class DataHelper {
}
/**
* Run a comparison on the byte arrays, byte by byte. <p />
* Run a comparison on the byte arrays, byte by byte. <p>
*
* This treats (null == null) as true, (null == (!null)) as false,
* and unequal length arrays as false.
@@ -1627,7 +1627,7 @@ public class DataHelper {
/**
* Compress the data and return a new GZIP compressed byte array.
* @throws IllegalArgumentException if size is over 40KB
* @throws IllegalArgumentException if input size is over 40KB
*/
public static byte[] compress(byte orig[]) {
return compress(orig, 0, orig.length);

View File

@@ -47,7 +47,7 @@ public class Hash extends SimpleDataStructure {
/**
* Pull from cache or return new
* @throws AIOOBE if not enough bytes
* @throws ArrayIndexOutOfBoundsException if not enough bytes
* @since 0.8.3
*/
public static Hash create(byte[] data, int off) {

View File

@@ -253,7 +253,7 @@ public class PrivateKeyFile {
}
/**
* @param padding null OK, must be non-null if spubkey length < 128
* @param padding null OK, must be non-null if spubkey length &lt; 128
* @throws IllegalArgumentException on mismatch of spubkey and spk types
* @since 0.9.16
*/

View File

@@ -29,7 +29,7 @@ public class PublicKey extends SimpleDataStructure {
* Pull from cache or return new.
* Deprecated - used only by deprecated Destination.readBytes(data, off)
*
* @throws AIOOBE if not enough bytes, FIXME should throw DataFormatException
* @throws ArrayIndexOutOfBoundsException if not enough bytes, FIXME should throw DataFormatException
* @since 0.8.3
*/
public static PublicKey create(byte[] data, int off) {

View File

@@ -25,7 +25,7 @@ import net.i2p.util.SystemVersion;
* Following is sample usage:
* <pre>
private static final SDSCache<Foo> _cache = new SDSCache(Foo.class, LENGTH, 1024);
private static final SDSCache&lt;Foo&gt; _cache = new SDSCache(Foo.class, LENGTH, 1024);
public static Foo create(byte[] data) {
return _cache.get(data);
@@ -113,7 +113,7 @@ public class SDSCache<V extends SimpleDataStructure> {
* @return the cached value if available, otherwise
* makes a new object and returns it
* @throws IllegalArgumentException if data is not the correct number of bytes
* @throws NPE
* @throws NullPointerException
*/
public V get(byte[] data) {
if (data == null)
@@ -155,8 +155,8 @@ public class SDSCache<V extends SimpleDataStructure> {
* @param off offset in the array to start reading from
* @return the cached value if available, otherwise
* makes a new object and returns it
* @throws AIOOBE if not enough bytes
* @throws NPE
* @throws ArrayIndexOutOfBoundsException if not enough bytes
* @throws NullPointerException
*/
public V get(byte[] b, int off) {
byte[] data = SimpleByteCache.acquire(_datalen);

View File

@@ -40,7 +40,7 @@ public class SigningPublicKey extends SimpleDataStructure {
* Pull from cache or return new.
* Deprecated - used only by deprecated Destination.readBytes(data, off)
*
* @throws AIOOBE if not enough bytes, FIXME should throw DataFormatException
* @throws ArrayIndexOutOfBoundsException if not enough bytes, FIXME should throw DataFormatException
* @since 0.8.3
*/
public static SigningPublicKey create(byte[] data, int off) {
@@ -150,7 +150,7 @@ public class SigningPublicKey extends SimpleDataStructure {
* Get the portion of this (type 0) SPK that is really padding based on the Key Cert type given,
* if any
*
* @return leading padding length > 0 or null if no padding or type is unknown
* @return leading padding length &gt; 0 or null if no padding or type is unknown
* @throws IllegalArgumentException if this is already typed to a different type
* @since 0.9.12
*/

View File

@@ -28,7 +28,7 @@ public abstract class I2CPMessageImpl extends DataStructureImpl implements I2CPM
}
/**
* Validate the type and size of the message, and then read the message into the data structures. <p />
* Validate the type and size of the message, and then read the message into the data structures. <p>
*
* @throws IOException
*/

View File

@@ -44,7 +44,7 @@ public class RequestVariableLeaseSetMessage extends I2CPMessageImpl {
* Does the client support this message?
*
* @param clientVersion may be null
* @return version != null and version >= 0.9.7
* @return version != null and version &gt;= 0.9.7
*/
public static boolean isSupported(String clientVersion) {
return clientVersion != null &&

View File

@@ -34,7 +34,7 @@ import net.i2p.util.ConcurrentHashSet;
* The keys are kept in a Set and are NOT sorted by last-seen.
* Per-key last-seen-time, failures, etc. must be tracked elsewhere.
*
* If this bucket is full (i.e. begin == end && size == max)
* If this bucket is full (i.e. begin == end &amp;&amp; size == max)
* then add() will call KBucketTrimmer.trim() do
* (possibly) remove older entries, and indicate whether
* to add the new entry. If the trimmer returns true without

View File

@@ -72,9 +72,9 @@ public class KBucketSet<T extends SimpleDataStructure> {
* Use the default trim strategy, which removes a random entry.
* @param us the local identity (typically a SHA1Hash or Hash)
* The class must have a zero-argument constructor.
* @param max the Kademlia value "k", the max per bucket, k >= 4
* @param max the Kademlia value "k", the max per bucket, k &gt;= 4
* @param b the Kademlia value "b", split buckets an extra 2**(b-1) times,
* b > 0, use 1 for bittorrent, Kademlia paper recommends 5
* b &gt; 0, use 1 for bittorrent, Kademlia paper recommends 5
*/
public KBucketSet(I2PAppContext context, T us, int max, int b) {
this(context, us, max, b, new RandomTrimmer<T>(context, max));
@@ -168,7 +168,7 @@ public class KBucketSet<T extends SimpleDataStructure> {
/**
* No lock required.
* FIXME will split the closest buckets too far if B > 1 and K < 2**B
* FIXME will split the closest buckets too far if B &gt; 1 and K &lt; 2**B
* Won't ever really happen and if it does it still works.
*/
private boolean shouldSplit(KBucket<T> b) {
@@ -625,7 +625,7 @@ public class KBucketSet<T extends SimpleDataStructure> {
/**
* Make a new SimpleDataStrucure from the data
* @param data size <= SDS length, else throws IAE
* @param data size &lt;= SDS length, else throws IAE
* Can be 1 bigger if top byte is zero
*/
@SuppressWarnings("unchecked")

View File

@@ -138,7 +138,7 @@ public class Rate {
/**
* Create a new rate and load its state from the properties, taking data
* from the data points underneath the given prefix. <p />
* from the data points underneath the given prefix. <p>
* (e.g. prefix = "profile.dbIntroduction.60m", this will load the associated data points such
* as "profile.dbIntroduction.60m.lifetimeEventCount"). The data can be exported
* through store(outputStream, "profile.dbIntroduction.60m").

View File

@@ -38,10 +38,10 @@ public class RateAverages {
/**
* @since 0.9.4
* @return one of several things:
* if there are any events (current or last) => weighted average
* if there are any events (current or last) =&gt; weighted average
* otherwise if the useLifetime parameter to Rate.computeAverages was:
* true => the lifetime average value
* false => zero
* true =&gt; the lifetime average value
* false =&gt; zero
*/
public double getAverage() {
return average;

View File

@@ -58,6 +58,19 @@ public abstract class Addresses {
return !getAddresses(true, false, false).isEmpty();
}
/**
* Do we have any non-loop, non-wildcard IPv6 address at all?
* @since 0.9.29
*/
public static boolean isConnectedIPv6() {
// not as good as using a Java DBus implementation to talk to NetworkManager...
for (String ip : getAddresses(false, true)) {
if (ip.contains(":"))
return true;
}
return false;
}
/** @return the first non-local address IPv4 address it finds, or null */
public static String getAnyAddress() {
SortedSet<String> a = getAddresses();
@@ -599,6 +612,7 @@ public abstract class Addresses {
} catch (UnknownHostException uhe) {}
System.out.println(buf.toString());
}
System.out.println("\nIs connected? " + isConnected());
System.out.println("\nIs connected? " + isConnected() +
"\nHas IPv6? " + isConnectedIPv6());
}
}

View File

@@ -607,9 +607,9 @@ public class EepGet {
/**
* Blocking fetch.
*
* @param fetchHeaderTimeout <= 0 for none (proxy will timeout if none, none isn't recommended if no proxy)
* @param totalTimeout <= 0 for default none
* @param inactivityTimeout <= 0 for default 60 sec
* @param fetchHeaderTimeout &lt;= 0 for none (proxy will timeout if none, none isn't recommended if no proxy)
* @param totalTimeout &lt;= 0 for default none
* @param inactivityTimeout &lt;= 0 for default 60 sec
*/
public boolean fetch(long fetchHeaderTimeout, long totalTimeout, long inactivityTimeout) {
_fetchHeaderTimeout = (int) Math.min(fetchHeaderTimeout, Integer.MAX_VALUE);

View File

@@ -13,7 +13,7 @@ import java.util.Set;
/**
* Event dispatching interface. It allows objects to receive and
* notify data events (basically String->Object associations) and
* notify data events (basically String-&gt;Object associations) and
* create notification chains. To ease the usage of this interface,
* you could define an EventDispatcherImpl attribute called
* <code>_event</code> (as suggested in EventDispatcherImpl documentation)

View File

@@ -31,7 +31,7 @@ public class InternalServerSocket extends ServerSocket {
//private static Log _log = I2PAppContext.getGlobalContext().logManager().getLog(InternalServerSocket.class);
/**
* @param port > 0
* @param port &gt; 0
*/
public InternalServerSocket(int port) throws IOException {
if (port <= 0)
@@ -87,7 +87,7 @@ public class InternalServerSocket extends ServerSocket {
/**
* This is how the client connects.
*
* @param port > 0
* @param port &gt; 0
*/
static void internalConnect(int port, InternalSocket clientSock) throws IOException {
InternalServerSocket iss = _sockets.get(Integer.valueOf(port));

View File

@@ -26,7 +26,7 @@ public class InternalSocket extends Socket {
/**
* client side
* @param port > 0
* @param port &gt; 0
*/
public InternalSocket(int port) throws IOException {
if (port <= 0)
@@ -36,7 +36,7 @@ public class InternalSocket extends Socket {
/**
* Convenience method to return either a Socket or an InternalSocket
* @param port > 0
* @param port &gt; 0
*/
public static Socket getSocket(String host, int port) throws IOException {
if (System.getProperty("router.version") != null &&

View File

@@ -206,20 +206,22 @@ public class Log {
}
/**
* logs a loop when closing a resource with level INFO
* logs a loop when closing a resource with level DEBUG
* This method is for debugging purposes only and
* as such subject to change or removal w/o notice.
* is subject to change or removal w/o notice.
* NOT a supported API.
* @param desc vararg description
* @since 0.9.8
*/
public void logCloseLoop(Object... desc) {
logCloseLoop(Log.INFO, desc);
logCloseLoop(Log.DEBUG, desc);
}
/**
* Logs a close loop when closing a resource
* This method is for debugging purposes only and
* as such subject to change or removal w/o notice.
* is subject to change or removal w/o notice.
* NOT a supported API.
* @param desc vararg description of the resource
* @param level level at which to log
* @since 0.9.8

View File

@@ -44,7 +44,7 @@ public class ObjectCounter<K> implements Serializable {
}
/**
* @return set of objects with counts > 0
* @return set of objects with counts &gt; 0
*/
public Set<K> objects() {
return this.map.keySet();

View File

@@ -50,7 +50,7 @@ public class PortMapper {
/**
* Add the service
* @param port > 0
* @param port &gt; 0
* @return success, false if already registered
*/
public boolean register(String service, int port) {
@@ -59,7 +59,7 @@ public class PortMapper {
/**
* Add the service
* @param port > 0
* @param port &gt; 0
* @return success, false if already registered
* @since 0.9.21
*/

View File

@@ -63,18 +63,18 @@ public class ReusableGZIPInputStream extends ResettableGZIPInputStream {
private static void test() {
byte b[] = "hi, how are you today?".getBytes();
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream(64);
GZIPOutputStream o = new GZIPOutputStream(baos);
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(64);
ResettableGZIPOutputStream o = new ResettableGZIPOutputStream(baos);
o.write(b);
o.finish();
o.flush();
byte compressed[] = baos.toByteArray();
ReusableGZIPInputStream in = ReusableGZIPInputStream.acquire();
in.initialize(new ByteArrayInputStream(compressed));
in.initialize(new java.io.ByteArrayInputStream(compressed));
byte rv[] = new byte[128];
int read = in.read(rv);
if (!DataHelper.eq(rv, 0, b, 0, b.length))
if (!net.i2p.data.DataHelper.eq(rv, 0, b, 0, b.length))
throw new RuntimeException("foo, read=" + read);
else
System.out.println("match, w00t");
@@ -84,18 +84,18 @@ public class ReusableGZIPInputStream extends ResettableGZIPInputStream {
private static boolean test(int size) {
byte b[] = new byte[size];
new java.util.Random().nextBytes(b);
RandomSource.getInstance().nextBytes(b);
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream(size);
GZIPOutputStream o = new GZIPOutputStream(baos);
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(size);
ResettableGZIPOutputStream o = new ResettableGZIPOutputStream(baos);
o.write(b);
o.finish();
o.flush();
byte compressed[] = baos.toByteArray();
ReusableGZIPInputStream in = ReusableGZIPInputStream.acquire();
in.initialize(new ByteArrayInputStream(compressed));
ByteArrayOutputStream baos2 = new ByteArrayOutputStream(size);
in.initialize(new java.io.ByteArrayInputStream(compressed));
java.io.ByteArrayOutputStream baos2 = new java.io.ByteArrayOutputStream(size);
byte rbuf[] = new byte[128];
try {
while (true) {
@@ -104,9 +104,9 @@ public class ReusableGZIPInputStream extends ResettableGZIPInputStream {
break;
baos2.write(rbuf, 0, read);
}
} catch (IOException ioe) {
} catch (java.io.IOException ioe) {
ioe.printStackTrace();
long crcVal = in.getCurrentCRCVal();
//long crcVal = in.getCurrentCRCVal();
//try { in.verifyFooter(); } catch (IOException ioee) {
// ioee.printStackTrace();
//}
@@ -120,10 +120,10 @@ public class ReusableGZIPInputStream extends ResettableGZIPInputStream {
if (rv.length != b.length)
throw new RuntimeException("read length: " + rv.length + " expected: " + b.length);
if (!DataHelper.eq(rv, 0, b, 0, b.length)) {
if (!net.i2p.data.DataHelper.eq(rv, 0, b, 0, b.length)) {
throw new RuntimeException("foo, read=" + rv.length);
} else {
System.out.println("match, w00t");
System.out.println("match, w00t @ " + size);
return true;
}
} catch (Exception e) {

View File

@@ -89,7 +89,7 @@ public class ReusableGZIPOutputStream extends ResettableGZIPOutputStream {
try {
for (int i = 0; i < 2; i++)
test();
for (int i = 500; i < 64*1024; i++) {
for (int i = 0; i < 64*1024; i++) {
if (!test(i)) break;
}
} catch (Exception e) { e.printStackTrace(); }
@@ -106,7 +106,7 @@ public class ReusableGZIPOutputStream extends ResettableGZIPOutputStream {
byte compressed[] = o.getData();
ReusableGZIPOutputStream.release(o);
GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(compressed));
ResettableGZIPInputStream in = new ResettableGZIPInputStream(new java.io.ByteArrayInputStream(compressed));
byte rv[] = new byte[128];
int read = in.read(rv);
if (!DataHelper.eq(rv, 0, b, 0, b.length))
@@ -118,7 +118,7 @@ public class ReusableGZIPOutputStream extends ResettableGZIPOutputStream {
private static boolean test(int size) {
byte b[] = new byte[size];
new java.util.Random().nextBytes(b);
RandomSource.getInstance().nextBytes(b);
try {
ReusableGZIPOutputStream o = ReusableGZIPOutputStream.acquire();
o.write(b);
@@ -127,8 +127,8 @@ public class ReusableGZIPOutputStream extends ResettableGZIPOutputStream {
byte compressed[] = o.getData();
ReusableGZIPOutputStream.release(o);
GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(compressed));
ByteArrayOutputStream baos2 = new ByteArrayOutputStream(256*1024);
ResettableGZIPInputStream in = new ResettableGZIPInputStream(new java.io.ByteArrayInputStream(compressed));
ByteArrayOutputStream baos2 = new ByteArrayOutputStream(size);
byte rbuf[] = new byte[128];
while (true) {
int read = in.read(rbuf);

View File

@@ -271,6 +271,7 @@ public class SSLEepGet extends EepGet {
X509TrustManager defaultTrustManager = (X509TrustManager)tmf.getTrustManagers()[0];
_stm = new SavingTrustManager(defaultTrustManager);
sslc.init(null, new TrustManager[] {_stm}, null);
/****
if (_log.shouldLog(Log.DEBUG)) {
SSLEngine eng = sslc.createSSLEngine();
SSLParameters params = sslc.getDefaultSSLParameters();
@@ -315,9 +316,14 @@ public class SSLEepGet extends EepGet {
_log.debug(s[i]);
}
}
****/
return sslc;
} catch (GeneralSecurityException gse) {
_log.error("Key Store update error", gse);
} catch (ExceptionInInitializerError eiie) {
// java 9 b134 see ../crypto/CryptoCheck for example
// Catching this may be pointless, fetch still fails
_log.error("SSL context error - Java 9 bug?", eiie);
}
return null;
}

View File

@@ -208,8 +208,8 @@ public class SimpleTimer2 {
* state of a given TimedEvent
*
* valid transitions:
* {IDLE,CANCELLED,RUNNING} -> SCHEDULED [ -> SCHEDULED ]* -> RUNNING -> {IDLE,CANCELLED,SCHEDULED}
* {IDLE,CANCELLED,RUNNING} -> SCHEDULED [ -> SCHEDULED ]* -> CANCELLED
* {IDLE,CANCELLED,RUNNING} -&gt; SCHEDULED [ -&gt; SCHEDULED ]* -&gt; RUNNING -&gt; {IDLE,CANCELLED,SCHEDULED}
* {IDLE,CANCELLED,RUNNING} -&gt; SCHEDULED [ -&gt; SCHEDULED ]* -&gt; CANCELLED
*
* anything else is invalid.
*/
@@ -231,10 +231,10 @@ public class SimpleTimer2 {
* in your constructor)
*
* Other porting:
* SimpleTimer.getInstance().addEvent(new foo(), timeout) => new foo(SimpleTimer2.getInstance(), timeout)
* SimpleTimer.getInstance().addEvent(this, timeout) => schedule(timeout)
* SimpleTimer.getInstance().addEvent(foo, timeout) => foo.reschedule(timeout)
* SimpleTimer.getInstance().removeEvent(foo) => foo.cancel()
* SimpleTimer.getInstance().addEvent(new foo(), timeout) =&gt; new foo(SimpleTimer2.getInstance(), timeout)
* SimpleTimer.getInstance().addEvent(this, timeout) =&gt; schedule(timeout)
* SimpleTimer.getInstance().addEvent(foo, timeout) =&gt; foo.reschedule(timeout)
* SimpleTimer.getInstance().removeEvent(foo) =&gt; foo.cancel()
*
* There's no global locking, but for scheduling, we synchronize on this
* to reduce the chance of duplicates on the queue.

View File

@@ -20,6 +20,7 @@ public abstract class SystemVersion {
* @since 0.9.28
*/
public static final String DAEMON_USER = "i2psvc";
public static final String GENTOO_USER = "i2p";
private static final boolean _isWin = System.getProperty("os.name").startsWith("Win");
private static final boolean _isMac = System.getProperty("os.name").startsWith("Mac");
@@ -63,7 +64,8 @@ public abstract class SystemVersion {
String runtime = System.getProperty("java.runtime.name");
_isOpenJDK = runtime != null && runtime.contains("OpenJDK");
_isLinuxService = !_isWin && !_isMac && !_isAndroid &&
DAEMON_USER.equals(System.getProperty("user.name"));
(DAEMON_USER.equals(System.getProperty("user.name")) ||
(_isGentoo && GENTOO_USER.equals(System.getProperty("user.name"))));
int sdk = 0;
if (_isAndroid) {
@@ -149,7 +151,7 @@ public abstract class SystemVersion {
}
/**
* Better than (new VersionComparator()).compare(System.getProperty("java.version"), "1.6") >= 0
* Better than (new VersionComparator()).compare(System.getProperty("java.version"), "1.6") &gt;= 0
* as it handles Android also, where java.version = "0".
*
* @return true if Java 1.6 or higher, or Android API 9 or higher
@@ -159,7 +161,7 @@ public abstract class SystemVersion {
}
/**
* Better than (new VersionComparator()).compare(System.getProperty("java.version"), "1.7") >= 0
* Better than (new VersionComparator()).compare(System.getProperty("java.version"), "1.7") &gt;= 0
* as it handles Android also, where java.version = "0".
*
* @return true if Java 1.7 or higher, or Android API 19 or higher
@@ -193,8 +195,8 @@ public abstract class SystemVersion {
* http://mark.koli.ch/2009/10/javas-osarch-system-property-is-the-bitness-of-the-jre-not-the-operating-system.html
* http://mark.koli.ch/2009/10/reliably-checking-os-bitness-32-or-64-bit-on-windows-with-a-tiny-c-app.html
* sun.arch.data.model not on all JVMs
* sun.arch.data.model == 64 => 64 bit processor
* sun.arch.data.model == 32 => A 32 bit JVM but could be either 32 or 64 bit processor or libs
* sun.arch.data.model == 64 =&gt; 64 bit processor
* sun.arch.data.model == 32 =&gt; A 32 bit JVM but could be either 32 or 64 bit processor or libs
* os.arch contains "64" could be 32 or 64 bit libs
*/
public static boolean is64Bit() {

View File

@@ -67,7 +67,7 @@ public abstract class Translate {
*
* @param s string to be translated containing {0}
* The {0} will be replaced by the parameter.
* Single quotes must be doubled, i.e. ' -> '' in the string.
* Single quotes must be doubled, i.e. ' -&gt; '' in the string.
* @param o parameter, not translated.
* To translate parameter also, use _t("foo {0} bar", _t("baz"))
* Do not double the single quotes in the parameter.

View File

@@ -37,7 +37,7 @@ public abstract class ZipFileComment {
* @return empty string if no comment, or the comment.
* The string is decoded with UTF-8
*
* @throws IOE if no valid end-of-central-directory record found
* @throws IOException if no valid end-of-central-directory record found
*/
public static String getComment(File file, int max) throws IOException {
return getComment(file, max, 0);
@@ -53,7 +53,7 @@ public abstract class ZipFileComment {
* @return empty string if no comment, or the comment.
* The string is decoded with UTF-8
*
* @throws IOE if no valid end-of-central-directory record found
* @throws IOException if no valid end-of-central-directory record found
*/
public static String getComment(File file, int max, int skip) throws IOException {
if (!file.exists())

View File

@@ -337,7 +337,7 @@ public class BlockFile implements Closeable {
/**
* Go to any page but the superblock.
* Page 1 is the superblock, must use file.seek(0) to get there.
* @param page >= 2
* @param page &gt;= 2
*/
public static void pageSeek(RandomAccessInterface file, int page) throws IOException {
if (page < METAINDEX_PAGE)

View File

@@ -221,6 +221,7 @@ public class BSkipList<K extends Comparable<? super K>, V> extends SkipList<K, V
}
****/
/** find */
@Override
public SkipIterator<K, V> find(K key) {
if (!this.fileOnly)

View File

@@ -38,7 +38,7 @@ public interface Mac
* Initialise the MAC.
*
* @param key the key required by the MAC.
* @exception IllegalArgumentException if the params argument is
* @throws IllegalArgumentException if the params argument is
* inappropriate.
*/
public void init(byte key[])
@@ -62,7 +62,7 @@ public interface Mac
* add a single byte to the mac for processing.
*
* @param in the byte to be processed.
* @exception IllegalStateException if the MAC is not initialised.
* @throws IllegalStateException if the MAC is not initialised.
*/
public void update(byte in)
throws IllegalStateException;
@@ -71,7 +71,7 @@ public interface Mac
* @param in the array containing the input.
* @param inOff the index in the array the data begins at.
* @param len the length of the input starting at inOff.
* @exception IllegalStateException if the MAC is not initialised.
* @throws IllegalStateException if the MAC is not initialised.
*/
public void update(byte[] in, int inOff, int len)
throws IllegalStateException;
@@ -84,7 +84,7 @@ public interface Mac
*
* @param out the array the MAC is to be output to.
* @param outOff the offset into the out buffer the output is to start at.
* @exception IllegalStateException if the MAC is not initialised.
* @throws IllegalStateException if the MAC is not initialised.
*/
public int doFinal(byte[] out, int outOff)
throws IllegalStateException;