Remove localhost server setup in WAN test

This commit is contained in:
Manfred Karrer 2014-10-23 14:13:33 +02:00
parent 3fddcddc1e
commit f81a584e70
4 changed files with 111 additions and 36 deletions

View File

@ -60,8 +60,8 @@ public class BasicUsecasesInLANTest {
private final static String CLIENT_1_ID = "alice";
private final static String CLIENT_2_ID = "bob";
private final static int CLIENT_1_PORT = 6500;
private final static int CLIENT_2_PORT = 6501;
private final static int CLIENT_1_PORT = 6510;
private final static int CLIENT_2_PORT = 6511;
private Thread serverThread;

View File

@ -42,9 +42,7 @@ import net.tomp2p.peers.Number160;
import net.tomp2p.peers.PeerAddress;
import net.tomp2p.storage.Data;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@ -65,42 +63,16 @@ public class BasicUsecasesInWANTest {
private final static String SERVER_ID = "digitalocean1.bitsquare.io";
private final static String SERVER_IP = "188.226.179.109";
//private final static String SERVER_IP = "128.199.251.106"; // steves server
private final static int SERVER_PORT = 5000;
private final static String CLIENT_1_ID = "alice";
private final static String CLIENT_2_ID = "bob";
private final static int CLIENT_1_PORT = 6503;
private final static int CLIENT_2_PORT = 6504;
private final static int CLIENT_1_PORT = 6505;
private final static int CLIENT_2_PORT = 6506;
private Thread serverThread;
@Before
public void startServer() throws Exception {
serverThread = new Thread(() -> {
Peer peer = null;
try {
peer = new PeerBuilder(Number160.createHash(SERVER_ID)).ports(SERVER_PORT).start();
log.debug("peer started.");
while (true) {
for (PeerAddress pa : peer.peerBean().peerMap().all()) {
log.debug("peer online (TCP):" + pa);
}
Thread.sleep(2000);
}
} catch (InterruptedException e) {
if (peer != null)
peer.shutdown().awaitUninterruptibly();
} catch (IOException e2) {
e2.printStackTrace();
}
});
serverThread.start();
}
@After
public void stopServer() throws Exception {
serverThread.interrupt();
}
@Test
@Ignore
@ -223,8 +195,9 @@ No future set beforehand, probably an early shutdown / timeout, or use setFailed
private PeerDHT startClient(String clientId, int clientPort) throws Exception {
Peer peer = null;
try {
Peer peer = new PeerBuilder(Number160.createHash(clientId)).ports(clientPort).behindFirewall().start();
peer = new PeerBuilder(Number160.createHash(clientId)).ports(clientPort).behindFirewall().start();
PeerDHT peerDHT = new PeerBuilderDHT(peer).storageLayer(new StorageLayer(new StorageMemory())).start();
PeerAddress masterNodeAddress = new PeerAddress(Number160.createHash(SERVER_ID), SERVER_IP, SERVER_PORT,
@ -242,8 +215,8 @@ No future set beforehand, probably an early shutdown / timeout, or use setFailed
if (futureNAT.isSuccess()) {
FutureDiscover futureDiscover2 = peer.discover().peerAddress(masterNodeAddress).start();
futureDiscover2.awaitUninterruptibly();
if (futureDiscover.isSuccess()) {
log.info("Discover with direct connection successful. Address = " + futureDiscover
if (futureDiscover2.isSuccess()) {
log.info("Discover with direct connection successful. Address = " + futureDiscover2
.peerAddress());
log.info("Automatic port forwarding is setup. Address = " +
@ -279,6 +252,7 @@ No future set beforehand, probably an early shutdown / timeout, or use setFailed
log.error("Bootstrap in relay mode failed " + e.getMessage());
e.printStackTrace();
Assert.fail("Bootstrap in relay mode failed " + e.getMessage());
peer.shutdown().awaitUninterruptibly();
return null;
}
}

View File

@ -0,0 +1,51 @@
/*
* This file is part of Bitsquare.
*
* Bitsquare is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/
package io.bitsquare.msg;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// http://systembash.com/content/a-simple-java-udp-server-and-udp-client/
public class UDPClient {
private static final Logger log = LoggerFactory.getLogger(UDPClient.class);
public static void main(String args[]) throws Exception {
BufferedReader inFromUser =
new BufferedReader(new InputStreamReader(System.in));
DatagramSocket clientSocket = new DatagramSocket();
InetAddress IPAddress = InetAddress.getByName("188.226.179.109");
byte[] sendData = new byte[1024];
byte[] receiveData = new byte[1024];
String sentence = inFromUser.readLine();
sendData = sentence.getBytes();
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9876);
clientSocket.send(sendPacket);
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
clientSocket.receive(receivePacket);
String modifiedSentence = new String(receivePacket.getData());
System.out.println("FROM SERVER:" + modifiedSentence);
clientSocket.close();
}
}

View File

@ -0,0 +1,50 @@
/*
* This file is part of Bitsquare.
*
* Bitsquare is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/
package io.bitsquare.msg;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// http://systembash.com/content/a-simple-java-udp-server-and-udp-client/
public class UDPServer {
private static final Logger log = LoggerFactory.getLogger(UDPServer.class);
public static void main(String args[]) throws Exception {
DatagramSocket serverSocket = new DatagramSocket(9876);
byte[] receiveData = new byte[1024];
byte[] sendData = new byte[1024];
while (true) {
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
serverSocket.receive(receivePacket);
String sentence = new String(receivePacket.getData());
System.out.println("RECEIVED: " + sentence);
InetAddress IPAddress = receivePacket.getAddress();
int port = receivePacket.getPort();
String capitalizedSentence = sentence.toUpperCase();
sendData = capitalizedSentence.getBytes();
DatagramPacket sendPacket =
new DatagramPacket(sendData, sendData.length, IPAddress, port);
serverSocket.send(sendPacket);
}
}
}