Skip to content
BoKSA

07 – Peer-to-Peer Networks and BitTorrent

07 – Peer-to-Peer Networks and BitTorrent

Course: ICT Basic course · Level: introductory Book: Kurose & Ross, 9th ed., chapter 2.5 (peer-to-peer file distribution)

Learning goals

After this article you can:

  • explain why P2P scales better than client-server for distributing large files;
  • compare the distribution time of client-server and P2P (without memorising the formulas);
  • explain how BitTorrent works: torrents, trackers, DHT, chunks, rarest first and tit-for-tat;
  • name current uses of P2P technology;
  • describe the security, privacy and legal risks of P2P.

1. Why peer-to-peer?

Imagine distributing a 10 GB game update to 1 million players.

  • Client-server: the server must upload N copies. Its upload capacity is the bottleneck. The more users, the longer it takes.
  • P2P: every peer that has received part of the file can upload it to others. Each new peer adds demand and capacity. This is called self-scalability.

1.1 Distribution time (idea)

Symbols: F = file size, N = number of peers, u_s = server upload rate, u_i = upload rate of peer i, d_min = lowest download rate.

Client-server:

D_cs ≥ max { N·F / u_s , F / d_min }

→ grows linearly with N.

P2P:

D_P2P ≥ max { F / u_s , F / d_min , N·F / (u_s + Σ u_i) }

→ the total upload capacity grows with N too, so the distribution time levels off.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
 distribution
 time  │                      client-server  /
       │                                   /
       │                                 /
       │                               /
       │                             /
       │                   ______----------  P2P
       │           ___----
       │     __---
       │ _--
       └────────────────────────────────────── N (number of peers)

You don't have to memorise the formulas, but you should be able to explain this graph (Kurose & Ross, fig. "Distribution time for P2P and client-server architectures").


2. BitTorrent

BitTorrent (Bram Cohen, 2001) is the most widely used P2P file-distribution protocol.

2.1 Terms

Term Meaning
Torrent / swarm the group of all peers sharing one particular file
Pieces (chunks) the file is split into pieces (typically 256 KiB – several MiB); each piece has a hash to check its integrity
.torrent file / magnet link metadata: file name, piece size, hashes (the info-hash identifies the torrent)
Tracker a server that keeps a list of peers in a swarm
DHT (Distributed Hash Table) a trackerless way to find peers: the peer list is spread over all participants (Kademlia algorithm)
Seeder a peer with the complete file that only uploads
Leecher a peer that is still downloading (and uploading what it has)

2.2 How it works

1
2
3
4
5
6
1. Alice opens a magnet link  →  asks tracker / DHT: "who has info-hash X?"
2. She gets a list of peers   →  sets up TCP (or uTP over UDP) connections to some of them
3. Peers exchange which pieces they have (bitfield)
4. Alice requests pieces; meanwhile she uploads pieces she already has
5. Each piece is checked against its hash; a bad piece is downloaded again
6. When complete, Alice can stay as a seeder

Two clever rules:

  • Rarest first: Alice first requests the pieces that the fewest of her neighbours have. This spreads rare pieces quickly, so the swarm doesn't depend on a few peers.
  • Tit-for-tat: Alice uploads to the 4 peers that send her data fastest (re-evaluated every 10 seconds). Every 30 seconds she also picks one random peer to upload to (optimistic unchoking), so newcomers get a chance and she may find better partners. Result: peers that upload get better download speeds, and "free riders" are discouraged.

2.3 Developments

Then (≈2010) Now
BitTorrent was a large share of all Internet traffic Its share is much smaller: most video now comes from streaming services via CDNs
Trackers essential DHT + magnet links standard; trackers optional
SHA-1 hashes BitTorrent v2 (BEP 52) uses SHA-256 and per-file hash trees
TCP only uTP (over UDP) with congestion control that gives way to other traffic (LEDBAT)
desktop clients also WebTorrent (P2P in the browser via WebRTC)

2.4 Where is P2P used today?

  • Legal distribution of large files: Linux ISO images (Debian, Ubuntu), game updates (Blizzard used P2P for years), scientific data sets (Academic Torrents).
  • Software updates on local networks: Windows Delivery Optimization shares updates between PCs on the same network.
  • Real-time communication: WebRTC sends audio/video directly between browsers (with STUN/TURN servers to traverse NAT).
  • Decentralised systems: IPFS (content-addressed storage), blockchains (Bitcoin and Ethereum nodes form P2P networks).
  • Hybrid CDNs: some video platforms let viewers share segments with each other.

3. Try it yourself

  1. Download the Debian netinst ISO via BitTorrent (https://www.debian.org/CD/torrent-cd/) with a client such as qBittorrent or Transmission. Look at the "Peers" tab: how many seeders and leechers? Which pieces are you downloading first?
  2. Run Wireshark during the download. Filter on bittorrent (or udp for DHT/uTP). Can you find the handshake with the info-hash?
  3. Calculate: a server with u_s = 1 Gbit/s distributes a 5 GB file to 1,000 clients. What is the minimum client-server distribution time? (Ignore d_min.)

Check your understanding

  1. What does "self-scalability" mean?
  2. What is the difference between a tracker and a DHT?
  3. Why does BitTorrent use "rarest first"?
  4. How does tit-for-tat discourage free riders?
  5. Name two legitimate, current uses of P2P technology.

References

Book

  • Kurose & Ross, 9th ed., chapter 2.5 (Peer-to-peer file distribution)

Videos

Articles and standards


Cyber Security

Why is this important for cyber security?

  • Your IP address is public. In a BitTorrent swarm every peer can see the IP addresses of the others. Monitoring companies (e.g. on behalf of rights holders) collect these.
  • Malware in disguise. Pirated software, games and films from P2P networks are a classic way to spread malware, cryptominers and infostealers.
  • Legal risk. In the Netherlands, downloading from illegal sources is not allowed (EU Court of Justice, ACI Adam ruling, 2014). Uploading copyrighted material (which BitTorrent does automatically) is illegal too. BREIN actively enforces this.
  • Data leaks. Wrongly configured P2P clients have shared entire hard drives, including private documents.
  • Abuse of P2P for attacks. Botnets use P2P networks for command and control (hard to take down because there's no central server), and DHT/uTP have been misused for DDoS amplification.
  • Corporate networks: P2P traffic can use a lot of bandwidth, bypass security controls and break company policy.

What can you do to make it safe?

  • Only use P2P for legal content from trusted sources (official Linux torrents, game launchers), and check hashes/signatures of downloaded files (sha256sum file.iso).
  • Scan downloads with antivirus, and never run cracked software.
  • Configure your client carefully: share only one dedicated download folder; enable protocol encryption (it only hides the traffic from simple inspection, it doesn't make you anonymous).
  • Organisations: define a policy, and block or limit P2P with a next-generation firewall (application detection) if it isn't needed.
  • Developers: in P2P applications, treat every peer as untrusted: verify data with hashes and signatures, and limit resources per peer.

Extra references