How is the algorithm of a P2P application?

Asked

Viewed 1,506 times

15

There are several P2P programs, I know that the concept is that each computer is like a client and server at the same time, and that they communicate with each other. On this type of communication:

  • If you don’t have a server, how does the program know where your "brothers are"?
  • What would be the algorithm of a P2P program for message transmission?
  • It is possible to create P2P communication on a local network?
  • Is there a standard port for this type of connection or can I choose any one "available"?
  • @Felipedoiradinho, I made an update on the question.

2 answers

12


There are several implementations of protocols peer to peer (among equals in free translation). In general, they are characterized by:

  • Communication of non-linear content: Large contents can be broken into smaller packages, and sent out of order (the client takes charge of organizing the packages);
  • Auto-resolution of services: The customer knows, by itself, how to search and initiate communication with other elements equal to himself present in the same logic mesh;
  • Unreliability: Client does not assume any external aspect as immutable and reliable (packages can be corrupted, peers can disconnect, or send wrong packets);
  • Control routing: The client knows how to pass on requests that he cannot comply with.

Some services also implement the concept of trackers (trackers) which are services where certain information (such as routing tables and correlations between peers and content) is compiled and can be checked for higher resolution speed.

Note that trackers act only as a hint; the client, possession of the list of peers of a certain content, tries to connect to them and validate the information they actually possess. Trackers with a lot of wrong information can enter for a Blacklist, for example.

Let’s take the chart below as a practical description of a peer-to-peer mesh, and simulate some cases:

inserir a descrição da imagem aqui

  • Resolution of peers: The machine 7 sends a message in style broadcast to the network, without any specific target, asking for members of the same mesh. The machines 5 and 6 reply, and are added to the list of peers that 7 can see.

  • Content resolution: 7 question both to 6 as to 5 where the content To can be found. 6 responds that the content exists in 2 and 1, while 5 replies that 2 has the contents. Machine 7 then attempts to establish a direct connection with 2 and 1, and marks them as likely repositories of To.

  • Transmission of content: 7 question to 2 the amount of packages that make up To. The answer, 5 packages, comes along with the statement that 2 has only the packages AP1 and AP2. 7 then requests the package AP1 to 2, while asking the 1 what packages of To he has; 7 will then attempt to coordinate the package request to cover the entire content (AP1-AP5).

  • Ads: 4, which also has the content To, enters the net, announcing its presence to 5. 5, in turn, warns the 7 that another customer containing To is available.

Note that at no time does any of the machines treat your peers as a classic server. This type of structure can be implemented on local network, and benefit from the (usually) increased reliability, speed and stability of the environment.

  • When you say "send a message in style broadcast to the network, "How exactly is this done? Do I need no "target" to send a request/message? Have some example in C#, PHP or other similar language?

  • @Kaduamaral There are several ways, and some do not require a 'target' for your messages - just that they are in the same subnet. You can use the UDP protocol in broadcast or multicast style, for example. You can see an example of implementation in C# in this link: http://feodrippe.com/post/9867540504/udp-codigos-em-c-para-cliente-e-server

  • Interesting haha, is that I work with web development, ie HTTP protocol in the vein, nor remember that there was UDP and TPC, hahah

  • @Kaduamaral and you can use both together when necessary. =)

5

There is no server, but there is an "queuer", called Tracker.

What are Trackers?

Trackers are servers responsible for telling your P2P program the IP of seeders and leechers. The more trackers, the more seeders and leechers.

Therefore, your P2P client sends your connection information (IP, PORT, etc) to the tracker (probably webservice). Another user with the same client, searching for a small part of the file, receives this information from(s) tracker(s) and therefore downloads. The more trackers, repeating, the more parts available as these in turn multiply the customer information (and therefore the parties).

The algorithm should only follow this workflow and of course, there is not only one algorithm, since trackers also use their own programs following the P2P standard.

  • In order to make a p2p system on a local network, I will also have to create the tracker?

  • Well, Kaduamaral, if the intention is to create a P2P system on a local network, I think the FTP concept is more appropriate. Anyway: yes, just set a machine to delegate and receive client information (which are also kkkk servers)

  • kkk, but the main focus is the exchange of messages, without a server intermediating this exchange, having the tracker (server) only to inform where the other "end of the string" is.

  • Ah tá hehe What would be the platform (OS and language)? Already in advance, o Pattern Observer can help, see here (examples of implementation at the bottom of the page): https://sourcemaking.com/design_patterns/observer

  • Windows systems probably in C#, perhaps later in python, both for language study.

  • Oh yes! I love C! Take a look: http://csharp.net-informations.com/communications/csharp-chat-server.htm and http://csharp.net-informations.com/communications/csharp-chat-server-programming.htm

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.