1 COMP3331/9331 Computer Networks and Applications Assignment for Term 3, 2019 Version 1.0 Due: 11:59am (noon) Friday, 22 November 2019 (Week 10) 1. Change Log Version 1.0 released on 7th October 2019. 2. Goal and learning objectives Instant messaging applications such as WhatsApp, WeChat, Facebook Messenger, etc. are widely used with millions of subscribers participating in them globally. In this assignment, you will have the opportunity to implement your own version of an instant messaging application. In addition to basic messaging functionality, you will also implement many additional services that are available in many of the aforementioned applications. Your application is based on a client server model consisting of one server and multiple messaging clients. The clients communicate with the server using TCP. The server is mainly used to authenticate the clients and direct the messages (online or offline) between clients. Besides, the server also has to support certain additional functions (presence notification, blacklisting, timeout, etc.). You should also implement functionality that allows clients to send peer- to-peer messages to each other that bypass the server. 2.1 Learning Objectives On completing this assignment, you will gain sufficient expertise in the following skills: 1. Detailed understanding of how instant messaging services work. 2. Expertise in socket programming. 3. Insights into designing an application layer protocol. 3. Assignment Specification The base specification of the assignment is worth 20 marks. The specification is structured in two parts. The first part covers the basic interactions between the clients and server and includes functionality for clients to communicate with each other through the server. The second part asks you implement additional functionality whereby two users can exchange messages with each other directly (i.e. bypassing the server) in a peer-to-peer fashion. This first part is self-contained (Sections 3.1-3.3) and is worth 15 marks. Implementing peer-to-peer messaging (Section 3.4) is worth 5 marks. CSE students are expected to implement both functionalities. Non-CSE students are only required to implement the first part (i.e. no peer-to-peer messaging). The marking guidelines are thus different for the two groups and are indicated in Section 7. Updates to the assignment, including any corrections and clarifications, will be posted on the subject website. Please make sure that you check the subject website regularly for updates. 2 The assignment includes 2 major modules, the server program and the client program. The server program will be run first followed by multiple instances of the client program (Each instance supports one client). They will be run from the terminals on the same and/or different hosts. There is an extension component (outlined in Section 3.5) that is worth 4 marks. Note that the bonus marks may not be proportional to the amount of extra work that you will have to do. They are there to encourage you to go beyond the standard assignment. The bonus marks can be used to make up for lost marks in the lab exercises but NOT for any of the exams (mid-session and final). 3.1. Server The server has the following responsibilities - User Authentication - When a new client requests for a connection, the server should prompt the user to input the username and password and authenticate the user. The valid username and password combinations will be stored in a file called credentials.txt which will be in the same directory as the server program. An example credentials.txt file is provided on the assignment page. Username and passwords are case-sensitive. We may use a different file for testing so DO NOT hardcode this information in your program. You may assume that each username and password will be on a separate line and that there will be one white space between the two. If the credentials are correct, the client is considered to be logged in (i.e. online) and a welcome message is displayed. When all messaging is done, a user should be able to logout from the server. On entering invalid credentials, the user is prompted to retry. After 3 consecutive failed attempts, the user is blocked for a duration of block_duration seconds (block_duration is a command line argument supplied to the server) and cannot login during this duration (even from another IP address). While a user is online, if someone uses the same username/password to log in (even from another IP address), then this new login attempt is denied. Timeout - The server should keep track of all online users. If the server does not receive any commands from a user for a period of timeout seconds (timeout is a command line argument supplied to the server), then the server should automatically log this user out. Note that, to be considered active, a user must actively issue a command. The receipt of a message does not count. Presence Broadcasts - The server should notify the presence/absence of other users logged into the server, i.e. send a broadcast notification to all online users when a user logs in and logs out. List of online users - The server should provide a list of users that are currently online in response to such a query from a user. Online history – The sever should provide a list of users that logged in for a user specified time in the past (e.g. users who logged in within the past 15 minutes). Message Forwarding - The server should forward each instant message to the correct recipient assuming they are online. Offline Messaging - When the recipient of a message is not logged in (i.e. is offline), the message will be saved by the server. When the recipient logs in next, the server will send all the unread messages stored for that user (timestamps are not required). Message Broadcast – The server should allow a user to broadcast a message to all online users. Offline messaging is not required for broadcast messages. 3 Blacklisting - The server should allow a user to block / unblock any other user. For example, if user A has blocked user B, B can no longer send messages to A i.e. the server should intercept such messages and inform B that the message cannot be forwarded. Blocked users also do not get presence notifications i.e. B will not be informed each time A logs in or logs out. 3.2. Client The client has the following responsibilities - Authentication - The client should provide a login prompt to enable the user to authenticate with the server. Message - The client should allow the user to send a message to any other user and display messages sent by other users. The client should also allow the user to send a broadcast message to all online users. Notifications - The client should display presence notifications sent by the server about users logging in and out from the server. Find users online - The client should provide a way for the user to obtain a list of all the users currently online from the server. Find online history – The client should provide a way for the user to obtain a list of all users who had logged in within a user specified time period. Blacklist – The client should allow a user to block a user from sending any further messages. The client should also allow a user to unblock a user that was earlier blocked. 3.3 Commands supported by the client After a user is logged in, the client should support all the commands shown in the table below. For the following, assume that commands were run by user A. Command Description message Send to through the server. If the user is online then deliver the message immediately, else store the message for offline delivery. If has blocked A, then a message to that effect should be displayed for A. If the is not present in the credentials file (i.e. invalid user) or is self (A) then an appropriate error message should be displayed. The used in our tests will be a few words at most. broadcast Send to all online users except A and those users who have blocked A. Inform A that message could not be sent to some recipients. whoelse This should display the names of all users that are currently online excluding A. Users can be displayed in any order. whoelsesince