Starting from:
$35

$29

Homework 3 - Bulletin Board System: Part 3 Solution

Description

In this part, you are going to write a client program for BBS service. However, in this part, the content of the post will store on the client-side (Amazon S3) instead of the server-side. Take the post function of the BBS service, for example. The server in this part only stores the metadata of posts (e.g., post id, post title, author and date.) except for the content of the post. That is to say, each client has its storage to store the content of their posts, and we use Amazon S3 for the storage service. Besides, you are also going to implement new features such as a simple mail service.

System Architecture











































The server here only stores user information, boards and some metadata of posts. (e.g., post id, post title, etc). The real content of the post will store on the client-side (Amazon S3). Each bucket of Amazon S3 represents the storage of each client. So, each client can store the content of its posts in its bucket, and this bucket is also an incoming mailbox for the mail service of this client. Note that only your client program can get access to Amazon S3 using Amazon S3 API.
Requirements

The service can serve at least 10 clients. Your server and client program must be able to handle all commands in the previous part (output results must be the same as the previous part). For some commands such as whoami, exit, logout, create-board, list-board ##<key> and list-post <board-name> ##<key>, your client program only sends the command to the server and gets the corresponding result from the server. However, there are some commands that your client program will interact with Amazon S3. These commands are described as follows:

Command format
Description

Result





register <username> <email> <password>
If successful execution, your client
Success
Register successfully.

program will create a new bucket in








Amazon S3 for this new user, and your





Fail
Username is already used.

server program will store the bucket



name of this new user so that the user




will be able to log in with its bucket in the




future.




If failed, only print the error message.



login <username> <password>
If successful execution, the user will log
Success
Welcome, <username>.

in with its Amazon S3 bucket, so that it








can manipulate (e.g., upload posts,





Fail (1)
Please logout first.

delete posts, etc) its bucket in the future.



If failed, only print the error message.





Fail (2)
Login failed.








create-post <board-name> --title <title> --
If successful execution, the user (client)
Success
Create post successfully.
content <content>
will upload the content of this post to








(command is in the same line )
its S3 bucket using Amazon S3 API,





Fail (1)
Board does not exist.

and the server will keep the metadata of








this post.





Fail (2)
Please login first.





If failed, only print the error message.








read <post-id>
Show the post whose ID is <post-id>.
Success
Author
:<Author1>








Title
:<Title1>

If successful execution, the client will

Date
:<Date1>



--


get the content of this post from the






<content>





post owner’s bucket using Amazon S3

--


API and print the result.

<User1>:<Comment1>











Fail
Post does not exist.

If failed, only print the error message.



delete-post <post-id>
Delete the post whose ID is <post-id>.
Success
Delete successfully.





If successful execution, the user (client)
Fail (1)
Please login first.






will delete this post from its bucket,





Fail (2)
Post does not exist.





and the server will delete the metadata




of this post.
Fail (3)
Not the post owner.

If failed, only print the error message.



update-post <post-id> --title/content <new>
Update the post whose ID is <post-id>.
Success
Update successfully.





If a successful update on the title, the
Fail (1)
Please login first.

server will update the title of this post.




Fail (2)
Post does not exist.

If a successful update on the content, the







user (client) will update the content of




Fail (3)
Not the post owner.

this post in Amazon S3 using Amazon







S3 API.



If failed, only print the error message.






comment <post-id> <comment>
Add a comment < comment > to the post
Success
Comment successfully.

whose ID is <post-id>.




Fail (1)
Please login first.





If successful execution, the user (client)




Fail (2)
Post does not exist.





will append the comment to the content



of this post in the post owner’s bucket.



That is to say, the comment stores in the



post owner’s bucket.



If failed, only print the error message.








Also, there are some new commands you have to implement for simple mail service. These commands are described as follows:

Command format
Description


Result






mail-to <username> --subject <subject>
Send a mail whose subject is <subject>
Success
Sent successfully.

--content <content>
and content is <content> to user




