Fix style
This commit is contained in:
parent
8d5ef8a52b
commit
e56aad5526
@ -89,28 +89,28 @@ public class ClientP2P {
|
|||||||
final ServerPortRange serverPortRange = new ServerPortRange();
|
final ServerPortRange serverPortRange = new ServerPortRange();
|
||||||
final TrackerPortRange trackerPortRange = new TrackerPortRange();
|
final TrackerPortRange trackerPortRange = new TrackerPortRange();
|
||||||
|
|
||||||
if ((args.length != 6) && (args.length != 0)){
|
if ((args.length != 6) && (args.length != 0)) {
|
||||||
ClientP2P.printUsage(serverPortRange, trackerPortRange);
|
ClientP2P.printUsage(serverPortRange, trackerPortRange);
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
else if(args.length == 6){
|
else if (args.length == 6) {
|
||||||
protocolClient = args[1];
|
protocolClient = args[1];
|
||||||
hostnameServer = args[2];
|
hostnameServer = args[2];
|
||||||
portServer = Integer.valueOf(Integer.parseInt(args[3]));
|
portServer = Integer.valueOf(Integer.parseInt(args[3]));
|
||||||
hostnameTracker = args[4];
|
hostnameTracker = args[4];
|
||||||
portTracker = Integer.valueOf(Integer.parseInt(args[5]));
|
portTracker = Integer.valueOf(Integer.parseInt(args[5]));
|
||||||
} else{
|
} else {
|
||||||
System.out.println("Client, wich transport protocol do you want to use (default = TCP): ");
|
System.out.println("Client, wich transport protocol do you want to use (default = TCP): ");
|
||||||
protocolClient = scanner.nextLine();
|
protocolClient = scanner.nextLine();
|
||||||
System.out.println("server side, enter hostname to bind (default = localhost): ");
|
System.out.println("server side, enter hostname to bind (default = localhost): ");
|
||||||
hostnameServer = scanner.nextLine();
|
hostnameServer = scanner.nextLine();
|
||||||
if(hostnameServer.equals("")){
|
if (hostnameServer.equals("")) {
|
||||||
hostnameServer = defaultHostname;
|
hostnameServer = defaultHostname;
|
||||||
System.out.println("using default hostname : " + hostnameServer);
|
System.out.println("using default hostname : " + hostnameServer);
|
||||||
}
|
}
|
||||||
System.out.println("enter port (default = " + serverPortRange.getDefaultPort() +"): ");
|
System.out.println("enter port (default = " + serverPortRange.getDefaultPort() +"): ");
|
||||||
String portServerStr = scanner.nextLine();
|
String portServerStr = scanner.nextLine();
|
||||||
if(portServerStr.equals("")){
|
if (portServerStr.equals("")) {
|
||||||
portServer = serverPortRange.getDefaultPort();
|
portServer = serverPortRange.getDefaultPort();
|
||||||
System.out.println("using default port : " + portServer);
|
System.out.println("using default port : " + portServer);
|
||||||
} else {
|
} else {
|
||||||
@ -118,13 +118,13 @@ public class ClientP2P {
|
|||||||
}
|
}
|
||||||
System.out.println("enter hostname of tracker (default = localhost): ");
|
System.out.println("enter hostname of tracker (default = localhost): ");
|
||||||
hostnameTracker = scanner.nextLine();
|
hostnameTracker = scanner.nextLine();
|
||||||
if(hostnameTracker.equals("")){
|
if (hostnameTracker.equals("")) {
|
||||||
hostnameTracker = defaultHostname;
|
hostnameTracker = defaultHostname;
|
||||||
System.out.println("tracker default hostname : " + hostnameTracker);
|
System.out.println("tracker default hostname : " + hostnameTracker);
|
||||||
}
|
}
|
||||||
System.out.println("enter tracker's port (default = "+trackerPortRange.getDefaultPort() + "): ");
|
System.out.println("enter tracker's port (default = "+trackerPortRange.getDefaultPort() + "): ");
|
||||||
String portTrackerStr = scanner.nextLine();
|
String portTrackerStr = scanner.nextLine();
|
||||||
if(portTrackerStr.equals("")){
|
if (portTrackerStr.equals("")) {
|
||||||
portTracker = trackerPortRange.getDefaultPort();
|
portTracker = trackerPortRange.getDefaultPort();
|
||||||
System.out.println("using default port : " + portTracker);
|
System.out.println("using default port : " + portTracker);
|
||||||
} else {
|
} else {
|
||||||
@ -132,8 +132,10 @@ public class ClientP2P {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (serverPortRange.isPortInRange(portServer)){
|
boolean serverInRange = serverPortRange.isPortInRange(portServer);
|
||||||
if(trackerPortRange.isPortInRange(portTracker)){
|
boolean trackerInRange = trackerPortRange.isPortInRange(portTracker);
|
||||||
|
|
||||||
|
if (serverInRange && trackerInRange) {
|
||||||
System.out.println("using hostname : " + hostnameServer);
|
System.out.println("using hostname : " + hostnameServer);
|
||||||
System.out.println("using port : " + portServer);
|
System.out.println("using port : " + portServer);
|
||||||
System.out.println("tracker hostname : " + hostnameTracker);
|
System.out.println("tracker hostname : " + hostnameTracker);
|
||||||
@ -152,12 +154,12 @@ public class ClientP2P {
|
|||||||
// This is not required, but allow to have a cleaner interface
|
// This is not required, but allow to have a cleaner interface
|
||||||
try {
|
try {
|
||||||
Thread.sleep(200);
|
Thread.sleep(200);
|
||||||
} catch(InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread tclient;
|
Thread tclient;
|
||||||
switch(protocolClient){
|
switch (protocolClient) {
|
||||||
case "UDP":
|
case "UDP":
|
||||||
case "udp":
|
case "udp":
|
||||||
case "upd": // to avoid users typos
|
case "upd": // to avoid users typos
|
||||||
@ -182,13 +184,14 @@ public class ClientP2P {
|
|||||||
} catch (InterruptedException e) {}
|
} catch (InterruptedException e) {}
|
||||||
smudp.setStop();
|
smudp.setStop();
|
||||||
smtcp.setStop();
|
smtcp.setStop();
|
||||||
|
} else {
|
||||||
|
if (!serverInRange) {
|
||||||
|
System.err.println("SERVER: Port not in range. " + serverPortRange);
|
||||||
}
|
}
|
||||||
else{
|
if (!trackerInRange) {
|
||||||
System.out.println("\n TRACKER: Port not in range. " + trackerPortRange);
|
System.err.println("TRACKER: Port not in range. " + trackerPortRange);
|
||||||
}
|
}
|
||||||
}
|
System.exit(2);
|
||||||
else{
|
|
||||||
System.out.println("\n SERVER: Port not in range. " + serverPortRange);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ public class ServerP2P {
|
|||||||
directories.createSubdir(subdir);
|
directories.createSubdir(subdir);
|
||||||
logger = new Logger(directories.getDataHomeDirectory() + "server.log");
|
logger = new Logger(directories.getDataHomeDirectory() + "server.log");
|
||||||
System.out.println("Server will listen on port " + portServer + " and serve files from " + directories.getDataHomeDirectory() + subdir);
|
System.out.println("Server will listen on port " + portServer + " and serve files from " + directories.getDataHomeDirectory() + subdir);
|
||||||
if(isInteractive){
|
if (isInteractive) {
|
||||||
directories.askOpenDataHomeDirectory(subdir, scanner);
|
directories.askOpenDataHomeDirectory(subdir, scanner);
|
||||||
}
|
}
|
||||||
scanner.close();
|
scanner.close();
|
||||||
@ -61,40 +61,43 @@ public class ServerP2P {
|
|||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
boolean isInteractive = false;
|
boolean isInteractive = false;
|
||||||
|
|
||||||
if ((args.length != 5) && (args.length != 0)){
|
if ((args.length != 5) && (args.length != 0)) {
|
||||||
System.out.println("usage : java serveurP2P.ServeurP2P (interactive) or java serveurP2P.ServeurP2P -- <serveurHOSTNAME> <serveurPORT> <trackerHOSTNAME> <trackerPORT> (" + serverPortRange + " and " + trackerPortRange +")");
|
System.out.println("usage : java serveurP2P.ServeurP2P (interactive) or java serveurP2P.ServeurP2P -- <serveurHOSTNAME> <serveurPORT> <trackerHOSTNAME> <trackerPORT> (" + serverPortRange + " and " + trackerPortRange +")");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
else if(args.length == 5){
|
else if (args.length == 5) {
|
||||||
|
isInteractive = false;
|
||||||
hostnameServer = args[1];
|
hostnameServer = args[1];
|
||||||
portServer = Integer.valueOf(Integer.parseInt(args[2]));
|
portServer = Integer.valueOf(Integer.parseInt(args[2]));
|
||||||
hostnameTracker = args[3];
|
hostnameTracker = args[3];
|
||||||
portTracker = Integer.valueOf(Integer.parseInt(args[4]));
|
portTracker = Integer.valueOf(Integer.parseInt(args[4]));
|
||||||
} else {
|
} else {
|
||||||
isInteractive = true;
|
isInteractive = true;
|
||||||
|
// configure application
|
||||||
System.out.println("Server, enter hostname to bind (default = localhost): ");
|
System.out.println("Server, enter hostname to bind (default = localhost): ");
|
||||||
hostnameServer = scanner.nextLine();
|
hostnameServer = scanner.nextLine();
|
||||||
if(hostnameServer.equals("")){
|
if (hostnameServer.equals("")) {
|
||||||
hostnameServer = defaultHostname;
|
hostnameServer = defaultHostname;
|
||||||
System.out.println("using default hostname : " + hostnameServer);
|
System.out.println("using default hostname : " + hostnameServer);
|
||||||
}
|
}
|
||||||
System.out.println("enter port (default = " + serverPortRange.getDefaultPort() + "): ");
|
System.out.println("Enter port (default = " + serverPortRange.getDefaultPort() + "): ");
|
||||||
String portServerStr = scanner.nextLine();
|
String portServerStr = scanner.nextLine();
|
||||||
if(portServerStr.equals("")){
|
if (portServerStr.equals("")) {
|
||||||
portServer = serverPortRange.getDefaultPort();
|
portServer = serverPortRange.getDefaultPort();
|
||||||
System.out.println("using default port : " + portServer);
|
System.out.println("using default port : " + portServer);
|
||||||
} else {
|
} else {
|
||||||
portServer = Integer.valueOf(Integer.parseInt(portServerStr));
|
portServer = Integer.valueOf(Integer.parseInt(portServerStr));
|
||||||
}
|
}
|
||||||
System.out.println("enter hostname of tracker (default = localhost): ");
|
// configure tracker
|
||||||
|
System.out.println("Enter hostname of tracker (default = localhost): ");
|
||||||
hostnameTracker = scanner.nextLine();
|
hostnameTracker = scanner.nextLine();
|
||||||
if(hostnameTracker.equals("")){
|
if (hostnameTracker.equals("")) {
|
||||||
hostnameTracker = defaultHostname;
|
hostnameTracker = defaultHostname;
|
||||||
System.out.println("tracker default hostname : " + hostnameTracker);
|
System.out.println("tracker default hostname : " + hostnameTracker);
|
||||||
}
|
}
|
||||||
System.out.println("enter tracker's port (default = " + trackerPortRange.getDefaultPort() + "): ");
|
System.out.println("Enter tracker's port (default = " + trackerPortRange.getDefaultPort() + "): ");
|
||||||
String portTrackerStr = scanner.nextLine();
|
String portTrackerStr = scanner.nextLine();
|
||||||
if(portTrackerStr.equals("")){
|
if (portTrackerStr.equals("")) {
|
||||||
portTracker = trackerPortRange.getDefaultPort();
|
portTracker = trackerPortRange.getDefaultPort();
|
||||||
System.out.println("using default port : " + portTracker);
|
System.out.println("using default port : " + portTracker);
|
||||||
} else {
|
} else {
|
||||||
@ -102,8 +105,9 @@ public class ServerP2P {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (serverPortRange.isPortInRange(portServer)){
|
boolean serverInRange = serverPortRange.isPortInRange(portServer);
|
||||||
if(trackerPortRange.isPortInRange(portTracker)){
|
boolean trackerInRange = trackerPortRange.isPortInRange(portTracker);
|
||||||
|
if (serverInRange && trackerInRange) {
|
||||||
System.out.println("using hostname : " + hostnameServer);
|
System.out.println("using hostname : " + hostnameServer);
|
||||||
System.out.println("using port : " + portServer);
|
System.out.println("using port : " + portServer);
|
||||||
System.out.println("tracker hostname : " + hostnameTracker);
|
System.out.println("tracker hostname : " + hostnameTracker);
|
||||||
@ -117,13 +121,14 @@ public class ServerP2P {
|
|||||||
Thread ttcp = new Thread(smtcp);
|
Thread ttcp = new Thread(smtcp);
|
||||||
ttcp.setName("server TCP P2P-JAVA-PROJECT");
|
ttcp.setName("server TCP P2P-JAVA-PROJECT");
|
||||||
ttcp.start();
|
ttcp.start();
|
||||||
|
} else {
|
||||||
|
if (!serverInRange) {
|
||||||
|
System.err.println("SERVER: Port not in range. " + serverPortRange);
|
||||||
}
|
}
|
||||||
else{
|
if (!trackerInRange) {
|
||||||
System.out.println("\n TRACKER: Port not in range. " + trackerPortRange);
|
System.err.println("TRACKER: Port not in range. " + trackerPortRange);
|
||||||
}
|
}
|
||||||
}
|
System.exit(2);
|
||||||
else{
|
|
||||||
System.out.println("\n SERVER: Port not in range. " + serverPortRange);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ public class Tracker {
|
|||||||
logger = new Logger(directories.getDataHomeDirectory() + "tracker.log");
|
logger = new Logger(directories.getDataHomeDirectory() + "tracker.log");
|
||||||
System.out.println("Tracker will listen on port " + port + " and write logs into " + directories.getDataHomeDirectory());
|
System.out.println("Tracker will listen on port " + port + " and write logs into " + directories.getDataHomeDirectory());
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
if(isInteractive){
|
if (isInteractive) {
|
||||||
directories.askOpenDataHomeDirectory(null, scanner);
|
directories.askOpenDataHomeDirectory(null, scanner);
|
||||||
}
|
}
|
||||||
scanner.close();
|
scanner.close();
|
||||||
@ -52,23 +52,24 @@ public class Tracker {
|
|||||||
Tracker t;
|
Tracker t;
|
||||||
boolean isInteractive = false;
|
boolean isInteractive = false;
|
||||||
|
|
||||||
if ((args.length != 3) && (args.length != 0)){
|
if ((args.length != 3) && (args.length != 0)) {
|
||||||
System.out.println("usage : java tracker.Tracker (interactive) or java trackerP2P.trackerP2P -- <hostname> <PORT> (" + trackerPortRange +")");
|
System.out.println("usage : java tracker.Tracker (interactive) or java trackerP2P.trackerP2P -- <hostname> <PORT> (" + trackerPortRange +")");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
} else if (args.length == 3){
|
} else if (args.length == 3) {
|
||||||
|
isInteractive = false;
|
||||||
hostname = args[1];
|
hostname = args[1];
|
||||||
port = Integer.valueOf(Integer.parseInt(args[2]));
|
port = Integer.valueOf(Integer.parseInt(args[2]));
|
||||||
} else {
|
} else {
|
||||||
isInteractive = true;
|
isInteractive = true;
|
||||||
System.out.println("Tracker Server, enter hostname to bind (default = localhost): ");
|
System.out.println("Tracker Server, enter hostname to bind (default = localhost): ");
|
||||||
hostname = scanner.nextLine();
|
hostname = scanner.nextLine();
|
||||||
if(hostname.equals("")){
|
if (hostname.equals("")) {
|
||||||
hostname = defaultHostname;
|
hostname = defaultHostname;
|
||||||
System.out.println("using default hostname : " + hostname);
|
System.out.println("using default hostname : " + hostname);
|
||||||
}
|
}
|
||||||
System.out.println("enter port (default = " + trackerPortRange.getDefaultPort() +"): ");
|
System.out.println("enter port (default = " + trackerPortRange.getDefaultPort() +"): ");
|
||||||
String portStr = scanner.nextLine();
|
String portStr = scanner.nextLine();
|
||||||
if(portStr.equals("")){
|
if (portStr.equals("")) {
|
||||||
port = trackerPortRange.getDefaultPort();
|
port = trackerPortRange.getDefaultPort();
|
||||||
System.out.println("using default port : " + port);
|
System.out.println("using default port : " + port);
|
||||||
} else {
|
} else {
|
||||||
@ -77,7 +78,7 @@ public class Tracker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("using hostname : " + hostname);
|
System.out.println("using hostname : " + hostname);
|
||||||
if(trackerPortRange.isPortInRange(port)) {
|
if (trackerPortRange.isPortInRange(port)) {
|
||||||
System.out.println("using port : " + port);
|
System.out.println("using port : " + port);
|
||||||
t = new Tracker(hostname, port, isInteractive);
|
t = new Tracker(hostname, port, isInteractive);
|
||||||
TrackerManagementUDP tmudp = new TrackerManagementUDP(t.tracker, t.logger);
|
TrackerManagementUDP tmudp = new TrackerManagementUDP(t.tracker, t.logger);
|
||||||
@ -88,9 +89,9 @@ public class Tracker {
|
|||||||
Thread ttcp = new Thread(tmtcp);
|
Thread ttcp = new Thread(tmtcp);
|
||||||
ttcp.setName("Tracker TCP P2P-JAVA-PROJECT");
|
ttcp.setName("Tracker TCP P2P-JAVA-PROJECT");
|
||||||
ttcp.start();
|
ttcp.start();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
System.out.println("Port not in range. " + trackerPortRange);
|
System.out.println("Port not in range. " + trackerPortRange);
|
||||||
|
System.exit(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user