Distributed application ----- peer-to-peer (p2p) network

Table of contents

1 Overview

1.1. The concept of P2P

1.2. Background of P2P

1.3. Advantages and disadvantages of P2P

2. P2P classification

2.1. According to the degree of centralization

2.2. According to the network topology

3. Detailed explanation of NAT technology

3.1. Overview

3.2. Advantages and disadvantages of NAT

3.3. Common solutions for NAT traversal

3.4. Basic principle of probe drilling

3.4.1. Fundamentals

3.4.2. Within the same NAT gateway

3.4.3. Unreachable in the NAT gateway

3.4.4. Multi-layer unreachable NAT gateway

3.4.5. Preschool

3.4.6. TCP hole punching

3.5. Commonly used hole punching protocol framework

4. P2P download technology principle

4.1. Overview

4.2. Two P2P download technical solutions

4.2.1. BitTorrent Technical Solution

4.2.2. Kademlia technical solution

4.3. P2P download implementation case based on BT technology

4.3.1. Problems encountered by P2P technology

4.3.2. Solutions


1 Overview

1.1. The concept of P2P

P2P, English full name: Peer To Peer, point-to-point technology, is a network model different from C/S, there is no unified central server node, and each Client is also a server that provides services. It was first recorded in RFC1 in April 1969.

1.2. Background of P2P

The concept of P2P first emerged on the Internet, starting with IPv4.

What is the Internet? It is the interconnection of various hardware devices, such as computers, mobile phones, and various networked devices, for information and service sharing. The Internet adopts the TCP/IP architecture model, which is essentially a C/S model. The communication parties (Client and Server) are marked by the five-tuple information (source IP+source port+destination IP+destination port+protocol type), and send data packets to the other party according to the standard protocol, and the other party parses the data packet according to the standard protocol to realize the information Resource Sharing. If we follow the original ideal interconnection model and don’t consider anything else, we don’t need P2P at all, because originally any object can provide services as a server or client, and they can be interconnected with each other. IP is used to mark the device, and the IPv4 version is widely used at present, while the port is used to mark the software service running on the device. IP and ports are limited. The original designer did not expect such a rapid development. The entire IPv4 address range is not enough for Internet devices to allocate. In order to solve the problem of insufficient addresses, NAT was introduced. Also since NAT, the boundary between Client and Server has become very obvious, leading to the emergence of P2P (of course, the emergence of IPv6 later expanded this address capacity to a very large number, but it is not infinite after all, and NAT with other perks).

NAT (Net Address Translate, Network Address Translation) is a technology of IP multiplexing, which expands limited IP to unlimited and brings IPv4 back to life. I won’t say anything about ABCDE IP classification here. To briefly summarize the principle of NAT, the network on the Internet is first divided: a network composed of any address that can be accessed on the Internet is called a public network, and a network composed of addresses that are not accessible on the Internet is called a private network. , On the private network side, the client is generally placed, and on the public network side, the server is generally placed (simplify first without considering concepts such as reverse proxy reverse links). As a bridge between the public network and the private network, the role of NAT is to open up the communication between the public network and the private network. Specifically, for the NAT device itself, as part of the public network, other people can access it. The NAT device directly forms a hardware interconnection with the private network. Generally speaking, the request is initiated by the client, and the client can reach the server (because the server is on the public network, the address can be accessed), the server cannot directly reach the client, because the client is on a private network. In this way, when the client initiates a request and the request goes out through the NAT device, we know that the request is located through the five-tuple information, and the NAT device is responsible for changing the IP of the request source (that is, the client) to the public IP of the NAT device. , the purpose is to allow the server to reply data to a valid address after receiving the request, and at the same time record the conversion of the requested client IP to public IP into a mapping table. When the server receives the data packet, it will reply the data packet to the public IP of the NAT. When the data arrives at the NAT, it will go through the previously recorded mapping table again to find out which client requested the data packet, and then transfer the data packet to the corresponding client. In this case, the IP of the private network is meaningless to the public network and can be customized arbitrarily. Usually, each organization will form such a private network, and these private network IPs of each organization are repeatable, so NAT essentially reuses the NAT public IP to each client of the private network.

The isolation of public and private networks through NAT technology can realize IP multiplexing, which solves the problem of insufficient IPv4, but at the same time brings new problems, which directly leads to difficulties in TCP/IP communication (due to NAT, IP becomes a virtual IP, and the external network cannot Direct communication for a host on the intranet, because there is no real address available). Since all services have to adopt the C/S architecture, the bandwidth cost is quite high for the enterprise that provides the server. In order to save the bandwidth cost, the internal and external communication of the NAT device is opened up, and the client is used as the resource service provider to reduce the direct access to the server. , thus resulting in P2P technology.

1.3. Advantages and disadvantages of P2P

Advantages of P2P:

  • Better parallel processing capability (compared to the C/S architecture, with more and more C, the speed is getting slower and slower, but the p2p network will not change significantly, all clients can provide resources, including bandwidth , storage space, computing power)
  • No central server, relying on user groups (peers) to exchange information, reducing network transmission nodes
  • No need to invest a lot of money in the software and hardware of the server

Disadvantages of P2P:

  • The architecture is relatively complex, and there is usually NAT isolation between nodes, so they cannot communicate directly, resulting in the need for additional path construction and resource coordination management of each node
  • P2P nodes spread all over the Internet, bringing monitoring problems to developers, organizations, and governments
  • When used in large-scale networks, resource sharing is disordered and management is difficult
  • less secure
    • Poisoning attack: serving files with different content than described
    • Denial of service attack: make the network run very slowly or even completely crash
    • Treachery attack (bleeding): A user or software uses the network without contributing its own resources
    • Viruses inserted into data: Downloaded or transmitted files may be infected with viruses and Trojan horses
    • Trojan horse of P2P software itself: the software may contain spyware
    • Filtering: network operators may try to prevent data from passing on P2P networks
    • Identity attack: track users on the network and carry out continuous harassment or legality attacks
    • Spam: Sending unsolicited messages on the Internet

Of course, there are corresponding solutions for some problems of P2P security.

2. P2P classification

2.1. According to the degree of centralization

General P2P

  • Node acts as client and server at the same time
  • no central server
  • no central router
  • Typical representative: Gnutella, a file sharing network, flood query search all nodes

Special type P2P

  • A central server saves node information
  • Nodes are responsible for publishing this information to let the central server know what files they want to share
  • Routing endpoints use addresses, referenced by a set of indices to obtain absolute addresses
  • Typical: Napster, a music-sharing network that relies on a central server to coordinate queries across the network

Hybrid P2P

  • Contains both general and special features
  • Typical representative: Skype

2.2. According to the network topology

Structure P2P

  • There are link consultations between point-to-point, forming a specific rule topology with each other
  • When a resource needs to be requested, it is searched according to the topology rules, and if it exists, it must be found
  • Typical representatives: Chord, YaCy (distributed open source free web search engine system, protecting user privacy, no central server search, ensuring that the content will not be censored), Kademlia (a protocol algorithm, specifying the structure of the network, and specifying through node query The way of information exchange, quickly locate the desired node)

Unstructured P2P

  • There are link consultations between point-to-point, forming an irregular topological structure with each other
  • When it is necessary to request resources, it is searched by broadcasting, usually with a TTL, even if it exists, it may not be found
  • Typical representative: Gnutella

loose structure P2P

  • There are link consultations between point-to-point, forming an irregular topological structure with each other
  • When it is necessary to request resources, search according to the existing consulting speculation, between the P2P structure and the unstructured type
  • Typical representative: Freenet (a software, anonymous Internet field)

3. Detailed explanation of NAT technology

One of the most critical technologies in P2P is the ability to penetrate NAT devices. Therefore, it is necessary to have a comprehensive understanding of NAT technology.

3.1. Overview

The essence of NAT was born to solve the shortage of IPv4 addresses, and the addresses can be expanded almost infinitely through IP multiplexing.

There are two common types of NAT:

  • Basic Network Address Translation (Basic NAT)
    • Also known as "static NAT", it only supports address translation and does not support port translation (generally there are multiple public IP pools available)
    • Broadband routers use this method (broadband routers are sometimes marked as DMZ hosts)

  • Network Address Port Translation (NAPT)
    • Allow multiple hosts to share a public IP
    • Usually consists of two simultaneous jobs:
      • Source address translation type (data packets sent by the internal network host can reach the external network host)
      • Destination address translation type (data packets sent by external network hosts can reach internal network hosts)

3.2. Advantages and disadvantages of NAT

Advantages of NAT:

  • Load balancing: by redirecting connections from some servers to other selected servers (switching IPs)
  • Failure termination: provide high-reliability services, once the router detects that the server is down, it will automatically transfer to the backup server
  • Transparent Proxy: Redirect HTTP connections to the Internet to an HTTP proxy server to cache data and filter requests, reducing bandwidth usage without configuring a browser proxy

Disadvantages of NAT:

  • Shorten the hold time of IP sessions
    • Session establishment will create an association table on the NAT gateway, consuming IP port numbers, and these resources are limited, and a resource recovery mechanism is required
    • Reclaim resources in real time (tcp connection, etc., according to the analysis package, it can be judged that resources are reclaimed when the session ends)
    • Timer recovery (udp and other unconnected states can only determine the packet survival period based on timing), examples of valid periods for different protocols:
      • DNS protocol: 10s
      • FTP-ctrl:300s
      • ICMP protocol: 10s
      • TCP protocol (usually 300s, fin, rst is 10s, syn is 10s)
      • UDP protocol: 240s
  • The internal host reuses IP, making the mechanism of relying on IP for host tracking invalid
    • Applications based on network traffic analysis cannot track the specific behavioral relationship between end users and traffic
    • IP-based user behavior log analysis becomes difficult, and it is difficult to locate malicious attack hosts
    • IP-based user authorization is no longer reliable
    • The connection limit of the server makes the service preemption queue between users (it was originally to prevent DOS attacks and prevent a large number of connection requests from one user, but here it caused manslaughter)
  • Disruption of the IP end-to-end model
    • NAT cannot guarantee the association of multiple sessions. When the NAT gateway has multiple public IP addresses, a group of associated sessions will be assigned to different public network addresses (that requires different domain names, which is very troublesome).
    • When the public network side needs to actively send data to the private network side, because the NAT gateway has not established a connection, usually the data packets cannot reach
  • Modifying the IP header information will hinder the work of some security protocols
    • The authentication protocol does not work properly (caused by NAT tampering with the IP address, transport layer port, and checksum, because the purpose of authentication is to ensure that these information remain unchanged during transmission)
    • There is a problem with the tunnel protocol (the tunnel protocol usually uses the outer address to identify the tunnel entity, and there will be an IP multiplexing relationship when crossing the NAT tunnel, and the other end needs to be handled carefully, such as adding a special tag to identify its own identity)
    • ICMP protocol demultiplexing failed (Because the IP correspondence is remapped, ICMP needs to multiplex and demultiplex. When the ICMP message load cannot provide enough information, demultiplexing will fail)
    • IP fragmentation (usually the transport layer information of IP fragmentation (including IP and port number, especially the port number) is only included in the first fragment. NAT usually relies on port number for mapping. Without transport layer information, NAT is difficult to identify The corresponding relationship between the subsequent fragments and the association table, which requires adding additional port number information for each fragment separately)

