|
|
@ -7,7 +7,6 @@ import tools.Directories;
|
|
|
|
import tools.Logger;
|
|
|
|
import tools.Logger;
|
|
|
|
import tools.LogLevel;
|
|
|
|
import tools.LogLevel;
|
|
|
|
import tools.TestPort;
|
|
|
|
import tools.TestPort;
|
|
|
|
import tools.TestLegitIP;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Tracker implementation
|
|
|
|
/** Tracker implementation
|
|
|
|
* First argument of main method is port listened by the tracker, and is mandatory.
|
|
|
|
* First argument of main method is port listened by the tracker, and is mandatory.
|
|
|
@ -43,44 +42,55 @@ public class Tracker {
|
|
|
|
final String defaultPort = "6969";
|
|
|
|
final String defaultPort = "6969";
|
|
|
|
final String defaultHostname = "localhost";
|
|
|
|
final String defaultHostname = "localhost";
|
|
|
|
Scanner scanner = new Scanner(System.in);
|
|
|
|
Scanner scanner = new Scanner(System.in);
|
|
|
|
TestLegitIP testLegitIP = new TestLegitIP();
|
|
|
|
|
|
|
|
TestPort testPortTracker = new TestPort();
|
|
|
|
TestPort testPortTracker = new TestPort();
|
|
|
|
|
|
|
|
String hostname;
|
|
|
|
|
|
|
|
String port;
|
|
|
|
Tracker t;
|
|
|
|
Tracker t;
|
|
|
|
|
|
|
|
|
|
|
|
do{
|
|
|
|
System.out.println("args.lenght : " + args.length);
|
|
|
|
System.out.println("Tracker Server, enter hostname to bind (default = localhost): ");
|
|
|
|
|
|
|
|
String hostname = scanner.nextLine();
|
|
|
|
|
|
|
|
if(hostname.equals("")){
|
|
|
|
|
|
|
|
hostname = defaultHostname;
|
|
|
|
|
|
|
|
System.out.println("using default hostname : " + hostname);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (!testLegitIP.TestIP(hostname))
|
|
|
|
|
|
|
|
System.out.println("using hostname : " + hostname);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println("enter port (default = 6969): ");
|
|
|
|
if ((args.length != 3) && (args.length != 0)){
|
|
|
|
String port = scanner.nextLine();
|
|
|
|
System.out.println("usage : java tracker.Tracker or java trackerP2P.trackerP2P -- <hostname> <PORT> (default localhost:6969, range 6000 -> 6999)");
|
|
|
|
if(port.equals("")){
|
|
|
|
|
|
|
|
port = defaultPort;
|
|
|
|
|
|
|
|
System.out.println("using default port : " + port);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
System.out.println("using port : " + port);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(testPortTracker.testPortTracker(Integer.parseInt(port))){
|
|
|
|
|
|
|
|
t = new Tracker(port);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
System.out.println("Wrong port (6000 -> 6999), using default port 6969");
|
|
|
|
|
|
|
|
t = new Tracker(defaultPort);
|
|
|
|
|
|
|
|
t.logger.write("Wrong port (6000 -> 6999), using default port 6969", LogLevel.Warning);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
if(args.length == 3){
|
|
|
|
|
|
|
|
hostname = args[1];
|
|
|
|
|
|
|
|
port = args[2];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else{
|
|
|
|
|
|
|
|
System.out.println("Tracker Server, enter hostname to bind (default = localhost): ");
|
|
|
|
|
|
|
|
hostname = scanner.nextLine();
|
|
|
|
|
|
|
|
if(hostname.equals("")){
|
|
|
|
|
|
|
|
hostname = defaultHostname;
|
|
|
|
|
|
|
|
System.out.println("using default hostname : " + hostname);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
System.out.println("enter port (default = 6969): ");
|
|
|
|
|
|
|
|
port = scanner.nextLine();
|
|
|
|
|
|
|
|
if(port.equals("")){
|
|
|
|
|
|
|
|
port = defaultPort;
|
|
|
|
|
|
|
|
System.out.println("using default port : " + port);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TrackerManagementUDP tmudp = new TrackerManagementUDP(hostname, t.port, t.logger);
|
|
|
|
System.out.println("using hostname : " + hostname);
|
|
|
|
TrackerManagementTCP tmtcp = new TrackerManagementTCP(hostname, t.port, t.logger);
|
|
|
|
if(testPortTracker.testPortTracker(Integer.parseInt(port))){
|
|
|
|
Thread tudp = new Thread(tmudp);
|
|
|
|
System.out.println("using port : " + port);
|
|
|
|
tudp.setName("Tracker UDP P2P-JAVA-PROJECT");
|
|
|
|
t = new Tracker(port);
|
|
|
|
tudp.start();
|
|
|
|
}
|
|
|
|
Thread ttcp = new Thread(tmtcp);
|
|
|
|
else {
|
|
|
|
ttcp.setName("Tracker TCP P2P-JAVA-PROJECT");
|
|
|
|
System.out.println("Wrong port (6000 -> 6999), using default port 6969");
|
|
|
|
ttcp.start();
|
|
|
|
t = new Tracker(defaultPort);
|
|
|
|
|
|
|
|
t.logger.write("Wrong port (6000 -> 6999), using default port 6969", LogLevel.Warning);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TrackerManagementUDP tmudp = new TrackerManagementUDP(hostname, t.port, t.logger);
|
|
|
|
|
|
|
|
TrackerManagementTCP tmtcp = new TrackerManagementTCP(hostname, t.port, t.logger);
|
|
|
|
|
|
|
|
Thread tudp = new Thread(tmudp);
|
|
|
|
|
|
|
|
tudp.setName("Tracker UDP P2P-JAVA-PROJECT");
|
|
|
|
|
|
|
|
tudp.start();
|
|
|
|
|
|
|
|
Thread ttcp = new Thread(tmtcp);
|
|
|
|
|
|
|
|
ttcp.setName("Tracker TCP P2P-JAVA-PROJECT");
|
|
|
|
|
|
|
|
ttcp.start();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|