mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-07-26 00:15:18 -04:00
Apply formatting to Java sources
This is essentially the default IDEA formatting settings, with one tweak made to allow same-line field annotations (useful particularly in the case of the @FXML annotation)
This commit is contained in:
parent
9c3df7375a
commit
7d6ca37d06
168 changed files with 3005 additions and 5439 deletions
|
@ -27,14 +27,13 @@ import org.junit.runners.Suite;
|
|||
|
||||
@RunWith(Suite.class)
|
||||
@Suite.SuiteClasses({
|
||||
BtcValidatorTest.class,
|
||||
BitSquareConverterTest.class,
|
||||
BitSquareNumberValidatorTest.class,
|
||||
P2PNodeTest.class,
|
||||
FiatValidatorTest.class,
|
||||
BtcValidatorTest.class
|
||||
})
|
||||
BtcValidatorTest.class,
|
||||
BitSquareConverterTest.class,
|
||||
BitSquareNumberValidatorTest.class,
|
||||
P2PNodeTest.class,
|
||||
FiatValidatorTest.class,
|
||||
BtcValidatorTest.class
|
||||
})
|
||||
|
||||
public class BitSquareTestSuite
|
||||
{
|
||||
public class BitSquareTestSuite {
|
||||
}
|
||||
|
|
|
@ -24,11 +24,9 @@ import org.junit.Test;
|
|||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class BtcValidatorTest
|
||||
{
|
||||
public class BtcValidatorTest {
|
||||
@Test
|
||||
public void testIsMinSpendableAmount()
|
||||
{
|
||||
public void testIsMinSpendableAmount() {
|
||||
Coin amount = null;
|
||||
//noinspection ConstantConditions
|
||||
assertFalse("tx unfunded, pending", BtcValidator.isMinSpendableAmount(amount));
|
||||
|
|
|
@ -21,12 +21,10 @@ import org.junit.Test;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class BitSquareConverterTest
|
||||
{
|
||||
public class BitSquareConverterTest {
|
||||
|
||||
@Test
|
||||
public void testStringToDouble()
|
||||
{
|
||||
public void testStringToDouble() {
|
||||
|
||||
assertEquals(1, BitSquareFormatter.parseToDouble("1"), 0);
|
||||
assertEquals(0.1, BitSquareFormatter.parseToDouble("0.1"), 0);
|
||||
|
|
|
@ -22,11 +22,9 @@ import org.junit.Test;
|
|||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class BitSquareNumberValidatorTest
|
||||
{
|
||||
public class BitSquareNumberValidatorTest {
|
||||
@Test
|
||||
public void testValidateStringAsDouble()
|
||||
{
|
||||
public void testValidateStringAsDouble() {
|
||||
assertTrue(BitSquareValidator.validateStringAsDouble("0"));
|
||||
assertTrue(BitSquareValidator.validateStringAsDouble("1"));
|
||||
assertTrue(BitSquareValidator.validateStringAsDouble("0,1"));
|
||||
|
@ -41,8 +39,7 @@ public class BitSquareNumberValidatorTest
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testValidateStringNotEmpty()
|
||||
{
|
||||
public void testValidateStringNotEmpty() {
|
||||
assertTrue(BitSquareValidator.validateStringNotEmpty("a"));
|
||||
assertTrue(BitSquareValidator.validateStringNotEmpty("123"));
|
||||
|
||||
|
|
|
@ -24,11 +24,9 @@ import org.junit.Test;
|
|||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class BtcValidatorTest
|
||||
{
|
||||
public class BtcValidatorTest {
|
||||
@Test
|
||||
public void testValidate()
|
||||
{
|
||||
public void testValidate() {
|
||||
BtcValidator validator = new BtcValidator();
|
||||
NumberValidator.ValidationResult validationResult;
|
||||
|
||||
|
|
|
@ -22,11 +22,9 @@ import org.junit.Test;
|
|||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class FiatValidatorTest
|
||||
{
|
||||
public class FiatValidatorTest {
|
||||
@Test
|
||||
public void testValidate()
|
||||
{
|
||||
public void testValidate() {
|
||||
FiatValidator validator = new FiatValidator();
|
||||
NumberValidator.ValidationResult validationResult;
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ package io.bitsquare.msg;
|
|||
import java.io.IOException;
|
||||
import java.security.*;
|
||||
import java.util.Random;
|
||||
|
||||
import net.tomp2p.connection.Ports;
|
||||
import net.tomp2p.dht.*;
|
||||
import net.tomp2p.futures.FutureDirect;
|
||||
|
@ -36,15 +37,13 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class P2PNodeTest
|
||||
{
|
||||
public class P2PNodeTest {
|
||||
private static final Logger log = LoggerFactory.getLogger(P2PNodeTest.class);
|
||||
|
||||
final private static Random rnd = new Random(42L);
|
||||
|
||||
@Test
|
||||
public void testSendData() throws Exception
|
||||
{
|
||||
public void testSendData() throws Exception {
|
||||
PeerDHT[] peers = UtilsDHT2.createNodes(3, rnd, new Ports().tcpPort());
|
||||
PeerDHT master = peers[0];
|
||||
PeerDHT client = peers[1];
|
||||
|
@ -52,13 +51,10 @@ public class P2PNodeTest
|
|||
UtilsDHT2.perfectRouting(peers);
|
||||
|
||||
|
||||
for (final PeerDHT peer : peers)
|
||||
{
|
||||
peer.peer().objectDataReply(new ObjectDataReply()
|
||||
{
|
||||
for (final PeerDHT peer : peers) {
|
||||
peer.peer().objectDataReply(new ObjectDataReply() {
|
||||
@Override
|
||||
public Object reply(PeerAddress sender, Object request) throws Exception
|
||||
{
|
||||
public Object reply(PeerAddress sender, Object request) throws Exception {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
@ -87,8 +83,7 @@ public class P2PNodeTest
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testProtectedPutGet() throws Exception
|
||||
{
|
||||
public void testProtectedPutGet() throws Exception {
|
||||
PeerDHT[] peers = UtilsDHT2.createNodes(3, rnd, new Ports().tcpPort());
|
||||
PeerDHT master = peers[0];
|
||||
PeerDHT client = peers[1];
|
||||
|
@ -171,18 +166,17 @@ public class P2PNodeTest
|
|||
|
||||
master.shutdown();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testChangeEntryProtectionKey() throws IOException, ClassNotFoundException, NoSuchAlgorithmException, InterruptedException, InvalidKeyException, SignatureException
|
||||
{
|
||||
public void testChangeEntryProtectionKey() throws IOException, ClassNotFoundException, NoSuchAlgorithmException, InterruptedException, InvalidKeyException, SignatureException {
|
||||
KeyPairGenerator gen = KeyPairGenerator.getInstance("DSA");
|
||||
|
||||
KeyPair keyPair1 = gen.generateKeyPair();
|
||||
KeyPair keyPair2 = gen.generateKeyPair();
|
||||
PeerDHT p1 = new PeerBuilderDHT(new PeerBuilder(Number160.createHash(1)).ports(4838)
|
||||
.keyPair(keyPair1).start()).start();
|
||||
.keyPair(keyPair1).start()).start();
|
||||
PeerDHT p2 = new PeerBuilderDHT(new PeerBuilder(Number160.createHash(2)).ports(4839)
|
||||
.keyPair(keyPair2).start()).start();
|
||||
.keyPair(keyPair2).start()).start();
|
||||
|
||||
p2.peer().bootstrap().peerAddress(p1.peerAddress()).start().awaitUninterruptibly();
|
||||
p1.peer().bootstrap().peerAddress(p2.peerAddress()).start().awaitUninterruptibly();
|
||||
|
@ -204,11 +198,10 @@ public class P2PNodeTest
|
|||
p1.shutdown().awaitUninterruptibly();
|
||||
p2.shutdown().awaitUninterruptibly();
|
||||
}
|
||||
|
||||
|
||||
// @Test
|
||||
public void testAddToListGetList() throws Exception
|
||||
{
|
||||
|
||||
|
||||
// @Test
|
||||
public void testAddToListGetList() throws Exception {
|
||||
|
||||
PeerDHT[] peers = UtilsDHT2.createNodes(3, rnd, new Ports().tcpPort());
|
||||
PeerDHT master = peers[0];
|
||||
|
@ -232,7 +225,7 @@ public class P2PNodeTest
|
|||
KeyPairGenerator gen = KeyPairGenerator.getInstance("DSA");
|
||||
KeyPair keyPair1 = gen.generateKeyPair();
|
||||
keyPairClient = keyPair1;
|
||||
|
||||
|
||||
node = new P2PNode(keyPairClient, client);
|
||||
locationKey = Number160.createHash("add to list clients location");
|
||||
data = new Data("add to list client data1");
|
||||
|
@ -251,21 +244,17 @@ public class P2PNodeTest
|
|||
futureGet.awaitUninterruptibly();
|
||||
assertTrue(futureGet.isSuccess());
|
||||
boolean foundData1 = futureGet.dataMap().values().stream().anyMatch(data1 -> {
|
||||
try
|
||||
{
|
||||
try {
|
||||
return data1.object().equals("add to list client data1");
|
||||
} catch (ClassNotFoundException | IOException e)
|
||||
{
|
||||
} catch (ClassNotFoundException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
});
|
||||
boolean foundData2 = futureGet.dataMap().values().stream().anyMatch(data1 -> {
|
||||
try
|
||||
{
|
||||
try {
|
||||
return data1.object().equals("add to list client data2");
|
||||
} catch (ClassNotFoundException | IOException e)
|
||||
{
|
||||
} catch (ClassNotFoundException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
|
@ -297,31 +286,25 @@ public class P2PNodeTest
|
|||
assertTrue(futureGet.isSuccess());
|
||||
|
||||
foundData1 = futureGet.dataMap().values().stream().anyMatch(data1 -> {
|
||||
try
|
||||
{
|
||||
try {
|
||||
return data1.object().equals("add to list client data1");
|
||||
} catch (ClassNotFoundException | IOException e)
|
||||
{
|
||||
} catch (ClassNotFoundException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
});
|
||||
foundData2 = futureGet.dataMap().values().stream().anyMatch(data1 -> {
|
||||
try
|
||||
{
|
||||
try {
|
||||
return data1.object().equals("add to list client data2");
|
||||
} catch (ClassNotFoundException | IOException e)
|
||||
{
|
||||
} catch (ClassNotFoundException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
});
|
||||
boolean foundData3 = futureGet.dataMap().values().stream().anyMatch(data1 -> {
|
||||
try
|
||||
{
|
||||
try {
|
||||
return data1.object().equals("add to list other peer data HACK!");
|
||||
} catch (ClassNotFoundException | IOException e)
|
||||
{
|
||||
} catch (ClassNotFoundException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
|
@ -343,31 +326,25 @@ public class P2PNodeTest
|
|||
assertTrue(futureGet.isSuccess());
|
||||
|
||||
foundData1 = futureGet.dataMap().values().stream().anyMatch(data1 -> {
|
||||
try
|
||||
{
|
||||
try {
|
||||
return data1.object().equals("add to list client data1");
|
||||
} catch (ClassNotFoundException | IOException e)
|
||||
{
|
||||
} catch (ClassNotFoundException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
});
|
||||
foundData2 = futureGet.dataMap().values().stream().anyMatch(data1 -> {
|
||||
try
|
||||
{
|
||||
try {
|
||||
return data1.object().equals("add to list client data2");
|
||||
} catch (ClassNotFoundException | IOException e)
|
||||
{
|
||||
} catch (ClassNotFoundException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
});
|
||||
foundData3 = futureGet.dataMap().values().stream().anyMatch(data1 -> {
|
||||
try
|
||||
{
|
||||
try {
|
||||
return data1.object().equals("add to list other peer data HACK!");
|
||||
} catch (ClassNotFoundException | IOException e)
|
||||
{
|
||||
} catch (ClassNotFoundException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
|
@ -390,31 +367,25 @@ public class P2PNodeTest
|
|||
assertTrue(futureGet.isSuccess());
|
||||
|
||||
foundData1 = futureGet.dataMap().values().stream().anyMatch(data1 -> {
|
||||
try
|
||||
{
|
||||
try {
|
||||
return data1.object().equals("add to list client data1");
|
||||
} catch (ClassNotFoundException | IOException e)
|
||||
{
|
||||
} catch (ClassNotFoundException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
});
|
||||
foundData2 = futureGet.dataMap().values().stream().anyMatch(data1 -> {
|
||||
try
|
||||
{
|
||||
try {
|
||||
return data1.object().equals("add to list client data2");
|
||||
} catch (ClassNotFoundException | IOException e)
|
||||
{
|
||||
} catch (ClassNotFoundException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
});
|
||||
foundData3 = futureGet.dataMap().values().stream().anyMatch(data1 -> {
|
||||
try
|
||||
{
|
||||
try {
|
||||
return data1.object().equals("add to list other peer data HACK!");
|
||||
} catch (ClassNotFoundException | IOException e)
|
||||
{
|
||||
} catch (ClassNotFoundException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -40,6 +40,7 @@ import java.io.InputStreamReader;
|
|||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.*;
|
||||
|
||||
import net.tomp2p.connection.Bindings;
|
||||
import net.tomp2p.dht.PeerBuilderDHT;
|
||||
import net.tomp2p.dht.PeerDHT;
|
||||
|
@ -52,8 +53,7 @@ import net.tomp2p.p2p.Peer;
|
|||
import net.tomp2p.p2p.PeerBuilder;
|
||||
import net.tomp2p.peers.*;
|
||||
|
||||
public class UtilsDHT2
|
||||
{
|
||||
public class UtilsDHT2 {
|
||||
/**
|
||||
* Used to make the testcases predictable. Used as an input for {@link java.util.Random}.
|
||||
*/
|
||||
|
@ -64,74 +64,64 @@ public class UtilsDHT2
|
|||
*/
|
||||
public static final long THE_ANSWER2 = 43L;
|
||||
|
||||
public static Message createDummyMessage() throws UnknownHostException
|
||||
{
|
||||
public static Message createDummyMessage() throws UnknownHostException {
|
||||
return createDummyMessage(false, false);
|
||||
}
|
||||
|
||||
public static Message createDummyMessage(boolean firewallUDP, boolean firewallTCP)
|
||||
throws UnknownHostException
|
||||
{
|
||||
throws UnknownHostException {
|
||||
return createDummyMessage(new Number160("0x4321"), "127.0.0.1", 8001, 8002, new Number160("0x1234"),
|
||||
"127.0.0.1", 8003, 8004, (byte) 0, Type.REQUEST_1, firewallUDP, firewallTCP);
|
||||
"127.0.0.1", 8003, 8004, (byte) 0, Type.REQUEST_1, firewallUDP, firewallTCP);
|
||||
}
|
||||
|
||||
public static PeerAddress createAddress(Number160 id) throws UnknownHostException
|
||||
{
|
||||
public static PeerAddress createAddress(Number160 id) throws UnknownHostException {
|
||||
return createAddress(id, "127.0.0.1", 8005, 8006, false, false);
|
||||
}
|
||||
|
||||
public static PeerAddress createAddress() throws UnknownHostException
|
||||
{
|
||||
public static PeerAddress createAddress() throws UnknownHostException {
|
||||
return createAddress(new Number160("0x5678"), "127.0.0.1", 8005, 8006, false, false);
|
||||
}
|
||||
|
||||
public static PeerAddress createAddress(int id) throws UnknownHostException
|
||||
{
|
||||
public static PeerAddress createAddress(int id) throws UnknownHostException {
|
||||
return createAddress(new Number160(id), "127.0.0.1", 8005, 8006, false, false);
|
||||
}
|
||||
|
||||
public static PeerAddress createAddress(String id) throws UnknownHostException
|
||||
{
|
||||
public static PeerAddress createAddress(String id) throws UnknownHostException {
|
||||
return createAddress(new Number160(id), "127.0.0.1", 8005, 8006, false, false);
|
||||
}
|
||||
|
||||
public static PeerAddress createAddress(Number160 idSender, String inetSender, int tcpPortSender,
|
||||
int udpPortSender, boolean firewallUDP, boolean firewallTCP) throws UnknownHostException
|
||||
{
|
||||
int udpPortSender, boolean firewallUDP, boolean firewallTCP) throws UnknownHostException {
|
||||
InetAddress inetSend = InetAddress.getByName(inetSender);
|
||||
PeerSocketAddress peerSocketAddress = new PeerSocketAddress(inetSend, tcpPortSender, udpPortSender);
|
||||
PeerAddress n1 = new PeerAddress(idSender, peerSocketAddress, firewallTCP, firewallUDP, false,
|
||||
PeerAddress.EMPTY_PEER_SOCKET_ADDRESSES);
|
||||
PeerAddress.EMPTY_PEER_SOCKET_ADDRESSES);
|
||||
return n1;
|
||||
}
|
||||
|
||||
public static Message createDummyMessage(Number160 idSender, String inetSender, int tcpPortSendor,
|
||||
int udpPortSender, Number160 idRecipien, String inetRecipient, int tcpPortRecipient,
|
||||
int udpPortRecipient, byte command, Type type, boolean firewallUDP, boolean firewallTCP)
|
||||
throws UnknownHostException
|
||||
{
|
||||
throws UnknownHostException {
|
||||
Message message = new Message();
|
||||
PeerAddress n1 = createAddress(idSender, inetSender, tcpPortSendor, udpPortSender, firewallUDP,
|
||||
firewallTCP);
|
||||
firewallTCP);
|
||||
message.sender(n1);
|
||||
//
|
||||
PeerAddress n2 = createAddress(idRecipien, inetRecipient, tcpPortRecipient, udpPortRecipient,
|
||||
firewallUDP, firewallTCP);
|
||||
firewallUDP, firewallTCP);
|
||||
message.recipient(n2);
|
||||
message.type(type);
|
||||
message.command(command);
|
||||
return message;
|
||||
}
|
||||
|
||||
public static PeerDHT[] createNodes(int nrOfPeers, Random rnd, int port) throws Exception
|
||||
{
|
||||
public static PeerDHT[] createNodes(int nrOfPeers, Random rnd, int port) throws Exception {
|
||||
return createNodes(nrOfPeers, rnd, port, null);
|
||||
}
|
||||
|
||||
public static PeerDHT[] createNodes(int nrOfPeers, Random rnd, int port, AutomaticFuture automaticFuture)
|
||||
throws Exception
|
||||
{
|
||||
throws Exception {
|
||||
return createNodes(nrOfPeers, rnd, port, automaticFuture, false);
|
||||
}
|
||||
|
||||
|
@ -146,17 +136,14 @@ public class UtilsDHT2
|
|||
* @throws Exception If the creation of nodes fail.
|
||||
*/
|
||||
public static PeerDHT[] createNodes(int nrOfPeers, Random rnd, int port, AutomaticFuture automaticFuture,
|
||||
boolean maintenance) throws Exception
|
||||
{
|
||||
if (nrOfPeers < 1)
|
||||
{
|
||||
boolean maintenance) throws Exception {
|
||||
if (nrOfPeers < 1) {
|
||||
throw new IllegalArgumentException("Cannot create less than 1 peer");
|
||||
}
|
||||
Bindings bindings = new Bindings();
|
||||
PeerDHT[] peers = new PeerDHT[nrOfPeers];
|
||||
final Peer master;
|
||||
if (automaticFuture != null)
|
||||
{
|
||||
if (automaticFuture != null) {
|
||||
Number160 peerId = new Number160(rnd);
|
||||
PeerMap peerMap = new PeerMap(new PeerMapConfiguration(peerId));
|
||||
master = new PeerBuilder(peerId)
|
||||
|
@ -164,34 +151,28 @@ public class UtilsDHT2
|
|||
.externalBindings(bindings).peerMap(peerMap).start().addAutomaticFuture(automaticFuture);
|
||||
peers[0] = new PeerBuilderDHT(master).start();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Number160 peerId = new Number160(rnd);
|
||||
PeerMap peerMap = new PeerMap(new PeerMapConfiguration(peerId));
|
||||
master = new PeerBuilder(peerId).enableMaintenance(maintenance).externalBindings(bindings)
|
||||
.peerMap(peerMap).ports(port).start();
|
||||
.peerMap(peerMap).ports(port).start();
|
||||
peers[0] = new PeerBuilderDHT(master).start();
|
||||
}
|
||||
|
||||
for (int i = 1; i < nrOfPeers; i++)
|
||||
{
|
||||
if (automaticFuture != null)
|
||||
{
|
||||
for (int i = 1; i < nrOfPeers; i++) {
|
||||
if (automaticFuture != null) {
|
||||
Number160 peerId = new Number160(rnd);
|
||||
PeerMap peerMap = new PeerMap(new PeerMapConfiguration(peerId));
|
||||
Peer peer = new PeerBuilder(peerId)
|
||||
.masterPeer(master)
|
||||
.enableMaintenance(maintenance).enableMaintenance(maintenance).peerMap(peerMap).externalBindings(bindings).start().addAutomaticFuture(automaticFuture);
|
||||
peers[i] = new PeerBuilderDHT(peer).start();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Number160 peerId = new Number160(rnd);
|
||||
PeerMap peerMap = new PeerMap(new PeerMapConfiguration(peerId).peerNoVerification());
|
||||
Peer peer = new PeerBuilder(peerId).enableMaintenance(maintenance)
|
||||
.externalBindings(bindings).peerMap(peerMap).masterPeer(master)
|
||||
.start();
|
||||
.externalBindings(bindings).peerMap(peerMap).masterPeer(master)
|
||||
.start();
|
||||
peers[i] = new PeerBuilderDHT(peer).start();
|
||||
}
|
||||
}
|
||||
|
@ -200,15 +181,12 @@ public class UtilsDHT2
|
|||
}
|
||||
|
||||
public static Peer[] createRealNodes(int nrOfPeers, Random rnd, int startPort,
|
||||
AutomaticFuture automaticFuture) throws Exception
|
||||
{
|
||||
if (nrOfPeers < 1)
|
||||
{
|
||||
AutomaticFuture automaticFuture) throws Exception {
|
||||
if (nrOfPeers < 1) {
|
||||
throw new IllegalArgumentException("Cannot create less than 1 peer");
|
||||
}
|
||||
Peer[] peers = new Peer[nrOfPeers];
|
||||
for (int i = 0; i < nrOfPeers; i++)
|
||||
{
|
||||
for (int i = 0; i < nrOfPeers; i++) {
|
||||
peers[i] = new PeerBuilder(new Number160(rnd))
|
||||
.ports(startPort + i).start().addAutomaticFuture(automaticFuture);
|
||||
}
|
||||
|
@ -216,18 +194,15 @@ public class UtilsDHT2
|
|||
return peers;
|
||||
}
|
||||
|
||||
public static Peer[] createNonMaintenanceNodes(int nrOfPeers, Random rnd, int port) throws IOException
|
||||
{
|
||||
if (nrOfPeers < 1)
|
||||
{
|
||||
public static Peer[] createNonMaintenanceNodes(int nrOfPeers, Random rnd, int port) throws IOException {
|
||||
if (nrOfPeers < 1) {
|
||||
throw new IllegalArgumentException("Cannot create less than 1 peer");
|
||||
}
|
||||
Peer[] peers = new Peer[nrOfPeers];
|
||||
peers[0] = new PeerBuilder(new Number160(rnd)).enableMaintenance(false).ports(port).start();
|
||||
for (int i = 1; i < nrOfPeers; i++)
|
||||
{
|
||||
for (int i = 1; i < nrOfPeers; i++) {
|
||||
peers[i] = new PeerBuilder(new Number160(rnd)).enableMaintenance(false).masterPeer(peers[0])
|
||||
.start();
|
||||
.start();
|
||||
}
|
||||
System.err.println("non-maintenance peers created.");
|
||||
return peers;
|
||||
|
@ -239,87 +214,69 @@ public class UtilsDHT2
|
|||
*
|
||||
* @param peers The peers taking part in the p2p network.
|
||||
*/
|
||||
public static void perfectRouting(PeerDHT... peers)
|
||||
{
|
||||
for (int i = 0; i < peers.length; i++)
|
||||
{
|
||||
public static void perfectRouting(PeerDHT... peers) {
|
||||
for (int i = 0; i < peers.length; i++) {
|
||||
for (int j = 0; j < peers.length; j++)
|
||||
peers[i].peer().peerBean().peerMap().peerFound(peers[j].peer().peerAddress(), null);
|
||||
}
|
||||
System.err.println("perfect routing done.");
|
||||
}
|
||||
|
||||
public static void perfectRoutingIndirect(PeerDHT... peers)
|
||||
{
|
||||
for (int i = 0; i < peers.length; i++)
|
||||
{
|
||||
public static void perfectRoutingIndirect(PeerDHT... peers) {
|
||||
for (int i = 0; i < peers.length; i++) {
|
||||
for (int j = 0; j < peers.length; j++)
|
||||
peers[i].peerBean().peerMap().peerFound(peers[j].peerAddress(), peers[j].peerAddress());
|
||||
}
|
||||
System.err.println("perfect routing done.");
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException
|
||||
{
|
||||
public static void main(String[] args) throws IOException {
|
||||
createTempDirectory();
|
||||
}
|
||||
|
||||
private static final int TEMP_DIR_ATTEMPTS = 10000;
|
||||
|
||||
public static File createTempDirectory() throws IOException
|
||||
{
|
||||
public static File createTempDirectory() throws IOException {
|
||||
File baseDir = new File(System.getProperty("java.io.tmpdir"));
|
||||
String baseName = System.currentTimeMillis() + "-";
|
||||
|
||||
for (int counter = 0; counter < TEMP_DIR_ATTEMPTS; counter++)
|
||||
{
|
||||
for (int counter = 0; counter < TEMP_DIR_ATTEMPTS; counter++) {
|
||||
File tempDir = new File(baseDir, baseName + counter);
|
||||
if (tempDir.mkdir())
|
||||
{
|
||||
if (tempDir.mkdir()) {
|
||||
return tempDir;
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException("Failed to create directory within " + TEMP_DIR_ATTEMPTS
|
||||
+ " attempts (tried " + baseName + "0 to " + baseName + (TEMP_DIR_ATTEMPTS - 1) + ')');
|
||||
+ " attempts (tried " + baseName + "0 to " + baseName + (TEMP_DIR_ATTEMPTS - 1) + ')');
|
||||
}
|
||||
|
||||
public static Peer[] createAndAttachNodes(int nr, int port, Random rnd) throws Exception
|
||||
{
|
||||
public static Peer[] createAndAttachNodes(int nr, int port, Random rnd) throws Exception {
|
||||
Peer[] peers = new Peer[nr];
|
||||
for (int i = 0; i < nr; i++)
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
for (int i = 0; i < nr; i++) {
|
||||
if (i == 0) {
|
||||
peers[0] = new PeerBuilder(new Number160(rnd)).ports(port).start();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
peers[i] = new PeerBuilder(new Number160(rnd)).masterPeer(peers[0]).start();
|
||||
}
|
||||
}
|
||||
return peers;
|
||||
}
|
||||
|
||||
public static void bootstrap(Peer[] peers)
|
||||
{
|
||||
public static void bootstrap(Peer[] peers) {
|
||||
List<FutureBootstrap> futures1 = new ArrayList<FutureBootstrap>();
|
||||
List<FutureDiscover> futures2 = new ArrayList<FutureDiscover>();
|
||||
for (int i = 1; i < peers.length; i++)
|
||||
{
|
||||
for (int i = 1; i < peers.length; i++) {
|
||||
FutureDiscover tmp = peers[i].discover().peerAddress(peers[0].peerAddress()).start();
|
||||
futures2.add(tmp);
|
||||
}
|
||||
for (FutureDiscover future : futures2)
|
||||
{
|
||||
for (FutureDiscover future : futures2) {
|
||||
future.awaitUninterruptibly();
|
||||
}
|
||||
for (int i = 1; i < peers.length; i++)
|
||||
{
|
||||
for (int i = 1; i < peers.length; i++) {
|
||||
FutureBootstrap tmp = peers[i].bootstrap().peerAddress(peers[0].peerAddress()).start();
|
||||
futures1.add(tmp);
|
||||
}
|
||||
for (int i = 1; i < peers.length; i++)
|
||||
{
|
||||
for (int i = 1; i < peers.length; i++) {
|
||||
FutureBootstrap tmp = peers[0].bootstrap().peerAddress(peers[i].peerAddress()).start();
|
||||
futures1.add(tmp);
|
||||
}
|
||||
|
@ -327,24 +284,21 @@ public class UtilsDHT2
|
|||
future.awaitUninterruptibly();
|
||||
}
|
||||
|
||||
public static void routing(Number160 key, Peer[] peers, int start)
|
||||
{
|
||||
public static void routing(Number160 key, Peer[] peers, int start) {
|
||||
System.out.println("routing: searching for key " + key);
|
||||
NavigableSet<PeerAddress> pa1 = new TreeSet<PeerAddress>(PeerMap.createComparator(key));
|
||||
NavigableSet<PeerAddress> queried = new TreeSet<PeerAddress>(PeerMap.createComparator(key));
|
||||
Number160 result = Number160.ZERO;
|
||||
Number160 resultPeer = new Number160("0xd75d1a3d57841fbc9e2a3d175d6a35dc2e15b9f");
|
||||
int round = 0;
|
||||
while (!resultPeer.equals(result))
|
||||
{
|
||||
while (!resultPeer.equals(result)) {
|
||||
System.out.println("round " + round);
|
||||
round++;
|
||||
pa1.addAll(peers[start].peerBean().peerMap().all());
|
||||
queried.add(peers[start].peerAddress());
|
||||
System.out.println("closest so far: " + queried.first());
|
||||
PeerAddress next = pa1.pollFirst();
|
||||
while (queried.contains(next))
|
||||
{
|
||||
while (queried.contains(next)) {
|
||||
next = pa1.pollFirst();
|
||||
}
|
||||
result = next.peerId();
|
||||
|
@ -352,24 +306,18 @@ public class UtilsDHT2
|
|||
}
|
||||
}
|
||||
|
||||
public static void findInMap(PeerAddress key, Peer[] peers)
|
||||
{
|
||||
for (int i = 0; i < peers.length; i++)
|
||||
{
|
||||
if (peers[i].peerBean().peerMap().contains(key))
|
||||
{
|
||||
public static void findInMap(PeerAddress key, Peer[] peers) {
|
||||
for (int i = 0; i < peers.length; i++) {
|
||||
if (peers[i].peerBean().peerMap().contains(key)) {
|
||||
System.out.println("Peer " + i + " with the id " + peers[i].peerID() + " knows the peer "
|
||||
+ key);
|
||||
+ key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static int findNr(String string, Peer[] peers)
|
||||
{
|
||||
for (int i = 0; i < peers.length; i++)
|
||||
{
|
||||
if (peers[i].peerID().equals(new Number160(string)))
|
||||
{
|
||||
public static int findNr(String string, Peer[] peers) {
|
||||
for (int i = 0; i < peers.length; i++) {
|
||||
if (peers[i].peerID().equals(new Number160(string))) {
|
||||
System.out.println("we found the number " + i + " for peer with id " + string);
|
||||
return i;
|
||||
}
|
||||
|
@ -377,12 +325,9 @@ public class UtilsDHT2
|
|||
return -1;
|
||||
}
|
||||
|
||||
public static Peer find(String string, Peer[] peers)
|
||||
{
|
||||
for (int i = 0; i < peers.length; i++)
|
||||
{
|
||||
if (peers[i].peerID().equals(new Number160(string)))
|
||||
{
|
||||
public static Peer find(String string, Peer[] peers) {
|
||||
for (int i = 0; i < peers.length; i++) {
|
||||
if (peers[i].peerID().equals(new Number160(string))) {
|
||||
System.out.println("!!we found the number " + i + " for peer with id " + string);
|
||||
return peers[i];
|
||||
}
|
||||
|
@ -390,37 +335,31 @@ public class UtilsDHT2
|
|||
return null;
|
||||
}
|
||||
|
||||
public static void exec(String cmd) throws Exception
|
||||
{
|
||||
public static void exec(String cmd) throws Exception {
|
||||
Process p = Runtime.getRuntime().exec(cmd);
|
||||
p.waitFor();
|
||||
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
||||
String line = null;
|
||||
while ((line = br.readLine()) != null)
|
||||
{
|
||||
while ((line = br.readLine()) != null) {
|
||||
System.out.println(line);
|
||||
}
|
||||
br.close();
|
||||
}
|
||||
|
||||
public static PeerAddress createAddressIP(String inet) throws UnknownHostException
|
||||
{
|
||||
public static PeerAddress createAddressIP(String inet) throws UnknownHostException {
|
||||
return createAddress(Number160.createHash(inet), inet, 8005, 8006, false, false);
|
||||
}
|
||||
|
||||
public static PeerAddress[] createDummyAddress(int size, int portTCP, int portUDP) throws UnknownHostException
|
||||
{
|
||||
public static PeerAddress[] createDummyAddress(int size, int portTCP, int portUDP) throws UnknownHostException {
|
||||
PeerAddress[] pa = new PeerAddress[size];
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
for (int i = 0; i < size; i++) {
|
||||
pa[i] = createAddress(i + 1, portTCP, portUDP);
|
||||
}
|
||||
return pa;
|
||||
}
|
||||
|
||||
public static PeerAddress createAddress(int iid, int portTCP, int portUDP) throws UnknownHostException
|
||||
{
|
||||
public static PeerAddress createAddress(int iid, int portTCP, int portUDP) throws UnknownHostException {
|
||||
Number160 id = new Number160(iid);
|
||||
InetAddress address = InetAddress.getByName("127.0.0.1");
|
||||
return new PeerAddress(id, address, portTCP, portUDP);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue