The architecture of the IM server

Source: Internet
Author: User

first, the overall framework structure:As shown, the current system is divided into six modules, respectively, network/Protocol resolution module, user account Management module, message processing module, action processing module, Data equalization Processing module, Customer status Processing module. The normal process should be implemented in such a way that a network/Protocol parsing module is run on one or several threads, and then he is distributed to the specific command processing module based on the specific package type, and each specific command processing module should run at least separate threads. As can be seen from the above structure diagram, wherein the customer status module and the network/Protocol resolution module are common modules, the other modules are almost dependent on these two modules. At present, because many functions are not implemented, such as not implementing offline messages, so only the user account management module is related to the database.second, the specific function of each module description
1. User account Management module:
The module manages all actions based on the user account: The following: Create user, delete user, modify user data, modify user password, get user's personal information, get friends list, login, log out, request authentication string, create group, join group, leave group. All of the above operations, in addition to creating users do not need to login, any other operations must be logged in the user, so there must be a login operation before the next operation, this rule for all commands are. Describe the login process:
The client sends the command request to obtain the authentication string--〉 Network/Protocol parsing module forwards the client request and its user flag to the user account management module--〉 the user account Management module automatically generates a random authentication string, while the client's user flag is saved in the list (in the list, the data can only be saved for one minute, More than the deletion, so the client must use this authentication string in one minute to login), while the authentication string by the network/Protocol resolution module sent to the client--〉 client to the user name and authentication string, user name, password a new string of MD5 together to the server request login--〉 Network/ The Protocol parsing module forwards the client request and its user flag to the user account management module--〉 the user account Management module first checks the list for the user's flag data, if any, continue--〉 remove the user name and password from the database, and then remove the authentication string from the list, generate MD5, see if it is consistent, If consistent, the login succeeds, the server generates the session encryption key, and all subsequent session information with the server takes this key to encrypt and decrypt the--〉 Network/Protocol resolution module sends the result to the client, if successful--〉 the network/Protocol resolution module to the user The flags and session encryption keys are saved in the Customer status module. 2. Network/Protocol Resolution module:
The network parsing module should keep a cache of the most recent logged-in user list, which should hold the IP and port, as well as the encryption key, when it was last accessed. Users in the list will be removed from the list if they have not accessed for a certain amount of time (for example, one minute). The main purpose of this list is to quickly find the logged-in user (so that frequent access to the server user login check does not need to cluster customer Status module query, improve efficiency), if not found in this list, then to the Customer status module lookup, if found, the user is added to this list. If it is not found, it is not a line. Any time a user's message is received, the last access time data in the cache of the logged in user list is updated, if the user is not in the list, but the final check has been logged, add. And the heartbeat command should not affect user data for this list. However, the heartbeat command affects the Customer status list. The network parsing module should keep a list of user flag mappings (or directly combine their data addresses), map the IP address and port of the client to a specific unique client flag value, and then this value will be used as the flag for the client, and any action on the client by each specific module is based on this flag. There are four of functions
First, according to the different types of the datagram decryption (if need to decrypt) distributed to the specific processing modules. Before distributing, first check whether the user is logged in, and if not, tell the client an error directly. For the new user, the login command, the command to get the authentication string does not need to check whether it has landed.
Second, processing the relevant messages yourself, the current processing of messages including heartbeat messages and client requests to establish direct-attached commands, and any packet format is not correct or the wrong version of the case, the module itself is processed.
Third, the status of the user when sending messages to the Customer status module, which includes the user's unique flag. If the address has been modified while the user is sending the message, the unique flag must remain intact, but the user address data in the user's flag list must be modified accordingly.
Finally, packets sent by each module to the client are encrypted (if needed) processed and sent to the client. 3. Customer Status Module:
The function of the module is as follows:
First, save and operate all current online user information, including the user's login time, user logo, user status (stealth, etc.), user account. provided to other modules to query whether a user is logged in.
Second, to deal with the message of getting online friends, if you receive this command, use the user account Management module to find the list of friends, and find the current list of online users, and then get the online friends list.
Third, to handle the user status change command, if you receive the user's status change message (such as login, logout, stealth, etc.), then find the user's online friends list, and then notify each.
Iv. If the user's message is not received for a long time, it is assumed that the user is disconnected because of an unexpected reason, and is automatically considered to be logged out. When no message needs to be sent, the client sends a heartbeat command to the server periodically, telling the server that the client is online and that the user is disconnected if the heartbeat information is not received for a period of time.
Save and manipulate the online group information. Provides other modules with the ability to get a list of users in a particular group or scene. 4. Message Processing module:
Handles all message forwarding, including group messages, friend messages.
For a friend message, the message processing module first checks whether a friend is online through the customer status module, sends a friend message past if it is online, and does not send it if it is not on the line.
For a group message, if it is for a normal group message, a list of online users of that group is obtained through the customer status module, and then the message is sent to everyone except themselves.
If it is a public message in the scene, first check the location of the user's scene, and then calculate a list of users who can hear the other users in the scene, and then send a message to everyone. The computed algorithm refers to the coordinates of each scene user, where the user in a particular scenario does not participate in the operation, unless the user is involved in the same particular scene.
Note: For scenario messages, you cannot send and receive scene messages if the client is not logged in as a scene. In addition to the above message, there are advertising messages, the system messages outside the client can be accepted outside, strangers cannot send messages to each other, if the server accepts this column message, it must be ignored and no reply is sent. 5. Action Processing module:
Handles all scene actions, which are logged only by the scene user to send and receive action commands. The server receives the user's action commands, calculates the list of people who can be seen in the scene where the user is located, and then sends a command to the user. The computed algorithm refers to the coordinates of each scene user, where the user in a particular scenario does not participate in the operation, unless the user is involved in the same particular scene. The module holds a user's position and action status table (including whether or not it is in a particular scene), saves the user's coordinates and the last action state information of the scene user's scene. Once the scene user logs in, the location must be sent to the server for each update, and the location coordinate data is not required for heartbeat and action information.

6. Data Equalization Processing module:
The module is mainly designed for distributed processing, server load balancing, the main issue of network server Redirection command, for these commands, all clients must handle, because once the server issued this command, the server no longer save the user information.
Currently the module is not implemented.

The architecture of the IM server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.