(command is in the same line )
<username>.





Use --subject and --content to separate





Fail (1)
Please login first.


subject and content.





<subject> has the same format as <title>





of the post.





<content> has the same format as





<content> of the post.





If successful execution, the user (client)





will create an object with <content> in





user <username>’s bucket using
Fail (2)
<username> does not exist.


Amazon S3 API.





Failed execution:





Fail (1): No user logged in.





Fail (2): User <username> doesn’t exist.










list-mail
List all incoming mails of the current
Success
ID
Subject    From
Date







logged in user.

1
<Subject1><From_user1> <Date1>



2
<Subject2><From_user2> <Date2>






Success:





Fail (1)
Please login first.


Note that each user has its mail id





sequence numbers. It should start at





1.












<Subject1> represents the subject of this




mail.




<From_user1> represents that this mail




is sent by user <From_user1>.




<Date1> represents the sent date of this




mail.




There is a \t between each column.




Failed execution:




Fail (1): No user logged in.








retr-mail <mail#>
Retrieve the content of the mail <mail#>
Success
Subject
:<Subject1>








From
:<From_user1>



Date
:<Date1>

If successful execution, the user (client)

--







will get the content of the mail from its

<content>



Fail (1)
Please login first.





bucket using Amazon S3 API and print




the result.




<Subject1> represents the subject of this




mail.





Fail (2)
No such mail.

<From_user1> represents that this mail








is sent by user <From_user1>.




<Date1> represents the sent date of this




mail.




There is a \t before ‘:’.




Failed execution:




Fail (1): No user logged in.




Fail (2): Mail <mail#> is not in your




mailbox.







delete-mail <mail#>
Delete mail <mail#> from your mailbox.
Success
Mail deleted.

If successful execution, the user (client)




Fail (1)
Please login first.

will delete the content of the mail from




its bucket using Amazon S3 API.




Failed execution:




Fail (1): No user logged in.




Fail (2)
No such mail.

Fail (2): Mail <mail#> is not in your




mailbox.










Scenario

Run your server first, and run your client program to connect to your server. If the line only shows “% “, that means we type <Enter> in our client program. It is just for the height alignment of two columns here. You can ignore that. The sample outputs of the client program are listed as follows:


Terminal output
Description and Amazon S3 Console State







Start with nothing in your Amazon S3.


bash$ ./client 127.0.0.1 7890
Create a bucket for user Brad. You can name the bucket name
********************************
of each user by yourself, but there are some limitations of the
** Welcome to the BBS server. **
bucket name. Please refer to the Note part.
********************************

% register Brad bb@cs.nctu.edu.tw 12345

Register successfully.


%





% register Brad bb@cs.nctu.edu.tw 12345
Just print the error message. Nothing changes in Amazon S3.
Username is already used.





% register V v@cs.nctu.edu.tw bt21
Create a bucket for user V.
Register successfully.


%



%



%



%






% login Brad 12345

The client program will log in with Brad’s bucket.
Welcome, Brad.









% whoami


Nothing changes in Amazon S3.
Brad









% create-board NP_HW
Nothing changes in Amazon S3.
Create board successfully.





% create-board NP_HW
Nothing changes in Amazon S3.
Board already exist.









% list-board



Index
Name
Moderator

1
NP_HW
Brad
Nothing changes in Amazon S3.
%



%








% list-board ##HW



Index   Name
Moderator
Nothing changes in Amazon S3.
1
NP_HW   Brad




% create-post NP_HW --title NP_HW3 --content Err...<br>Ha!
Create an object to store the content of this post in Brad’s
Create post successfully.

bucket. By the way, you can name the object by yourself, but
%



there are some restrictions for object naming. Please refer to
%



the Note part.
%




%




%




%




%




%




%






% create-post NCTU --title NP_HW3 --content Uh...
Nothing changes in Amazon S3.
Board does not exist.







% create-post NP_HW --title NP_HW4 --content Wow...
Create a new post.
Create post successfully.


%




%




%




%




%




%




%




%








% list-post NP



Board does not exist.

Nothing changes in Amazon S3.
%









%








% list-post NP_HW



ID Title
Author
Date
Nothing changes in Amazon S3.
1
NP_HW3
Brad
04/14






2   NP_HW4   Brad
04/14




% list-post NP_HW ##HW3


ID
Title
Author
Date
Nothing changes in Amazon S3.
1
NP_HW3
Brad
04/14





% read 888



Post does not exist.


%



Nothing changes in Amazon S3.
%




%










% read 1



Author
:Brad

Title

:NP_HW3

Date
:2020-04-14
Get the content of post 1 from the post owner’s bucket.
--







Err...



Ha!



--





% update-post 888 --title NP HW_4
Nothing changes in Amazon S3.
Post does not exist.





% update-post 1 --title NP HW_4
The state of Amazon S3 may be unchanged. It depends on your
Update successfully.
design. But for my design, I changed the object key of that post.
%



%



%



%



%



%



%



%



%



%







% read 1



Author
:Brad

Title

:NP HW_4

Date
:2020-04-14
Get the content of post 1 from the post owner’s bucket.
--







Err...



Ha!



--





% update-post 1 --content Yeah!
Update the content of this post in Amazon S3.
Update successfully.







% read 1



Author
:Brad

Title

:NP HW_4

Date

:2020-04-14
Get the content of post 1 from the post owner’s bucket.
--



Yeah!



--







% logout


Nothing changes in Amazon S3.
Bye, Brad.











% whoami


Nothing changes in Amazon S3.





Please login first.




% logout

Nothing changes in Amazon S3.
Please login first.





% login V bt21
The client program will login with V’s bucket.
Welcome, V.







% create-post NP_HW --title Hello --content I am<br><br>V.

Create post successfully.

%


%


%


%


%


%


%




% update-post 1 --content Ha!<br>ha!
Nothing changes in Amazon S3.
Not the post owner.





% delete-post 1
Nothing changes in Amazon S3.
Not the post owner.





% comment 888 Ha ha!
Nothing changes in Amazon S3.
Post does not exist.





% comment 1 Ha ha!
The client program will append the comment to the
Comment successfully.
corresponding post object (e.g., NP_HW_4-
%

1586850747968524907 object in Brad’s bucket) in Amazon S3.



% read 1


Author
:Brad

Title
:NP HW_4

Date
:2020-04-14
Get the content of post 1 from the post owner’s bucket.
--





Yeah!


--


V:Ha ha!



% mail-to TT --subject Hi TT --content Hi <br> TT!
Nothing changes in Amazon S3.
TT does not exist.





% mail-to Brad --subject Hi Brad --content Hi <br> Brad!
User V creates two email objects in Brad’s bucket.
Sent successfully.

% mail-to Brad --subject Hey --content Hey <br>Brad!

Sent successfully.

%


%


%


%


%






% list-mail



Nothing changes in Amazon S3.
ID
Subject
From   Date









% delete-mail 1


Nothing changes in Amazon S3.
No such mail.














% retr-mail 1



Nothing changes in Amazon S3.
No such mail.














% logout



Nothing changes in Amazon S3.
Bye, V.














% login Brad 12345

The client program will login with Brad’s bucket.
Welcome, Brad.












% list-mail




ID
Subject
From Date
Nothing changes in Amazon S3.
1
Hi Brad
V
04/14






2
Hey

V
04/14






% retr-mail 1




Subject
:Hi Brad


From
:V



Date
:2020-04-14
Get the content of the mail from his bucket.
--





Hi





Brad!






% mail-to V --subject Hi V --content WoW V!
User Brad creates a mail object in V’s bucket.
Sent successfully.



%





%





%





%





%





%





%










% logout



Nothing changes in Amazon S3.
Bye, Brad.













% login V bt21


The client program will login with V’s bucket.
Welcome, V.














% list-mail



