Architecture, Wire Format and Production Engineering of Wisp Protocol v2
Introduction
Chapter 1: Introduction to the Wisp Protocol
- 1.1 What is Wisp?
- 1.2 Design Goals
- 1.3 Architectural Principles
- 1.4 Practical Use Cases
- 1.5 Wisp Versions
- 1.6 Summary
Chapter 2: Terminology and Conceptual Framework
- 2.1 Core Terminology
- 2.2 Conceptual Models
- 2.3 Relationship to Other Concepts
- 2.4 Notation and Conventions
- 2.5 Summary
Chapter 3: Architecture Overview
- 3.1 Layered Architecture
- 3.2 Component Architecture
- 3.3 Data Flow
- 3.4 Concurrency Model
- 3.5 Resource Management
- 3.6 Security Architecture
- 3.7 Interoperability Considerations
- 3.8 Summary
Chapter 4: Wire Format and Binary Encoding
- 4.1 Fundamental Data Types
- 4.2 The Wisp Packet Structure
- 4.3 Packet Type Encoding
- 4.4 Payload Formats by Packet Type
- 4.5 Extension Data Format
- 4.6 Complete Packet Examples
- 4.7 Encoding and Decoding in Code
- 4.8 Common Encoding Mistakes
- 4.9 Summary
Chapter 5: Packet Types and Message Framing
- 5.1 Packet Type Summary
- 5.2 CONNECT Packet (0x01)
- 5.3 DATA Packet (0x02)
- 5.4 CONTINUE Packet (0x03)
- 5.5 CLOSE Packet (0x04)
- 5.6 INFO Packet (0x05)
- 5.7 Optimistic Data Transfer
- 5.8 Packet Framing and WebSocket
- 5.9 Summary of Packet Types
Chapter 6: Connection Lifecycle and Handshake
- 6.1 Overview: The Phases of a Wisp Connection
- 6.2 Transport Establishment
- 6.3 The Wisp v2 Handshake: Step by Step
- 6.4 Version Negotiation and v1/v2 Compatibility
- 6.5 Authentication During the Handshake
- 6.6 Connection Termination
- 6.7 Formal State Machine
- 6.8 Timing, Ordering and Concurrency Rules
- 6.9 Common Handshake Failures and Diagnostics
- 6.10 Summary
Chapter 7: Protocol Extensions
- 7.1 The Extension System Overview
- 7.2 Extension Wire Format
- 7.3 Extension Negotiation Rules
- 7.4 Extension 0x01: UDP Support
- 7.5 Extension 0x02: Password Authentication
- 7.6 Extension 0x03: Public/Private Key Authentication
- 7.7 Extension 0x04: Server MOTD
- 7.8 Extension 0x05: Stream Open Confirmation
- 7.9 Extension Registry
- 7.10 The wisp-js Extension Architecture
- 7.11 Designing New Extensions
- 7.12 Summary
Chapter 8: Flow Control and Buffering
- 8.1 Design Goals
- 8.2 Directionality of Flow Control
- 8.3 The CONTINUE Packet as a Credit Grant
- 8.4 Client-Side Flow Control
- 8.5 Server-Side Per-Stream Buffering
- 8.6 A Complete Flow Control Trace
- 8.7 The Throttle Kill Switch
- 8.8 Server-to-Client Backpressure
- 8.9 Buffering and the Stream Lifecycle
- 8.10 Tuning Flow Control Parameters
- 8.11 Design Analysis: Packet Count vs. Byte Count
- 8.12 Summary
Chapter 9: Error Handling and Close Reasons
- 9.1 Principles of Error Handling in Wisp
- 9.2 The CLOSE Packet: Format and Semantics
- 9.3 Close Reason Taxonomy
- 9.4 Stream Creation Errors
- 9.5 Data Transfer and Runtime Errors
- 9.6 Handshake Errors
- 9.7 Malformed Packets and Protocol Violations
- 9.8 Client-Side Error Handling
- 9.9 Error Handling Best Practices for Applications
- 9.10 Monitoring and Diagnostics with Close Reasons
- 9.11 Summary
Chapter 10: Security Model
- 10.1 Security Architecture Overview
- 10.2 Transport Security: TLS
- 10.3 Authentication
- 10.4 Authorization and Access Control
- 10.5 SSRF: The Central Threat to Proxy Protocols
- 10.6 Denial-of-Service Protections
- 10.7 Data Confidentiality and Integrity
- 10.8 Extension Security
- 10.9 Deployment Security Checklist
- 10.10 Comparison with Alternative Tunneling Approaches
- 10.11 Summary
Chapter 11: Interoperability Requirements
- 11.1 The Importance of Interoperability in Proxy Protocols
- 11.2 Conformance Levels
- 11.3 Mandatory Protocol Behaviors
- 11.4 Wire Format Interoperability
- 11.5 Handshake Interoperability
- 11.6 Flow Control Interoperability
- 11.7 Known Discrepancies Between Specification and Implementations
- 11.8 Interoperability Testing Requirements
- 11.9 Guidelines for New Implementations
- 11.10 Future Compatibility and Extension Design
- 11.11 Summary
Chapter 12: The wisp-js Reference Implementation
- 12.1 Package Structure
- 12.2 Design Philosophy
- 12.3 Class Architecture
- 12.4 Mapping to the Specification
- 12.5 Testing Strategy
- 12.6 Development Tools
- 12.7 Version History and Compatibility
- 12.8 Summary
Chapter 13: wisp-js Source Code Analysis: Client
- 13.1 Client Architecture Overview
- 13.2 The Packet Codec (Shared Core)
- 13.3 The ClientStream Class
- 13.4 The ClientConnection Class
- 13.5 The WispWebSocket Polyfill
- 13.6 Client-Side Flow Control in Detail
- 13.7 Error Handling on the Client
- 13.8 Known Limitations and Deviations
- 13.9 Summary
Chapter 14: wisp-js Source Code Analysis: Server
- 14.1 Server Architecture Overview
- 14.2 The ServerStream Class
- 14.3 The ServerConnection Class
- 14.4 HTTP Upgrade Routing
- 14.5 The WebSocket Proxy (wsproxy)
- 14.6 Access Control and Filtering
- 14.7 Networking Wrappers
- 14.8 Server Configuration Options
- 14.9 Server-Side Extensions
- 14.10 Key Design Decisions and Trade-offs
- 14.11 Summary
Chapter 15: Other Wisp Implementations
- 15.1 The Wisp Ecosystem at a Glance
- 15.2 wisp-server-python
- 15.3 epoxy-tls: Rust Library and Browser Client
- 15.4 wisp-server-workers: Cloudflare Workers
- 15.5 Woeful: C++ High-Performance Server with Packet Capture
- 15.6 WispServerCpp
- 15.7 Go and Other Languages: The State of the Ecosystem
- 15.8 wispmark: Benchmarking Tool
- 15.9 Cross-Implementation Comparison
- 15.10 Interoperability
- 15.11 The Future of Wisp Implementations
- 15.12 Summary
Chapter 16: Development Environment Setup
- 16.1 Prerequisites
- 16.2 Required Tools
- 16.3 Project Setup
- 16.4 Cloning Reference Repositories
- 16.5 Understanding the WebSocket Environment
- 16.6 Development Workflow
- 16.7 Testing Environment
- 16.8 Security Considerations During Development
- 16.9 Summary
Chapter 17: Building a Minimal Wisp v2 Client
- 17.1 Project Setup
- 17.2 Step 1: Packet Encoding and Decoding
- 17.3 Step 2: The Stream Abstraction
- 17.4 Step 3: The Wisp v2 Client
- 17.5 Step 4: Putting It All Together - A Working Example
- 17.6 Step 5: Running the Client
- 17.7 Understanding the Minimal Implementation
- 17.8 Summary
Chapter 18: Building a Minimal Wisp v2 Server
- 18.1 Project Setup
- 18.2 Project Structure
- 18.3 Step 1: The Server-Side Stream Abstraction
- 18.4 Step 2: The Server Connection Handler
- 18.5 Step 3: The Wisp Server
- 18.6 Step 4: The Server Entry Point
- 18.7 Step 5: Testing the Server
- 18.8 Understanding the Minimal Server
- 18.9 Common Issues and Troubleshooting
- 18.10 Summary
Chapter 19: Building a Production-Ready Wisp v2 Client
- 19.1 Production Client Requirements
- 19.2 Project Structure
- 19.3 Step 1: Configuration and Logging
- 19.4 Step 2: Enhanced Stream with Backpressure
- 19.5 Step 3: Extension Handling
- 19.6 Step 4: Reconnection Logic
- 19.7 Step 5: The Production Client
- 19.8 Production Examples
- 19.9 Testing the Production Client
- 19.10 Summary
Chapter 20: Building a Production-Ready Wisp v2 Server
- 20.1 Production Server Requirements
- 20.2 Project Structure
- 20.3 Step 1: Configuration System
- 20.4 Step 2: Access Control
- 20.5 Step 3: Rate Limiting
- 20.6 Step 4: UDP Stream Support
- 20.7 Step 5: Enhanced Connection Handler
- 20.8 Step 6: The Production Server
- 20.9 Step 7: The Server Entry Point
- 20.10 Running the Production Server
- 20.11 Summary
Chapter 21: Testing Infrastructure
- 21.1 Testing Strategy Overview
- 21.2 Unit Tests
- 21.3 Integration Tests
- 21.4 Fuzz Testing
- 21.5 Conformance Testing
- 21.6 Load Testing
- 21.7 Continuous Integration
- 21.8 Testing Checklist
- 21.9 Summary
Chapter 22: Performance Analysis
- 22.1 Performance Model of Wisp
- 22.2 Key Performance Metrics
- 22.3 Factors Affecting Performance
- 22.4 Benchmarking Methodology
- 22.5 Performance Comparison: Wisp vs Alternatives
- 22.6 Optimization Techniques
- 22.7 Profiling and Monitoring
- 22.8 Case Studies
- 22.9 Summary
Chapter 23: Troubleshooting
- 23.1 Systematic Debugging Approach
- 23.2 Connection Issues
- 23.3 Handshake Issues
- 23.4 Stream Issues
- 23.5 Flow Control Issues
- 23.6 Performance Issues
- 23.7 Security Issues
- 23.8 Debugging Tools and Techniques
- 23.9 Common Error Code Quick Reference
- 23.10 Summary
Chapter 24: Production Deployment
- 24.1 Deployment Architectures
- 24.2 TLS Configuration
- 24.3 Reverse Proxy Configuration
- 24.4 Containerization
- 24.5 Configuration Management
- 24.6 Monitoring and Alerting
- 24.7 Scaling Strategies
- 24.8 High Availability
- 24.9 Security Hardening
- 24.10 Deployment Checklist
- 24.11 Summary
Appendix A: Complete Packet Type Reference
- A.1 Universal Packet Envelope
- A.2 Packet Type Registry
- A.3 CONNECT (0x01)
- A.4 DATA (0x02)
- A.5 CONTINUE (0x03)
- A.6 CLOSE (0x04)
- A.7 INFO (0x05)
- A.8 Quick-Reference Encoding Cheat Sheet
- A.9 Relationship to Other References
Appendix B: Complete Close Reason Reference
- B.1 Close Reason Structure
- B.2 Complete Close Reason Registry (Wisp v2.1)
- B.3 Usage Guidance for Implementers
- B.4 Close Reasons in Wisp v1 vs v2
- B.5 Relationship to Other References
Appendix C: Extension ID Reference
- C.1 The Extension System in Brief
- C.2 Common Extension Wire Format
- C.3 Complete Extension ID Registry (Wisp v2.1)
- C.4 Extension 0x01: UDP
- C.5 Extension 0x02: Password Authentication
- C.6 Extension 0x03: Public/Private Key Authentication
- C.7 Extension 0x04: Server MOTD
- C.8 Extension 0x05: Stream Open Confirmation
- C.9 Handling Unknown Extensions
- C.10 Extension Negotiation Rules
- C.11 Relationship to Other References
Appendix D: Working End-to-End Example
- D.1 Running the Example
- D.2 The Minimal Wisp v2 Server
- D.3 The Minimal Wisp v2 Client
- D.4 Sample Output
- D.5 Tracing the Packets
- D.6 Extending the Example
- D.7 Verifying with Wireshark
- D.8 Relationship to Other References
Appendix E: Wisp v1 vs v2 Migration Guide
- E.1 Overview of the Two Versions
- E.2 Packet Type Differences
- E.3 Handshake Differences
- E.4 Migration Checklist
- E.5 Dual-Version Support
- E.6 Behavioral Differences
- E.7 Code Changes Required
- E.8 Testing the Migration
- E.9 Deprecation Timeline
- E.10 Relationship to Other References