3 connection modes in content sharing app
Description:
There is a content sharing app.
A user can create a content as owner
, then others may connect to the content as guest
.
A content can be connected up to N
clients concurrently.
Each client belongs to a user, a user may have multiple clients.
And there are 3 modes to check the N
limit:
- 0 (multi): each user can connect to a content with multiple clients concurrently.
- 1 (single refuse new): each user can only connect to a content with up to 1 client concurrently, a 2nd client of the user will be refused.
- 2 (single kick out old): each user can only connect to a content with up to 1 client concurrently, the user's 2nd client will kick out the user's previous client first, and get connected.
There are several special design to make the app works reasonable:
- The
owner
can always connect to it's own content, if not yet, evenN
is reached.
Because the owner might need to maintain the content, (if you can't connect to your own content, that's weird, right?).
That means there might be up toN+1
connections, if the owner connects as the last user. - In mode
2 (single kick out old)
, since a user's 2nd client will kick out its old client first; thus should always allow the user's 2nd client to connect, (aka. no need to check the maxN
again for the 2nd client). - In mode
2 (single kick out old)
,kick out
happens before check ofN
limit.
The content server knows:
- The upper limit
N
. - The owner of each content.
- Full list of connected clients for a content, and which user each client represents.
When a client try to connect to a content, the server will call function IsNeedCheckMaxConn(mode, isUserConnected, isOwner)
to decide whether need to check the N
limit for this client, (true -> pass, false -> refuse).
The task is to implement the function IsNeedCheckMaxConn()
.
Tips:
- There are 12 cases, you need to pass each of them.
Think about each of the cases 1 by 1. - In mode
1 (single refuse new)
, refuse happens first, if user already connected, before check max limit.
(BTW: the solution & logic is taken from a real project where client & server are connected via websocket, the logic is tested, and works well so far.)
Similar Kata:
Stats:
Created | Jun 15, 2022 |
Published | Jun 15, 2022 |
Warriors Trained | 31 |
Total Skips | 7 |
Total Code Submissions | 67 |
Total Times Completed | 3 |
Go Completions | 3 |
Total Stars | 0 |
% of votes with a positive feedback rating | 0% of 1 |
Total "Very Satisfied" Votes | 0 |
Total "Somewhat Satisfied" Votes | 0 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 2 |
Average Assessed Rank | 8 kyu |
Highest Assessed Rank | 7 kyu |
Lowest Assessed Rank | 8 kyu |