



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An assignment to create a concurrent web proxy that logs requests. The proxy acts as an intermediary between a web browser and an end server, forwarding requests and responses. The assignment consists of three parts: writing a simple sequential proxy, extending it to log requests, and upgrading it to handle multiple requests concurrently using threads. The document also provides instructions on testing the echo server and sending http requests to servers and proxies.
Typology: Assignments
1 / 6
This page cannot be seen from the preview
Don't miss anything!




A Web proxy is a program that acts as a middleman between a Web browser and an end server. Instead of contacting the end server directly to get a Web page, the browser contacts the proxy, which forwards the request on to the end server. When the end server replies to the proxy, the proxy sends the reply on to the browser.
Proxies are used for many purposes. Sometimes proxies are used in firewalls, such that the proxy is the only way for a browser inside the firewall to contact an end server outside. The proxy may do translation on the page, for instance, to make it viewable on a Web-enabled cell phone. Proxies are also used as anonymizers. By stripping a request of all identifying information, a proxy can make the browser anonymous to the end server. Proxies can even be used to cache Web objects, by storing a copy of, say, an image when a request for it is first made, and then serving that image in response to future requests rather than going to the end server.
In this assignment, you will write a concurrent Web proxy that logs requests. In the first part of the assign- ment, you will write a simple sequential proxy that repeatedly waits for a request, forwards the request to the end server, and returns the result back to the browser. This part will help you understand basics about network programming and the HTTP protocol.
In the second part of the assignment, you will extend your proxy from the first part to keep a log of requests in a disk file. This part will help you learn how to manipulate files in C.
In the third part of the assignment, you will upgrade your proxy from the first part so that it uses threads to deal with multiple clients concurrently. This part will give you some experience with concurrency and synchronization, which are crucial computer systems concepts.
In your csc2405 directory, copy proxy-handout.tar from /tmp:
cp /tmp/proxy-handout.tar ∼/csc
Next use the command
tar xvf proxy-handout.tar
This will cause a number of files to be unpacked in the directory proxy-handout:
Your proxy.c file may call any function in the csapp.c file. However, since you are only handing in a single proxy.c file, please do not modify the csapp.c file. If you need different versions of functions in csapp.c (as suggested in the Hints section), write the new functions in the proxy.c file.
Build the echoservert executable on tanner by typing in make echoservert, then test the server using telnet as follows. Pick a random 5-digit integer N no greater than 64000 and pass it to the server as an argument:
./echoservert N
Open a second terminal window on tanner and invoke telnet at the shell prompt, passing the port number N as a second argument:
telnet tanner N
The telnet application opens a TCP connection to port N on tanner. Now anything that you type into the telnet window will be sent over this connection and echoed back to you by the server.
In this part you will implement a sequential proxy. Your proxy should open a socket and listen for a connection request. When it receives a connection request, it should accept the connection, read the HTTP request, and parse it to determine the name of the end server. It should then open a connection to the end server, send the request (altered as described in subsequent sections), receive the reply, and forward the reply (unaltered) to the browser, if the request is not blocked. Check the Hints section for details on error handling. You know that your program works if the browser displays the information correctly.
Since your proxy is a middleman between client and end server, it will have elements of both. It will act as a server to the web browser, and as a client to the end server. Thus you will get experience with both client and server programming. Chapter 12 in our textbook is a very good reference material – use it as needed.
HTTP requests are of many types, but we will only concern ourselves with the GET request in this as- signment. Suppose that you type the URL http://www.google.com/index.html into your Web browser. The Web browser will open a TCP connection to www.google.com on port 80 and send the request (followed by a number of lines not shown here):
A unique port number has been assigned to you – please check the class website to find out the port number your server is supposed to use. This is to ensure that your port number is not currently being used by other students or system services (see /etc/services for a list of the port numbers reserved by system services).
Your proxy should keep track of all requests in a log file named proxy.log. Each log file entry should be a line of the form:
Date: browserIP URL size
where browserIP is the IP address of the browser, URL is the URL asked for, size is the size in bytes of the object that was returned. For instance:
Sun 16 Feb 2009 02:51:02 EST: 128.2.111.38 http://www.xxx.com/ 34056
Note that size is essentially the number of bytes received from the end server, from the time the connection is opened to the time it is closed. Only requests that are met by a response from an end server should be logged. We have provided the function format log entry in csapp.c to create a log entry in the required format. See
http://www.csc.villanova.edu/∼mdamian/C/c-files.htm
for instructions on manipulating files in C.
Real proxies do not process requests sequentially. They deal with multiple requests concurrently. Once you have a working sequential logging proxy, you should alter it to handle multiple requests concurrently. The simplest approach is to create a new thread to deal with each new connection request that arrives. Use echoservert.c as a guiding example.
With this approach, it is possible for multiple peer threads to access the log file concurrently. Thus, you will need to use a semaphore to synchronize access to the file such that only one peer thread can modify it at a time. If you do not synchronize the threads, the log file might be corrupted. For instance, one line in the file might begin in the middle of another. Check the Hints section for details on thread-safe functions.
Each student will be evaluated on the basis of a demo to your instructor. Evaluation criteria include: