6.033 Lab - Computer System Engineering Lab 1 - February 11, 2000

A TCP Proxy Server

Due date: February 18 (timers), February 25 (tcp proxy). Don't wait until the last minute.


Introduction

The first programming project in 6.033 is meant to prepare you for the next two projects by acquainting you with UNIX programming, especially network programming. Unlike the other labs, we will start you off with some code for setting up network connections, since the code for doing this is very mechanical. From this point, you will build a fully functional TCP proxy.


Running a simple client/server program

We'll be using a trivial client/server program as our stepping stone. The C sources for the program can be found in the 6033 locker in the lab/src/one directory. You should copy the contents of the directory to a directory under your control.

Now, build the client and server. Start the server by typing ./server. In another window, type ./client name, where name is the name of the machine on which the server is running. You can find out the name of a machine you are using into by typing hostname. Every time you run the client, the server will print the notorious "hello, world!" message.


Understanding the client and the server

Once you get the programs running, you should study the code and try to understand it. The specifics of each UNIX networking call can be found in the manual pages (e.g., type man socket). If you cannot make sense out of the program using the sources and the man pages, you might want to borrow "UNIX network programming," written by Richard Stevens; or, get in touch with your TA.


TCP Proxy Server

A TCP proxy server is a server which acts as an intermediary between a client and another server, called the destination server. Clients establish connections to the TCP proxy server, which then establishes a connection to the destination server. The proxy server sends data received from the client to the destination server and forwards data received from the destination server to the client. Interestingly, the TCP proxy server is actually both a server and a client. It is a server to its client and a client to its destination server.

A TCP proxy server can be useful to get around services which restrict connections based on the network addresses. For example, there are many servers at MIT which will only serve data to addresses within the MIT network. By running a proxy server on the MIT network, clients from outside MIT can use those servers by connecting through the proxy server. The MIT servers will think they are serving data to a machine on the MIT network (namely the proxy server machine) and they'll be right. However, the proxy is forwarding the data out of the MIT subnet, thus subverting the protection mechanism. This is a violation of the rules of use on most of those server, so we do not encourage you to do this.

The proxy server you will build for this lab will be invoked at the command line as follows:

% ./proxy destination-host   destination-port   listen-port

For example, to redirect all connections to port 3000 on your local machine to the MIT web server, do:

% ./proxy web.mit.edu 80 3000 &

The proxy server will accept connections from multiple clients and forward them using multiple connections to the server. No client or server should be able to hang the proxy server by refusing to read or write data on its connection. For instance, if one client suddenly stops reading from the socket to the proxy, other clients should not notice interruptions of service through the proxy. You will need asynchronous behavior, described in "Using TCP Through Sockets".

Additionally, if a connection hangs for more than 30 seconds, it must be terminated. The proxy server should dump to stderr a message stating that the connection has been dropped. The message should include ip address of the client or server that hang.


Asynchronous Library

You should use the asynchronous library in your proxy to manage asynchronous connections to servers and clients. The library is described in "Using TCP Through Sockets".


How/What to hand in

February 18 - Asynchronous library with timers

The asynchronous library (provided in /mit/6.033/lab/src/one/async, described in "Using TCP Through Sockets") manages callbacks for reading and writing a file descriptor, but not for timeouts. Modify this library to include callback support for timeouts. Specifically, add the following two features: Additionally, modify the multifinger program so that it would close any idling connection or connection attempt after 30 seconds. All related callbacks should be canceled as well.

Hand in your asynchronous library and multifinger program in a tar image named "timers.tar". The tar image should include a valid Makefile that creates a library named libasync.a and a program named multifinger. Prior to coming to recitation, place this image in your home directory. Please make sure the tar image is readable by 6.033. The tar images will be collected sometimes after recitation.

We will test both your multifinger program and asynchronous library. If your library fails to work properly, we will try your multifinger program with our own library. You can place comments and/or directions in a README file.

February 25 - TCP proxy

Hand in the entire tcp proxy in a tar image named "proxy.tar". The tar image should include a valid Makefile that creates a proxy server named proxy and a library named libasync.a. Prior to coming to recitation, place this image in your home directory. Please make sure the tar image is readable by 6.033. The tar images will be collected sometimes after recitation.


Testing

You should test your library and programs by creating some simple servers to connect to. lab/one/myfingerd contains an example finger daemon. You can, for example, put in arbitrary delays in the daemon to achieve hanging effects. We will supply additional test programs during next week.


If You Are Curious...

Here is a question for you to think about if you are curious:


References

The following books are useful: