forked from I2P_Developers/i2p.i2p
Router tests: Remove or supporess deprecation warnings
Remove cast warnings Fix RouterAddress.setExpiration() to match javadoc, used only by tests
This commit is contained in:
@ -146,7 +146,10 @@ public class RouterAddress extends DataStructureImpl {
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void setExpiration(Date expiration) {
|
public void setExpiration(Date expiration) {
|
||||||
_expiration = expiration.getDate();
|
if (expiration != null)
|
||||||
|
_expiration = expiration.getDate();
|
||||||
|
else
|
||||||
|
_expiration = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -22,8 +22,8 @@ import net.i2p.data.TunnelId;
|
|||||||
public class DeliveryInstructionsTest extends StructureTest {
|
public class DeliveryInstructionsTest extends StructureTest {
|
||||||
public DataStructure createDataStructure() throws DataFormatException {
|
public DataStructure createDataStructure() throws DataFormatException {
|
||||||
DeliveryInstructions instructions = new DeliveryInstructions();
|
DeliveryInstructions instructions = new DeliveryInstructions();
|
||||||
instructions.setDelayRequested(true);
|
//instructions.setDelayRequested(true);
|
||||||
instructions.setDelaySeconds(42);
|
//instructions.setDelaySeconds(42);
|
||||||
instructions.setDeliveryMode(DeliveryInstructions.DELIVERY_MODE_TUNNEL);
|
instructions.setDeliveryMode(DeliveryInstructions.DELIVERY_MODE_TUNNEL);
|
||||||
// encryption key read/write disabled
|
// encryption key read/write disabled
|
||||||
//instructions.setEncrypted(true);
|
//instructions.setEncrypted(true);
|
||||||
|
@ -14,6 +14,7 @@ import java.util.Properties;
|
|||||||
import net.i2p.data.DataFormatException;
|
import net.i2p.data.DataFormatException;
|
||||||
import net.i2p.data.DataStructure;
|
import net.i2p.data.DataStructure;
|
||||||
import net.i2p.data.StructureTest;
|
import net.i2p.data.StructureTest;
|
||||||
|
import net.i2p.util.OrderedProperties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test harness for loading / storing Hash objects
|
* Test harness for loading / storing Hash objects
|
||||||
@ -22,21 +23,16 @@ import net.i2p.data.StructureTest;
|
|||||||
*/
|
*/
|
||||||
public class RouterAddressTest extends StructureTest {
|
public class RouterAddressTest extends StructureTest {
|
||||||
public DataStructure createDataStructure() throws DataFormatException {
|
public DataStructure createDataStructure() throws DataFormatException {
|
||||||
RouterAddress addr = new RouterAddress();
|
|
||||||
byte data[] = new byte[32];
|
|
||||||
for (int i = 0; i < data.length; i++)
|
|
||||||
data[i] = (byte)(i%16);
|
|
||||||
addr.setCost(42);
|
|
||||||
//addr.setExpiration(new Date(1000*60*60*24)); // jan 2 1970
|
//addr.setExpiration(new Date(1000*60*60*24)); // jan 2 1970
|
||||||
Properties options = new Properties();
|
OrderedProperties options = new OrderedProperties();
|
||||||
options.setProperty("hostname", "localhost");
|
options.setProperty("hostname", "localhost");
|
||||||
options.setProperty("portnum", "1234");
|
options.setProperty("portnum", "1234");
|
||||||
addr.setOptions(options);
|
RouterAddress addr = new RouterAddress("Blah", options, 42);
|
||||||
addr.setTransportStyle("Blah");
|
|
||||||
return addr;
|
return addr;
|
||||||
}
|
}
|
||||||
public DataStructure createStructureToRead() { return new RouterAddress(); }
|
public DataStructure createStructureToRead() { return new RouterAddress(); }
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void testSetNullOptions(){
|
public void testSetNullOptions(){
|
||||||
RouterAddress addr = new RouterAddress();
|
RouterAddress addr = new RouterAddress();
|
||||||
boolean error = false;
|
boolean error = false;
|
||||||
@ -48,12 +44,12 @@ public class RouterAddressTest extends StructureTest {
|
|||||||
assertTrue(error);
|
assertTrue(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void testSetOptionsAgain(){
|
public void testSetOptionsAgain(){
|
||||||
RouterAddress addr = new RouterAddress();
|
OrderedProperties options = new OrderedProperties();
|
||||||
Properties options = new Properties();
|
|
||||||
options.setProperty("hostname", "localhost");
|
options.setProperty("hostname", "localhost");
|
||||||
options.setProperty("portnum", "1234");
|
options.setProperty("portnum", "1234");
|
||||||
addr.setOptions(options);
|
RouterAddress addr = new RouterAddress("Blah", options, 42);
|
||||||
options.setProperty("portnum", "2345");
|
options.setProperty("portnum", "2345");
|
||||||
boolean error = false;
|
boolean error = false;
|
||||||
try{
|
try{
|
||||||
@ -76,33 +72,21 @@ public class RouterAddressTest extends StructureTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testNullEquals(){
|
public void testNullEquals(){
|
||||||
RouterAddress addr = new RouterAddress();
|
|
||||||
byte data[] = new byte[32];
|
|
||||||
for (int i = 0; i < data.length; i++)
|
|
||||||
data[i] = (byte)(i%16);
|
|
||||||
addr.setCost(42);
|
|
||||||
//addr.setExpiration(new Date(1000*60*60*24)); // jan 2 1970
|
//addr.setExpiration(new Date(1000*60*60*24)); // jan 2 1970
|
||||||
Properties options = new Properties();
|
OrderedProperties options = new OrderedProperties();
|
||||||
options.setProperty("hostname", "localhost");
|
options.setProperty("hostname", "localhost");
|
||||||
options.setProperty("portnum", "1234");
|
options.setProperty("portnum", "1234");
|
||||||
addr.setOptions(options);
|
RouterAddress addr = new RouterAddress("Blah", options, 42);
|
||||||
addr.setTransportStyle("Blah");
|
|
||||||
assertFalse(addr.equals(null));
|
assertFalse(addr.equals(null));
|
||||||
assertFalse(addr.equals(""));
|
assertFalse(addr.equals(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testToString(){
|
public void testToString(){
|
||||||
RouterAddress addr = new RouterAddress();
|
|
||||||
byte data[] = new byte[32];
|
|
||||||
for (int i = 0; i < data.length; i++)
|
|
||||||
data[i] = (byte)(i%16);
|
|
||||||
addr.setCost(42);
|
|
||||||
//addr.setExpiration(new Date(1000*60*60*24)); // jan 2 1970
|
//addr.setExpiration(new Date(1000*60*60*24)); // jan 2 1970
|
||||||
Properties options = new Properties();
|
OrderedProperties options = new OrderedProperties();
|
||||||
options.setProperty("hostname", "localhost");
|
options.setProperty("hostname", "localhost");
|
||||||
options.setProperty("portnum", "1234");
|
options.setProperty("portnum", "1234");
|
||||||
addr.setOptions(options);
|
RouterAddress addr = new RouterAddress("Blah", options, 42);
|
||||||
addr.setTransportStyle("Blah");
|
|
||||||
String ret = addr.toString();
|
String ret = addr.toString();
|
||||||
//assertEquals("[RouterAddress: \n\tTransportStyle: Blah\n\tCost: 42\n\tExpiration: Fri Jan 02 00:00:00 UTC 1970\n\tOptions: #: 2\n\t\t[hostname] = [localhost]\n\t\t[portnum] = [1234]]", ret);
|
//assertEquals("[RouterAddress: \n\tTransportStyle: Blah\n\tCost: 42\n\tExpiration: Fri Jan 02 00:00:00 UTC 1970\n\tOptions: #: 2\n\t\t[hostname] = [localhost]\n\t\t[portnum] = [1234]]", ret);
|
||||||
assertEquals("[RouterAddress: \n\tType: Blah\n\tCost: 42\n\tOptions (2):\n\t\t[hostname] = [localhost]\n\t\t[portnum] = [1234]]", ret);
|
assertEquals("[RouterAddress: \n\tType: Blah\n\tCost: 42\n\tOptions (2):\n\t\t[hostname] = [localhost]\n\t\t[portnum] = [1234]]", ret);
|
||||||
|
@ -31,6 +31,8 @@ import net.i2p.util.Log;
|
|||||||
*/
|
*/
|
||||||
public class RouterInfoTest extends StructureTest {
|
public class RouterInfoTest extends StructureTest {
|
||||||
private final static Log _log = new Log(RouterInfoTest.class);
|
private final static Log _log = new Log(RouterInfoTest.class);
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public DataStructure createDataStructure() throws DataFormatException {
|
public DataStructure createDataStructure() throws DataFormatException {
|
||||||
RouterInfo info = new RouterInfo();
|
RouterInfo info = new RouterInfo();
|
||||||
HashSet<RouterAddress> addresses = new HashSet<RouterAddress>();
|
HashSet<RouterAddress> addresses = new HashSet<RouterAddress>();
|
||||||
|
@ -219,6 +219,7 @@ public class SSUDemo {
|
|||||||
* Deal with an Foo message received
|
* Deal with an Foo message received
|
||||||
*/
|
*/
|
||||||
private class FooJobBuilder implements HandlerJobBuilder {
|
private class FooJobBuilder implements HandlerJobBuilder {
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public FooJobBuilder() {
|
public FooJobBuilder() {
|
||||||
I2NPMessageImpl.registerBuilder(new FooBuilder(), FooMessage.MESSAGE_TYPE);
|
I2NPMessageImpl.registerBuilder(new FooBuilder(), FooMessage.MESSAGE_TYPE);
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ public class SessionEncryptionTest extends TestCase{
|
|||||||
|
|
||||||
byte[] msg = DataHelper.getASCII("msg 1");
|
byte[] msg = DataHelper.getASCII("msg 1");
|
||||||
|
|
||||||
byte emsg[] = _context.elGamalAESEngine().encrypt(msg, pubKey, curKey, 64);
|
byte emsg[] = _context.elGamalAESEngine().encrypt(msg, pubKey, curKey, null, null, 64);
|
||||||
byte dmsg[] = _context.elGamalAESEngine().decrypt(emsg, privKey, skm);
|
byte dmsg[] = _context.elGamalAESEngine().decrypt(emsg, privKey, skm);
|
||||||
assertTrue(DataHelper.eq(dmsg, msg));
|
assertTrue(DataHelper.eq(dmsg, msg));
|
||||||
}
|
}
|
||||||
@ -62,7 +62,7 @@ public class SessionEncryptionTest extends TestCase{
|
|||||||
|
|
||||||
byte[] msg = DataHelper.getASCII("msg 2");
|
byte[] msg = DataHelper.getASCII("msg 2");
|
||||||
|
|
||||||
byte emsg[] = _context.elGamalAESEngine().encrypt(msg, pubKey, curKey, 64);
|
byte emsg[] = _context.elGamalAESEngine().encrypt(msg, pubKey, curKey, null, null, 64);
|
||||||
byte dmsg[] = _context.elGamalAESEngine().decrypt(emsg, privKey, skm);
|
byte dmsg[] = _context.elGamalAESEngine().decrypt(emsg, privKey, skm);
|
||||||
assertTrue(DataHelper.eq(dmsg, msg));
|
assertTrue(DataHelper.eq(dmsg, msg));
|
||||||
}
|
}
|
||||||
@ -101,7 +101,7 @@ public class SessionEncryptionTest extends TestCase{
|
|||||||
byte[] msg4 = DataHelper.getASCII("msg 4");
|
byte[] msg4 = DataHelper.getASCII("msg 4");
|
||||||
byte[] msg5 = DataHelper.getASCII("msg 5");
|
byte[] msg5 = DataHelper.getASCII("msg 5");
|
||||||
|
|
||||||
byte emsg1[] = _context.elGamalAESEngine().encrypt(msg1, pubKey, curKey, firstTags, 64);
|
byte emsg1[] = _context.elGamalAESEngine().encrypt(msg1, pubKey, curKey, firstTags, null, 64);
|
||||||
|
|
||||||
byte dmsg1[] = _context.elGamalAESEngine().decrypt(emsg1, privKey, skm);
|
byte dmsg1[] = _context.elGamalAESEngine().decrypt(emsg1, privKey, skm);
|
||||||
assertTrue(DataHelper.eq(dmsg1, msg1));
|
assertTrue(DataHelper.eq(dmsg1, msg1));
|
||||||
@ -201,7 +201,7 @@ public class SessionEncryptionTest extends TestCase{
|
|||||||
byte[] msg4 = DataHelper.getASCII("msg 4");
|
byte[] msg4 = DataHelper.getASCII("msg 4");
|
||||||
byte[] msg5 = DataHelper.getASCII("msg 5");
|
byte[] msg5 = DataHelper.getASCII("msg 5");
|
||||||
|
|
||||||
byte emsg1[] = _context.elGamalAESEngine().encrypt(msg1, pubKey, curKey, firstTags, 64);
|
byte emsg1[] = _context.elGamalAESEngine().encrypt(msg1, pubKey, curKey, firstTags, null, 64);
|
||||||
|
|
||||||
byte dmsg1[] = _context.elGamalAESEngine().decrypt(emsg1, privKey, skm);
|
byte dmsg1[] = _context.elGamalAESEngine().decrypt(emsg1, privKey, skm);
|
||||||
assertTrue(DataHelper.eq(dmsg1, msg1));
|
assertTrue(DataHelper.eq(dmsg1, msg1));
|
||||||
|
@ -110,10 +110,6 @@ public class BuildTestMessageJob extends JobImpl {
|
|||||||
|
|
||||||
DeliveryInstructions instructions = new DeliveryInstructions();
|
DeliveryInstructions instructions = new DeliveryInstructions();
|
||||||
instructions.setDeliveryMode(DeliveryInstructions.DELIVERY_MODE_ROUTER);
|
instructions.setDeliveryMode(DeliveryInstructions.DELIVERY_MODE_ROUTER);
|
||||||
instructions.setDelayRequested(false);
|
|
||||||
instructions.setDelaySeconds(0);
|
|
||||||
instructions.setEncrypted(false);
|
|
||||||
instructions.setEncryptionKey(null);
|
|
||||||
instructions.setRouter(_target.getIdentity().getHash());
|
instructions.setRouter(_target.getIdentity().getHash());
|
||||||
instructions.setTunnelId(null);
|
instructions.setTunnelId(null);
|
||||||
|
|
||||||
@ -135,9 +131,6 @@ public class BuildTestMessageJob extends JobImpl {
|
|||||||
DeliveryInstructions ackInstructions = new DeliveryInstructions();
|
DeliveryInstructions ackInstructions = new DeliveryInstructions();
|
||||||
ackInstructions.setDeliveryMode(DeliveryInstructions.DELIVERY_MODE_ROUTER);
|
ackInstructions.setDeliveryMode(DeliveryInstructions.DELIVERY_MODE_ROUTER);
|
||||||
ackInstructions.setRouter(_replyTo); // yikes!
|
ackInstructions.setRouter(_replyTo); // yikes!
|
||||||
ackInstructions.setDelayRequested(false);
|
|
||||||
ackInstructions.setDelaySeconds(0);
|
|
||||||
ackInstructions.setEncrypted(false);
|
|
||||||
|
|
||||||
DeliveryStatusMessage msg = new DeliveryStatusMessage(getContext());
|
DeliveryStatusMessage msg = new DeliveryStatusMessage(getContext());
|
||||||
msg.setArrival(getContext().clock().now());
|
msg.setArrival(getContext().clock().now());
|
||||||
|
@ -25,6 +25,7 @@ import net.i2p.data.router.RouterInfo;
|
|||||||
import net.i2p.data.SigningPrivateKey;
|
import net.i2p.data.SigningPrivateKey;
|
||||||
import net.i2p.data.SigningPublicKey;
|
import net.i2p.data.SigningPublicKey;
|
||||||
import net.i2p.util.Clock;
|
import net.i2p.util.Clock;
|
||||||
|
import net.i2p.util.OrderedProperties;
|
||||||
|
|
||||||
public class RouterGenerator {
|
public class RouterGenerator {
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
@ -121,16 +122,12 @@ public class RouterGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static RouterAddress createTCPAddress(int num) {
|
private static RouterAddress createTCPAddress(int num) {
|
||||||
RouterAddress addr = new RouterAddress();
|
OrderedProperties props = new OrderedProperties();
|
||||||
addr.setCost(10);
|
|
||||||
addr.setExpiration(null);
|
|
||||||
Properties props = new Properties();
|
|
||||||
String name = "blah.random.host.org";
|
String name = "blah.random.host.org";
|
||||||
String port = "" + (1024+num);
|
String port = "" + (1024+num);
|
||||||
props.setProperty("host", name);
|
props.setProperty("host", name);
|
||||||
props.setProperty("port", port);
|
props.setProperty("port", port);
|
||||||
addr.setOptions(props);
|
RouterAddress addr = new RouterAddress("TCP", props, 10);
|
||||||
addr.setTransportStyle("TCP");
|
|
||||||
return addr;
|
return addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ class UDPFlooder implements Runnable {
|
|||||||
if (now >= nextSend) {
|
if (now >= nextSend) {
|
||||||
// peers always grows, so this is fairly safe
|
// peers always grows, so this is fairly safe
|
||||||
for (int i = 0; i < _peers.size(); i++) {
|
for (int i = 0; i < _peers.size(); i++) {
|
||||||
PeerState peer = (PeerState)_peers.get(i);
|
PeerState peer = _peers.get(i);
|
||||||
DataMessage m = new DataMessage(_context);
|
DataMessage m = new DataMessage(_context);
|
||||||
byte data[] = _floodData; // new byte[4096];
|
byte data[] = _floodData; // new byte[4096];
|
||||||
//_context.random().nextBytes(data);
|
//_context.random().nextBytes(data);
|
||||||
|
@ -10,7 +10,7 @@ package net.i2p.router.tunnel;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import static junit.framework.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ public class BuildMessageTestStandalone extends TestCase {
|
|||||||
// populate and encrypt the message
|
// populate and encrypt the message
|
||||||
TunnelBuildMessage msg = new TunnelBuildMessage(ctx);
|
TunnelBuildMessage msg = new TunnelBuildMessage(ctx);
|
||||||
for (int i = 0; i < order.size(); i++) {
|
for (int i = 0; i < order.size(); i++) {
|
||||||
int hop = ((Integer)order.get(i)).intValue();
|
int hop = order.get(i).intValue();
|
||||||
PublicKey key = null;
|
PublicKey key = null;
|
||||||
if (hop < _pubKeys.length)
|
if (hop < _pubKeys.length)
|
||||||
key = _pubKeys[hop];
|
key = _pubKeys[hop];
|
||||||
@ -119,7 +119,7 @@ public class BuildMessageTestStandalone extends TestCase {
|
|||||||
boolean allAgree = true;
|
boolean allAgree = true;
|
||||||
for (int i = 0; i < cfg.getLength(); i++) {
|
for (int i = 0; i < cfg.getLength(); i++) {
|
||||||
Hash peer = cfg.getPeer(i);
|
Hash peer = cfg.getPeer(i);
|
||||||
int record = ((Integer)order.get(i)).intValue();
|
int record = order.get(i).intValue();
|
||||||
if (statuses[record] != 0)
|
if (statuses[record] != 0)
|
||||||
allAgree = false;
|
allAgree = false;
|
||||||
//else
|
//else
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package net.i2p.router.tunnel;
|
package net.i2p.router.tunnel;
|
||||||
|
|
||||||
import static junit.framework.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -154,6 +154,8 @@ public abstract class GatewayTestBase extends RouterTestBase {
|
|||||||
_handler = new FragmentHandler(_context, TestReceiver.this);
|
_handler = new FragmentHandler(_context, TestReceiver.this);
|
||||||
_received = new ArrayList<I2NPMessage>(1000);
|
_received = new ArrayList<I2NPMessage>(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public long receiveEncrypted(byte[] encrypted) {
|
public long receiveEncrypted(byte[] encrypted) {
|
||||||
// fake all the hops...
|
// fake all the hops...
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ public class InboundGatewayTest extends GatewayTestBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
protected void handleAtEndpoint(byte []encrypted) {
|
protected void handleAtEndpoint(byte []encrypted) {
|
||||||
// now handle it at the endpoint
|
// now handle it at the endpoint
|
||||||
InboundEndpointProcessor end = new InboundEndpointProcessor(_context, _config);
|
InboundEndpointProcessor end = new InboundEndpointProcessor(_context, _config);
|
||||||
|
@ -13,7 +13,7 @@ import org.junit.Test;
|
|||||||
import net.i2p.data.DataHelper;
|
import net.i2p.data.DataHelper;
|
||||||
import net.i2p.data.Hash;
|
import net.i2p.data.Hash;
|
||||||
|
|
||||||
import static junit.framework.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quick unit test for base functionality of inbound tunnel
|
* Quick unit test for base functionality of inbound tunnel
|
||||||
@ -23,6 +23,7 @@ import static junit.framework.Assert.assertTrue;
|
|||||||
public class InboundTest extends RouterTestBase {
|
public class InboundTest extends RouterTestBase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void testInbound() {
|
public void testInbound() {
|
||||||
int numHops = 8;
|
int numHops = 8;
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ public class OutboundTest extends TestCase{
|
|||||||
_context = new RouterContext(null);
|
_context = new RouterContext(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void testOutbound() {
|
public void testOutbound() {
|
||||||
int numHops = 8;
|
int numHops = 8;
|
||||||
TunnelCreatorConfig config = prepareConfig(numHops);
|
TunnelCreatorConfig config = prepareConfig(numHops);
|
||||||
|
Reference in New Issue
Block a user