From 0f414763849ac5435284db6ba412f8a57b298ee5 Mon Sep 17 00:00:00 2001 From: Wang Yuyang Date: Sat, 20 Nov 2021 16:36:07 +0800 Subject: [PATCH] comments --- src/main/java/com/echo/p2p_project/Util.java | 2 + .../echo/p2p_project/client/ClientMain.java | 54 ++++++++++++++++++- .../com/echo/p2p_project/client/Test.java | 1 + .../client/gui/ClientIndexController.java | 1 + .../client/gui/ClientIndexView.java | 1 + .../client/interfaces/P2P_FileRegistry.java | 1 + .../echo/p2p_project/server/ServerMain.java | 5 ++ .../server/interfaces/ConstructRegistry.java | 2 + .../server/interfaces/FileLookupRegistry.java | 3 +- .../server/interfaces/HeartBeatRegistry.java | 1 + .../interfaces/HelloRegistryFacade.java | 1 + .../server/model/ConstructImpl.java | 12 ++++- .../server/model/FileLookupImpl.java | 5 +- .../server/model/HeartBeatImpl.java | 2 + .../server/model/HelloRegistryFacadeImpl.java | 1 + .../p2p_project/server/model/WatchDog.java | 7 +++ .../com/echo/p2p_project/u_model/Peer.java | 3 +- .../echo/p2p_project/u_model/Resource.java | 1 + 18 files changed, 98 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/echo/p2p_project/Util.java b/src/main/java/com/echo/p2p_project/Util.java index 0d6123d..47adf8c 100644 --- a/src/main/java/com/echo/p2p_project/Util.java +++ b/src/main/java/com/echo/p2p_project/Util.java @@ -16,6 +16,7 @@ import java.security.NoSuchAlgorithmException; * @Description: **/ public class Util { + //A util of getting the ip address. public static String getIP() { try { InetAddress ip4 = Inet4Address.getLocalHost(); @@ -25,6 +26,7 @@ public class Util { return null; } } + //get hash using SHA-1 public static String createSha1(File file){ MessageDigest digest = null; try { diff --git a/src/main/java/com/echo/p2p_project/client/ClientMain.java b/src/main/java/com/echo/p2p_project/client/ClientMain.java index 49b3d79..20ffc7f 100644 --- a/src/main/java/com/echo/p2p_project/client/ClientMain.java +++ b/src/main/java/com/echo/p2p_project/client/ClientMain.java @@ -31,8 +31,11 @@ import java.util.*; * @Description: **/ public class ClientMain { + //The default main server address public static String MainServerIP = "127.0.0.1"; + //The default main server port public static int RMI_PORT = 1099; + //Information about this peer public static Peer peer; public static ObservableMapWrapper DHRT = new ObservableMapWrapper<>(new LinkedHashMap<>()); public static Integer retry_times = 0; @@ -52,6 +55,7 @@ public class ClientMain { public static void main(String[] args) throws ConnectException { + //service thread service = new Thread(new Runnable() { @Override public void run() { @@ -64,6 +68,8 @@ public class ClientMain { } catch (InterruptedException e) { e.printStackTrace(); } + + //Command line of the peer sc = new Scanner(System.in); System.out.println(""); System.out.print(">>> "); @@ -71,9 +77,11 @@ public class ClientMain { String line = sc.nextLine(); switch (line) { case "\n": + //Promote System.out.print(">>> "); break; case "i": + //print the information about his peer System.out.println("GUID: " + peer.getGUID()); System.out.println("P2P_Port: " + peer.getP2P_port()); System.out.println("Possessing: " + peer.getPossessing()); @@ -104,8 +112,11 @@ public class ClientMain { } public static void download(String hash) { + //download by hash + //first look up this res Resource resources = look_up_file(hash); if (resources != null) { + //found System.out.println("Download: " + resources.getGUID()); download(resources); } @@ -113,6 +124,7 @@ public class ClientMain { } private static void download(String hash, Integer retry_count) { + //retry download if (download_retry_count <= 5) { download_retry_count += 1; System.out.println("Retrying " + download_retry_count); @@ -135,20 +147,25 @@ public class ClientMain { Boolean file_status = false; hasStarted = false; try { + //Connect to the main server registry = LocateRegistry.getRegistry(MainServerIP, RMI_PORT); + //check if connection is successful center_status = lookup_registry() && register_peer() ? true : false; } catch (RemoteException e) { // e.printStackTrace(); } if (peer == null) { + //can't init peer, then server is not start. System.out.println("Server Not Running."); exit(); } + //start regular heart beat to make sure the peer is alive CHeartBeat.StartHeart(heartBeatRegistry, peer.getGUID()); //Init file services try { + //init local server file_service = LocateRegistry.createRegistry(Port); P2P_FileRegistry p2PFileRegistry = new P2PFileImpl(); file_service.rebind("p2PFileRegistry", p2PFileRegistry); @@ -173,8 +190,10 @@ public class ClientMain { private static Boolean register_peer() { System.out.println("+++++++ Register & Construct Peer +++++++"); + //get one available port Port = NetUtil.getUsableLocalPort(35000, 45000); try { + //get peer information from server peer = constructRegistry.ConstructPeer(name, IP, Port); System.out.println("+++++++ Peer Construct Success ! +++++++"); System.out.println("Peer GUID: " + peer.getGUID()); @@ -182,6 +201,7 @@ public class ClientMain { System.out.println("+++++++ Register Finished +++++++"); return true; } catch (RemoteException e) { + //server connect failed hasStarted = false; System.out.println("register_peer RemoteException"); e.printStackTrace(); @@ -191,6 +211,7 @@ public class ClientMain { private static Boolean lookup_registry() { try { + //check if server is responding. HelloRegistryFacade hello = (HelloRegistryFacade) registry.lookup("HelloRegistry"); String response = hello.helloWorld(name); System.out.println("=======> " + response + " <======="); @@ -198,6 +219,7 @@ public class ClientMain { System.out.println("server failed"); return false; } + // get the server functions constructRegistry = (ConstructRegistry) registry.lookup("constructRegistry"); heartBeatRegistry = (HeartBeatRegistry) registry.lookup("heatBeatRegistry"); fileLookupRegistry = (FileLookupRegistry) registry.lookup("syncingRegistry"); @@ -212,6 +234,7 @@ public class ClientMain { } public static Boolean reg_file(String name) { + //register a file File file = new File("res/" + name); if (!file.exists()) { System.out.println("File not exists !"); @@ -221,14 +244,18 @@ public class ClientMain { System.out.println("File ok."); System.out.println("File length: " + file.length()); } + //get file hash String hash = Util.createSha1(file); System.out.println(hash); try { + //send the information about the file to the server Resource resource = constructRegistry.ConstructResource(peer.getGUID(), name, hash); + //save it to local DHRT ClientMain.DHRT.put(resource.getGUID(), resource); - DHRT.put(resource.getGUID(), resource); +// DHRT.put(resource.getGUID(), resource); System.out.println("File Register Success!"); System.out.println("Resource GUID: " + resource.getGUID()); + //update possessing list sync_peer(); } catch (RemoteException e) { e.printStackTrace(); @@ -239,6 +266,7 @@ public class ClientMain { } private static void sync_peer() { + //update possessing list try { peer = fileLookupRegistry.syncPeer(peer.getGUID()); } catch (RemoteException e) { @@ -249,36 +277,48 @@ public class ClientMain { } public static Resource look_up_file(String hash) { + //look up a file using hash System.out.println("Looking HASH for: " + hash); + //try to get from local DHRT Resource res = ClientMain.DHRT.get(hash); if (res == null) { + //not found in local System.out.println("Not found in local DHRT"); System.out.println("Lookup in UHRT..."); try { + //let server find this file res = fileLookupRegistry.lookupInUHRT(hash); } catch (RemoteException e) { e.printStackTrace(); } if (res == null) { + //not in server UHRT System.out.println("Not found in UHRT"); System.out.println("Abort"); return null; } + //found the file in server UHRT System.out.println("Found in UHRT: " + res.getGUID()); System.out.println("Update DHRT"); ClientMain.DHRT.put(res.getGUID(), res); } else{ + //found in local System.out.println("Found in DHRT."); } return res; } public static void download(Resource resources) { + //download by resources if (resources == null || resources.possessedBy.size() == 0) { + //resource is invalid System.out.println("Resource can not be download !"); return; } + //if processed by more than one peer(DHRT), then do sort. + //Although server has give the best peer, but since the DHRT is not always up-to-date + //so make sure is the best peer. ArrayList processed_peers = new ArrayList<>(); for (Peer p : resources.possessedBy.values()) { processed_peers.add(p); @@ -291,19 +331,23 @@ public class ClientMain { }); Peer best_peer = processed_peers.get(0); System.out.println("Best peer is: " + best_peer.getGUID()); + //go download with the best peer P2P_download(best_peer, resources); } public static void P2P_download(Peer p, Resource resource) { + //download in a new thread new Thread(new Runnable() { @Override public void run() { + //start download timing long start_time = System.currentTimeMillis(); Integer port = p.getP2P_port(); String IP = p.getIP(); Registry p2pRegistry = null; File file = null; try { + //get target peer connection p2pRegistry = LocateRegistry.getRegistry(IP, port); System.out.println("Try to connect: " + p.getGUID()); P2P_FileRegistry p2PFileRegistry = (P2P_FileRegistry) p2pRegistry.lookup("p2PFileRegistry"); @@ -311,13 +355,16 @@ public class ClientMain { System.out.println("Downloading FROM: " + p.getGUID()); byte[] file_byte = p2PFileRegistry.download(resource.getGUID()); System.out.println("File byte[] length: " + file_byte.length); + //end download timing long end_time = System.currentTimeMillis(); long start_writing_time = System.currentTimeMillis(); + //write to file file = FileUtil.writeBytes(file_byte, new File("download/" + peer.getGUID() + "_FROM_" + p.getGUID() + "_" + resource.getName())); long end_writing_time = System.currentTimeMillis(); System.out.println("File downloaded !"); System.out.println("File length : " + file.length()); + //display the result regarding the file size. float file_size_B = file.length(); float file_size_KB = file.length() / 1024; float file_size_MB = file_size_KB / 1024; @@ -347,9 +394,11 @@ public class ClientMain { } } catch (RemoteException e) { + //download failed. System.out.println("RemoteException"); DHRT.clear(); try { + //do re-lookup Resource res = fileLookupRegistry.lookupInUHRT(resource.getGUID()); if (res != null) DHRT.put(res.getGUID(), res); @@ -368,6 +417,7 @@ public class ClientMain { public static void P2P_download(Peer p, Resource resource, Runnable runnable) { + //same as the upper function, but with a customizable runnable after the file downloaded new Thread(new Runnable() { @Override public void run() { @@ -496,6 +546,7 @@ public class ClientMain { } public static void recover(int retry_count) { + //self-recovery retry_count += 1; System.out.println("Try to recover......." + retry_count); if (retry_count > 10) { @@ -512,6 +563,7 @@ public class ClientMain { @Override public void run() { try { + //wait 1s then try again. Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); diff --git a/src/main/java/com/echo/p2p_project/client/Test.java b/src/main/java/com/echo/p2p_project/client/Test.java index 1dafd29..f37c7b4 100644 --- a/src/main/java/com/echo/p2p_project/client/Test.java +++ b/src/main/java/com/echo/p2p_project/client/Test.java @@ -11,6 +11,7 @@ import java.rmi.ConnectException; **/ public class Test { public static void main(String[] args) { + //Limit testing for(int i = 0; i < 5000; i++){ try { Thread.sleep(10); diff --git a/src/main/java/com/echo/p2p_project/client/gui/ClientIndexController.java b/src/main/java/com/echo/p2p_project/client/gui/ClientIndexController.java index 85a01c9..14d51f6 100644 --- a/src/main/java/com/echo/p2p_project/client/gui/ClientIndexController.java +++ b/src/main/java/com/echo/p2p_project/client/gui/ClientIndexController.java @@ -51,6 +51,7 @@ public class ClientIndexController { public Button lookup_button; public void initialize() { + //Init GUI Controller ObservableList local_file_list = new ObservableListWrapper<>(Collections.synchronizedList(new ArrayList<>())); ObservableList remote_file_list = new ObservableListWrapper<>(Collections.synchronizedList(new ArrayList<>())); ClientMain.DHRT.addListener(new MapChangeListener() { diff --git a/src/main/java/com/echo/p2p_project/client/gui/ClientIndexView.java b/src/main/java/com/echo/p2p_project/client/gui/ClientIndexView.java index 6dbdb5c..ad5f355 100644 --- a/src/main/java/com/echo/p2p_project/client/gui/ClientIndexView.java +++ b/src/main/java/com/echo/p2p_project/client/gui/ClientIndexView.java @@ -21,6 +21,7 @@ import java.io.IOException; public class ClientIndexView extends Application { @Override public void start(Stage stage) throws IOException { + //GUI main view FXMLLoader fxmlLoader = new FXMLLoader(ResourceUtil.getResource("gui/client_index.fxml")); Scene scene = new Scene(fxmlLoader.load()); stage.setTitle("Client!"); diff --git a/src/main/java/com/echo/p2p_project/client/interfaces/P2P_FileRegistry.java b/src/main/java/com/echo/p2p_project/client/interfaces/P2P_FileRegistry.java index a59821e..347a651 100644 --- a/src/main/java/com/echo/p2p_project/client/interfaces/P2P_FileRegistry.java +++ b/src/main/java/com/echo/p2p_project/client/interfaces/P2P_FileRegistry.java @@ -13,5 +13,6 @@ import java.util.UUID; * @Description: **/ public interface P2P_FileRegistry extends Remote { + //Proved the services of letting other peer download from this peer. byte[] download(String resID) throws RemoteException; } diff --git a/src/main/java/com/echo/p2p_project/server/ServerMain.java b/src/main/java/com/echo/p2p_project/server/ServerMain.java index 6a0bccb..79b956e 100644 --- a/src/main/java/com/echo/p2p_project/server/ServerMain.java +++ b/src/main/java/com/echo/p2p_project/server/ServerMain.java @@ -30,6 +30,7 @@ public class ServerMain{ private static Thread service; public static void main(String[] args) { + //start service service = new Thread(new Runnable() { @Override public void run() { @@ -37,6 +38,7 @@ public class ServerMain{ } }); service.start(); + //start command line promote Scanner sc = new Scanner(System.in); System.out.println(""); System.out.print(">>> "); @@ -47,6 +49,7 @@ public class ServerMain{ System.out.print(">>> "); break; case "i": + //get information about the server System.out.println("UHPT: " + UHPT); System.out.println("UHPT Size: " + UHPT.size()); System.out.println("UHRT: " + UHRT); @@ -73,6 +76,7 @@ public class ServerMain{ System.out.println("Registered: " + s); } System.out.println("============ WatchDog ============"); + //start watch dog. if (!HasStarted) WatchDog.startWatchDog(); System.out.println("======= Start Up Finished ========"); @@ -85,6 +89,7 @@ public class ServerMain{ private static void reg_services() { try { + //Register all the services. HelloRegistryFacade hello = new HelloRegistryFacadeImpl(); ConstructRegistry constructRegistry = new ConstructImpl(); HeartBeatRegistry heartBeatRegistry = new HeartBeatImpl(); diff --git a/src/main/java/com/echo/p2p_project/server/interfaces/ConstructRegistry.java b/src/main/java/com/echo/p2p_project/server/interfaces/ConstructRegistry.java index 13ebd20..f93e8d3 100644 --- a/src/main/java/com/echo/p2p_project/server/interfaces/ConstructRegistry.java +++ b/src/main/java/com/echo/p2p_project/server/interfaces/ConstructRegistry.java @@ -15,6 +15,8 @@ import java.util.UUID; * @Description: **/ public interface ConstructRegistry extends Remote { + //saving the peer information and transfer back to the peer. Peer ConstructPeer(String name, String IP, Integer P2P_port) throws RemoteException; + //saving the resource information and transfer back to the peer. Resource ConstructResource(UUID PeerGUID, String name, String hash) throws RemoteException; } diff --git a/src/main/java/com/echo/p2p_project/server/interfaces/FileLookupRegistry.java b/src/main/java/com/echo/p2p_project/server/interfaces/FileLookupRegistry.java index 00dcf7a..63ef7b7 100644 --- a/src/main/java/com/echo/p2p_project/server/interfaces/FileLookupRegistry.java +++ b/src/main/java/com/echo/p2p_project/server/interfaces/FileLookupRegistry.java @@ -16,7 +16,8 @@ import java.util.UUID; * @Description: **/ public interface FileLookupRegistry extends Remote { + //update the peer's possessing list Peer syncPeer(UUID GUID) throws RemoteException; -// HashMap lookupInUHRT(String filename) throws RemoteException; + //lookup in server UHRT using the GUID(hash) Resource lookupInUHRT(String hash) throws RemoteException; } diff --git a/src/main/java/com/echo/p2p_project/server/interfaces/HeartBeatRegistry.java b/src/main/java/com/echo/p2p_project/server/interfaces/HeartBeatRegistry.java index 27381b9..2fb65b1 100644 --- a/src/main/java/com/echo/p2p_project/server/interfaces/HeartBeatRegistry.java +++ b/src/main/java/com/echo/p2p_project/server/interfaces/HeartBeatRegistry.java @@ -12,5 +12,6 @@ import java.util.UUID; * @Description: **/ public interface HeartBeatRegistry extends Remote { + //make sure the peer is alive Boolean heartBeat(UUID GUID) throws RemoteException; } diff --git a/src/main/java/com/echo/p2p_project/server/interfaces/HelloRegistryFacade.java b/src/main/java/com/echo/p2p_project/server/interfaces/HelloRegistryFacade.java index c6e151b..60faedc 100644 --- a/src/main/java/com/echo/p2p_project/server/interfaces/HelloRegistryFacade.java +++ b/src/main/java/com/echo/p2p_project/server/interfaces/HelloRegistryFacade.java @@ -11,5 +11,6 @@ import java.rmi.RemoteException; * @Description: **/ public interface HelloRegistryFacade extends Remote { + //a test for checking if the server is responding String helloWorld(String name) throws RemoteException; } diff --git a/src/main/java/com/echo/p2p_project/server/model/ConstructImpl.java b/src/main/java/com/echo/p2p_project/server/model/ConstructImpl.java index e5e1edc..71dc030 100644 --- a/src/main/java/com/echo/p2p_project/server/model/ConstructImpl.java +++ b/src/main/java/com/echo/p2p_project/server/model/ConstructImpl.java @@ -36,23 +36,28 @@ public class ConstructImpl extends UnicastRemoteObject implements ConstructRegis @Override public Peer ConstructPeer(String name, String IP_Address, Integer P2P_port) throws RemoteException { + //get a random UUID UUID GUID = UUID.randomUUID(); if(ServerMain.UHPT.containsKey(GUID)) { + //Really Rarely happen, Peer reg failed. System.out.println("DUP GUID!!!!!!!"); return null; } + //information String peerName = name; String IP = IP_Address; Integer port = P2P_port; Random random = new Random(); Integer routingMetric = random.nextInt(100); Peer peer = new Peer(GUID, peerName, IP, port, routingMetric); + //put in to UHPT ServerMain.UHPT.put(peer.getGUID(), peer); System.out.println("Peer Reg: " + peer); return peer; } @Override public Resource ConstructResource(UUID PeerGUID, String name, String hash) throws RemoteException { + //get Peer from UHPT to insure the integrity Peer peer = ServerMain.UHPT.get(PeerGUID); //If peer not registered in center @@ -61,18 +66,23 @@ public class ConstructImpl extends UnicastRemoteObject implements ConstructRegis //If duplicated GUID if(ServerMain.UHRT.containsKey(hash)) { - // Res is in UHRT + // Res is in UHRT, so DUP GUID System.out.println("DUP GUID! Res is in UHRT"); Resource res = ServerMain.UHRT.get(hash); + //add to possessedBy res.possessedBy.put(peer.getGUID(), peer); + //add to possessing ServerMain.UHPT.get(peer.getGUID()).possessing.put(res.getGUID(), res); return res; } String ResName = name; + //not in UHRT, create a new one Resource res = new Resource(hash, ResName, hash); + //add to possessedBy res.possessedBy.put(peer.getGUID(), peer); ServerMain.UHRT.put(res.getGUID(), res); + //add to possessing ServerMain.UHPT.get(peer.getGUID()).possessing.put(res.getGUID(), res); System.out.println("Resources Registered: " + res); return res; diff --git a/src/main/java/com/echo/p2p_project/server/model/FileLookupImpl.java b/src/main/java/com/echo/p2p_project/server/model/FileLookupImpl.java index 9a30e24..948050f 100644 --- a/src/main/java/com/echo/p2p_project/server/model/FileLookupImpl.java +++ b/src/main/java/com/echo/p2p_project/server/model/FileLookupImpl.java @@ -42,11 +42,13 @@ public class FileLookupImpl extends UnicastRemoteObject implements FileLookupReg @Override public Resource lookupInUHRT(String hash) throws RemoteException { - + //try to find the resource. Resource res = ServerMain.UHRT.get(hash); if(res==null){ + //not found return null; } + //find the best peer. ArrayList processed_peers = new ArrayList<>(); for (Peer p : res.possessedBy.values()) { processed_peers.add(p); @@ -62,6 +64,7 @@ public class FileLookupImpl extends UnicastRemoteObject implements FileLookupReg System.out.println(peer.getGUID() + " <> " + peer.getRoutingMetric()); } System.out.println("BEST: " + best_peer.getGUID()); + //Prepare the return result. Resource tmp = new Resource(res.getGUID(), res.getName(), res.getHash()); tmp.possessedBy.put(best_peer.getGUID(), best_peer); diff --git a/src/main/java/com/echo/p2p_project/server/model/HeartBeatImpl.java b/src/main/java/com/echo/p2p_project/server/model/HeartBeatImpl.java index 64b658b..9a451d6 100644 --- a/src/main/java/com/echo/p2p_project/server/model/HeartBeatImpl.java +++ b/src/main/java/com/echo/p2p_project/server/model/HeartBeatImpl.java @@ -33,9 +33,11 @@ public class HeartBeatImpl extends UnicastRemoteObject implements HeartBeatRegis @Override public Boolean heartBeat(UUID GUID) throws RemoteException { + //ge the peer Peer peer = ServerMain.UHPT.get(GUID); if(peer == null) return false; + //zero out the counter peer.setMissedHartBeat(0); return true; } diff --git a/src/main/java/com/echo/p2p_project/server/model/HelloRegistryFacadeImpl.java b/src/main/java/com/echo/p2p_project/server/model/HelloRegistryFacadeImpl.java index 2f7cb92..5c302df 100644 --- a/src/main/java/com/echo/p2p_project/server/model/HelloRegistryFacadeImpl.java +++ b/src/main/java/com/echo/p2p_project/server/model/HelloRegistryFacadeImpl.java @@ -28,6 +28,7 @@ public class HelloRegistryFacadeImpl extends UnicastRemoteObject implements Hell */ public HelloRegistryFacadeImpl() throws RemoteException { super(); + //a test. System.out.println("HelloRegistryFacadeImpl"); } diff --git a/src/main/java/com/echo/p2p_project/server/model/WatchDog.java b/src/main/java/com/echo/p2p_project/server/model/WatchDog.java index 02a6e06..f09b066 100644 --- a/src/main/java/com/echo/p2p_project/server/model/WatchDog.java +++ b/src/main/java/com/echo/p2p_project/server/model/WatchDog.java @@ -35,12 +35,16 @@ public class WatchDog { return; // System.out.println(p); if (p == null) { + //Really rarely happen, remove the null peer. System.out.println("REMOVED(peer is null): " + uuid); ServerMain.UHPT.remove(uuid); continue; } + //increment the counter p.setMissedHartBeat(p.getMissedHartBeat() + 1); if (p.getMissedHartBeat() > 5) { + //if missed is grater than 5, then this peer is down. + //remove it. System.out.println(); System.out.println("==================================== REMOVE ====================================="); System.out.println("PEER (peer MissedHartBeat > 5): " + uuid); @@ -48,9 +52,11 @@ public class WatchDog { System.out.println("Resources: " + guid); Resource resource = ServerMain.UHRT.get(guid); if(resource.possessedBy.size() == 1) { + //remove from UHRT ServerMain.UHRT.remove(guid); } else { + //remove from possessedBy resource.possessedBy.remove(uuid); } } @@ -59,6 +65,7 @@ public class WatchDog { } } try { + //sleep and run again. Thread.sleep(1000); } catch (InterruptedException e) { System.out.println("WatchDog Interrupted"); diff --git a/src/main/java/com/echo/p2p_project/u_model/Peer.java b/src/main/java/com/echo/p2p_project/u_model/Peer.java index 761ae77..f88926b 100644 --- a/src/main/java/com/echo/p2p_project/u_model/Peer.java +++ b/src/main/java/com/echo/p2p_project/u_model/Peer.java @@ -19,6 +19,7 @@ import java.util.UUID; * @Description: **/ public class Peer implements Serializable,Comparable { + //All the information about the Peer. private UUID GUID; private String name; private String IP; @@ -146,6 +147,6 @@ public class Peer implements Serializable,Comparable { @Override public int compareTo(@NotNull Object o) { Peer p = (Peer) o; - return p.routingMetric - p.routingMetric; + return p.routingMetric - this.routingMetric; } } diff --git a/src/main/java/com/echo/p2p_project/u_model/Resource.java b/src/main/java/com/echo/p2p_project/u_model/Resource.java index 54900dc..fdf2dff 100644 --- a/src/main/java/com/echo/p2p_project/u_model/Resource.java +++ b/src/main/java/com/echo/p2p_project/u_model/Resource.java @@ -15,6 +15,7 @@ import java.util.UUID; * @Description: **/ public class Resource implements Serializable { + //All the information about the resource. private String GUID; private String name; public HashMap possessedBy = new LinkedHashMap<>();