Method, device and system for realizing data communication protocol

The dynamic library injection technology takes over the network IO library functions of the application and replaces the communication protocol based on the hook mechanism, solving the problem of opaque protocol replacement in the existing technology, and realizing unconscious communication protocol replacement.

CN119172446AActive Publication Date: 2024-12-20XIAN TONGXING HENGYAO INFORMATION TECHNOLOGY CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202310942784.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-07-28
Publication Date
2024-12-20
Estimated Expiration
2043-07-28

AI Technical Summary

Technical Problem

In the prior art, the network communication protocol that replaces the application program requires the modification of the application source code, and cannot realize transparent replacement of the network communication protocol, and cannot be compatible with other applications that follow the old communication protocol.

Method used

By injecting the target dynamic library into the target application, taking over the network IO-related library functions, and using the new protocol to replace the target application's initial protocol based on the network IO-related library function hook.

Benefits of technology

It realizes transparent replacement of the application communication protocol, without modifying code or recompiling the target application, and has no perception to the user.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119172446A_ABST
    Figure CN119172446A_ABST
Patent Text Reader

Abstract

The invention discloses a data communication protocol implementation system, and relates to the technical field of communication. The system comprises a first communication main body and a second communication main body which communicate with each other based on an initial protocol; the first communication main body is used for injecting the first dynamic library into a first application program so as to take over a network IO related library function; replacing an initial protocol of the first application program with a new protocol based on the network IO related library function hook; the second communication main body is used for injecting a second dynamic library into a second application program to take over a network IO related library function; and replacing the initial protocol of the second application program with the new protocol based on the network IO related library function hook. According to the embodiment, transparent replacement of the application program communication protocol is realized.
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, specifically to the field of communication technology, and in particular to a method, device and system for implementing a data communication protocol. Background Art

[0002] In the prior art, replacing the network communication protocol of an application requires modifying the application source code. Moreover, once the original network communication protocol of an application is replaced, it is difficult to make it compatible with other applications that follow the old communication protocol and simultaneously access this application. 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. Summary of the invention

[0003] Embodiments of the present application provide a data communication protocol implementation method, apparatus, system, device, and storage medium.

[0004] According to the first aspect, an embodiment of the present application provides a method for implementing a data communication protocol, the method comprising: 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.

[0005] According to the second aspect, an embodiment of the present application 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 a network IO related library function hook.

[0006] According to the third aspect, an embodiment of the present application 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.

[0007] According to the fourth aspect, an embodiment of the present application provides an electronic device, which includes one or more processors; a storage device on which one or more programs are stored, and when the one or more programs are executed by the one or more processors, the one or more processors implement a data communication protocol implementation method as in any embodiment of the first aspect.

[0008] According to the fifth aspect, an embodiment of the present application provides a computer-readable medium having a computer program stored thereon, which, when executed by a processor, implements a data communication protocol implementation method as in any embodiment of the first aspect.

[0009] The present application 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, that is, transparent replacement of application communication protocols is achieved through dynamic library injection.

[0010] 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

[0011] Figure 1a is an architectural diagram of an embodiment of a data communication protocol implementation system according to the present application;

[0012] Figure 1b is a flow chart of an embodiment of a data communication protocol implementation system according to the present application;

[0013] Figure 1c is a flow chart of an embodiment of a data communication protocol implementation system according to the present application;

[0014] Figure 1d is a flow chart of an embodiment of a data communication protocol implementation system according to the present application;

[0015] Figure 1e is a flow chart of an embodiment of a data communication protocol implementation system according to the present application;

[0016] Figure 1f is a flow chart of an embodiment of a data communication protocol implementation system according to the present application;

[0017] Figure 1g is a flow chart of an embodiment of a data communication protocol implementation system according to the present application;

[0018] Figure 1h is a flow chart of an embodiment of a data communication protocol implementation system according to the present application;

[0019] Figure 1i is a flow chart of an embodiment of a data communication protocol implementation system according to the present application;

