-
Notifications
You must be signed in to change notification settings - Fork 7
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
Contact Information #20
base: master
Are you sure you want to change the base?
Changes from 6 commits
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,13 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7"> | ||
<output url="file://$MODULE_DIR$/target/classes" /> | ||
<output-test url="file://$MODULE_DIR$/target/test-classes" /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> | ||
<excludeFolder url="file://$MODULE_DIR$/target" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.6.2" level="project" /> | ||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:3.8.1" level="project" /> | ||
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.6.2" level="project" /> | ||
</component> | ||
</module> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,17 +9,28 @@ | |
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.io.*; | ||
import java.text.DateFormat; | ||
import java.text.SimpleDateFormat; | ||
import java.util.*; | ||
|
||
|
||
/** | ||
* The Discoverer module : Find Peers in communication ranges | ||
*/ | ||
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; | ||
File file; /* File attribute added */ | ||
final Thread[] thread = new Thread[3]; | ||
final BroadcastThread broadcastThread; | ||
final ListenThread listenThread; | ||
|
@@ -31,11 +42,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) { | ||
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.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 | ||
|
@@ -58,6 +84,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(){ | ||
|
@@ -113,7 +140,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(); | ||
|
@@ -287,6 +330,26 @@ public void run() { | |
if(willUpdatePeer) { | ||
String peerID = new String(datagramPacket.getData(), 0, datagramPacket.getLength()); | ||
updatePeers(datagramPacket.getAddress().getHostAddress(), peerID); | ||
/////////Added code | ||
|
||
|
||
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss"); | ||
Calendar cal = Calendar.getInstance(); | ||
String timeStamp = dateFormat.format(cal.getTime()); | ||
mp.put(peerID, timeStamp); | ||
FileWriter fileWriter = new FileWriter(file.getAbsoluteFile(), true); | ||
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); | ||
PrintWriter printWriter = new PrintWriter(bufferedWriter); | ||
PrintWriter writer = new PrintWriter(file); | ||
writer.print(""); | ||
writer.close(); | ||
for(Map.Entry m:mp.entrySet()) | ||
{ | ||
//System.out.println(m.getKey()+" "+m.getValue()); | ||
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. Dont commit commented codes |
||
printWriter.println(m.getKey()+" "+m.getValue()); | ||
} | ||
printWriter.close(); | ||
//////////// | ||
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 unnecessary comments |
||
} | ||
} // end of while | ||
}catch (UnknownHostException e){ | ||
|
@@ -382,4 +445,5 @@ public void stop() { | |
} | ||
|
||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
import java.text.SimpleDateFormat; | ||
import java.util.Calendar; | ||
|
||
|
||
public class SyncService { | ||
|
||
private static final String BROADCAST_IP = "172.16.5.255"; | ||
|
@@ -17,69 +18,82 @@ 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 contactName ="contactHistoryFile.txt"; | ||
|
||
|
||
public Logger logger; | ||
public WebServer webServer; | ||
public Discoverer discoverer; | ||
public FileManager fileManager; | ||
public FileTransporter fileTransporter; | ||
public Controller controller; | ||
|
||
|
||
public SyncService() throws IOException { | ||
|
||
public SyncService() { | ||
//System.exit(0); | ||
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); | ||
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); | ||
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 |
||
|
||
} | ||
|
||
|
||
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; | ||
|
||
//System.exit(0); | ||
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); | ||
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); | ||
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 |
||
} | ||
|
||
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" + "/"; | ||
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? 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 '/'). 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. 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. 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; | ||
|
||
//System.exit(0); | ||
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); | ||
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); | ||
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 |
||
} | ||
|
||
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); | ||
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; | ||
|
||
logger = new Logger(databaseAndLogDirectory, PEER_ID); | ||
discoverer = new Discoverer(BROADCAST_IP, PEER_ID, PORT, logger); | ||
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); | ||
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 |
||
|
||
} | ||
|
||
|
||
|
||
public void start(){ | ||
public void start() throws FileNotFoundException { | ||
|
||
|
||
|
||
discoverer.startDiscoverer(); | ||
fileManager.startFileManager(); | ||
controller.startController(); | ||
|
@@ -97,7 +111,7 @@ public void stop() { | |
webServer.stop(); | ||
} | ||
|
||
public static void main(final String[] args) { | ||
public static void main(final String[] args) throws IOException { | ||
System.out.println(args.length); | ||
if(args.length < 2){ | ||
SyncService s = new SyncService(); | ||
|
@@ -147,6 +161,8 @@ public void uncaughtException(Thread t, Throwable e) { | |
} | ||
} | ||
}); | ||
|
||
|
||
} | ||
|
||
} |
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.
Remove unnecessary comments