File restoration method, terminal, and storage medium
By using multi-threaded processing technology, efficient reassembly and restoration of file data packets are achieved, solving the problems of low file restoration efficiency and complex process in existing technologies, thus improving the efficiency of file restoration and simplifying the process.
Patent Information
- Application Number
- CN202080099591.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-06-15
- Publication Date
- 2025-11-25
- Estimated Expiration
- 2040-06-15
AI Technical Summary
The existing file restoration process is inefficient and complex, especially when file data packets are reassembled and restored sequentially, which adds extra interaction and complexity.
A multi-threaded processing approach is adopted, in which a reassembly thread completes the data packet reassembly and stores it to the reassembly storage address, while a restoration thread performs file restoration processing, thereby realizing independent reassembly and restoration of data packets.
It improves file restoration efficiency, simplifies the restoration process, and overcomes the problems of low efficiency and high complexity in traditional methods.
Smart Images

Figure CN115380280B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of network data processing, and in particular to a file restoration method, terminal, and storage medium. Background Technology
[0002] With the development of the internet, accessing the internet has become an integral part of people's lives. People can transfer files online to achieve various information exchanges (such as online chat, email, online audio and video viewing or downloading, etc.). In the current network environment, there are many ways to transfer files, such as obtaining files through web pages, sending files via email, or downloading files based on file transfer protocols, etc.
[0003] Since file transfer over a network is based on sending and receiving data packets, file restoration is necessary before the actual text or file content can be presented to the user. File restoration primarily involves two processes: file reassembly and file storage. Existing technologies generally employ sequential file data packet reassembly and restoration, or perform file restoration on different devices. This approach results in low restoration efficiency and requires additional interaction, increasing the complexity of the file restoration process. Summary of the Invention
[0004] This application provides a file recovery method, terminal, and storage medium, which has high file recovery efficiency and overcomes the shortcomings of complex recovery process, thereby improving file recovery technology.
[0005] The technical solution of this application embodiment is implemented as follows:
[0006] In a first aspect, embodiments of this application provide a file restoration method, the method comprising:
[0007] If the data packet obtained through the reassembly thread is the first data packet of the file to be processed, then extract the metadata corresponding to the file to be processed from the first data packet;
[0008] If the file to be processed is determined to be restored based on the metadata, the reconstructed storage address corresponding to the file to be processed is determined according to the preset storage mapping table, and the first data packet is stored in the reconstructed storage address through the reconstructed thread.
[0009] The reconstructing thread continues to acquire other data packets of the file to be processed, and these other data packets are sequentially stored in the reconstructing storage address to obtain the reconstructed data packets corresponding to the file to be processed.
[0010] The reconstructing thread stores the metadata and the reconstructed data packet to the first storage address.
[0011] If the reconstruction data packet corresponding to the file to be processed is found at the second storage address through the restoration thread, the file to be processed is restored according to the reconstruction data packet.
[0012] Secondly, embodiments of this application provide a terminal, which includes: an extraction section, a determination section, a storage section, an acquisition section, and a restoration section.
[0013] The extraction part is configured to extract the metadata corresponding to the file to be processed from the first data packet if the data packet obtained by the reassembly thread is the first data packet of the file to be processed.
[0014] The determining part is configured such that if it is determined based on the metadata that the file to be processed is to be restored, then the reconstructed storage address corresponding to the file to be processed is determined according to a preset storage mapping table.
[0015] The storage portion is configured to store the first data packet to the reassembly storage address via the reassembly thread;
[0016] The acquisition section is configured to continue acquiring other data packets of the file to be processed through the reorganization thread;
[0017] The storage section is further configured to sequentially store the other data packets to the reconstructed storage address to obtain the reconstructed data packet corresponding to the file to be processed; and to store the metadata and the reconstructed data packet to the first storage address through the reconstructed thread;
[0018] The restoration section is configured such that if the restoration thread finds that the reconstructed data packet corresponding to the file to be processed exists at the second storage address, the file to be processed is restored based on the reconstructed data packet.
[0019] Thirdly, this application provides a terminal, which includes a processor and a memory storing processor-executable instructions. When the instructions are executed by the processor, the file restoration method described above is implemented.
[0020] Fourthly, embodiments of this application provide a computer-readable storage medium storing a program applied in a terminal, wherein when the program is executed by a processor, it implements the file restoration method described above.
[0021] This application provides a file restoration method, terminal, and storage medium. If the data packet obtained by the terminal through the reconstruction thread is the first data packet of the file to be processed, the terminal extracts the metadata corresponding to the file to be processed from the first data packet. If it is determined that the file to be processed needs to be restored based on the metadata, the reconstruction storage address corresponding to the file to be processed is determined according to a preset storage mapping table, and the first data packet is stored in the reconstruction storage address through the reconstruction thread. The reconstruction thread continues to obtain other data packets of the file to be processed and stores them sequentially in the reconstruction storage address to obtain the reconstructed data packet corresponding to the file to be processed. The reconstruction thread stores the metadata and the reconstructed data packet in a first storage address. If the restoration thread finds that the reconstructed data packet corresponding to the file to be processed exists in a second storage address, the file to be processed is restored based on the reconstructed data packet. In other words, in this application, while the terminal uses the reconstruction thread to complete the reconstruction of data packets to obtain the reconstructed data packet of the file to be processed, the terminal can also use the restoration thread to restore the reconstructed data packet to obtain the file to be processed. Therefore, the terminal can independently complete the data packet reconstruction and restoration process of the file to be processed through multiple threads, resulting in high file restoration efficiency and overcoming the shortcomings of complex restoration processes, thereby improving file restoration technology. Attached Figure Description
[0022] Figure 1 This is a schematic diagram of the implementation process of the file restoration method proposed in the embodiments of this application. Figure 1 ;
[0023] Figure 2 This is a schematic diagram of the execution flow of the file restoration thread proposed in an embodiment of this application;
[0024] Figure 3 This is a schematic diagram of the implementation process of the file restoration method proposed in the embodiments of this application. Figure 2 ;
[0025] Figure 4 This is a schematic diagram of the implementation process of the file restoration method proposed in the embodiments of this application. Figure 3 ;
[0026] Figure 5 This is a schematic diagram of the implementation process of the file restoration method proposed in the embodiments of this application. Figure 4 ;
[0027] Figure 6 This is a schematic diagram of the implementation process of the file restoration method proposed in the embodiments of this application. Figure 5 ;
[0028] Figure 7 This is a schematic diagram of the execution flow of the file reassembly thread proposed in an embodiment of this application;
[0029] Figure 8This is a schematic diagram of the terminal structure proposed in the embodiments of this application. Figure 1 ;
[0030] Figure 9 This is a schematic diagram of the terminal structure proposed in the embodiments of this application. Figure 2 . Detailed Implementation
[0031] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are only for explaining the relevant application and not for limiting the application. Furthermore, it should be noted that, for ease of description, only the parts related to the relevant application are shown in the accompanying drawings.
[0032] Before providing a further detailed description of the embodiments of the present invention, the nouns and terms involved in the embodiments of the present invention will be explained, and the nouns and terms involved in the embodiments of the present invention shall be interpreted as follows.
[0033] 1) File restoration: Restore a file from its original state during network transmission by reassembling the data into a single file.
[0034] 2) Hypertext Transfer Protocol (HTTP): The most widely used network protocol on the Internet, typically running on top of Transmission Control Protocol (TCP). HTTP is based on a client / server model, specifying what messages a client might send to a server and what responses it might receive.
[0035] 3) File Transfer Protocol (FTP): This is a standard protocol for transferring files over a network. It is designed based on the client-server model. In particular, FTP uses two TCP connections between two communicating hosts: one is a data connection for data transfer, and the other is a control connection for transmitting control information (commands and responses). That is, commands and data are transmitted separately, which is multi-stream transmission.
[0036] 4) Simple Mail Transfer Protocol (SMTP): This is a protocol that provides reliable and efficient email transmission. It is an email service built on top of FTP file transfer service and is mainly used for the transmission of email information between systems and to provide notifications about incoming emails.
[0037] 5) Single-stream transmission: File attribute fields (including file name, file size, file orientation, etc.) and file content are transmitted in a single stream.
[0038] 6) Multi-stream transmission: File attribute fields and file content are transmitted in multiple streams, or file attribute fields, file content, or file content may be transmitted in different streams.
[0039] 7) Meta-information: Meta-information is information about information, used to describe the structure, semantics, purpose, and usage of the information. The browser receiving the data can determine what content the server sent, what data is expected, whether the data is complete, and whether any errors occurred during the process, based on the meta-information. This allows the client to know the type of object being transmitted.
[0040] In today's network environment, there are many ways to transfer files, such as obtaining files through web pages, sending files via email, or downloading files based on file transfer protocols. All of these methods utilize data packets for sending and receiving. Specifically, the file transfer process over a network is based on the Open Systems Interconnection (OSI) reference model. When sending a file to a peer, the sender packages the data, processes it through each layer of the protocol (each layer adds its own header information), and encapsulates the file. Then, when the peer receives the file, it decapsulates the received data packets layer by layer—that is, it performs restoration processing—to obtain the original file and present the actual text or file content to the user.
[0041] File restoration mainly involves two processes: file reconstruction and file storage. Existing technologies generally use sequential file restoration or file restoration based on different devices. This not only results in low restoration efficiency but also requires additional interaction during the restoration process, thus increasing the complexity of the file restoration process.
[0042] To address the problems of traditional file recovery mechanisms, this application provides a file recovery method, terminal, and storage medium. Specifically, while the terminal uses a reassembly thread to reassemble data packets to obtain reassembled data packets of the file to be processed, the terminal can also use a recovery thread to restore the reassembled data packets to obtain the file to be processed. It is evident that the terminal can independently complete the data packet reassembly and recovery process of the file to be processed through multiple threads, resulting in high file recovery efficiency and overcoming the drawbacks of complex recovery processes, thereby improving file recovery technology.
[0043] The technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings.
[0044] Figure 1This is a schematic diagram of the implementation process of the file restoration method proposed in the embodiments of this application. Figure 1 ,like Figure 1 As shown in the embodiments of this application, the method for restoring files on a terminal may include the following steps:
[0045] Step 101: If the data packet obtained by the reassembly thread is the first data packet of the file to be processed, then extract the metadata corresponding to the file to be processed from the first data packet.
[0046] In the embodiments of this application, the terminal can obtain data packets through the reassembly thread. If the data packet obtained by the terminal is the first data packet of the file to be processed, the terminal can extract the metadata corresponding to the file to be processed from the first data packet.
[0047] It should be noted that, in the embodiments of this application, the terminal can be any device with file receiving and storage functions. Optionally, the terminal can be a physical server, a virtual server (such as a cloud server), a tablet computer, a personal computer (PC), a laptop computer, or other devices with computing and storage functions.
[0048] It should be noted that, in the embodiments of this application, the file to be processed can be a file downloaded from a webpage (e.g., e-books, audio / video files, etc. downloaded from a website); a file uploaded from a webpage (e.g., images and text shared through social media platforms such as Facebook and Weibo); a file shared directly through platforms such as WeChat or QQ; or a file sent / received via email (e.g., sending emails using 163 email, Sina email, etc.). This application does not specifically limit the file to be processed.
[0049] It should be noted that, in the embodiments of this application, since the carrier for transmitting files over the network is network traffic, the transmission process of a file may be carried out by a single traffic stream or by multiple network traffic streams. Therefore, the file to be processed may contain at least one data packet. Consequently, the terminal can obtain at least one data packet of the file to be processed.
[0050] Optionally, the terminal can create a reassembly thread to obtain at least one data packet of the file to be processed. Specifically, during the acquisition of at least one data packet of the file to be processed, the terminal can first obtain the first data packet of the file to be processed through the reassembly thread, and parse and process the first data packet to obtain the metadata corresponding to the file to be processed. This metadata may include the session identifier and attribute parameters corresponding to the file to be processed. The session identifier is the identification information corresponding to a file transfer process, such as the source address, source port, destination address, and destination port. The attribute parameters are the characteristic information corresponding to the transferred file, such as the filename, file type, file size, and network address of the file to be processed.
[0051] For example, if a computer corresponding to address A and port A sends a 400KB paper named "How to Restore a File" to another computer corresponding to address B and port B, then the session identifier for sending the file from address A and port A to address B and port B is the file's corresponding session identifier; the file size is 400KB, the file type is a text file, and the file name is "How to Restore a File".
[0052] It should be noted that, in the embodiments of this application, the terminal can also parse the request information corresponding to the file to be processed from the first data packet of the file to be processed, and determine the request type (e.g., upload request or download request) corresponding to the file to be processed based on the request information. Furthermore, since different request types obtain metadata in different ways (e.g., upload requests and download requests correspond to different ways of obtaining metadata), the terminal can obtain metadata in different ways based on different request types.
[0053] For example, suppose terminal A sends a file to terminal B. The request type corresponding to the file to be processed is an upload request. In this case, the data packet is transmitted from terminal A to terminal B. Therefore, metadata needs to be extracted from the first data packet sent from terminal A to terminal B. When the request type corresponding to the file to be processed is a download request, terminal A receives the file to be processed sent by terminal B. The data packet is transmitted from terminal B to terminal A. Therefore, the terminal needs to extract metadata from the first data packet sent from terminal B to terminal A.
[0054] Furthermore, in the embodiments of this application, after the terminal obtains the first data packet of the file to be processed through the reassembly thread and extracts the metadata corresponding to the file to be processed from the first data packet, the terminal can further determine whether to restore the file to be processed based on the metadata.
[0055] Step 102: If the file to be processed is determined to be restored based on the metadata, the reconstructed storage address corresponding to the file to be processed is determined according to the preset storage mapping table, and the first data packet is stored in the reconstructed storage address through the reconstructed thread.
[0056] In the embodiments of this application, after the terminal obtains the first data packet of the file to be processed through the reassembly thread and extracts the metadata corresponding to the file to be processed from the first data packet, the terminal can further determine whether to restore the file to be processed based on the metadata. If it is determined to restore the file to be processed, the terminal can determine the reassembly storage address corresponding to the file to be processed according to the preset storage mapping table, and then store the first data packet to the reassembly storage address through the reassembly thread.
[0057] It should be noted that in the embodiments of this application, since there are some files that have no value to be processed, such as files of Hyper Text Markup Language (HTML) or JavaScript (JS) types, the terminal does not need to perform restoration processing on these files. Therefore, in order to better restore the truly meaningful files, the terminal can pre-set preset filtering rules to filter out files that do not meet the restoration conditions and have no restoration value, thereby determining the files that truly need restoration processing.
[0058] Optionally, the terminal can set corresponding preset filtering rules based on metadata; the terminal can also set corresponding preset filtering rules based on domain name, and this application does not specifically limit this.
[0059] Specifically, if preset filtering rules are set based on metadata, the terminal needs to compare the metadata corresponding to the file to be processed with the preset filtering rules. If the metadata corresponding to the file to be processed does not conform to the preset filtering rules, the terminal determines to restore the file to be processed; if the metadata corresponding to the file to be processed conforms to the preset filtering rules, it indicates that the file to be processed is not worth restoring, meaning it does not need to be restored. For example, assuming the preset filtering rule is "files to be processed that are web pages," if the metadata corresponding to the file to be processed indicates that the file type is a web page, the terminal determines not to restore the file to be processed; otherwise, the terminal determines to restore the file to be processed.
[0060] Specifically, if preset filtering rules are set based on domain names, the terminal needs to parse the domain name corresponding to the file to be processed from the first data packet and compare it with the preset filtering rules. If the domain name of the file to be processed does not conform to the preset filtering rules, the terminal determines to restore the file to be processed; if the domain name of the file to be processed conforms to the preset filtering rules, it indicates that the file to be processed has no value for restoration. For example, if the domain names in the filter list of the preset filtering rules are set to "Computer A, Computer D", meaning that files uploaded or downloaded by Computer A and Computer D will not be restored, then when a file sent by Computer A is received, the terminal determines not to restore the file to be processed; otherwise, it determines to restore the file to be processed.
[0061] Furthermore, in the embodiments of this application, after the terminal determines that the file to be processed needs to be restored, the terminal can continue to determine the reconstructed storage address corresponding to the file to be processed through the reconstructed thread and the preset storage mapping table, so as to store the first data packet corresponding to the file to be processed to the reconstructed storage address.
[0062] It should be noted that, in the embodiments of this application, the terminal can determine the reconstructed storage address corresponding to the file to be processed based on metadata and a preset storage mapping table. Specifically, the preset storage mapping table stores metadata, including file session identifiers, attribute parameters, and their correspondence with reconstructed storage addresses. The reconstructed storage address is the memory space for storing file data packets and reconstructing them. The terminal can look up the storage address corresponding to the metadata in the preset storage mapping table based on the metadata of the file to be processed, and use this storage address as the reconstructed storage address corresponding to the file to be processed, thereby storing the first data packet of the file to be processed at this reconstructed storage address.
[0063] Specifically, if the reconstructed storage address corresponding to the file to be processed can be found in the pre-stored storage mapping table based on the metadata of the file to be processed, then the terminal can directly store the first data packet of the file to be processed into the reconstructed storage address; if the reconstructed storage address corresponding to the file to be processed is not found in the pre-stored storage mapping table, then the terminal needs to create a new reconstructed storage address for the file to be processed and update the pre-stored storage mapping table.
[0064] Furthermore, in the embodiments of this application, after the terminal determines the file to be processed based on the metadata, determines the reconstructed storage address corresponding to the file to be processed through the reconstructing thread and the preset storage mapping table, and stores the first data packet to the reconstructed storage address, the terminal can further obtain other data packets of the file to be processed through the reconstructing thread and store the other data packets to the reconstructed storage address as well.
[0065] Step 103: Continue to obtain other data packets of the file to be processed through the reassembly thread, and store the other data packets in sequence to the reassembly storage address to obtain the reassembly data packets corresponding to the file to be processed.
[0066] In the embodiments of this application, after the terminal determines the file to be processed based on the metadata, determines the reconstructed storage address corresponding to the file to be processed through the reconstructing thread and the preset storage mapping table, and stores the first data packet to the reconstructed storage address, the terminal can continue to obtain other data packets corresponding to the file to be processed, and store the other data packets to the same reconstructed storage address to perform data packet reconstructing, thereby obtaining the reconstructed data packet corresponding to the file to be processed.
[0067] It should be noted that, in the embodiments of this application, since the metadata corresponding to the file to be processed is usually carried in the first data packet of the file to be processed, while other data packets are used to carry the file content of the file to be processed, the terminal only needs to obtain the metadata corresponding to the file to be processed from the first data packet of the file to be processed. At the same time, since the terminal judges whether the file to be processed meets the restoration conditions based on the metadata corresponding to the file to be processed, and other data packets only carry the file content of the file to be processed, other data packets only need to be stored in the reconstructed storage address corresponding to the file to be processed according to their corresponding offset positions.
[0068] It should be noted that, in the embodiments of this application, the file to be processed includes single-stream transmission and multi-stream transmission. In single-stream transmission, the first data packet of the file to be processed is the entirety of the file's data packets; while in multi-stream transmission, the file to be processed includes at least two data packets. Therefore, when the file to be processed is in multi-stream transmission, before performing the file restoration process, the terminal needs to perform packet reassembly. That is, the terminal needs to obtain all the data packets of the file to be processed and assemble them in the correct order—this is packet reassembly.
[0069] Specifically, if the file to be processed is transmitted in a single stream, the first data packet contains all file-related information, including file metadata and content. In this case, the terminal does not need to acquire or process other data packets of the file. If the file to be processed is transmitted in multiple streams, after determining the reassembly storage address corresponding to the file, the terminal continues to acquire the remaining data packets of the file. These remaining data packets are identical to the first data packet, and the terminal also stores them at the reassembly storage address to complete the reassembly of the data packets.
[0070] It should be noted that in the embodiments of this application, during normal file transmission, data packets are transmitted in the correct order. However, there is also a process where data packets of the file to be processed are retransmitted or out of order. Since each data packet of the file to be processed carries the sequence number of the fragment data, that is, which fragment of the entire data packet of the file to be processed is the data packet, or the offset, that is, the position of the fragment in the entire data packet; therefore, the terminal can determine the order of storing the data packets to the reassembled storage address according to the correct offset position based on the sequence number of the fragment data or the offset.
[0071] For example, assuming the currently received data packet is the third fragment of the file to be processed, if the data packet was transmitted in the correct order (meaning the reassembled storage address currently only contains the first and second fragments), then the terminal, through the reassembly thread, stores the data packet immediately after the end of the second fragment. If the data packet is out of order, and the first, second, and fourth fragments have already been received before the third fragment, then the terminal needs to store the data packet immediately after the end of the second fragment and immediately after the beginning of the fourth fragment through the reassembly thread. Similarly, if the sequence number corresponding to the data packet is 100-150, then the terminal, through the reassembly thread, only needs to store the data packet immediately after sequence number 99, or between sequence numbers 99 and 151.
[0072] Furthermore, in the embodiments of this application, after storing a portion of the data packets of the file to be processed, the terminal needs to determine whether the data packets stored at the current reassembled storage address are all the data packets of the file to be processed. If it is determined that they are not all the data packets, the terminal continues to obtain the next data packet of the file to be processed until it is determined that all the data packets of the file to be processed are stored at the reassembled storage address.
[0073] Optionally, the terminal can determine whether to store all data packets of the file to be processed in the reassembled storage address based on the number of fragments or the file size. This application does not impose specific limitations on this.
[0074] Specifically, when determining whether to store all data packets based on the number of fragments, the terminal can obtain the total number of fragments based on the first data packet of the file to be processed, and then further determine whether the reassembled storage address has stored all data packets of the file to be processed based on the sequence number of the fragment data carried by each data packet; for example, if the file to be processed has a total of 4 fragments, when the terminal obtains the data packets with the fragment sequence numbers of the first, second, third and fourth fragments of the file to be processed, it indicates that the reassembled storage address is currently storing all data packets of the file to be processed.
[0075] Specifically, when determining whether to store a complete data packet based on the file size, the terminal can obtain the total file size based on the first data packet of the file to be processed, and then further determine whether the reassembled storage address has stored all the data packets of the file to be processed based on the general field representing the file size corresponding to the segment carried by each data packet; for example, if the file to be processed is 100 bytes in total and each segment is 20 bytes, when the terminal obtains 5 segments of the file to be processed, that is, a total of 100 bytes, it indicates that the reassembled storage address is currently storing all the data packets of the file to be processed.
[0076] Furthermore, the terminal uses a reassembly thread to store all data packets of the file to be processed at the correct offset position to the reassembly storage address. That is, after obtaining the reassembly data packet corresponding to the file to be processed, the terminal can further read the reassembly data packet from the reassembly storage address and store the metadata of the file to be processed and the reassembly data packet to the first storage address through the reassembly thread.
[0077] Step 104: Store the metadata and reassembled data packets to the first storage address using the reassembly thread.
[0078] In the embodiments of this application, after the terminal stores all data packets of the file to be processed to the reconstructed storage address and obtains the reconstructed data packets of the file to be processed, the terminal can further store the metadata and reconstructed data packets corresponding to the file to be processed to the first storage address.
[0079] Specifically, in the embodiments of this application, after the terminal completes the data packet reassembly of a certain file to be processed at the reassembly storage address and obtains the corresponding reassembled data packet, the terminal can read the reassembled data packet corresponding to the file from the reassembly storage address through the reassembly thread and then store it in the first storage address.
[0080] It should be noted that in the embodiments of this application, the first storage address is determined by the first address pointer. That is, if the first address pointer points to the first storage address, then after the terminal completes the data packet reconstruction of a certain file to be processed by reconstructing the storage address, it can access the first storage address through the first address pointer and store the metadata and the reconstructed data packet in the first storage address pointed to by the first address pointer. It can be seen that the storage address corresponding to the metadata and the reconstructed data packet is determined based on the direction pointed to by the first address pointer.
[0081] It is understood that, in the embodiments of this application, the first address pointer points to a memory space distinct from the reconstructed memory address, used to store the reconstructed data packets of the file to be processed that has been reconstructed. Specifically, when the first address pointer points to the first storage address, that is, when the first storage address is used to store the reconstructed data packets of the file to be processed, the terminal can access the first storage address based on the first address pointer and store the metadata and reconstructed data packets corresponding to the file to be processed into the first storage address.
[0082] Furthermore, in the embodiments of this application, after the terminal stores the metadata and reassembled data packets to the first storage address pointed to by the first address pointer through the reassembly thread, the terminal continues to read the reassembled data packets of another file to be processed from the reassembly storage address. That is, as long as the reassembly storage address completes the reassembly of a file's data packets, the terminal reads the reassembled data packets through the reassembly thread and stores them to the first storage address pointed to by the first address pointer.
[0083] Step 105: If the reconstruction data packet corresponding to the file to be processed is found at the second storage address through the restoration thread, then the file to be processed is restored according to the reconstruction data packet.
[0084] In the embodiments of this application, if the terminal finds a reconstructed data packet of the file to be processed at the second storage address through the restoration thread, the terminal can restore the file to be processed based on the reconstructed data packet.
[0085] It should be noted that, in the embodiments of this application, the terminal can create a restoration thread, which is used to restore the reconstructed data packets of the file to be processed, so as to obtain the file to be processed. Specifically, the terminal can periodically query the second storage address through the restoration thread to determine whether the reconstructed data packets of the file to be processed exist at the second storage address. If the reconstructed data packets do not exist at the current second storage address, the terminal will wait for the next query time; if the reconstructed data packets exist at the current second storage address, the terminal can restore the file to be processed based on the reconstructed data packets.
[0086] It should be noted that in the embodiments of this application, the second storage address is determined by the second address pointer. That is, if the second address pointer points to the second storage address, the terminal can query the second storage address through the restoration thread, and when there is a reassembled data packet at the second storage address, restore the file to be processed according to the reassembled data packet. It can be seen that the storage address used to store the reassembled data packet is determined based on the pointer of the second address.
[0087] It is understood that in the embodiments of this application, the second address pointer is used to point to the storage address corresponding to the restoration thread. Specifically, when the second address pointer points to the second storage address, that is, when the restoration thread needs to query whether the second storage address contains a reconstructed data packet, the terminal can access the second storage address based on the second address pointer and periodically query whether the second storage address contains a reconstructed data packet to be restored. Then, when a reconstructed data packet exists at the second storage address, the file to be processed is restored based on the reconstructed data packet.
[0088] Specifically, the terminal can obtain the metadata corresponding to the file to be processed from the second storage address pointed to by the second address pointer through the restoration thread, and then extract the reconstructed data packet corresponding to the metadata from the second storage address based on the metadata, and restore the reconstructed data packet to obtain the file to be processed.
[0089] Furthermore, in the embodiments of this application, after the terminal performs restoration processing on the reconstructed data packet through the restoration thread to generate a file to be processed, if a reconstructed data packet corresponding to another file to be processed exists in the second storage address pointed to by the second address pointer, the terminal continues to restore the other file to be processed through the restoration thread until the second storage address pointed to by the second address pointer is empty. That is to say, as long as a reconstructed data packet exists in the storage address pointed to by the second address pointer, the terminal can perform restoration processing through the restoration thread to write the metadata and file content of the file to be processed to the disk.
[0090] Furthermore, in the embodiments of this application, the terminal can also perform pointer switching processing when a preset switching condition is met; that is, when the preset switching condition is met, the terminal can switch the first address pointer from pointing to a first storage address to pointing to a second storage address, and switch the second address pointer from pointing to a second storage address to pointing to a first storage address. At this time, based on the pointer switching processing, the first storage address will be used as the storage address for storing the reassembled data packet, queried by the restoration thread, while the second storage address will be used as the storage address for storing the reassembled data packet, corresponding to the reassembly thread.
[0091] For example, the terminal is provided with a first address pointer P1 and a second address pointer P2, as well as a first storage address Q1 and a second address pointer Q2. Assuming that pointer P1 currently points to address Q1 and pointer P2 points to address Q2, that is, the terminal stores the reassembled data packet in address Q1 through a reassembly thread and restores the reassembled data packet in address Q2 through a restoration thread. When a preset switching condition is met, the terminal performs pointer switching, setting pointer P1 to address Q2 and pointer P2 to address Q1. At this time, the terminal stores the reassembled data packet in address Q2 through the reassembly thread and restores the reassembled data packet in address Q1 through the restoration thread.
[0092] It should be noted that, in the embodiments of this application, the file to be processed obtained by the terminal through the restoration thread includes a session identifier, attribute parameters, and file content. Multiple files to be processed under the same session identifier can be associated for subsequent analysis and processing of these associated files.
[0093] Figure 2 This is a schematic diagram of the execution flow of the file restoration thread proposed in the embodiments of this application, as shown below. Figure 2 As shown, the terminal starts a restoration thread, which continuously polls the storage address pointed to by the second address pointer (step 201) to determine whether the storage address contains a reconstructed data packet of the file to be processed (step 202). If no reconstructed data packet is found, the terminal continues to wait for the next polling. If a reconstructed data packet is found, the terminal obtains the metadata corresponding to the file to be processed (step 203) and extracts the reconstructed data packet corresponding to the file to be processed from the storage address based on the metadata (step 204). Then, the terminal performs restoration processing on the reconstructed data packet to generate the file to be processed (step 205). Further, the terminal performs restoration processing on the next file to be processed, that is, it determines whether the storage address contains a reconstructed data packet of the next file to be processed. If it does, it continues to obtain the metadata corresponding to the next file to be processed to restore the next file to be processed.
[0094] Furthermore, in the embodiments of this application, the terminal can also create a detection thread. After restoring the file to be processed, the terminal can use the detection thread to detect the file content of the file to be processed in order to filter illegal file content. Specifically, if the file content contains illegal or unhealthy content, the terminal will not perform visualization processing on the file to be processed, or will not save the file to be processed; if the file content is ordinary and legal content, the terminal can perform visualization processing on the file to be processed, or save the file to be processed.
[0095] It is understood that in the embodiments of this application, the terminal can create a reassembly thread and a restoration thread. While the reassembly thread reassembles the data packets of the file to be processed that meets the restoration conditions, the terminal can also restore the reassembled data packets through the restoration thread to further obtain the file to be processed. It is evident that the terminal can independently complete the data packet reassembly and restoration process of the file to be processed through multiple threads, which not only simplifies the restoration process but also improves restoration efficiency.
[0096] This application provides a file restoration method. If the data packet obtained by the terminal through the reassembly thread is the first data packet of the file to be processed, the terminal extracts the metadata corresponding to the file to be processed from the first data packet. If the file to be processed is determined to be restored based on the metadata, the reassembly storage address corresponding to the file to be processed is determined according to a preset storage mapping table, and the first data packet is stored in the reassembly storage address through the reassembly thread. The terminal continues to obtain other data packets of the file to be processed through the reassembly thread, and stores these other data packets sequentially in the reassembly storage address to obtain the reassembled data packet corresponding to the file to be processed. The metadata and the reassembled data packet are stored in the first storage address through the reassembly thread. If the restoration thread finds that the reassembled data packet corresponding to the file to be processed exists in the second storage address, the file to be processed is restored based on the reassembled data packet. In other words, in this application embodiment, while the terminal uses the reassembly thread to complete the reassembly of data packets to obtain the reassembled data packet of the file to be processed, the terminal can also use the restoration thread to restore the reassembled data packet to obtain the file to be processed. It is evident that the terminal can independently complete the data packet reassembly and restoration process of the file to be processed through multiple threads, resulting in high file restoration efficiency and overcoming the shortcomings of complex restoration processes, thereby improving file restoration technology.
[0097] Based on the above embodiments, in another embodiment of this application... Figure 3 This is a schematic diagram of the implementation process of the file restoration method proposed in the embodiments of this application. Figure 2 ,like Figure 3 As shown, before extracting the metadata corresponding to the file to be processed from the first data packet obtained by the reassembly thread (i.e., before step 101), the method for the terminal to restore the file may further include the following steps:
[0098] Step 106: Obtain the data packets of the file to be processed through the reorganization thread, and parse the protocol type corresponding to the file to be processed from the data packets.
[0099] In the embodiments of this application, the terminal can obtain the data packets of the file through the reassembly thread, and can further parse the protocol type corresponding to the file to be processed from the data packets.
[0100] It should be noted that, in the embodiments of this application, the terminal can capture the data packets of the file to be processed from the corresponding network port. Since the data packets are encapsulated, the terminal needs to decapsulate the data packets of the file to be processed in order to obtain the protocol type corresponding to the file to be processed.
[0101] Optionally, the terminal can determine the protocol type of the file to be processed based on the network port number or the request type. Specifically, the data packet of the file to be processed carries general fields representing the network port number and the request type. After parsing the data packet, the terminal can determine the network port number and the request type of the file to be processed based on the corresponding general fields, and thus determine the protocol type of the file to be processed based on the network port number or the request type.
[0102] For example, if the terminal determines that the network port number corresponding to the file to be processed is port 80, or that the request type corresponding to the file to be processed is a GET / HOST request, then the terminal can determine that the protocol type corresponding to the file to be processed is the HTTP protocol type.
[0103] Furthermore, in the embodiments of this application, after the terminal obtains the data packet of the file to be processed through the reassembly thread and parses the protocol type corresponding to the file to be processed from the data packet, the terminal can further determine whether the protocol type is the target protocol type.
[0104] Step 107a: If the protocol type is the target protocol type, then the reassembly thread determines whether the data packet is the first data packet of the file to be processed.
[0105] In the embodiments of this application, after the terminal obtains the data packet of the file to be processed through the reassembly thread and parses the protocol type corresponding to the file to be processed from the data packet, the terminal can further determine whether the protocol type is the target protocol type. If the protocol type is the target protocol type, the terminal can continue to determine whether the data packet is the first data packet of the file to be processed through the reassembly thread.
[0106] It should be noted that, in the embodiments of this application, the user can restore the file to be processed corresponding to a specified protocol type according to actual needs. Since the parsing process of the data packets for different protocol types and the restoration process of the files differ, once the user pre-sets the target protocol type, the terminal can only restore the file to be processed corresponding to the target protocol type. Specifically, after determining the protocol type corresponding to the file to be processed, the terminal needs to further determine whether the protocol type is the target protocol type. If it is the target protocol type, then the terminal will further process the data packets of the file to be processed.
[0107] For example, a company's traffic analysis product involves file restoration, but since most of the company's service traffic is HTTP, meaning the target protocol type is HTTP, this indicates that the traffic analysis product only restores HTTP type files to be processed.
[0108] Furthermore, in the embodiments of this application, after determining that the protocol type corresponding to the file to be processed is the target protocol type, the terminal needs to further determine whether the data packet is the first data packet of the file to be processed.
[0109] Optionally, in embodiments of this application, the terminal can determine whether the data packet is the first data packet of the file to be processed based on the request information carried in the data packet. Specifically, the terminal can continue to parse and process the data packet through a reassembly thread to obtain a general field, wherein the general field is used to characterize the request information corresponding to the file to be processed; the terminal can further judge the request information, and if the request information characterizes a start request, then the terminal can determine that the data packet is the first data packet of the file to be processed.
[0110] Furthermore, after obtaining the request information corresponding to the file to be processed, the terminal can also determine the request type corresponding to the file to be processed based on the request information, and obtain the metadata of the file to be processed in a manner corresponding to the request type.
[0111] Step 107b: If the protocol type is not the target protocol type, the next data packet will be obtained through the reassembly thread.
[0112] In the embodiments of this application, after the terminal obtains the data packet of the file to be processed through the reassembly thread and parses the protocol type corresponding to the file to be processed from the data packet, the terminal can further determine whether the protocol type is the target protocol type. If the protocol type is not the target protocol type, the terminal continues to obtain the next data packet through the reassembly thread.
[0113] It should be noted that, in the embodiments of this application, if the protocol type corresponding to the file to be processed is not the target type, then the file to be processed is considered not to meet the restoration conditions, and therefore the terminal does not perform restoration processing on the file to be processed. Further, the terminal continues to receive data packets of the next file to be processed through a reassembly thread to determine the protocol type corresponding to the next file to be processed.
[0114] This application provides a file restoration method. The terminal can parse the data packets of the file to be processed to determine the protocol type corresponding to the file to be processed, so as to further restore the file to be processed with the target protocol type. The file restoration process is simple, overcomes the defects of complex restoration process, and has high file restoration efficiency, further improving the file restoration technology.
[0115] Based on the above embodiments, in another embodiment of this application... Figure 4 This is a schematic diagram of the implementation process of the file restoration method proposed in the embodiments of this application. Figure 3 ,like Figure 4As shown, the method by which the terminal determines the reconstructed storage address corresponding to the file to be processed through the reconstructing thread and the preset storage mapping table includes:
[0116] Step 102a1: If a session identifier exists in the preset storage mapping table, the reorganized storage address is determined based on the attribute parameters and the preset storage mapping table.
[0117] In the embodiments of this application, after determining the file to be processed based on metadata, the terminal can determine the reconstructed storage address based on metadata (session identifier and attribute parameters) and a preset storage mapping table. If a session identifier exists in the preset storage mapping table, the terminal can further determine the reconstructed storage address based on the attribute parameters and the preset storage mapping table.
[0118] Specifically, in the embodiments of this application, the terminal can first determine whether there is a session identifier corresponding to the file to be processed in the preset storage mapping table. If the session identifier exists, the terminal can continue to determine whether there are attribute parameters corresponding to the file to be processed in the preset storage mapping table, thereby determining the reorganization storage address corresponding to the file to be processed.
[0119] It is understood that in the embodiments of this application, different session identifiers correspond to different reassembly storage addresses. Therefore, the terminal can first look up the reassembly storage address corresponding to the file to be processed from the preset storage mapping table based on the session identifier corresponding to the file to be processed.
[0120] Furthermore, since multiple files to be processed may be associated with the same session identifier—for example, multiple different attachments in the same email—and these files are distinguished by different filenames, the same session identifier may correspond to multiple different reconstructed storage addresses in the preset storage mapping table. That is, multiple reconstructed storage addresses are distinguished by multiple attribute parameters, with one attribute parameter corresponding to one reconstructed storage address. Therefore, after determining that a session identifier exists in the preset storage mapping table, the terminal can further determine whether the file parameter corresponding to the file to be processed exists in the preset storage mapping table.
[0121] Optionally, if the preset storage mapping table contains attribute parameters corresponding to the file to be processed, the terminal can determine the storage address corresponding to the attribute parameter in the preset storage mapping table as the reconstructed memory address corresponding to the file to be processed.
[0122] Optionally, if the preset storage mapping table does not contain the attribute parameters corresponding to the file to be processed, meaning that the preset storage mapping table only contains reconstructed storage addresses for other files to be processed that belong to the same session identifier as the file to be processed, then the terminal needs to create a reconstructed storage address corresponding to the current file to be processed. Specifically, the terminal can create a reconstructed storage address corresponding to the file to be processed based on the session identifier and attribute parameters corresponding to the current file to be processed, and store the newly created session identifier, metadata, and the correspondence between the reconstructed storage address into the preset storage mapping table to update the original preset storage mapping table.
[0123] Furthermore, in the embodiments of this application, after the terminal determines the reconstructed storage address corresponding to the file to be processed, it can store the first data packet of the file to be processed obtained into the reconstructed storage address (step 102b).
[0124] Step 102a2: If the session identifier does not exist in the preset storage mapping table, create a reorganized storage address based on the session identifier and attribute parameters, and update the preset storage mapping table.
[0125] In the embodiments of this application, if the session identifier does not exist in the preset storage mapping table, the terminal can create the reconstructed storage address corresponding to the file to be processed based on the session identifier and attribute parameters corresponding to the file to be processed, and update the preset storage mapping table.
[0126] It should be noted that, in the embodiments of this application, if the session identifier corresponding to the file to be processed does not exist in the preset storage mapping table, it indicates that the terminal has not previously created a corresponding reconstructed storage address for any file to be processed associated with that session identifier. Therefore, the terminal can create a reconstructed storage address corresponding to the file to be processed based on the session identifier and attribute parameters of the current file to be processed, and store this new correspondence between the created file to be processed session identifier, metadata, and reconstructed storage address into the preset storage mapping table to update the original preset storage mapping table.
[0127] This application provides a file restoration method. A terminal can further determine the reconstructed storage address corresponding to the file to be processed based on the session identifier, attribute parameters, and a preset storage mapping table, and then reconstruct the file data packets at that reconstructed storage address. The file restoration process is simple, overcoming the shortcomings of complex restoration processes, and has high file restoration efficiency, further improving file restoration technology.
[0128] Based on the above embodiments, in another embodiment of this application... Figure 5 This is a schematic diagram of the implementation process of the file restoration method proposed in the embodiments of this application. Figure 4 ,like Figure 5As shown, the method for restoring files in a terminal may also include the following steps:
[0129] Step 301: Determine the preset switching period corresponding to the first storage address and the storage status corresponding to the second storage address.
[0130] Step 302: If the preset switching period and the storage state meet the first preset switching condition, then perform pointer switching processing to point the first address pointer to the second storage address, and the second address pointer to the first storage address.
[0131] In the embodiments of this application, after the terminal reads the reconstructed data packet corresponding to the file to be processed from the reconstructed storage address and stores it in the first storage address pointed to by the first address pointer, the terminal can confirm the preset switching period corresponding to the first storage address and the storage status corresponding to the second storage address pointed to by the second address pointer in real time, and perform pointer switching processing when the preset switching period and the storage status meet the first preset switching condition.
[0132] It should be noted that, in the embodiments of this application, the terminal is provided with two address pointers, including a first address pointer and a second address pointer; and two storage addresses are allocated to the two address pointers, including a first storage address and a second storage address.
[0133] Specifically, the first address pointer is used to point to the memory space corresponding to the reassembly thread that stores the reassembled data packets. That is, the terminal reads the reassembled data packets corresponding to the file to be processed from the reassembly storage address through the reassembly thread and puts them into the storage address pointed to by the first address pointer. Optionally, if the first address pointer points to the first storage address, then the terminal stores the reassembled data packets of the reassembly storage address into the first storage address; if the first address pointer points to the second storage address, then the terminal stores the reassembled data packets of the reassembly storage address into the second storage address.
[0134] Specifically, the second address pointer is used to point to the memory space corresponding to the restoration thread where the reassembled data packets are stored. That is, the terminal can use the restoration thread to restore the reassembled data packets in the memory address pointed to by the second address pointer. Optionally, if the second address pointer points to the first memory address, the terminal can use the restoration thread to restore the reassembled data packets in the first memory address; if the second address pointer points to the second memory address, the terminal can use the restoration thread to restore the reassembled data packets in the second memory address.
[0135] It is understood that, in the embodiments of this application, the types of data packets stored at the first storage address and the second storage address are determined based on the first address pointer and the second address pointer. That is, if the first address pointer points to the first storage address, then the first storage address is used to store the reassembled data packets corresponding to the reassembled thread; if the first address pointer points to the second storage address, then the second storage address is used to store the reassembled data packets corresponding to the reassembled thread; the same applies to the second storage address, and will not be elaborated here.
[0136] Furthermore, in the embodiments of this application, in order to better save memory space and avoid the performance overhead caused by frequent locking during multi-threaded operations, the terminal can switch storage addresses when preset conditions are met. Specifically, the terminal can switch storage addresses through pointer switching. For example, assuming that the first address pointer currently points to the first storage address and the second address pointer points to the second storage address, that is, the first storage address stores the reassembled data packet corresponding to the reassembled thread, and the second storage address stores the reassembled data packet corresponding to the restore thread; if the terminal wants to store the reassembled data packet to the second storage address through the reassembled thread, and query the reassembled data packet in the first storage address through the restore thread, then the terminal can switch the first address pointer from pointing to the first storage address to pointing to the second storage address, and switch the second address pointer from pointing to the second storage address to pointing to the first storage address.
[0137] Specifically, the terminal can perform pointer switching processing when a first preset condition is met. More specifically, when the first address pointer currently points to the first storage address and the second address pointer points to the second storage address, the terminal can determine the preset switching period corresponding to the first storage address and the storage state corresponding to the second storage address. If the first storage address meets the preset switching period and the storage state corresponding to the second storage address is empty, then the terminal can perform pointer switching processing to switch the first address pointer from pointing to the first storage address to pointing to the second storage address, and to switch the second address pointer from pointing to the second storage address to pointing to the first storage address. After the switching, the terminal can store the reassembled data packet in the second storage address through the reassembly thread, and query the reassembled data packet in the first storage address through the restoration thread.
[0138] Based on the above embodiments, in another embodiment of this application... Figure 6 This is a schematic diagram of the implementation process of the file restoration method proposed in the embodiments of this application. Figure 5 ,like Figure 6 As shown, the method for restoring files in a terminal may also include the following steps:
[0139] Step 401: Determine the storage status corresponding to the first storage address and the storage status corresponding to the second storage address.
[0140] Step 402: If the storage state corresponding to the first address pointer and the storage state corresponding to the second address pointer satisfy the second preset switching condition, then perform pointer switching processing to make the first address pointer point to the second storage address and the second address pointer point to the first storage address.
[0141] In the embodiments of this application, after the terminal reads the reconstructed data packet corresponding to the file to be processed from the reconstructed storage address and stores it into the first storage address pointed to by the first address pointer, the terminal can confirm the storage status corresponding to the first storage address and the storage status corresponding to the second storage address pointed to by the second address pointer in real time, and perform pointer switching processing when the storage status meets the second preset switching condition.
[0142] Specifically, the terminal can perform pointer switching processing when the second preset condition is met. More specifically, when the first address pointer currently points to the first storage address and the second address pointer points to the second storage address, the terminal can first determine the storage state corresponding to the first storage address and the storage state corresponding to the second storage address. If the storage state corresponding to the first storage address meets the preset storage threshold and the storage state corresponding to the second storage address is empty, then the terminal can perform pointer switching processing to switch the first address pointer from pointing to the first storage address to pointing to the second storage address, and switch the second address pointer from pointing to the second storage address to pointing to the first storage address. After the switching, the terminal can store the reassembled data packet in the second storage address through the reassembly thread, and query the reassembled data packet in the first storage address through the restoration thread.
[0143] This application provides a file restoration method. When the preset switching conditions are met, the terminal can perform pointer switching to realize the switching of storage addresses, which saves memory space, avoids the performance overhead caused by frequent locking during multi-threaded operations, simplifies the file restoration process, overcomes the defects of complex restoration processes, and has high file restoration efficiency, further improving file restoration technology.
[0144] Based on the above embodiments, in another embodiment of this application, Figure 7 This is a schematic diagram of the execution flow of the file reassembly thread proposed in an embodiment of this application, as shown below. Figure 7 As shown in the embodiments of this application, the method for restoring files by the terminal through a reassembly thread may include the following steps:
[0145] Step 501: Obtain the data packet of the file to be processed.
[0146] Since the file to be processed is transmitted over the network in the form of data packets, the terminal can capture the data packets of the file to be processed from the corresponding network port.
[0147] Step 502: Parse the protocol type corresponding to the file to be processed from the data packet.
[0148] Because the data packets are encapsulated, the terminal needs to decapsulate the data packets of the file to be processed to obtain the protocol type corresponding to the file. Specifically, the terminal can determine the protocol type of the file to be processed based on the network port number corresponding to the file or the request type.
[0149] Step 503: Determine if the protocol type is the target protocol type; if yes, proceed to step 504; otherwise, proceed to step 501.
[0150] Specifically, after determining the protocol type corresponding to the file to be processed, the terminal needs to further determine whether the protocol type is the target protocol type. If it is the target protocol type, then continue to execute step 504; if the protocol type corresponding to the file to be processed does not belong to the target protocol type, then jump to execute step 501 and continue to receive the data packets of the next file to be processed through the reassembly thread.
[0151] Step 504: Determine if the data packet is the first data packet of the file to be processed; if yes, proceed to step 505; otherwise, proceed to step 508.
[0152] Specifically, the terminal can continue to parse and process the data packet through the reassembly thread to obtain a general field, which is used to represent the request information corresponding to the file to be processed. Further, the terminal can determine whether the request information is a start request. If the request information is a start request, that is, the data packet is the first data packet of the file to be processed, then continue to execute step 505; otherwise, it is not the first data packet of the file to be processed, and the terminal jumps to execute step 508 to store the data packet according to the offset position to the reassembly storage address corresponding to the file to be processed.
[0153] Step 505: Extract metadata from the first data packet and determine whether the metadata conforms to the preset filtering rules; if it does, proceed to step 501; otherwise, proceed to step 506.
[0154] Optionally, the terminal can set corresponding preset filtering rules based on metadata; or the terminal can set corresponding preset filtering rules based on domain name.
[0155] For example, if the preset filtering rule is "files to be processed that are web pages", then when the file type corresponding to the file to be processed is a web page, the terminal determines that the metadata meets the preset filtering rule. That is, the terminal does not restore the file to be processed. At this time, the terminal executes step 501, that is, obtains the next data packet; otherwise, the terminal determines that the metadata does not meet the preset filtering rule, that is, it determines to restore the file to be processed, and continues to execute step 506.
[0156] 506. Determine whether the reconstructed storage address corresponding to the file to be processed exists in the preset storage mapping table; if it exists, proceed to step 508; otherwise, proceed to step 507.
[0157] The preset storage mapping table contains metadata, namely the session identifier and file attribute parameters corresponding to the file, and their correspondence with the file reconstruction storage address. Specifically, the terminal can first determine whether the preset storage mapping table contains a session identifier corresponding to the file to be processed. If the session identifier exists, the terminal can then determine whether the preset storage mapping table contains the attribute parameters corresponding to the file to be processed. If the preset storage mapping table contains both the session identifier and attribute parameters corresponding to the file to be processed, it indicates that the preset storage mapping table contains the reconstruction storage address corresponding to the file to be processed, and the terminal proceeds to step 508; otherwise, it indicates that the reconstruction storage address corresponding to the file to be processed does not exist, and the terminal continues to step 507.
[0158] Step 507: Create the reconstructed storage address corresponding to the file to be processed based on the session identifier and attribute parameters, and update the preset storage mapping table.
[0159] Specifically, the terminal can create a reconstructed storage address corresponding to the file to be processed based on the session identifier and attribute parameters corresponding to the file to be processed, and store the newly created session identifier, metadata and reconstructed storage address correspondence into a preset storage mapping table to update the original preset storage mapping table.
[0160] Step 508: Store the data packet at the reassembly storage address corresponding to the file to be processed.
[0161] After determining the reassembly storage address corresponding to the file to be processed, the terminal can store all the data packets of the file to be processed at the reassembly storage address according to the corresponding offset position in order to reassemble the data packets.
[0162] Step 509: Determine whether the recombination is complete; if complete, proceed to step 510; otherwise, proceed to step 501.
[0163] Optionally, the terminal can determine whether the data packets corresponding to the file to be processed have been reassembled based on the number of fragments corresponding to the file to be processed, or based on the file size. If the reassembly is complete, then proceed to step 510; if the reassembly is not complete, then proceed to step 501 to continue receiving the next data packet of the file to be processed.
[0164] Step 510: When the first address pointer points to the first storage address, the reassembled data packet is stored in the first storage address.
[0165] The terminal can read the reassembled data packet of the file to be processed after the reassembly is completed from the reassembly storage address and store it in the storage address pointed to by the first address pointer; if the first address pointer is currently pointing to the first storage address, then the reassembled data packet is stored in the first storage address.
[0166] Based on the method for terminal file restoration via a reassembly thread proposed in steps 501 to 510 above, the terminal can filter out files that do not meet the restoration conditions through the reassembly thread, and further reassemble the data packets of the files to be processed based on the reassembly storage address corresponding to the files to be processed. After completing the data packet reassembly of a file to be processed, the reassembly process of the next file to be processed continues. It is evident that the terminal can independently complete the reassembly process of the files to be processed through the reassembly thread, which not only simplifies the process and overcomes the shortcomings of complex processes, but also achieves high reassembly efficiency, further improving file restoration technology.
[0167] This application provides a file restoration method in which the terminal can independently complete the reconstruction process of the file to be processed through the reconstruction thread, overcoming the defects of complex process and having high reconstruction efficiency, thus further improving the file restoration technology.
[0168] Select the files to be processed that meet the restoration conditions, determine the reconstructed storage address corresponding to the files to be processed, and then reconstruct the data packets based on the reconstructed storage address to obtain the reconstructed data packets corresponding to the files to be processed. Furthermore, store the reconstructed data packets at the storage address pointed to by the first address pointer.
[0169] Based on the above embodiments, in another embodiment of this application... Figure 8 This is a schematic diagram of the terminal structure proposed in this application. Figure 1 ,like Figure 8 As shown, the terminal 10 proposed in this application embodiment may include an extraction part 11, a determination part 12, a storage part 13, an acquisition part 14, a restoration part 15, a parsing part 16, a judgment part 17, and a switching part 18.
[0170] The extraction part 11 is configured to extract the metadata corresponding to the file to be processed from the first data packet if the data packet obtained by the reorganization thread is the first data packet of the file to be processed.
[0171] The determining part 12 is configured to determine the reconstructed storage address corresponding to the file to be processed according to a preset storage mapping table if it is determined that the file to be processed is to be restored based on the metadata.
[0172] The storage portion 13 is configured to store the first data packet to the reassembly storage address via the reassembly thread;
[0173] The acquisition section 14 is configured to continue acquiring other data packets of the file to be processed through the reorganization thread;
[0174] The storage section 13 is further configured to sequentially store the other data packets to the reconstructed storage address to obtain the reconstructed data packet corresponding to the file to be processed; and to store the metadata and the reconstructed data packet to the first storage address through the reconstructed thread;
[0175] The restoration section 15 is configured to restore the file to be processed based on the reconstructed data packet if the second storage address is found to contain the file to be processed through the restoration thread.
[0176] Furthermore, in an embodiment of this application, the parsing part 16 is configured to obtain the data packet of the file to be processed through the reassembly thread and parse the protocol type corresponding to the file to be processed from the data packet before extracting the metadata corresponding to the file to be processed from the first data packet if the data packet obtained through the reassembly thread is the first data packet of the file to be processed.
[0177] Furthermore, in an embodiment of this application, the determination part 17 is configured to determine whether the data packet is the first data packet of the file to be processed by the reassembly thread if the protocol type is the target protocol type.
[0178] Furthermore, in an embodiment of this application, the acquisition part 14 is also configured to continue acquiring the next data packet through the reassembly thread if the protocol type is not the target protocol type.
[0179] Furthermore, in an embodiment of this application, the determination part 17 is specifically configured to continue parsing the data packet through the reorganization thread to obtain the request information corresponding to the file to be processed; and if the request information indicates a start request, then the data packet is determined to be the first data packet.
[0180] Furthermore, in an embodiment of this application, the extraction part 11 is specifically configured to determine the request type corresponding to the file to be processed based on the request information; wherein the request type includes upload request and download request; and to obtain the metadata based on the request type.
[0181] Furthermore, in an embodiment of this application, the determination part 17 is further configured to, after extracting the metadata corresponding to the file to be processed from the first data packet, and before determining the reconstructed storage address corresponding to the file to be processed according to a preset storage mapping table if the metadata does not conform to a preset filtering rule, then determine to restore the file to be processed; wherein, the preset filtering rule is used to filter out files to be processed that do not conform to the restoration conditions; if the metadata conforms to the preset filtering rule, then determine not to restore the file to be processed.
[0182] Furthermore, in the embodiments of this application, the metadata includes a session identifier and attribute parameters. The determining part 12 is specifically configured to: if the session identifier exists in the preset storage mapping table, determine the reconstructed storage address based on the attribute parameters and the preset storage mapping table; and if the session identifier does not exist in the preset storage mapping table, create the reconstructed storage address based on the session identifier and the attribute parameters, and update the preset storage mapping table.
[0183] Furthermore, in the embodiments of this application, the determining part 12 is specifically configured to: if the attribute parameter exists in the preset storage mapping table, determine the storage address corresponding to the attribute parameter in the preset storage mapping table as the reconstructed memory address; and if the attribute parameter does not exist in the preset storage mapping table, create the reconstructed memory address according to the session identifier and the attribute parameter, and update the preset storage mapping table.
[0184] Furthermore, in an embodiment of this application, when the first address pointer points to the first storage address and the second address pointer points to the second storage address, the storage portion 13 is specifically configured to access the first storage address based on the first address pointer; and to store the metadata and the reassembled data packet in the first storage address.
[0185] Furthermore, in an embodiment of this application, the restoration part 15 is specifically configured to access the second storage address based on the second address pointer to obtain the metadata; and extract the reconstructed data packet corresponding to the file to be processed from the second storage address according to the metadata; and generate the file to be processed according to the reconstructed data packet.
[0186] Furthermore, in an embodiment of this application, the determining part 12 is further configured to determine the preset switching period corresponding to the first storage address and the storage state corresponding to the second storage address.
[0187] Furthermore, in an embodiment of this application, the switching part 18 is configured to perform pointer switching processing if the preset switching period and the storage state satisfy the first preset switching condition, so as to point the first address pointer to the second storage address and the second address pointer to the first storage address.
[0188] Furthermore, in an embodiment of this application, the determining part 12 is further configured to determine the storage state corresponding to the first storage address and the storage state corresponding to the second storage address.
[0189] Furthermore, in an embodiment of this application, the switching part 18 is further configured to perform pointer switching processing if the storage state corresponding to the first address pointer and the storage state corresponding to the second address pointer meet the second preset switching condition, so as to make the first address pointer point to the second storage address and the second address pointer point to the first storage address.
[0190] In the embodiments of this application, further, Figure 9 This is a schematic diagram of the terminal structure proposed in this application. Figure 2 ,like Figure 9 As shown, the terminal 10 proposed in this application embodiment may further include a processor 19, a memory 110 storing instructions executable by the processor 19, and further, the terminal 10 may also include a communication interface 111 and a bus 112 for connecting the processor 19, the memory 110 and the communication interface 111.
[0191] In the embodiments of this application, the processor 19 can be at least one of the following: Application-Specific Integrated Circuit (ASIC), Digital Signal Processor (DSP), Digital Signal Processing Device (DSPD), Programmable Logic Device (PLD), Field Programmable Gate Array (FPGA), Central Processing Unit (CPU), Controller, Microcontroller, and Microprocessor. It is understood that for different devices, the electronic device used to implement the above-mentioned processor function can also be other, and this application embodiment does not specifically limit it. The terminal 10 may also include a memory 110, which can be connected to the processor 19. The memory 110 is used to store executable program code, which includes computer operation instructions. The memory 110 may include high-speed RAM memory and may also include non-volatile memory, such as at least two disk drives.
[0192] In embodiments of this application, bus 112 is used to connect communication interface 111, processor 19, and memory 110, as well as the mutual communication between these devices.
[0193] In embodiments of this application, memory 110 is used to store instructions and data.
[0194] Further, in an embodiment of this application, the processor 19 is configured to: if the data packet obtained by the reassembly thread is the first data packet of the file to be processed, extract the metadata corresponding to the file to be processed from the first data packet; if it is determined that the file to be processed should be restored based on the metadata, determine the reassembly storage address corresponding to the file to be processed according to a preset storage mapping table, and store the first data packet to the reassembly storage address through the reassembly thread; continue to obtain other data packets of the file to be processed through the reassembly thread, and store the other data packets sequentially to the reassembly storage address to obtain the reassembly data packet corresponding to the file to be processed; store the metadata and the reassembly data packet to a first storage address through the reassembly thread; if the reassembly data packet corresponding to the file to be processed is found in the second storage address through the restoration thread, restore the file to be processed according to the reassembly data packet.
[0195] In practical applications, the aforementioned memory 110 can be volatile memory, such as random-access memory (RAM); or non-volatile memory, such as read-only memory (ROM), flash memory, hard disk drive (HDD), or solid-state drive (SSD); or a combination of the above types of memory, and provides instructions and data to the processor 19.
[0196] Furthermore, in this embodiment, the functional modules can be integrated into a single file restoration unit, or each unit can exist as a separate physical entity, or two or more units can be integrated into a single unit. The integrated unit can be implemented in hardware or as a software functional module.
[0197] If the integrated unit is implemented as a software functional module and is not sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this embodiment, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute all or part of the steps of the method of this embodiment. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0198] This application provides a terminal. If the data packet obtained by the reassembly thread is the first data packet of the file to be processed, the terminal extracts the metadata corresponding to the file to be processed from the first data packet. If it is determined that the file to be processed needs to be restored based on the metadata, the terminal determines the reassembly storage address corresponding to the file to be processed according to a preset storage mapping table, and stores the first data packet to the reassembly storage address through the reassembly thread. The terminal continues to obtain other data packets of the file to be processed through the reassembly thread, and stores these other data packets sequentially to the reassembly storage address to obtain the reassembled data packet corresponding to the file to be processed. The reassembly thread stores the metadata and the reassembled data packet to a first storage address. If the restoration thread finds that the reassembled data packet corresponding to the file to be processed exists at a second storage address, the terminal performs restoration processing on the file to be processed based on the reassembled data packet. In other words, in this application embodiment, while the terminal uses the reassembly thread to complete the reassembly of data packets to obtain the reassembled data packet of the file to be processed, the terminal can also use the restoration thread to restore the reassembled data packet to obtain the file to be processed. It is evident that the terminal can independently complete the data packet reassembly and restoration process of the file to be processed through multiple threads, achieving high file restoration efficiency and overcoming the shortcomings of complex restoration processes, thereby improving file restoration technology.
[0199] This application provides a computer-readable storage medium storing a program thereon, which, when executed by a processor, implements the file restoration method described above.
[0200] Specifically, the program instructions corresponding to a file recovery method in this embodiment can be stored on storage media such as optical discs, hard disks, and USB flash drives. When the program instructions corresponding to a file recovery method in the storage media are read or executed by an electronic device, the following steps are included:
[0201] If the data packet obtained through the reassembly thread is the first data packet of the file to be processed, then extract the metadata corresponding to the file to be processed from the first data packet;
[0202] If the file to be processed is determined to be restored based on the metadata, the reconstructed storage address corresponding to the file to be processed is determined according to the preset storage mapping table, and the first data packet is stored in the reconstructed storage address through the reconstructed thread.
[0203] The reconstructing thread continues to acquire other data packets of the file to be processed, and these other data packets are sequentially stored in the reconstructing storage address to obtain the reconstructed data packets corresponding to the file to be processed.
[0204] The reconstructing thread stores the metadata and the reconstructed data packet to the first storage address.
[0205] If the reconstruction data packet corresponding to the file to be processed is found at the second storage address through the restoration thread, the file to be processed is restored according to the reconstruction data packet.
[0206] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of hardware embodiments, software embodiments, or embodiments combining software and hardware aspects. Furthermore, this application can take the form of a computer program product implemented on one or more computer-usable storage media (including, but not limited to, disk storage and optical storage) containing computer-usable program code.
[0207] This application is described with reference to schematic and / or block diagrams of implementations of methods, apparatus (systems), and computer program products according to embodiments of this application. It should be understood that each block of the schematic and / or block diagrams can be implemented by computer program instructions, and combinations of blocks in the schematic and / or block diagrams can be implemented. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create a machine for implementing the schematic and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0208] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in the implementation flow diagram. Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0209] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0210] The above description is merely a preferred embodiment of this application and is not intended to limit the scope of protection of this application.
[0211] Industrial applicability
[0212] This application discloses a file restoration method, terminal, and storage medium. The method includes: if the data packet obtained by the reassembly thread is the first data packet of the file to be processed, then extracting the metadata corresponding to the file to be processed from the first data packet; if it is determined that the file to be processed needs to be restored based on the metadata, then determining the reassembly storage address corresponding to the file to be processed according to a preset storage mapping table, and storing the first data packet to the reassembly storage address through the reassembly thread; continuing to obtain other data packets of the file to be processed through the reassembly thread, and storing the other data packets sequentially to the reassembly storage address to obtain the reassembly data packet corresponding to the file to be processed; storing the metadata and the reassembly data packet to a first storage address through the reassembly thread; if the restoration thread finds that the reassembly data packet corresponding to the file to be processed exists at a second storage address, then restoring the file to be processed based on the reassembly data packet. In other words, in the embodiments of this application, while the terminal uses the reassembly thread to complete the reassembly of data packets to obtain the reassembly data packet of the file to be processed, the terminal can also use the restoration thread to restore the reassembly data packet to obtain the file to be processed. It is evident that the terminal can independently complete the data packet reassembly and restoration process of the file to be processed through multiple threads, resulting in high file restoration efficiency and overcoming the shortcomings of complex restoration processes, thereby improving file restoration technology.
Claims
1. A file recovery method, the method comprising: If the data packet obtained through the reassembly thread is the first data packet of the file to be processed, then extract the metadata corresponding to the file to be processed from the first data packet; If the file to be processed is determined to be restored based on the metadata, the reconstructed storage address corresponding to the file to be processed is determined according to the preset storage mapping table, and the first data packet is stored in the reconstructed storage address through the reconstructed thread. The reconstructing thread continues to acquire other data packets of the file to be processed, and these other data packets are sequentially stored in the reconstructing storage address to obtain the reconstructed data packets corresponding to the file to be processed. The reconstructing thread stores the metadata and the reconstructed data packet to the first storage address. If the reconstruction data packet corresponding to the file to be processed is found at the second storage address through the restoration thread, the file to be processed is restored according to the reconstruction data packet.
2. The method according to claim 1, wherein, If the data packet obtained through the reassembly thread is the first data packet of the file to be processed, before extracting the metadata corresponding to the file to be processed from the first data packet, the method further includes: The reassembly thread obtains the data packets of the file to be processed and parses the protocol type corresponding to the file to be processed from the data packets; If the protocol type is the target protocol type, then the reassembly thread determines whether the data packet is the first data packet of the file to be processed; If the protocol type is not the target protocol type, the next data packet will be obtained through the reassembly thread.
3. The method according to claim 2, wherein, The step of determining whether the data packet is the first data packet of the file to be processed through the reassembly thread includes: The data packet is further parsed and processed by the reassembly thread to obtain the request information corresponding to the file to be processed; If the request information indicates a start request, then the data packet is determined to be the first data packet.
4. The method according to claim 3, wherein, Extracting the metadata corresponding to the file to be processed from the first data packet includes: The request type corresponding to the file to be processed is determined based on the request information; wherein, the request type includes upload request and download request; The metadata is obtained based on the request type.
5. The method according to claim 1, wherein, After extracting the metadata corresponding to the file to be processed from the first data packet, and before determining the reconstructed storage address corresponding to the file to be processed according to a preset storage mapping table if the file to be processed is determined to be restored based on the metadata, the method further includes: If the metadata does not conform to the preset filtering rules, then it is determined to restore the file to be processed; wherein, the preset filtering rules are used to filter out the files to be processed that do not meet the restoration conditions; If the metadata matches the preset filtering rules, then it is determined that the file to be processed will not be restored.
6. The method according to claim 1, wherein, The metadata includes a session identifier and attribute parameters. Determining the reconstructed storage address corresponding to the file to be processed based on a preset storage mapping table includes: If the session identifier exists in the preset storage mapping table, the reorganized storage address is determined according to the attribute parameters and the preset storage mapping table; If the session identifier does not exist in the preset storage mapping table, the reconstructed storage address is created based on the session identifier and the attribute parameters, and the preset storage mapping table is updated.
7. The method according to claim 6, wherein, Determining the reorganized storage address based on the attribute parameters and the preset storage mapping table includes: If the attribute parameter exists in the preset storage mapping table, then the storage address corresponding to the attribute parameter in the preset storage mapping table is determined as the reorganized storage address; If the attribute parameter does not exist in the preset storage mapping table, the reconstructed storage address is created based on the session identifier and the attribute parameter, and the preset storage mapping table is updated.
8. The method according to claim 1, wherein, When the first address pointer points to the first storage address and the second address pointer points to the second storage address, the step of storing the metadata and the reassembled data packet to the first storage address through the reassembly thread includes: Access the first storage address based on the first address pointer; The metadata and the reassembled data packet are stored in the first storage address.
9. The method according to claim 8, wherein, If the reconstruction data packet corresponding to the file to be processed is found at the second storage address through the restoration thread, then the file to be processed is restored according to the reconstruction data packet, including: Access the second storage address based on the second address pointer to obtain the metadata; Based on the metadata, extract the reconstructed data packet corresponding to the file to be processed from the second storage address; The file to be processed is generated based on the recombined data packet.
10. The method according to claim 9, wherein, The method further includes: Determine the preset switching period corresponding to the first storage address and the storage status corresponding to the second storage address; If the preset switching period and the storage state meet the first preset switching condition, then a pointer switching process is performed to point the first address pointer to the second storage address, and the second address pointer to the first storage address.
11. The method according to claim 9, wherein, The method further includes: Determine the storage state corresponding to the first storage address and the storage state corresponding to the second storage address; If the storage state corresponding to the first address pointer and the storage state corresponding to the second address pointer meet the second preset switching condition, then a pointer switching process is performed to make the first address pointer point to the second storage address and the second address pointer point to the first storage address.
12. A terminal, the terminal comprising: Extraction section, determination section, storage section, retrieval section, and restoration section. The extraction part is configured to extract the metadata corresponding to the file to be processed from the first data packet if the data packet obtained by the reassembly thread is the first data packet of the file to be processed. The determining part is configured such that if it is determined based on the metadata that the file to be processed is to be restored, then the reconstructed storage address corresponding to the file to be processed is determined according to a preset storage mapping table. The storage portion is configured to store the first data packet to the reassembly storage address via the reassembly thread; The acquisition section is configured to continue acquiring other data packets of the file to be processed through the reorganization thread; The storage section is further configured to sequentially store the other data packets to the reconstructed storage address to obtain the reconstructed data packet corresponding to the file to be processed; and to store the metadata and the reconstructed data packet to the first storage address through the reconstructed thread; The restoration section is configured to perform restoration processing on the file to be processed based on the reconstructed data packet if the second storage address is found to contain the file to be processed through the restoration thread.
13. A terminal, the terminal comprising a processor and a memory storing processor-executable instructions, wherein when the instructions are executed by the processor, the terminal implements the method as described in any one of claims 1-11.
14. A computer-readable storage medium having a program stored thereon, which is applied to a terminal and, when executed by a processor, implements the method as described in any one of claims 1-11.
Citation Information
Patent Citations
File uploading method and device
CN107743137A
Data processing method and device, equipment and storage medium
CN110825694A