3.3. Common solutions for NAT traversal

  • Application Layer Gateway (ALG): Identify the protocol according to the transport layer port number, then query the IP address and port corresponding to the protocol, convert it to the IP and port in the NAT conversion table, and record the before conversion to form a query association table. In this way, all the IPs and ports sent to the private network side are the IPs and ports of the converted NAT gateway, and then the private network side sends data packets to the public network side, and it will query the table before conversion recorded last time, Find the corresponding one and restore it back
    • Upgrades to all application protocols must be tracked, as well as new protocols
    • Some protocols are encrypted and cannot be parsed, so they cannot be converted
  • Probe technology STUN: Need to add code support for each service, deploy STUN service at the same time, use the timeliness of the NAT temporary mapping table for hole-punching
  • Middleware technology (UPnP): The client participates in the maintenance of the gateway public network mapping information, requests the mapping table from the gateway through UPnP, saves it on the client, and directly rewrites the IP port involved in the protocol when it needs to send data. Rewrite the public network IP port of the NAT gateway to send data out, and when the NAT gateway receives data from the external network, it only converts the IP and port information (transport layer) through the mapping table established by UPnP to send the data to the internal network
    • UPnP, Universal Plug and Play, is a communication protocol between network terminals and gateways
    • It is required that the NAT gateway, internal host, and application programs support UPnP at the same time, and the NAT gateway and the internal network host need to be allowed to exchange UPnP signaling when networking
  • Relay proxy technology (TURN): a public network application proxy server for transit
  • Protocol-specific self-traversal technology (IKE, IPSec technology): use UDP to add a layer of encapsulation to the outside of the message, and the internal message will no longer be affected
    • Because the protocol itself considers security and has the ability to identify messages against modification, other methods are invalid

3.4. Basic principle of probe drilling

Here we first describe the technology based on UDP protocol hole punching, and finally compare it with TCP hole punching

3.4.1. Fundamentals

Basic principle: With the assistance of the intermediate server, a mapping table is established on the respective NAT gateways, so that the messages of the two parties in the P2P connection can directly pass through the other party's NAT gateway. The client is connected to the intermediate server respectively, and the intermediate server will record the client's internal network IP port and external network IP port.

P2P Session establishment principle:

  • Client A and client B log in to the centralized server respectively, and the centralized server records their respective internal and external network IP ports (here, the centralized server needs to keep alive and refresh their respective IP port information)
  • Client A initially does not know how to initiate a connection to client B, so A sends a message to the centralized server, requesting the centralized server to help establish a UDP connection with client B
  • The centralized server sends B's internal and external network IP ports to A, and also sends A's internal and external network IP ports to B
  • A starts to send UDP packets to B's internal and external network address 2-tuple, and A will automatically lock the first B's address 2-tuple that responds (why do you need to send two sets of data packets at the same time? Because it is not clear that B is and A under the same NAT gateway, or under a different NAT gateway)
  • B starts to send UDP packets to A's internal and external network address 2-tuple, and B will automatically lock the first address 2-tuple that gives the corresponding A

3.4.2. Within the same NAT gateway

Usually a local area network.

UDP hole punching process:

before drilling

  • A (10.0.0.1:4321) registers and logs in to S (18.181.0.31:1234) through the NAT gateway (155.99.25.11)
    • After the data packet passes through NAT, a random port number 62005 will be assigned to A's connection
    • What S sees is (155.99.25.11:62005 sends information to it), recorded in the mapping table of S
  • B (10.1.1.3:4321) registers and logs in to S (18.181.0.31:1234) through the NAT gateway (155.99.25.11)
    • After the data packet passes through NAT, a random port number 62000 will be assigned to this connection of B
    • What S sees is (155.99.25.11:62000 sends information to it), recorded in the mapping table of S

