Data communication protocol implementation method, apparatus, and system
Through dynamic library injection and library function hook technology, transparent replacement of network communication protocols is realized, and the problem of poor compatibility after protocol replacement in the prior art is solved, and unsensed communication protocol replacement is realized.
Patent Information
- Application Number
- PCT/CN2024/073797
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-07-28
- Filing Date
- 2024-01-24
- Publication Date
- 2025-02-06
AI Technical Summary
The prior art is difficult to realize transparent replacement of network communication protocols, resulting in applications that cannot be compatible with other applications that follow the old communication protocol after replacing the network communication protocol.
By injecting the target dynamic library into the target application, it takes over the network IO-related library functions and based on these library function hooks, a new protocol is used to replace the target application's initial protocol.
It realizes transparent replacement of the application communication protocol, without modifying code or recompiling the target application, and has no perception to the user.
Smart Images

Figure CN2024073797_06022025_PF_FP_ABST
Abstract
Description
Data communication protocol implementation method, device, and system
[0001] CROSS-REFERENCE TO RELATED APPLICATIONS
[0002] This patent application claims priority to the Chinese patent application filed on July 28, 2023, with application number 202310942784.9 and invention name “Data Communication Protocol Implementation Method, Device, and System”. The full text of the application is incorporated into this application by reference. Technical Field
[0003] The present disclosure relates to the field of computer technology, specifically to the field of communication technology, and more particularly to a method, device, and system for implementing a data communication protocol. Background Art
[0004] In related technologies, replacing the network communication protocol of an application requires modifying the application source code. Moreover, once the original network communication protocol of the application is replaced, it is difficult to make it compatible with other applications that follow the old communication protocol and access this application at the same time. It is impossible to achieve a "transparent" replacement effect of the network communication protocol, that is, there is no need to modify the code or recompile the target application, and the user is not aware of it.
[0005] Summary of the Invention
[0006] Embodiments of the present disclosure provide a data communication protocol implementation method, apparatus, system, device, and storage medium.
[0007] In one or more embodiments, the present disclosure provides a data communication protocol implementation method, which includes: injecting a target dynamic library into a target application to take over network IO related library functions; based on the network IO related library function hook, using a new protocol to replace the initial protocol of the target application.
[0008] In one or more embodiments, the present disclosure provides a data communication protocol implementation device, which includes: an injection module, configured to inject a target dynamic library into a target application to take over network IO related library functions; a replacement module, configured to replace the initial protocol of the target application with a new protocol based on the network IO related library function hook.
[0009] In one or more embodiments, the present disclosure provides a data communication protocol implementation system, which includes: a first communication subject and a second communication subject that communicate with each other based on an initial protocol; the first communication subject is used to inject a first dynamic library into a first application to take over network IO related library functions; based on a network IO related library function hook, a new protocol is used to replace the initial protocol of the first application; the second communication subject is used to inject a second dynamic library into a second application to take over network IO related library functions; based on a network IO related library function hook, a new protocol is used to replace the initial protocol of the second application.
[0010] In one or more embodiments, the present disclosure provides an electronic device comprising one or more processors; a storage device storing one or computer instructions, wherein when the one or more computer instructions are executed by the one or more processors, the one or more processors implement the data communication protocol implementation method as in the above-mentioned method embodiment.
[0011] In one or more embodiments, the present disclosure provides a non-transitory computer-readable storage medium having computer instructions stored thereon. When the computer instructions are executed by a processor, the data communication protocol implementation method in the above method embodiment is implemented.
[0012] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] FIG1A is an architectural diagram of an embodiment of a data communication protocol implementation system according to the present disclosure;
[0014] FIG1B is a flow chart of an embodiment of a data communication protocol implementation system according to the present disclosure;
[0015] FIG1C is a flow chart of one embodiment of a data communication protocol implementation system according to the present disclosure;
[0016] FIG1D is a flow chart of one embodiment of a data communication protocol implementation system according to the present disclosure;
[0017] FIG1E is a flow chart of one embodiment of a data communication protocol implementation system according to the present disclosure;
[0018] FIG1F is a flow chart of one embodiment of a data communication protocol implementation system according to the present disclosure;
[0019] FIG1G is a flow chart of one embodiment of a data communication protocol implementation system according to the present disclosure;
[0020] FIG1H is a flow chart of one embodiment of a data communication protocol implementation system according to the present disclosure;
[0021] FIG. 1I is a flow chart of an embodiment of a data communication protocol implementation system according to the present disclosure;
[0022] FIG1J is a flow chart of one embodiment of a data communication protocol implementation system according to the present disclosure;
[0023] FIG1K is a flow chart of an application scenario of a data communication protocol implementation system according to the present disclosure;
[0024] FIG2 is an architecture diagram of an application scenario of a data communication protocol implementation system according to the present disclosure;
[0025] FIG3 is a flow chart of an embodiment of a method for implementing a data communication protocol according to the present disclosure;
[0026] FIG4 is a flow chart of an embodiment of a data communication implementation apparatus according to the present disclosure;
[0027] FIG5 is a schematic diagram of the structure of a computer system suitable for implementing a server according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0028] The following description of exemplary embodiments of the present disclosure is made in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding. These details should be considered as merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0029] It should be noted that, in the absence of conflict, the embodiments and features of the embodiments in the present disclosure can be combined with each other. The present disclosure will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0030] 1A shows an architecture 100 of a data communication protocol implementation system applicable to the present disclosure. In this embodiment, the data communication protocol implementation system includes a first communication subject and a second communication subject that communicate with each other based on an initial protocol.
[0031] The first communication subject and the second communication subject may be two communication subjects that communicate in accordance with any communication protocol (eg, a connection-oriented protocol, a connectionless protocol, a data stream protocol, a datagram protocol, a reliable protocol, an unreliable protocol, etc.).
[0032] The first communication subject may inject the first dynamic library into the first application to take over the network IO-related library functions and replace the initial protocol of the first application with a new protocol based on the network IO-related library function hook or the callback interface of the network IO-related library function hook. In other words, the dynamic library injection method is used to replace the initial protocol with the new protocol.
[0033] The second communication subject injects the second dynamic library into the second application to take over the network IO-related library functions and replaces the initial protocol of the second application with the new protocol based on the network IO-related library function hook or the callback interface of the network IO-related library function hook. In other words, the dynamic library injection method is used to replace the initial protocol with the new protocol.
[0034] The first dynamic library and the second dynamic library are the same.
[0035] The data communication protocol implementation system of the disclosed embodiment realizes transparent replacement of application communication protocols through dynamic library injection.
[0036] After the new protocol is replaced, the first communication subject and the second communication subject can communicate based on the new protocol.
[0037] Here, for a connection-oriented protocol, the IO-related library functions may be socket, bind, listen, accept, recv, send, and close; for a connectionless protocol, the IO-related library functions may be recv and send, sendmsg, and recvmsg, etc.
[0038] Among them, the new protocol and the initial protocol can both be connection protocols, such as the TCP protocol, etc., the new protocol and the initial protocol can also both be connectionless protocols, such as the UDP protocol, etc., the new protocol and the initial protocol can both be data stream protocols or datagram protocols, the new protocol and the initial protocol can also both be reliable protocols or unreliable protocols, and this disclosure does not limit this.
[0039] Here, dynamic library injection is used to indicate that the code in the dynamic library is injected into the target application by loading the dynamic library into the application, so that this part of the code is executed by the application, or the original code in the application is dynamically replaced with the injected code (the injected code is also called a code "hook").
[0040] The dynamic library injected into the application can override the code of the application itself or the code of the dynamic library that the application depends on, which is not limited in this disclosure.
[0041] Specifically, in Linux systems, you can specify the environment variable "LD_PRELOAD" to set the dynamic library to be preloaded when starting the application; when the client or server application starts, the specified dynamic library will be loaded into the memory address space of the process before the application is executed. The relevant code is as follows:
[0042] Server
[0043] LD_PRELOAD= / my / dir / newprotocol.so server
[0044] Client
[0045] LD_PRELOAD= / my / dir / newprotocol.so client
[0046] Here, when the application is started, the execution entity may inject the dynamic library into the application in various specific ways, such as inline injection, overlay injection, etc.
[0047] Among them, inline injection is used to indicate that the code is injected directly into the original code location, thereby "hijacking" the original code; overlay injection is used to indicate that the function pointer in the function jump table or symbol table is overwritten and redirected to the target function.
[0048] Here, the object of overlay injection can be the application itself or a library function that the application depends on.
[0049] In some optional embodiments, the first communication subject is used to execute the library function of the new client protocol when initiating a connection; the second communication subject is used to execute the library function of the new server protocol when monitoring the connection establishment.
[0050] In this implementation, the new protocol is a client / server architecture communication protocol, that is, a client / server architecture communication protocol, that is, a CS architecture communication protocol. The first communication subject is the client and the second communication subject is the server. The first communication subject is used to execute the library function of the client's new protocol when initiating a connection; the second communication subject is used to execute the library function of the server's new protocol when listening for connection establishment.
[0051] Specifically, when the initial network protocol is based on monitoring and connection establishment, the monitoring and connection establishment operation is replaced by overloading the bind, listen, and accept functions on the server side and overloading the connect function on the client side.
[0052] After the connection is established, the server and client perform data transmission based on the overloaded send and recv functions.
[0053] This implementation method implements the connection establishment function between the first communication subject and the second communication subject in accordance with the communication protocol of the client / server architecture by executing the library function of the new client protocol when initiating a connection; and the second communication subject executes the library function of the new server protocol when listening for connection establishment.
[0054] In some optional manners, the server is configured to simultaneously monitor connection establishment requests of the original protocol and the new protocol, and perform data transmission based on the new protocol or the initial protocol.
[0055] In this implementation, the server can monitor the connection requests of the original protocol and the new protocol at the same time. If a connection request of the new protocol is monitored, data transmission is performed based on the new protocol. If a connection request of the initial protocol is monitored, data transmission is performed based on the initial protocol, thereby achieving compatibility with the two monitoring and connection operations.
[0056] In some optional methods, connection establishment requests of the original protocol and the new protocol are monitored simultaneously, and data transmission is performed based on the new protocol or the initial protocol, specifically including: configuring a monitoring specified context structure, for the monitoring specified context structure, in response to determining that there is a monitoring socket indicating that a new connection request has arrived, creating a target specified context structure corresponding to the monitoring socket, and filling the first address field in the target specified context structure with the address and port of the other end; in response to determining that the target specified context structure is a new protocol specified context structure and the sending or receiving state is ready, data transmission is performed between the client and the client based on the address and port of the other end in the first address field.
[0057] In this implementation, for a new protocol that is a client / server architecture communication protocol, the execution subject may pre-configure a listening specified context structure based on a callback interface of a network IO related library function hook.
[0058] The monitoring specified context structure includes a new protocol monitoring socket, an initial protocol monitoring socket and a second address. The second address (such as sock_addr) is used to store the bound address and the monitoring port.
[0059] Furthermore, in response to determining that a listening socket exists in the new protocol listening socket or the initial protocol listening socket, indicating that a new connection request has arrived, the server creates a target specified context structure corresponding to the listening socket, and fills the first address field (such as peer_addr) in the target specified context structure with the address and port of the other end.
[0060] The target specified context structure is a new protocol specified context structure or an initial protocol specified context structure.
[0061] Here, the listening specified context structure, the new protocol specified context node and the initial protocol specified context structure are different types of specified context structures. The listening specified context structure, the new protocol specified context node and the initial protocol specified context structure have the same data structure as the specified context structure, but use different fields. The listening specified context structure, the new protocol specified context node and the initial protocol specified context structure are respectively used to maintain different types of socket descriptors.
[0062] Among them, the specified context structure, such as the context structure named "SockFd", can include: FD (used to store the socket file descriptor), flags: used to store the socket status mark (such as: NON_BLOCKING, etc.), the first address field (used to store the peer address and port of the established socket), the new protocol listening socket field (used to store the new protocol listening socket), the initial protocol listening socket field (used to store the new protocol listening socket), and the second address field (used to store the bound address and listening port), as shown in Figure 1B.
[0063] Here, it should be noted that the new protocol can be any client / server architecture communication protocol, such as the TCP protocol, etc., and this disclosure does not limit this.
[0064] Furthermore, if the new protocol is a KCP protocol using a UDP link as the transport layer, the listening socket is a UDP listen socket, and the specified context structure may also include a KCP field for storing a KCP connection context pointer. Specifically, if the new protocol listening socket is a UDP listen socket, after filling in the second address field, the execution entity must also create a KCP context for it and bind it to the KCP ID in the connection request packet, thereby achieving KCP communication pairing.
[0065] Furthermore, if the new protocol is the KCP protocol and the initial protocol is the TCP protocol, both are connection-oriented protocols. The KCP protocol communication-related functions are socket, bind, listen, accept, recv, send, and close. The server can create a socket through the socket function; take over the binding operation to the listening port through the callback interface of the bind function hook; take over the listening operation through the callback interface of the listen function hook; take over the operation of accepting new connection requests from the listening socket through the callback interface of the accept function hook; and take over the operation of initiating a connection from the client through the callback interface of the connect library function hook.
[0066] Specifically, as shown in Figure 1C, in the callback of the library function socket hook, it is determined whether the socket type requested to be created by the application is the initial protocol type of the application, such as TCP. If so, the system call SYS_socket is executed to create a socket descriptor, and the specified context structure is created with this socket descriptor as the key, and the specified context structure is stored in the SockFd table, that is, the specified context structure table; if not, the control is returned to the system native library function, and the operation logic of the native library function is followed.
[0067] Furthermore, as shown in FIG1D , in the callback of the library function bind hook, the socket descriptor is searched in the SockFd table. If found, the initial protocol listening socket, i.e., the TCP listening socket, is created, and the system call SYS_bind is executed to bind the initial protocol address and port. If the binding fails, an error code is returned and the error is processed. If the binding is successful, a new protocol listening socket, i.e., the UDP listening socket, is created, and the system call SYS_bind is executed to bind the new protocol port. If the binding is successful, the second address field sock_addr of the specified context structure SockFd is set with the passed-in second address sock_addr to obtain the listening specified context structure. If the binding fails, an error code is returned and the error is processed.
[0068] 1E , in the callback of the library function accept hook, the socket descriptor is searched in the SockFd table. If found, the POLLIN state of the TCP listening socket is judged, and whether there is a new connection is determined. If so, the system call SYS_accept is executed to create a server-side TCP socket, and whether the TCP connection is successful is determined. If so, a TCP specified context structure corresponding to the TCP listen socket is created, namely TCP SockFd, and stored in the SockFd table. The socket FD of the server-side TCP connection is returned. If the TCP connection is not successful, an error code is returned and the error is processed. If there is no new connection, the POLLIN state of the UDP listening socket is judged, and whether there is a new connection request packet. If so, the system call SYS_recv is executed to receive the connection request packet from the UDP listening socket, and whether the connection request packet is valid. If valid, the system call SYS_socket is executed to create a server-side UDP socket and SockFd, create a KCP context for SockFd, set KCP->kcp_id = connection request ID, that is, create a UDP specified context structure, namely UDP SockFD further determines whether the KCP connection is successful. If successful, it stores the UDP SockFD in the SockFd table and returns the UDP socket FD for the new KCP connection. If it fails, it returns an error code and handles the error. If there is no new connection request packet or the connection request packet is invalid, it returns "New connection not ready".
[0069] In addition, for the listen library function, its callback process is shown in Figure 1F. Specifically, the socket descriptor is searched in the SockFd table. If found, the SYS_listen system call is called for the TCP listen socket in the SockFd, and it is determined whether the Listen is successful. If successful, the operation is successful. If failed, an error code is returned and the error is handled.
[0070] Furthermore, if the target specified context structure is a new protocol specified context structure, and the sending state or receiving state is ready, that is, there is free space in the sending buffer or the received data is cached in the receiving buffer, that is, POLLOUT is valid or POLLIN is valid, then the send library function hook and the recv library function hook can be further utilized to send and receive data with the client based on the address and port of the other end recorded in the first address field.
[0071] Specifically, taking the new protocol as the KCP protocol that uses the UDP link as the transport layer and the initial protocol as the TCP protocol as an example, as shown in Figure 1G, in the callback of the library function send hook, the socket descriptor is searched in the SockFd table. If not found, the control is handed over to the native library function. If found, the KCP connection status is checked, and it is determined whether the KCP is not connected or closed. If so, an error code is returned and the error is processed. If not, the KCP sending interface is called. Further, it is determined whether the KCP sending window is full. If so, an error code is returned and the error is processed. If not, the actual number of bytes sent is returned.
[0072] As shown in Figure 1H, in the callback of the library function recv hook, the socket descriptor is searched in the SockFd table. If not found, the control is handed over to the native library function. If found, the KCP connection status is checked and it is determined whether the KCP is not connected. If so, an error code is returned and the error is processed. If not, it is further determined whether the KCP is closed. If so, 0 is returned to indicate that the other end is closed. If not, the KCP receive data interface is called and it is determined whether there is no data in the KCP receive buffer. If so, an error code is returned and the error is processed. If not, the actual number of bytes received is returned.
[0073] In addition, after the data transmission is completed, it is necessary to close the communication based on the network IO related library function hook.
[0074] Specifically, as shown in Figure 1I, the initial protocol is the TCP protocol, and the target protocol is the KCP protocol that uses the UDP link as the transport layer. In the callback of the library function close hook, the socket descriptor is searched in the SockFd table. If not found, the control is handed over to the native library function. If found, the key value is deleted from the SockFd table, and it is determined whether the type of SockFD, that is, the specified context structure, is the UDP type. If so, the KCP connection is closed, SockFd is released, and the system call SYS_close is executed to close the socket descriptor. If SockFD is not of UDP type, SockFd is directly released and the system call SYS_close is executed to close the socket descriptor.
[0075] This implementation method configures a specified context structure. For a listening specified context structure, in response to determining that there is a listening socket indicating that a new connection request has arrived, a target specified context structure corresponding to the listening socket is created, and the first address field in the target specified context structure is filled with the address and port of the other end. In response to determining that the target specified context structure is a new protocol specified context structure and the sending or receiving state is ready, data is transmitted between the client based on the address and port of the other end in the first address field, thereby achieving support for the initial protocol and the new protocol.
[0076] In some optional embodiments, the server configures a callback interface for library function calls to monitor whether the specified context structure indicates that a new connection request has arrived, whether the new protocol specified context structure is ready for receiving and sending.
[0077] In this implementation, the server can configure a callback interface to detect whether the specified context structure indicates that a new connection request has arrived, that is, POLLIN is valid, whether the new protocol specifies whether the receiving state of the context structure is ready, that is, POLLIN is valid, and whether the sending state is ready, that is, POLLOUT is valid, that is, to detect the poll state for calling library function hooks such as poll / select / epoll_wait.
[0078] Specifically, as shown in Figure 1J, taking the application's initial protocol as TCP and the new protocol as UDP as an example, the socket descriptor is searched in the SockFd table. If found, the type of the designated context structure corresponding to the socket descriptor, i.e., the SockFd type, is further determined. If it is a listening designated context structure, the TCP listen socket is determined to be ready. If so, POLLIN is returned. If not, the UDP listen socket is determined to be readable. If so, POLLIN is returned. If not, 0 is returned to indicate that there is no ready event. Furthermore, if the designated context structure type is the new protocol designated context structure, i.e., the UDP designated context structure, the KCP is determined to be unopened or closed. If so, an error code is returned and the error is handled. If not, the KCP interface is called to check the send / receive window status and determine whether both send / receive windows are not ready. If so, 0 is returned to indicate that there is no ready event. If not, the POLLIN state or the POLLOUT state is returned. If the designated context structure type is the initial protocol designated context structure, i.e., the TCP designated context structure, control is returned.
[0079] This implementation improves the timeliness of detecting connection requests by configuring a callback interface for library function calls to monitor whether the specified context structure indicates that a new connection request has arrived, whether the new protocol specified context structure is ready to receive, and whether the send status is ready.
[0080] In some optional embodiments, the server is further configured to, in response to determining that the new protocol is a communication protocol of a client / server architecture, receive a connection establishment request sent by a client of the new protocol based on a network IO related library function hook.
[0081] In this embodiment, if the new protocol is a client / server communication protocol, the server can receive a connection request from a client of the new protocol based on a callback interface of a network IO related library function hook, i.e., receive a connection request from a client initiated by dynamic injection.
[0082] Here, the specified dynamic library can be injected into the client application in advance to take over the network IO related library functions, such as the connect library function. Furthermore, a new protocol connection request packet is sent to the server's new protocol listening port through the callback interface of the network IO related library function hook to initiate a new protocol connection request.
[0083] Specifically, as shown in Figure 1K, the new protocol is the KCP protocol. On the client side of the KCP protocol, the callback process of the connect library function hook is as follows: search for the socket descriptor in the client SockFd table. If found, assign a new KCP connection ID, create a KCP context, and set KCP->kcp_id = new connection ID, that is, configure the client's new protocol specified context structure UDP SockFd. Further, send a connection request packet and determine whether the connection is successful. If successful, return the operation success. If failed, return the operation code and handle the error.
[0084] Here, the peer_addr field in UDP SockFd is filled with the server's network address and listening port.
[0085] In some optional embodiments, the server is further configured to, in response to determining that the target specified context structure is the initial protocol specified context structure, control the network IO operation according to the corresponding operation logic in the initial protocol.
[0086] In this implementation, if the target specified context structure is the initial protocol specified context structure, the control of the network IO operation is returned to the corresponding operation logic in the initial protocol, that is, the network IO operation is controlled according to the corresponding operation logic in the initial protocol, so that the application still supports the original communication protocol, that is, the initial protocol, and can communicate with the client that supports the initial protocol.
[0087] In some optional embodiments, a global lock-free hash table is configured to store the listening-specified context structure, the new protocol-specified context structure, and the initial protocol-specified context structure.
[0088] In this implementation, the server may configure a global lock-free hash table to store the listening specified context structure, the new protocol specified context structure, and the initial protocol specified context structure.
[0089] Here, the monitoring specified context structure, the new protocol specified context structure, and the initial protocol specified context structure are respectively used to maintain different socket descriptors. The global lock-free hash table can use the socket descriptor as the key value to index the specified context structure.
[0090] Among them, a lock-free hash table is a multi-threaded safe hash table, mostly implemented using atomic operations such as CAS. Because no locking is required during concurrent access, its concurrency performance is better than that of a regular hash table with locks.
[0091] Here, CAS is a hardware synchronization primitive provided by a processor (CPU) that supports concurrency. The CAS operation consists of three operands, namely the memory location (V), the expected original value (A), and the new value (B), written as CAS(V,A,B). If the value of the memory location matches the expected original value, the processor will automatically update the location value to the new value. Otherwise, the processor does nothing. In either case, it will return the value of the location before the CAS instruction. Atomic operations implemented based on the CAS mechanism often use a CAS loop: that is, if the CAS operation fails (that is, the expected original value A and the value stored in the memory location V are not equal), the CAS operation will be repeatedly attempted in a loop until the operation succeeds.
[0092] This implementation method configures a global lock-free hash table to store the monitoring specified context structure, the new protocol specified context structure and the initial protocol specified context structure, thereby speeding up the search speed of the specified context structure.
[0093] Continuing to refer to FIG. 2 , FIG. 2 is an architecture diagram of an application scenario of the data communication protocol implementation system according to this embodiment.
[0094] In the application scenario of Figure 2, the initial protocol is the TCP / IP protocol, and the new protocol is the KCP protocol (i.e., an RUDP protocol) that uses the UDP protocol as the network transport layer. The server injects the target dynamic library into the second application to take over network IO related library functions, such as socket, bind, listen, accept, send, recv and other library functions. For the KCP client, the target dynamic library is injected into the first application to take over network IO related library functions, such as socket, connect, send, recv and other library functions. Based on the callback interface of the network IO related library function hook, the server uses the new protocol to replace the initial protocol of the second application. Furthermore, the server can pre-configure the listening specified context structure, i.e., Listen SockFd, based on the callback interface of the network IO related library function hook, and the specified context structure is used to maintain the socket descriptor. For the listening specified context structure, in response to determining that there is a listening socket indicating that a new connection request has arrived, a target specified context structure corresponding to the listening socket is created, and the first address field in the target specified context structure is filled with the address and port of the other party. In response to determining that the target specified context structure is a new protocol specified context structure, namely TCP SockFd, and the sending or receiving state is ready, data transmission is performed between the client and the client based on the address and port of the other party in the first address field.
[0095] The KCP protocol is an open-source ARQ (Automatic Repeat ReQuest) transport layer protocol with reliability. It was designed to address the slow transmission speed of the TCP protocol under network congestion. KCP strives to improve transmission speed while ensuring reliability. Its focus is on controlling data reliability and improving transmission speed. Therefore, it does not specify the underlying transport protocol (most KCP-based implementations use UDP as the underlying transport protocol). KCP-layer protocol packets add a control header to the underlying transport protocol datagram. Because data transmission delay in the network is variable, the time for timeout retransmission is difficult to predict. To detect packet loss as early as possible, KCP introduces a fast retransmit mechanism. Compared to the TCP protocol, KCP's fast retransmit mechanism improves transmission performance by 20% in weak network environments (such as those with severe delay jitter or high packet loss rates) at the expense of approximately 20% additional network bandwidth and CPU utilization.
[0096] RUDP, or Reliable User Datagram Protocol, is a simple packet transport protocol based on the Reliable Data Protocol (RDP: RFCs 908 and 1151 (Revision 2)). As a reliable transport protocol, RUDP is used to transmit telephone signals across IP networks. It allows for independent configuration of each connection's properties, enabling simultaneous implementation of protocols with varying transport requirements on different platforms.
[0097] 3 shows a process 300 of an embodiment of a data communication protocol implementation method applicable to the present disclosure. In this embodiment, the data communication protocol implementation method includes the following steps.
[0098] Step 301: inject the target dynamic library into the target application to take over the network IO related library functions.
[0099] In this embodiment, the execution entity can inject the target dynamic library into the target application to take over the network IO related library functions, for example, for a connection-oriented protocol, the IO related library functions can be socket, bind, listen, accept, recv, send, close; for a connectionless protocol, the related library functions can be recv and send, sendmsg and recvmsg, etc., that is, the network IO related library functions are taken over by using the dynamic library injection method.
[0100] Step 302: Based on the network IO related library function hook, the new protocol is used to replace the initial protocol of the target application.
[0101] In this embodiment, the execution subject may replace the initial protocol of the target application with a new protocol according to the network IO related library function hook or the callback interface of the network IO related library function hook, ie, callback.
[0102] Here, the new protocol and the initial protocol can both be connection protocols, such as the TCP protocol, etc., the new protocol and the initial protocol can both be connectionless protocols, such as the UDP protocol, etc., the new protocol and the initial protocol can both be data stream protocols or datagram protocols, the new protocol and the initial protocol can also both be reliable protocols or unreliable protocols, and this disclosure does not limit this.
[0103] In some optional embodiments, the method further includes: simultaneously monitoring connection establishment requests of the original protocol and the new protocol, and performing data transmission based on the new protocol or the initial protocol.
[0104] In this implementation, the new protocol is a communication protocol of a client / server architecture, and the execution entity can configure a listening specified context structure. For the listening specified context structure, in response to determining that there is a listening socket indicating that a new connection request has arrived, a target specified context structure corresponding to the listening socket is created, and the first address field in the target specified context structure is filled with the address and port of the other end, wherein the listening specified context structure includes a new protocol listening socket, an initial protocol listening socket and a second address, the second address is used to store the bound address and listening port, and the target specified context structure is a new protocol specified context structure or an initial protocol specified context structure; in response to determining that the target specified context structure is a new protocol specified context structure and the sending or receiving state is ready, data transmission is performed between the client and the client based on the address and port of the other end in the first address field.
[0105] Further referring to FIG4 , as an implementation of the methods shown in the above figures, the present disclosure provides an embodiment of a data communication protocol implementation device. This device embodiment corresponds to the method embodiment shown in FIG3 , and the device can be specifically applied to various electronic devices.
[0106] As shown in FIG4 , the data communication protocol implementation device 400 of this embodiment includes: an injection module 401 and a replacement module 402 .
[0107] The injection module 401 may be configured to inject the target dynamic library into the target application to take over the network IO related library functions.
[0108] The replacement module 402 may be configured to replace the initial protocol of the target application with a new protocol based on a network IO related library function hook.
[0109] In some optional aspects of this embodiment, the device further includes a monitoring module configured to monitor connection establishment requests of the original protocol and the new protocol simultaneously, and perform data transmission based on the new protocol or the initial protocol.
[0110] In some optional embodiments of this embodiment, the listening module is specifically configured to: configure a listening specified context structure, and for the listening specified context structure, in response to determining that there is a listening socket indicating that a new connection request has arrived, create a target specified context structure corresponding to the listening socket, and fill the first address field in the target specified context structure with the address and port of the other end, wherein the listening specified context structure includes a new protocol listening socket, an initial protocol listening socket and a second address, the second address is used to store the bound address and listening port, and the target specified context structure is a new protocol specified context structure or an initial protocol specified context structure; in response to determining that the target specified context structure is a new protocol specified context structure and the sending or receiving state is ready, data transmission is performed between the client and the client based on the address and port of the other end in the first address field.
[0111] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device and a readable storage medium.
[0112] As shown in FIG5 , it is a block diagram of an electronic device according to a method for implementing a data communication protocol according to an embodiment of the present disclosure.
[0113] 500 is a block diagram of an electronic device for implementing a data communication protocol according to an embodiment of the present disclosure. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or claimed herein.
[0114] As shown in Figure 5, the electronic device includes: one or more processors 501, a memory 502, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. The various components are connected to each other using different buses and can be installed on a common mainboard or installed in other ways as needed. The processor can process instructions executed in the electronic device, including instructions stored in or on the memory to display graphical information of a GUI on an external input / output device (such as a display device coupled to the interface). In other embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple electronic devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). In Figure 5, a processor 501 is taken as an example.
[0115] Memory 502 is a non-transitory computer-readable storage medium provided in the present disclosure. The memory stores instructions executable by at least one processor, causing the at least one processor to perform the data communication protocol implementation method provided in the present disclosure. The non-transitory computer-readable storage medium of the present disclosure stores computer instructions for causing a computer to perform the data communication protocol implementation method provided in the present disclosure.
[0116] The memory 502, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs, non-transitory computer executable programs, and modules, such as the program instructions / modules corresponding to the data communication protocol implementation method in the embodiments of the present disclosure (for example, the injection module 401 and the replacement module 402 shown in FIG. 4 ). The processor 501 executes the various functional applications and data processing of the server by running the non-transitory software programs, instructions, and modules stored in the memory 502, thereby implementing the data communication protocol implementation method in the above-mentioned method embodiment.
[0117] The memory 502 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and application programs required for at least one function; the data storage area may store data created by the use of the electronic device implemented by the data communication protocol, etc. In addition, the memory 502 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory 502 may optionally include a memory remotely located relative to the processor 501, and these remote memories may be connected to the electronic device implemented by the data communication protocol via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0118] The electronic device implementing the data communication protocol method may further include an input device 503 and an output device 504. The processor 501, memory 502, input device 503 and output device 504 may be connected via a bus or other means, with FIG5 taking bus connection as an example.
[0119] The input device 503 can receive input digital or character information, such as an input device such as a touch screen, a keypad, a mouse, a trackpad, a touch pad, a pointer, one or more mouse buttons, a trackball, a joystick, etc. The output device 504 can include a display device, an auxiliary lighting device (e.g., an LED), and a tactile feedback device (e.g., a vibration motor). The display device can include, but is not limited to, a liquid crystal display (LCD), a light emitting diode (LED) display, and a plasma display. In some embodiments, the display device can be a touch screen.
[0120] Various implementations of the systems and techniques described herein can be realized in digital electronic circuit systems, integrated circuit systems, dedicated ASICs (application specific integrated circuits), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system that includes at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0121] These computer programs (also referred to as programs, software, software applications, or code) include machine instructions for a programmable processor and can be implemented using high-level procedural and / or object-oriented programming languages, and / or assembly / machine languages. As used herein, the terms "machine-readable medium" and "computer-readable medium" refer to any computer program product, apparatus, and / or device (e.g., a magnetic disk, an optical disk, a memory, a programmable logic device (PLD)) for providing machine instructions and / or data to a programmable processor, including a machine-readable medium that receives machine instructions as a machine-readable signal. The term "machine-readable signal" refers to any signal for providing machine instructions and / or data to a programmable processor.
[0122] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0123] The systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network (LAN), a wide area network (WAN), and the Internet.
[0124] Computer systems may include clients and servers. A client and server are generally remote from each other and typically interact through a communication network. The client and server relationship arises through computer programs running on the respective computers and having a client-server relationship to each other.
[0125] According to the technical solution of the embodiment of the present disclosure, transparent replacement of application communication protocols is achieved.
[0126] It should be understood that the various forms of the processes shown above can be used to reorder, add, or delete steps. For example, the steps described in this application can be performed in parallel, sequentially, or in a different order, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved. This is not a limitation herein.
[0127] The above specific embodiments do not constitute a limitation on the scope of protection of this disclosure. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions may be made based on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this disclosure shall be included within the scope of protection of this disclosure.
Claims
1. A data communication protocol implementation system, the system comprising: A first communication subject and a second communication subject communicating with each other based on an initial protocol; The first communication subject is used to inject the first dynamic library into the first application to take over the network IO related library functions; Based on the network IO related library function hook, the new protocol is used to replace the initial protocol of the first application program; The second communication subject is used to inject the second dynamic library into the second application to take over the network IO related library function; based on the network IO related library function hook, the new protocol is used to replace the initial protocol of the second application; The first dynamic library is the same as the second dynamic library.
2. The system according to claim 1, wherein: The new protocol is a communication protocol of a client / server architecture, the first communication subject is a client, and the second communication subject is a server; The first communication subject is used to execute the library function of the new client protocol when initiating a connection; The second communication subject is used to execute the library function of the new protocol of the server when monitoring the connection establishment.
3. The system according to claim 2, wherein: The server is used to monitor the connection establishment requests of the original protocol and the new protocol at the same time, and perform data transmission based on the new protocol or the initial protocol.
4. The system according to claim 3, wherein: The simultaneously monitoring the connection establishment requests of the original protocol and the new protocol, and performing data transmission based on the new protocol or the initial protocol, includes: Configure a listening specified context structure, for the listening specified context structure, in response to determining that there is a listening socket indicating that a new connection request has arrived, create a target specified context structure corresponding to the listening socket, and fill the first address field in the target specified context structure with the address and port of the other end, wherein the listening specified context structure includes a new protocol listening socket, an initial protocol listening socket and a second address, the second address is used to store the bound address and listening port, and the target specified context structure is a new protocol specified context structure or an initial protocol specified context structure; In response to determining that the target specified context structure is a new protocol specified context structure and is in a sending or receiving state, data is transmitted with the client based on the address and port of the opposite end in the first address field.
5. The system according to claim 4, wherein: The method of simultaneously monitoring the connection establishment requests of the original protocol and the new protocol and performing data transmission based on the new protocol or the initial protocol also includes: In response to determining that the target specified context structure is an initial protocol specified context structure, the network IO operation is controlled according to the corresponding operation logic in the initial protocol.
6. The system according to claim 4, wherein: The server is further used for: The callback interface for library function call is configured to monitor whether the specified context structure indicates that a new connection request has arrived, whether the receiving state of the new protocol specified context structure is ready, and whether the sending state is ready.
7. The system according to claim 4, wherein: The server is further used for: A global lock-free hash table is configured to store the monitoring specified context structure, the new protocol specified context structure and the initial protocol specified context structure.
8. A method for implementing a data communication protocol, the method comprising: Inject the target dynamic library into the target application to take over the network IO related library functions; Based on the network IO related library function hook, a new protocol is adopted to replace the initial protocol of the target application.
9. The method according to claim 8, wherein: The new protocol is a communication protocol of a client / server architecture, and the method further comprises: It monitors the connection requests of the original protocol and the new protocol at the same time, and transmits data based on the new protocol or the initial protocol, including: Configure a listening specified context structure, for which, in response to determining that there is a listening socket indicating that a new connection request has arrived, create a target specified context structure corresponding to the listening socket, and fill the first address field in the target specified context structure with the address of the other end and port, wherein the listening specified context structure includes a new protocol listening socket, an initial protocol listening socket and a second address, the second address is used to store the bound address and the listening port, and the target specified context structure is a new protocol specified context structure or an initial protocol specified context structure; In response to determining that the target specified context structure is a new protocol specified context structure and is in a sending or receiving state, data is transmitted with the client based on the address and port of the opposite end in the first address field.
10. A data communication protocol implementation device, the device comprising: An injection module is configured to inject a target dynamic library into a target application to take over network IO related library functions; The replacement module is configured to replace the initial protocol of the target application with a new protocol based on a network IO related library function hook.
11. The device according to claim 10, wherein: The device also includes a monitoring module configured to monitor connection establishment requests of the original protocol and the new protocol at the same time, and perform data transmission based on the new protocol or the initial protocol.
12. The device according to claim 11, wherein The monitoring module is specifically configured as follows: Configure a listening specified context structure, for the listening specified context structure, in response to determining that there is a listening socket indicating that a new connection request has arrived, create a target specified context structure corresponding to the listening socket, and fill the first address field in the target specified context structure with the address and port of the other end, wherein the listening specified context structure includes a new protocol listening socket, an initial protocol listening socket and a second address, the second address is used to store the bound address and listening port, and the target specified context structure is a new protocol specified context structure or an initial protocol specified context structure; In response to determining that the target specified context structure is a new protocol specified context structure and is in a sending or receiving state, data is transmitted with the client based on the address and port of the opposite end in the first address field.
13. An electronic device, characterized in that: include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores computer instructions that can be executed by the at least one processor. When the computer instructions are executed by the at least one processor, the at least one processor implements the method according to any one of claims 8 to 9.
14. A non-transitory computer-readable storage medium storing computer instructions, characterized in that: The computer instructions are used to cause the computer to execute the method according to any one of claims 8 to 9.
Citation Information
Patent Citations
Method for realizing a firewall of a database
CN109657491A
Remote function calling method based on dedicated channel
CN114816792A
C + + code uninterrupted operation updating method and computer system
CN115167905A
Method for analyzing and controlling hot loading industrial control protocol and system with same
CN115941818A
Method for network fuzzing apparatus using windows socket API hooking
KR1020080043209A
Cited By
Service systematization providing method and device based on model context protocol
CN121441989A