allow a whole set of OOM listeners on threads, not just one
cache the hash's base64 value too use the context's logging more logging updates
This commit is contained in:
@ -31,6 +31,8 @@ public class AESEngine {
|
|||||||
public AESEngine(I2PAppContext ctx) {
|
public AESEngine(I2PAppContext ctx) {
|
||||||
_context = ctx;
|
_context = ctx;
|
||||||
_log = _context.logManager().getLog(AESEngine.class);
|
_log = _context.logManager().getLog(AESEngine.class);
|
||||||
|
if (getClass() == AESEngine.class)
|
||||||
|
_log.warn("Warning: AES is disabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Encrypt the payload with the session key
|
/** Encrypt the payload with the session key
|
||||||
@ -44,7 +46,6 @@ public class AESEngine {
|
|||||||
|| (initializationVector.length != 16)) return null;
|
|| (initializationVector.length != 16)) return null;
|
||||||
|
|
||||||
byte cyphertext[] = new byte[payload.length + (16 - (payload.length % 16))];
|
byte cyphertext[] = new byte[payload.length + (16 - (payload.length % 16))];
|
||||||
_log.warn("Warning: AES is disabled");
|
|
||||||
System.arraycopy(payload, 0, cyphertext, 0, payload.length);
|
System.arraycopy(payload, 0, cyphertext, 0, payload.length);
|
||||||
return cyphertext;
|
return cyphertext;
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ import net.i2p.I2PAppContext;
|
|||||||
* @author jrandom
|
* @author jrandom
|
||||||
*/
|
*/
|
||||||
public class DummyElGamalEngine extends ElGamalEngine {
|
public class DummyElGamalEngine extends ElGamalEngine {
|
||||||
private final static Log _log = new Log(DummyElGamalEngine.class);
|
private Log _log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ElGamal engine should only be constructed and accessed through the
|
* The ElGamal engine should only be constructed and accessed through the
|
||||||
@ -35,6 +35,7 @@ public class DummyElGamalEngine extends ElGamalEngine {
|
|||||||
*/
|
*/
|
||||||
public DummyElGamalEngine(I2PAppContext context) {
|
public DummyElGamalEngine(I2PAppContext context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
_log = context.logManager().getLog(DummyElGamalEngine.class);
|
||||||
_log.log(Log.CRIT, "Dummy ElGamal engine in use! NO DATA SECURITY. Danger Will Robinson, Danger!",
|
_log.log(Log.CRIT, "Dummy ElGamal engine in use! NO DATA SECURITY. Danger Will Robinson, Danger!",
|
||||||
new Exception("I really hope you know what you're doing"));
|
new Exception("I really hope you know what you're doing"));
|
||||||
}
|
}
|
||||||
@ -93,11 +94,13 @@ public class DummyElGamalEngine extends ElGamalEngine {
|
|||||||
}
|
}
|
||||||
Hash calcHash = SHA256Generator.getInstance().calculateHash(rv);
|
Hash calcHash = SHA256Generator.getInstance().calculateHash(rv);
|
||||||
if (calcHash.equals(hash)) {
|
if (calcHash.equals(hash)) {
|
||||||
_log.debug("Hash matches: " + DataHelper.toString(hash.getData(), hash.getData().length));
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
|
_log.debug("Hash matches: " + DataHelper.toString(hash.getData(), hash.getData().length));
|
||||||
return rv;
|
return rv;
|
||||||
} else {
|
} else {
|
||||||
_log.debug("Doesn't match hash [calc=" + calcHash + " sent hash=" + hash + "]\ndata = " + new String(rv),
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
new Exception("Doesn't match"));
|
_log.debug("Doesn't match hash [calc=" + calcHash + " sent hash=" + hash + "]\ndata = " + new String(rv),
|
||||||
|
new Exception("Doesn't match"));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ public class Hash extends DataStructureImpl {
|
|||||||
private final static Log _log = new Log(Hash.class);
|
private final static Log _log = new Log(Hash.class);
|
||||||
private byte[] _data;
|
private byte[] _data;
|
||||||
private volatile String _stringified;
|
private volatile String _stringified;
|
||||||
|
private volatile String _base64ed;
|
||||||
|
|
||||||
public final static int HASH_LENGTH = 32;
|
public final static int HASH_LENGTH = 32;
|
||||||
public final static Hash FAKE_HASH = new Hash(new byte[HASH_LENGTH]);
|
public final static Hash FAKE_HASH = new Hash(new byte[HASH_LENGTH]);
|
||||||
@ -44,11 +45,13 @@ public class Hash extends DataStructureImpl {
|
|||||||
public void setData(byte[] data) {
|
public void setData(byte[] data) {
|
||||||
_data = data;
|
_data = data;
|
||||||
_stringified = null;
|
_stringified = null;
|
||||||
|
_base64ed = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
public void readBytes(InputStream in) throws DataFormatException, IOException {
|
||||||
_data = new byte[HASH_LENGTH];
|
_data = new byte[HASH_LENGTH];
|
||||||
_stringified = null;
|
_stringified = null;
|
||||||
|
_base64ed = null;
|
||||||
int read = read(in, _data);
|
int read = read(in, _data);
|
||||||
if (read != HASH_LENGTH) throw new DataFormatException("Not enough bytes to read the hash");
|
if (read != HASH_LENGTH) throw new DataFormatException("Not enough bytes to read the hash");
|
||||||
}
|
}
|
||||||
@ -82,4 +85,11 @@ public class Hash extends DataStructureImpl {
|
|||||||
}
|
}
|
||||||
return _stringified;
|
return _stringified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String toBase64() {
|
||||||
|
if (_base64ed == null) {
|
||||||
|
_base64ed = super.toBase64();
|
||||||
|
}
|
||||||
|
return _base64ed;
|
||||||
|
}
|
||||||
}
|
}
|
@ -9,6 +9,11 @@ package net.i2p.util;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In case its useful later...
|
* In case its useful later...
|
||||||
* (e.g. w/ native programatic thread dumping, etc)
|
* (e.g. w/ native programatic thread dumping, etc)
|
||||||
@ -16,7 +21,7 @@ package net.i2p.util;
|
|||||||
*/
|
*/
|
||||||
public class I2PThread extends Thread {
|
public class I2PThread extends Thread {
|
||||||
private static Log _log;
|
private static Log _log;
|
||||||
private static OOMEventListener _lsnr;
|
private static Set _listeners = new HashSet(4);
|
||||||
|
|
||||||
public I2PThread() {
|
public I2PThread() {
|
||||||
super();
|
super();
|
||||||
@ -38,19 +43,29 @@ public class I2PThread extends Thread {
|
|||||||
try {
|
try {
|
||||||
super.run();
|
super.run();
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
if ((t instanceof OutOfMemoryError) && (_lsnr != null)) _lsnr.outOfMemory((OutOfMemoryError) t);
|
if (t instanceof OutOfMemoryError)
|
||||||
|
fireOOM((OutOfMemoryError)t);
|
||||||
// we cant assume log is created
|
// we cant assume log is created
|
||||||
if (_log == null) _log = new Log(I2PThread.class);
|
if (_log == null) _log = new Log(I2PThread.class);
|
||||||
_log.log(Log.CRIT, "Killing thread " + getName(), t);
|
_log.log(Log.CRIT, "Killing thread " + getName(), t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setOOMEventListener(OOMEventListener lsnr) {
|
private void fireOOM(OutOfMemoryError oom) {
|
||||||
_lsnr = lsnr;
|
for (Iterator iter = _listeners.iterator(); iter.hasNext(); ) {
|
||||||
|
OOMEventListener listener = (OOMEventListener)iter.next();
|
||||||
|
listener.outOfMemory(oom);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OOMEventListener getOOMEventListener() {
|
/** register a new component that wants notification of OOM events */
|
||||||
return _lsnr;
|
public static void addOOMEventListener(OOMEventListener lsnr) {
|
||||||
|
_listeners.add(lsnr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** unregister a component that wants notification of OOM events */
|
||||||
|
public static void removeOOMEventListener(OOMEventListener lsnr) {
|
||||||
|
_listeners.remove(lsnr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface OOMEventListener {
|
public interface OOMEventListener {
|
||||||
|
@ -269,6 +269,9 @@ public class LogManager {
|
|||||||
_consoleBufferSize = DEFAULT_CONSOLEBUFFERSIZE;
|
_consoleBufferSize = DEFAULT_CONSOLEBUFFERSIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
|
_log.debug("Log set to use the base log file as " + _baseLogfilename);
|
||||||
|
|
||||||
parseLimits(config);
|
parseLimits(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user