forked from I2P_Developers/i2p.i2p
I2CP: Don't have I2CP Messages extend DataStructureImpl, to save space
Ditto MessageId and SessionId. Fixup unit tests as required
This commit is contained in:
@ -13,14 +13,14 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
import net.i2p.data.DataStructure;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the base functionality of API messages
|
* Defines the base functionality of API messages
|
||||||
*
|
*
|
||||||
|
* As of 0.9.48, does NOT extend DataStructure.
|
||||||
|
*
|
||||||
* @author jrandom
|
* @author jrandom
|
||||||
*/
|
*/
|
||||||
public interface I2CPMessage extends DataStructure {
|
public interface I2CPMessage {
|
||||||
/**
|
/**
|
||||||
* Read the contents from the input stream into the current class's format.
|
* Read the contents from the input stream into the current class's format.
|
||||||
* The stream should be the message body as defined by the client access layer
|
* The stream should be the message body as defined by the client access layer
|
||||||
|
@ -16,14 +16,15 @@ import java.io.OutputStream;
|
|||||||
|
|
||||||
import net.i2p.data.DataFormatException;
|
import net.i2p.data.DataFormatException;
|
||||||
import net.i2p.data.DataHelper;
|
import net.i2p.data.DataHelper;
|
||||||
import net.i2p.data.DataStructureImpl;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the base message implementation.
|
* Defines the base message implementation.
|
||||||
*
|
*
|
||||||
|
* As of 0.9.48, does NOT extend DataStructureImpl.
|
||||||
|
*
|
||||||
* @author jrandom
|
* @author jrandom
|
||||||
*/
|
*/
|
||||||
public abstract class I2CPMessageImpl extends DataStructureImpl implements I2CPMessage {
|
public abstract class I2CPMessageImpl implements I2CPMessage {
|
||||||
|
|
||||||
public I2CPMessageImpl() { // nop
|
public I2CPMessageImpl() { // nop
|
||||||
}
|
}
|
||||||
|
@ -15,15 +15,16 @@ import java.io.OutputStream;
|
|||||||
|
|
||||||
import net.i2p.data.DataFormatException;
|
import net.i2p.data.DataFormatException;
|
||||||
import net.i2p.data.DataHelper;
|
import net.i2p.data.DataHelper;
|
||||||
import net.i2p.data.DataStructureImpl;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the message ID of a message delivered between a router and a client
|
* Defines the message ID of a message delivered between a router and a client
|
||||||
* in a particular session. These IDs are not globally unique.
|
* in a particular session. These IDs are not globally unique.
|
||||||
*
|
*
|
||||||
|
* As of 0.9.48, does NOT extend DataStructureImpl.
|
||||||
|
*
|
||||||
* @author jrandom
|
* @author jrandom
|
||||||
*/
|
*/
|
||||||
public class MessageId extends DataStructureImpl {
|
public class MessageId {
|
||||||
private long _messageId;
|
private long _messageId;
|
||||||
|
|
||||||
public MessageId() {
|
public MessageId() {
|
||||||
|
@ -14,15 +14,16 @@ import java.io.OutputStream;
|
|||||||
|
|
||||||
import net.i2p.data.DataFormatException;
|
import net.i2p.data.DataFormatException;
|
||||||
import net.i2p.data.DataHelper;
|
import net.i2p.data.DataHelper;
|
||||||
import net.i2p.data.DataStructureImpl;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the token passed between the router and client to associate messages
|
* Defines the token passed between the router and client to associate messages
|
||||||
* with a particular session. These IDs are not globally unique.
|
* with a particular session. These IDs are not globally unique.
|
||||||
*
|
*
|
||||||
|
* As of 0.9.48, does NOT extend DataStructureImpl.
|
||||||
|
*
|
||||||
* @author jrandom
|
* @author jrandom
|
||||||
*/
|
*/
|
||||||
public class SessionId extends DataStructureImpl {
|
public class SessionId {
|
||||||
private int _sessionId;
|
private int _sessionId;
|
||||||
|
|
||||||
public SessionId() {
|
public SessionId() {
|
||||||
|
@ -26,7 +26,7 @@ public class TunnelIdTest extends StructureTest {
|
|||||||
* so we can test it as a structure
|
* so we can test it as a structure
|
||||||
* @since 0.9.48 TunnelId no longer extends DataStructureImpl
|
* @since 0.9.48 TunnelId no longer extends DataStructureImpl
|
||||||
*/
|
*/
|
||||||
private class TunnelIdStructure extends TunnelId implements DataStructure {
|
private static class TunnelIdStructure extends TunnelId implements DataStructure {
|
||||||
public Hash calculateHash() { return null; }
|
public Hash calculateHash() { return null; }
|
||||||
public void fromByteArray(byte[] in) {}
|
public void fromByteArray(byte[] in) {}
|
||||||
public byte[] toByteArray() { return null; }
|
public byte[] toByteArray() { return null; }
|
||||||
|
@ -8,8 +8,6 @@ package net.i2p.data.i2cp;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import net.i2p.data.StructureTest;
|
|
||||||
import net.i2p.data.DataStructure;
|
|
||||||
import net.i2p.data.DataFormatException;
|
import net.i2p.data.DataFormatException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,10 +15,10 @@ import net.i2p.data.DataFormatException;
|
|||||||
*
|
*
|
||||||
* @author str4d
|
* @author str4d
|
||||||
*/
|
*/
|
||||||
public class BandwidthLimitsMessageTest extends StructureTest {
|
public class BandwidthLimitsMessageTest extends I2CPTstBase {
|
||||||
public DataStructure createDataStructure() throws DataFormatException {
|
public I2CPMessageImpl createDataStructure() throws DataFormatException {
|
||||||
BandwidthLimitsMessage msg = new BandwidthLimitsMessage(10240, 1024);
|
BandwidthLimitsMessage msg = new BandwidthLimitsMessage(10240, 1024);
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
public DataStructure createStructureToRead() { return new BandwidthLimitsMessage(); }
|
public I2CPMessageImpl createStructureToRead() { return new BandwidthLimitsMessage(); }
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,6 @@ package net.i2p.data.i2cp;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import net.i2p.data.StructureTest;
|
|
||||||
import net.i2p.data.DataStructure;
|
|
||||||
import net.i2p.data.DataFormatException;
|
import net.i2p.data.DataFormatException;
|
||||||
import net.i2p.data.PrivateKey;
|
import net.i2p.data.PrivateKey;
|
||||||
import net.i2p.data.PrivateKeyTest;
|
import net.i2p.data.PrivateKeyTest;
|
||||||
@ -23,8 +21,8 @@ import net.i2p.data.LeaseSetTest;
|
|||||||
*
|
*
|
||||||
* @author jrandom
|
* @author jrandom
|
||||||
*/
|
*/
|
||||||
public class CreateLeaseSetMessageTest extends StructureTest {
|
public class CreateLeaseSetMessageTest extends I2CPTstBase {
|
||||||
public DataStructure createDataStructure() throws DataFormatException {
|
public I2CPMessageImpl createDataStructure() throws DataFormatException {
|
||||||
CreateLeaseSetMessage msg = new CreateLeaseSetMessage();
|
CreateLeaseSetMessage msg = new CreateLeaseSetMessage();
|
||||||
msg.setPrivateKey((PrivateKey)(new PrivateKeyTest()).createDataStructure());
|
msg.setPrivateKey((PrivateKey)(new PrivateKeyTest()).createDataStructure());
|
||||||
msg.setSigningPrivateKey((SigningPrivateKey)(new SigningPrivateKeyTest()).createDataStructure());
|
msg.setSigningPrivateKey((SigningPrivateKey)(new SigningPrivateKeyTest()).createDataStructure());
|
||||||
@ -32,5 +30,5 @@ public class CreateLeaseSetMessageTest extends StructureTest {
|
|||||||
msg.setSessionId((SessionId)(new SessionIdTest()).createDataStructure());
|
msg.setSessionId((SessionId)(new SessionIdTest()).createDataStructure());
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
public DataStructure createStructureToRead() { return new CreateLeaseSetMessage(); }
|
public I2CPMessageImpl createStructureToRead() { return new CreateLeaseSetMessage(); }
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,6 @@ package net.i2p.data.i2cp;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import net.i2p.data.StructureTest;
|
|
||||||
import net.i2p.data.DataStructure;
|
|
||||||
import net.i2p.data.DataFormatException;
|
import net.i2p.data.DataFormatException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,11 +15,11 @@ import net.i2p.data.DataFormatException;
|
|||||||
*
|
*
|
||||||
* @author jrandom
|
* @author jrandom
|
||||||
*/
|
*/
|
||||||
public class CreateSessionMessageTest extends StructureTest {
|
public class CreateSessionMessageTest extends I2CPTstBase {
|
||||||
public DataStructure createDataStructure() throws DataFormatException {
|
public I2CPMessageImpl createDataStructure() throws DataFormatException {
|
||||||
CreateSessionMessage msg = new CreateSessionMessage();
|
CreateSessionMessage msg = new CreateSessionMessage();
|
||||||
msg.setSessionConfig((SessionConfig)(new SessionConfigTest()).createDataStructure());
|
msg.setSessionConfig((SessionConfig)(new SessionConfigTest()).createDataStructure());
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
public DataStructure createStructureToRead() { return new CreateSessionMessage(); }
|
public I2CPMessageImpl createStructureToRead() { return new CreateSessionMessage(); }
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,6 @@ package net.i2p.data.i2cp;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import net.i2p.data.StructureTest;
|
|
||||||
import net.i2p.data.DataStructure;
|
|
||||||
import net.i2p.data.DataFormatException;
|
import net.i2p.data.DataFormatException;
|
||||||
import net.i2p.data.Hash;
|
import net.i2p.data.Hash;
|
||||||
import net.i2p.util.RandomSource;
|
import net.i2p.util.RandomSource;
|
||||||
@ -19,13 +17,13 @@ import net.i2p.util.RandomSource;
|
|||||||
*
|
*
|
||||||
* @author str4d
|
* @author str4d
|
||||||
*/
|
*/
|
||||||
public class DestLookupMessageTest extends StructureTest {
|
public class DestLookupMessageTest extends I2CPTstBase {
|
||||||
public DataStructure createDataStructure() throws DataFormatException {
|
public I2CPMessageImpl createDataStructure() throws DataFormatException {
|
||||||
byte h[] = new byte[Hash.HASH_LENGTH];
|
byte h[] = new byte[Hash.HASH_LENGTH];
|
||||||
RandomSource.getInstance().nextBytes(h);
|
RandomSource.getInstance().nextBytes(h);
|
||||||
Hash hash = new Hash(h);
|
Hash hash = new Hash(h);
|
||||||
DestLookupMessage msg = new DestLookupMessage(hash);
|
DestLookupMessage msg = new DestLookupMessage(hash);
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
public DataStructure createStructureToRead() { return new DestLookupMessage(); }
|
public I2CPMessageImpl createStructureToRead() { return new DestLookupMessage(); }
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,6 @@ package net.i2p.data.i2cp;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import net.i2p.data.StructureTest;
|
|
||||||
import net.i2p.data.DataStructure;
|
|
||||||
import net.i2p.data.DataFormatException;
|
import net.i2p.data.DataFormatException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,10 +15,10 @@ import net.i2p.data.DataFormatException;
|
|||||||
*
|
*
|
||||||
* @author str4d
|
* @author str4d
|
||||||
*/
|
*/
|
||||||
public class DestReplyMessageTest extends StructureTest {
|
public class DestReplyMessageTest extends I2CPTstBase {
|
||||||
public DataStructure createDataStructure() throws DataFormatException {
|
public I2CPMessageImpl createDataStructure() throws DataFormatException {
|
||||||
DestReplyMessage msg = new DestReplyMessage();
|
DestReplyMessage msg = new DestReplyMessage();
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
public DataStructure createStructureToRead() { return new DestReplyMessage(); }
|
public I2CPMessageImpl createStructureToRead() { return new DestReplyMessage(); }
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,6 @@ package net.i2p.data.i2cp;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import net.i2p.data.StructureTest;
|
|
||||||
import net.i2p.data.DataStructure;
|
|
||||||
import net.i2p.data.DataFormatException;
|
import net.i2p.data.DataFormatException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,11 +15,11 @@ import net.i2p.data.DataFormatException;
|
|||||||
*
|
*
|
||||||
* @author jrandom
|
* @author jrandom
|
||||||
*/
|
*/
|
||||||
public class DestroySessionMessageTest extends StructureTest {
|
public class DestroySessionMessageTest extends I2CPTstBase {
|
||||||
public DataStructure createDataStructure() throws DataFormatException {
|
public I2CPMessageImpl createDataStructure() throws DataFormatException {
|
||||||
DestroySessionMessage msg = new DestroySessionMessage();
|
DestroySessionMessage msg = new DestroySessionMessage();
|
||||||
msg.setSessionId((SessionId)(new SessionIdTest()).createDataStructure());
|
msg.setSessionId((SessionId)(new SessionIdTest()).createDataStructure());
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
public DataStructure createStructureToRead() { return new DestroySessionMessage(); }
|
public I2CPMessageImpl createStructureToRead() { return new DestroySessionMessage(); }
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,6 @@ package net.i2p.data.i2cp;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import net.i2p.data.StructureTest;
|
|
||||||
import net.i2p.data.DataStructure;
|
|
||||||
import net.i2p.data.DataFormatException;
|
import net.i2p.data.DataFormatException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,11 +15,11 @@ import net.i2p.data.DataFormatException;
|
|||||||
*
|
*
|
||||||
* @author jrandom
|
* @author jrandom
|
||||||
*/
|
*/
|
||||||
public class DisconnectMessageTest extends StructureTest {
|
public class DisconnectMessageTest extends I2CPTstBase {
|
||||||
public DataStructure createDataStructure() throws DataFormatException {
|
public I2CPMessageImpl createDataStructure() throws DataFormatException {
|
||||||
DisconnectMessage msg = new DisconnectMessage();
|
DisconnectMessage msg = new DisconnectMessage();
|
||||||
msg.setReason("Because I say so");
|
msg.setReason("Because I say so");
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
public DataStructure createStructureToRead() { return new DisconnectMessage(); }
|
public I2CPMessageImpl createStructureToRead() { return new DisconnectMessage(); }
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,6 @@ package net.i2p.data.i2cp;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import net.i2p.data.StructureTest;
|
|
||||||
import net.i2p.data.DataStructure;
|
|
||||||
import net.i2p.data.DataFormatException;
|
import net.i2p.data.DataFormatException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,10 +15,10 @@ import net.i2p.data.DataFormatException;
|
|||||||
*
|
*
|
||||||
* @author str4d
|
* @author str4d
|
||||||
*/
|
*/
|
||||||
public class GetBandwidthLimitsMessageTest extends StructureTest {
|
public class GetBandwidthLimitsMessageTest extends I2CPTstBase {
|
||||||
public DataStructure createDataStructure() throws DataFormatException {
|
public I2CPMessageImpl createDataStructure() throws DataFormatException {
|
||||||
GetBandwidthLimitsMessage msg = new GetBandwidthLimitsMessage();
|
GetBandwidthLimitsMessage msg = new GetBandwidthLimitsMessage();
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
public DataStructure createStructureToRead() { return new GetBandwidthLimitsMessage(); }
|
public I2CPMessageImpl createStructureToRead() { return new GetBandwidthLimitsMessage(); }
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,6 @@ package net.i2p.data.i2cp;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import net.i2p.data.StructureTest;
|
|
||||||
import net.i2p.data.DataStructure;
|
|
||||||
import net.i2p.data.DataFormatException;
|
import net.i2p.data.DataFormatException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,10 +15,10 @@ import net.i2p.data.DataFormatException;
|
|||||||
*
|
*
|
||||||
* @author str4d
|
* @author str4d
|
||||||
*/
|
*/
|
||||||
public class GetDateMessageTest extends StructureTest {
|
public class GetDateMessageTest extends I2CPTstBase {
|
||||||
public DataStructure createDataStructure() throws DataFormatException {
|
public I2CPMessageImpl createDataStructure() throws DataFormatException {
|
||||||
GetDateMessage msg = new GetDateMessage("0.8.13-0");
|
GetDateMessage msg = new GetDateMessage("0.8.13-0");
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
public DataStructure createStructureToRead() { return new GetDateMessage(); }
|
public I2CPMessageImpl createStructureToRead() { return new GetDateMessage(); }
|
||||||
}
|
}
|
||||||
|
65
core/java/test/junit/net/i2p/data/i2cp/I2CPTstBase.java
Normal file
65
core/java/test/junit/net/i2p/data/i2cp/I2CPTstBase.java
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
package net.i2p.data.i2cp;
|
||||||
|
/*
|
||||||
|
* 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 static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import net.i2p.data.DataFormatException;
|
||||||
|
import net.i2p.data.DataHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility class for wrapping I2CP message tests
|
||||||
|
*
|
||||||
|
* @since 0.9.48
|
||||||
|
*/
|
||||||
|
|
||||||
|
public abstract class I2CPTstBase {
|
||||||
|
|
||||||
|
/** create a populated structure for writing */
|
||||||
|
public abstract I2CPMessageImpl createDataStructure() throws DataFormatException;
|
||||||
|
|
||||||
|
/** create an unpopulated structure for reading */
|
||||||
|
public abstract I2CPMessageImpl createStructureToRead();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStructure() throws Exception{
|
||||||
|
byte[] temp = null;
|
||||||
|
|
||||||
|
I2CPMessageImpl orig;
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
|
||||||
|
orig = createDataStructure();
|
||||||
|
orig.writeBytes(baos);
|
||||||
|
|
||||||
|
|
||||||
|
temp = baos.toByteArray();
|
||||||
|
|
||||||
|
I2CPMessageImpl ds;
|
||||||
|
ByteArrayInputStream bais = new ByteArrayInputStream(temp);
|
||||||
|
|
||||||
|
ds = createStructureToRead();
|
||||||
|
ds.readBytes(bais);
|
||||||
|
|
||||||
|
|
||||||
|
// I2CP message classes don't implement equals()
|
||||||
|
if (!getClass().getName().startsWith("net.i2p.data.i2cp."))
|
||||||
|
assertEquals(orig, ds);
|
||||||
|
|
||||||
|
// Not all classes implement equals, so write out again
|
||||||
|
ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
|
||||||
|
ds.writeBytes(baos2);
|
||||||
|
byte[] temp2 = baos2.toByteArray();
|
||||||
|
assert(DataHelper.eq(temp, temp2));
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,7 @@ package net.i2p.data.i2cp;
|
|||||||
import net.i2p.data.StructureTest;
|
import net.i2p.data.StructureTest;
|
||||||
import net.i2p.data.DataStructure;
|
import net.i2p.data.DataStructure;
|
||||||
import net.i2p.data.DataFormatException;
|
import net.i2p.data.DataFormatException;
|
||||||
|
import net.i2p.data.Hash;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test harness for loading / storing Hash objects
|
* Test harness for loading / storing Hash objects
|
||||||
@ -19,9 +20,21 @@ import net.i2p.data.DataFormatException;
|
|||||||
*/
|
*/
|
||||||
public class MessageIdTest extends StructureTest {
|
public class MessageIdTest extends StructureTest {
|
||||||
public DataStructure createDataStructure() throws DataFormatException {
|
public DataStructure createDataStructure() throws DataFormatException {
|
||||||
MessageId id = new MessageId();
|
MessageIdStructure id = new MessageIdStructure();
|
||||||
id.setMessageId(101);
|
id.setMessageId(101);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
public DataStructure createStructureToRead() { return new MessageId(); }
|
public DataStructure createStructureToRead() { return new MessageIdStructure(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* so we can test it as a structure
|
||||||
|
* @since 0.9.48 no longer extends DataStructureImpl
|
||||||
|
*/
|
||||||
|
private static class MessageIdStructure extends MessageId implements DataStructure {
|
||||||
|
public Hash calculateHash() { return null; }
|
||||||
|
public void fromByteArray(byte[] in) {}
|
||||||
|
public byte[] toByteArray() { return null; }
|
||||||
|
public void fromBase64(String in) {}
|
||||||
|
public String toBase64() { return null; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,6 @@ package net.i2p.data.i2cp;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import net.i2p.data.StructureTest;
|
|
||||||
import net.i2p.data.DataStructure;
|
|
||||||
import net.i2p.data.DataFormatException;
|
import net.i2p.data.DataFormatException;
|
||||||
import net.i2p.data.Payload;
|
import net.i2p.data.Payload;
|
||||||
import net.i2p.data.PayloadTest;
|
import net.i2p.data.PayloadTest;
|
||||||
@ -20,14 +18,14 @@ import net.i2p.data.PayloadTest;
|
|||||||
* @author jrandom
|
* @author jrandom
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class MessagePayloadMessageTest extends StructureTest {
|
public class MessagePayloadMessageTest extends I2CPTstBase {
|
||||||
public DataStructure createDataStructure() throws DataFormatException {
|
public I2CPMessageImpl createDataStructure() throws DataFormatException {
|
||||||
MessagePayloadMessage msg = new MessagePayloadMessage();
|
MessagePayloadMessage msg = new MessagePayloadMessage();
|
||||||
msg.setMessageId(123);
|
msg.setMessageId(123);
|
||||||
msg.setPayload((Payload)(new PayloadTest()).createDataStructure());
|
msg.setPayload((Payload)(new PayloadTest()).createDataStructure());
|
||||||
msg.setSessionId(321);
|
msg.setSessionId(321);
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
public DataStructure createStructureToRead() { return new MessagePayloadMessage(); }
|
public I2CPMessageImpl createStructureToRead() { return new MessagePayloadMessage(); }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,6 @@ package net.i2p.data.i2cp;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import net.i2p.data.StructureTest;
|
|
||||||
import net.i2p.data.DataStructure;
|
|
||||||
import net.i2p.data.DataFormatException;
|
import net.i2p.data.DataFormatException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,8 +15,8 @@ import net.i2p.data.DataFormatException;
|
|||||||
*
|
*
|
||||||
* @author jrandom
|
* @author jrandom
|
||||||
*/
|
*/
|
||||||
public class MessageStatusMessageTest extends StructureTest {
|
public class MessageStatusMessageTest extends I2CPTstBase {
|
||||||
public DataStructure createDataStructure() throws DataFormatException {
|
public I2CPMessageImpl createDataStructure() throws DataFormatException {
|
||||||
MessageStatusMessage msg = new MessageStatusMessage();
|
MessageStatusMessage msg = new MessageStatusMessage();
|
||||||
msg.setSessionId(42);
|
msg.setSessionId(42);
|
||||||
msg.setMessageId(41);
|
msg.setMessageId(41);
|
||||||
@ -27,5 +25,5 @@ public class MessageStatusMessageTest extends StructureTest {
|
|||||||
msg.setNonce(1);
|
msg.setNonce(1);
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
public DataStructure createStructureToRead() { return new MessageStatusMessage(); }
|
public I2CPMessageImpl createStructureToRead() { return new MessageStatusMessage(); }
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,6 @@ package net.i2p.data.i2cp;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import net.i2p.data.StructureTest;
|
|
||||||
import net.i2p.data.DataStructure;
|
|
||||||
import net.i2p.data.DataFormatException;
|
import net.i2p.data.DataFormatException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,12 +15,12 @@ import net.i2p.data.DataFormatException;
|
|||||||
*
|
*
|
||||||
* @author jrandom
|
* @author jrandom
|
||||||
*/
|
*/
|
||||||
public class ReceiveMessageBeginMessageTest extends StructureTest {
|
public class ReceiveMessageBeginMessageTest extends I2CPTstBase {
|
||||||
public DataStructure createDataStructure() throws DataFormatException {
|
public I2CPMessageImpl createDataStructure() throws DataFormatException {
|
||||||
ReceiveMessageBeginMessage msg = new ReceiveMessageBeginMessage();
|
ReceiveMessageBeginMessage msg = new ReceiveMessageBeginMessage();
|
||||||
msg.setSessionId(321);
|
msg.setSessionId(321);
|
||||||
msg.setMessageId(123);
|
msg.setMessageId(123);
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
public DataStructure createStructureToRead() { return new ReceiveMessageBeginMessage(); }
|
public I2CPMessageImpl createStructureToRead() { return new ReceiveMessageBeginMessage(); }
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,6 @@ package net.i2p.data.i2cp;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import net.i2p.data.StructureTest;
|
|
||||||
import net.i2p.data.DataStructure;
|
|
||||||
import net.i2p.data.DataFormatException;
|
import net.i2p.data.DataFormatException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,12 +15,12 @@ import net.i2p.data.DataFormatException;
|
|||||||
*
|
*
|
||||||
* @author jrandom
|
* @author jrandom
|
||||||
*/
|
*/
|
||||||
public class ReceiveMessageEndMessageTest extends StructureTest {
|
public class ReceiveMessageEndMessageTest extends I2CPTstBase {
|
||||||
public DataStructure createDataStructure() throws DataFormatException {
|
public I2CPMessageImpl createDataStructure() throws DataFormatException {
|
||||||
ReceiveMessageEndMessage msg = new ReceiveMessageEndMessage();
|
ReceiveMessageEndMessage msg = new ReceiveMessageEndMessage();
|
||||||
msg.setSessionId(321);
|
msg.setSessionId(321);
|
||||||
msg.setMessageId(123);
|
msg.setMessageId(123);
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
public DataStructure createStructureToRead() { return new ReceiveMessageEndMessage(); }
|
public I2CPMessageImpl createStructureToRead() { return new ReceiveMessageEndMessage(); }
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,6 @@ package net.i2p.data.i2cp;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import net.i2p.data.StructureTest;
|
|
||||||
import net.i2p.data.DataStructure;
|
|
||||||
import net.i2p.data.DataFormatException;
|
import net.i2p.data.DataFormatException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,12 +15,12 @@ import net.i2p.data.DataFormatException;
|
|||||||
*
|
*
|
||||||
* @author str4d
|
* @author str4d
|
||||||
*/
|
*/
|
||||||
public class ReconfigureSessionMessageTest extends StructureTest {
|
public class ReconfigureSessionMessageTest extends I2CPTstBase {
|
||||||
public DataStructure createDataStructure() throws DataFormatException {
|
public I2CPMessageImpl createDataStructure() throws DataFormatException {
|
||||||
ReconfigureSessionMessage msg = new ReconfigureSessionMessage();
|
ReconfigureSessionMessage msg = new ReconfigureSessionMessage();
|
||||||
msg.setSessionId((SessionId)(new SessionIdTest()).createDataStructure());
|
msg.setSessionId((SessionId)(new SessionIdTest()).createDataStructure());
|
||||||
msg.setSessionConfig((SessionConfig)(new SessionConfigTest()).createDataStructure());
|
msg.setSessionConfig((SessionConfig)(new SessionConfigTest()).createDataStructure());
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
public DataStructure createStructureToRead() { return new ReconfigureSessionMessage(); }
|
public I2CPMessageImpl createStructureToRead() { return new ReconfigureSessionMessage(); }
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,6 @@ package net.i2p.data.i2cp;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import net.i2p.data.StructureTest;
|
|
||||||
import net.i2p.data.DataStructure;
|
|
||||||
import net.i2p.data.DataFormatException;
|
import net.i2p.data.DataFormatException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,8 +15,8 @@ import net.i2p.data.DataFormatException;
|
|||||||
*
|
*
|
||||||
* @author jrandom
|
* @author jrandom
|
||||||
*/
|
*/
|
||||||
public class ReportAbuseMessageTest extends StructureTest {
|
public class ReportAbuseMessageTest extends I2CPTstBase {
|
||||||
public DataStructure createDataStructure() throws DataFormatException {
|
public I2CPMessageImpl createDataStructure() throws DataFormatException {
|
||||||
ReportAbuseMessage msg = new ReportAbuseMessage();
|
ReportAbuseMessage msg = new ReportAbuseMessage();
|
||||||
msg.setMessageId((MessageId)(new MessageIdTest()).createDataStructure());
|
msg.setMessageId((MessageId)(new MessageIdTest()).createDataStructure());
|
||||||
msg.setReason((AbuseReason)(new AbuseReasonTest()).createDataStructure());
|
msg.setReason((AbuseReason)(new AbuseReasonTest()).createDataStructure());
|
||||||
@ -26,5 +24,5 @@ public class ReportAbuseMessageTest extends StructureTest {
|
|||||||
msg.setSeverity((AbuseSeverity)(new AbuseSeverityTest()).createDataStructure());
|
msg.setSeverity((AbuseSeverity)(new AbuseSeverityTest()).createDataStructure());
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
public DataStructure createStructureToRead() { return new ReportAbuseMessage(); }
|
public I2CPMessageImpl createStructureToRead() { return new ReportAbuseMessage(); }
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,6 @@ package net.i2p.data.i2cp;
|
|||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import net.i2p.data.StructureTest;
|
|
||||||
import net.i2p.data.DataStructure;
|
|
||||||
import net.i2p.data.DataFormatException;
|
import net.i2p.data.DataFormatException;
|
||||||
import net.i2p.data.Hash;
|
import net.i2p.data.Hash;
|
||||||
import net.i2p.data.TunnelId;
|
import net.i2p.data.TunnelId;
|
||||||
@ -22,8 +20,8 @@ import net.i2p.data.TunnelIdTest;
|
|||||||
*
|
*
|
||||||
* @author jrandom
|
* @author jrandom
|
||||||
*/
|
*/
|
||||||
public class RequestLeaseSetMessageTest extends StructureTest {
|
public class RequestLeaseSetMessageTest extends I2CPTstBase {
|
||||||
public DataStructure createDataStructure() throws DataFormatException {
|
public I2CPMessageImpl createDataStructure() throws DataFormatException {
|
||||||
RequestLeaseSetMessage msg = new RequestLeaseSetMessage();
|
RequestLeaseSetMessage msg = new RequestLeaseSetMessage();
|
||||||
msg.setSessionId((SessionId)(new SessionIdTest()).createDataStructure());
|
msg.setSessionId((SessionId)(new SessionIdTest()).createDataStructure());
|
||||||
msg.setEndDate(new Date(1000*60*60*12));
|
msg.setEndDate(new Date(1000*60*60*12));
|
||||||
@ -31,5 +29,5 @@ public class RequestLeaseSetMessageTest extends StructureTest {
|
|||||||
msg.addEndpoint(new Hash(h), (TunnelId)(new TunnelIdTest()).createDataStructure());
|
msg.addEndpoint(new Hash(h), (TunnelId)(new TunnelIdTest()).createDataStructure());
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
public DataStructure createStructureToRead() { return new RequestLeaseSetMessage(); }
|
public I2CPMessageImpl createStructureToRead() { return new RequestLeaseSetMessage(); }
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,6 @@ package net.i2p.data.i2cp;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import net.i2p.data.StructureTest;
|
|
||||||
import net.i2p.data.DataStructure;
|
|
||||||
import net.i2p.data.DataFormatException;
|
import net.i2p.data.DataFormatException;
|
||||||
import net.i2p.data.Destination;
|
import net.i2p.data.Destination;
|
||||||
import net.i2p.data.DestinationTest;
|
import net.i2p.data.DestinationTest;
|
||||||
@ -24,9 +22,9 @@ import net.i2p.data.DateAndFlagsTest;
|
|||||||
* @author str4d
|
* @author str4d
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class SendMessageExpiresMessageTest extends StructureTest {
|
public class SendMessageExpiresMessageTest extends I2CPTstBase {
|
||||||
|
|
||||||
public DataStructure createDataStructure() throws DataFormatException {
|
public I2CPMessageImpl createDataStructure() throws DataFormatException {
|
||||||
SendMessageExpiresMessage msg = new SendMessageExpiresMessage();
|
SendMessageExpiresMessage msg = new SendMessageExpiresMessage();
|
||||||
msg.setDestination((Destination)(new DestinationTest()).createDataStructure());
|
msg.setDestination((Destination)(new DestinationTest()).createDataStructure());
|
||||||
msg.setPayload((Payload)(new PayloadTest()).createDataStructure());
|
msg.setPayload((Payload)(new PayloadTest()).createDataStructure());
|
||||||
@ -37,6 +35,6 @@ import net.i2p.data.DateAndFlagsTest;
|
|||||||
msg.setFlags(daf.getFlags());
|
msg.setFlags(daf.getFlags());
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
public DataStructure createStructureToRead() { return new SendMessageExpiresMessage(); }
|
public I2CPMessageImpl createStructureToRead() { return new SendMessageExpiresMessage(); }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,6 @@ package net.i2p.data.i2cp;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import net.i2p.data.StructureTest;
|
|
||||||
import net.i2p.data.DataStructure;
|
|
||||||
import net.i2p.data.DataFormatException;
|
import net.i2p.data.DataFormatException;
|
||||||
import net.i2p.data.Destination;
|
import net.i2p.data.Destination;
|
||||||
import net.i2p.data.DestinationTest;
|
import net.i2p.data.DestinationTest;
|
||||||
@ -22,9 +20,9 @@ import net.i2p.data.PayloadTest;
|
|||||||
* @author jrandom
|
* @author jrandom
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class SendMessageMessageTest extends StructureTest {
|
public class SendMessageMessageTest extends I2CPTstBase {
|
||||||
|
|
||||||
public DataStructure createDataStructure() throws DataFormatException {
|
public I2CPMessageImpl createDataStructure() throws DataFormatException {
|
||||||
SendMessageMessage msg = new SendMessageMessage();
|
SendMessageMessage msg = new SendMessageMessage();
|
||||||
msg.setDestination((Destination)(new DestinationTest()).createDataStructure());
|
msg.setDestination((Destination)(new DestinationTest()).createDataStructure());
|
||||||
msg.setPayload((Payload)(new PayloadTest()).createDataStructure());
|
msg.setPayload((Payload)(new PayloadTest()).createDataStructure());
|
||||||
@ -32,6 +30,6 @@ import net.i2p.data.PayloadTest;
|
|||||||
msg.setNonce(1);
|
msg.setNonce(1);
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
public DataStructure createStructureToRead() { return new SendMessageMessage(); }
|
public I2CPMessageImpl createStructureToRead() { return new SendMessageMessage(); }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ package net.i2p.data.i2cp;
|
|||||||
import net.i2p.data.StructureTest;
|
import net.i2p.data.StructureTest;
|
||||||
import net.i2p.data.DataStructure;
|
import net.i2p.data.DataStructure;
|
||||||
import net.i2p.data.DataFormatException;
|
import net.i2p.data.DataFormatException;
|
||||||
|
import net.i2p.data.Hash;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test harness for loading / storing SessionId objects
|
* Test harness for loading / storing SessionId objects
|
||||||
@ -19,9 +20,21 @@ import net.i2p.data.DataFormatException;
|
|||||||
*/
|
*/
|
||||||
public class SessionIdTest extends StructureTest {
|
public class SessionIdTest extends StructureTest {
|
||||||
public DataStructure createDataStructure() throws DataFormatException {
|
public DataStructure createDataStructure() throws DataFormatException {
|
||||||
SessionId id = new SessionId();
|
SessionIdStructure id = new SessionIdStructure();
|
||||||
id.setSessionId(7);
|
id.setSessionId(7);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
public DataStructure createStructureToRead() { return new SessionId(); }
|
public DataStructure createStructureToRead() { return new SessionIdStructure(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* so we can test it as a structure
|
||||||
|
* @since 0.9.48 no longer extends DataStructureImpl
|
||||||
|
*/
|
||||||
|
private static class SessionIdStructure extends SessionId implements DataStructure {
|
||||||
|
public Hash calculateHash() { return null; }
|
||||||
|
public void fromByteArray(byte[] in) {}
|
||||||
|
public byte[] toByteArray() { return null; }
|
||||||
|
public void fromBase64(String in) {}
|
||||||
|
public String toBase64() { return null; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,6 @@ package net.i2p.data.i2cp;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import net.i2p.data.StructureTest;
|
|
||||||
import net.i2p.data.DataStructure;
|
|
||||||
import net.i2p.data.DataFormatException;
|
import net.i2p.data.DataFormatException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,12 +15,12 @@ import net.i2p.data.DataFormatException;
|
|||||||
*
|
*
|
||||||
* @author jrandom
|
* @author jrandom
|
||||||
*/
|
*/
|
||||||
public class SessionStatusMessageTest extends StructureTest {
|
public class SessionStatusMessageTest extends I2CPTstBase {
|
||||||
public DataStructure createDataStructure() throws DataFormatException {
|
public I2CPMessageImpl createDataStructure() throws DataFormatException {
|
||||||
SessionStatusMessage msg = new SessionStatusMessage();
|
SessionStatusMessage msg = new SessionStatusMessage();
|
||||||
msg.setSessionId((SessionId)(new SessionIdTest()).createDataStructure());
|
msg.setSessionId((SessionId)(new SessionIdTest()).createDataStructure());
|
||||||
msg.setStatus(SessionStatusMessage.STATUS_CREATED);
|
msg.setStatus(SessionStatusMessage.STATUS_CREATED);
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
public DataStructure createStructureToRead() { return new SessionStatusMessage(); }
|
public I2CPMessageImpl createStructureToRead() { return new SessionStatusMessage(); }
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,6 @@ package net.i2p.data.i2cp;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import net.i2p.data.StructureTest;
|
|
||||||
import net.i2p.data.DataStructure;
|
|
||||||
import net.i2p.data.DataFormatException;
|
import net.i2p.data.DataFormatException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,10 +15,10 @@ import net.i2p.data.DataFormatException;
|
|||||||
*
|
*
|
||||||
* @author str4d
|
* @author str4d
|
||||||
*/
|
*/
|
||||||
public class SetDateMessageTest extends StructureTest {
|
public class SetDateMessageTest extends I2CPTstBase {
|
||||||
public DataStructure createDataStructure() throws DataFormatException {
|
public I2CPMessageImpl createDataStructure() throws DataFormatException {
|
||||||
SetDateMessage msg = new SetDateMessage("0.8.13-0");
|
SetDateMessage msg = new SetDateMessage("0.8.13-0");
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
public DataStructure createStructureToRead() { return new SetDateMessage(); }
|
public I2CPMessageImpl createStructureToRead() { return new SetDateMessage(); }
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user