punching

  • A (10.0.0.1:4321) requests B's address 2-tuple information from S (18.181.0.31:1234) through the NAT gateway (155.99.25.11), and the data packet contains A's intranet address (10.0.0.1:4321)
  • The request of A (10.0.0.1:4321) becomes the request of A' (155.99.25.11:62005) on the established NAT mapping table through the NAT gateway, and sends it to S
  • S (18.181.0.31:1234) sends a data packet to A' (155.99.25.11:62005) it sees, including B's internal and external network address information (10.1.1.3:4321, 155.99.25.11:62000), A Save the address information of B
  • S (18.181.0.31:1234) then sends a data packet to B' (155.99.25.11:62000) it sees, including A's internal and external network address information (10.0.0.1:4321, 155.99.25.11:62005) , B saves the address information of A
  • Then communicate with each other, A sends data to B, and B sends data to A, both of which try to communicate with the intranet address first. If the data packets are received by each other, remember the first packet return address information of the other party to identify the identity of the other party. Confirm that the internal network can communicate

After punching

  • A and B directly use the intranet address to communicate

Notice:

  • The UDP packets sent by A and B to the two-tuple information of the public network address of the other party may not be received by the other party, depending on whether the current NAT device supports the delivery of UDP data packets between different ports (Hairpin loopback conversion feature)
  • However, if the NAT device supports the Hairpin feature, try to use the intranet as a priority

3.4.3. Unreachable in the NAT gateway

UDP hole punching process:

before drilling

  • A (10.0.0.1:4321) registers and logs in to S (18.181.0.31:1234) through the NAT gateway (155.99.25.11)
    • After the data packet passes through NAT, a random port number 62000 will be assigned to A's connection
    • What S sees is (155.99.25.11:62000 sends information to it), recorded in the mapping table of S
  • B (10.1.1.3:4321) registers and logs in to S (18.181.0.31:1234) through the NAT gateway (138.76.29.7)
    • After the data packet passes through NAT, a random port number 31000 will be assigned to this connection of B
    • What S sees is (138.76.29.7:31000 sends information to it), recorded in the mapping table of S

punching

  • A (10.0.0.1:4321) requests B's address 2-tuple information from S (18.181.0.31:1234) through the NAT gateway (155.99.25.11), and the data packet contains A's intranet address (10.0.0.1:4321)
  • The request of A (10.0.0.1:4321) becomes the request of A' (155.99.25.11:62000) on the established NAT mapping table through the NAT gateway, and sends it to S
  • S (18.181.0.31:1234) sends a data packet to A' (155.99.25.11:62000) it sees, including B's internal and external network address information (10.1.1.3:4321, 138.76.29.7:31000), A Save the address information of B
  • S (18.181.0.31:1234) then sends a data packet to B' (138.76.29.7:31000) it sees, including A's internal and external network address information (10.0.0.1:4321, 155.99.25.11:62000) , B saves the address information of A
  • Then communicate with each other, A sends data to B, and B sends data to A. They both try to communicate with each other on the intranet first. If the data packets are received from each other, remember the first reply packet address information of the other party to identify the identity of the other party. Confirm that the internal network cannot communicate, and all subsequent packets will communicate with B's external network address

After punching

  • A and B directly use the intranet address to communicate

Note: If the packet sent by A to B arrives before the packet sent by B to A arrives at B's NAT device, the packet will be discarded, because the external network is not allowed to send packets to the inside by default.

3.4.4. Multi-layer unreachable NAT gateway

A general model of Internet ISP deployment to individual clients

UDP hole punching process:

before drilling

  • A (10.0.0.1:4321) sends data through the NAT-A gateway (10.0.1.1), and then sends the data packet to S (18.181.0.31:1234) through the NAT-C gateway (155.99.25.11) for registration and login
    • After the data packet passes through NAT-A, a random port number 45000 will be assigned to this connection of A
    • After the data packet passes through NAT-C, a random port number 62000 will be assigned to this connection
    • What S sees is (155.99.25.11:62000 sends information to it), recorded in the mapping table of S
  • B (10.1.1.3:4321) sends data through the NAT-B gateway (10.0.1.2), and then sends the data packet to S (18.181.0.31:1234) through the NAT-C gateway (155.99.25.11) for registration and login
    • After the data packet passes through NAT-B, a random port number 55000 will be assigned to this connection of B.
    • After the data packet passes through NAT-C, a random port number 62005 will be assigned to this connection
    • What S sees is (155.99.25.11:62005 sends information to it), recorded in the mapping table of S

