diff --git a/build.xml b/build.xml index c9fb19bff8..88265be882 100644 --- a/build.xml +++ b/build.xml @@ -1027,12 +1027,6 @@ - - - - - - @@ -1277,25 +1271,30 @@ + + + + + + - - + - + + + + - - - - + diff --git a/core/java/build.xml b/core/java/build.xml index dad75fc9b5..a4d5957c78 100644 --- a/core/java/build.xml +++ b/core/java/build.xml @@ -28,17 +28,6 @@ - - - - - - - - - @@ -73,40 +62,70 @@ - - - - + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + - - - - + + + + + @@ -114,16 +133,24 @@ + + + + + + + + + + + + - - - - - + @@ -132,8 +159,25 @@ - - + + + + + + + + + + + + + + + + + + + diff --git a/core/java/test/net/i2p/client/datagram/DatagramTest.java b/core/java/test/net/i2p/client/datagram/DatagramTest.java index c521bc48ec..04ca0ded70 100644 --- a/core/java/test/net/i2p/client/datagram/DatagramTest.java +++ b/core/java/test/net/i2p/client/datagram/DatagramTest.java @@ -28,86 +28,94 @@ import net.i2p.data.Hash; */ public class DatagramTest extends TestCase { private I2PClient _client; - + public void setUp(){ } - + protected void tearDown() { System.gc(); } - + public void testDatagram() throws Exception{ ByteArrayOutputStream out = new ByteArrayOutputStream(); I2PClient client = I2PClientFactory.createClient(); Destination d = client.createDestination(out); I2PSession session = client.createSession(new ByteArrayInputStream(out.toByteArray()), null); - + I2PDatagramMaker dm = new I2PDatagramMaker(session); byte[] dg = dm.makeI2PDatagram("What's the deal with 42?".getBytes()); - + I2PDatagramDissector dd = new I2PDatagramDissector(); dd.loadI2PDatagram(dg); byte[] x = dd.getPayload(); assertTrue(DataHelper.eq(x, "What's the deal with 42?".getBytes())); - + x = dd.extractPayload(); assertTrue(DataHelper.eq(x, "What's the deal with 42?".getBytes())); - + assertEquals(d, dd.getSender()); assertEquals(d, dd.extractSender()); - } - - /*public void testMakeNullDatagram() throws Exception{ + + public void testMakeNullDatagram() throws Exception{ ByteArrayOutputStream out = new ByteArrayOutputStream(); I2PClient client = I2PClientFactory.createClient(); Destination d = client.createDestination(out); I2PSession session = client.createSession(new ByteArrayInputStream(out.toByteArray()), null); I2PDatagramMaker dm = new I2PDatagramMaker(session); - + byte[] dg = dm.makeI2PDatagram(null); assertNull(dg); - }*/ - - /*public void testExtractNullDatagram() throws Exception{ + } + + public void testExtractNullDatagram() throws Exception{ ByteArrayOutputStream out = new ByteArrayOutputStream(); I2PClient client = I2PClientFactory.createClient(); Destination d = client.createDestination(out); I2PSession session = client.createSession(new ByteArrayInputStream(out.toByteArray()), null); - + I2PDatagramDissector dd = new I2PDatagramDissector(); dd.loadI2PDatagram(null); - }*/ - + } + public void testBadagram() throws Exception{ ByteArrayOutputStream out = new ByteArrayOutputStream(); I2PClient client = I2PClientFactory.createClient(); Destination d = client.createDestination(out); I2PSession session = client.createSession(new ByteArrayInputStream(out.toByteArray()), null); DSAEngine dsaEng = DSAEngine.getInstance(); - + ByteArrayOutputStream dout = new ByteArrayOutputStream(); d.writeBytes(dout); dsaEng.sign(Hash.FAKE_HASH.toByteArray(), session.getPrivateKey()).writeBytes(dout); dout.write("blah".getBytes()); - + byte[] data = dout.toByteArray(); I2PDatagramDissector dd = new I2PDatagramDissector(); dd.loadI2PDatagram(data); - + boolean error = false; try{ dd.getPayload(); }catch(I2PInvalidDatagramException i2pide){ error = true; } - + assertTrue(error); + error = false; try{ dd.getSender(); }catch(I2PInvalidDatagramException i2pide){ error = true; } - + assertTrue(error); + + error = false; + try{ + dd.getHash(); + }catch(I2PInvalidDatagramException i2pide){ + error = true; + } + assertTrue(error); } -} \ No newline at end of file +} diff --git a/core/java/test/net/i2p/client/naming/BlockfileNamingServiceTest.java b/core/java/test/net/i2p/client/naming/BlockfileNamingServiceTest.java new file mode 100644 index 0000000000..b6635cf713 --- /dev/null +++ b/core/java/test/net/i2p/client/naming/BlockfileNamingServiceTest.java @@ -0,0 +1,65 @@ +package net.i2p.client.naming; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import junit.framework.TestCase; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Properties; + +import net.i2p.I2PAppContext; +import net.i2p.data.DataHelper; +import net.i2p.data.Destination; + + +public class BlockfileNamingServiceTest extends TestCase { + BlockfileNamingService _bns; + List _names; + + public void setUp() { + I2PAppContext ctx = new I2PAppContext(); + _bns = new BlockfileNamingService(ctx); + _names = null; + Properties props = new Properties(); + try { + DataHelper.loadProps(props, new File("../../installer/resources/hosts.txt"), true); + _names = new ArrayList(props.keySet()); + Collections.shuffle(_names); + } catch (IOException ioe) { + _bns.shutdown(); + return; + } + } + + public void tearDown() { + _bns.shutdown(); + File f = new File("hostsdb.blockfile"); + f.delete(); + } + + public void testRepeatedLookup() throws Exception{ + int found = 0; + int notfound = 0; + int rfound = 0; + int rnotfound = 0; + for (String name : _names) { + Destination dest = _bns.lookup(name); + if (dest != null) { + found++; + String reverse = _bns.reverseLookup(dest); + if (reverse != null) + rfound++; + else + rnotfound++; + } else { + notfound++; + } + } + assertEquals(0, notfound); + assertEquals(0, rnotfound); + } +} diff --git a/core/java/test/net/i2p/client/naming/DummyNamingServiceTest.java b/core/java/test/net/i2p/client/naming/DummyNamingServiceTest.java new file mode 100644 index 0000000000..d523b2b1c2 --- /dev/null +++ b/core/java/test/net/i2p/client/naming/DummyNamingServiceTest.java @@ -0,0 +1,45 @@ +package net.i2p.client.naming; + +import junit.framework.TestCase; + +import net.i2p.I2PAppContext; +import net.i2p.data.Destination; + + +public class DummyNamingServiceTest extends TestCase { + private I2PAppContext _context; + + public void setUp() { + _context = new I2PAppContext(); + } + + public void testLookup() throws Exception{ + // The good b64 and b32 are the destination of www.i2p2.i2p =) + String goodB64 = "-KR6qyfPWXoN~F3UzzYSMIsaRy4quickbrownfoxXSzUQXQdi2Af1TV2UMH3PpPuNu-GwrqihwmLSkPFg4fv4yQQY3E10VeQVuI67dn5vlan3NGMsjqxoXTSHHt7C3nX3szXK90JSoO~tRMDl1xyqtKm94-RpIyNcLXofd0H6b02683CQIjb-7JiCpDD0zharm6SU54rhdisIUVXpi1xYgg2pKVpssL~KCp7RAGzpt2rSgz~RHFsecqGBeFwJdiko-6CYW~tcBcigM8ea57LK7JjCFVhOoYTqgk95AG04-hfehnmBtuAFHWklFyFh88x6mS9sbVPvi-am4La0G0jvUJw9a3wQ67jMr6KWQ~w~bFe~FDqoZqVXl8t88qHPIvXelvWw2Y8EMSF5PJhWw~AZfoWOA5VQVYvcmGzZIEKtFGE7bgQf3rFtJ2FAtig9XXBsoLisHbJgeVb29Ew5E7bkwxvEe9NYkIqvrKvUAt1i55we0Nkt6xlEdhBqg6xXOyIAAAA"; + String goodB32 = "rjxwbsw4zjhv4zsplma6jmf5nr24e4ymvvbycd3swgiinbvg7oga.b32.i2p"; + // TODO: Come up with an actual bad b64 and b32 + String badB64 = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; + String badB32 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.b32.i2p"; + + DummyNamingService ns = new DummyNamingService(_context); + + assertNull(ns.lookup("")); + // TODO: Could this case ever come up? + //assertNull(ns.lookup(null)); + + Destination dGoodB64 = ns.lookup(goodB64); + assertNotNull(dGoodB64); + // TODO: Check that the b64 is preserved. + + Destination dGoodB32 = ns.lookup(goodB32); + assertNotNull(dGoodB32); + // TODO: Check that the b32 is preserved. + + // TODO: Come up with an actual bad b64 and b32 + //assertNull(ns.lookup(badB64)); + //assertNull(ns.lookup(badB32)); + + // DummyNameService only handles b64 and b32 addresses + assertNull(ns.lookup("www.i2p2.i2p")); + } +} diff --git a/core/java/test/net/i2p/client/naming/SingleFileNamingServiceTest.java b/core/java/test/net/i2p/client/naming/SingleFileNamingServiceTest.java new file mode 100644 index 0000000000..a7411fd62e --- /dev/null +++ b/core/java/test/net/i2p/client/naming/SingleFileNamingServiceTest.java @@ -0,0 +1,66 @@ +package net.i2p.client.naming; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import junit.framework.TestCase; + +import java.io.File; +import java.util.Collections; + +import net.i2p.I2PAppContext; +import net.i2p.data.Destination; + + +public class SingleFileNamingServiceTest extends TestCase { + private I2PAppContext _context; + + public void setUp() { + _context = new I2PAppContext(); + } + + public void tearDown() { + File f = new File("testhosts.txt"); + f.delete(); + } + + public void testAddRemoveLookup() throws Exception{ + String testB64 = "-KR6qyfPWXoN~F3UzzYSMIsaRy4quickbrownfoxXSzUQXQdi2Af1TV2UMH3PpPuNu-GwrqihwmLSkPFg4fv4yQQY3E10VeQVuI67dn5vlan3NGMsjqxoXTSHHt7C3nX3szXK90JSoO~tRMDl1xyqtKm94-RpIyNcLXofd0H6b02683CQIjb-7JiCpDD0zharm6SU54rhdisIUVXpi1xYgg2pKVpssL~KCp7RAGzpt2rSgz~RHFsecqGBeFwJdiko-6CYW~tcBcigM8ea57LK7JjCFVhOoYTqgk95AG04-hfehnmBtuAFHWklFyFh88x6mS9sbVPvi-am4La0G0jvUJw9a3wQ67jMr6KWQ~w~bFe~FDqoZqVXl8t88qHPIvXelvWw2Y8EMSF5PJhWw~AZfoWOA5VQVYvcmGzZIEKtFGE7bgQf3rFtJ2FAtig9XXBsoLisHbJgeVb29Ew5E7bkwxvEe9NYkIqvrKvUAt1i55we0Nkt6xlEdhBqg6xXOyIAAAA"; + Destination testDest = new Destination(); + testDest.fromBase64(testB64); + String testB642 = "24SmhWiRDm-GzpV5Gq2sXhuvPpa1OihY7rkxQO4aHy5qKjr6zmEnZ3xQXdkFJJ0Z1lKy73XRmgCyys02G25Hl3cuxlZ2fNbp6KhOzlRKpOIAWFdSWZNF4Fp7sos0x-a-9fxOWnwwQ9MFcRYwixE~iCZf4JG~-Pd-MHgAuDhIX0P3~GmfUvo~9xPjof1ZsnaOV1zC0XUkHxZA5D6V0Bse~Ptfb66lPNcgBxIEntCStBAy~rTjaA3SdAufG29IRWDscpFq1-D4XPaXHnlXu7n7WdpFEM8WWd3ebUMqnq8XvLL1eqoWYzKCe3aaavC3W6~pJp8cxKl2IKrhvSFatHZ0chRg3B4~ja1Cxmw1psisplSkJqMnF921E6pury0i6GH52XAVoj4iiDY~EAvqDhzG-ThwlzTs~2JKzslwxOrD2ejd-dcKdi4i9xvi2JQ4Ib2Mw2ktaQhuAw3Y9EkqAs7oriQQN8N8dwIoYkJLfvh7ousm0iKJJvMt3s55PccM46SoAAAA"; + Destination testDest2 = new Destination(); + testDest2.fromBase64(testB642); + + SingleFileNamingService ns = new SingleFileNamingService(_context, "testhosts.txt"); + + // testhosts.txt is empty. + assertThat(ns.size(), is(equalTo(0))); + assertThat(ns.getEntries(), is(equalTo(Collections.EMPTY_MAP))); + assertThat(ns.lookup("test.i2p"), is(nullValue())); + assertThat(ns.reverseLookup(testDest), is(nullValue())); + + // First put should add the hostname. + ns.put("test.i2p", testDest); + assertThat(ns.size(), is(equalTo(1))); + assertThat(ns.getEntries().size(), is(equalTo(1))); + assertThat(ns.lookup("test.i2p"), is(equalTo(testDest))); + assertThat(ns.reverseLookup(testDest), is(equalTo("test.i2p"))); + + // Second put should replace the first. + ns.put("test.i2p", testDest2); + assertThat(ns.size(), is(equalTo(1))); + assertThat(ns.lookup("test.i2p"), is(equalTo(testDest2))); + assertThat(ns.reverseLookup(testDest2), is(equalTo("test.i2p"))); + assertThat(ns.lookup("test.i2p"), is(not(equalTo(testDest)))); + assertThat(ns.reverseLookup(testDest), is(nullValue())); + + // Removing the hostname should give an empty file again. + ns.remove("test.i2p"); + assertThat(ns.lookup("test.i2p"), is(nullValue())); + assertThat(ns.reverseLookup(testDest2), is(nullValue())); + // Odd quirk - the above lookups don't update size, but getEntries() does... + assertThat(ns.size(), is(equalTo(1))); + assertThat(ns.getEntries(), is(equalTo(Collections.EMPTY_MAP))); + assertThat(ns.size(), is(equalTo(0))); + } +} diff --git a/core/java/test/net/i2p/crypto/CryptoTestSuite.java b/core/java/test/net/i2p/crypto/CryptoTestSuite.java index a29b8a2ff7..4300802659 100644 --- a/core/java/test/net/i2p/crypto/CryptoTestSuite.java +++ b/core/java/test/net/i2p/crypto/CryptoTestSuite.java @@ -24,7 +24,6 @@ public class CryptoTestSuite { suite.addTestSuite(AESInputStreamTest.class); suite.addTestSuite(CryptixAESEngineTest.class); suite.addTestSuite(CryptixRijndael_AlgorithmTest.class); - suite.addTestSuite(DHSessionKeyBuilderTest.class); suite.addTestSuite(DSATest.class); suite.addTestSuite(ElGamalTest.class); suite.addTestSuite(HMACSHA256Test.class); @@ -35,4 +34,4 @@ public class CryptoTestSuite { return suite; } -} \ No newline at end of file +} diff --git a/core/java/test/net/i2p/crypto/ElGamalTest.java b/core/java/test/net/i2p/crypto/ElGamalTest.java index 7789f99d9f..c917219adf 100644 --- a/core/java/test/net/i2p/crypto/ElGamalTest.java +++ b/core/java/test/net/i2p/crypto/ElGamalTest.java @@ -372,8 +372,10 @@ public class ElGamalTest extends TestCase{ public void testYKGen(){ RandomSource.getInstance().nextBoolean(); + I2PAppContext context = new I2PAppContext(); + YKGenerator ykgen = new YKGenerator(context); for (int i = 0; i < 5; i++) { - YKGenerator.getNextYK(); + ykgen.getNextYK(); } } -} \ No newline at end of file +} diff --git a/core/java/test/net/i2p/data/LeaseTest.java b/core/java/test/net/i2p/data/LeaseTest.java index 15a9366da0..bb13c149ef 100644 --- a/core/java/test/net/i2p/data/LeaseTest.java +++ b/core/java/test/net/i2p/data/LeaseTest.java @@ -28,7 +28,8 @@ public class LeaseTest extends StructureTest { return lease; } public DataStructure createStructureToRead() { return new Lease(); } - + + /* TODO: Delete this if Lease.getNumSuccess() / getNumFailure() get deleted public void testNumSuccessFail() throws Exception{ Lease lease = new Lease(); lease.setEndDate(new Date(1000*60*2)); @@ -40,7 +41,8 @@ public class LeaseTest extends StructureTest { lease.getNumSuccess(); lease.getNumFailure(); } - + */ + public void testExpiration() throws Exception{ Lease lease = new Lease(); assertTrue(lease.isExpired()); diff --git a/core/java/test/net/i2p/data/RouterAddressTest.java b/core/java/test/net/i2p/data/RouterAddressTest.java index aab4a88bb9..dc7bce3d2b 100644 --- a/core/java/test/net/i2p/data/RouterAddressTest.java +++ b/core/java/test/net/i2p/data/RouterAddressTest.java @@ -33,10 +33,37 @@ public class RouterAddressTest extends StructureTest { return addr; } public DataStructure createStructureToRead() { return new RouterAddress(); } - + + public void testSetNullOptions(){ + RouterAddress addr = new RouterAddress(); + boolean error = false; + try{ + addr.setOptions(null); + }catch(NullPointerException dfe){ + error = true; + } + assertTrue(error); + } + + public void testSetOptionsAgain(){ + RouterAddress addr = new RouterAddress(); + Properties options = new Properties(); + options.setProperty("hostname", "localhost"); + options.setProperty("portnum", "1234"); + addr.setOptions(options); + options.setProperty("portnum", "2345"); + boolean error = false; + try{ + addr.setOptions(options); + }catch(IllegalStateException dfe){ + error = true; + } + assertTrue(error); + } + public void testBadWrite() throws Exception{ RouterAddress addr = new RouterAddress(); - boolean error = true; + boolean error = false; try{ addr.writeBytes(new ByteArrayOutputStream()); }catch(DataFormatException dfe){ @@ -44,7 +71,7 @@ public class RouterAddressTest extends StructureTest { } assertTrue(error); } - + public void testNullEquals(){ RouterAddress addr = new RouterAddress(); byte data[] = new byte[32]; @@ -60,7 +87,7 @@ public class RouterAddressTest extends StructureTest { assertFalse(addr.equals(null)); assertFalse(addr.equals("")); } - + public void testToString(){ RouterAddress addr = new RouterAddress(); byte data[] = new byte[32]; @@ -73,8 +100,7 @@ public class RouterAddressTest extends StructureTest { options.setProperty("portnum", "1234"); addr.setOptions(options); addr.setTransportStyle("Blah"); - addr.toString(); - addr.setOptions(null); - 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); } } diff --git a/core/java/test/net/i2p/stat/RateStatTest.java b/core/java/test/net/i2p/stat/RateStatTest.java index a3869bdc6d..fe02a9b086 100644 --- a/core/java/test/net/i2p/stat/RateStatTest.java +++ b/core/java/test/net/i2p/stat/RateStatTest.java @@ -6,6 +6,30 @@ import junit.framework.TestCase; public class RateStatTest extends TestCase { + public void testGettersEtc() throws Exception{ + long emptyArray[] = new long[0]; + RateStat rs = new RateStat("test", "test RateStat getters etc", "tests", emptyArray); + + // Test basic getters + assertEquals("test", rs.getName()); + assertEquals("tests", rs.getGroupName()); + assertEquals("test RateStat getters etc", rs.getDescription()); + + // There should be no periods, so other getters should return defaults + // TODO: Fix this so it checks that the array is empty rather than comparing objects + //assertEquals(rs.getPeriods(), emptyArray); + assertEquals(0.0, rs.getLifetimeAverageValue()); + assertEquals(0, rs.getLifetimeEventCount()); + assertNull(rs.getRate(2000)); + + // Test adding and removing a period + assertFalse(rs.containsRate(1000)); + rs.addRate(1000); + assertTrue(rs.containsRate(1000)); + rs.removeRate(1000); + assertFalse(rs.containsRate(1000)); + } + public void testRateStat() throws Exception{ RateStat rs = new RateStat("moo", "moo moo moo", "cow trueisms", new long[] { 60 * 1000, 60 * 60 * 1000, 24 * 60 * 60 * 1000}); @@ -30,4 +54,4 @@ public class RateStatTest extends TestCase { assertEquals(rs, loadedRs); } -} \ No newline at end of file +} diff --git a/router/java/build.xml b/router/java/build.xml index 3d5e33183d..2b6d286b5e 100644 --- a/router/java/build.xml +++ b/router/java/build.xml @@ -5,9 +5,6 @@ - - - @@ -42,17 +39,6 @@ - - - - - - - - - @@ -89,9 +75,6 @@ - - - @@ -102,41 +85,76 @@ splitindex="true" windowtitle="I2P Router" /> - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -145,28 +163,25 @@ - - - - - - + - - - - - - - + + + + + + - - + + + + + diff --git a/core/java/test/net/i2p/crypto/DHSessionKeyBuilderTest.java b/router/java/test/net/i2p/router/transport/crypto/DHSessionKeyBuilderTest.java similarity index 97% rename from core/java/test/net/i2p/crypto/DHSessionKeyBuilderTest.java rename to router/java/test/net/i2p/router/transport/crypto/DHSessionKeyBuilderTest.java index 0bf6a1f611..44a43d3e92 100644 --- a/core/java/test/net/i2p/crypto/DHSessionKeyBuilderTest.java +++ b/router/java/test/net/i2p/router/transport/crypto/DHSessionKeyBuilderTest.java @@ -1,4 +1,4 @@ -package net.i2p.crypto; +package net.i2p.router.transport.crypto; /* * free (adj.): unencumbered; not under the control of others