Chain File Sample

4
129.82.45.59 20000
129.82.47.209 25000
129.82.47.223 30000
129.82.47.243 35000

Program Flow

ss

  1. ss takes one optional argument, the port it will listen on. Example(./ss 20000)

  2. ss prints the hostname and port, it is running on. To find hostname, you can use gethostname.

  3. Create the socket and fill in its values. Then Bind the socket.

  4. Create a loop statement and set the socket in listen mode.

  5. Once a connection arrives, it reads the URL and the chain information.

  6. Create a thread using pthread_create and pass the arguments.[Or use select()]

  7. If the chain list is empty:


    1. The ss uses the system call system() to issue a wget to retrieve the file specified in the URL.
    2. Reads the file in small chunks and transmits it back to the previous SS. The Previous SS also receives the file in chunks.
    3. Once the file is completely transmitted, the ss should tear down the connection.
    4. Erase the local copy and go back to listening for more requests.

  8. If the chain list is not empty:


    1. Uses a random algorithm such as rand() function to select the next SS from the list.
    2. Remove the current ss details from the chain list and send the url and chainlist to the next ss.
    3. Wait till you receive the fill from the next ss.
    4. Reads the file in small chunks and transmits it back to the previous SS. The Previous SS also receives the file in chunks.
    5. Once the file is completely transmitted, the ss should tear down the connection.
    6. Erase the local copy and go back to listening for more requests.

awget


  1. awget will have up to two command line arguments:

  2. Example ./awget [-c chainfile]
  3. The URL should point to the document you want to retrieve.

  4. Passing the chainfile as an argument is optional

  5. If chainfile is not specified awget should read the chain configuration from a local file called chaingang.txt.

  6. If no chainfile is given at the command line and awget fails to locate the chaingang.txt file, awget should print an error message and exit.

  7. If awget can read both URL and chainfile correctly, proceed.

  8. Find a random ss from the list. You can use rand() function. Seed the value to get different random number each time.

  9. Once you have the ss, IP address and port number, create the socket and fill in its values.

  10. Send a connect request to the ss.

  11. Once the connect request is accepted, strip the ss details from the chainlist and then send the URL and chainlist to the ss.

  12. Wait till you receive the file.

  13. Create a looping statement to receive the file in chunks.

  14. Save the data received in a local file. The file name should be same as the file requested. For Example: For example, when given URL is http://www.cs.colostate.edu/~cs457/p2.html the file saved will be named p2.html

  15. When URL with no file name is specified, fetch index.html, that is, awget of www.google.com will fetch a file called index.html.