punching

  • A (10.0.0.1:4321) requests the address 2-tuple information of B from S (18.181.0.31:1234) through the NAT-A gateway (10.0.1.1) and the NAT-C gateway (155.99.25.11), and the data packet contains A Intranet address (10.0.0.1:4321)
  • S (18.181.0.31:1234) sends a data packet to A' (155.99.25.11:62000) it sees, including B's internal and external network address information (10.1.1.3:4321, 155.99.25.11:62005), A Save the address information of B
  • S (18.181.0.31:1234) then sends a data packet to B' (155.99.25.11:62005) it sees, including A's internal and external network address information (10.0.0.1:4321, 155.99.25.11:62000) , B saves the address information of A
  • Then communicate with each other, A sends data to B, and B sends data to A. They both try to communicate with each other on the intranet first. If the data packets are received from each other, remember the first reply packet address information of the other party to identify the identity of the other party. Confirm that the internal network cannot communicate, and all subsequent packets will communicate with B's external network address

After punching

  • A and B directly use the intranet address to communicate

3.4.5. Preschool

  • Since the NAT device has an idle timeout count for UDP, all traversals will have a validity period
  • Both parties need to send heartbeat packets to each other, and this heartbeat packet must be sent by both parties to ensure that both sessions can work normally

3.4.6. TCP hole punching

Differences from UDP hole punching:

  • Generally, NAT devices are more friendly to UDP support, and TCP is more complicated (because the validity period of the mapping table of the TCP protocol on NAT can be automatically invalidated according to the TCP connection situation, while UDP can only be invalidated periodically; the NAT mapping table will be based on the port of the TCP sender number, that is, it must be consistent with the previous registration and login, otherwise the port address sent to the other end is different, and there is a high probability of failure)
  • UDP only needs to handle the sending and receiving communication of one socket, while TCP needs to bind the same port with multiple sockets (port multiplexing)
  • The success rate of TCP hole punching is far lower than that of UDP (NAT firewall strategy is not very friendly to TCP protocol)

TCP hole punching session establishment principle:

  • Client A uses its connection to the server to send a request to the server, asking the server to help it connect to client B
  • The server returns the TCP address 2-tuple information of client B's internal and external network to A, and at the same time, the server sends A's internal and external network TCP address 2-tuple to B
  • Clients A and B each use the port connected to the server to asynchronously initiate a TCP connection to the other party's internal and external network address 2-tuple, and at the same time monitor whether there is an external connection access on their respective local TCP ports
  • A and B start to wait for the outgoing connection to check whether there is a new connection. If an outgoing connection fails due to some kind of network error, the client can retry with a delay
  • After the TCP connection is established, the authentication operation should be started between the clients to ensure that the current incoming connection is the desired connection (compare the IP ports of both parties). If the authentication fails, the client will close the connection and wait for a new connection to be connected. The client only accepts the first authenticated client, and then enters the P2P communication process without continuing to wait for new connections

3.5. Commonly used hole punching protocol framework

  • STUN (P2P solution, supports TCP penetration and UDP penetration)
  • TURN (relay technology)
  • ICE (integrated STUN, TURN)

4. P2P download technology principle

4.1. Overview

The essence of downloading is to request resource data from a resource server, usually a limited server is used as a resource server.
For P2P downloading, it is considered that all the people who participate in the download are also resource servers, providing content for others to download. The downloader needs to know who to download, and it relies on the seed file to provide the resource server index.