Nothing changes in Amazon S3. But note that user V has its
ID Subject   From
Date
mail id sequence number. It starts at 1.
1
Hi V

Brad
04/14






% logout



Nothing changes in Amazon S3.
Bye, V.














% login Brad 12345

The client program will login with Brad’s bucket.
Welcome, Brad.














% list-mail



ID Subject
From
Date
Nothing changes in Amazon S3.
1
Hi Brad
V
04/14






2
Hey
V
04/14





% delete-mail 1


User Brad deletes the object corresponding to his mail 1 from
Mail deleted.


his bucket.
%




%




%




%




%




%




%




%




%








% list-mail


Nothing changes in Amazon S3. But note that ID of the mail with
ID Subject From
Date



the subject “Hey” is 1.
1
Hey
V
04/14










% logout


Nothing changes in Amazon S3.
Bye, Brad.












% exit



Nothing changes in Amazon S3.









Note

    1. About bucket naming:

        ◦ Bucket names must be unique across all existing bucket names in Amazon S3.

        ◦ Bucket names must be at least 3 and no more than 63 characters long.

        ◦ Bucket names must not contain uppercase characters or underscores.

        ◦ Bucket names must start with a lowercase letter or number.

    2. About object key name:

        ◦ Unique identifier within a bucket. If you upload the same key name object without versioning-enabled, it will overwrite the original one.
        ◦ The following character sets are generally safe for use in key names.















For more details about buckets and objects, you can refer to reference [5][6]

    3. About AWS API access key:

If you want to use AWS SDK to make Amazon S3 API calls, you have to provide your AWS credential first. How to set up authentication credential:

Create a credential file at ~/.aws/credentials. The content of this file is described as follows:

[default]

aws_access_key_id=<your access key>

aws_secret_access_key=<your secret access key> aws_session_token=<your session token>


You can get these key from your AWS Educate account. Log in your account and go to Intro. to Network Programming classroom. Then, you will see the following page.



Click Account Details

Click Show and copy those keys into ~/.aws/credentials

























The credential we use here is temporary, so you have to copy and paste again when the credential expiration.



    4. About C++ AWS SDK:

To use the AWS SDK for C++, you need:

Visual Studio 2015 or later

or GNU Compiler Collection (GCC) 4.9 or later or Clang 3.3 or later

A minimum of 4 GB of RAM


So, if you currently use Amazon EC2 with instance type of t2.micro, please change to at least t2.medium. Moreover, please backup all your environment when you are running out of classroom credits. We suggest you write a script to set up your environment. It will save a lot of time.

How to change instance type:

Right-click your original instance -> Instance Settings -> Change Instance Type

    5. You can use any code examples in the Amazon S3 API documentation to manipulate your Amazon S3.

Grade (100%)

For those commands that interact with Amazon S3, we will check your Amazon S3 console. If the state of your Amazon S3 is wrong, we will deduct some scores of that command.

register command – (8%) login command – (8%)

create-post command – (8%) read command – (8%)

delete-post command – (8%) update-post command – (8%) comment command – (8%)

mail-to command – (8%) list-mail command – (8%) retr-mail command – (8%)

delete-mail command – (8%) list-post command – (5%)

logout command – (2%) exit command – (2%)

whoami command – (1%)

create-board command – (1%) list-board command – (1%)


Submission

Please upload a zip file called “hw3_{$student_id}.zip” (e.g., hw3_0856020.zip) that includes your source code. It must include at least your server source code and client source code. Submission that doesn’t follow the rule will get 20% punishment on the grade.

You will get 0 points on this project for plagiarism. Please don’t copy-paste other students’ code!

Reference

1.

2.

3.

4.

C/C++ Socket

SQLite C/C++ Interface

Linux socket SELECT

AWS SDK supported languages
5.

6.

7.

8.

9.

10.

Bucket Restrictions and Limitations

Object Key and Metadata

AWS Command Line Interface

AWS SDK for C++

AWS SDK for Python

Sequence diagram reference

More products