[0020] Figure 1j is a flow chart of an embodiment of a data communication protocol implementation system according to the present application;

[0021] Figure 1k It is a flow chart of an application scenario of a system implementing the data communication protocol of the present application;

[0022] Figure 2 It is an architectural diagram of an application scenario of a system implementing the data communication protocol of the present application;

[0023] Figure 3 is a flow chart of an embodiment of a method for implementing a data communication protocol according to the present application;

[0024] Figure 4 is a flow chart of an embodiment of a data communication implementation device according to the present application;

[0025] Figure 5 It is a structural diagram of a computer system suitable for implementing a server of an embodiment of the present application. DETAILED DESCRIPTION

[0026] The following is a description of exemplary embodiments of the present application in conjunction with the accompanying drawings, including various details of the embodiments of the present application to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present application. Similarly, for the sake of clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0027] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.

[0028] Figure 1a The data communication protocol implementation system architecture 100 that can be applied to the present application is shown. 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.

[0029] 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.).

[0030] The first communication subject may inject the first dynamic library into the first application to take over the network IO related library function, and replace the initial protocol of the first 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. That is, the dynamic library injection method is used to replace the initial protocol with a new protocol.

[0031] The second communication subject injects the second dynamic library into the second application to take over the network IO related library function, and replaces the initial protocol of the second 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. That is, the dynamic library injection method is used to replace the initial protocol with a new protocol.

[0032] The first dynamic library and the second dynamic library are the same.

[0033] After the new protocol is replaced, the first communication subject and the second communication subject can communicate based on the new protocol.

[0034] Here, for a connection-oriented protocol, the IO-related library functions may be socket, bind, listen, accept, recv, send, close; for a connectionless protocol, the IO-related library functions may be recv and send, sendmsg and recvmsg, etc.

[0035] 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 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 be reliable protocols or unreliable protocols, and this application does not limit this.

[0036] 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").

[0037] 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 application.

[0038] Specifically, in the Linux system, you can set the dynamic library to be preloaded when starting the application by specifying the environment variable "LD_PRELOAD"; when the client or server application is started, 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:

[0039] Server

[0040] LD_PRELOAD= / my / dir / newprotocol.so server

[0041] Client

[0042] LD_PRELOAD= / my / dir / newprotocol.so client

[0043] Here, when the application is started, the execution subject may inject the dynamic library into the application in a variety of specific ways, such as inline injection, overlay injection, etc.

[0044] Among them, inline injection is used to indicate that the code is directly injected 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.

[0045] Here, the object of overlay injection can be the application itself or a library function that the application depends on.

[0046] In some optional embodiments, the first communication subject is used to execute the library function of the new protocol of the client when initiating a connection; the second communication subject is used to execute the library function of the new protocol of the server when listening to the connection establishment.

[0047] In this implementation, the new protocol is a communication protocol of a client / server architecture, that is, a communication protocol of a client / server architecture, that is, a communication protocol of a CS architecture. 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 new protocol of the client when initiating a connection; the second communication subject is used to execute the library function of the new protocol of the server when listening to the connection establishment.

[0048] Specifically, when the initial network protocol is based on monitoring and establishing a connection, the monitoring and establishing a connection operation is replaced by overloading the bind, listen, and accept functions on the server side and overloading the connect function on the client side.

[0049] After the connection is established, the server and the client perform data transmission based on the overloaded send and recv functions.

[0050] 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 protocol of the client when initiating the connection; and the second communication subject executes the library function of the new protocol of the server when listening for the connection establishment.

[0051] In some optional methods, 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.

[0052] In this implementation, the server can monitor the connection establishment requests of the original protocol and the new protocol at the same time. If a connection establishment request of the new protocol is monitored, data transmission is performed based on the new protocol. If a connection establishment 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 establishment operations.

[0053] 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.

[0054] 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.

[0055] The listening designated context structure includes a new protocol listening socket, an initial protocol listening socket and a second address, and the second address (such as sock_addr) is used to store the bound address and the listening port.

