|
|
|
@ -20,18 +20,22 @@ public class Tracker {
|
|
|
|
|
private HostItem tracker;
|
|
|
|
|
private Directories directories;
|
|
|
|
|
private Logger logger;
|
|
|
|
|
private boolean isinteractive;
|
|
|
|
|
|
|
|
|
|
/** Constructor with portStr containing a port number.
|
|
|
|
|
* @param hostname hostname to bind
|
|
|
|
|
* @param port port to bind
|
|
|
|
|
*/
|
|
|
|
|
public Tracker(String hostname, int port) {
|
|
|
|
|
public Tracker(String hostname, int port, boolean isinteractive) {
|
|
|
|
|
this.isinteractive = isinteractive;
|
|
|
|
|
tracker = new HostItem(hostname, port);
|
|
|
|
|
directories = new Directories("P2P_JAVA_PROJECT_TRACKER_" + port);
|
|
|
|
|
logger = new Logger(directories.getDataHomeDirectory() + "tracker.log");
|
|
|
|
|
System.out.println("Tracker will listen on port " + port + " and write logs into " + directories.getDataHomeDirectory());
|
|
|
|
|
Scanner scanner = new Scanner(System.in);
|
|
|
|
|
directories.askOpenDataHomeDirectory(null, scanner);
|
|
|
|
|
if(isinteractive){
|
|
|
|
|
directories.askOpenDataHomeDirectory(null, scanner);
|
|
|
|
|
}
|
|
|
|
|
scanner.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -47,6 +51,7 @@ public class Tracker {
|
|
|
|
|
String hostname = "";
|
|
|
|
|
int port = 0;
|
|
|
|
|
Tracker t;
|
|
|
|
|
boolean isinteractive = false;
|
|
|
|
|
|
|
|
|
|
if ((args.length != 3) && (args.length != 0)){
|
|
|
|
|
System.out.println("usage : java tracker.Tracker (interactive) or java trackerP2P.trackerP2P -- <hostname> <PORT> (" + trackerPortRange +")");
|
|
|
|
@ -55,6 +60,7 @@ public class Tracker {
|
|
|
|
|
hostname = args[1];
|
|
|
|
|
port = Integer.valueOf(Integer.parseInt(args[2]));
|
|
|
|
|
} else {
|
|
|
|
|
isinteractive = true;
|
|
|
|
|
System.out.println("Tracker Server, enter hostname to bind (default = localhost): ");
|
|
|
|
|
hostname = scanner.nextLine();
|
|
|
|
|
if(hostname.equals("")){
|
|
|
|
@ -74,7 +80,7 @@ public class Tracker {
|
|
|
|
|
System.out.println("using hostname : " + hostname);
|
|
|
|
|
if(trackerPortRange.isPortInRange(port)) {
|
|
|
|
|
System.out.println("using port : " + port);
|
|
|
|
|
t = new Tracker(hostname, port);
|
|
|
|
|
t = new Tracker(hostname, port, isinteractive);
|
|
|
|
|
TrackerManagementUDP tmudp = new TrackerManagementUDP(t.tracker, t.logger);
|
|
|
|
|
TrackerManagementTCP tmtcp = new TrackerManagementTCP(t.tracker, t.logger);
|
|
|
|
|
Thread tudp = new Thread(tmudp);
|
|
|
|
|