forked from I2P_Developers/i2p.i2p
Doing something different this time -- but only to core
I marked all the empty statements with //nop I removed unneccessary elses (ie, the if returns or throws) I took out some casts (integral promotions/some didn't need to be there) -- Love, shendaras (2 in one day, w00t)
This commit is contained in:
@ -187,7 +187,7 @@ public class ATalk implements I2PSessionListener, Runnable {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Thread.sleep(5000);
|
Thread.sleep(5000);
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) { // nop!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -302,7 +302,7 @@ public class ATalk implements I2PSessionListener, Runnable {
|
|||||||
_log.debug("Keys generation failed");
|
_log.debug("Keys generation failed");
|
||||||
try {
|
try {
|
||||||
Thread.sleep(5000);
|
Thread.sleep(5000);
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) { // nop
|
||||||
}
|
}
|
||||||
} else if (args.length == 3) {
|
} else if (args.length == 3) {
|
||||||
_log.debug("Starting chat");
|
_log.debug("Starting chat");
|
||||||
@ -320,7 +320,7 @@ public class ATalk implements I2PSessionListener, Runnable {
|
|||||||
System.out.println(MANUAL);
|
System.out.println(MANUAL);
|
||||||
try {
|
try {
|
||||||
Thread.sleep(5000);
|
Thread.sleep(5000);
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) { // nop
|
||||||
}
|
}
|
||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
}
|
}
|
||||||
|
@ -223,7 +223,7 @@ class ConnectionRunner implements I2CPMessageReader.I2CPMessageEventListener {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void sessionCreated() {
|
protected void sessionCreated() { // nop
|
||||||
}
|
}
|
||||||
|
|
||||||
protected SessionConfig getConfig() {
|
protected SessionConfig getConfig() {
|
||||||
|
@ -252,7 +252,7 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
|
|||||||
synchronized (_dateReceivedLock) {
|
synchronized (_dateReceivedLock) {
|
||||||
_dateReceivedLock.wait(1000);
|
_dateReceivedLock.wait(1000);
|
||||||
}
|
}
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) { // nop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_log.shouldLog(Log.DEBUG)) _log.debug(getPrefix() + "After received a SetDate response");
|
if (_log.shouldLog(Log.DEBUG)) _log.debug(getPrefix() + "After received a SetDate response");
|
||||||
@ -266,7 +266,7 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
|
|||||||
synchronized (_leaseSetWait) {
|
synchronized (_leaseSetWait) {
|
||||||
try {
|
try {
|
||||||
_leaseSetWait.wait(1000);
|
_leaseSetWait.wait(1000);
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) { // nop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -375,7 +375,8 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
|
|||||||
if (_pendingIds.size() <= 0) {
|
if (_pendingIds.size() <= 0) {
|
||||||
try {
|
try {
|
||||||
AvailabilityNotifier.this.wait();
|
AvailabilityNotifier.this.wait();
|
||||||
} catch (InterruptedException ie) {}
|
} catch (InterruptedException ie) { // nop
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (_pendingIds.size() > 0) {
|
if (_pendingIds.size() > 0) {
|
||||||
msgId = (Integer)_pendingIds.remove(0);
|
msgId = (Integer)_pendingIds.remove(0);
|
||||||
@ -480,7 +481,7 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
|
|||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug(getPrefix() + "Message written out and flushed w/ "
|
_log.debug(getPrefix() + "Message written out and flushed w/ "
|
||||||
+ (inSync-beforeSync) + "ms to sync and "
|
+ (inSync-beforeSync) + "ms to sync and "
|
||||||
+ (afterSync-inSync) + "ms to send");;
|
+ (afterSync-inSync) + "ms to send");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -551,9 +552,8 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
|
|||||||
if (reconnect()) {
|
if (reconnect()) {
|
||||||
if (_log.shouldLog(Log.INFO)) _log.info(getPrefix() + "I2CP reconnection successful");
|
if (_log.shouldLog(Log.INFO)) _log.info(getPrefix() + "I2CP reconnection successful");
|
||||||
return;
|
return;
|
||||||
} else {
|
|
||||||
if (_log.shouldLog(Log.ERROR)) _log.error(getPrefix() + "I2CP reconnection failed");
|
|
||||||
}
|
}
|
||||||
|
if (_log.shouldLog(Log.ERROR)) _log.error(getPrefix() + "I2CP reconnection failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_log.shouldLog(Log.ERROR))
|
if (_log.shouldLog(Log.ERROR))
|
||||||
|
@ -76,9 +76,8 @@ class I2PSessionImpl2 extends I2PSessionImpl {
|
|||||||
// as well as the nonblocking sends with application managed keys. Later.
|
// as well as the nonblocking sends with application managed keys. Later.
|
||||||
if (isGuaranteed() || true) {
|
if (isGuaranteed() || true) {
|
||||||
return sendGuaranteed(dest, payload, keyUsed, tagsSent);
|
return sendGuaranteed(dest, payload, keyUsed, tagsSent);
|
||||||
} else {
|
|
||||||
return sendBestEffort(dest, payload, keyUsed, tagsSent);
|
|
||||||
}
|
}
|
||||||
|
return sendBestEffort(dest, payload, keyUsed, tagsSent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -94,9 +93,8 @@ class I2PSessionImpl2 extends I2PSessionImpl {
|
|||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
throw new I2PSessionException("Error decompressing message", ioe);
|
throw new I2PSessionException("Error decompressing message", ioe);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return compressed;
|
|
||||||
}
|
}
|
||||||
|
return compressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean sendBestEffort(Destination dest, byte payload[], SessionKey keyUsed, Set tagsSent)
|
private boolean sendBestEffort(Destination dest, byte payload[], SessionKey keyUsed, Set tagsSent)
|
||||||
@ -116,7 +114,7 @@ class I2PSessionImpl2 extends I2PSessionImpl {
|
|||||||
if (false) // rekey
|
if (false) // rekey
|
||||||
newKey = _context.keyGenerator().generateSessionKey();
|
newKey = _context.keyGenerator().generateSessionKey();
|
||||||
|
|
||||||
long nonce = (long)_context.random().nextInt(Integer.MAX_VALUE);
|
long nonce = _context.random().nextInt(Integer.MAX_VALUE);
|
||||||
MessageState state = new MessageState(nonce, getPrefix());
|
MessageState state = new MessageState(nonce, getPrefix());
|
||||||
state.setKey(key);
|
state.setKey(key);
|
||||||
state.setTags(sentTags);
|
state.setTags(sentTags);
|
||||||
@ -196,7 +194,7 @@ class I2PSessionImpl2 extends I2PSessionImpl {
|
|||||||
if (false) // rekey
|
if (false) // rekey
|
||||||
newKey = _context.keyGenerator().generateSessionKey();
|
newKey = _context.keyGenerator().generateSessionKey();
|
||||||
|
|
||||||
long nonce = (long)_context.random().nextInt(Integer.MAX_VALUE);
|
long nonce = _context.random().nextInt(Integer.MAX_VALUE);
|
||||||
MessageState state = new MessageState(nonce, getPrefix());
|
MessageState state = new MessageState(nonce, getPrefix());
|
||||||
state.setKey(key);
|
state.setKey(key);
|
||||||
state.setTags(sentTags);
|
state.setTags(sentTags);
|
||||||
|
@ -127,7 +127,7 @@ class MessageState {
|
|||||||
synchronized (_lock) {
|
synchronized (_lock) {
|
||||||
try {
|
try {
|
||||||
_lock.wait(timeToWait);
|
_lock.wait(timeToWait);
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) { // nop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -163,13 +163,11 @@ class MessageState {
|
|||||||
case MessageStatusMessage.STATUS_SEND_ACCEPTED:
|
case MessageStatusMessage.STATUS_SEND_ACCEPTED:
|
||||||
if (wantedStatus == MessageStatusMessage.STATUS_SEND_ACCEPTED) {
|
if (wantedStatus == MessageStatusMessage.STATUS_SEND_ACCEPTED) {
|
||||||
return true; // if we're only looking for accepted, take it directly (don't let any GUARANTEED_* override it)
|
return true; // if we're only looking for accepted, take it directly (don't let any GUARANTEED_* override it)
|
||||||
} else {
|
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
|
||||||
_log.debug(_prefix + "Got accepted, but we're waiting for more from "
|
|
||||||
+ toString());
|
|
||||||
continue;
|
|
||||||
// ignore accepted, as we want something better
|
|
||||||
}
|
}
|
||||||
|
// ignore accepted, as we want something better
|
||||||
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
|
_log.debug(_prefix + "Got accepted, but we're waiting for more from " + toString());
|
||||||
|
continue;
|
||||||
case MessageStatusMessage.STATUS_SEND_BEST_EFFORT_SUCCESS:
|
case MessageStatusMessage.STATUS_SEND_BEST_EFFORT_SUCCESS:
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug(_prefix + "Received best effort success after " + getElapsed()
|
_log.debug(_prefix + "Received best effort success after " + getElapsed()
|
||||||
|
@ -64,7 +64,7 @@ public class TestClient implements I2PSessionListener {
|
|||||||
while ((_dest1 == null) || (_dest2 == null))
|
while ((_dest1 == null) || (_dest2 == null))
|
||||||
try {
|
try {
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) { // nop
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isDest1) {
|
if (isDest1) {
|
||||||
@ -79,12 +79,12 @@ public class TestClient implements I2PSessionListener {
|
|||||||
try {
|
try {
|
||||||
_log.debug("waiting for a message...");
|
_log.debug("waiting for a message...");
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) { // nop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Thread.sleep(5000);
|
Thread.sleep(5000);
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) { // nop
|
||||||
}
|
}
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
@ -98,7 +98,7 @@ public class TestClient implements I2PSessionListener {
|
|||||||
doTest();
|
doTest();
|
||||||
try {
|
try {
|
||||||
Thread.sleep(30 * 1000);
|
Thread.sleep(30 * 1000);
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) { // nop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ public class TestServer implements Runnable {
|
|||||||
* Fire up the router
|
* Fire up the router
|
||||||
*/
|
*/
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
if (args.length == 1) {
|
if (args.length == 1) { // nop
|
||||||
} else if (args.length == 2) {
|
} else if (args.length == 2) {
|
||||||
try {
|
try {
|
||||||
LISTEN_PORT = Integer.parseInt(args[1]);
|
LISTEN_PORT = Integer.parseInt(args[1]);
|
||||||
|
@ -46,7 +46,8 @@ public final class I2PDatagramDissector {
|
|||||||
/**
|
/**
|
||||||
* Crate a new I2P repliable datagram dissector.
|
* Crate a new I2P repliable datagram dissector.
|
||||||
*/
|
*/
|
||||||
public I2PDatagramDissector() {}
|
public I2PDatagramDissector() { // nop
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load an I2P repliable datagram into the dissector.
|
* Load an I2P repliable datagram into the dissector.
|
||||||
|
@ -61,7 +61,7 @@ public class HostsTxtNamingService extends NamingService {
|
|||||||
} finally {
|
} finally {
|
||||||
if (fis != null) try {
|
if (fis != null) try {
|
||||||
fis.close();
|
fis.close();
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) { // nop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String res = hosts.getProperty(hostname);
|
String res = hosts.getProperty(hostname);
|
||||||
|
@ -35,7 +35,8 @@ public abstract class NamingService {
|
|||||||
protected NamingService(I2PAppContext context) {
|
protected NamingService(I2PAppContext context) {
|
||||||
_context = context;
|
_context = context;
|
||||||
}
|
}
|
||||||
private NamingService() {}
|
private NamingService() { // nop
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Look up a host name.
|
* Look up a host name.
|
||||||
|
@ -73,30 +73,27 @@ public class AESInputStream extends FilterInputStream {
|
|||||||
Integer nval = getNext();
|
Integer nval = getNext();
|
||||||
if (nval != null) {
|
if (nval != null) {
|
||||||
return nval.intValue();
|
return nval.intValue();
|
||||||
} else {
|
}
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("No byte available. eof? " + _eofFound);
|
_log.debug("No byte available. eof? " + _eofFound);
|
||||||
|
|
||||||
if (_eofFound)
|
if (_eofFound)
|
||||||
return -1;
|
return -1;
|
||||||
else {
|
|
||||||
throw new IOException("Not EOF, but none available? " + _readyBuf.size() + "/" + _encryptedBuf.size()
|
throw new IOException("Not EOF, but none available? " + _readyBuf.size() + "/" + _encryptedBuf.size()
|
||||||
+ "/" + _cumulativeRead + "... impossible");
|
+ "/" + _cumulativeRead + "... impossible");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int read(byte dest[]) throws IOException {
|
public int read(byte dest[]) throws IOException {
|
||||||
for (int i = 0; i < dest.length; i++) {
|
for (int i = 0; i < dest.length; i++) {
|
||||||
int val = read();
|
int val = read();
|
||||||
if (val == -1) {
|
if (val == -1) {
|
||||||
// no more to read... can they expect more?
|
// no more to read... can they expect more?
|
||||||
if (_eofFound && (i == 0))
|
if (_eofFound && (i == 0)) return -1;
|
||||||
return -1;
|
|
||||||
else
|
|
||||||
return i;
|
return i;
|
||||||
} else {
|
|
||||||
dest[i] = (byte) val;
|
|
||||||
}
|
}
|
||||||
|
dest[i] = (byte) val;
|
||||||
}
|
}
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Read the full buffer of size " + dest.length);
|
_log.debug("Read the full buffer of size " + dest.length);
|
||||||
@ -141,7 +138,7 @@ public class AESInputStream extends FilterInputStream {
|
|||||||
+ encrypted + " still encrypted]");
|
+ encrypted + " still encrypted]");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void mark(int readLimit) {
|
public void mark(int readLimit) { // nop
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reset() throws IOException {
|
public void reset() throws IOException {
|
||||||
@ -159,9 +156,9 @@ public class AESInputStream extends FilterInputStream {
|
|||||||
private Integer getNext() {
|
private Integer getNext() {
|
||||||
if (_readyBuf.size() > 0) {
|
if (_readyBuf.size() > 0) {
|
||||||
return (Integer) _readyBuf.remove(0);
|
return (Integer) _readyBuf.remove(0);
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -240,7 +237,7 @@ public class AESInputStream extends FilterInputStream {
|
|||||||
byte data[] = DataHelper.xor(decrypted, _lastBlock);
|
byte data[] = DataHelper.xor(decrypted, _lastBlock);
|
||||||
int cleaned[] = stripPadding(data);
|
int cleaned[] = stripPadding(data);
|
||||||
for (int j = 0; j < cleaned.length; j++) {
|
for (int j = 0; j < cleaned.length; j++) {
|
||||||
if (((int) cleaned[j]) <= 0) {
|
if (cleaned[j] <= 0) {
|
||||||
cleaned[j] += 256;
|
cleaned[j] += 256;
|
||||||
//_log.error("(modified: " + cleaned[j] + ")");
|
//_log.error("(modified: " + cleaned[j] + ")");
|
||||||
}
|
}
|
||||||
@ -258,7 +255,7 @@ public class AESInputStream extends FilterInputStream {
|
|||||||
+ " bytes back onto the buffer, lets delay 1s our action so we don't fast busy until the net transfers data");
|
+ " bytes back onto the buffer, lets delay 1s our action so we don't fast busy until the net transfers data");
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) { // nop
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//_log.debug("No remaining encrypted bytes beyond the block size");
|
//_log.debug("No remaining encrypted bytes beyond the block size");
|
||||||
@ -280,7 +277,7 @@ public class AESInputStream extends FilterInputStream {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private int[] stripPadding(byte data[]) throws IOException {
|
private int[] stripPadding(byte data[]) throws IOException {
|
||||||
int numPadBytes = (int) data[data.length - 1];
|
int numPadBytes = data[data.length - 1];
|
||||||
if ((numPadBytes >= data.length) || (numPadBytes <= 0)) {
|
if ((numPadBytes >= data.length) || (numPadBytes <= 0)) {
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("stripPadding from block " + DataHelper.toHexString(data) + " (" + data.length + "bytes): "
|
_log.debug("stripPadding from block " + DataHelper.toHexString(data) + " (" + data.length + "bytes): "
|
||||||
@ -363,7 +360,7 @@ public class AESInputStream extends FilterInputStream {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(30 * 1000);
|
Thread.sleep(30 * 1000);
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) { // nop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,15 +166,14 @@ public final class CryptixRijndael_Algorithm // implicit no-argument constructor
|
|||||||
t++;
|
t++;
|
||||||
if (t == 4)
|
if (t == 4)
|
||||||
throw new RuntimeException("G matrix is not invertible");
|
throw new RuntimeException("G matrix is not invertible");
|
||||||
else {
|
|
||||||
for (j = 0; j < 8; j++) {
|
for (j = 0; j < 8; j++) {
|
||||||
tmp = AA[i][j];
|
tmp = AA[i][j];
|
||||||
AA[i][j] = AA[t][j];
|
AA[i][j] = AA[t][j];
|
||||||
AA[t][j] = (byte) tmp;
|
AA[t][j] = tmp;
|
||||||
}
|
}
|
||||||
pivot = AA[i][i];
|
pivot = AA[i][i];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
for (j = 0; j < 8; j++)
|
for (j = 0; j < 8; j++)
|
||||||
if (AA[i][j] != 0) AA[i][j] = (byte) _alog[(255 + _log[AA[i][j] & 0xFF] - _log[pivot & 0xFF]) % 255];
|
if (AA[i][j] != 0) AA[i][j] = (byte) _alog[(255 + _log[AA[i][j] & 0xFF] - _log[pivot & 0xFF]) % 255];
|
||||||
for (t = 0; t < 4; t++)
|
for (t = 0; t < 4; t++)
|
||||||
|
@ -266,7 +266,7 @@ public class DHSessionKeyBuilder {
|
|||||||
RandomSource.getInstance().nextBoolean(); // warm it up
|
RandomSource.getInstance().nextBoolean(); // warm it up
|
||||||
try {
|
try {
|
||||||
Thread.sleep(20 * 1000);
|
Thread.sleep(20 * 1000);
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) { // nop
|
||||||
}
|
}
|
||||||
I2PAppContext ctx = new I2PAppContext();
|
I2PAppContext ctx = new I2PAppContext();
|
||||||
_log.debug("\n\n\n\nBegin test\n");
|
_log.debug("\n\n\n\nBegin test\n");
|
||||||
@ -303,7 +303,7 @@ public class DHSessionKeyBuilder {
|
|||||||
_log.debug("Negotiation time for 5 runs: " + negTime + " @ " + negTime / 5l + "ms each");
|
_log.debug("Negotiation time for 5 runs: " + negTime + " @ " + negTime / 5l + "ms each");
|
||||||
try {
|
try {
|
||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) { // nop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -329,7 +329,7 @@ public class DHSessionKeyBuilder {
|
|||||||
// for some relief...
|
// for some relief...
|
||||||
try {
|
try {
|
||||||
Thread.sleep(CALC_DELAY);
|
Thread.sleep(CALC_DELAY);
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) { // nop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -343,7 +343,7 @@ public class DHSessionKeyBuilder {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Thread.sleep(30 * 1000);
|
Thread.sleep(30 * 1000);
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) { // nop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -157,7 +157,7 @@ public class DSAEngine {
|
|||||||
k += 512;
|
k += 512;
|
||||||
}
|
}
|
||||||
int padbytes = k / 8;
|
int padbytes = k / 8;
|
||||||
int wordlength = (int) (source.length / 4 + padbytes / 4 + 3);
|
int wordlength = source.length / 4 + padbytes / 4 + 3;
|
||||||
int[] M0 = new int[wordlength];
|
int[] M0 = new int[wordlength];
|
||||||
int wordcount = 0;
|
int wordcount = 0;
|
||||||
int x = 0;
|
int x = 0;
|
||||||
|
@ -97,11 +97,10 @@ public class DummyElGamalEngine extends ElGamalEngine {
|
|||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Hash matches: " + DataHelper.toString(hash.getData(), hash.getData().length));
|
_log.debug("Hash matches: " + DataHelper.toString(hash.getData(), hash.getData().length));
|
||||||
return rv;
|
return rv;
|
||||||
} else {
|
}
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Doesn't match hash [calc=" + calcHash + " sent hash=" + hash + "]\ndata = " + new String(rv),
|
_log.debug("Doesn't match hash [calc=" + calcHash + " sent hash=" + hash + "]\ndata = " + new String(rv),
|
||||||
new Exception("Doesn't match"));
|
new Exception("Doesn't match"));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
@ -37,7 +37,9 @@ public class ElGamalAESEngine {
|
|||||||
private final static int MIN_ENCRYPTED_SIZE = 80; // smallest possible resulting size
|
private final static int MIN_ENCRYPTED_SIZE = 80; // smallest possible resulting size
|
||||||
private I2PAppContext _context;
|
private I2PAppContext _context;
|
||||||
|
|
||||||
private ElGamalAESEngine() {}
|
private ElGamalAESEngine() { // nop
|
||||||
|
}
|
||||||
|
|
||||||
public ElGamalAESEngine(I2PAppContext ctx) {
|
public ElGamalAESEngine(I2PAppContext ctx) {
|
||||||
_context = ctx;
|
_context = ctx;
|
||||||
|
|
||||||
@ -217,14 +219,13 @@ public class ElGamalAESEngine {
|
|||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Decrypt with a non session tag, but tags read: " + foundTags.size());
|
_log.debug("Decrypt with a non session tag, but tags read: " + foundTags.size());
|
||||||
return decryptNewSession(data, targetPrivateKey, foundTags, usedKey, foundKey);
|
return decryptNewSession(data, targetPrivateKey, foundTags, usedKey, foundKey);
|
||||||
} else {
|
}
|
||||||
// existing session decrypted successfully!
|
// existing session decrypted successfully!
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Decrypt with an EXISTING session tag successfull, # tags read: " + foundTags.size(),
|
_log.debug("Decrypt with an EXISTING session tag successfull, # tags read: " + foundTags.size(),
|
||||||
new Exception("Decrypted by"));
|
new Exception("Decrypted by"));
|
||||||
return decrypted;
|
return decrypted;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decrypt the AES data with the session key and IV. The result should be:
|
* Decrypt the AES data with the session key and IV. The result should be:
|
||||||
@ -292,9 +293,9 @@ public class ElGamalAESEngine {
|
|||||||
foundTags.addAll(tags);
|
foundTags.addAll(tags);
|
||||||
if (newKey != null) foundKey.setData(newKey.getData());
|
if (newKey != null) foundKey.setData(newKey.getData());
|
||||||
return unencrData;
|
return unencrData;
|
||||||
} else {
|
|
||||||
throw new Exception("Hash does not match");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw new Exception("Hash does not match");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (_log.shouldLog(Log.WARN)) _log.warn("Unable to decrypt AES block", e);
|
if (_log.shouldLog(Log.WARN)) _log.warn("Unable to decrypt AES block", e);
|
||||||
return null;
|
return null;
|
||||||
@ -321,13 +322,12 @@ public class ElGamalAESEngine {
|
|||||||
_log.info("Current tag is null, encrypting as new session", new Exception("encrypt new"));
|
_log.info("Current tag is null, encrypting as new session", new Exception("encrypt new"));
|
||||||
_context.statManager().updateFrequency("crypto.elGamalAES.encryptNewSession");
|
_context.statManager().updateFrequency("crypto.elGamalAES.encryptNewSession");
|
||||||
return encryptNewSession(data, target, key, tagsForDelivery, newKey, paddedSize);
|
return encryptNewSession(data, target, key, tagsForDelivery, newKey, paddedSize);
|
||||||
} else {
|
}
|
||||||
if (_log.shouldLog(Log.INFO))
|
if (_log.shouldLog(Log.INFO))
|
||||||
_log.info("Current tag is NOT null, encrypting as existing session", new Exception("encrypt existing"));
|
_log.info("Current tag is NOT null, encrypting as existing session", new Exception("encrypt existing"));
|
||||||
_context.statManager().updateFrequency("crypto.elGamalAES.encryptExistingSession");
|
_context.statManager().updateFrequency("crypto.elGamalAES.encryptExistingSession");
|
||||||
return encryptExistingSession(data, target, key, tagsForDelivery, currentTag, newKey, paddedSize);
|
return encryptExistingSession(data, target, key, tagsForDelivery, currentTag, newKey, paddedSize);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encrypt the data to the target using the given key and deliver the specified tags
|
* Encrypt the data to the target using the given key and deliver the specified tags
|
||||||
|
@ -75,7 +75,9 @@ public class ElGamalEngine {
|
|||||||
_context = context;
|
_context = context;
|
||||||
_log = context.logManager().getLog(ElGamalEngine.class);
|
_log = context.logManager().getLog(ElGamalEngine.class);
|
||||||
}
|
}
|
||||||
private ElGamalEngine() {}
|
|
||||||
|
private ElGamalEngine() { // nop
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private final static BigInteger _two = new NativeBigInteger(1, new byte[] { 0x02});
|
private final static BigInteger _two = new NativeBigInteger(1, new byte[] { 0x02});
|
||||||
@ -215,13 +217,12 @@ public class ElGamalEngine {
|
|||||||
if (ok) {
|
if (ok) {
|
||||||
//_log.debug("Hash matches: " + DataHelper.toString(hash.getData(), hash.getData().length));
|
//_log.debug("Hash matches: " + DataHelper.toString(hash.getData(), hash.getData().length));
|
||||||
return rv;
|
return rv;
|
||||||
} else {
|
}
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Doesn't match hash [calc=" + calcHash + " sent hash=" + hash + "]\ndata = "
|
_log.debug("Doesn't match hash [calc=" + calcHash + " sent hash=" + hash + "]\ndata = "
|
||||||
+ Base64.encode(rv), new Exception("Doesn't match"));
|
+ Base64.encode(rv), new Exception("Doesn't match"));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
long eTime = 0;
|
long eTime = 0;
|
||||||
@ -230,12 +231,12 @@ public class ElGamalEngine {
|
|||||||
int numRuns = 100;
|
int numRuns = 100;
|
||||||
if (args.length > 0) try {
|
if (args.length > 0) try {
|
||||||
numRuns = Integer.parseInt(args[0]);
|
numRuns = Integer.parseInt(args[0]);
|
||||||
} catch (NumberFormatException nfe) {
|
} catch (NumberFormatException nfe) { // nop
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(30 * 1000);
|
Thread.sleep(30 * 1000);
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) { // nop
|
||||||
}
|
}
|
||||||
|
|
||||||
RandomSource.getInstance().nextBoolean();
|
RandomSource.getInstance().nextBoolean();
|
||||||
|
@ -11,7 +11,9 @@ import net.i2p.data.SessionKey;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class HMACSHA256Generator {
|
public class HMACSHA256Generator {
|
||||||
public HMACSHA256Generator(I2PAppContext context) {};
|
public HMACSHA256Generator(I2PAppContext context) { // nop
|
||||||
|
}
|
||||||
|
|
||||||
public static HMACSHA256Generator getInstance() {
|
public static HMACSHA256Generator getInstance() {
|
||||||
return I2PAppContext.getGlobalContext().hmac();
|
return I2PAppContext.getGlobalContext().hmac();
|
||||||
}
|
}
|
||||||
|
@ -166,7 +166,7 @@ public class KeyGenerator {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(5000);
|
Thread.sleep(5000);
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) { // nop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -182,7 +182,7 @@ public class PersistentSessionKeyManager extends TransientSessionKeyManager {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Thread.sleep(3000);
|
Thread.sleep(3000);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) { // nop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -39,7 +39,9 @@ import net.i2p.data.Hash;
|
|||||||
* @author thecrypto,jrandom
|
* @author thecrypto,jrandom
|
||||||
*/
|
*/
|
||||||
public class SHA256Generator {
|
public class SHA256Generator {
|
||||||
public SHA256Generator(I2PAppContext context) {};
|
public SHA256Generator(I2PAppContext context) { // nop
|
||||||
|
}
|
||||||
|
|
||||||
public static SHA256Generator getInstance() {
|
public static SHA256Generator getInstance() {
|
||||||
return I2PAppContext.getGlobalContext().sha();
|
return I2PAppContext.getGlobalContext().sha();
|
||||||
}
|
}
|
||||||
@ -66,7 +68,7 @@ public class SHA256Generator {
|
|||||||
k += 512;
|
k += 512;
|
||||||
}
|
}
|
||||||
int padbytes = k / 8;
|
int padbytes = k / 8;
|
||||||
int wordlength = (int) (source.length / 4 + padbytes / 4 + 3);
|
int wordlength = source.length / 4 + padbytes / 4 + 3;
|
||||||
int[] M0 = new int[wordlength];
|
int[] M0 = new int[wordlength];
|
||||||
int wordcount = 0;
|
int wordcount = 0;
|
||||||
int x = 0;
|
int x = 0;
|
||||||
|
@ -25,9 +25,12 @@ import net.i2p.data.SessionTag;
|
|||||||
*/
|
*/
|
||||||
public class SessionKeyManager {
|
public class SessionKeyManager {
|
||||||
/** session key managers must be created through an app context */
|
/** session key managers must be created through an app context */
|
||||||
protected SessionKeyManager(I2PAppContext context) {}
|
protected SessionKeyManager(I2PAppContext context) { // nop
|
||||||
|
}
|
||||||
|
|
||||||
/** see above */
|
/** see above */
|
||||||
private SessionKeyManager() {}
|
private SessionKeyManager() { // nop
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the session key currently associated with encryption to the target,
|
* Retrieve the session key currently associated with encryption to the target,
|
||||||
@ -43,7 +46,7 @@ public class SessionKeyManager {
|
|||||||
* when to expire that key begin with this call.
|
* when to expire that key begin with this call.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void createSession(PublicKey target, SessionKey key) {
|
public void createSession(PublicKey target, SessionKey key) { // nop
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,7 +93,7 @@ public class SessionKeyManager {
|
|||||||
* method after receiving an ack to a message delivering them)
|
* method after receiving an ack to a message delivering them)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void tagsDelivered(PublicKey target, SessionKey key, Set sessionTags) {
|
public void tagsDelivered(PublicKey target, SessionKey key, Set sessionTags) { // nop
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -99,14 +102,14 @@ public class SessionKeyManager {
|
|||||||
* from corrupted tag sets and crashes
|
* from corrupted tag sets and crashes
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void failTags(PublicKey target) {
|
public void failTags(PublicKey target) { // nop
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Accept the given tags and associate them with the given key for decryption
|
* Accept the given tags and associate them with the given key for decryption
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void tagsReceived(SessionKey key, Set sessionTags) {
|
public void tagsReceived(SessionKey key, Set sessionTags) { // nop
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -125,6 +128,6 @@ public class SessionKeyManager {
|
|||||||
* whatever precautions are necessary (saving state, etc)
|
* whatever precautions are necessary (saving state, etc)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void shutdown() {
|
public void shutdown() { // nop
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -123,9 +123,8 @@ class TransientSessionKeyManager extends SessionKeyManager {
|
|||||||
+ new Date(sess.getEstablishedDate())
|
+ new Date(sess.getEstablishedDate())
|
||||||
+ " with target " + target);
|
+ " with target " + target);
|
||||||
return null;
|
return null;
|
||||||
} else {
|
|
||||||
return sess.getCurrentKey();
|
|
||||||
}
|
}
|
||||||
|
return sess.getCurrentKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -158,12 +157,11 @@ class TransientSessionKeyManager extends SessionKeyManager {
|
|||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Tag consumed: " + nxt);
|
_log.debug("Tag consumed: " + nxt);
|
||||||
return nxt;
|
return nxt;
|
||||||
} else {
|
}
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Key does not match existing key, no tag");
|
_log.debug("Key does not match existing key, no tag");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine (approximately) how many available session tags for the current target
|
* Determine (approximately) how many available session tags for the current target
|
||||||
@ -175,9 +173,8 @@ class TransientSessionKeyManager extends SessionKeyManager {
|
|||||||
if (sess == null) { return 0; }
|
if (sess == null) { return 0; }
|
||||||
if (sess.getCurrentKey().equals(key)) {
|
if (sess.getCurrentKey().equals(key)) {
|
||||||
return sess.availableTags();
|
return sess.availableTags();
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -189,9 +186,8 @@ class TransientSessionKeyManager extends SessionKeyManager {
|
|||||||
if (sess == null) { return 0; }
|
if (sess == null) { return 0; }
|
||||||
if (sess.getCurrentKey().equals(key)) {
|
if (sess.getCurrentKey().equals(key)) {
|
||||||
return (sess.getLastExpirationDate() + SESSION_TAG_DURATION_MS) - Clock.getInstance().now();
|
return (sess.getLastExpirationDate() + SESSION_TAG_DURATION_MS) - Clock.getInstance().now();
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -263,9 +259,9 @@ class TransientSessionKeyManager extends SessionKeyManager {
|
|||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Cannot consume tag " + tag + " as it is not known");
|
_log.debug("Cannot consume tag " + tag + " as it is not known");
|
||||||
return null;
|
return null;
|
||||||
} else {
|
|
||||||
tagSet.consume(tag);
|
|
||||||
}
|
}
|
||||||
|
tagSet.consume(tag);
|
||||||
|
|
||||||
SessionKey key = tagSet.getAssociatedKey();
|
SessionKey key = tagSet.getAssociatedKey();
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Consuming tag " + tag + " for sessionKey " + key);
|
_log.debug("Consuming tag " + tag + " for sessionKey " + key);
|
||||||
@ -555,12 +551,12 @@ class TransientSessionKeyManager extends SessionKeyManager {
|
|||||||
public SessionTag consumeNext() {
|
public SessionTag consumeNext() {
|
||||||
if (_sessionTags.size() <= 0) {
|
if (_sessionTags.size() <= 0) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
SessionTag first = (SessionTag) _sessionTags.iterator().next();
|
SessionTag first = (SessionTag) _sessionTags.iterator().next();
|
||||||
_sessionTags.remove(first);
|
_sessionTags.remove(first);
|
||||||
return first;
|
return first;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
long rv = 0;
|
long rv = 0;
|
||||||
|
@ -157,7 +157,7 @@ class YKGenerator {
|
|||||||
RandomSource.getInstance().nextBoolean(); // warm it up
|
RandomSource.getInstance().nextBoolean(); // warm it up
|
||||||
try {
|
try {
|
||||||
Thread.sleep(20 * 1000);
|
Thread.sleep(20 * 1000);
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) { // nop
|
||||||
}
|
}
|
||||||
_log.debug("\n\n\n\nBegin test\n");
|
_log.debug("\n\n\n\nBegin test\n");
|
||||||
long negTime = 0;
|
long negTime = 0;
|
||||||
@ -169,7 +169,7 @@ class YKGenerator {
|
|||||||
_log.debug("YK fetch time for 5 runs: " + negTime + " @ " + negTime / 5l + "ms each");
|
_log.debug("YK fetch time for 5 runs: " + negTime + " @ " + negTime / 5l + "ms each");
|
||||||
try {
|
try {
|
||||||
Thread.sleep(30 * 1000);
|
Thread.sleep(30 * 1000);
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) { // nop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,7 +197,7 @@ class YKGenerator {
|
|||||||
// for some relief...
|
// for some relief...
|
||||||
try {
|
try {
|
||||||
Thread.sleep(CALC_DELAY);
|
Thread.sleep(CALC_DELAY);
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) { // nop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -211,7 +211,7 @@ class YKGenerator {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Thread.sleep(CHECK_DELAY);
|
Thread.sleep(CHECK_DELAY);
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) { // nop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,7 @@ public class Base64 {
|
|||||||
private final static byte EQUALS_SIGN_ENC = -1; // Indicates equals sign in encoding
|
private final static byte EQUALS_SIGN_ENC = -1; // Indicates equals sign in encoding
|
||||||
|
|
||||||
/** Defeats instantiation. */
|
/** Defeats instantiation. */
|
||||||
private Base64() {
|
private Base64() { // nop
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -40,7 +40,8 @@ public class ByteArray implements Serializable {
|
|||||||
if (o == null) return false;
|
if (o == null) return false;
|
||||||
if (o instanceof ByteArray) {
|
if (o instanceof ByteArray) {
|
||||||
return compare(getData(), ((ByteArray) o).getData());
|
return compare(getData(), ((ByteArray) o).getData());
|
||||||
} else {
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
byte val[] = (byte[]) o;
|
byte val[] = (byte[]) o;
|
||||||
return compare(getData(), val);
|
return compare(getData(), val);
|
||||||
@ -48,7 +49,6 @@ public class ByteArray implements Serializable {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private boolean compare(byte[] lhs, byte[] rhs) {
|
private boolean compare(byte[] lhs, byte[] rhs) {
|
||||||
return DataHelper.eq(lhs, rhs);
|
return DataHelper.eq(lhs, rhs);
|
||||||
|
@ -78,9 +78,9 @@ public class Certificate extends DataStructureImpl {
|
|||||||
if (_type < 0) throw new DataFormatException("Invalid certificate type: " + _type);
|
if (_type < 0) throw new DataFormatException("Invalid certificate type: " + _type);
|
||||||
if ((_type != 0) && (_payload == null)) throw new DataFormatException("Payload is required for non null type");
|
if ((_type != 0) && (_payload == null)) throw new DataFormatException("Payload is required for non null type");
|
||||||
|
|
||||||
DataHelper.writeLong(out, 1, (long) _type);
|
DataHelper.writeLong(out, 1, _type);
|
||||||
if (_payload != null) {
|
if (_payload != null) {
|
||||||
DataHelper.writeLong(out, 2, (long) _payload.length);
|
DataHelper.writeLong(out, 2, _payload.length);
|
||||||
out.write(_payload);
|
out.write(_payload);
|
||||||
} else {
|
} else {
|
||||||
DataHelper.writeLong(out, 2, 0L);
|
DataHelper.writeLong(out, 2, 0L);
|
||||||
|
@ -148,9 +148,8 @@ public class DataHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String toString(byte buf[]) {
|
public static String toString(byte buf[]) {
|
||||||
if (buf == null)
|
if (buf == null) return "";
|
||||||
return "";
|
|
||||||
else
|
|
||||||
return toString(buf, buf.length);
|
return toString(buf, buf.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,7 +163,7 @@ public class DataHelper {
|
|||||||
out.append("00");
|
out.append("00");
|
||||||
}
|
}
|
||||||
for (int i = 0; i < buf.length && i < len; i++) {
|
for (int i = 0; i < buf.length && i < len; i++) {
|
||||||
StringBuffer temp = new StringBuffer(Integer.toHexString((int) buf[i]));
|
StringBuffer temp = new StringBuffer(Integer.toHexString(buf[i]));
|
||||||
while (temp.length() < 2) {
|
while (temp.length() < 2) {
|
||||||
temp.insert(0, '0');
|
temp.insert(0, '0');
|
||||||
}
|
}
|
||||||
@ -241,9 +240,8 @@ public class DataHelper {
|
|||||||
*/
|
*/
|
||||||
public static Date readDate(InputStream in) throws DataFormatException, IOException {
|
public static Date readDate(InputStream in) throws DataFormatException, IOException {
|
||||||
long date = readLong(in, 8);
|
long date = readLong(in, 8);
|
||||||
if (date == 0L)
|
if (date == 0L) return null;
|
||||||
return null;
|
|
||||||
else
|
|
||||||
return new Date(date);
|
return new Date(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -448,9 +446,8 @@ public class DataHelper {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static int hashCode(Object obj) {
|
public static int hashCode(Object obj) {
|
||||||
if (obj == null)
|
if (obj == null) return 0;
|
||||||
return 0;
|
|
||||||
else
|
|
||||||
return obj.hashCode();
|
return obj.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -459,9 +456,8 @@ public class DataHelper {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static int hashCode(Date obj) {
|
public static int hashCode(Date obj) {
|
||||||
if (obj == null)
|
if (obj == null) return 0;
|
||||||
return 0;
|
|
||||||
else
|
|
||||||
return (int) obj.getTime();
|
return (int) obj.getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -495,9 +491,8 @@ public class DataHelper {
|
|||||||
while (cur < target.length) {
|
while (cur < target.length) {
|
||||||
int numRead = in.read(target, cur, target.length - cur);
|
int numRead = in.read(target, cur, target.length - cur);
|
||||||
if (numRead == -1) {
|
if (numRead == -1) {
|
||||||
if (cur == 0)
|
if (cur == 0) return -1; // throw new EOFException("EOF Encountered during reading");
|
||||||
return -1; // throw new EOFException("EOF Encountered during reading");
|
|
||||||
else
|
|
||||||
return cur;
|
return cur;
|
||||||
}
|
}
|
||||||
cur += numRead;
|
cur += numRead;
|
||||||
|
@ -29,7 +29,7 @@ public abstract class DataStructureImpl implements DataStructure {
|
|||||||
byte data[] = toByteArray();
|
byte data[] = toByteArray();
|
||||||
if (data == null)
|
if (data == null)
|
||||||
return null;
|
return null;
|
||||||
else
|
|
||||||
return Base64.encode(data);
|
return Base64.encode(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ public class LeaseSet extends DataStructureImpl {
|
|||||||
Hash rk = RoutingKeyGenerator.getInstance().getRoutingKey(destKey);
|
Hash rk = RoutingKeyGenerator.getInstance().getRoutingKey(destKey);
|
||||||
if (rk.equals(getRoutingKey()))
|
if (rk.equals(getRoutingKey()))
|
||||||
return true;
|
return true;
|
||||||
else
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,7 +136,7 @@ public class LeaseSet extends DataStructureImpl {
|
|||||||
public long getEarliestLeaseDate() {
|
public long getEarliestLeaseDate() {
|
||||||
long when = -1;
|
long when = -1;
|
||||||
for (int i = 0; i < getLeaseCount(); i++) {
|
for (int i = 0; i < getLeaseCount(); i++) {
|
||||||
Lease lse = (Lease) getLease(i);
|
Lease lse = getLease(i);
|
||||||
if ((lse != null) && (lse.getEndDate() != null)) {
|
if ((lse != null) && (lse.getEndDate() != null)) {
|
||||||
if ((when <= 0) || (lse.getEndDate().getTime() < when)) when = lse.getEndDate().getTime();
|
if ((when <= 0) || (lse.getEndDate().getTime() < when)) when = lse.getEndDate().getTime();
|
||||||
}
|
}
|
||||||
|
@ -302,7 +302,7 @@ public class RouterInfo extends DataStructureImpl {
|
|||||||
Hash rk = RoutingKeyGenerator.getInstance().getRoutingKey(identKey);
|
Hash rk = RoutingKeyGenerator.getInstance().getRoutingKey(identKey);
|
||||||
if (rk.equals(getRoutingKey()))
|
if (rk.equals(getRoutingKey()))
|
||||||
return true;
|
return true;
|
||||||
else
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,12 +316,11 @@ public class RouterInfo extends DataStructureImpl {
|
|||||||
*/
|
*/
|
||||||
public boolean isCurrent(long maxAgeMs) {
|
public boolean isCurrent(long maxAgeMs) {
|
||||||
long earliestExpire = Clock.getInstance().now() - maxAgeMs;
|
long earliestExpire = Clock.getInstance().now() - maxAgeMs;
|
||||||
if (getPublished() < earliestExpire) {
|
if (getPublished() < earliestExpire)
|
||||||
return false;
|
return false;
|
||||||
} else {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Actually validate the signature
|
* Actually validate the signature
|
||||||
|
@ -124,7 +124,7 @@ public class RoutingKeyGenerator {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) { // nop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -76,7 +76,7 @@ public class UnsignedInteger {
|
|||||||
} else if (data.length == 0) { return 0; }
|
} else if (data.length == 0) { return 0; }
|
||||||
long rv = 0;
|
long rv = 0;
|
||||||
for (int i = 0; i < data.length; i++) {
|
for (int i = 0; i < data.length; i++) {
|
||||||
long cur = (long)(data[i]&0xFF);
|
long cur = data[i] & 0xFF;
|
||||||
if (cur < 0) cur = cur+256;
|
if (cur < 0) cur = cur+256;
|
||||||
cur = (cur << (8*(data.length-i-1)));
|
cur = (cur << (8*(data.length-i-1)));
|
||||||
rv += cur;
|
rv += cur;
|
||||||
@ -90,7 +90,7 @@ public class UnsignedInteger {
|
|||||||
+ " != \n " + Long.toBinaryString(rv) + " /\t" + Long.toHexString(rv)
|
+ " != \n " + Long.toBinaryString(rv) + " /\t" + Long.toHexString(rv)
|
||||||
+ " /\t" + rv);
|
+ " /\t" + rv);
|
||||||
for (int i = 0; i < data.length; i++) {
|
for (int i = 0; i < data.length; i++) {
|
||||||
long cur = (long)(data[i]&0xFF);
|
long cur = data[i] & 0xFF;
|
||||||
if (cur < 0) cur = cur+256;
|
if (cur < 0) cur = cur+256;
|
||||||
long shiftBy = (8*(data.length-i-1));
|
long shiftBy = (8*(data.length-i-1));
|
||||||
long old = cur;
|
long old = cur;
|
||||||
@ -210,9 +210,8 @@ public class UnsignedInteger {
|
|||||||
if ((obj != null) && (obj instanceof UnsignedInteger)) {
|
if ((obj != null) && (obj instanceof UnsignedInteger)) {
|
||||||
return DataHelper.eq(_data, ((UnsignedInteger) obj)._data)
|
return DataHelper.eq(_data, ((UnsignedInteger) obj)._data)
|
||||||
&& DataHelper.eq(_value, ((UnsignedInteger) obj)._value);
|
&& DataHelper.eq(_value, ((UnsignedInteger) obj)._value);
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
@ -242,7 +241,7 @@ public class UnsignedInteger {
|
|||||||
} catch (Throwable t) { t.printStackTrace(); }
|
} catch (Throwable t) { t.printStackTrace(); }
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) { // nop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,9 +114,9 @@ public class CreateLeaseSetMessage extends I2CPMessageImpl {
|
|||||||
&& DataHelper.eq(getSigningPrivateKey(), msg.getSigningPrivateKey())
|
&& DataHelper.eq(getSigningPrivateKey(), msg.getSigningPrivateKey())
|
||||||
&& DataHelper.eq(getPrivateKey(), msg.getPrivateKey())
|
&& DataHelper.eq(getPrivateKey(), msg.getPrivateKey())
|
||||||
&& DataHelper.eq(getLeaseSet(), msg.getLeaseSet());
|
&& DataHelper.eq(getLeaseSet(), msg.getLeaseSet());
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
@ -74,9 +74,9 @@ public class CreateSessionMessage extends I2CPMessageImpl {
|
|||||||
if ((object != null) && (object instanceof CreateSessionMessage)) {
|
if ((object != null) && (object instanceof CreateSessionMessage)) {
|
||||||
CreateSessionMessage msg = (CreateSessionMessage) object;
|
CreateSessionMessage msg = (CreateSessionMessage) object;
|
||||||
return DataHelper.eq(getSessionConfig(), msg.getSessionConfig());
|
return DataHelper.eq(getSessionConfig(), msg.getSessionConfig());
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
@ -70,9 +70,9 @@ public class DestroySessionMessage extends I2CPMessageImpl {
|
|||||||
if ((object != null) && (object instanceof DestroySessionMessage)) {
|
if ((object != null) && (object instanceof DestroySessionMessage)) {
|
||||||
DestroySessionMessage msg = (DestroySessionMessage) object;
|
DestroySessionMessage msg = (DestroySessionMessage) object;
|
||||||
return DataHelper.eq(getSessionId(), msg.getSessionId());
|
return DataHelper.eq(getSessionId(), msg.getSessionId());
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
@ -66,9 +66,9 @@ public class DisconnectMessage extends I2CPMessageImpl {
|
|||||||
if ((object != null) && (object instanceof DisconnectMessage)) {
|
if ((object != null) && (object instanceof DisconnectMessage)) {
|
||||||
DisconnectMessage msg = (DisconnectMessage) object;
|
DisconnectMessage msg = (DisconnectMessage) object;
|
||||||
return DataHelper.eq(getReason(), msg.getReason());
|
return DataHelper.eq(getReason(), msg.getReason());
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
@ -42,9 +42,9 @@ public class GetDateMessage extends I2CPMessageImpl {
|
|||||||
public boolean equals(Object object) {
|
public boolean equals(Object object) {
|
||||||
if ((object != null) && (object instanceof GetDateMessage)) {
|
if ((object != null) && (object instanceof GetDateMessage)) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
@ -27,7 +27,7 @@ import net.i2p.util.Log;
|
|||||||
public abstract class I2CPMessageImpl extends DataStructureImpl implements I2CPMessage {
|
public abstract class I2CPMessageImpl extends DataStructureImpl implements I2CPMessage {
|
||||||
private final static Log _log = new Log(I2CPMessageImpl.class);
|
private final static Log _log = new Log(I2CPMessageImpl.class);
|
||||||
|
|
||||||
public I2CPMessageImpl() {
|
public I2CPMessageImpl() { // nop
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -168,7 +168,7 @@ public class I2CPMessageReader {
|
|||||||
// pause .5 secs when we're paused
|
// pause .5 secs when we're paused
|
||||||
try {
|
try {
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) { // nop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,9 +103,9 @@ public class MessagePayloadMessage extends I2CPMessageImpl {
|
|||||||
return DataHelper.eq(getSessionId(), msg.getSessionId())
|
return DataHelper.eq(getSessionId(), msg.getSessionId())
|
||||||
&& DataHelper.eq(getMessageId(), msg.getMessageId())
|
&& DataHelper.eq(getMessageId(), msg.getMessageId())
|
||||||
&& DataHelper.eq(getPayload(), msg.getPayload());
|
&& DataHelper.eq(getPayload(), msg.getPayload());
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
@ -146,9 +146,9 @@ public class MessageStatusMessage extends I2CPMessageImpl {
|
|||||||
return DataHelper.eq(getSessionId(), msg.getSessionId())
|
return DataHelper.eq(getSessionId(), msg.getSessionId())
|
||||||
&& DataHelper.eq(getMessageId(), msg.getMessageId()) && (getNonce() == msg.getNonce())
|
&& DataHelper.eq(getMessageId(), msg.getMessageId()) && (getNonce() == msg.getNonce())
|
||||||
&& DataHelper.eq(getSize(), msg.getSize()) && DataHelper.eq(getStatus(), msg.getStatus());
|
&& DataHelper.eq(getSize(), msg.getSize()) && DataHelper.eq(getStatus(), msg.getStatus());
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
@ -83,9 +83,9 @@ public class ReceiveMessageBeginMessage extends I2CPMessageImpl {
|
|||||||
ReceiveMessageBeginMessage msg = (ReceiveMessageBeginMessage) object;
|
ReceiveMessageBeginMessage msg = (ReceiveMessageBeginMessage) object;
|
||||||
return DataHelper.eq(getSessionId(), msg.getSessionId())
|
return DataHelper.eq(getSessionId(), msg.getSessionId())
|
||||||
&& DataHelper.eq(getMessageId(), msg.getMessageId());
|
&& DataHelper.eq(getMessageId(), msg.getMessageId());
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
@ -83,9 +83,9 @@ public class ReceiveMessageEndMessage extends I2CPMessageImpl {
|
|||||||
ReceiveMessageEndMessage msg = (ReceiveMessageEndMessage) object;
|
ReceiveMessageEndMessage msg = (ReceiveMessageEndMessage) object;
|
||||||
return DataHelper.eq(getSessionId(), msg.getSessionId())
|
return DataHelper.eq(getSessionId(), msg.getSessionId())
|
||||||
&& DataHelper.eq(getMessageId(), msg.getMessageId());
|
&& DataHelper.eq(getMessageId(), msg.getMessageId());
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
@ -113,9 +113,9 @@ public class ReportAbuseMessage extends I2CPMessageImpl {
|
|||||||
ReportAbuseMessage msg = (ReportAbuseMessage) object;
|
ReportAbuseMessage msg = (ReportAbuseMessage) object;
|
||||||
return DataHelper.eq(getSessionId(), msg.getSessionId()) && DataHelper.eq(getSeverity(), msg.getSeverity())
|
return DataHelper.eq(getSessionId(), msg.getSessionId()) && DataHelper.eq(getSeverity(), msg.getSeverity())
|
||||||
&& DataHelper.eq(getReason(), msg.getReason()) && DataHelper.eq(getMessageId(), msg.getMessageId());
|
&& DataHelper.eq(getReason(), msg.getReason()) && DataHelper.eq(getMessageId(), msg.getMessageId());
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
@ -131,9 +131,9 @@ public class RequestLeaseSetMessage extends I2CPMessageImpl {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return DataHelper.eq(getSessionId(), msg.getSessionId()) && DataHelper.eq(getEndDate(), msg.getEndDate());
|
return DataHelper.eq(getSessionId(), msg.getSessionId()) && DataHelper.eq(getEndDate(), msg.getEndDate());
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
@ -111,9 +111,9 @@ public class SendMessageMessage extends I2CPMessageImpl {
|
|||||||
return DataHelper.eq(getSessionId(), msg.getSessionId())
|
return DataHelper.eq(getSessionId(), msg.getSessionId())
|
||||||
&& DataHelper.eq(getDestination(), msg.getDestination()) && (getNonce() == msg.getNonce())
|
&& DataHelper.eq(getDestination(), msg.getDestination()) && (getNonce() == msg.getNonce())
|
||||||
&& DataHelper.eq(getPayload(), msg.getPayload());
|
&& DataHelper.eq(getPayload(), msg.getPayload());
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
@ -204,9 +204,9 @@ public class SessionConfig extends DataStructureImpl {
|
|||||||
&& DataHelper.eq(getDestination(), cfg.getDestination())
|
&& DataHelper.eq(getDestination(), cfg.getDestination())
|
||||||
&& DataHelper.eq(getCreationDate(), cfg.getCreationDate())
|
&& DataHelper.eq(getCreationDate(), cfg.getCreationDate())
|
||||||
&& DataHelper.eq(getOptions(), cfg.getOptions());
|
&& DataHelper.eq(getOptions(), cfg.getOptions());
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
@ -86,9 +86,9 @@ public class SessionStatusMessage extends I2CPMessageImpl {
|
|||||||
if ((object != null) && (object instanceof SessionStatusMessage)) {
|
if ((object != null) && (object instanceof SessionStatusMessage)) {
|
||||||
SessionStatusMessage msg = (SessionStatusMessage) object;
|
SessionStatusMessage msg = (SessionStatusMessage) object;
|
||||||
return DataHelper.eq(getSessionId(), msg.getSessionId()) && DataHelper.eq(getStatus(), msg.getStatus());
|
return DataHelper.eq(getSessionId(), msg.getSessionId()) && DataHelper.eq(getStatus(), msg.getStatus());
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
@ -69,9 +69,9 @@ public class SetDateMessage extends I2CPMessageImpl {
|
|||||||
if ((object != null) && (object instanceof SetDateMessage)) {
|
if ((object != null) && (object instanceof SetDateMessage)) {
|
||||||
SetDateMessage msg = (SetDateMessage) object;
|
SetDateMessage msg = (SetDateMessage) object;
|
||||||
return DataHelper.eq(getDate(), msg.getDate());
|
return DataHelper.eq(getDate(), msg.getDate());
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
@ -55,9 +55,8 @@ public class Frequency {
|
|||||||
/** calculate how many events would occur in a period given the current average */
|
/** calculate how many events would occur in a period given the current average */
|
||||||
public double getAverageEventsPerPeriod() {
|
public double getAverageEventsPerPeriod() {
|
||||||
synchronized (_lock) {
|
synchronized (_lock) {
|
||||||
if (_avgInterval > 0)
|
if (_avgInterval > 0) return _period / _avgInterval;
|
||||||
return _period / _avgInterval;
|
|
||||||
else
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -65,9 +64,8 @@ public class Frequency {
|
|||||||
/** calculate how many events would occur in a period given the maximum average */
|
/** calculate how many events would occur in a period given the maximum average */
|
||||||
public double getMaxAverageEventsPerPeriod() {
|
public double getMaxAverageEventsPerPeriod() {
|
||||||
synchronized (_lock) {
|
synchronized (_lock) {
|
||||||
if (_minAverageInterval > 0)
|
if (_minAverageInterval > 0) return _period / _minAverageInterval;
|
||||||
return _period / _minAverageInterval;
|
|
||||||
else
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -76,9 +74,8 @@ public class Frequency {
|
|||||||
public double getStrictAverageInterval() {
|
public double getStrictAverageInterval() {
|
||||||
synchronized (_lock) {
|
synchronized (_lock) {
|
||||||
long duration = now() - _start;
|
long duration = now() - _start;
|
||||||
if ((duration <= 0) || (_count <= 0))
|
if ((duration <= 0) || (_count <= 0)) return 0;
|
||||||
return 0;
|
|
||||||
else
|
|
||||||
return duration / _count;
|
return duration / _count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -87,9 +84,8 @@ public class Frequency {
|
|||||||
public double getStrictAverageEventsPerPeriod() {
|
public double getStrictAverageEventsPerPeriod() {
|
||||||
double avgInterval = getStrictAverageInterval();
|
double avgInterval = getStrictAverageInterval();
|
||||||
synchronized (_lock) {
|
synchronized (_lock) {
|
||||||
if (avgInterval > 0)
|
if (avgInterval > 0) return _period / avgInterval;
|
||||||
return _period / avgInterval;
|
|
||||||
else
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -182,15 +182,15 @@ public class Rate {
|
|||||||
if (measuredPeriod < _period) {
|
if (measuredPeriod < _period) {
|
||||||
// no need to coallesce
|
// no need to coallesce
|
||||||
return;
|
return;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
// ok ok, lets coallesce
|
// ok ok, lets coallesce
|
||||||
|
|
||||||
// how much were we off by? (so that we can sample down the measured values)
|
// how much were we off by? (so that we can sample down the measured values)
|
||||||
double periodFactor = measuredPeriod / _period;
|
double periodFactor = measuredPeriod / _period;
|
||||||
_lastTotalValue = (_currentTotalValue == 0 ? 0.0d : _currentTotalValue / periodFactor);
|
_lastTotalValue = (_currentTotalValue == 0 ? 0.0D : _currentTotalValue / periodFactor);
|
||||||
_lastEventCount = (_currentEventCount == 0 ? 0l : (long) (_currentEventCount / periodFactor));
|
_lastEventCount = (_currentEventCount == 0 ? 0L : (long) (_currentEventCount / periodFactor));
|
||||||
_lastTotalEventTime = (_currentTotalEventTime == 0 ? 0l
|
_lastTotalEventTime = (_currentTotalEventTime == 0 ? 0L : (long) (_currentTotalEventTime / periodFactor));
|
||||||
: (long) (_currentTotalEventTime / periodFactor));
|
|
||||||
_lastCoallesceDate = now;
|
_lastCoallesceDate = now;
|
||||||
|
|
||||||
if (_lastTotalValue > _extremeTotalValue) {
|
if (_lastTotalValue > _extremeTotalValue) {
|
||||||
@ -199,35 +199,34 @@ public class Rate {
|
|||||||
_extremeTotalEventTime = _lastTotalEventTime;
|
_extremeTotalEventTime = _lastTotalEventTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
_currentTotalValue = 0.0d;
|
_currentTotalValue = 0.0D;
|
||||||
_currentEventCount = 0;
|
_currentEventCount = 0;
|
||||||
_currentTotalEventTime = 0;
|
_currentTotalEventTime = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/** what was the average value across the events in the last period? */
|
/** what was the average value across the events in the last period? */
|
||||||
public double getAverageValue() {
|
public double getAverageValue() {
|
||||||
if ((_lastTotalValue != 0) && (_lastEventCount > 0))
|
if ((_lastTotalValue != 0) && (_lastEventCount > 0))
|
||||||
return _lastTotalValue / _lastEventCount;
|
return _lastTotalValue / _lastEventCount;
|
||||||
else
|
|
||||||
return 0.0d;
|
return 0.0D;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** what was the average value across the events in the most active period? */
|
/** what was the average value across the events in the most active period? */
|
||||||
public double getExtremeAverageValue() {
|
public double getExtremeAverageValue() {
|
||||||
if ((_extremeTotalValue != 0) && (_extremeEventCount > 0))
|
if ((_extremeTotalValue != 0) && (_extremeEventCount > 0))
|
||||||
return _extremeTotalValue / _extremeEventCount;
|
return _extremeTotalValue / _extremeEventCount;
|
||||||
else
|
|
||||||
return 0.0d;
|
return 0.0D;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** what was the average value across the events since the stat was created? */
|
/** what was the average value across the events since the stat was created? */
|
||||||
public double getLifetimeAverageValue() {
|
public double getLifetimeAverageValue() {
|
||||||
if ((_lifetimeTotalValue != 0) && (_lifetimeEventCount > 0))
|
if ((_lifetimeTotalValue != 0) && (_lifetimeEventCount > 0))
|
||||||
return _lifetimeTotalValue / _lifetimeEventCount;
|
return _lifetimeTotalValue / _lifetimeEventCount;
|
||||||
else
|
|
||||||
return 0.0d;
|
return 0.0D;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -239,12 +238,12 @@ public class Rate {
|
|||||||
public double getLastEventSaturation() {
|
public double getLastEventSaturation() {
|
||||||
if ((_lastEventCount > 0) && (_lastTotalEventTime > 0)) {
|
if ((_lastEventCount > 0) && (_lastTotalEventTime > 0)) {
|
||||||
double eventTime = (double) _lastTotalEventTime / (double) _lastEventCount;
|
double eventTime = (double) _lastTotalEventTime / (double) _lastEventCount;
|
||||||
double maxEvents = (double) _period / eventTime;
|
double maxEvents = _period / eventTime;
|
||||||
double saturation = _lastEventCount / maxEvents;
|
double saturation = _lastEventCount / maxEvents;
|
||||||
return saturation;
|
return saturation;
|
||||||
} else {
|
|
||||||
return 0.0d;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0.0D;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -256,11 +255,10 @@ public class Rate {
|
|||||||
public double getExtremeEventSaturation() {
|
public double getExtremeEventSaturation() {
|
||||||
if ((_extremeEventCount > 0) && (_extremeTotalEventTime > 0)) {
|
if ((_extremeEventCount > 0) && (_extremeTotalEventTime > 0)) {
|
||||||
double eventTime = (double) _extremeTotalEventTime / (double) _extremeEventCount;
|
double eventTime = (double) _extremeTotalEventTime / (double) _extremeEventCount;
|
||||||
double maxEvents = (double) _period / eventTime;
|
double maxEvents = _period / eventTime;
|
||||||
return _extremeEventCount / maxEvents;
|
return _extremeEventCount / maxEvents;
|
||||||
} else {
|
|
||||||
return 0.0d;
|
|
||||||
}
|
}
|
||||||
|
return 0.0D;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -272,13 +270,12 @@ public class Rate {
|
|||||||
public double getLifetimeEventSaturation() {
|
public double getLifetimeEventSaturation() {
|
||||||
if ((_lastEventCount > 0) && (_lifetimeTotalEventTime > 0)) {
|
if ((_lastEventCount > 0) && (_lifetimeTotalEventTime > 0)) {
|
||||||
double eventTime = (double) _lifetimeTotalEventTime / (double) _lifetimeEventCount;
|
double eventTime = (double) _lifetimeTotalEventTime / (double) _lifetimeEventCount;
|
||||||
double maxEvents = (double) _period / eventTime;
|
double maxEvents = _period / eventTime;
|
||||||
double numPeriods = getLifetimePeriods();
|
double numPeriods = getLifetimePeriods();
|
||||||
double avgEventsPerPeriod = _lifetimeEventCount / numPeriods;
|
double avgEventsPerPeriod = _lifetimeEventCount / numPeriods;
|
||||||
return avgEventsPerPeriod / maxEvents;
|
return avgEventsPerPeriod / maxEvents;
|
||||||
} else {
|
|
||||||
return 0.0d;
|
|
||||||
}
|
}
|
||||||
|
return 0.0D;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** how many periods have we already completed? */
|
/** how many periods have we already completed? */
|
||||||
@ -297,13 +294,11 @@ public class Rate {
|
|||||||
public double getLastSaturationLimit() {
|
public double getLastSaturationLimit() {
|
||||||
if ((_lastTotalValue != 0) && (_lastEventCount > 0) && (_lastTotalEventTime > 0)) {
|
if ((_lastTotalValue != 0) && (_lastEventCount > 0) && (_lastTotalEventTime > 0)) {
|
||||||
double saturation = getLastEventSaturation();
|
double saturation = getLastEventSaturation();
|
||||||
if (saturation != 0.0d)
|
if (saturation != 0.0D) return _lastTotalValue / saturation;
|
||||||
return _lastTotalValue / saturation;
|
|
||||||
else
|
return 0.0D;
|
||||||
return 0.0d;
|
|
||||||
} else {
|
|
||||||
return 0.0d;
|
|
||||||
}
|
}
|
||||||
|
return 0.0D;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -315,13 +310,12 @@ public class Rate {
|
|||||||
public double getExtremeSaturationLimit() {
|
public double getExtremeSaturationLimit() {
|
||||||
if ((_extremeTotalValue != 0) && (_extremeEventCount > 0) && (_extremeTotalEventTime > 0)) {
|
if ((_extremeTotalValue != 0) && (_extremeEventCount > 0) && (_extremeTotalEventTime > 0)) {
|
||||||
double saturation = getExtremeEventSaturation();
|
double saturation = getExtremeEventSaturation();
|
||||||
if (saturation != 0.0d)
|
if (saturation != 0.0d) return _extremeTotalValue / saturation;
|
||||||
return _extremeTotalValue / saturation;
|
|
||||||
else
|
return 0.0D;
|
||||||
return 0.0d;
|
|
||||||
} else {
|
|
||||||
return 0.0d;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0.0D;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -331,8 +325,8 @@ public class Rate {
|
|||||||
public double getPercentageOfExtremeValue() {
|
public double getPercentageOfExtremeValue() {
|
||||||
if ((_lastTotalValue != 0) && (_extremeTotalValue != 0))
|
if ((_lastTotalValue != 0) && (_extremeTotalValue != 0))
|
||||||
return _lastTotalValue / _extremeTotalValue;
|
return _lastTotalValue / _extremeTotalValue;
|
||||||
else
|
|
||||||
return 0.0d;
|
return 0.0D;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -343,9 +337,9 @@ public class Rate {
|
|||||||
if ((_lastTotalValue != 0) && (_lifetimeTotalValue != 0)) {
|
if ((_lastTotalValue != 0) && (_lifetimeTotalValue != 0)) {
|
||||||
double lifetimePeriodValue = _period * (_lifetimeTotalValue / (now() - _creationDate));
|
double lifetimePeriodValue = _period * (_lifetimeTotalValue / (now() - _creationDate));
|
||||||
return _lastTotalValue / lifetimePeriodValue;
|
return _lastTotalValue / lifetimePeriodValue;
|
||||||
} else {
|
|
||||||
return 0.0d;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0.0D;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void store(String prefix, StringBuffer buf) throws IOException {
|
public void store(String prefix, StringBuffer buf) throws IOException {
|
||||||
@ -468,7 +462,7 @@ public class Rate {
|
|||||||
for (int i = 0; i < 50; i++) {
|
for (int i = 0; i < 50; i++) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(20);
|
Thread.sleep(20);
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) { // nop
|
||||||
}
|
}
|
||||||
rate.addData(i * 100, 20);
|
rate.addData(i * 100, 20);
|
||||||
}
|
}
|
||||||
@ -492,7 +486,7 @@ public class Rate {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Thread.sleep(5000);
|
Thread.sleep(5000);
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) { // nop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -97,9 +97,9 @@ public class RateStat {
|
|||||||
for (int i = 0; i < _rates.length; i++)
|
for (int i = 0; i < _rates.length; i++)
|
||||||
if (!_rates[i].equals(rs.getRate(_rates[i].getPeriod()))) return false;
|
if (!_rates[i].equals(rs.getRate(_rates[i].getPeriod()))) return false;
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void store(OutputStream out, String prefix) throws IOException {
|
public void store(OutputStream out, String prefix) throws IOException {
|
||||||
@ -158,7 +158,7 @@ public class RateStat {
|
|||||||
for (int i = 0; i < 50; i++) {
|
for (int i = 0; i < 50; i++) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(20);
|
Thread.sleep(20);
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) { // nop
|
||||||
}
|
}
|
||||||
rs.addData(i * 100, 20);
|
rs.addData(i * 100, 20);
|
||||||
}
|
}
|
||||||
@ -185,7 +185,7 @@ public class RateStat {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Thread.sleep(5000);
|
Thread.sleep(5000);
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) { // nop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -132,7 +132,7 @@ public class EventDispatcherImpl implements EventDispatcher {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
_events.wait(1 * 1000);
|
_events.wait(1 * 1000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) { // nop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (true);
|
} while (true);
|
||||||
|
@ -84,7 +84,7 @@ public class HTTPSendData {
|
|||||||
_log.debug("Sent? " + sent);
|
_log.debug("Sent? " + sent);
|
||||||
try {
|
try {
|
||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) { // nop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -106,7 +106,7 @@ public class HexDump {
|
|||||||
if (i >= nextbytes) {
|
if (i >= nextbytes) {
|
||||||
out.write(" ".getBytes());
|
out.write(" ".getBytes());
|
||||||
} else {
|
} else {
|
||||||
val = ((int) data[dumpoff + i]) & 0xff;
|
val = data[dumpoff + i] & 0xff;
|
||||||
out.write(HEXCHARS[val >>> 4]);
|
out.write(HEXCHARS[val >>> 4]);
|
||||||
out.write(HEXCHARS[val & 0xf]);
|
out.write(HEXCHARS[val & 0xf]);
|
||||||
out.write(" ".getBytes());
|
out.write(" ".getBytes());
|
||||||
|
@ -86,7 +86,7 @@ public class I2PThread extends Thread {
|
|||||||
t.start();
|
t.start();
|
||||||
try {
|
try {
|
||||||
Thread.sleep(10000);
|
Thread.sleep(10000);
|
||||||
} catch (Throwable tt) {
|
} catch (Throwable tt) { // nop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -161,9 +161,8 @@ public class Log {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
if (_class != null)
|
if (_class != null) return _class.getName();
|
||||||
return _class.getName();
|
|
||||||
else
|
|
||||||
return _name;
|
return _name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,9 +188,9 @@ public class Log {
|
|||||||
LogScope s = (LogScope)obj;
|
LogScope s = (LogScope)obj;
|
||||||
return DataHelper.eq(s._scopeName, _scopeName) &&
|
return DataHelper.eq(s._scopeName, _scopeName) &&
|
||||||
DataHelper.eq(s._scopeClass, _scopeClass);
|
DataHelper.eq(s._scopeClass, _scopeClass);
|
||||||
} else {
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
@ -108,7 +108,9 @@ public class LogManager {
|
|||||||
}
|
}
|
||||||
//System.out.println("Created logManager " + this + " with context: " + context);
|
//System.out.println("Created logManager " + this + " with context: " + context);
|
||||||
}
|
}
|
||||||
private LogManager() {}
|
|
||||||
|
private LogManager() { // nop
|
||||||
|
}
|
||||||
|
|
||||||
public Log getLog(Class cls) { return getLog(cls, null); }
|
public Log getLog(Class cls) { return getLog(cls, null); }
|
||||||
public Log getLog(String name) { return getLog(null, name); }
|
public Log getLog(String name) { return getLog(null, name); }
|
||||||
@ -213,10 +215,11 @@ public class LogManager {
|
|||||||
+ (_context.clock().now() - _configLastRead) + "ms ago, config file modified "
|
+ (_context.clock().now() - _configLastRead) + "ms ago, config file modified "
|
||||||
+ (_context.clock().now() - cfgFile.lastModified()) + "ms ago");
|
+ (_context.clock().now() - cfgFile.lastModified()) + "ms ago");
|
||||||
return;
|
return;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Loading config from " + _location);
|
_log.debug("Loading config from " + _location);
|
||||||
}
|
|
||||||
Properties p = new Properties();
|
Properties p = new Properties();
|
||||||
FileInputStream fis = null;
|
FileInputStream fis = null;
|
||||||
try {
|
try {
|
||||||
@ -228,7 +231,7 @@ public class LogManager {
|
|||||||
} finally {
|
} finally {
|
||||||
if (fis != null) try {
|
if (fis != null) try {
|
||||||
fis.close();
|
fis.close();
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) { // nop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
parseConfig(p);
|
parseConfig(p);
|
||||||
@ -320,7 +323,7 @@ public class LogManager {
|
|||||||
char mod = size.toUpperCase().charAt(size.length() - 1);
|
char mod = size.toUpperCase().charAt(size.length() - 1);
|
||||||
if (!Character.isDigit(mod)) v = size.substring(0, size.length() - 1);
|
if (!Character.isDigit(mod)) v = size.substring(0, size.length() - 1);
|
||||||
int val = Integer.parseInt(v);
|
int val = Integer.parseInt(v);
|
||||||
switch ((int) mod) {
|
switch (mod) {
|
||||||
case 'K':
|
case 'K':
|
||||||
val *= 1024;
|
val *= 1024;
|
||||||
break;
|
break;
|
||||||
@ -443,7 +446,7 @@ public class LogManager {
|
|||||||
l1.error("test exception", new Exception("test"));
|
l1.error("test exception", new Exception("test"));
|
||||||
try {
|
try {
|
||||||
Thread.sleep(2 * 1000);
|
Thread.sleep(2 * 1000);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) { // nop
|
||||||
}
|
}
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
@ -33,20 +33,20 @@ class LogRecordFormatter {
|
|||||||
StringBuffer buf = new StringBuffer(size);
|
StringBuffer buf = new StringBuffer(size);
|
||||||
char format[] = manager.getFormat();
|
char format[] = manager.getFormat();
|
||||||
for (int i = 0; i < format.length; ++i) {
|
for (int i = 0; i < format.length; ++i) {
|
||||||
switch ((int) format[i]) {
|
switch (format[i]) {
|
||||||
case (int) LogManager.DATE:
|
case LogManager.DATE:
|
||||||
buf.append(getWhen(manager, rec));
|
buf.append(getWhen(manager, rec));
|
||||||
break;
|
break;
|
||||||
case (int) LogManager.CLASS:
|
case LogManager.CLASS:
|
||||||
buf.append(getWhere(rec));
|
buf.append(getWhere(rec));
|
||||||
break;
|
break;
|
||||||
case (int) LogManager.THREAD:
|
case LogManager.THREAD:
|
||||||
buf.append(getThread(rec));
|
buf.append(getThread(rec));
|
||||||
break;
|
break;
|
||||||
case (int) LogManager.PRIORITY:
|
case LogManager.PRIORITY:
|
||||||
buf.append(getPriority(rec));
|
buf.append(getPriority(rec));
|
||||||
break;
|
break;
|
||||||
case (int) LogManager.MESSAGE:
|
case LogManager.MESSAGE:
|
||||||
buf.append(getWhat(rec));
|
buf.append(getWhat(rec));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -62,7 +62,7 @@ class LogRecordFormatter {
|
|||||||
try {
|
try {
|
||||||
pw.flush();
|
pw.flush();
|
||||||
baos.flush();
|
baos.flush();
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) { // nop
|
||||||
}
|
}
|
||||||
byte tb[] = baos.toByteArray();
|
byte tb[] = baos.toByteArray();
|
||||||
buf.append(new String(tb));
|
buf.append(new String(tb));
|
||||||
|
@ -33,7 +33,9 @@ class LogWriter implements Runnable {
|
|||||||
|
|
||||||
private boolean _write;
|
private boolean _write;
|
||||||
|
|
||||||
private LogWriter() {}
|
private LogWriter() { // nop
|
||||||
|
}
|
||||||
|
|
||||||
public LogWriter(LogManager manager) {
|
public LogWriter(LogManager manager) {
|
||||||
_manager = manager;
|
_manager = manager;
|
||||||
}
|
}
|
||||||
@ -69,7 +71,10 @@ class LogWriter implements Runnable {
|
|||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
try { Thread.sleep(100); } catch (InterruptedException ie) {}
|
try {
|
||||||
|
Thread.sleep(100);
|
||||||
|
} catch (InterruptedException ie) { // nop
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,20 +153,22 @@ class LogWriter implements Runnable {
|
|||||||
*/
|
*/
|
||||||
private File getNextFile(String pattern) {
|
private File getNextFile(String pattern) {
|
||||||
File f = null;
|
File f = null;
|
||||||
|
|
||||||
if (pattern.indexOf('#') < 0) {
|
if (pattern.indexOf('#') < 0) {
|
||||||
return new File(pattern);
|
return new File(pattern);
|
||||||
} else {
|
}
|
||||||
|
|
||||||
int max = _manager.getRotationLimit();
|
int max = _manager.getRotationLimit();
|
||||||
if (_rotationNum == -1) {
|
if (_rotationNum == -1) {
|
||||||
return getFirstFile(pattern, max);
|
return getFirstFile(pattern, max);
|
||||||
} else {
|
}
|
||||||
|
|
||||||
// we're in rotation, just go to the next
|
// we're in rotation, just go to the next
|
||||||
_rotationNum++;
|
_rotationNum++;
|
||||||
if (_rotationNum > max) _rotationNum = 0;
|
if (_rotationNum > max) _rotationNum = 0;
|
||||||
|
|
||||||
return new File(replace(pattern, _rotationNum));
|
return new File(replace(pattern, _rotationNum));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the first file, updating the rotation number accordingly
|
* Retrieve the first file, updating the rotation number accordingly
|
||||||
|
@ -137,7 +137,7 @@ public class NativeBigInteger extends BigInteger {
|
|||||||
public BigInteger modPow(BigInteger exponent, BigInteger m) {
|
public BigInteger modPow(BigInteger exponent, BigInteger m) {
|
||||||
if (_nativeOk)
|
if (_nativeOk)
|
||||||
return new NativeBigInteger(nativeModPow(toByteArray(), exponent.toByteArray(), m.toByteArray()));
|
return new NativeBigInteger(nativeModPow(toByteArray(), exponent.toByteArray(), m.toByteArray()));
|
||||||
else
|
|
||||||
return super.modPow(exponent, m);
|
return super.modPow(exponent, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,11 +197,11 @@ public class NativeBigInteger extends BigInteger {
|
|||||||
System.err.println("ERROR: java modPow value: " + jval.toString());
|
System.err.println("ERROR: java modPow value: " + jval.toString());
|
||||||
System.err.println("ERROR: run time: " + totalTime + "ms (" + (totalTime / (runsProcessed + 1)) + "ms each)");
|
System.err.println("ERROR: run time: " + totalTime + "ms (" + (totalTime / (runsProcessed + 1)) + "ms each)");
|
||||||
break;
|
break;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
System.out.println("DEBUG: current run time: " + (afterModPow - beforeModPow) + "ms (total: "
|
System.out.println("DEBUG: current run time: " + (afterModPow - beforeModPow) + "ms (total: "
|
||||||
+ totalTime + "ms, " + (totalTime / (runsProcessed + 1)) + "ms each)");
|
+ totalTime + "ms, " + (totalTime / (runsProcessed + 1)) + "ms each)");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
System.out.println("INFO: run time: " + totalTime + "ms (" + (totalTime / (runsProcessed + 1)) + "ms each)");
|
System.out.println("INFO: run time: " + totalTime + "ms (" + (totalTime / (runsProcessed + 1)) + "ms each)");
|
||||||
if (numRuns == runsProcessed)
|
if (numRuns == runsProcessed)
|
||||||
System.out.println("INFO: " + runsProcessed + " runs complete without any errors");
|
System.out.println("INFO: " + runsProcessed + " runs complete without any errors");
|
||||||
@ -212,7 +212,7 @@ public class NativeBigInteger extends BigInteger {
|
|||||||
System.out.println("native run time: \t" + totalTime + "ms (" + (totalTime / (runsProcessed + 1))
|
System.out.println("native run time: \t" + totalTime + "ms (" + (totalTime / (runsProcessed + 1))
|
||||||
+ "ms each)");
|
+ "ms each)");
|
||||||
System.out.println("java run time: \t" + javaTime + "ms (" + (javaTime / (runsProcessed + 1)) + "ms each)");
|
System.out.println("java run time: \t" + javaTime + "ms (" + (javaTime / (runsProcessed + 1)) + "ms each)");
|
||||||
System.out.println("native = " + ((totalTime * 100.0d) / (double) javaTime) + "% of pure java time");
|
System.out.println("native = " + ((totalTime * 100.0D) / javaTime) + "% of pure java time");
|
||||||
} else {
|
} else {
|
||||||
System.out.println("java run time: \t" + javaTime + "ms (" + (javaTime / (runsProcessed + 1)) + "ms each)");
|
System.out.println("java run time: \t" + javaTime + "ms (" + (javaTime / (runsProcessed + 1)) + "ms each)");
|
||||||
System.out.println("However, we couldn't load the native library, so this doesn't test much");
|
System.out.println("However, we couldn't load the native library, so this doesn't test much");
|
||||||
@ -349,7 +349,12 @@ public class NativeBigInteger extends BigInteger {
|
|||||||
ioe.printStackTrace();
|
ioe.printStackTrace();
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (in != null) try { in.close(); } catch (IOException ioe) {}
|
if (in != null) {
|
||||||
|
try {
|
||||||
|
in.close();
|
||||||
|
} catch (IOException ioe) { // nop
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,9 +69,9 @@ public class OrderedProperties extends Properties {
|
|||||||
synchronized (_lock) {
|
synchronized (_lock) {
|
||||||
return _data.equals(obj);
|
return _data.equals(obj);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
@ -96,9 +96,8 @@ public class OrderedProperties extends Properties {
|
|||||||
if (key == null) return null;
|
if (key == null) return null;
|
||||||
synchronized (_lock) {
|
synchronized (_lock) {
|
||||||
Object rv = _data.get(key);
|
Object rv = _data.get(key);
|
||||||
if ((rv != null) && (rv instanceof String))
|
if ((rv != null) && (rv instanceof String)) return (String) rv;
|
||||||
return (String) rv;
|
|
||||||
else
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -191,17 +190,17 @@ public class OrderedProperties extends Properties {
|
|||||||
return Collections.enumeration(keySet());
|
return Collections.enumeration(keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void list(PrintStream out) {
|
public void list(PrintStream out) { // nop
|
||||||
}
|
}
|
||||||
|
|
||||||
public void list(PrintWriter out) {
|
public void list(PrintWriter out) { // nop
|
||||||
}
|
}
|
||||||
|
|
||||||
public void load(InputStream in) {
|
public void load(InputStream in) { // nop
|
||||||
}
|
}
|
||||||
|
|
||||||
//public void save(OutputStream out, String header) {}
|
//public void save(OutputStream out, String header) {}
|
||||||
public void store(OutputStream out, String header) {
|
public void store(OutputStream out, String header) { // nop
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set buildEntrySet(Set data) {
|
private Set buildEntrySet(Set data) {
|
||||||
|
Reference in New Issue
Block a user