6.824 Lab 1: Multifinger Timeouts


The first programming project is meant to introduce you to some programming tools you'll be using for the rest of the course, particularly the Unix software development environment (g++, autoconf, etc.) and the C++ asynchronous I/O library. You'll start with source to the C++ multifinger program described in Using TCP through sockets. You will modify multifinger to add a timeout, so that it does not sit waiting forever when a finger server hangs. Finally, you should turn in a software distribution of the modified multifinger program.

You will need to obtain an account on the class machines to complete this lab. See the lab information page for more information.

This lab is due at the start of class on Thursday, September 13th.

Fetching and building the source

Start by unpacking the multifinger source in your home directory. The tarball is available at /home/to2/labs/multifinger.tar.gz on the class machines. On these machines, you can get started with the following commands:
benb@blood [~] > tar xzf /home/to2/labs/multifinger.tar.gz
benb@blood [~] > cd multifinger
benb@blood [~] > sh ./setup
automake: configure.in: installing `./install-sh'
automake: configure.in: installing `./mkinstalldirs'
automake: configure.in: installing `./missing'
configure.in: 22: required file `./ltconfig' not found
automake: Makefile.am: installing `./INSTALL'
automake: Makefile.am: installing `./COPYING'
+ autoconf
+ set +x
benb@blood [~] >
Next, you must configure the software and generate a Makefile--a set of instructions for how to compile the software. For this class, we will use the GNU autoconf and automake tools to generate Makefiles. You will also be linking against the libasync library; you can find the source in /home/to2/sfs/async or on the SFS web site. On the class machines, generate the Makefile with the following commands:
benb@blood [~] > ./configure --with-sfs=/home/to2/sfs-debug
creating cache ./config.cache
checking for a BSD compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking whether make sets ${MAKE}... yes
checking for working aclocal... found
checking for working autoconf... found
checking for working automake... found
checking for working autoheader... found
checking for working makeinfo... found
checking host system type... i386-unknown-openbsd2.8
updating cache ./config.cache
creating ./config.status
creating Makefile
creating config.h
benb@blood [~] > 
It is very important that you supply the argument --with-sfs=/home/to2/sfs-debug to ./configure. If you don't, things will appear to work, but you will get a version of libasync without built-in debugging sanity checks (including the dmalloc library). Your assignment will be linked against debugging libraries for grading, so you want to make sure you get the benefit of the sanity checking while testing the software yourself.

Once the software is configured, you can build multifinger by running gmake. (Note that this is gmake with a g, and not make. At the end of the assignment you will make a software distribution that compiles with any make, but for development you must use gmake which is GNU make.)

benb@blood [~] > gmake
c++ -DHAVE_CONFIG_H -I. -I. -I.   -I/home/c/class/lib/debug ...
/bin/sh ./libtool --mode=link c++  -g -ansi -Wall -Wsign-compare ...
mkdir .libs
c++ -g -ansi -Wall -Wsign-compare -Wchar-subscripts -Werror -Wno-unused ...
benb@blood [~] > 
That's it! You've now built multifinger. To test it, type:
benb@blood [~] > ./multifinger fdabek@mit.edu rtm@mit.edu
You should get finger information for Frank Dabek and Robert Morris, though not necessarily in that order.

Adding Timeouts

Now try this:
benb@blood [~] > ./multifinger rtm@frenulum.lcs.mit.edu
benb@blood [~] > 
The problem is that while the machine frenulum accepts finger requests, it never produces any responses.

Your assignment is to modify multifinger.C to terminate connections that don't finish producing a response within 10 seconds of the connection setup. That is, after finger::connected is called, your multifinger should spend no more than 10 seconds waiting for the write()s and read()s to complete. If 10 seconds pass without a complete answer from the server, close the file descriptor and move on to another command-line argument. For example, when your multifinger is run thus:

benb@blood [~] > ./multifinger rtm@frenulum.lcs.mit.edu fdabek@mit.edu
it should quickly print the information for Frank Dabek, then wait 10 seconds, then exit.

You'll want to use the delaycb function mentioned in Section 6.6 of Using TCP Through Sockets.


The perl script test-mf contains a few tests to help make sure your multifinger works. You can find this script on the class machines in /home/to2/labs. Copy it to your home directory and run the tests as follows:
benb@blood [~] > cp /home/to2/labs/test-mf .
benb@blood [~] > limit -h descriptors 64
benb@blood [~] > ./test-mf
Finger one user: passed
Finger two users: passed
Time out a stuck host in 10 seconds: passed
Combination of good and stuck hosts: passed
More than 64 hosts: passed
Lots of good and stuck hosts: passed
benb@blood [~] > 
(If the limit command doesn't work, try limit -h openfiles 64 or ulimit -n 64 instead.) If all goes well, test-mf should finish in about 40 seconds and print out messages as above. Your program program will be graded with test-mf, and perhaps other tests.

How/What to hand in

You should submit a complete software distribution of the modified multifinger program. To build a software distribution, run the command:
benb@blood [~] > gmake dist
rm -rf multifinger-0.0
mkdir multifinger-0.0
chmod 777 multifinger-0.0
multifinger-0.0.tar.gz is ready for distribution
benb@blood [~] > 
To turn in your distribution, copy it to the directory ~/handin/lab1/ in your home directory. It will be copied from this directory by the staff.
benb@blood [~] > mkdir -p ~/handin/lab1/
benb@blood [~] > cp multifinger-0.0.tar.gz ~/handin/lab1/
benb@blood [~] > 
If you have any problems about submission, please contact your TA (fdabek@mit.edu).