big ol' update to strip out the singletons, replacing them with

a rooted app context.  The core itself has its own I2PAppContext
(see its javadoc for, uh, docs), and the router extends that to
expose the router's singletons.  The main point of this is to
make it so that we can run multiple routers in the same JVM, even
to allow different apps in the same JVM to switch singleton
implementations (e.g. run some routers with one set of profile
calculators, and other routers with a different one).
There is still some work to be done regarding the actual boot up
of multiple routers in a JVM, as well as their configuration,
though the plan is to have the RouterContext override the
I2PAppContext's getProperty/getPropertyNames methods to read from
a config file (seperate ones per context) instead of using the
System.getProperty that the base I2PAppContext uses.
Once the multi-router is working, i'll shim in a VMCommSystem
that doesn't depend upon sockets or threads to read/write (and
that uses configurable message send delays / disconnects / etc,
perhaps using data from the routerContext.getProperty to drive it).
I could hold off until the sim is all working, but there's a
truckload of changes in here and I hate dealing with conflicts ;)
Everything works - I've been running 'er for a while and kicked
the tires a bit, but if you see something amiss, please let me
know.
This commit is contained in:
jrandom
2004-04-24 11:54:35 +00:00
committed by zzz
parent c29a6b95ae
commit 393b1d7674
217 changed files with 16662 additions and 15452 deletions

View File

@ -1,9 +1,9 @@
package net.i2p.data.i2np;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
@ -29,13 +29,13 @@ class DatabaseStoreMessageTest extends StructureTest {
TestData.registerTest(new DatabaseStoreMessageTest(), "DatabaseStoreMessage");
}
public DataStructure createDataStructure() throws DataFormatException {
DatabaseStoreMessage msg = new DatabaseStoreMessage();
RouterInfo info = (RouterInfo)new RouterInfoTest().createDataStructure();
msg.setKey(info.getIdentity().getHash());
msg.setMessageExpiration(new Date(Clock.getInstance().now()));
msg.setUniqueId(42);
msg.setRouterInfo(info);
return msg;
DatabaseStoreMessage msg = new DatabaseStoreMessage(_context);
RouterInfo info = (RouterInfo)new RouterInfoTest().createDataStructure();
msg.setKey(info.getIdentity().getHash());
msg.setMessageExpiration(new Date(Clock.getInstance().now()));
msg.setUniqueId(42);
msg.setRouterInfo(info);
return msg;
}
public DataStructure createStructureToRead() { return new DatabaseStoreMessage(); }
public DataStructure createStructureToRead() { return new DatabaseStoreMessage(_context); }
}

View File

@ -1,9 +1,9 @@
package net.i2p.data.i2np;
/*
* free (adj.): unencumbered; not under the control of others
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* Written by jrandom in 2003 and released into the public domain
* with no warranty of any kind, either expressed or implied.
* It probably won't make your computer catch on fire, or eat
* your children, but it might. Use at your own risk.
*
*/
@ -18,6 +18,7 @@ import net.i2p.data.i2np.DatabaseStoreMessage;
import net.i2p.data.i2np.I2NPMessage;
import net.i2p.data.i2np.I2NPMessageReader;
import net.i2p.util.Log;
import net.i2p.router.RouterContext;
/**
* Test harness for loading / storing I2NP DatabaseStore message objects
@ -26,53 +27,54 @@ import net.i2p.util.Log;
*/
class I2NPMessageReaderTest implements I2NPMessageReader.I2NPMessageEventListener {
private final static Log _log = new Log(I2NPMessageReaderTest.class);
private static RouterContext _context = new RouterContext(null);
public static void main(String args[]) {
I2NPMessageReaderTest test = new I2NPMessageReaderTest();
test.runTest();
try { Thread.sleep(30*1000); } catch (InterruptedException ie) {}
I2NPMessageReaderTest test = new I2NPMessageReaderTest();
test.runTest();
try { Thread.sleep(30*1000); } catch (InterruptedException ie) {}
}
public void runTest() {
InputStream data = getData();
test(data);
InputStream data = getData();
test(data);
}
private InputStream getData() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
DatabaseStoreMessage msg = (DatabaseStoreMessage)new DatabaseStoreMessageTest().createDataStructure();
msg.writeBytes(baos);
msg.writeBytes(baos);
msg.writeBytes(baos);
_log.debug("DB Store message in tunnel contains: " + msg);
msg.writeBytes(baos);
} catch (DataFormatException dfe) {
_log.error("Error building data", dfe);
} catch (IOException ioe) {
_log.error("Error writing stream", ioe);
}
return new ByteArrayInputStream(baos.toByteArray());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
DatabaseStoreMessage msg = (DatabaseStoreMessage)new DatabaseStoreMessageTest().createDataStructure();
msg.writeBytes(baos);
msg.writeBytes(baos);
msg.writeBytes(baos);
_log.debug("DB Store message in tunnel contains: " + msg);
msg.writeBytes(baos);
} catch (DataFormatException dfe) {
_log.error("Error building data", dfe);
} catch (IOException ioe) {
_log.error("Error writing stream", ioe);
}
return new ByteArrayInputStream(baos.toByteArray());
}
private void test(InputStream in) {
_log.debug("Testing the input stream");
I2NPMessageReader reader = new I2NPMessageReader(in, this);
_log.debug("Created, beginning reading");
reader.startReading();
_log.debug("Reading commenced");
_log.debug("Testing the input stream");
I2NPMessageReader reader = new I2NPMessageReader(_context, in, this);
_log.debug("Created, beginning reading");
reader.startReading();
_log.debug("Reading commenced");
}
public void disconnected(I2NPMessageReader reader) {
_log.debug("Disconnected");
_log.debug("Disconnected");
}
public void messageReceived(I2NPMessageReader reader, I2NPMessage message, long msToRead) {
_log.debug("Message received: " + message);
_log.debug("Message received: " + message);
}
public void readError(I2NPMessageReader reader, Exception error) {
_log.debug("Read error: " + error.getMessage(), error);
_log.debug("Read error: " + error.getMessage(), error);
}
}