[0056] Furthermore, in response to determining that there is a listening socket 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.

[0057] The target specified context structure is a new protocol specified context structure or an initial protocol specified context structure.

[0058] Here, the listening specified context structure, the new protocol specified context node and the initial protocol specified context structure are different types of the specified context structure. 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.

[0059] 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), the second address field (used to store the bound address and listening port), as shown in the following figure: Figure 1b shown.

[0060] Here, it should be noted that the new protocol can be any communication protocol of the client / server architecture, such as the TCP protocol, etc., and this application does not limit this.

[0061] In addition, if the new protocol is a KCP protocol that uses a UDP link as the transport layer, the listening socket is a UDP listening socket, i.e., a UDP listen socket, and the specified context structure may also include a KCP field: used to store 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 subject must also create a KCP context for it and bind it to the KCP ID in the connection request packet, thereby achieving pairing of KCP communication.

[0062] Furthermore, if the new protocol is the KCP protocol and the initial protocol is the TCP protocol, both are connection-oriented protocols, and 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 of 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 the client initiating a connection through the callback interface of the connect library function hook.

[0063] Specifically, Figure 1c As shown, 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 SockFdtable, 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.

[0064] Furthermore, if Figure 1d As shown, 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, that is, 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, that is, 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 second address sock_addr passed in to obtain the listening specified context structure. If the binding fails, an error code is returned and the error is processed.

[0065] Furthermore, if Figure 1eAs shown, 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 determined, and whether there is a new connection. If so, the system call SYS_accept is executed to create a server-side TCP socket, and determine whether the TCP connection is successful. If so, a TCP specified context structure corresponding to the TCP listen socket is created, that is, TCP SockFd, and stored in the SockFd table, and 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 determined, 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 determine 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, that is, UDP SockFD, further, determines whether the KCP connection is successful. If successful, it stores the UDP SockFD in the SockFd table and returns the UDPsocket FD of 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 that the new connection is not ready.

[0066] In addition, for the listen library function, its callback process is as follows Figure 1f As shown, 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 processed.

[0067] 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 according to the address and port of the other end recorded in the first address field.

[0068] Specifically, take the new protocol as the KCP protocol using the UDP link as the transport layer, and the initial protocol as the TCP protocol as an example. Figure 1g As shown, 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.

[0069] Another example Figure 1h As shown, 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 to determine 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 data receiving interface is called to determine whether there is no data in the KCP receiving buffer. If so, an error code is returned and the error is processed. If not, the actual number of bytes received is returned.

[0070] In addition, after the data transmission is completed, it is necessary to close the communication based on the network IO related library function hook.

[0071] Specifically, Figure 1i As shown, 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.

[0072] This implementation configures a specified context structure, and for a listening specified context structure, in response to determining that there is a listening socket indicating that a new connection request has arrived, creates a target specified context structure corresponding to the listening socket, and fills 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 is transmitted between the client based on the address and port of the other end in the first address field, thereby implementing support for the initial protocol and the new protocol.

[0073] In some optional ways, 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.

[0074] In this implementation, the server can configure a callback interface to detect whether the specified listening 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 poll / select / epoll_wait and other library function hook calls.

[0075] Specifically, Figure 1j As shown, taking the initial protocol of the application as TCP protocol and the new protocol as UDP protocol as an example, the socket descriptor is searched in the SockFd table. If found, the type of the specified context structure corresponding to the socket descriptor, i.e., the SockFd type, is further determined. If it is a listening specified context structure, whether the TCP listen socket is ready is determined. If so, POLLIN is returned. If not, whether the UDP listen socket is readable is determined. If so, POLLIN is returned. If not, 0 is returned to indicate that there is no ready event. Further, if the type of the specified context structure is the new protocol specified context structure, i.e., the UDP specified context structure, whether the KCP is not opened or closed is determined. If so, an error code is returned and error is processed. If not, the KCP interface is called to check the send / receive window status and determine whether the 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 type of the specified context structure is the initial protocol specified context structure, i.e., the TCP specified context structure, the control right is returned.

