The code simulates a peer-to-peer network, in which new nodes randomly join a single pre-existing node in the network as the network grows. Also note that for Deliverable 1 of this assignment, machines.txt will be empty. For later deliverables, it will be used as a master document to note which machines have access to which files in addition to which machines are participating in the network.
- SSH into the machine dc01 and create a folder, "F", in your directory somewhere.
- Upload machines.txt and P2P.java to "F".
- Ensure that machines.txt is completely empty (no whitespaces or text characters).
- Navigate to "X" and then type 'javac P2P.java' to compile the Java program into .class files.
- Type 'ls' and ensure the class files have been created.
- Create 15 subdirectories (for example, "sub01" to "sub15") under "F".
- Repeatedly copy the files P2P.class and Listener.class into each subdirectory like so: type 'cp {P2P.class,Listener.class} sub01' and repeat for "sub02" to "sub15".
- For the sake of the simulation, let us use only machines dc01 through dc15 (so that they correspond to "sub01" to "sub15").
- SSH into whichever machine dcXX you would like to initiate the network, where XX is between 01 and 15.
- Navigate to the subfolder of "F" named "subXX".
- Type 'ls' and verify that there are only two files in "subXX": P2P.class and Listener.class.
- Now type 'java P2P' and verify that the host name is printed out.
- Now open a second terminal and SSH into another machine dcYY, where YY is between 01 and 15 and YY does not equal XX.
- Navigate to the subfolder of "F" named "subYY".
- Type 'ls' and verify that there are only two files in "subYY": P2P.class and Listener.class.
- Now type 'java P2P' and verify that along with the host name being printed out, a neighbor list consisting of just the first host name of dcXX is also printed out.
- Switch over to the first terminal (of dcXX) and verify that a neighbor list was printed after 'java P2P' was run on dcYY.
- Repeat this process with other machines and verify that the neighbor picked by each incoming machine is random.
- When you are done with a particular machine, simply hit Ctrl+C to exit the process.
- Once in, you can simply type 'Search ' where X represents a keyword (first token in a file) or an actual file name.
- After waiting for a bit, you can see all the search results. The search will terminate at the hop count where it found at least 1 result. If the final hop count of 16 fails, an error output will be produced.
- If the file you searched for was found, a numbered list of tuples will show up in the format ([search term],[file],[machine]).
- Type out the number of the option you want, or alternatively type 0 to cancel the file transfer.
- If you do not type 0, then a one-time socket instance is created between the requester and the machine containing the file.
- At the end, a success notification should appear.
- To leave the network, simply type Leave. The program on the machine that leaves should simply end without fuss.
- On the other machines that were once neighbors of this machine, type the command 'Peers' to get a list of Peers.
- If there were only two peers it is nigh impossible to determine which peer was chosen as the replacement machine for connections.
- If there are more than 2 peers, you can use the 'Peers' command to tell which neighbor of the leaving machine had the other neighbors added as neighbors of its own.