Web Basics
Web Essentials
Transfer: Networking/ OS basics, HTTP Content: HTML, Encoding, Dynamic pages
Networking Basics
Before being sent, files are broken up into packets of data
- Circuit Switching: All the packets are sent along the same route. Cons: easy to hack because you know the exact route the packets are going to follow Pros: Good for real time things like voice, call, video
- Packet Switching: All the packets are sent along different routes. Downsides: It will take more time because the packets need to be reassembled at the end Pros: Makes better use of resources, if one node in network is destroyed can still work because doesn't depend on a singular route
Network Protocol Stack Model
Open System Interconnection (OSI) Reference Model
The layers are
- User interaction (HTTP, FTP, SMTP)
- Data representation (XML, cryptography)
- Dialogue management (?)
- Reliable end-to-end link (TCP)
- Routing via many nodes (IP)
- Physical addressing (Ethernet)
- Metal or RF representation (Wifi, Bluetooth)
- Network Transport Protocols: IP, TCP and UDP
- TCP and UDP are built on top of IP
- IP is the route and addressing between the nodes. TCP/UDP are the protocols for how to transfer the data
- TCP is reliable end-to-end network. It has error checking, makes sure packets get to recipient in the correct order
- UDP is meant for speed. It uses IP directly, as a forwarding service. It's a one way connection, not reliable, and no error checking. Often used for streaming
Network Transfer & HTTP (Hypertext Transfer Protocol)
Language client uses to talk to the server
- Browser(client) opens TCP connection to server, writes request, server responds, connection closed (if HTTP 1.0)
- It's stateless: every request is brand new
- HTTP 1.0 has a non persistent TCP connection, 1.1 has a persistent connection HTTP Structure:
- Break URL into hostname and path
- Contact host at port and send any data to server
- Download result code, bytes, and send to HTML renderer to show page
HTTP Server Design Approaches
- Wait until HTTP request arrives, start server, serve request, kill server (super inefficient)
- Sit in a loop waiting for requests (can only have one request at a time)
- Have a bunch of processes sitting around waiting (high memory overhead)
- Best option: Processes with threadpools (threads lighter than processes, but lose some memory protection)
URL Encoding
DNS lookup translates server name into an IP address (the numbers that a computer uses to identify itself on a network) DNS (Domain Name System) is a database of network names and IP addresses on the internet
- Content Encoding: HTML (Hypertext Markup Language)
More Networking Basics
- IP address assigned using Dynamic Host Configuration Protocol (DHCP) and mapped to target Ethernet address with Address Resolution Protocol (ARP)
- ARP can be subject to man-in-the-middle attacks
- Sliding window algorithm Handles communication buffering between sender and receiver.
- Helps receiver handle input by ensuring the sender never transmits more than the advertised window size. The sender buffers unACKed data, receiver buffers data that is out-of-order or not yet read
- 3 Way Handshake: Sender sends sequencenum x, receiver sends sequencenum y, x+1, and ACK, sender sends ACK and y + 1
Congestion
Handling buffering in the network
- Buffers in middle of network, like routers, can become overloaded because they're not part of window negotiation -Queue and drop-tail technique Drop the incoming packet if the queue is full
- AIMD (Additive Increase Multiplicative Decrease) -An algorithm for cautious network load calculation
- Upon losing a packet, decreases this number. Upon success, increases this number. Trying to always figure out what's a successful transfer rate
Summary:
- TCP Flow Control: receiver window
- TCP Congestion Control: congestion window (max number of bytes to have in transit)
- TCP Window: min { congestion window, receiver window }