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
- ss takes one optional argument, the port it will listen on. Example(./ss 20000)
- ss prints the hostname and port, it is running on. To find hostname, you can use gethostname.
- Create the socket and fill in its values. Then Bind the socket.
- Create a loop statement and set the socket in listen mode.
- Once a connection arrives, it reads the URL and the chain information.
- Create a thread using pthread_create and pass the arguments.[Or use select()]
- If the chain list is empty:
- The ss uses the system call system() to issue a wget to retrieve the file specified in the URL.
- Reads the file in small chunks and transmits it back to the previous SS. The Previous SS also receives the file in chunks.
- Once the file is completely transmitted, the ss should tear down the connection.
- Erase the local copy and go back to listening for more requests.
- If the chain list is not empty:
- Uses a random algorithm such as rand() function to select the next SS from the list.
- Remove the current ss details from the chain list and send the url and chainlist to the next ss.
- Wait till you receive the fill from the next ss.
- Reads the file in small chunks and transmits it back to the previous SS. The Previous SS also receives the file in chunks.
- Once the file is completely transmitted, the ss should tear down the connection.
- Erase the local copy and go back to listening for more requests.
awget
- awget will have up to two command line arguments:
- Example ./awget [-c chainfile]
- The URL should point to the document you want to retrieve.
- Passing the chainfile as an argument is optional
- If chainfile is not specified awget should read the chain configuration from a local file called chaingang.txt.
- 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.
- If awget can read both URL and chainfile correctly, proceed.
- Find a random ss from the list. You can use rand() function. Seed the value to get different random number each time.
- Once you have the ss, IP address and port number, create the socket and fill in its values.
- Send a connect request to the ss.
- Once the connect request is accepted, strip the ss details from the chainlist and then send the URL and chainlist to the ss.
- Wait till you receive the file.
- Create a looping statement to receive the file in chunks.
- 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
- 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.