Study notesWeek 3: Peer-To-Peer Networks
Week 3

Peer-To-Peer Networks

Outcomes

What You Can Do By The End

Two shapes

Client-Server Versus Peer-To-Peer

Client-server        P2P

 c   c   c          p--p--p
  \  |  /           |\ | /|
   [server]          p--p--p
Napster to now

A Short History

SystemYearLookup
Napster1999Central index
Gnutella2000Flooding
BitTorrent2001Tracker, later DHT
Kademlia2002Key distance
Sharing in pieces

BitTorrent In One Picture

Integrity

Hashes Protect Every Piece

import hashlib
print(hashlib.sha256(b'hello').hexdigest())
print(hashlib.sha256(b'hellp').hexdigest())
Incentives

Fairness And The Swarm

Where is the data?

The Lookup Problem

Kademlia

DHT: A Table Spread Over Peers

DHT in action

A Lookup, Step By Step

081725341020301,000 peers1,000,000 peers1,000,000,000 peers
key = 0b1011
asker  -> knows 0b0001, 0b1000
0b1000 -> knows 0b1010
0b1010 -> holds key 0b1011
Epidemic spread

Gossip: Spreading By Rumor

Code

Gossip Simulation

import random

n, fanout = 100, 2
known = {0}
rounds = 0
while len(known) < n:
    for p in list(known):
        known.update(random.sample(range(n), fanout))
    rounds += 1
print(rounds)
Reaching home computers

The NAT Problem

Remedies

Working Around NAT

Bootstrap and attacks

The First Connection And Its Dangers

Summary

Recap

Week 4

Next Week

Your turn

Questions And Exercise