[0076] 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 receiving state of the new protocol specified context structure is ready, and whether the sending state is ready.

[0077] 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.

[0078] In this embodiment, if the new protocol is a communication protocol of a client / server architecture, the server can receive a connection request sent by a client of the new protocol based on a callback interface of a network IO related library function hook, that is, receive a connection request from a client started by dynamic injection.

[0079] 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 new protocol listening port of the server through the callback interface of the network IO related library function hook to initiate a new protocol connection request.

[0080] Specifically, Figure 1k As shown in the figure, 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 to specify the 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.

[0081] Here, the peer_addr field in UDP SockFd is filled with the server's network address and listening port.

[0082] 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.

[0083] 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.

[0084] In some optional methods, 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.

[0085] 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.

[0086] Here, the listening specified context structure, the new protocol specified context structure and the initial protocol specified context structure are respectively used to maintain different socket descriptors, and the global lock-free hash table can use the socket descriptor as the key value to index the specified context structure.

[0087] Among them, the lock-free hash table is a multi-threaded safe hash table, most of which are implemented using atomic operations such as CAS. Since no locking is required during concurrent access, its concurrency performance is better than the implementation of ordinary hash table + lock.

[0088] Here, CAS is a hardware synchronization primitive provided by a processor (CPU) that supports concurrency. The CAS operation contains 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 value of the location to the new value. Otherwise, the processor does nothing. In either case, it returns 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 is repeatedly attempted in a loop until the operation succeeds.

[0089] 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.

[0090] Continue to see Figure 2 , Figure 2 It is an architecture diagram of an application scenario of the data communication protocol implementation system according to this embodiment.

[0091] exist Figure 2In the application scenario, 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 the 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, and the network IO related library functions, such as socket, connect, send, recv and other library functions, are taken over. 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 based on the callback interface of the network IO related library function hook, i.e., Listen SockFd, 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 end, in response to determining that the target specified context structure is a new protocol specified context structure, i.e., 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 end in the first address field.

[0092] Among them, the KCP protocol is an open source ARQ (Automatic Repeat reQuest) protocol with reliability in the transport layer. It is designed to solve the problem of slow transmission speed of the TCP protocol under network congestion. KCP strives to improve the transmission speed while ensuring reliability. Its focus is mainly on controlling the reliability of data and improving the transmission speed. Therefore, it does not specify its lower layer transmission protocol (most implementations based on KCP use UDP as the lower layer transmission protocol). The data packet of the KCP layer protocol adds a control header based on the data packet of its lower layer transmission protocol. Since the transmission delay of data in the network is not fixed, the time of timeout retransmission is difficult to predict; in order to determine the loss of data packets as early as possible, KCP introduces a fast retransmission mechanism. Compared with the TCP protocol, the fast retransmission mechanism of KCP improves the transmission performance by 20% in a weak network (severe delay jitter or high packet loss rate) environment at the cost of occupying about 20% more network bandwidth and CPU occupancy.

[0093] RUDP, or Reliable User Datagram Protocol, is a simple packet transmission protocol based on the Reliable Data Protocol (RDP: RFC908 and 1151 (Second Edition)). As a reliable transmission protocol, RUDP is used to transmit telephone signals between IP networks. It allows each connection attribute to be configured independently, so that protocols with different transmission requirements can be implemented simultaneously on different platforms.

[0094] Figure 3 The flowchart 300 of the embodiment of the data communication protocol implementation method applicable to the present application is shown. In this embodiment, the data communication protocol implementation method includes the following steps.

[0095] Step 301, injecting the target dynamic library into the target application to take over the network IO related library functions.

[0096] 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 may be socket, bind, listen, accept, recv, send, close; for a connectionless protocol, the related library functions may 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.

