minor style changes
This commit is contained in:
@ -92,6 +92,7 @@ public class I2PAppContext {
|
|||||||
private volatile boolean _randomInitialized;
|
private volatile boolean _randomInitialized;
|
||||||
private volatile boolean _keyGeneratorInitialized;
|
private volatile boolean _keyGeneratorInitialized;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pull the default context, creating a new one if necessary, else using
|
* Pull the default context, creating a new one if necessary, else using
|
||||||
* the first one created.
|
* the first one created.
|
||||||
@ -113,6 +114,7 @@ public class I2PAppContext {
|
|||||||
public I2PAppContext() {
|
public I2PAppContext() {
|
||||||
this(true, null);
|
this(true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lets root a brand new context
|
* Lets root a brand new context
|
||||||
*
|
*
|
||||||
@ -120,6 +122,7 @@ public class I2PAppContext {
|
|||||||
public I2PAppContext(Properties envProps) {
|
public I2PAppContext(Properties envProps) {
|
||||||
this(true, envProps);
|
this(true, envProps);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param doInit should this context be used as the global one (if necessary)?
|
* @param doInit should this context be used as the global one (if necessary)?
|
||||||
*/
|
*/
|
||||||
@ -175,6 +178,7 @@ public class I2PAppContext {
|
|||||||
}
|
}
|
||||||
return System.getProperty(propName, defaultValue);
|
return System.getProperty(propName, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Access the configuration attributes of this context, listing the properties
|
* Access the configuration attributes of this context, listing the properties
|
||||||
* provided during the context construction, as well as the ones included in
|
* provided during the context construction, as well as the ones included in
|
||||||
@ -194,9 +198,11 @@ public class I2PAppContext {
|
|||||||
* over time.
|
* over time.
|
||||||
*/
|
*/
|
||||||
public StatManager statManager() {
|
public StatManager statManager() {
|
||||||
if (!_statManagerInitialized) initializeStatManager();
|
if (!_statManagerInitialized)
|
||||||
|
initializeStatManager();
|
||||||
return _statManager;
|
return _statManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeStatManager() {
|
private void initializeStatManager() {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (_statManager == null)
|
if (_statManager == null)
|
||||||
@ -215,9 +221,11 @@ public class I2PAppContext {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public SessionKeyManager sessionKeyManager() {
|
public SessionKeyManager sessionKeyManager() {
|
||||||
if (!_sessionKeyManagerInitialized) initializeSessionKeyManager();
|
if (!_sessionKeyManagerInitialized)
|
||||||
|
initializeSessionKeyManager();
|
||||||
return _sessionKeyManager;
|
return _sessionKeyManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeSessionKeyManager() {
|
private void initializeSessionKeyManager() {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (_sessionKeyManager == null)
|
if (_sessionKeyManager == null)
|
||||||
@ -232,9 +240,11 @@ public class I2PAppContext {
|
|||||||
* specified to customize the naming service exposed.
|
* specified to customize the naming service exposed.
|
||||||
*/
|
*/
|
||||||
public NamingService namingService() {
|
public NamingService namingService() {
|
||||||
if (!_namingServiceInitialized) initializeNamingService();
|
if (!_namingServiceInitialized)
|
||||||
|
initializeNamingService();
|
||||||
return _namingService;
|
return _namingService;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeNamingService() {
|
private void initializeNamingService() {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (_namingService == null) {
|
if (_namingService == null) {
|
||||||
@ -245,9 +255,11 @@ public class I2PAppContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public PetNameDB petnameDb() {
|
public PetNameDB petnameDb() {
|
||||||
if (!_petnameDbInitialized) initializePetnameDb();
|
if (!_petnameDbInitialized)
|
||||||
|
initializePetnameDb();
|
||||||
return _petnameDb;
|
return _petnameDb;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializePetnameDb() {
|
private void initializePetnameDb() {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (_petnameDb == null) {
|
if (_petnameDb == null) {
|
||||||
@ -266,9 +278,11 @@ public class I2PAppContext {
|
|||||||
* it ;)
|
* it ;)
|
||||||
*/
|
*/
|
||||||
public ElGamalEngine elGamalEngine() {
|
public ElGamalEngine elGamalEngine() {
|
||||||
if (!_elGamalEngineInitialized) initializeElGamalEngine();
|
if (!_elGamalEngineInitialized)
|
||||||
|
initializeElGamalEngine();
|
||||||
return _elGamalEngine;
|
return _elGamalEngine;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeElGamalEngine() {
|
private void initializeElGamalEngine() {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (_elGamalEngine == null) {
|
if (_elGamalEngine == null) {
|
||||||
@ -289,9 +303,11 @@ public class I2PAppContext {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public ElGamalAESEngine elGamalAESEngine() {
|
public ElGamalAESEngine elGamalAESEngine() {
|
||||||
if (!_elGamalAESEngineInitialized) initializeElGamalAESEngine();
|
if (!_elGamalAESEngineInitialized)
|
||||||
|
initializeElGamalAESEngine();
|
||||||
return _elGamalAESEngine;
|
return _elGamalAESEngine;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeElGamalAESEngine() {
|
private void initializeElGamalAESEngine() {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (_elGamalAESEngine == null)
|
if (_elGamalAESEngine == null)
|
||||||
@ -307,9 +323,11 @@ public class I2PAppContext {
|
|||||||
* disable it.
|
* disable it.
|
||||||
*/
|
*/
|
||||||
public AESEngine aes() {
|
public AESEngine aes() {
|
||||||
if (!_AESEngineInitialized) initializeAESEngine();
|
if (!_AESEngineInitialized)
|
||||||
|
initializeAESEngine();
|
||||||
return _AESEngine;
|
return _AESEngine;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeAESEngine() {
|
private void initializeAESEngine() {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (_AESEngine == null) {
|
if (_AESEngine == null) {
|
||||||
@ -329,9 +347,11 @@ public class I2PAppContext {
|
|||||||
* their own log levels, output locations, and rotation configuration.
|
* their own log levels, output locations, and rotation configuration.
|
||||||
*/
|
*/
|
||||||
public LogManager logManager() {
|
public LogManager logManager() {
|
||||||
if (!_logManagerInitialized) initializeLogManager();
|
if (!_logManagerInitialized)
|
||||||
|
initializeLogManager();
|
||||||
return _logManager;
|
return _logManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeLogManager() {
|
private void initializeLogManager() {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (_logManager == null)
|
if (_logManager == null)
|
||||||
@ -339,15 +359,18 @@ public class I2PAppContext {
|
|||||||
_logManagerInitialized = true;
|
_logManagerInitialized = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* There is absolutely no good reason to make this context specific,
|
* There is absolutely no good reason to make this context specific,
|
||||||
* other than for consistency, and perhaps later we'll want to
|
* other than for consistency, and perhaps later we'll want to
|
||||||
* include some stats.
|
* include some stats.
|
||||||
*/
|
*/
|
||||||
public HMACGenerator hmac() {
|
public HMACGenerator hmac() {
|
||||||
if (!_hmacInitialized) initializeHMAC();
|
if (!_hmacInitialized)
|
||||||
|
initializeHMAC();
|
||||||
return _hmac;
|
return _hmac;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeHMAC() {
|
private void initializeHMAC() {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (_hmac == null) {
|
if (_hmac == null) {
|
||||||
@ -358,9 +381,11 @@ public class I2PAppContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public HMAC256Generator hmac256() {
|
public HMAC256Generator hmac256() {
|
||||||
if (!_hmac256Initialized) initializeHMAC256();
|
if (!_hmac256Initialized)
|
||||||
|
initializeHMAC256();
|
||||||
return _hmac256;
|
return _hmac256;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeHMAC256() {
|
private void initializeHMAC256() {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (_hmac256 == null) {
|
if (_hmac256 == null) {
|
||||||
@ -375,9 +400,11 @@ public class I2PAppContext {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public SHA256Generator sha() {
|
public SHA256Generator sha() {
|
||||||
if (!_shaInitialized) initializeSHA();
|
if (!_shaInitialized)
|
||||||
|
initializeSHA();
|
||||||
return _sha;
|
return _sha;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeSHA() {
|
private void initializeSHA() {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (_sha == null)
|
if (_sha == null)
|
||||||
@ -391,9 +418,11 @@ public class I2PAppContext {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public DSAEngine dsa() {
|
public DSAEngine dsa() {
|
||||||
if (!_dsaInitialized) initializeDSA();
|
if (!_dsaInitialized)
|
||||||
|
initializeDSA();
|
||||||
return _dsa;
|
return _dsa;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeDSA() {
|
private void initializeDSA() {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (_dsa == null) {
|
if (_dsa == null) {
|
||||||
@ -411,9 +440,11 @@ public class I2PAppContext {
|
|||||||
* the appContext, see the DSA, HMAC, and SHA comments above.
|
* the appContext, see the DSA, HMAC, and SHA comments above.
|
||||||
*/
|
*/
|
||||||
public KeyGenerator keyGenerator() {
|
public KeyGenerator keyGenerator() {
|
||||||
if (!_keyGeneratorInitialized) initializeKeyGenerator();
|
if (!_keyGeneratorInitialized)
|
||||||
|
initializeKeyGenerator();
|
||||||
return _keyGenerator;
|
return _keyGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeKeyGenerator() {
|
private void initializeKeyGenerator() {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (_keyGenerator == null)
|
if (_keyGenerator == null)
|
||||||
@ -428,9 +459,11 @@ public class I2PAppContext {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public Clock clock() { // overridden in RouterContext
|
public Clock clock() { // overridden in RouterContext
|
||||||
if (!_clockInitialized) initializeClock();
|
if (!_clockInitialized)
|
||||||
|
initializeClock();
|
||||||
return _clock;
|
return _clock;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void initializeClock() { // overridden in RouterContext
|
protected void initializeClock() { // overridden in RouterContext
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (_clock == null)
|
if (_clock == null)
|
||||||
@ -447,9 +480,11 @@ public class I2PAppContext {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public RoutingKeyGenerator routingKeyGenerator() {
|
public RoutingKeyGenerator routingKeyGenerator() {
|
||||||
if (!_routingKeyGeneratorInitialized) initializeRoutingKeyGenerator();
|
if (!_routingKeyGeneratorInitialized)
|
||||||
|
initializeRoutingKeyGenerator();
|
||||||
return _routingKeyGenerator;
|
return _routingKeyGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeRoutingKeyGenerator() {
|
private void initializeRoutingKeyGenerator() {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (_routingKeyGenerator == null)
|
if (_routingKeyGenerator == null)
|
||||||
@ -463,9 +498,11 @@ public class I2PAppContext {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public RandomSource random() {
|
public RandomSource random() {
|
||||||
if (!_randomInitialized) initializeRandom();
|
if (!_randomInitialized)
|
||||||
|
initializeRandom();
|
||||||
return _random;
|
return _random;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeRandom() {
|
private void initializeRandom() {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (_random == null) {
|
if (_random == null) {
|
||||||
|
@ -41,24 +41,34 @@ import net.i2p.util.Log;
|
|||||||
public class ATalk implements I2PSessionListener, Runnable {
|
public class ATalk implements I2PSessionListener, Runnable {
|
||||||
/** logging hook - status messages are piped to this */
|
/** logging hook - status messages are piped to this */
|
||||||
private final static Log _log = new Log(ATalk.class);
|
private final static Log _log = new Log(ATalk.class);
|
||||||
|
|
||||||
/** platform independent newline */
|
/** platform independent newline */
|
||||||
private final static String NL = System.getProperty("line.separator");
|
private final static String NL = System.getProperty("line.separator");
|
||||||
|
|
||||||
/** the current session */
|
/** the current session */
|
||||||
private I2PSession _session;
|
private I2PSession _session;
|
||||||
|
|
||||||
/** who am i */
|
/** who am i */
|
||||||
private Destination _myDestination;
|
private Destination _myDestination;
|
||||||
|
|
||||||
/** who are you? */
|
/** who are you? */
|
||||||
private Destination _peerDestination;
|
private Destination _peerDestination;
|
||||||
|
|
||||||
/** location of my secret key file */
|
/** location of my secret key file */
|
||||||
private String _myKeyFile;
|
private String _myKeyFile;
|
||||||
|
|
||||||
/** location of their public key */
|
/** location of their public key */
|
||||||
private String _theirDestinationFile;
|
private String _theirDestinationFile;
|
||||||
|
|
||||||
/** where the application reads input from. currently set to standard input */
|
/** where the application reads input from. currently set to standard input */
|
||||||
private BufferedReader _in;
|
private BufferedReader _in;
|
||||||
|
|
||||||
/** where the application sends output to. currently set to standard output */
|
/** where the application sends output to. currently set to standard output */
|
||||||
private BufferedWriter _out;
|
private BufferedWriter _out;
|
||||||
|
|
||||||
/** string that messages must begin with to be treated as files */
|
/** string that messages must begin with to be treated as files */
|
||||||
private final static String FILE_COMMAND = ".file: ";
|
private final static String FILE_COMMAND = ".file: ";
|
||||||
|
|
||||||
/** the, erm, manual */
|
/** the, erm, manual */
|
||||||
private final static String MANUAL = "ATalk: Anonymous Talk, a demo program for the Invisible Internet Project SDK"
|
private final static String MANUAL = "ATalk: Anonymous Talk, a demo program for the Invisible Internet Project SDK"
|
||||||
+ NL
|
+ NL
|
||||||
@ -84,7 +94,9 @@ public class ATalk implements I2PSessionListener, Runnable {
|
|||||||
+ NL
|
+ NL
|
||||||
+ "To end the talk session, enter a period on a line by itself and hit return"
|
+ "To end the talk session, enter a period on a line by itself and hit return"
|
||||||
+ NL;
|
+ NL;
|
||||||
|
|
||||||
public final static String PROP_CONFIG_LOCATION = "configFile";
|
public final static String PROP_CONFIG_LOCATION = "configFile";
|
||||||
|
|
||||||
private static final SimpleDateFormat _fmt = new SimpleDateFormat("hh:mm:ss.SSS");
|
private static final SimpleDateFormat _fmt = new SimpleDateFormat("hh:mm:ss.SSS");
|
||||||
|
|
||||||
/** Construct the talk engine, but don't connect yet */
|
/** Construct the talk engine, but don't connect yet */
|
||||||
@ -111,11 +123,12 @@ public class ATalk implements I2PSessionListener, Runnable {
|
|||||||
_log.warn("Unable to load up the ATalk config file " + configLocation);
|
_log.warn("Unable to load up the ATalk config file " + configLocation);
|
||||||
}
|
}
|
||||||
// Provide any router or client API configuration here.
|
// Provide any router or client API configuration here.
|
||||||
if (!props.containsKey(I2PClient.PROP_TCP_HOST)) props.setProperty(I2PClient.PROP_TCP_HOST, "localhost");
|
if (!props.containsKey(I2PClient.PROP_TCP_HOST))
|
||||||
if (!props.containsKey(I2PClient.PROP_TCP_PORT)) props.setProperty(I2PClient.PROP_TCP_PORT, "7654");
|
props.setProperty(I2PClient.PROP_TCP_HOST, "localhost");
|
||||||
|
if (!props.containsKey(I2PClient.PROP_TCP_PORT))
|
||||||
|
props.setProperty(I2PClient.PROP_TCP_PORT, "7654");
|
||||||
if (!props.containsKey(I2PClient.PROP_RELIABILITY))
|
if (!props.containsKey(I2PClient.PROP_RELIABILITY))
|
||||||
props.setProperty(I2PClient.PROP_RELIABILITY,
|
props.setProperty(I2PClient.PROP_RELIABILITY, I2PClient.PROP_RELIABILITY_BEST_EFFORT);
|
||||||
I2PClient.PROP_RELIABILITY_BEST_EFFORT);
|
|
||||||
_session = client.createSession(new FileInputStream(myFile), props);
|
_session = client.createSession(new FileInputStream(myFile), props);
|
||||||
_session.setSessionListener(this);
|
_session.setSessionListener(this);
|
||||||
_session.connect();
|
_session.connect();
|
||||||
@ -365,3 +378,4 @@ public class ATalk implements I2PSessionListener, Runnable {
|
|||||||
_log.debug("Abuse reported of severity " + severity);
|
_log.debug("Abuse reported of severity " + severity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user