Bulletin Board Messages and Distributed Agreement: A CSC 590 Challenge
This challenge consists of two phases. In the first phase you will construct a simple network server. The next phase will consists of convincing multiple such servers to work together. Read the document com- pletely before starting any coding; everything in the document is part of the specification and it is your responsibility to ensure that you have implemented the whole server as specified.
The challenge is set up so that it gives you the opportunity to showcase your skills at system program- ming in a POSIX1 environment. Indeed, you must implement the server as a UNIX service (“daemon”) and you further must use the POSIX API provided by the UNIX standard C library. Therefore your server must be written in C or C++.
1In case you are wondering, POSIX originally came from “Portable Operating System Interface for uniX”. As time went by the standard was adopted by other operating systems, so that the “for uniX” part is no longer pertinent. Thus many people claim that nowadays POSIX stands for “Portable Operating System Interface with an X added at the end for coolness”.
Throughout the handout we will refer to the following configuration parameters. How these parameters are obtained will be described in Section3.1.
bbfile is the name of the bulletin board file that will be manipulated throughout this project (string), see Section1;
peers the list of peers participating in synchronization (possibly empty list of pairs host name–port number), see Section2;
1 Phase 1: A Bulletin Board Server
Your first task is to construct a simple bulletin board server. The server accepts one-line messages from multiple clients, stores them in a local file, and serves them back on request. The name of the file is given by the parameter bbfile. Messages are identified upon storage by an unique number established by the server, and by the “sender” of the message (as provided by the USER command explained below).
The clients connect to our server on port bp. We also assume a production environment so that we implement concurrency control.
Below is a description of the basic application protocol i.e., of the commands send by the clients as well as the answers returned by the server (fixed-width font represents text which is well, fixed for the given command or response, while parameters that may vary are shown in italics).
Every command and response consists of a single line of text. The server should handle any combination of the characters ’\n’ and ’\r’ as line terminator and should send back responses terminated by a single ’\n’.
At the beginning of the interaction the server send the following text to the client that just connected:
where greeting is some (possibly empty) message intended for human consumption. There is no par- ticular format for the greeting text, but it is strongly suggested for this text to summarize the com- mands available to clients.
This commands identifies the client. The argument name is a string not containing the character /. Future messages posted by the respective client will be identified as posted by name. Normally, a client will send this command at the beginning of the session, but the server should handle the case in which this command is sent more than once during the interaction with a particular client, as well as the case when a client does not send a USER command at all (case in which the poster will be nobody).
The server response is the line
1.0 HELLO name text
where text is some (possibly empty) message intended for human consumption.
This command asks for the message number message-number. In the event that this message exists on the bulletin-board, the server will send in response one line of the form
where message represents the requested message, prefixed by its poster (as identified by the USER
command in effect at the time of posting).
If message message-number does not exist, then the server sends the line:
where text is a message for human consumption. If the server encounters an internal error while serving the request (e.g., the unavailability of the bulletin board file), then the following response is sent back to the client:
Again, text is an explanatory message with no particular structure.
This command sends message to the server for storage. The server will store the message into the bulletin board file as a line of the form:
where message-number is a unique number assigned by the server, and poster is the poster of the mes- sage as specified by a previous USER command issued by the respective client (nobody if no USER command has been issued by that client). Upon successful storage, the server returns the following message to the client:
3.0 WROTE message-number
When an error occurs during the storage process, the server responds with this message instead:
3.2 ERROR WRITE text
The receipt of such a response must guarantee that no message has been written to the bulletin board.
This command asks the server to erase message number message-number and replace it with message (which will be assigned the same message number as the original). The poster is also changed to the current poster as identified by a previous USER command (nobody if no such command has been issued).
The server response is identical to the response to a WRITE request, plus
3.1 UNKNOWN message-number
when message number message-number does not exist in the bulletin board file (case in which no message is added to the file).
Signals the end of interaction. Upon receipt of this message the server sends back the line
4.0 BYE some-text
and closes the socket. The same response (including the socket close) is given by the server to a client that just shuts down its connection. The server always closes the socket in a civilized manner (by shutting down the socket before closing it).
Your server must be robust, in the sense that no message shall be lost when the server is terminated, except possibly a message that is currently being written to disk. The bulletin board file should be considered too large to be kept completely in memory.
Your server must also be efficient, in the sense that it must not rewrite the whole bulletin board file upon the receipt of each and every message. It should use the file system as little as possible (within the robustness requirements above).
You need to provide a mechanism for rolling back the most recent transaction (write or replace). This is going to be used in the second part of the assignment.
You must build a concurrent server, which is able to serve many clients simultaneously. You must pro- vide an implementation based on POSIX threads, using concurrency management and thread preallocation (as explained in Section1.4).
The bulletin board file specified in the configuration file or on the command line must be created if nonex- istent and must be re-used as is otherwise (rather than being overwritten). Message numbers are assigned by the server in sequence, according to the order in which the WRITE requests have been received. No two messages can have the same number in any bulletin board file. In particular, if the server is started on an existing file it should inspect the file on startup and make sure that any new message written to the file has an associated number that does not conflict with existing message numbers.
The access control to the bulletin board file follows the readers/writers paradigm, a common scheme in operating systems. Simultaneous reads of the bulletin board file by different threads of execution must be allowed. However, no other operation (read or write) is allowed when a thread writes to the bulletin board file. Of course, if a write request is issued while several read operations are in progress, the write will have to wait until the current reads complete. Note that this mechanism is slightly more complicated than the normal file locking. You may want to use a structure (that records the number of current read and write operations) protected by a critical region and also a condition variable to enforce this restriction. Inefficient implementations of this access control mechanism will be penalized. Do not use file locking for implementing the access control since this method will not work as expected.
For solution, connect with online professionals.