Simple version of dropbox using file-socket


Introduction

Dropbox is a service that permits a user to save files onto their server, and automatically synchronize the files between the server and a number of devices comprising computers, phones, and tablets. The user installs client software onto their computer, and the client software takes care of automatically synchronizing files between client and server.

Your task in this assignment is to apply a simple version of Dropbox, using the file, socket and select system calls. While you may find it interesting to read more about Dropbox itself, the specifications in this document describe your task for assignment. Dbclient
When the dbclient is run, it will first establish a socket connection to dbserver, and will send a message having the userid, and the name of the directory that the client wants to synchronize. We will restrict synchronization to files in one directory and will not handle subdirectories. Every N seconds, client will initiate a synchronization operation.

A synchronization operation uses the subsequent algorithm:

For every file in the local directory get the last modified time and size send a sync_message request to the server containing the filename, last modified time, and size. Read a sync_message response from server having filename, the server's last modified time for the file, and size of the file on the server. If the last modified time in message from server is more recent that the local last modified time the client will read the file from server one CHUNKSIZE chunk at a time and will replace the local file with the contents from the server. Or else, the client will send the local file one CHUNKSIZE chunk at a time to the server. After iterating over all files in the local directory, the client checks to see if the server has any new files to send by sending an "empty" sync_message (a message with an empty string for the file name, a last modified time of 0, and a size of 0). It reads the response message from the server. If the server's response message is also an empty message, then client knows there are no new files.

If the server's response message has a non-empty file name, a non-zero last modified time, then the client will read file from the server as above. After it has completed reading file, it will repeat the procedure of sending a new file request (by sending an empty sync_message) and reading new files from server till it receives an empty message from the server.

dbserver

The server is a little more difficult. It will generate a directory for each user under the directory name provided by user. If two users use the same directory name, we will assume they are sharing the directory.

Since the server is maintaining multiple connections, we do not want the server to block on a read or accept from any client. To solve this problem, we will employ select to multiplex between clients. This also means that we will need to keep track of the type of message that the server anticipates to receive from a client depending on state of the client. When the server is notified (via select), that a message is accessible to read from the client, there are several possible options. The server may be expecting a login_message, if it hasn't read anything from the client yet.

A CHUNKSIZE chunk of a file, if server has realized that a file is newer on client than on server. A sync_message, otherwise, the server will store the following information for each client:

- The user id of the client
- The socket files descriptor
- The directory name where the client's files are stored
- A list of the files that the client has synchronized with server. Information about each file includes:
- The file name
- The last modified time sent by the client.

A partial algorithm that describes the communication between the server and a single client follows. Note that the server only acts in response to a message from the client. Apart from the initial setup, it does not initiate any operations. Handle a read from a client

case LOGIN:
        read login message and store userid and dir in client array
        create dir if doesn't exist
        set state = SYNC
    case SYNC:
        read sync_message
        if sync_message is an empty message
            figure out how to identify a file on the server that is not on
            the client, and add it to the client list
        else
            find filename in client's files array
           
        write response (if there are no new files to send, then send an empty response)
        if file's mtime is newer in clients' files array on server than in sync_message
            write file to client
            set state = SYNC
        else
            set state GETFILE
            (keep track of which file we are expecting to read)
    case GETFILE:
        read chunk
        write chunk
        if finished reading file (keep track of size vs bytes read)
            set state SYNC

Part of algorithm is missing. In particular, the server needs to handle an empty sync_message from the client which is an indication that the client is checking if the server has a file that the client does not. You will need to figure out a strategy to identify the files that the server is storing in the appropriate directory that are not in the client's list of files, so that they can be added to the client's list.

Tips:

Take advantage of the example code shown in class and given on the course web site. The example code will help you set up the sockets and the select call.

Write the code incrementally. Make sure each step compiles and runs before moving on. It will save you time!! The first step might be to write a client that just sends the login message, and the server that receives only the login message a store’s the client info. An intermediate step might be one where no file data is transferred, but the sync_messages are sent. Write and test a function that fills in a sync_message for a file.

Note that we have taken lots of shortcuts with the starter code. In particular, the number of clients and the number of files are artificially limited. I would not write production code this way, but it simplifies this part of the assignment.

Also note that we don't allow file deletion on the server. Once a file has been synchronized to the server, it stays there.
Be careful to handle the case where a client connection is closed.

Request for Solution File

Ask an Expert for Answer!!
Programming Languages: Simple version of dropbox using file-socket
Reference No:- TGS01485

Expected delivery within 24 Hours