Building a p2p network in 2021 with Rust

I am looking for tips on what I should look for when building my own p2p network over UDP (NB: I am not against switching to TCP if UDP does not make any sense).

This is how I plan the future developments of my program and my questions:

  • Make it truly p2p (currently only sharing between client and server) -> for that I was thinking to build a tracker server that would send a list of peers that hold the desired file and then I realize I could just make each client as tracker. However, how does a new peer connect to the other peers since he has not yet discovered their IP? There must still be an original (gateway) tracker right?
  • Currently I am send every blocks of the file using the max size one can send over UDP (64kb), but I loose quite a significant amount of packets (25%, probably due to MTU), I wonder if I should reduce this size (of course I will test it if no one has any insight about this). But it may have to do with the fact that I literally blast the packets over the internet without waiting for confirmation that the packet has been received. Hence I am also thinking to add a limit to the amount of packets that are sent by server peers. How to deal with the ISP MTU?
  • I only send a custom header on top of the UDP and IP header that only specify how many blocks have to be received and the total amount of blocks. I think I will switch to the following p2p system, once the tracker server is setup:
    • a) Peer (client) sends request to the tracker(s) to see what is available, he gets back a list of files that are keys of a multivalue hashmap. Each key being the file and value points to IP of peers owning at least 3.125% of the file.
    • b) Then after choosing which files he want, the peer (client) send a requests to the nodes (server) owning the file, where he specifies what is the filename that he wants (his IP is already part of the UDP header).
    • c) The server nodes will start sending a list of index blocks they own, if no answer after 10sd the server node will repeat its question.
    • d) On the client side, he will start asking for blocks that have the lowest ownership (rarest blocks first), and start answering back to the server nodes about which blocks they would like to get.

I appreciate any insight. Thanks!

Links that helped me to understand the general ideas:

1 Like