P2P vs. C/S download:

  • In the original C/S mode, the more people download, the less bandwidth they get
  • P2P download mode, the more people download, the greater the bandwidth provided

4.2. Two P2P download technical solutions

4.2.1. BitTorrent Technical Solution

The BitTorrent protocol, released by American programmers in 2001, is a communication protocol based on P2P file transfer. The protocol requires resource publishers to provide a .torrent file based on file generation, which is a seed file.

Seed composition:

  • Tracker information: the address of the Tracker server and the settings for the Tracker server that need to be used in BT download
  • File information: Virtually divide the target file into blocks of equal size. The block size is an integer power of 2K. The file information here includes the index information and Hash information of each block.

The basic principle of P2P seed operation:

  • To download users, you first need to obtain the seed information, tracker server address and related settings
  • When a user downloads a resource and the local resource fragments land, the Tracker server will be notified, and the Tracker server will record the downloaded user information and store it in the server cache (the role of the Tracker server is similar to service discovery)
  • When someone else needs to download, it will first connect to the Tracker server to obtain the Peer list of downloaded resources, including users who have downloaded before.
  • Before the Peer and Peer downloads are ready to start, holes will be punched through the BT software (such as through the NAT device port validity period mechanism, etc.), so that they can communicate with each other, and then the file fragments will be downloaded. The BitTorrent software may request resource downloads from multiple people for multiple shards at the same time. If the Hash verification fails after downloading, other Peers will be tried

Defects of the BT scheme:

  • If the Tracker server is abnormal, the Peer list may not be obtained (single point of failure)
  • If each Peer fails, the download may time out

4.2.2. Kademlia technical solution

To be more precise, Kademlia is a P2P protocol for DHT (Distributed Hash Table) decentralized P2P solutions to solve the single point of failure problem in the BT solution, and the blockchain is such a solution.

Basic agreement:

  • Each node has an ID (very long), which is the HASH of a certain calculation method of a file in the DHT network
  • Each node needs to be responsible for storing file indexes, file fragments, etc., but each node does not have a complete knowledge, only one fragment, and does not know where all file fragments are stored
  • HASH is calculated for each file, then the node ID is the same or similar to the HASH, and the node needs to know where the file is stored

Session establishment principle:

  • node new is online, you need to download file 1
  • First, node new needs to obtain the seed file of file 1. This seed file will contain the addresses of some nodes and the Hash of file 1.
  • node new Inquire among the known nodes in the seed file according to the file 1Hash, and find the node information that is the same as or similar to Hash
  • When each node receives a request from node new, it will first check whether it meets the requirements. If it does not meet the requirements, it will further broadcast the request (similar to finding someone in a social network)
  • Once the node is found (we are node C here, which contains the index of file 1), it will reply to tell node new that it needs to go to B, D, and F to query respectively
  • node new connects with B first, and starts downloading. If you have file 1 locally, you will tell node C and the node with a similar ID that file 1 exists, and you can add that file to the owner list.
  • node C and other file 1 index owners will also add node new to the file 1 index list

4.3. P2P download implementation case based on BT technology

4.3.1. Problems encountered by P2P technology

The biggest problem is that the P2P rate is not high, and they often seek resources directly from the server, which makes it impossible to reduce the bandwidth cost of many servers. We can imagine that the most common thing is that when we push certain update files, it is usually at the same time. If the time periods for everyone's updates overlap, it is easy to cause a shortage of Peer nodes.

4.3.2. Solutions

By pre-push files, download resources can reach users in advance, and actively increase the number of Peer nodes. For this reason, it is also necessary not to affect the user's own experience. Generally, the following goals need to be achieved:

  • Under the premise that the user's bandwidth allows, increase the download speed
  • It is also necessary to strictly control the user's uplink bandwidth so as not to affect the user's access to the Internet
  • Guaranteed download quality and error control for large file downloads

Guess you like

Origin blog.csdn.net/a1058926697/article/details/131339909