-
Notifications
You must be signed in to change notification settings - Fork 7
Contact Information #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
08e9bfb
5c3622e
7740ea9
08ab4ff
a78a074
83b9d1e
8f11c64
c6ae90d
c34b1c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| package bishakh.psync; | ||
|
|
||
| import javax.swing.plaf.basic.BasicInternalFrameTitlePane; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why this? |
||
| import java.io.IOException; | ||
| import java.net.DatagramPacket; | ||
| import java.net.DatagramSocket; | ||
|
|
@@ -25,6 +26,10 @@ public class Discoverer { | |
| HashMap<String,String>mp = new HashMap<>(); /* Store contact information */ | ||
|
|
||
| String BROADCAST_IP; | ||
| final String DATABASE_NAME; | ||
| final String DATABASE_PATH; | ||
|
|
||
|
|
||
| int PORT; | ||
| String PEER_ID; | ||
| Logger logger; | ||
|
|
@@ -40,12 +45,26 @@ public class Discoverer { | |
| public volatile ConcurrentHashMap<String, ArrayList<String>> priorityPeerList; | ||
| public volatile ConcurrentHashMap<String, ArrayList<String>> originalPeerList; | ||
|
|
||
| public Discoverer(String BROADCAST_IP, String PEER_ID, int PORT, Logger LoggerObj,File ffile) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fileName? what file name. use a better variable name please. |
||
| public Discoverer(String BROADCAST_IP, String PEER_ID, int PORT, Logger LoggerObj,String fileName,String databaseDirectory ) throws IOException { | ||
| this.BROADCAST_IP = BROADCAST_IP; | ||
| this.PORT = PORT; | ||
| this.PEER_ID = PEER_ID; | ||
| this.logger = LoggerObj; | ||
| this.file = ffile; /*file is assigned*/ | ||
| this.DATABASE_NAME = fileName; | ||
| this.DATABASE_PATH = databaseDirectory+DATABASE_NAME; | ||
| this.file = new File(DATABASE_PATH); | ||
|
|
||
| if(file.exists()) | ||
| { | ||
| System.out.println("File exists"); | ||
| } | ||
| else | ||
| { | ||
| System.out.println("File not there"); | ||
| file.createNewFile(); | ||
| System.out.println("File is created"); | ||
| } | ||
|
|
||
|
|
||
| // Initialize priorities (lower int = higher priority) | ||
| // The peers whose ID starts with these keywords will have the priority | ||
|
|
@@ -68,6 +87,7 @@ public Discoverer(String BROADCAST_IP, String PEER_ID, int PORT, Logger LoggerOb | |
| thread[0] = new Thread(broadcastThread); | ||
| thread[1] = new Thread(listenThread); | ||
| thread[2] = new Thread(peerExpiryThread); | ||
|
|
||
| } | ||
|
|
||
| public void startBroadcast(){ | ||
|
|
@@ -123,7 +143,23 @@ public void stopPeerExpiry() { | |
| } | ||
| } | ||
|
|
||
| public void startDiscoverer(){ | ||
| public void startDiscoverer() throws FileNotFoundException { | ||
| FileReader fileReader = new FileReader(file); | ||
| BufferedReader bufferedReader = new BufferedReader(fileReader); | ||
| try { | ||
| String line =bufferedReader.readLine(); | ||
| while(line!=null) | ||
| { | ||
| String[] one=line.split(" ",100); /// here length of PEER_ID is restricted | ||
| mp.put(one[0],one[1]); | ||
| line=bufferedReader.readLine(); | ||
| } | ||
| } catch (IOException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| PrintWriter writer = new PrintWriter(file); | ||
| writer.print(""); | ||
| writer.close(); | ||
| startBroadcast(); | ||
| startListener(); | ||
| startPeerExpiry(); | ||
|
|
@@ -412,4 +448,5 @@ public void stop() { | |
| } | ||
|
|
||
|
|
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,7 +33,7 @@ public void downloadFile(String fileID, String fileName, String filePath, String | |
| if(!parent.exists() && !parent.mkdirs()){ | ||
| throw new IllegalStateException("Couldn't create dir: " + parent); | ||
| } | ||
| URL fileUrl = new URL("http://"+ peerIP +":8080/getFile/" + fileID); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here. port. |
||
| URL fileUrl = new URL("http://"+ peerIP +":5345/getFile/" + fileID); | ||
| ResumeDownloadThread resumeDownloadThread = new ResumeDownloadThread(fileUrl , fileID, fileName, f, startByte, endByte, fileSize, peerID); | ||
| Thread t = new Thread(resumeDownloadThread); | ||
| ongoingDownloadThreads.put(t, resumeDownloadThread); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,69 +18,73 @@ public class SyncService { | |
| private static String mapFileServerDirectory = "/home/alarm/DMS/"; | ||
| private static String databaseAndLogDirectory = "/home/alarm/DMS/"; | ||
| private static String databaseName = "fileDB.txt"; | ||
| private static String contactFile = "contact.txt"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. contactFileName or contactHistoryFileName more descriptive name = better |
||
| private static String contactName ="contact.txt"; | ||
|
|
||
|
|
||
| public Logger logger; | ||
| public WebServer webServer; | ||
| public Discoverer discoverer; | ||
| public FileManager fileManager; | ||
| public FileTransporter fileTransporter; | ||
| public Controller controller; | ||
| public File nfile; | ||
|
|
||
|
|
||
| public SyncService() throws IOException { | ||
|
|
||
| public SyncService() { | ||
| File nfile =new File(contactFile); | ||
| //System.exit(0); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same. |
||
| logger = new Logger(databaseAndLogDirectory, PEER_ID); | ||
| discoverer = new Discoverer(BROADCAST_IP, PEER_ID, PORT, logger,nfile); | ||
| discoverer = new Discoverer(BROADCAST_IP, PEER_ID, PORT, logger,contactName,databaseAndLogDirectory); | ||
| fileManager = new FileManager(PEER_ID, databaseName, databaseAndLogDirectory, syncDirectory, mapFileServerDirectory, logger); | ||
| fileTransporter = new FileTransporter(syncDirectory, logger); | ||
| controller = new Controller(discoverer, fileManager, fileTransporter, syncInterval, maxRunningDownloads, logger, 2, true); | ||
| webServer = new WebServer(8080, controller, logger); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. port |
||
| webServer = new WebServer(5345, controller, logger); | ||
|
|
||
| } | ||
|
|
||
|
|
||
| public SyncService(String inputPeerId, String baseDirectory) { | ||
| syncDirectory = baseDirectory + File.separator + "sync" + File.separator; | ||
| public SyncService(String inputPeerId, String baseDirectory) throws IOException { | ||
| syncDirectory = baseDirectory + "sync" + "/"; | ||
| mapFileServerDirectory = baseDirectory; | ||
| databaseAndLogDirectory = baseDirectory; | ||
| PEER_ID = inputPeerId; | ||
| File nfile =new File(contactFile); | ||
|
|
||
| //System.exit(0); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same |
||
| logger = new Logger(databaseAndLogDirectory, PEER_ID); | ||
| discoverer = new Discoverer(BROADCAST_IP, PEER_ID, PORT, logger,nfile); | ||
| discoverer = new Discoverer(BROADCAST_IP, PEER_ID, PORT, logger,contactName,databaseAndLogDirectory); | ||
| fileManager = new FileManager(PEER_ID, databaseName, databaseAndLogDirectory, syncDirectory, mapFileServerDirectory, logger); | ||
| fileTransporter = new FileTransporter(syncDirectory, logger); | ||
| controller = new Controller(discoverer, fileManager, fileTransporter, syncInterval, maxRunningDownloads, logger, 2, true); | ||
| webServer = new WebServer(8080, controller, logger); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. port |
||
| webServer = new WebServer(5345, controller, logger); | ||
| } | ||
|
|
||
| public SyncService(String inputPeerId, String baseDirectory, int priorityMethod) { | ||
| syncDirectory = baseDirectory + File.separator + "sync" + File.separator; | ||
| public SyncService(String inputPeerId, String baseDirectory, int priorityMethod) throws IOException { | ||
| syncDirectory = baseDirectory +"sync" + "/"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? why this?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suppose my baseDirectory is provided as "C:/Users/Desktop/WorkingDirectory/" (with a trailing '/').
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay then I am replacing last '/' with File.separator |
||
| mapFileServerDirectory = baseDirectory; | ||
| databaseAndLogDirectory = baseDirectory; | ||
| PEER_ID = inputPeerId; | ||
|
|
||
| File nfile =new File(contactFile); | ||
| //System.exit(0); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove commented codes. |
||
| logger = new Logger(databaseAndLogDirectory, PEER_ID); | ||
| discoverer = new Discoverer(BROADCAST_IP, PEER_ID, PORT, logger,nfile); | ||
| discoverer = new Discoverer(BROADCAST_IP, PEER_ID, PORT, logger,contactName,databaseAndLogDirectory); | ||
| fileManager = new FileManager(PEER_ID, databaseName, databaseAndLogDirectory, syncDirectory, mapFileServerDirectory, logger); | ||
| fileTransporter = new FileTransporter(syncDirectory, logger); | ||
| controller = new Controller(discoverer, fileManager, fileTransporter, syncInterval, maxRunningDownloads, logger, priorityMethod, true); | ||
| webServer = new WebServer(8080, controller, logger); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. port |
||
| webServer = new WebServer(5345, controller, logger); | ||
| } | ||
|
|
||
| public SyncService(String inputPeerId, String baseDirectory, int priorityMethod, boolean restrictedEpidemicFlag) { | ||
| syncDirectory = baseDirectory + File.separator + "sync" + File.separator; | ||
| public SyncService(String inputPeerId, String baseDirectory, int priorityMethod, boolean restrictedEpidemicFlag) throws IOException { | ||
|
|
||
| //System.exit(0); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same |
||
| syncDirectory = baseDirectory + "sync" + "/"; | ||
| mapFileServerDirectory = baseDirectory; | ||
| databaseAndLogDirectory = baseDirectory; | ||
| PEER_ID = inputPeerId; | ||
| File nfile =new File(contactFile); | ||
| logger = new Logger(databaseAndLogDirectory, PEER_ID); | ||
| discoverer = new Discoverer(BROADCAST_IP, PEER_ID, PORT, logger,nfile); | ||
| discoverer = new Discoverer(BROADCAST_IP, PEER_ID, PORT, logger,contactName,databaseAndLogDirectory); | ||
| fileManager = new FileManager(PEER_ID, databaseName, databaseAndLogDirectory, syncDirectory, mapFileServerDirectory, logger); | ||
| fileTransporter = new FileTransporter(syncDirectory, logger); | ||
| controller = new Controller(discoverer, fileManager, fileTransporter, syncInterval, maxRunningDownloads, logger, priorityMethod, restrictedEpidemicFlag); | ||
| webServer = new WebServer(8080, controller, logger); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. port |
||
| webServer = new WebServer(5345, controller, logger); | ||
|
|
||
| } | ||
|
|
||
|
|
@@ -89,22 +93,7 @@ public SyncService(String inputPeerId, String baseDirectory, int priorityMethod, | |
| public void start() throws FileNotFoundException { | ||
|
|
||
|
|
||
| FileReader fileReader = new FileReader(nfile); | ||
| BufferedReader bufferedReader = new BufferedReader(fileReader); | ||
| try { | ||
| String line =bufferedReader.readLine(); | ||
| while(line!=null) | ||
| { | ||
| String[] one=line.split(" ",100); /// here length of PEER_ID is restricted | ||
| discoverer.mp.put(one[0],one[1]); | ||
| line=bufferedReader.readLine(); | ||
| } | ||
| } catch (IOException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| PrintWriter writer = new PrintWriter(nfile); | ||
| writer.print(""); | ||
| writer.close(); | ||
|
|
||
| discoverer.startDiscoverer(); | ||
| fileManager.startFileManager(); | ||
| controller.startController(); | ||
|
|
@@ -122,7 +111,7 @@ public void stop() { | |
| webServer.stop(); | ||
| } | ||
|
|
||
| public static void main(final String[] args) throws FileNotFoundException { | ||
| public static void main(final String[] args) throws IOException { | ||
| System.out.println(args.length); | ||
| if(args.length < 2){ | ||
| SyncService s = new SyncService(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just change this port while testing. Do not commit this change.