Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How NAT traversal works in case of peer to peer protocols like bittorrent.

Tags:

I know about NAT traversal and about STUN, TURN and ICE and its use. I want to know whether these are implemented in peer to peer file sharing application like bittorrent. Whether trackers facilitate peers behind NATs to communicate with each other by helping in creating direct connection using STUN or relay through TURN. In the case of Distributed Hash Table(DHT) how one peer would communicate with other peer behind NAT ?

like image 725
user1887464 Avatar asked May 21 '16 20:05

user1887464


People also ask

How does BitTorrent get around NAT?

Each client get its public IP and temporary port number (UDP) using STUN server. STUN server helps client to detect presence of NAT and detecting public ip + temporary port number (assigned by NAT). Then client tries to establish a direct connection to other peer using punching hole technique (see wikipedia).

What is the problem of NAT used in the P2P application?

Network Address Translation (NAT) causes well-known difficulties for peer-to-peer (P2P) communication, since the peers involved may not be reachable at any globally valid IP address.

What protocol does BitTorrent use?

Data transport in BitTorrent Typically, BitTorrent uses TCP as its transport protocol for exchanging pieces, and it uses HTTP for tracker comms. The well known TCP port for BitTorrent traffic is 6881-6889 (and 6969 for the tracker port).

Is BitTorrent a client server protocol?

A BitTorrent client enables a user to exchange data as a peer in one or more swarms. Because BitTorrent is a peer-to-peer communications protocol that does not need a server, the BitTorrent definition of client differs from the conventional meaning expressed in the client–server model.


1 Answers

BitTorrent does not need to connect to any particular member in a swarm, it's not a p2p chat protocol where two specific end points want to talk to each other. All it cares about is that the connection graph of the swarm has a sufficiently high connectivity degree.

In other words, getting clients behind a NATs to talk to each other is somewhat desirable, but not to the point where major resources, such as traffic forwarding, would be expended on that goal. Failure is an option.

Thus it does not use sip/turn/etc.

Various clients use some combination of the following approaches to improve connectivity for the bulk transport connections:

  • PCP, NAT-PMP or UPnP-IGD negotiation with the gateway to forward a port as long as the application is running.
  • For TCP one can use source port binding (outgoing connections) and port reuse (listen + outgoing) socket options to use the same local port for all connections to exploit end-point independent (EIM) NAT mappings (also known as full cone NAT).
  • Similarly for UDP one should use a single socket in combination with sendto/recvfrom or equivalent APIs to multiplex all application-level connections over a single port instead of creating one socket per peer.
  • the largely undocumented ut_holepunch extension that uses mutually reachable swarm members in place of stun servers.
  • an optional UDP-based transport protocol (µTP) that can be used in combination with the previous points. generally nat traversal is easier to achieve with udp
  • IPv6 capability signalling, which in principle allows clients to upgrade their connections and then gossip about v6 peers via PEX/DHT.
  • prompting the user to perform manual port forwarding

In the case of the DHT only the first two points (gateway negotiation and port reuse) are used. The overhead of attempting nat traversal for a single request-reply cycle would be >100% and is not worth it.

like image 184
the8472 Avatar answered Sep 20 '22 04:09

the8472