Networking method and network system based on P2P technology
By establishing a P2P tunnel between network terminal devices, the high economic expenditure and low efficiency problems of traditional video stream transit methods are solved, direct access and efficient data transmission of different local area networks are achieved, and the dependence of cloud servers is reduced.
Patent Information
- Application Number
- CN202410991226.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-23
- Publication Date
- 2024-11-12
AI Technical Summary
The traditional way of video streaming through cloud servers leads to high economic expenditures and low data transmission efficiency. P2P technology can only realize point-to-point data transmission, cannot realize the functions of the network layer, and cannot directly connect different local area networks.
By establishing a P2P tunnel between network terminal devices, using the P2P-TUN module to drill holes, forming a P2P network connection, realizing direct access and data transmission of different local area networks, and avoiding data transfer through cloud servers.
It realizes direct access to different LANs, saves economic expenses of transit servers, reduces the time delay of data transmission, and improves data transmission efficiency.
Smart Images

Figure CN118945173A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of communication technology, and in particular to a networking method and a network system based on P2P technology. Background Art
[0002] In some engineering projects, the amount of video transmission data is large. The traditional way of transferring video streams through cloud servers not only brings high economic expenses, but also the network delay is affected by the bandwidth of the cloud server, resulting in low data transmission efficiency. P2P (Peer-to-Peer) technology is a point-to-point direct tunnel technology, which does not transfer data through cloud servers in the middle. However, P2P technology can only realize point-to-point data transmission and cannot realize the functions of the network layer.
[0003] Therefore, how to use P2P technology to connect different local area networks to achieve direct access between different networks has become one of the technical problems that need to be solved urgently at this stage. Summary of the invention
[0004] In order to solve the above technical problems, the present disclosure provides a networking method and a network system based on P2P technology.
[0005] In a first aspect, the present disclosure provides a networking method based on P2P technology, comprising:
[0006] Setting configuration information of a first networking terminal device and a second networking terminal device, and powering on the first networking terminal device and the second networking terminal device, wherein the first networking terminal device and the second networking terminal device both include a P2P-TUN module, and the first networking terminal device and the second networking terminal device have the same networking number;
[0007] The P2P-TUN module is initialized;
[0008] The P2P-TUN module in the first networking terminal device sends a first online information data packet to the P2P server, and the P2P-TUN module in the second networking terminal device sends a second online information data packet to the P2P server;
[0009] The P2P server receives the first online information data packet and the second online information data packet, sends the first online information data packet to the second networking terminal device having the same networking number as the first networking terminal device, and sends the second online information data packet to the first networking terminal device having the same networking number as the second networking terminal device;
[0010] The P2P-TUN module performs hole punching, the first networking terminal device and the second networking terminal device establish a P2P tunnel, the first networking terminal device receives the second online information data packet of the second networking terminal device, and the second networking terminal device receives the first online information data packet of the first networking terminal device;
[0011] The first networking terminal device performs network settings on the first networking terminal device according to the second online information data packet, and the second networking terminal device performs network settings on the second networking terminal device according to the first online information data packet.
[0012] Optionally, where:
[0013] The first online information data packet and the second online information data packet both include: the public network NAT IP address of the device, the source port number after NAT, the device number, the device IP address, the routing network segment and the networking number.
[0014] Optionally, where:
[0015] The P2P-TUN module performs hole punching including:
[0016] Setting the TTL value of the first online information data packet and the TTL value of the second online information data packet to be less than the propagation threshold, so that the second networking terminal device cannot receive the first online information data packet, and the first networking terminal device cannot receive the second online information data packet;
[0017] The first network NAT router corresponding to the first networking terminal device generates a forward Session record for the second networking terminal device, and the second network NAT router corresponding to the second networking terminal device generates a forward Session record for the first networking terminal device.
[0018] Optionally, where:
[0019] The P2P-TUN module performs periodic hole punching, the hole punching period is T, and the number of hole punching is N;
[0020] T≥2s, N≥3 times.
[0021] Optionally, where:
[0022] Also includes:
[0023] In the Linux system in the first networking terminal device, a virtual network card is established.
[0024] Optionally, where:
[0025] The method also includes transmitting the data of the virtual network card through the P2P tunnel.
[0026] Optionally, where:
[0027] The method also includes receiving data through the P2P tunnel and writing the data into the virtual network card.
[0028] Optionally, where:
[0029] The configuration information includes: device number, VPN IP address, networking number, authorization number, and P2P server IP address.
[0030] Optionally, where:
[0031] The P2P-TUN module initialization specifically includes: creating a network VPN interface, identifying whether the authorization number is a valid authorization number according to the configuration information, terminating the networking when the authorization number is invalid, and starting the networking terminal device to send online information data packets when the authorization number is valid.
[0032] In a second aspect, based on the same inventive concept, the present disclosure also provides a network system based on P2P technology, comprising a plurality of sub-networks, wherein the sub-networks are formed by networking using the networking method based on P2P technology as described in any one of the first aspects, and the networking numbers of any two sub-networks are different.
[0033] Compared with the prior art, the technical solution provided by the embodiments of the present disclosure has the following advantages:
[0034] The present invention provides a networking method and a network system based on P2P technology, wherein the networking method comprises setting configuration information of a first networking terminal device and a second networking terminal device and powering on the devices, wherein the first networking terminal device and the second networking terminal device both comprise a P2P-TUN module; after the devices are powered on, the P2P-TUN module is initialized; the first networking terminal device sends a first online information data packet to a P2P server, and the second networking terminal device sends a second online information data packet to the P2P server; the P2P server receives the first online information data packet and the second online information data packet, and sends the first online information data packet to the second networking terminal device having the same networking number as the first networking terminal device, and sends the second online information data packet to the first networking terminal device having the same networking number as the second networking terminal device; the P2P-TUN module performs hole punching, and the first networking terminal device and the second networking terminal device establish a P2P tunnel; the first networking terminal device performs network settings on the first networking terminal device according to the second online information data packet, and the second networking terminal device performs network settings on the second networking terminal device according to the first online information data packet. The networking method based on P2P technology provided by the present disclosure forms a P2P tunnel by drilling holes between networking terminal devices, which is conducive to connecting different local area networks to form a larger network. Different local area networks can also be directly accessed, and data transmission does not need to pass through the cloud server, which is conducive to saving the economic expenses of the transit server and reducing the time delay of data transmission, thereby improving the efficiency of data transmission. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0036] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0037] Figure 1 The figure is a flow chart of a networking method based on P2P technology provided by an embodiment of the present disclosure;
[0038] Figure 2 Shown Figure 1 A detailed flow chart of step S05 in FIG. DETAILED DESCRIPTION
[0039] In order to more clearly understand the above-mentioned objectives, features and advantages of the present disclosure, the scheme of the present disclosure will be further described below. It should be noted that the embodiments of the present disclosure and the features in the embodiments can be combined with each other without conflict.
[0040] In the following description, many specific details are set forth to facilitate a full understanding of the present disclosure, but the present disclosure may also be implemented in other ways different from those described herein; it is obvious that the embodiments in the specification are only part of the embodiments of the present disclosure, rather than all of the embodiments.
[0041] The inventor found in the research that in some engineering projects, the amount of video transmission data is large. The traditional way of transferring video streams through cloud servers not only brings high economic expenses, but also the network delay is affected by the bandwidth of the cloud server, resulting in low data transmission efficiency. P2P (Peer-to-Peer) technology is a point-to-point direct tunnel technology, which does not transfer data through cloud servers in the middle. However, P2P technology can only realize point-to-point data transmission, and cannot realize the functions of the network layer.
[0042] Therefore, how to use P2P technology to connect different local area networks to achieve direct access between different networks has become one of the technical problems that need to be solved urgently at this stage.
[0043] Figure 1 FIG. 1 is a flow chart of a networking method based on P2P technology provided by an embodiment of the present disclosure. Please refer to Figure 1 The present disclosure provides a networking method based on P2P technology, including:
[0044] Step S01: setting configuration information of a first networking terminal device and a second networking terminal device, and powering on the first networking terminal device and the second networking terminal device, wherein both the first networking terminal device and the second networking terminal device include a P2P-TUN module, and the first networking terminal device and the second networking terminal device have the same networking number;
[0045] Step S02, P2P-TUN module initialization;
[0046] Step S03: The P2P-TUN module in the first networking terminal device sends a first online information data packet to the P2P server, and the P2P-TUN module in the second networking terminal device sends a second online information data packet to the P2P server;
[0047] Step S04: The P2P server receives the first online information data packet and the second online information data packet, sends the first online information data packet to the second networking terminal device having the same networking number as the first networking terminal device, and sends the second online information data packet to the first networking terminal device having the same networking number as the second networking terminal device;
[0048] Step S05: The P2P-TUN module performs hole punching, the first networking terminal device and the second networking terminal device establish a P2P tunnel, the first networking terminal device receives the second online information data packet of the second networking terminal device, and the second networking terminal device receives the first online information data packet of the first networking terminal device;
[0049] Step S06: The first networking terminal device performs network settings on the first networking terminal device according to the second online information data packet, and the second networking terminal device performs network settings on the second networking terminal device according to the first online information data packet.
[0050] Specifically, the present disclosure provides a networking method based on P2P technology, including but not limited to steps S01 to S06. It should be noted that the networking method based on P2P technology provided by the present disclosure uses a networking terminal device for networking, and there are a number of networking terminal devices. Network connections are established between the networking terminal devices, so that direct access between different networks can be achieved. When a connection is established between two networking terminal devices, the networking terminal device that initiates the connection is the local device, and the target networking terminal device that wants to establish a network connection is the opposite device. The networking terminal device can be either the local device or the opposite device. For the sake of clarity, the present disclosure distinguishes between networking terminal devices. The first networking terminal device and the second networking terminal device are opposite devices to each other. When the first networking terminal device is the local device, the second networking terminal device is the opposite device. When the second networking terminal device is the local device, the first networking terminal device is the opposite device. Moreover, one local device can correspond to multiple opposite devices, that is, one first networking terminal device can establish connections with multiple second networking terminal devices, and one second networking terminal device can also establish connections with multiple first networking terminal devices.
[0051] In step S01, firstly, the configuration information of the first networking terminal device and the second networking terminal device is set, and the configuration information is equivalent to identifying the networking terminal device. The present disclosure provides an optional implementation mode, that is, the configuration information is set by modifying the configuration file. The configuration information is set for the first networking terminal device and the second networking terminal device respectively, and powered on. The present disclosure provides an optional implementation mode, that the networking terminal device includes a DC power converter and an ARM chip. After the device is powered on, the networking terminal device converts AC (Alternating Current) 220V into DC (Direct Current) 18V medium voltage power supply, and then the DC power converter converts DC18V into DC3.3V and DC5.0V low ripple to supply the ARM chip to work, and the ARM chip self-checks the hardware and starts the embedded Linux system. After success, the P2P-TUN module is loaded. It should be noted that the present disclosure is only described by taking the P2P-TUN module being set in the ARM chip as an example, and is not limited to this. The first networking terminal device and the second networking terminal device are to be networked, and therefore have the same networking number.
[0052] In step S02, the P2P-TUN module is initialized and a network VPN (Virtual Private Network) interface is created.
[0053] In step S03, the P2P-TUN module in the first networking terminal device sends a first online information data packet to the P2P server to notify the P2P server device to go online; the P2P-TUN module in the second networking terminal device also sends a second online information data packet to the P2P server to notify the P2P server device to go online, that is, when the networking terminal device is turned on for networking, an online information data packet is sent to the P2P server to notify the P2P server device to go online. It should be noted that the first networking terminal device and the second networking terminal device do not have to go online at the same time, that is, the first online information data packet and the second online information data packet are not sent at the same time. The present disclosure provides an optional implementation method in which the networking terminal device sends an online information data packet every 2 seconds, which is conducive to keeping the device online, but the present disclosure is only described as an example and is not limited to this.
[0054] It should be noted that although the present invention uses a P2P server to transfer online information data packets during the networking process, the bandwidth occupied by the data packets is far smaller than the bandwidth occupied by data transmitted between networks (such as audio and video). After the networking is successful, the transmitted data does not pass through the data transfer of the cloud server, which is beneficial to saving the economic expenses of the transfer server.
[0055] In step S04, the P2P server receives a first online information data packet sent by the first networking terminal device, and sends the first online information data packet to the second networking terminal device with the same networking number, so that the second networking terminal device with the same networking number knows that the first networking terminal device is online; at the same time, the P2P server receives a second online information data packet sent by the second networking terminal device, and sends the second online information data packet to the first networking terminal device with the same networking number, so that the first terminal device with the same networking number knows that the second networking terminal device is online.
[0056] In step S05, the P2P-TUN module performs hole punching, so that the first networking terminal device and the second networking terminal device establish a P2P tunnel. After the tunnel is successfully established, the first networking terminal device will receive the second online information data packet sent by the second networking terminal device (the TTL (Time To Live) value of the second online information data packet is a normal TTL value), and the second networking terminal device will receive the first online information data packet sent by the first networking terminal device (the TTL value of the first online information data packet is a normal TTL value). At this time, it means that the hole between the first networking terminal device and the second networking terminal device is successfully punched, and the local area network corresponding to the first networking terminal device and the local area network corresponding to the second networking terminal device are successfully connected, and they can communicate with each other.
[0057] Figure 2 Shown Figure 1 For a detailed flowchart of step S05, please refer to Figure 1 and Figure 2 The present disclosure provides an optional implementation mode in which the P2P-TUN module performs hole punching including:
[0058] Step S051, setting the TTL value of the first online information data packet and the TTL value of the second online information data packet to be less than the propagation threshold, so that the second networking terminal device cannot receive the first online information data packet, and the first networking terminal device cannot receive the second online information data packet;
[0059] Step S052: The first network NAT router corresponding to the first networking terminal device generates a forward session record for the second networking terminal device, and the second network NAT router corresponding to the second networking terminal device generates a forward session record for the first networking terminal device.
[0060] Specifically, the TTL (Time To Live) value of the first online information data packet and the TTL value of the second online information data packet are both set to be less than the propagation threshold, so that the second networking terminal device cannot receive the first online information data packet, and the first networking terminal device cannot receive the second online information data packet. It should be noted that the IP layer header of the online information data packet includes a TTL value, which is usually a field or parameter used to specify the time a data packet can exist in the network or the maximum number of hops it passes through. The main function of the TTL value is to prevent the data packet from infinitely circulating or existing for a long time in the network, thereby avoiding network congestion and waste of resources. When a data packet is transmitted in the network, the TTL value will be reduced by 1 for each router or network node it passes through. If the TTL value is reduced to 0 and the data packet has not reached the target address, the data packet will be discarded. Usually the TTL value is 64, that is, if a data packet has not reached the target address after passing through 64 routers or network nodes, it will be discarded. In this embodiment, the TTL value of the first online information data packet and the TTL value of the second online information data packet are set to be less than the propagation threshold. The setting of the propagation threshold needs to make the first online information data packet unable to reach the second networking terminal device, and the second online information data packet unable to reach the first networking communication device. The present disclosure takes the propagation threshold equal to 5 as an example for explanation, but is not limited to this. For example, the propagation threshold is equal to 5, then the TTL value of the first online information data packet and the TTL of the second online information data packet are 4 at most. Usually, it takes far more than 4 hops for a data packet to reach the target address. Therefore, the first online information data packet cannot reach the second networking terminal device, and the second online information data packet cannot reach the first networking communication device.
[0061] Although the first online information data packet cannot reach the second networking terminal device, and the second online information data packet cannot reach the first networking communication device, the first network NAT router corresponding to the first networking terminal device generates a forward session record for the second networking terminal device, and the second network NAT router corresponding to the second networking terminal device generates a forward session record for the first networking terminal device. Such a setting is conducive to preventing the second networking terminal device from treating the first online information data packet sent by the first networking terminal device as an uninvited hacker attack data packet, and using a black hole record to prevent subsequent reception of data packets sent by the first networking terminal device. Similarly, it is also conducive to preventing the first networking terminal device from treating the second online information data packet sent by the second networking terminal device as an uninvited hacker data packet, and using a black hole record to prevent subsequent reception of data packets sent by the second networking terminal device, that is, it is conducive to preventing the first networking terminal device and the second networking terminal device from adding each other to the blacklist and prohibiting communication.
[0062] It should be noted that this embodiment first sends an online information data packet with a TTL value less than the propagation threshold to the peer network, so that the online information data packet cannot reach the peer network, but can generate a positive Session record to prevent the peer network from treating the online information data packet as an uninvited data packet.
[0063] Optionally, the P2P-TUN module performs periodic hole punching, where the hole punching period is T and the number of hole punchings is N; T ≥ 2s, N ≥ 3 times.
[0064] Specifically, the present disclosure provides an optional implementation scheme in which the P2P-TUN module performs periodic hole punching, that is, sends an online information data packet with a TTL value less than the propagation threshold once at an interval of 2s, and sends it 3 times in total. This is conducive to the successful hole punching of the P2P-TUN module. After the hole punching is successful, the first networking terminal device will receive the second online information data packet directly sent by the second networking terminal device (the TTL value of the second online information data packet is a normal TTL value), and the second networking terminal device will receive the first online information data packet directly sent by the first networking terminal device (the TTL value of the first online information data packet is a normal TTL value). This indicates that the hole punching is successful, and the P2P tunnel has been completed and can communicate with each other. In order to prevent the P2P tunnel from being released by the NAT router, the P2P-TUN module will also send a freshness-keeping data packet to the networking terminal device with the same networking number at an interval of every 2 seconds for freshness-keeping. It should be noted that when punching a hole, the P2P-TUN module of the first networking terminal device sends the first online information data packet to the P2P server with a period of 1 second. In order to increase the probability that the second networking terminal device receives the first online information data packet, a certain waiting time is set, and the P2P-TUN module is set to send the first online information data packet with a TTL value less than the propagation threshold to the second networking terminal device with a period of 2 seconds, and it is set to send three times. This is conducive to improving the success rate of punching a hole. This embodiment sets the P2P-TUN module to punch a hole with a period of 2 seconds, and the number of punchings is 3. This is only used as an example for explanation, and is not limited to this. It can be set according to specific circumstances. It should also be noted that when the hole punching fails, the P2P-TUN module can continue to punch a hole until the hole punching is successful.
[0065] In step S06, the first networking terminal device performs network settings for the first networking terminal device according to the second online information data packet, and the second networking terminal device performs network settings for the second networking terminal device according to the first online information data packet. The present disclosure provides an optional implementation method of adding the network segment of the second networking terminal device to the static routing table of the first networking terminal device, so that the VPN interfaces of the first networking terminal device and the second networking terminal device can access each other. At this time, the first networking terminal device and the second networking terminal device have completed networking and can be connected to each other.
[0066] It can be understood that the networking method based on P2P technology provided by the present disclosure, by forming a P2P tunnel by drilling holes between networking terminal devices, is conducive to connecting different local area networks to form a larger network. Different local area networks can also be directly accessed, and data transmission does not need to pass through the cloud server, which is conducive to saving the economic expenses of the transit server. At the same time, it is conducive to reducing the time delay of data transmission, thereby helping to improve data transmission efficiency.
[0067] Please continue to refer to Figure 1 The present disclosure provides an optional implementation scheme in which the first online information data packet and the second online information data packet both include: the public network NAT IP address of the device for accessing the Internet, the source port number after NAT, the device number, the device IP address, the routing network segment and the networking number.
[0068] It should be noted that, in the present embodiment, after the first networking terminal device comes online, it sends a first online information data packet to the P2P server, and after the second networking terminal device comes online, it sends a second online information data packet to the P2P server. Both the first online information data packet and the second online information data packet include the public network NAT IP address of the device, the source port number after NAT, the device number, the device IP address, the routing network segment and the networking number. This is beneficial for networking terminal devices with the same networking number to obtain relevant information of other networking devices, thereby helping to improve the success rate of networking.
[0069] Please continue to refer to Figure 1 The present disclosure provides an optional implementation mode, in which the networking method based on P2P technology further includes: establishing a virtual network card in the Linux system in the first networking terminal device.
[0070] Specifically, the networking terminal device includes an ARM chip, and a RAM chip is embedded in the Linux system. For example, the / dev / net / tun interface method in the related technology can be referred to. The / dev / net / tun interface method is provided in the Linux system. The parameters of the virtual interface are passed to / dev / net / tun through this interface method. In this way, a kernel-level virtual network card is established. The operating system can configure the IP address of the virtual network card like configuring a local network, which is facilitating the subsequent data interaction with the virtual network card through a P2P tunnel.
[0071] Please continue to refer to Figure 1 The present disclosure provides an optional implementation, which further includes transmitting the data of the virtual network card through a P2P tunnel.
[0072] Specifically, in this embodiment, the networking method based on P2P technology also includes transmitting the data of the virtual network card through the P2P tunnel, which specifically includes the following two aspects: First: the P2P tunnel receives the broadcast of the virtual network card: receiving the original data packet from the virtual network card, the data packet starts with the Ethernet layer, and includes: MAC address, destination MAC address, destination IP, source IP, protocol number, and the upper layer data packet header and data body. According to whether the destination MAC address is {0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, multicast {0x01, 0x00, 0x5E} or {0x33, 0x33}, it is judged whether it is necessary to send it to all the same network numbers through the P2P tunnel. If the destination MAC address is {0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, multicast {0x01, 0x00, 0x5E} or {0x33, 0x33}, it is sent to all the same network numbers through the P2P tunnel. The above three types of data packet characteristics belong to the broadcast or multicast of the local area network, and are sent to all nodes with the same networking number. The purpose is to let the nodes with the same networking number know the existence of the local network, let the opposite network learn the ARP (Address Resolution Protocol) information of the local network, and let the opposite network find the MAC address of the local host. The data packets sent out also start with the Ethernet layer and are consistent with the data packets of the virtual network card.
[0073] Second: receiving unicast data from the virtual network card: the ability to receive unicast data from the virtual network card indicates that the Linux kernel has learned the network connection status through the broadcast mechanism. At this time, the unicast of the virtual network card needs to send data one-to-one. The role of the tunnel protocol module here is to complete the one-to-one relay transmission through the P2P tunnel. According to the destination MAC address in the data packet and the MAC / P2P comparison table of the tunnel protocol module, the corresponding P2P tunnel information is found, and the data is transmitted through the corresponding P2P tunnel. The unicast transmission is completed.
[0074] Please continue to refer to Figure 1 The present disclosure provides an optional implementation method, which also includes receiving data through a P2P tunnel and writing it into a virtual network card.
[0075] Specifically, in this embodiment, the networking method based on P2P technology also includes receiving data through the P2P tunnel and writing it into the virtual network card, which specifically includes the following two aspects: First: receiving the broadcast packet of the P2P tunnel: it is the reverse process of the broadcast process of the P2P tunnel receiving the virtual network card, receiving the broadcast packet from the P2P tunnel, and writing it into the virtual network card, so that the local network knows the existence of the opposite network, and the Linux kernel learns the ARP information and MAC address of the opposite network for subsequent unicast transmission. At this time, the source MAC and P2P tunnel information should be recorded, which is called the MAC / P2P comparison table, which is used to accurately find the required P2P tunnel when sending unicast data later.
[0076] Second: receiving unicast data from the P2P tunnel. Receiving unicast data from the P2P tunnel is the reverse process of receiving unicast data from the virtual network card. Just write the unicast data into the virtual network card. When the data of the virtual network card can be transmitted through the P2P tunnel, or when data is received through the P2P tunnel and written into the virtual network card, the process of transmitting network data through the P2P tunnel has been completed, forming the networking mode of the virtual network card. The Linux system kernel can complete all communication functions through the virtual network card, including the fourth layer data link layer, and complete higher-level transmission according to information such as TCP, UDP, and destination port.
[0077] It should be noted that the networking method based on P2P technology provided by the present disclosure realizes the function of the network layer. In the OSI (Open Systems Interconnection Reference Model) model defined by the International Organization for Standardization, the work of network communication is divided into seven layers, from bottom to top: physical layer: responsible for transmitting the original bit stream on the physical medium, defining the physical characteristics of cables, connectors, signal types, etc.; data link layer: combining bits into frames, performing error detection and correction, and managing node-to-node communication; network layer: responsible for routing and forwarding of data packets, determining the transmission path of data in the network; transport layer: providing end-to-end reliable or unreliable data transmission services, such as TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) are in this layer; session layer: establishing, managing and terminating sessions between applications; presentation layer: processing the representation of data, including data encryption, compression and format conversion; application layer: providing network services for applications, such as HTTP (HyperText Transfer Protocol), FTP (File Transfer Protocol), SMTP (Simple Mail Transfer Protocol) The present disclosure is based on P2P technology to form a network, connect different local area networks, facilitate direct access between different networks, realize the function of the third network layer in the OSI model, improve the convenience of network use, and improve data transmission efficiency while saving cloud server expenses.
[0078] Please continue to refer to Figure 1 The present disclosure provides an optional implementation mode in which the configuration information includes: device number, VPN IP address, networking number, authorization number and P2P server IP address.
[0079] Specifically, in this embodiment, a method for setting the content of configuration information is provided, including a device number, a VPN IP address, a networking number, an authorization number, and a P2P server IP address. The specific networking terminal device can be found through the device number; the networking terminal devices used for networking are determined through the networking number, and only networking terminal devices with the same networking number can be used for networking; the authorization number is used to determine whether the networking terminal device has networking authority. When the authorization number is invalid, it means that the networking terminal device does not have networking authority; when the authorization number is a valid authorization number, it means that the networking terminal device has networking authority; and networking is started by sending an online information data packet through the VPN IP address and the P2P server address. The setting of configuration information is conducive to improving the convenience and security performance of networking. This disclosure only takes the above-mentioned configuration information as an example for explanation, and is not limited to this. It can be set according to actual conditions.
[0080] Please continue to refer to Figure 1 The present disclosure provides an optional implementation method, in which the P2P-TUN module initialization specifically includes: creating a network VPN interface, identifying whether the authorization number is a valid authorization number based on the configuration information, terminating the networking when the authorization number is invalid, and starting the networking terminal device to send online information data packets when the authorization number is valid.
[0081] Specifically, in this embodiment, the P2P-TUN module initialization is specifically as follows: creating a network VPN interface, identifying whether the authorization number is a valid authorization number according to the configuration information set in step S01, judging whether the networking terminal device has the networking authority through the authorization number, and when the authorization number is invalid, it means that the networking terminal device does not have the networking authority, and the networking is terminated; when the authorization number is a valid authorization number, it means that the networking terminal device has the networking authority, and the networking starts, and the online information data packet is sent. In this way, judging whether the networking terminal device has the networking authority through the authorization number is conducive to preventing the networking terminal device that does not have the networking authority from being connected, thereby helping to improve the security performance of the network.
[0082] Based on the same inventive concept, the present disclosure also provides a network system based on P2P technology, including multiple sub-networks, which are formed by networking using any of the P2P technology-based networking methods provided in the embodiments of the present disclosure, and the networking numbers of any two sub-networks are different.
[0083] It should be noted that the network system based on P2P technology provided by the present disclosure includes multiple sub-networks, each of which is formed by the networking method based on P2P technology provided by the present disclosure, and network terminal devices with the same networking number are networked, and network terminal devices with different networking numbers are isolated from each other, that is, only the same networking number can communicate with each other, which can realize that a network system includes multiple independent sub-networks. In actual use, networking can be carried out according to actual needs, and the same networking number can be set between devices that need to communicate. This is conducive to improving the security and practicality of the network.
[0084] It can be seen from the above embodiments that the networking method and network system based on P2P technology provided by the present invention at least achieve the following beneficial effects:
[0085] The present invention provides a networking method and a network system based on P2P technology, wherein the networking method comprises setting configuration information of a first networking terminal device and a second networking terminal device and powering on the devices, wherein the first networking terminal device and the second networking terminal device both comprise a P2P-TUN module; after the devices are powered on, the P2P-TUN module is initialized; the first networking terminal device sends a first online information data packet to a P2P server, and the second networking terminal device sends a second online information data packet to the P2P server; the P2P server receives the first online information data packet and the second online information data packet, and sends the first online information data packet to the second networking terminal device having the same networking number as the first networking terminal device, and sends the second online information data packet to the first networking terminal device having the same networking number as the second networking terminal device; the P2P-TUN module performs hole punching, and the first networking terminal device and the second networking terminal device establish a P2P tunnel; the first networking terminal device performs network settings on the first networking terminal device according to the second online information data packet, and the second networking terminal device performs network settings on the second networking terminal device according to the first online information data packet. The networking method based on P2P technology provided by the present disclosure forms a P2P tunnel by drilling holes between networking terminal devices, which is conducive to connecting different local area networks to form a larger network. Different local area networks can also be directly accessed, and data transmission does not need to pass through the cloud server, which is conducive to saving the economic expenses of the transit server and reducing the time delay of data transmission, thereby improving the efficiency of data transmission.
[0086] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0087] The above description is only a specific embodiment of the present disclosure, so that those skilled in the art can understand or implement the present disclosure. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure will not be limited to the embodiments described herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A networking method based on P2P technology, characterized in that: include: Setting configuration information of a first networking terminal device and a second networking terminal device, and powering on the first networking terminal device and the second networking terminal device, wherein the first networking terminal device and the second networking terminal device both include a P2P-TUN module, and the first networking terminal device and the second networking terminal device have the same networking number; The P2P-TUN module is initialized; The P2P-TUN module in the first networking terminal device sends a first online information data packet to the P2P server, and the P2P-TUN module in the second networking terminal device sends a second online information data packet to the P2P server; The P2P server receives the first online information data packet and the second online information data packet, sends the first online information data packet to the second networking terminal device having the same networking number as the first networking terminal device, and sends the second online information data packet to the first networking terminal device having the same networking number as the second networking terminal device; The P2P-TUN module performs hole punching, the first networking terminal device and the second networking terminal device establish a P2P tunnel, the first networking terminal device receives the second online information data packet of the second networking terminal device, and the second networking terminal device receives the first online information data packet of the first networking terminal device; The first networking terminal device performs network settings on the first networking terminal device according to the second online information data packet, and the second networking terminal device performs network settings on the second networking terminal device according to the first online information data packet.
2. The networking method based on P2P technology according to claim 1, characterized in that: The first online information data packet and the second online information data packet both include: the public network NAT IP address of the device, the source port number after NAT, the device number, the device IP address, the routing network segment and the networking number.
3. The networking method based on P2P technology according to claim 1, characterized in that: The P2P-TUN module performs hole punching including: Setting the TTL value of the first online information data packet and the TTL value of the second online information data packet to be less than the propagation threshold, so that the second networking terminal device cannot receive the first online information data packet, and the first networking terminal device cannot receive the second online information data packet; The first network NAT router corresponding to the first networking terminal device generates a forward Session record for the second networking terminal device, and the second network NAT router corresponding to the second networking terminal device generates a forward Session record for the first networking terminal device.
4. The networking method based on P2P technology according to claim 3, characterized in that: The P2P-TUN module performs periodic hole punching, the hole punching period is T, and the number of hole punching is N; T≥2s, N≥3 times.
5. The networking method based on P2P technology according to claim 1, characterized in that: Also includes: In the Linux system in the first networking terminal device, a virtual network card is established.
6. The networking method based on P2P technology according to claim 5, characterized in that: The method also includes transmitting the data of the virtual network card through the P2P tunnel.
7. The networking method based on P2P technology according to claim 5, characterized in that: The method also includes receiving data through the P2P tunnel and writing the data into the virtual network card.
8. The networking method based on P2P technology according to claim 1, characterized in that: The configuration information includes: device number, VPN IP address, networking number, authorization number and P2P server IP address.
9. The networking method based on P2P technology according to claim 8, characterized in that: The P2P-TUN module initialization specifically includes: creating a network VPN interface, identifying whether the authorization number is a valid authorization number according to the configuration information, terminating the networking when the authorization number is invalid, and starting the networking terminal device to send online information data packets when the authorization number is valid.
10. A network system based on P2P technology, characterized in that: It comprises a plurality of sub-networks, wherein the sub-networks are formed by using the networking method based on P2P technology as claimed in any one of claims 1 to 9, and the networking numbers of any two of the sub-networks are different.
