



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Important: This project may be done individually or in pairs. Be sure to carefully read the course policies for assignments (including the honor code policy) on the assignments page of the course web site. Because this assignment is due at the end of the semester, you may use at most 2 slip days (subject to all of the other requirements for using slip days).
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 lab, you will write a concurrent Web proxy that logs requests. In the first part of the lab, 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, keeping a log of such requests in a disk file. This part will help you understand the basics about network programming and the HTTP protocol. In the second part of the lab, you will upgrade your proxy 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 this part you will implement a sequential logging 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 it the request, receive the reply, and forward the reply to the browser if the request is not blocked. 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.
Your proxy should keep track of all requests in a log file named proxy.log. Each log file entry should be a file of the form:
Date: browserIP URL size
where browserIP is the IP address of the browser, URL is the requested URL, size is the size in bytes of the object that was returned. For instance:
Wed 5 Nov 2008 12:51:02 CDT: 128.2.111.38 http://www.rice.edu/ 34314
Note that size is 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 proxy.c to create a log entry in the required format. Note that format log entry does not put a trailing newline on the returned string.
Your proxy should listen for its connection requests on the port number passed in on the command line:
unix> ./proxy 2345
You may use any port number p, where 2000 ≤ p ≤ 3000 , and where p is not currently being used by any other system or user services (including other students’ proxies). See /etc/services for a list of the port numbers reserved by other system services.
The port number restrictions are imposed by Owlnet. In general, you would be able to run a proxy on a wider range of ports. Also, not all Owlnet servers can access the Internet or be accessed by other machines. For this assign- ment, you will have to run your proxy on long-eared or short-eared. If you experience problems with either of these machines, you should notify the instructor and the labbies as quickly as possible so we can work to resolve the issue. Owlnet restrictions make it so that you cannot access long-eared and short-eared from outside of Rice. However, you should be able to run your browser to access your proxy on any system at Rice. If you are off-campus, you will need to use VPN in order to access your proxy running on long-eared or short-eared.
Part II: Dealing with multiple requests concurrently
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 (CSAPP 13.3.8). 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.
http://www.owlnet.rice.edu/˜comp221/proxytest.html
Once you get that working, we suggest you try the course web page and the links therein:
http://www.owlnet.rice.edu/˜comp221/2008/html/
Then you can try more complicated sites with multiple files and images, such as www.rice.edu and www.yahoo.com. If you have trouble with a particular site, you may always use proxyref to see what features may be required to access that site.
Evaluation
To turn in your code, you should run the ˜comp221/bin/proj6submit program in the directory that contains the files you wish to submit. Be sure that your code is entirely contained in a file named proxy.c. Note that we will compile only your proxy.c file along with the provided csapp.c. Note that the proj6submit program submits your entire directory. If there are additional files in the directory, that is okay, but we will not use them for grading purposes. Instead of a writeup, each individual/group will be evaluated on the basis of a demonstration to the instructor. During the demo, you will demonstrate that your proxy behaves correctly and you will answer basic questions about your proxy. These demos will occur during the last week of classes and will be scheduled near the end of the term. The project will be graded as follows:
Additional web sites will be tested at the demo.