[0097] Step 302: Based on the network IO related library function hook, a new protocol is used to replace the initial protocol of the target application.

[0098] 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.

[0099] 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 application does not limit this.

[0100] 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.

[0101] 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 other end based on the address and port of the other end in the first address field.

[0102] Further references Figure 4 As an implementation of the methods shown in the above figures, the present application provides an embodiment of a data communication protocol implementation device, and the device embodiment is Figure 3 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.

[0103] like Figure 4 As shown, the data communication protocol implementation device 400 of this embodiment includes: an injection module 401 and a replacement module 402.

[0104] 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.

[0105] 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.

[0106] 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.

[0107] According to an embodiment of the present application, the present application also provides an electronic device and a readable storage medium.

[0108] like Figure 5 , 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 application.

[0109] 500 is a block diagram of an electronic device according to a data communication protocol implementation method of an embodiment of the present application. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workbenches, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, 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 application described herein and / or required.

[0110] like Figure 5 As shown, 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 interconnected 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 the graphical information of the 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). Figure 5 A processor 501 is taken as an example.

[0111] The memory 502 is a non-transient computer-readable storage medium provided in the present application. The memory stores instructions executable by at least one processor to enable the at least one processor to execute the data communication protocol implementation method provided in the present application. The non-transient computer-readable storage medium of the present application stores computer instructions, which are used to enable a computer to execute the data communication protocol implementation method provided in the present application.

[0112] The memory 502 is a non-transient computer-readable storage medium that can be used to store non-transient software programs, non-transient computer executable programs and modules, such as program instructions / modules corresponding to the data communication protocol implementation method in the embodiment of the present application (for example, the attached Figure 4 The processor 501 executes various functional applications and data processing of the server by running the non-transient software programs, instructions and modules stored in the memory 502, that is, the data communication protocol implementation method in the above method embodiment is implemented.

[0113] The memory 502 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created by the use of an electronic device implemented by a 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 arranged 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.

[0114] The electronic device for implementing the data communication protocol method may further include: an input device 503 and an output device 504. The processor 501, the memory 502, the input device 503 and the output device 504 may be connected via a bus or other means. Figure 5 The example of connecting through bus is taken in the following.

[0115] The input device 503 can receive input digital or character information, such as a touch screen, a keypad, a mouse, a track pad, a touch pad, an indicator bar, one or more mouse buttons, a track ball, a joystick, and other input devices. The output device 504 may include a display device, an auxiliary lighting device (e.g., an LED), and a tactile feedback device (e.g., a vibration motor), etc. The display device may 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 may be a touch screen.

[0116] 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 including 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.

[0117] These computer programs (also referred to as programs, software, software applications, or code) include machine instructions for programmable processors 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, device, and / or means (e.g., disk, optical disk, memory, 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.

[0118] 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).

[0119] The systems and techniques described herein may 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 may 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.

[0120] A computer system may include clients and servers. Clients and servers are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship to each other.

[0121] According to the technical solution of the embodiment of the present application, transparent replacement of the application communication protocol is achieved.

[0122] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this application can be executed in parallel, sequentially or in different orders, as long as the expected results of the technical solution disclosed in this application can be achieved, and this document is not limited here.

[0123] The above specific implementations do not constitute a limitation on the protection scope of this application. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of this application should be included in the protection scope of this application.

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. According to the system of claim 1, 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, comprises: 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. According to the system of claim 4, 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 further comprises: 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. According to the system of claim 4, 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 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.

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. 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 instructions executable by the at least one processor so that the at least one processor can perform the method according to any one of claims 9 to 10.

12. 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 9 to 10.

Citation Information

Patent Citations

  • Memory test method, tested terminal, test client and system

    CN106557424A

  • Method for realizing a firewall of a database

    CN109657491A

  • Generation method and system for three-layer associated information, electronic equipment and storage medium

    CN110990168A

  • QuIC protocol-based port sharing method, system and server

    CN114531499A

  • Automated testing of systems and applications

    US11301350B1