propagate from branch 'i2p.i2p.zzz.i2psnark' (head 738b0ee2a3e938f83c8524d7ee1cbd66c83d7d56)

to branch 'i2p.i2p' (head 7bc276bf13158ca72d687031fdf5e9921efc5050)
This commit is contained in:
zzz
2008-12-01 02:51:28 +00:00
35 changed files with 299 additions and 115 deletions

View File

@ -15,7 +15,7 @@ package net.i2p;
*/
public class CoreVersion {
public final static String ID = "$Revision: 1.72 $ $Date: 2008-08-24 12:00:00 $";
public final static String VERSION = "0.6.4";
public final static String VERSION = "0.6.5";
public static void main(String args[]) {
System.out.println("I2P Core version: " + VERSION);

View File

@ -91,7 +91,8 @@ public class I2PAppContext {
private volatile boolean _routingKeyGeneratorInitialized;
private volatile boolean _randomInitialized;
private volatile boolean _keyGeneratorInitialized;
/**
* Pull the default context, creating a new one if necessary, else using
* the first one created.
@ -105,7 +106,7 @@ public class I2PAppContext {
}
return _globalAppContext;
}
/**
* Lets root a brand new context
*
@ -113,6 +114,7 @@ public class I2PAppContext {
public I2PAppContext() {
this(true, null);
}
/**
* Lets root a brand new context
*
@ -120,6 +122,7 @@ public class I2PAppContext {
public I2PAppContext(Properties envProps) {
this(true, envProps);
}
/**
* @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);
}
/**
* Access the configuration attributes of this context, listing the properties
* provided during the context construction, as well as the ones included in
@ -194,9 +198,11 @@ public class I2PAppContext {
* over time.
*/
public StatManager statManager() {
if (!_statManagerInitialized) initializeStatManager();
if (!_statManagerInitialized)
initializeStatManager();
return _statManager;
}
private void initializeStatManager() {
synchronized (this) {
if (_statManager == null)
@ -215,9 +221,11 @@ public class I2PAppContext {
*
*/
public SessionKeyManager sessionKeyManager() {
if (!_sessionKeyManagerInitialized) initializeSessionKeyManager();
if (!_sessionKeyManagerInitialized)
initializeSessionKeyManager();
return _sessionKeyManager;
}
private void initializeSessionKeyManager() {
synchronized (this) {
if (_sessionKeyManager == null)
@ -232,9 +240,11 @@ public class I2PAppContext {
* specified to customize the naming service exposed.
*/
public NamingService namingService() {
if (!_namingServiceInitialized) initializeNamingService();
if (!_namingServiceInitialized)
initializeNamingService();
return _namingService;
}
private void initializeNamingService() {
synchronized (this) {
if (_namingService == null) {
@ -245,9 +255,11 @@ public class I2PAppContext {
}
public PetNameDB petnameDb() {
if (!_petnameDbInitialized) initializePetnameDb();
if (!_petnameDbInitialized)
initializePetnameDb();
return _petnameDb;
}
private void initializePetnameDb() {
synchronized (this) {
if (_petnameDb == null) {
@ -266,9 +278,11 @@ public class I2PAppContext {
* it ;)
*/
public ElGamalEngine elGamalEngine() {
if (!_elGamalEngineInitialized) initializeElGamalEngine();
if (!_elGamalEngineInitialized)
initializeElGamalEngine();
return _elGamalEngine;
}
private void initializeElGamalEngine() {
synchronized (this) {
if (_elGamalEngine == null) {
@ -289,9 +303,11 @@ public class I2PAppContext {
*
*/
public ElGamalAESEngine elGamalAESEngine() {
if (!_elGamalAESEngineInitialized) initializeElGamalAESEngine();
if (!_elGamalAESEngineInitialized)
initializeElGamalAESEngine();
return _elGamalAESEngine;
}
private void initializeElGamalAESEngine() {
synchronized (this) {
if (_elGamalAESEngine == null)
@ -307,9 +323,11 @@ public class I2PAppContext {
* disable it.
*/
public AESEngine aes() {
if (!_AESEngineInitialized) initializeAESEngine();
if (!_AESEngineInitialized)
initializeAESEngine();
return _AESEngine;
}
private void initializeAESEngine() {
synchronized (this) {
if (_AESEngine == null) {
@ -329,9 +347,11 @@ public class I2PAppContext {
* their own log levels, output locations, and rotation configuration.
*/
public LogManager logManager() {
if (!_logManagerInitialized) initializeLogManager();
if (!_logManagerInitialized)
initializeLogManager();
return _logManager;
}
private void initializeLogManager() {
synchronized (this) {
if (_logManager == null)
@ -339,15 +359,18 @@ public class I2PAppContext {
_logManagerInitialized = true;
}
}
/**
* There is absolutely no good reason to make this context specific,
* other than for consistency, and perhaps later we'll want to
* include some stats.
*/
public HMACGenerator hmac() {
if (!_hmacInitialized) initializeHMAC();
if (!_hmacInitialized)
initializeHMAC();
return _hmac;
}
private void initializeHMAC() {
synchronized (this) {
if (_hmac == null) {
@ -358,9 +381,11 @@ public class I2PAppContext {
}
public HMAC256Generator hmac256() {
if (!_hmac256Initialized) initializeHMAC256();
if (!_hmac256Initialized)
initializeHMAC256();
return _hmac256;
}
private void initializeHMAC256() {
synchronized (this) {
if (_hmac256 == null) {
@ -375,9 +400,11 @@ public class I2PAppContext {
*
*/
public SHA256Generator sha() {
if (!_shaInitialized) initializeSHA();
if (!_shaInitialized)
initializeSHA();
return _sha;
}
private void initializeSHA() {
synchronized (this) {
if (_sha == null)
@ -391,9 +418,11 @@ public class I2PAppContext {
*
*/
public DSAEngine dsa() {
if (!_dsaInitialized) initializeDSA();
if (!_dsaInitialized)
initializeDSA();
return _dsa;
}
private void initializeDSA() {
synchronized (this) {
if (_dsa == null) {
@ -411,9 +440,11 @@ public class I2PAppContext {
* the appContext, see the DSA, HMAC, and SHA comments above.
*/
public KeyGenerator keyGenerator() {
if (!_keyGeneratorInitialized) initializeKeyGenerator();
if (!_keyGeneratorInitialized)
initializeKeyGenerator();
return _keyGenerator;
}
private void initializeKeyGenerator() {
synchronized (this) {
if (_keyGenerator == null)
@ -428,9 +459,11 @@ public class I2PAppContext {
*
*/
public Clock clock() { // overridden in RouterContext
if (!_clockInitialized) initializeClock();
if (!_clockInitialized)
initializeClock();
return _clock;
}
protected void initializeClock() { // overridden in RouterContext
synchronized (this) {
if (_clock == null)
@ -447,9 +480,11 @@ public class I2PAppContext {
*
*/
public RoutingKeyGenerator routingKeyGenerator() {
if (!_routingKeyGeneratorInitialized) initializeRoutingKeyGenerator();
if (!_routingKeyGeneratorInitialized)
initializeRoutingKeyGenerator();
return _routingKeyGenerator;
}
private void initializeRoutingKeyGenerator() {
synchronized (this) {
if (_routingKeyGenerator == null)
@ -463,9 +498,11 @@ public class I2PAppContext {
*
*/
public RandomSource random() {
if (!_randomInitialized) initializeRandom();
if (!_randomInitialized)
initializeRandom();
return _random;
}
private void initializeRandom() {
synchronized (this) {
if (_random == null) {

View File

@ -41,24 +41,34 @@ import net.i2p.util.Log;
public class ATalk implements I2PSessionListener, Runnable {
/** logging hook - status messages are piped to this */
private final static Log _log = new Log(ATalk.class);
/** platform independent newline */
private final static String NL = System.getProperty("line.separator");
/** the current session */
private I2PSession _session;
/** who am i */
private Destination _myDestination;
/** who are you? */
private Destination _peerDestination;
/** location of my secret key file */
private String _myKeyFile;
/** location of their public key */
private String _theirDestinationFile;
/** where the application reads input from. currently set to standard input */
private BufferedReader _in;
/** where the application sends output to. currently set to standard output */
private BufferedWriter _out;
/** string that messages must begin with to be treated as files */
private final static String FILE_COMMAND = ".file: ";
/** the, erm, manual */
private final static String MANUAL = "ATalk: Anonymous Talk, a demo program for the Invisible Internet Project SDK"
+ NL
@ -84,7 +94,9 @@ public class ATalk implements I2PSessionListener, Runnable {
+ NL
+ "To end the talk session, enter a period on a line by itself and hit return"
+ NL;
public final static String PROP_CONFIG_LOCATION = "configFile";
private static final SimpleDateFormat _fmt = new SimpleDateFormat("hh:mm:ss.SSS");
/** 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);
}
// 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_PORT)) props.setProperty(I2PClient.PROP_TCP_PORT, "7654");
if (!props.containsKey(I2PClient.PROP_TCP_HOST))
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))
props.setProperty(I2PClient.PROP_RELIABILITY,
I2PClient.PROP_RELIABILITY_BEST_EFFORT);
props.setProperty(I2PClient.PROP_RELIABILITY, I2PClient.PROP_RELIABILITY_BEST_EFFORT);
_session = client.createSession(new FileInputStream(myFile), props);
_session.setSessionListener(this);
_session.connect();
@ -364,4 +377,5 @@ public class ATalk implements I2PSessionListener, Runnable {
public void reportAbuse(I2PSession session, int severity) {
_log.debug("Abuse reported of severity " + severity);
}
}
}

View File

@ -171,18 +171,14 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
for (Iterator iter = options.keySet().iterator(); iter.hasNext();) {
String key = (String) iter.next();
String val = options.getProperty(key);
if (key.startsWith("java")) {
if (_log.shouldLog(Log.DEBUG)) _log.debug("Skipping java.* property: " + key);
} else if (key.startsWith("user")) {
if (_log.shouldLog(Log.DEBUG)) _log.debug("Skipping user.* property: " + key);
} else if (key.startsWith("os")) {
if (_log.shouldLog(Log.DEBUG)) _log.debug("Skipping os.* property: " + key);
} else if (key.startsWith("sun")) {
if (_log.shouldLog(Log.DEBUG)) _log.debug("Skipping sun.* property: " + key);
} else if (key.startsWith("file")) {
if (_log.shouldLog(Log.DEBUG)) _log.debug("Skipping file.* property: " + key);
} else if (key.startsWith("line")) {
if (_log.shouldLog(Log.DEBUG)) _log.debug("Skipping line.* property: " + key);
if (key.startsWith("java") ||
key.startsWith("user") ||
key.startsWith("os") ||
key.startsWith("sun") ||
key.startsWith("file") ||
key.startsWith("line") ||
key.startsWith("wrapper")) {
if (_log.shouldLog(Log.DEBUG)) _log.debug("Skipping property: " + key);
} else if ((key.length() > 255) || (val.length() > 255)) {
if (_log.shouldLog(Log.WARN))
_log.warn(getPrefix() + "Not passing on property ["

View File

@ -39,6 +39,8 @@ public class Certificate extends DataStructureImpl {
/** Signed with 40-byte Signature and (optional) 32-byte hash */
public final static int CERTIFICATE_TYPE_SIGNED = 3;
public final static int CERTIFICATE_LENGTH_SIGNED_WITH_HASH = Signature.SIGNATURE_BYTES + Hash.HASH_LENGTH;
/** Contains multiple certs */
public final static int CERTIFICATE_TYPE_MULTIPLE = 4;
public Certificate() {
_type = 0;

View File

@ -164,7 +164,7 @@ public class PrivateKeyFile {
}
/** Also reads in the file to get the privKay and signingPrivKey,
/** Also reads in the file to get the privKey and signingPrivKey,
* which aren't available from I2PClient.
*/
public Destination createIfAbsent() throws I2PException, IOException, DataFormatException {

View File

@ -132,6 +132,7 @@ public class EepGet {
int numRetries = 5;
int markSize = 1024;
int lineLen = 40;
int inactivityTimeout = 60*1000;
String etag = null;
String saveAs = null;
String url = null;
@ -145,6 +146,9 @@ public class EepGet {
} else if (args[i].equals("-n")) {
numRetries = Integer.parseInt(args[i+1]);
i++;
} else if (args[i].equals("-t")) {
inactivityTimeout = 1000 * Integer.parseInt(args[i+1]);
i++;
} else if (args[i].equals("-e")) {
etag = "\"" + args[i+1] + "\"";
i++;
@ -174,7 +178,7 @@ public class EepGet {
EepGet get = new EepGet(I2PAppContext.getGlobalContext(), true, proxyHost, proxyPort, numRetries, saveAs, url, true, etag);
get.addStatusListener(get.new CLIStatusListener(markSize, lineLen));
get.fetch();
get.fetch(45*1000, -1, inactivityTimeout);
}
public static String suggestName(String url) {
@ -208,7 +212,7 @@ public class EepGet {
}
private static void usage() {
System.err.println("EepGet [-p localhost:4444] [-n #retries] [-o outputFile] [-m markSize lineLen] url");
System.err.println("EepGet [-p localhost:4444] [-n #retries] [-o outputFile] [-m markSize lineLen] [-t timeout] url");
}
public static interface StatusListener {
@ -416,7 +420,7 @@ public class EepGet {
SocketTimeout timeout = null;
if (_fetchHeaderTimeout > 0)
timeout = new SocketTimeout(_fetchHeaderTimeout);
final SocketTimeout stimeout = timeout; // ugly
final SocketTimeout stimeout = timeout; // ugly - why not use sotimeout?
timeout.setTimeoutCommand(new Runnable() {
public void run() {
if (_log.shouldLog(Log.DEBUG))
@ -457,7 +461,7 @@ public class EepGet {
}
_currentAttempt++;
if (_currentAttempt > _numRetries)
if (_currentAttempt > _numRetries || !_keepFetching)
break;
try {
long delay = _context.random().nextInt(60*1000);
@ -629,8 +633,6 @@ public class EepGet {
if (_log.shouldLog(Log.DEBUG))
_log.debug("rc: " + responseCode + " for " + _actualURL);
if(_transferFailed)
_log.error("Already failed for " + _actualURL);
boolean rcOk = false;
switch (responseCode) {
case 200: // full
@ -661,16 +663,24 @@ public class EepGet {
_keepFetching = false;
_notModified = true;
return;
case 403: // bad req
case 404: // not found
case 409: // bad addr helper
case 503: // no outproxy
_keepFetching = false;
_transferFailed = true;
// maybe we should throw instead of return to get the return code back to the user
return;
case 416: // completed (or range out of reach)
_bytesRemaining = 0;
_keepFetching = false;
return;
case 504: // gateway timeout
// throw out of doFetch() to fetch() and try again
throw new IOException("HTTP Proxy timeout");
default:
rcOk = false;
_keepFetching = false;
_transferFailed = true;
}