beginning of branch i2p.i2p.i2p
This commit is contained in:
7
router/java/test/net/i2p/data/i2np/.nbattrs
Normal file
7
router/java/test/net/i2p/data/i2np/.nbattrs
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE attributes PUBLIC "-//NetBeans//DTD DefaultAttributes 1.0//EN" "http://www.netbeans.org/dtds/attributes-1_0.dtd">
|
||||
<attributes version="1.0">
|
||||
<fileobject name="DatabaseStoreMessageTest.java">
|
||||
<attr name="class_dependency_net.i2p.data.StructureTest" stringvalue="DatabaseStoreMessageTest"/>
|
||||
</fileobject>
|
||||
</attributes>
|
@ -0,0 +1,38 @@
|
||||
package net.i2p.data;
|
||||
/*
|
||||
* 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
|
||||
* your children, but it might. Use at your own risk.
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import net.i2p.data.DataFormatException;
|
||||
import net.i2p.data.DataStructure;
|
||||
import net.i2p.data.RouterInfo;
|
||||
import net.i2p.data.i2np.DatabaseStoreMessage;
|
||||
import net.i2p.util.Clock;
|
||||
|
||||
/**
|
||||
* Test harness for loading / storing I2NP DatabaseStore message objects
|
||||
*
|
||||
* @author jrandom
|
||||
*/
|
||||
class DatabaseStoreMessageTest extends StructureTest {
|
||||
static {
|
||||
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;
|
||||
}
|
||||
public DataStructure createStructureToRead() { return new DatabaseStoreMessage(); }
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package net.i2p.data;
|
||||
/*
|
||||
* 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
|
||||
* your children, but it might. Use at your own risk.
|
||||
*
|
||||
*/
|
||||
|
||||
import net.i2p.data.DataFormatException;
|
||||
import net.i2p.data.DataStructure;
|
||||
import net.i2p.data.Hash;
|
||||
import net.i2p.data.SessionKey;
|
||||
import net.i2p.data.TunnelId;
|
||||
import net.i2p.data.i2np.DeliveryInstructions;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
* Test harness for loading / storing DeliveryInstructions objects
|
||||
*
|
||||
* @author jrandom
|
||||
*/
|
||||
class DeliveryInstructionsTest extends StructureTest {
|
||||
private final static Log _log = new Log(DeliveryInstructionsTest.class);
|
||||
static {
|
||||
TestData.registerTest(new DeliveryInstructionsTest(), "DeliveryInstructions");
|
||||
}
|
||||
public DataStructure createDataStructure() throws DataFormatException {
|
||||
DeliveryInstructions instructions = new DeliveryInstructions();
|
||||
instructions.setDelayRequested(true);
|
||||
instructions.setDelaySeconds(42);
|
||||
instructions.setDeliveryMode(DeliveryInstructions.DELIVERY_MODE_TUNNEL);
|
||||
instructions.setEncrypted(true);
|
||||
SessionKey key = new SessionKey();
|
||||
byte keyData[] = new byte[SessionKey.KEYSIZE_BYTES];
|
||||
for (int i = 0; i < keyData.length; i++)
|
||||
keyData[i] = (byte)i;
|
||||
key.setData(keyData);
|
||||
instructions.setEncryptionKey(key);
|
||||
Hash hash = new Hash();
|
||||
byte hashData[] = new byte[32];
|
||||
for (int i = 0; i < hashData.length; i++)
|
||||
hashData[i] = (byte)(i%32);
|
||||
hash.setData(hashData);
|
||||
instructions.setRouter(hash);
|
||||
TunnelId id = new TunnelId();
|
||||
id.setTunnelId(666);
|
||||
instructions.setTunnelId(id);
|
||||
_log.debug("Instructions created: " + instructions + "\nBase 64: " + instructions.toBase64());
|
||||
return instructions;
|
||||
}
|
||||
public DataStructure createStructureToRead() { return new DeliveryInstructions(); }
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
package net.i2p.data;
|
||||
/*
|
||||
* 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
|
||||
* your children, but it might. Use at your own risk.
|
||||
*
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import net.i2p.data.DataFormatException;
|
||||
import net.i2p.data.i2np.DatabaseStoreMessage;
|
||||
import net.i2p.data.i2np.I2NPMessage;
|
||||
import net.i2p.data.i2np.I2NPMessageReader;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
/**
|
||||
* Test harness for loading / storing I2NP DatabaseStore message objects
|
||||
*
|
||||
* @author jrandom
|
||||
*/
|
||||
class I2NPMessageReaderTest implements I2NPMessageReader.I2NPMessageEventListener {
|
||||
private final static Log _log = new Log(I2NPMessageReaderTest.class);
|
||||
|
||||
public static void main(String args[]) {
|
||||
I2NPMessageReaderTest test = new I2NPMessageReaderTest();
|
||||
test.runTest();
|
||||
try { Thread.sleep(30*1000); } catch (InterruptedException ie) {}
|
||||
}
|
||||
|
||||
public void runTest() {
|
||||
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());
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
public void disconnected(I2NPMessageReader reader) {
|
||||
_log.debug("Disconnected");
|
||||
}
|
||||
|
||||
public void messageReceived(I2NPMessageReader reader, I2NPMessage message, long msToRead) {
|
||||
_log.debug("Message received: " + message);
|
||||
}
|
||||
|
||||
public void readError(I2NPMessageReader reader, Exception error) {
|
||||
_log.debug("Read error: " + error.getMessage(), error);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user