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 | |
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 | |
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
- 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?
- Run Wireshark during the download. Filter on
bittorrent(orudpfor DHT/uTP). Can you find the handshake with the info-hash? - 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
- What does "self-scalability" mean?
- What is the difference between a tracker and a DHT?
- Why does BitTorrent use "rarest first"?
- How does tit-for-tat discourage free riders?
- Name two legitimate, current uses of P2P technology.
References
Book
- Kurose & Ross, 9th ed., chapter 2.5 (Peer-to-peer file distribution)
Videos
- Jim Kurose's video lectures, chapter 2 (P2P) – https://gaia.cs.umass.edu/kurose_ross/lectures.php
- Computerphile – Hashing Algorithms and Security (why pieces are hashed) https://www.youtube.com/watch?v=b4b8ktEV4Bg
Articles and standards
- BEP 3 – The BitTorrent Protocol Specification – https://www.bittorrent.org/beps/bep_0003.html
- BEP 5 – DHT Protocol – https://www.bittorrent.org/beps/bep_0005.html
- BEP 52 – BitTorrent v2 – https://www.bittorrent.org/beps/bep_0052.html
- WebRTC (MDN) – https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API
- Debian – Downloading Debian CD/DVD images with BitTorrent – https://www.debian.org/CD/torrent-cd/
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
- Stichting BREIN (NL) – https://www.stichtingbrein.nl/
- NCSC-NL – https://www.ncsc.nl/
- Computerphile – How TOR Works (anonymity vs. P2P) https://www.youtube.com/watch?v=QRYzre4bf7I