Chapter 08 of 22Part II: Networks and Communication
The Incredible Journey of an Internet Packet
Each project below is tailored to a specific algorithm and scientific question from Chapter 08, with concrete inputs, verifiable numerical outputs, boundary cases, and links to the related lab and pioneer.
Project 1 of 3 · v1-c08-p01Foundational · ~25 min
Hierarchical Mini-DNS Resolver
Lab activity: 1. Mini DNS · Related code: block-01.js · Pioneer: View profile
Real-World Problem: Humans remember names like howdigitalworks.dev, while Internet routers forward packets using numeric IP addresses.
Scientific Question: How do recursive resolvers, authoritative zones, and TTL caches work together without one central bottleneck?
Objective: Build a miniature DNS resolver with caching, TTL expiration, and NXDOMAIN error handling.
Hypothesis to Test: Caching resolved records for their TTL avoids repeated upstream lookups while still picking up updates after expiry.
Step-by-Step Implementation
Populate a miniature zone table mapping domain names to fictional IPv4/IPv6 addresses and TTLs.
Implement lookup(domain, nowSec) checking cache validity before querying the zone.
Test cache hits, cache expiration, and unknown domain NXDOMAIN responses.
Trace how CNAME aliases resolve to target A/AAAA records.
Concrete Input: Query "howdigitalworks.dev" twice within TTL=60s, then after 61s; query "missing.invalid".
Expected Output: Query 1: cache MISS (authoritative lookup); Query 2: cache HIT; After 61s: refreshed; missing.invalid -> NXDOMAIN.
Test Cases: Known domain -> IP; Unknown domain -> NXDOMAIN; Expired TTL -> fresh lookup.
Boundary Condition: Detect CNAME loops (A -> B -> A) with a max-hop counter to avoid infinite recursion.
Common Mistake to Avoid: Forgetting case-insensitivity of DNS domain names (Example.COM === example.com).
Interpreting Results: Paul Mockapetris's hierarchical DNS design lets billions of devices resolve names quickly and reliably.
Show Hint, Extension Challenge & Reflection
Hint: Review the worked example and equation in Chapter 08 before testing the boundary case: Detect CNAME loops (A -> B -> A) with a max-hop counter to avoid infinite recursion.
Extension Challenge: Add a hop limit (max 5 CNAME redirects) and test a deliberate CNAME cycle.
Reflection Question: Why does changing a website's IP address sometimes take minutes or hours to appear worldwide?
Test Cases: Connected graph -> optimal path; Single link down -> alternate path; Partitioned graph -> unreachable.
Boundary Condition: Zero-cost or negative link weights break standard Dijkstra and must be rejected.
Common Mistake to Avoid: Leaving stale bidirectional edges when disabling only one direction of a broken link.
Interpreting Results: Packet switching and dynamic routing give the Internet decentralized fault tolerance.
Show Hint, Extension Challenge & Reflection
Hint: Review the worked example and equation in Chapter 08 before testing the boundary case: Zero-cost or negative link weights break standard Dijkstra and must be rejected.
Extension Challenge: Add a Time-To-Live (TTL) hop counter to each packet so routing loops terminate cleanly.
Reflection Question: How did Bob Kahn, Vint Cerf, and Radia Perlman's routing ideas make global packet networks possible?
Real-World Problem: IP routers can drop, duplicate, or reorder packets during congestion.
Scientific Question: How do TCP sequence numbers and acknowledgments reconstruct an exact byte stream over an unreliable channel?
Objective: Split a message into numbered segments, simulate packet loss and reordering, and verify complete reassembly.
Hypothesis to Test: With sequence numbers and ACK-based retransmission, the receiver reconstructs the exact original text even when 30% of packets are dropped or shuffled.
Step-by-Step Implementation
Chunk a string into numbered packets (seq = 0, 1, 2...).
Shuffle arrival order and drop one selected packet in transit.
Have the receiver acknowledge received sequence numbers and request missing gaps.
Sort buffered segments by sequence number and verify exact equality with the original message.
Concrete Input: Message "PACKETS_WORK" split into 4-byte segments; drop seq #1 and swap seq #2 and #0.
Expected Output: Receiver buffers seq #2 and #0, requests retransmit of seq #1, reassembles exact "PACKETS_WORK".
Boundary Condition: Exceeding max retry count should report a connection timeout rather than looping forever.
Common Mistake to Avoid: Appending packets in arrival order instead of indexing by sequence number.
Interpreting Results: Layering reliable TCP on top of best-effort IP keeps core routers simple while guaranteeing end-to-end delivery.
Show Hint, Extension Challenge & Reflection
Hint: Review the worked example and equation in Chapter 08 before testing the boundary case: Exceeding max retry count should report a connection timeout rather than looping forever.
Extension Challenge: Add a simple sliding window (window size = 2) and count total round trips needed.
Reflection Question: Why do live voice/video calls often use UDP instead of waiting for TCP retransmissions?