Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

P2P Simulating using PeerSim Use PeerSim to implement a Chord network with a key

ID: 3732842 • Letter: P

Question

P2P Simulating using PeerSim Use PeerSim to implement a Chord network with a key space of size n = 2128 ie, each key consists of 128 bits. The Chord overlay is used to serve as distributed DNS servers. Each node will store a set of URLs When a user ask for a URL the system will look up for that URL form the Chord Overlay first, if he does not fined it he will get it from a centralized DNS server (known server). Initially no machine has any URL, when the system works each machine ask for a URL the system will store that URL on the machine that he is responsible for. Place 5000 nodes (machines) on the network and name each machine with a string from MachinesName.txt file. Use the out of the MD5 hash function of machine name as the id of each machine. Also use the out of the MD5 hash function of URL name only as the key for each URL URLs can be found on the DNS-DataBase.txt file For each cycle of the simulation, each peer in the network chooses a URL randomly from the DNS DataBase.txt. Then he uses the chord routing algorithm to find the peer that is responsible for, if he does not find it, he uses the insert algorithm to store that URL on the responsible machine What to out: For each peer in each cycle record in a text file the number of messages need for look up for a URL and if it hit or miss (a separate line for each peer) (hit mean that he found the URL in the chord, miss he does not find it). The last line of the file will have the average number of lookup messages for all peers in the network and the total number of hit. Finally draw a graph between cycles and average look up and a graph between cycles and number of hits. Note you will have a number of text file out equal to the number of ycles that you run the simulation. The simulation shout run not less than 24 cycles A java Implementation of the MD5 Hash Function, you can embedded in your code import java.security.*; import ava.math.*; public class ShowUncheckedWarning f public static void main(String[] args) throws Exception ( String s-"String to be hashed"; sageDigest m=MessageDigest.getInstance ("MD5"); m.update(s.getBytes(),0,s.length()); System.out.println("MD5: "+new BigInteger(1,m.digest)).toString (16)); Web site has an implementation example of P2P using PeerSim http://peersim.sourceforge.net#code

Explanation / Answer

code - import java.io.FileInputStream;

import java.io.UnsupportedEncodingException;

import java.math.BigInteger;

import java.security.MessageDigest;

import java.security.NoSuchAlgorithmException;

public class MD5

{

    public static String getMD5(String input)

{

        try {

            MessageDigest md = MessageDigest.getInstance("MD5");

            byte[] messageDigest = md.digest(input.getBytes());

            BigInteger number = new BigInteger(1, messageDigest);

            String hashtext = number.toString(16);

while (hashtext.length() < 32)

{

                hashtext = "0" + hashtext;

            }

            return hashtext;

        }

        catch (NoSuchAlgorithmException e)

{

            throw new RuntimeException(e);

        }

    }

    public static void main(String[] args) throws NoSuchAlgorithmException {

        System.out.println(getMD5("Java.com"));

    }

}