From 5e70670cc51e5714f8411e88b8e41404413e550e Mon Sep 17 00:00:00 2001 From: flavien Date: Mon, 30 Mar 2020 15:47:23 +0200 Subject: [PATCH] tracker doesnt ask to open his home directory when arguments are passed --- src/tracker/Tracker.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/tracker/Tracker.java b/src/tracker/Tracker.java index 8b096a6..807a3d5 100644 --- a/src/tracker/Tracker.java +++ b/src/tracker/Tracker.java @@ -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 -- (" + 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);