Message processing method and device, computer equipment and storage medium

By using quadruple information in the Linux kernel to determine the target key and find matching sockets in the socket management table, the problem of low efficiency in UDP socket search is solved and the packet processing performance is improved.

CN118972476AActive Publication Date: 2024-11-15NETEASE (HANGZHOU) NETWORK CO LTD
View PDF 8 Cites 0 Cited by

Patent Information

Application Number
CN202410951564.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-16
Publication Date
2024-11-15
Estimated Expiration
2044-07-16

AI Technical Summary

Technical Problem

The search efficiency of UDP sockets in the Linux kernel is low, resulting in poor packet processing performance, and it is necessary to traverse all sockets in the hash table to find matching sockets.

Method used

By obtaining the quadruple information in the message, determining the target key, and finding matching target sockets based on client and server endpoint information in the first socket management table, improving search efficiency.

Benefits of technology

Quickly find the corresponding socket, improves packet processing performance and reduces processing time.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118972476A_ABST
    Figure CN118972476A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a message processing method and device, computer equipment and a storage medium. According to the scheme, when the message is received, the tetrad information in the message is obtained; determining a target key corresponding to the message based on the tetrad information; according to the target key, a first target socket matched with the target key is searched from a first socket management table, and keys corresponding to all sockets in the first socket management table are obtained according to client end point information and server end point information corresponding to all sockets; and processing the message based on the first target socket. In this way, the corresponding socket can be quickly found in the message processing process, and therefore the processing performance can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a message processing method, apparatus, computer equipment and storage medium. Background Art

[0002] In the UDP (User Datagram Protocol) protocol, after receiving a message, it is necessary to find a matching UDP sock for the message, and then ensure that the message is sent to the correct destination based on the matching UDP sock. Each socket has a unique identifier in the kernel and is associated with a specific application or process.

[0003] In the related art, the Linux kernel organizes UDP socks by calculating a hash value based on the server's address and port number, and then determines the slot of the hash table (the location in the hash table used to store data) based on the hash value. UDP socks with the same hash value are inserted into the same slot of the hash table. However, since all socks in the slot are organized as a linked list, when receiving a message, it is necessary to traverse all socks in the slot to find the most suitable sock, which takes a lot of time, resulting in low search efficiency and poor performance. Summary of the invention

[0004] The embodiments of the present application provide a message processing method, apparatus, computer equipment and storage medium, which can improve processing performance.

[0005] The present application provides a message processing method, including:

[0006] Based on the four-tuple information, determine the target key corresponding to the message;

[0007] According to the target key, searching a first target socket matching the target key from a first socket management table, wherein the key corresponding to each socket in the first socket management table is obtained according to the client endpoint information and the server endpoint information corresponding to each socket;

[0008] The message is processed based on the first target socket.

[0009] Accordingly, the embodiment of the present application further provides a message processing device, including:

[0010] A first acquisition unit, configured to acquire, when receiving a message, four-tuple information in the message;

[0011] A first determining unit, configured to determine a target key corresponding to the message based on the four-tuple information;

[0012] A first search unit is used to search a first target socket matching the target key from a first socket management table according to the target key, wherein the key corresponding to each socket in the first socket management table is obtained according to the client endpoint information and the server endpoint information corresponding to each socket;

[0013] A processing unit is used to process the message based on the first target socket.

[0014] Correspondingly, an embodiment of the present application also provides a computer device, including a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor executes any message processing method provided in the embodiments of the present application.

[0015] Correspondingly, an embodiment of the present application further provides a storage medium, which stores a plurality of instructions, and the instructions are suitable for loading by a processor to execute the above message processing method.

[0016] The embodiment of the present application obtains the four-tuple information in the message when receiving the message; determines the target key corresponding to the message based on the four-tuple information; searches for the first target socket matching the target key from the first socket management table according to the target key, wherein the key corresponding to each socket in the first socket management table is obtained according to the client endpoint information and the server endpoint information corresponding to each socket; and processes the message based on the first target socket. In this way, the corresponding socket can be quickly found during the message processing, thereby improving the processing performance. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0018] Figure 1 A flowchart of a message processing method provided in an embodiment of the present application.

[0019] Figure 2 A schematic diagram of an application scenario of a message processing method provided in an embodiment of the present application.

[0020] Figure 3 A schematic diagram of an application scenario of another message processing method provided in an embodiment of the present application.

[0021] Figure 4 A schematic diagram of an application scenario of another message processing method provided in an embodiment of the present application.

[0022] Figure 5 A structural block diagram of a message processing device provided in an embodiment of the present application.

[0023] Figure 6 A schematic diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0024] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of this application.

[0025] The embodiments of the present application provide a message processing method, apparatus, storage medium and computer equipment. Specifically, the message processing method of the embodiments of the present application can be executed by a computer device, wherein the computer device can be a server or other equipment. The server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms.

[0026] For example, the computer device may be a server, which may obtain four-tuple information in a message when receiving the message; determine a target key corresponding to the message based on the four-tuple information; search a first target socket that matches the target key from a first socket management table according to the target key, wherein the key corresponding to each socket in the first socket management table is obtained according to the client endpoint information and the server endpoint information corresponding to each socket; and process the message based on the first target socket.

[0027] Based on the above problems, the embodiments of the present application provide a first message processing method, apparatus, computer device and storage medium, which can improve processing performance.

[0028] It should be noted that the description order of the following embodiments is not intended to limit the preferred order of the embodiments.

[0029] An embodiment of the present application provides a message processing method, which can be executed by a terminal or a server. The embodiment of the present application takes the message processing method executed by a server as an example for explanation.

[0030] like Figure 1 As shown, Figure 1 A schematic diagram of a message processing method provided in an embodiment of the present application. The specific process of the message processing method may be as follows:

[0031] 101. When receiving a message, obtain the four-tuple information in the message.

[0032] A message is a unit of information transmitted in computer networks and communication systems. It usually contains one or more data blocks (also called data segments or data frames) that are encapsulated together for transmission from one device (such as a computer, server, router, etc.) to another. The message contains enough information to ensure that the receiving device can correctly identify, process and respond to the sent data.

[0033] Specifically, a message may include two parts: a header and data. The header is the control information part of the message, which is used to transmit some necessary metadata; the data is the actual payload part of the message, which is used to transmit real information.

[0034] The four-tuple information in the message may include: a source IP (Internet Protocol) address, a target IP address, a source port number, and a target port number.

[0035] The source IP address refers to the IP address of the host that sends the datagram. Each computer connected to the network has a unique IP address that identifies its location in the network.

[0036] The target IP address refers to the IP address of the host that receives the datagram. This IP address determines the destination of the data packet, that is, the location where it will be delivered.

[0037] The source port number is the port number used by the application of the sending host. On a computer, different applications can communicate over the network at the same time, and each application uses a unique port number to distinguish between each other.

[0038] The destination port number is the port number used by the application of the receiving host. The destination port number tells the operating system of the receiving host which application to pass the data packet to for processing.

[0039] In an embodiment of the present application, the source IP address may be a client address; the target IP address may be a server address; the source port number may be a client port number; and the target port number may be a server port number.

[0040] For example, in a game business scenario, the client refers to the player client; the source IP address can be the address of the player client, and the source port number can be the port number of the player client; the server refers to the game server, and the target IP address can be the IP address of the game server, and the target port number can be the port number of the game server; the player client and the game server can communicate based on UDP. The UDP communication process between the player client and the game server can include the following steps:

[0041] 1) Initialization: First, create a UDP socket. Both the player client and the game server need to call the socket() function to create a UDP socket. This socket will be used for subsequent data sending and receiving. Then, bind the port. The game server needs to call the bind() function to bind the socket to the local IP address and port number in order to receive data from the client.

[0042] When creating a socket, you need to specify the address family (such as AF_INET for IPv4) and the socket type (SOCK_DGRAM for UDP).

[0043] 2) Data transmission: The player client sends data. The player client uses the sendto() function to send data to the game server. Before sending data, the client needs to know the server's IP address and port number.

[0044] Among them, the sendto() function allows the client to specify the destination address of the data (that is, the server's IP address and port number) and send the data.

[0045] Then, the game server receives the data, and the game server uses the recvfrom() function to receive the data from the client. This function can not only receive data, but also obtain the IP address and port number of the client that sent the data.

[0046] Furthermore, after receiving the data, the server will process it according to the game logic and may need to send a response to the client.

[0047] If the game server needs to send a response or data to the player client, it uses the sendto() function and specifies the client's IP address and port number as the destination address.

[0048] After receiving the data from the client, the game server will parse and process it according to the game logic. This may include verifying the validity of the data, updating the game status, etc. Finally, after processing the data, the server may need to send feedback or new game status information to the client. This is also achieved through the sendto() function.

[0049] In network communications based on the UDP protocol, after receiving a message, it is necessary to find a socket that matches the message to ensure that the message can be correctly processed and delivered to the application. This process is crucial to achieving accuracy and reliability of network communications.

[0050] Each socket has a unique identifier in the Linux kernel and is associated with a specific application or process. When the network layer receives a UDP message, the Linux kernel needs to determine which application should handle the message. By finding a matching socket, the kernel can ensure that the message is sent to the correct destination.

[0051] Among them, socket is an important concept in computer networks. It provides a programming interface that enables applications to exchange data through the network. Socket is essentially an abstraction of the endpoint for two-way communication between application processes on different hosts in the network. A socket is one end of process communication on the network, providing a corresponding mechanism for application layer processes to exchange data using network protocols. Socket connects to the application process upward and to the network protocol stack downward. It is the interface for the application to interact with the network protocol stack.

[0052] For example, in a multiplayer online game, the player client can connect to the game server through a Socket to achieve real-time game state synchronization and player interaction.

[0053] In some embodiments, in order to improve the socket search efficiency, in the step of "receiving a message", the method may further include the following steps:

[0054] In response to a socket creation event, obtaining first client endpoint information and first server endpoint information corresponding to the socket to be created;

[0055] Based on the first client endpoint information and the first server endpoint information, a socket creation event is generated to indicate the created socket, and the socket is stored in a first socket management table.

[0056] The socket creation event indicates the creation of a socket. The socket creation event is triggered before the client and the server need to communicate.

[0057] The first client endpoint information and the first server endpoint information corresponding to the socket to be created refer to the endpoint information of the first client and the first server that need to communicate based on the socket to be created.

[0058] The first client endpoint information may include: the IP address and port number of the first client; the first server endpoint information may include: the IP address and port number of the first server.

[0059] For example, the IP address of the first client may be 192.168.0.1, and the port number may be 10001, and the first client endpoint information may be (192.168.0.1 10001); the IP address of the first server may be 192.168.100.10, and the port number may be 10000, and the first server endpoint information may be (192.168.100.10 10000).

[0060] Among them, based on the first client endpoint information and the first server endpoint information, generating a socket created by a socket creation event indication may include: creating an initial socket, then binding the IP address and port number of the first server to the initial socket, and then binding the IP address and port number of the first client to the initial socket, thereby obtaining the socket created by the socket creation event indication.

[0061] Specifically, in UDP, the creation of a socket is mainly done through the socket() function, which specifies the address family (such as AF_INET for IPv4) and the socket type (SOCK_DGRAM for datagram sockets, i.e. UDP). First, an initial UDP socket is created. After the UDP socket is created, the bind() function is used to bind it to a specific local IP address and port.

[0062] When a UDP socket is ready to send data, it can call the sendto() function, which requires the destination IP address and port number to be specified. Similarly, when a UDP socket receives data, the recvfrom() function fills in a sockaddr structure, which contains the sender's IP address and port number (that is, the source IP and source port in the four-tuple).

[0063] In the embodiment of the present application, the first socket management table refers to a table in the Linux system kernel for storing and managing created sockets. Specifically, the first socket management table is used to record the corresponding relationship between the sockets of the client and the server corresponding to the message transmission. In this embodiment, the four-tuple of the UDP message, namely the source port number, the source IP address, the destination port number and the destination port number, is used as the key, and the relevant information identifying the socket is used as the key value corresponding to the key.

[0064] In some embodiments, in order to improve the lookup speed of the first socket management table, the socket management table may adopt a table with a hash structure.

[0065] Among them, the key corresponding to each socket in the first socket management table is obtained according to the client endpoint information and server endpoint information corresponding to each socket, that is, the key corresponding to the socket is determined according to the client IP address, port number, server IP address, and port number corresponding to the socket.

[0066] Specifically, a hash value is calculated for the client IP address, port number, server IP address, and port number corresponding to the socket according to a hash function, and the hash value is used as the key corresponding to the socket.

[0067] In the embodiment of the present application, for the sock organization of UDP, the IP address and port number of the client and the IP address and port number of the server are usually combined, and the hash value is calculated through a hash function to achieve efficient search and management. Among them, the main purpose of the hash value calculation is to map the variable-length input (in this case, the IP address and port number of the client and the IP address and port number of the server) to a fixed-length output so as to serve as an index of an array or a hash table.

[0068] The input parameters may include: the IP address and port number of the client, the IP address and port number of the server, wherein the IP address may include IPv4 or IPv6 format. The port number is usually a 16-bit unsigned integer.

[0069] Among them, hash functions can include addition hash, multiplication hash, division hash, bit operation hash and table lookup hash, etc.

[0070] In the embodiment of the present application, the first socket management table may include multiple storage modules, and different storage modules store sockets corresponding to different keys. That is, a storage module may store at least one socket corresponding to the same key.

[0071] In some embodiments, the first socket management table may be a hash table, and the storage module in the first socket management table may be a bucket in the hash table, and each bucket is composed of elements with the same hash value (i.e., key value). Therefore, the search of the hash table is to first locate the bucket according to the hash value, and then search for the elements that meet the conditions in the bucket. The calculation of the hash value is calculated by passing the hash function into the matching domain.

[0072] The hash value is an integer greater than or equal to 0.

[0073] Specifically, a bucket in a hash table is a unit used by the hash table to store data, and is also the actual container for data storage. In a hash table, a bucket maps a keyword (key) to a specific location in the table through a hash function to achieve fast access and search of data. Each bucket corresponds to a unique address (Bucket Address). In a hash table, a bucket is the basic unit of data storage. Through a hash function, a keyword is mapped to a corresponding bucket for fast access to data.

[0074] Among them, storing the socket in the first socket management table can include, according to the first client endpoint information (client IP address and port number) and the first server endpoint information (server IP address and port number) corresponding to the socket, calculating the hash value through a hash function as a key, then determining the bucket corresponding to the key from the first socket management table, and finally storing the socket in the bucket.

[0075] For example, see Figure 2 , Figure 2 A schematic diagram of an application scenario of a message processing method provided in an embodiment of the present application. Figure 2 The method of storing the corresponding socket in the first socket management table according to the four-tuple information of the network message is shown. Specifically, it can include: calculating the hash value according to the address and port of the client and the address and port of the server corresponding to each network message, determining the storage module matching the hash value from the first socket management table according to the hash value, and then storing the socket in the matching storage module.

[0076] Among them, the four-tuple information of the first network message may include: the address and port of client 1, and the address and port of the server; the four-tuple information of the second network message may include: the address and port of client 2, and the address and port of the server; the four-tuple information of the third network message may include: the address and port of client 3, and the address and port of the server; the four-tuple information of the nth network message may include: the address and port of client n, and the address and port of the server. Since the addresses and ports of different clients are different, the hash values ​​calculated according to the four-tuple information of each network message are different, and the sockets corresponding to each network message can be stored in different modules of the first socket management table.

[0077] For example, the hash value calculated according to the quadruple information of the first network message corresponds to the storage module 1 of the first socket management table, and the socket corresponding to the quadruple information of the first network message can be stored in the storage module 1; the hash value calculated according to the quadruple information of the second network message corresponds to the storage module 2 of the first socket management table, and the socket corresponding to the quadruple information of the second network message can be stored in the storage module 2; the hash value calculated according to the quadruple information of the third network message corresponds to the storage module 3 of the first socket management table, and the socket corresponding to the quadruple information of the third network message can be stored in the storage module 3; the hash value calculated according to the quadruple information of the nth network message corresponds to the storage module n of the first socket management table, and the socket corresponding to the quadruple information of the nth network message can be stored in the storage module n.

[0078] For example, there are four tuples of information corresponding to four player clients: (because they are all UDP, they do not contain protocols), assuming that the hash function is hash(x). Among them, the source address (S), source port (SP), destination address (D), destination port (DP), hash(S, SP, D, DP). Among them, the tuple information of player client 1 is (192.168.0.1 10001

[0079] 192.168.100.10 10000), the four-tuple information of player client 2 is (192.168.0.210002192.168.100.10 10000), the four-tuple information of player client 3 is (192.168.0.3 10003192.168.100.10 10000), and the four-tuple information of player client 4 is (192.168.0.4 10004192.168.100.10 10000) 。

[0080] The hash value is calculated based on the four-tuple, hash (S, SP, D, DP). Since the source address (S) and source port (SP) corresponding to each player client are different, the calculated hash values ​​corresponding to each player client can be different. For example, assuming that the calculated hash value corresponding to player client 1 is 11, the hash value corresponding to player client 2 is 12, the hash value corresponding to player client 3 is 13, and the hash value corresponding to player client 4 is 14, the sockets corresponding to each player client will be stored in four different buckets. Therefore, when searching later, the corresponding tuple can be used to calculate the hash, which may directly locate the specific bucket and speed up the query of the socket.

[0081] The specific hash value calculated based on the quaternary group mainly depends on the design of the adopted hash function, and different hash functions may have different calculation methods.

[0082] In some embodiments, the step of “obtaining, in response to a socket creation event, first client endpoint information and first server endpoint information corresponding to a socket to be created” may include the following operations:

[0083] In response to the socket creation event, searching for a message processing object;

[0084] In the message processing object, the preset connection function is replaced with the target connection function by replacing the function pointer;

[0085] Execute the target connection function to obtain the first client endpoint information and the first server endpoint information corresponding to the socket to be created.

[0086] Among them, the message processing object refers to an object udp_prot encapsulated by the Linux kernel for UDP message processing. The message processing object contains the function pointers and configuration information required for UDP protocol processing. These function pointers point to functions that handle operations such as sending, receiving, and error handling of UDP data packets. For example, the message processing object can at least include a preset connection function, which can be: udp->connect function. The preset connection function is a function that can be called when a udp connection is used. The udp->connect function is the final calling function when the user mode calls the connect system call.

[0087] Specifically, the functions of the connect function in UDP can include: address and port binding. By calling the connect function, the UDP socket can be bound to a specific remote address and port. That is, if the socket is connected, all data packets sent through the socket will be automatically sent to the specified remote address and port, without having to specify them each time they are sent.

[0088] Replacing a function pointer refers to changing a pointer to a specific function to point to another function with the same signature. This allows the calling behavior of a function to be changed dynamically at runtime or compile time.

[0089] Among them, the execution logic of the target connection function may include: when the user program calls the connect function, the destination IP address and destination port passed in by connect are combined with the local bind IP address (source address) and source port as a key of the udp socket. In addition, when the connect is called, the actual storage address of the udp socket can be obtained from the Linux system kernel, and this actual storage address is used as another key of the udp socket. Both keys correspond to the same udp socket. Then, based on the two keys, the same udp socket will be put into two hash tables, one is the uslk table (also known as the first socket management table, which is used to find the socket according to the four-tuple information of the message when receiving the message), and the other is the uslksock table (also known as the third socket management table, which is used to clean up the socket when closing the socket).

[0090] The actual storage address of the udp socket refers to the address of the kernel's native UDP Socket, which can be an identifier composed of an IP address and a port number.

[0091] In an embodiment of the present application, replacing a preset connection function with a target connection function by replacing a function pointer may include: modifying the member function pointer connect of the message processing object to uslk_datagram_connect (that is, the target connection function). That is, replacing the callback function interface udp_prot of the message processing object. Replacing the preset connection function with the target connection function by replacing the function pointer does not bring any additional consumption, and is basically the same as the execution process before the modification. By directly replacing the function pointer in the Linux kernel, the purpose of executing a custom function and bypassing the original function can be achieved.

[0092] 102. Based on the four-tuple information, determine the target key corresponding to the message.

[0093] The four-tuple information includes: client address, client port, server address and server port.

[0094] In some embodiments, the step of “determining the target key corresponding to the message based on the four-tuple information” may include the following operations:

[0095] The client address, client port, server address and server port are mapped to a fixed-length output through a preset hash function to obtain the target key.

[0096] Specifically, the client address, client port, server address and server port are input into a preset hash function, and the hash value is calculated by the preset hash function, that is, an output of a fixed length is obtained, which can be used as a target key for searching for the socket corresponding to the message.

[0097] 103. According to the target key, search the first socket management table for a first target socket that matches the target key.

[0098] The first socket management table stores a plurality of created sockets.

[0099] In some embodiments, in order to improve the socket search speed, the step of "searching for a first target socket matching the target key from the first socket management table according to the target key" may include the following operations:

[0100] Determine a target storage module corresponding to the target key from multiple storage modules;

[0101] A socket matching the four-tuple information is determined from the sockets in the target storage module to obtain a first target socket.

[0102] The first socket management table may include multiple storage modules, and different storage modules store sockets corresponding to different keys. That is, one storage module may store at least one socket corresponding to the same key.

[0103] First, the target key may be matched with the keys corresponding to the various storage modules, and the storage module corresponding to the key that successfully matches the target key may be determined as the target storage module corresponding to the target key.

[0104] For example, the first socket management table includes: storage module 1, storage module 2, storage module 3, and storage module 4, etc. Among them, the key value corresponding to storage module 1 may be: 11, the key corresponding to storage module 2 may be: 12, the key corresponding to storage module 3 may be: 13, and the key corresponding to storage module 4 may be: 14. If the target key may be 11, it can be determined that the target storage module corresponding to the target key may be: storage module 1.

[0105] Among them, determining the socket that matches the four-tuple information from the socket in the target storage module can include: matching the four-tuple information of the message with the four-tuples corresponding to each socket in the target storage module (that is, the client IP address, port, and the server IP address, port), and determining the socket corresponding to the four-tuple that successfully matches the four-tuple information of the message as the first target socket.

[0106] In some embodiments, the step of “searching the first target socket matching the target key from the first socket management table according to the target key” may include the following operations:

[0107] Find the message processing object;

[0108] Replace the empty instructions of the preset search function with jump instructions;

[0109] A jump instruction of a preset search function is executed to jump to the target search function to search for a first target socket matching the target key from the first socket management table according to the target key.

[0110] The message processing object may further include a preset search function, which may be: udp4_lib_lookup function.

[0111] Specifically, the udp4_lib_lookup function is a function in the Linux kernel that is used to find a socket that matches a given condition in the UDP socket table. This function is an important part of the UDP protocol stack when processing received packets, especially when determining which user space application the packet should be passed to.

[0112] Among them, the main function of the udp4_lib_lookup function is to search in the UDP socket table according to the provided parameters (such as source IP address, source port number, destination IP address, destination port number, etc.) to find a socket that matches these parameters. Once a matching socket is found, the function usually returns a pointer to the socket for subsequent data packet delivery and processing operations.

[0113] The search call stack of udp sock (also known as udp socket) is: udp_rcv->_udp4_lib_rcv->_udp4_lib_lookup_skb->_udp4_lib_lookup. Among them, udp_rcv is the callback function interface of the kernel object udp_prot.

[0114] The call stack is a stack used in computer science to store messages about running subroutines. It uses a Last-In-First-Out (LIFO) data structure, that is, the last called function will be processed first.

[0115] Function: Stores information such as the return address of the subroutine to ensure that the program can correctly track function calls and returns.

[0116] Among them, udp_rcv is used to receive datagrams arriving at the UDP socket to process the UDP data received from the network. The specific execution steps may include: receiving UDP datagrams from the network interface or network layer. These datagrams may usually include the source port, destination port, length and actual user data; decapsulating the received datagram to extract the user data and related information (such as the source IP address and port); searching for the corresponding UDP socket in the list of local sockets according to the destination port in the datagram. If a matching socket is found, the next step is carried out; if not found, the datagram may be discarded, an ICMP port unreachable message may be sent, or other processing may be performed according to the specific situation; the decapsulated user data is passed to the matching UDP socket so that the application can read it. This usually involves putting the data into the socket's receive buffer and may trigger some events or callbacks to notify the application that the data has arrived.

[0117] Among them, udp4_lib_rcv is one of the core functions in the Linux kernel that processes IPv4 UDP packets. This function is called after receiving IPv4 UDP packets and is responsible for further processing these packets, including verification, socket search, data delivery, etc.

[0118] During the reception and processing of UDP packets, the udp4_lib_rcv function (or other similar functions) calls udp4_lib_lookup_skb to find a matching socket. Once a matching socket is found, the udp4_lib_rcv function calls other functions (such as udp_queue_rcv_skb) to put the data packet into the socket's receive queue, waiting for the user space application to read it.

[0119] If a function pointer is used to replace udp_rcv, then the multiple search logics implemented in udp_rcv need to be rewritten, and a large modification range is very likely to introduce defects. Therefore, the embodiment of the present application provides a solution with a small modification range to implement the hook (a technology or mechanism that allows developers to insert their own code into a specific execution point of a program without modifying the original code to monitor, modify or extend the program behavior) effect of the udp4_lib_lookup function, that is, to achieve it through the ftrace framework.

[0120] Among them, the Ftrace framework is a powerful tracing and debugging tool in the Linux kernel, which is mainly used to track and record function calls during kernel runtime. Ftrace is designed to help kernel designers and developers track the function call flow within the system. In addition to tracking function calls, it can also be used to debug and analyze system latency and performance issues.

[0121] Specifically, Ftrace uses static instrumentation and dynamic instrumentation to implement it. Static instrumentation can include:

[0122] CONFIG_FUNCTION_TRACER function, and add -pg compilation option, insert bl mcount jump instruction for each function entry in the kernel. In this way, when the function is called, it will first jump to the mcount function for recording; dynamic stubs can include: In order to reduce performance overhead, Dynamic Ftrace is introduced. At compile time, although jump instructions are inserted for all functions, the kernel will replace these jump instructions with nop (no operation) instructions. When a function needs to be traced, the nop instruction is replaced back to the jump instruction by dynamically modifying the instruction.

[0123] In the embodiment of the present application, the principle of using the ftrace framework is:

[0124] The first five nop instructions of the _udp4_lib_lookup function are replaced with jump instructions. Then, when the first five bytes of the function are executed, it will jump to the implemented function, thus achieving the purpose of hooking. ftrace will use the text_poke interface to replace the first five nop instructions of the function with jump instructions. Before executing the function body, it will execute the instruction to jump to the target search function. After execution, it will return directly, bypassing the original function execution.

[0125] The text_poke interface is a function interface provided by the Linux kernel to modify existing code segments in the kernel. This interface allows developers to dynamically modify the code in the kernel at runtime without recompiling and loading the entire kernel.

[0126] In the embodiment of the present application, text_poke is called to modify the instruction code of the first five bytes of the incoming udp4_lib_lookup function address into a jump instruction, which was originally 5 nops (null instructions).

[0127] For example, see Figure 3 , Figure 3 A schematic diagram of an application scenario of another message processing method provided in an embodiment of the present application. Figure 3 The function execution flow of this solution in the process of searching for a socket is shown.

[0128] Among them, the receiving function refers to: udp_rcv function; the first processing function refers to: udp4_lib_rcv function; the second processing function refers to: udp4_lib_lookup_skb function; the preset search function refers to: udp4_lib_lookup function; the jump function refers to: fentry function; the tracking module refers to: ftrace framework; the instruction replacement module refers to: uslk_stub; the target search function refers to: uslk_udp4_lib_lookup function; the hook function refers to: hook function;

[0129] Among them, the fentry function can be used to call the registered callback function uslk_stub;

[0130] uslk_stub can be used to modify the address of the executed instruction; the hook function, also known as the hook function, refers to a function called when a specific event occurs, and is used to perform some specific operations before or after the event occurs; the uslk_udp4_lib_lookup function can be used to trigger the search for a socket based on the quadruple information.

[0131] Specifically, when a message is received, udp_rcv can be called, the udp4_lib_lookup_skb function is called through udp4_lib_rcv, and then the udp4_lib_lookup function is called through the udp4_lib_lookup_skb function, and the fentry function is called through the udp4_lib_lookup function, which triggers the execution of the first 5 executions of the udp4_lib_lookup function and jumps to ftrace.

[0132] Among them, ftrace is called. There is a fentry function call at the beginning of the udp4_lib_lookup function. This function is implemented by the ftrace framework. Originally, the first five bytes are nop instructions. When the uslk module is loaded, the first byte is replaced by a jump instruction, and the next four bytes are replaced by the offset of the ftrace function. After the jump is executed, the control is handed over to ftrace.

[0133] Then, ftrace calls the callback function uslk_stub implemented by the uslk module. There is a simple logic in uslk_stub, which is to modify the value of the instruction register %rip in the pt_regs structure to uslk_udp4_lib_lookup.

[0134] Among them, %rip is the 64-bit instruction pointer register in the x86-64 architecture, which is used to store and update the address of the currently executed instruction. By modifying the value of the instruction register %rip, the function is to modify the instruction register to the target search function (uslk_udp4_lib_lookup), that is, the next instruction executed is the first instruction of the uslk_udp4_lib_lookup function.

[0135] Further, the callback function uslk_udp4_lib_lookup implemented by the uslk module is executed, that is, the udp sock is first searched from the custom uslk_table table (the first socket search table) based on the four-tuple. If it is found, it returns, and the whole call is completed.

[0136] In some embodiments, in order to find a socket matching the message, the method may further include the following steps:

[0137] If the first target socket is not found in the first socket management table, a socket matching the binary information of the message is searched in the second target socket management table as the first target socket.

[0138] In the embodiment of the present application, the second target socket management table refers to a table in the Linux system kernel for storing and managing created sockets. Specifically, the second target socket management table is used to record the corresponding relationship between the sockets of the client and the server corresponding to the message transmission. In this embodiment, the tuple of the UDP message, i.e., the destination port number and the destination port number, is used as the key, and the relevant information identifying the socket is used as the key value corresponding to the key.

[0139] In some embodiments, in order to improve the lookup speed of the second target socket management table, the socket management table may adopt a table with a hash structure.

[0140] Among them, the key corresponding to each socket in the second target socket management table is obtained according to the server endpoint information corresponding to each socket, that is, the key corresponding to the socket is determined according to the server IP address and port number corresponding to the socket.

[0141] Specifically, a hash value is calculated for the server IP address and port number corresponding to the socket according to a hash function, and the hash value is used as the key corresponding to the socket.

[0142] Among them, storing the socket in the second target socket management table can include, according to the second server endpoint information (server IP address and port number) corresponding to the socket, calculating the hash value through a hash function as a key, then determining the bucket corresponding to the key from the second target socket management table, and finally storing the socket in the bucket.

[0143] For example, see Figure 4 , Figure 4 A schematic diagram of an application scenario of another message processing method provided in an embodiment of the present application. Figure 4 The method of storing the corresponding socket in the first socket management table according to the binary information of the network message is shown. Specifically, it may include: calculating the hash value according to the address and port of the server corresponding to each network message, determining the storage module matching the hash value from the second target socket management table according to the hash value, and then storing the socket in the matching storage module.

[0144] Among them, the binary information of the first network message may include: the address and port of the server; the binary information of the second network message may include: the address and port of the server; the binary information of the third network message may include: the address and port of the server; the binary information of the nth network message may include: the address and port of the server. Since the address and port of the server corresponding to each network message are the same, the hash values ​​calculated according to the binary information of each network message are the same, and the sockets corresponding to each network message can be stored in the same storage module of the second target socket management table.

[0145] Among them, searching for a socket that matches the binary information of the message from the second target socket management table may include: determining, from multiple storage modules of the second target socket management table, a storage module corresponding to a key generated according to the binary information of the message; and then determining, from the sockets in the storage module, a socket that matches the binary information as the first target socket.

[0146] In some embodiments, in order to retain multiple socket search methods, the step of "searching a socket matching the binary information of the message from the second target socket management table as the first target socket" may include the following operations:

[0147] The preset search function is called by the target search function, and the preset search function is executed to search for a socket matching the binary information of the message from the second target socket management table as the first target socket.

[0148] For example, see Figure 3If uslk_udp4_lib_lookup does not find the udp sock, it continues to call the original function udp4_lib_lookup to execute the original search logic (that is, to search for the socket according to the two-tuple information of the message).

[0149] In an embodiment of the present application, in order to prevent recursive calls, when initializing and registering the original callback function original, the udp4_lib_lookup function address can be offset by 5 bytes and then assigned to the original member of ftrace_hook, so that no recursive call problem occurs when uslk_udp4_lib_lookup calls the original function.

[0150] Among them, the original callback function original, that is, udp4_lib_lookup. In the line of sight logic of the uslk_udp4_lib_lookup function, first quickly find the udp sock from the uslk table (the first socket lookup table) based on the four-tuple of the message. If it is found, it returns. If it is not found, it will call the original kernel function, that is, udp4_lib_lookup, to do a slow search for the udp sock from the original udp table (that is, the second target socket lookup table).

[0151] 104. Process the message based on the first target socket.

[0152] Wherein, the message is processed based on the first target socket, and the message can be sent to the destination port of the destination IP address through the first target socket, that is, sent to the correct target application for processing, so that the target application can read the data in the message for processing.

[0153] In some embodiments, the method may further include the following steps:

[0154] In response to the socket closing event, searching the third socket management table for a second target socket corresponding to the socket closing event;

[0155] The second target socket is cleared in the third socket management table.

[0156] The socket close event indicates closing the socket and cleaning up the socket. The socket close event may be triggered after the client communicates with the service segment.

[0157] The key corresponding to each socket in the third socket management table is obtained according to the actual storage address corresponding to each socket.

[0158] In the embodiment of the present application, the third socket management table refers to a table in the Linux system kernel for cleaning up created sockets. In this embodiment, the actual storage address of the socket is used as a key, and the relevant information identifying the socket is used as the key value corresponding to the key.

[0159] Among them, searching for the second target socket corresponding to the socket closing event from the third socket management table may include: obtaining the actual storage address corresponding to the socket closing event, generating a key based on the actual storage address, and then searching for the socket corresponding to the key from the third socket lookup table as the second target socket.

[0160] Specifically, when the user-mode program calls close (triggering a socket closing event), the socket corresponding to the sock address can be found in the third socket management table based on the sock address of close (that is, the actual storage address of the second target socket), and the socket can be cleaned up.

[0161] In some embodiments, the step of “in response to the socket closing event, searching the third socket management table for the second target socket corresponding to the socket closing event” may specifically include the following operations:

[0162] Get the first address of the socket that needs to be closed as indicated by the socket close event;

[0163] Based on the first address, a socket matching the first address is searched in the third socket management table to obtain a second target socket.

[0164] The socket closing event may include an actual storage address indicating the socket to be closed (ie, the address of the kernel native UDP Socket), and the actual storage address may be obtained as the first address.

[0165] Furthermore, the first address is matched with addresses corresponding to each socket in the third socket management table to determine a socket that successfully matches the first address, thereby obtaining a second target socket.

[0166] In some embodiments, the step of “in response to the socket closing event, searching the third socket management table for the second target socket corresponding to the socket closing event” may include the following operations:

[0167] In response to the socket closing event, searching for a message processing object;

[0168] In the message processing object, the preset closing function is replaced with the target closing function by replacing the function pointer;

[0169] The target connection function is executed to search the third socket management table for the second target socket corresponding to the socket closing event.

[0170] The message processing object may also include a preset close function, which may be a udp_prot->unhash function, which is a function called when the socket is closed. The udp_prot->unhash function is the final call function when the user mode calls the close system call.

[0171] Specifically, the functions of the unhash function in UDP may include: closing the socket.

[0172] In an embodiment of the present application, replacing a preset close function with a target close function by replacing a function pointer may include: modifying the member function pointer unhash of the message processing object to uslk_udp_lib_unhash (i.e., the target close function). That is, replacing the callback function interface udp_prot of the message processing object. Replacing the preset close function with the target close function by replacing the function pointer does not bring any additional consumption, and is basically the same as the execution process before the modification. By directly replacing the function pointer in the Linux kernel, the purpose of executing a custom function and bypassing the original function can be achieved.

[0173] The embodiment of the present application discloses a message processing method, which includes: when receiving a message, obtaining four-tuple information in the message; based on the four-tuple information, determining the target key corresponding to the message; according to the target key, searching for a first target socket matching the target key from a first socket management table, wherein the key corresponding to each socket in the first socket management table is obtained according to the client endpoint information and the server endpoint information corresponding to each socket; and processing the message based on the first target socket. In this way, the corresponding socket can be quickly found during the message processing process, thereby improving the processing performance.

[0174] In order to better implement the message processing method provided in the embodiment of the present application, the embodiment of the present application also provides a message processing device based on the above message processing method. The meanings of the terms are the same as those in the above message processing method, and the specific implementation details can refer to the description in the method embodiment.

[0175] See also Figure 5 , Figure 5 A structural block diagram of a message processing device provided in an embodiment of the present application, the device comprising:

[0176] The first acquisition unit 301 is used to acquire the quadruple information in the message when receiving the message;

[0177] A first determining unit 302, configured to determine a target key corresponding to the message based on the four-tuple information;

[0178] A first search unit 303 is used to search for a first target socket matching the target key from a first socket management table according to the target key, wherein the key corresponding to each socket in the first socket management table is obtained according to the client endpoint information and the server endpoint information corresponding to each socket;

[0179] The processing unit 304 is configured to process the message based on the first target socket.

[0180] In some embodiments, the first socket management table includes multiple storage modules, and different storage modules store sockets corresponding to different keys; the first search unit 303 may include:

[0181] A first determining subunit, configured to determine a target storage module corresponding to the target key from the plurality of storage modules;

[0182] The second determining subunit is used to determine a socket matching the four-tuple information from the sockets in the target storage module to obtain the first target socket.

[0183] In some embodiments, the first search unit 303 may include:

[0184] A first search subunit, used to search for a message processing object, wherein the message processing object at least includes a preset search function;

[0185] A first replacement subunit, used for replacing the empty instruction of the preset search function with a jump instruction;

[0186] The first execution subunit is used to execute the jump instruction of the preset search function, jump to the execution target search function, and search for the first target socket matching the target key from the first socket management table according to the target key.

[0187] In some embodiments, the apparatus may further include:

[0188] A second search unit is used to search for a socket that matches the binary information of the message from the second target socket management table as the first target socket if the first target socket is not found in the first socket management table, wherein the key corresponding to each socket in the second target socket management table is obtained according to the server endpoint information corresponding to each socket.

[0189] In some embodiments, the second search unit may include:

[0190] The second execution subunit is used to call the preset search function through the target search function, execute the preset search function, and search for a socket matching the binary information of the message from the second target socket management table as the first target socket.

[0191] In some embodiments, the apparatus may further include:

[0192] A second acquisition unit, configured to acquire, in response to a socket creation event, first client endpoint information and first server endpoint information corresponding to a socket to be created;

[0193] A generating unit is used to generate a socket created by the socket creation event indication based on the first client endpoint information and the first server endpoint information, and store the socket in the first socket management table.

[0194] In some embodiments, the second acquiring unit may include:

[0195] A second search subunit, configured to search for a message processing object in response to the socket creation event, wherein the message processing object at least includes a preset connection function;

[0196] A second replacement subunit is used to replace the preset connection function with a target connection function in the message processing object by replacing a function pointer;

[0197] The third execution subunit is used to execute the target connection function to obtain the first client endpoint information and the first server endpoint information corresponding to the socket to be created.

[0198] In some embodiments, the apparatus may further include:

[0199] a third search unit, configured to search, in response to a socket close event, a second target socket corresponding to the socket close event from a third socket management table, wherein a key corresponding to each socket in the third socket management table is obtained according to an actual storage address corresponding to each socket;

[0200] A cleaning unit is used to clean up the second target socket in the third socket management table.

[0201] In some embodiments, the third search unit may include:

[0202] A third search subunit, configured to search for a message processing object in response to the socket closing event, wherein the message processing object at least includes a preset closing function;

[0203] A third replacement subunit is used to replace the preset closing function with a target closing function in the message processing object by replacing a function pointer;

[0204] The fourth execution subunit is used to execute the target connection function to search the third socket management table for the second target socket corresponding to the socket closing event.

[0205] In some embodiments, the third search unit may include:

[0206] An acquisition subunit, used for acquiring a first address of a socket that needs to be closed as indicated by the socket closing event;

[0207] The fourth search subunit is used to search for a socket matching the first address from a third socket management table based on the first address to obtain the second target socket.

[0208] In some embodiments, the four-tuple information includes: client address, client port, server address and server port; the first determination unit 302 may include:

[0209] The mapping subunit is used to map the client address, the client port, the server address and the server port into a fixed-length output through a preset hash function to obtain the target key.

[0210] The embodiment of the present application discloses a message processing device, wherein the first acquisition unit 301 acquires the four-tuple information in the message when receiving the message; the first determination unit 302 determines the target key corresponding to the message based on the four-tuple information; the first search unit 303 searches the first target socket matching the target key from the first socket management table according to the target key, wherein the key corresponding to each socket in the first socket management table is obtained according to the client endpoint information and the server endpoint information corresponding to each socket; the processing unit 304 processes the message based on the first target socket. In this way, the processing performance can be improved.

[0211] Accordingly, the embodiment of the present application also provides a computer device, which may be a server. Figure 6 As shown, Figure 6A schematic diagram of the structure of a computer device provided in an embodiment of the present application. The computer device 400 includes a processor 401 having one or more processing cores, a memory 402 having one or more computer-readable storage media, and a computer program stored in the memory 402 and executable on the processor. The processor 401 is electrically connected to the memory 402. It will be understood by those skilled in the art that the computer device structure shown in the figure does not constitute a limitation on the computer device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.

[0212] The processor 401 is the control center of the computer device 400. It uses various interfaces and lines to connect the various parts of the entire computer device 400, executes various functions of the computer device 400 and processes data by running or loading software programs and / or modules stored in the memory 402, and calling data stored in the memory 402, thereby monitoring the computer device 400 as a whole.

[0213] In the embodiment of the present application, the processor 401 in the computer device 400 will load instructions corresponding to the processes of one or more application programs into the memory 402 according to the following steps, and the processor 401 will run the application programs stored in the memory 402 to implement various functions:

[0214] When receiving a message, obtain the four-tuple information in the message;

[0215] Based on the four-tuple information, determine the target key corresponding to the message;

[0216] According to the target key, searching the first target socket matching the target key from the first socket management table, wherein the key corresponding to each socket in the first socket management table is obtained according to the client endpoint information and the server endpoint information corresponding to each socket;

[0217] The message is processed based on the first target socket.

[0218] The embodiment of the present application obtains the four-tuple information in the message when receiving the message; determines the target key corresponding to the message based on the four-tuple information; searches for the first target socket matching the target key from the first socket management table according to the target key, wherein the key corresponding to each socket in the first socket management table is obtained according to the client endpoint information and the server endpoint information corresponding to each socket; and processes the message based on the first target socket. In this way, the corresponding socket can be quickly found during the message processing process, thereby improving the processing performance.

[0219] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.

[0220] Optional, such as Figure 6 As shown, the computer device 400 further includes: a touch screen 403, a radio frequency circuit 404, an audio circuit 405, an input unit 406, and a power supply 407. The processor 401 is electrically connected to the touch screen 403, the radio frequency circuit 404, the audio circuit 405, the input unit 406, and the power supply 407, respectively. Those skilled in the art can understand that Figure 6 The computer device structure shown in the figure does not constitute a limitation on the computer device, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.

[0221] The touch display screen 403 can be used to display a graphical user interface and receive operation instructions generated by the user acting on the graphical user interface. The touch display screen 403 may include a display panel and a touch panel. Among them, the display panel may be used to display information input by the user or information provided to the user and various graphical user interfaces of the computer device, and these graphical user interfaces may be composed of graphics, text, icons, videos and any combination thereof. Optionally, the display panel may be configured in the form of a liquid crystal display (LCD, Liquid Crystal Display), an organic light emitting diode (OLED, Organic Light-Emitting Diode) and the like. The touch panel may be used to collect the user's touch operation on or near it (such as the user using any suitable object or attachment such as a finger, a stylus, etc. on the touch panel or near the touch panel), and generate corresponding operation instructions, and the operation instructions execute corresponding programs. Optionally, the touch panel may include two parts, a touch detection device and a touch controller. Among them, the touch detection device detects the user's touch orientation, detects the signal brought by the touch operation, and transmits the signal to the touch controller; the touch controller receives the touch information from the touch detection device, converts it into the touch point coordinates, and then sends it to the processor 401, and can receive the command sent by the processor 401 and execute it. The touch panel can cover the display panel. When the touch panel detects a touch operation on or near it, it is transmitted to the processor 401 to determine the type of touch event, and then the processor 401 provides a corresponding visual output on the display panel according to the type of touch event. In an embodiment of the present application, the touch panel and the display panel can be integrated into the touch display screen 403 to realize the input and output functions. However, in some embodiments, the touch panel and the touch panel can be used as two independent components to realize the input and output functions. That is, the touch display screen 403 can also be used as a part of the input unit 406 to realize the input function.

[0222] In the embodiment of the present application, the processor 401 executes the game application to generate a graphical user interface on the touch screen 403. The virtual scene on the graphical user interface includes at least one skill control area, and the skill control area includes at least one skill control. The touch screen 403 is used to present the graphical user interface and receive operation instructions generated by the user acting on the graphical user interface.

[0223] The radio frequency circuit 404 may be used to send and receive radio frequency signals, so as to establish wireless communication with a network device or other computer devices through wireless communication, and to send and receive signals between the network device or other computer devices.

[0224] The audio circuit 405 can be used to provide an audio interface between the user and the computer device through a speaker and a microphone. The audio circuit 405 can transmit the electrical signal converted from the received audio data to the speaker, which is converted into a sound signal for output; on the other hand, the microphone converts the collected sound signal into an electrical signal, which is received by the audio circuit 405 and converted into audio data, and then the audio data is output to the processor 401 for processing, and then sent to another computer device through the radio frequency circuit 404, or the audio data is output to the memory 402 for further processing. The audio circuit 405 may also include an earphone jack to provide communication between an external headset and the computer device.

[0225] The input unit 406 may be used to receive input numbers, character information or user feature information (such as fingerprint, iris, facial information, etc.), and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control.

[0226] The power supply 407 is used to supply power to various components of the computer device 400. Optionally, the power supply 407 can be logically connected to the processor 401 through a power management system, so that the power management system can manage charging, discharging, and power consumption. The power supply 407 can also include one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, power status indicators, and other arbitrary components.

[0227] although Figure 6 Not shown, the computer device 400 may also include a camera, a sensor, a wireless fidelity module, a Bluetooth module, etc., which will not be described in detail here.

[0228] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0229] As can be seen from the above, the computer device provided in this embodiment can obtain the four-tuple information in the message when receiving the message; determine the target key corresponding to the message based on the four-tuple information; according to the target key, search the first target socket matching the target key from the first socket management table, wherein the key corresponding to each socket in the first socket management table is obtained according to the client endpoint information and the server endpoint information corresponding to each socket; and process the message based on the first target socket.

[0230] A person of ordinary skill in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be completed by instructions, or by controlling related hardware through instructions. The instructions may be stored in a computer-readable storage medium and loaded and executed by a processor.

[0231] To this end, an embodiment of the present application provides a computer-readable storage medium, in which multiple computer programs are stored, and the computer program can be loaded by a processor to execute the steps in any message processing method provided in the embodiment of the present application. For example, the computer program can execute the following steps:

[0232] When receiving a message, obtain the four-tuple information in the message;

[0233] Based on the four-tuple information, determine the target key corresponding to the message;

[0234] According to the target key, searching the first target socket matching the target key from the first socket management table, wherein the key corresponding to each socket in the first socket management table is obtained according to the client endpoint information and the server endpoint information corresponding to each socket;

[0235] The message is processed based on the first target socket.

[0236] The embodiment of the present application obtains the four-tuple information in the message when receiving the message; determines the target key corresponding to the message based on the four-tuple information; searches for the first target socket matching the target key from the first socket management table according to the target key, wherein the key corresponding to each socket in the first socket management table is obtained according to the client endpoint information and the server endpoint information corresponding to each socket; and processes the message based on the first target socket. In this way, the corresponding socket can be quickly found during the message processing process, thereby improving the processing performance.

[0237] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.

[0238] The storage medium may include: a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.

[0239] Since the computer program stored in the storage medium can execute the steps in any message processing method provided in the embodiments of the present application, the beneficial effects that can be achieved by any message processing method provided in the embodiments of the present application can be achieved. Please refer to the previous embodiments for details and will not be repeated here.

[0240] The above is a detailed introduction to a message processing method, device, storage medium and computer equipment provided in the embodiments of the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for technical personnel in this field, according to the ideas of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A message processing method, characterized in that: The method comprises: When receiving a message, obtaining the four-tuple information in the message; Based on the four-tuple information, determine the target key corresponding to the message; According to the target key, searching a first target socket matching the target key from a first socket management table, wherein the key corresponding to each socket in the first socket management table is obtained according to the client endpoint information and the server endpoint information corresponding to each socket; The message is processed based on the first target socket.

2. The method according to claim 1, characterized in that The first socket management table includes a plurality of storage modules, and different storage modules store sockets corresponding to different keys; The step of searching, according to the target key, a first target socket matching the target key from a first socket management table comprises: Determine, from the multiple storage modules, a target storage module corresponding to the target key; A socket matching the four-tuple information is determined from the sockets in the target storage module to obtain the first target socket.

3. The method according to claim 1, characterized in that The step of searching, according to the target key, a first target socket matching the target key from a first socket management table comprises: Searching for a message processing object, wherein the message processing object at least includes a preset search function; Replacing the empty instruction of the preset search function with a jump instruction; The jump instruction of the preset search function is executed to jump to the execution target search function to search for a first target socket matching the target key from a first socket management table according to the target key.

4. The method according to claim 3, characterized in that The method further comprises: If the first target socket is not found in the first socket management table, a socket matching the tuple information of the message is searched in the second target socket management table as the first target socket, wherein the key corresponding to each socket in the second target socket management table is obtained according to the server endpoint information corresponding to each socket.

5. The method according to claim 4, characterized in that The step of searching the second target socket management table for a socket that matches the binary information of the message as the first target socket comprises: The preset search function is called by the target search function, and the preset search function is executed to search for a socket matching the binary information of the message from the second target socket management table as the first target socket.

6. The method according to claim 1, characterized in that Before receiving the message, the method further includes: In response to a socket creation event, obtaining first client endpoint information and first server endpoint information corresponding to the socket to be created; Based on the first client endpoint information and the first server endpoint information, a socket created as indicated by the socket creation event is generated, and the socket is stored in the first socket management table.

7. The method according to claim 6, characterized in that The step of obtaining, in response to a socket creation event, first client endpoint information and first server endpoint information corresponding to a socket to be created includes: In response to the socket creation event, searching for a message processing object, wherein the message processing object at least includes a preset connection function; In the message processing object, the preset connection function is replaced with a target connection function by replacing a function pointer; The target connection function is executed to obtain the first client endpoint information and the first server endpoint information corresponding to the socket to be created.

8. The method according to claim 1, characterized in that The method further comprises: In response to a socket closing event, searching a third socket management table for a second target socket corresponding to the socket closing event, wherein a key corresponding to each socket in the third socket management table is obtained according to an actual storage address corresponding to each socket; The second target socket is cleared in the third socket management table.

9. The method according to claim 8, characterized in that In response to the socket closing event, searching the third socket management table for a second target socket corresponding to the socket closing event includes: In response to the socket closing event, searching for a message processing object, wherein the message processing object at least includes a preset closing function; In the message processing object, the preset closing function is replaced with the target closing function by replacing the function pointer; A target connection function is executed to search a third socket management table for a second target socket corresponding to the socket closing event.

10. The method according to claim 8, characterized in that In response to the socket closing event, searching the third socket management table for a second target socket corresponding to the socket closing event includes: Obtaining a first address of a socket that needs to be closed as indicated by the socket close event; Based on the first address, a socket matching the first address is searched in a third socket management table to obtain the second target socket.

11. The method according to claim 1, characterized in that: The four-tuple information includes: client address, client port, server address and server port; The determining, based on the four-tuple information, a target key corresponding to the message includes: The client address, the client port, the server address and the server port are mapped to an output of fixed length through a preset hash function to obtain the target key.

12. A message processing device, characterized in that: The device comprises: A first acquisition unit, configured to acquire, when receiving a message, four-tuple information in the message; A first determining unit, configured to determine a target key corresponding to the message based on the four-tuple information; A first search unit is used to search a first target socket matching the target key from a first socket management table according to the target key, wherein the key corresponding to each socket in the first socket management table is obtained according to the client endpoint information and the server endpoint information corresponding to each socket; A processing unit is used to process the message based on the first target socket.

13. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the message processing method according to any one of claims 1 to 11 is implemented.

14. A storage medium, characterized in that: The storage medium stores a plurality of instructions, and the instructions are suitable for being loaded by a processor to execute the message processing method according to any one of claims 1 to 11.

Citation Information

Patent Citations

  • Message transmission method and device

    CN103986647A

  • Load balancing method and device supporting QUIC connection migration and computer product

    CN112653740A

  • UDP message distribution method and equipment and storage medium

    CN113132356A

  • Data processing method and device, server and storage medium

    CN114697411A

  • Local area network node data interaction method, medium and system

    CN116781803A