Chapter 08 of 22 Part 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-p01 Foundational · ~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

  1. Populate a miniature zone table mapping domain names to fictional IPv4/IPv6 addresses and TTLs.
  2. Implement lookup(domain, nowSec) checking cache validity before querying the zone.
  3. Test cache hits, cache expiration, and unknown domain NXDOMAIN responses.
  4. 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?

Project 2 of 3 · v1-c08-p02 Intermediate · ~30 min

Resilient Packet-Routing Graph Simulator

Lab activity: 2. Route around broken links · Related code: block-02.js · Pioneer: View profile

Real-World Problem: Undersea cables and fiber links get cut every week, yet the Internet stays online.
Scientific Question: How do shortest-path routing algorithms automatically detour packets around failed links?

Objective: Run breadth-first / Dijkstra shortest-path routing on a fictional router graph and test link failures.

Hypothesis to Test: Disabling the primary link between Router A and Router D forces packets onto the lowest-cost surviving alternate path.

Step-by-Step Implementation

  1. Represent routers and weighted links as an adjacency list.
  2. Compute shortest path from source to destination router.
  3. Mark one active link as down and recompute the route dynamically.
  4. Remove a cut-edge (bridge) and verify graceful "Destination Unreachable" reporting.
Concrete Input: 6-router weighted graph; remove link B–C and route from A to F.
Expected Output: Primary path A->B->C->F (cost 5) fails -> automatic reroute A->B->E->F (cost 7).

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?

Project 3 of 3 · v1-c08-p03 Intermediate · ~30 min

TCP Sequence, Drop & Retransmission Lab

Lab activity: 3. Message delivery · Related code: block-03.js · Pioneer: View profile

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

  1. Chunk a string into numbered packets (seq = 0, 1, 2...).
  2. Shuffle arrival order and drop one selected packet in transit.
  3. Have the receiver acknowledge received sequence numbers and request missing gaps.
  4. 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".

Test Cases: Out-of-order delivery -> exact output; Duplicate packet -> ignored cleanly; Dropped packet -> retransmitted.

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?