|
|
|
@ -7,7 +7,6 @@ import tools.Directories;
|
|
|
|
|
import tools.Logger;
|
|
|
|
|
import tools.LogLevel;
|
|
|
|
|
import tools.TestPort;
|
|
|
|
|
import tools.TestLegitIP;
|
|
|
|
|
|
|
|
|
|
/** Tracker implementation
|
|
|
|
|
* 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 defaultHostname = "localhost";
|
|
|
|
|
Scanner scanner = new Scanner(System.in);
|
|
|
|
|
TestLegitIP testLegitIP = new TestLegitIP();
|
|
|
|
|
TestPort testPortTracker = new TestPort();
|
|
|
|
|
String hostname;
|
|
|
|
|
String port;
|
|
|
|
|
Tracker t;
|
|
|
|
|
|
|
|
|
|
do{
|
|
|
|
|
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("args.lenght : " + args.length);
|
|
|
|
|
|
|
|
|
|
System.out.println("enter port (default = 6969): ");
|
|
|
|
|
String port = scanner.nextLine();
|
|
|
|
|
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);
|
|
|
|
|
if ((args.length != 3) && (args.length != 0)){
|
|
|
|
|
System.out.println("usage : java tracker.Tracker or java trackerP2P.trackerP2P -- <hostname> <PORT> (default localhost:6969, range 6000 -> 6999)");
|
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
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();
|
|
|
|
|
System.out.println("using hostname : " + hostname);
|
|
|
|
|
if(testPortTracker.testPortTracker(Integer.parseInt(port))){
|
|
|
|
|
System.out.println("using port : " + 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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|