Expand description
§Download Manager Service
§Core Responsibilities
The DownloadManager provides a comprehensive, resilient service for downloading files, extensions, dependencies, and packages within the Land ecosystem. It serves as the central download authority across all components including:
- Cocoon (Extension Host): VSIX extension downloads from marketplaces
- Mountain (Tauri Bundling): Package and dependency downloads for builds
- Air (Background Daemon): Runtime updates and internal component downloads
- Other Components: File downloads, resource fetching, and asset management
§Architecture and Design Patterns
Based on VSCode’s download manager patterns found in:
src/vs/platform/download/common/downloadService.ts
Key architectural principles:
- Resilient Pattern: Circuit breaker with exponential backoff for retry logic
- Streaming Pattern: Progressive downloads with real-time progress tracking
- Verification Pattern: SHA-256 checksum validation for integrity assurance
- Resource Management: Parallel downloads controlled by bandwidth limits
- Priority Queuing: Download scheduling based on urgency and dependencies
§Resilient Downloading Patterns
§Retry Logic with Circuit Breaker
- Exponential backoff: 1s, 2s, 4s, 8s, 16s, 32s (max)
- Circuit breaker opens after consecutive failures to prevent cascade
- Success/failure budgets controlled per-minute limits
- Automatic recovery attempts with grace periods
§Partial Download Resume
- Supports HTTP Range headers for interrupted download recovery
- Hash verification on resume ensures data integrity
- Temporary file management with atomic commit
- Cleanup of corrupted partial files on failure
§Integrity Verification
- SHA-256 checksum validation during and after download
- Progressive verification for large files (chunked hashing)
- Signature verification for signed packages
- Detection and handling of tampered downloads
§Integration Points
§Cocoon Extension Workflow
- Extension host requests VSIX download from marketplace APIs
- DownloadManager validates VSIX manifest and signed content
- Download proceeds with progress callbacks to UI
- Checksum verification of signed .vsix package
- Atomic commit to extension installation directory
§Mountain Package Workflow
- Build system initiates dependency downloads
- DownloadManager validates package signatures
- Parallel chunk downloads for large packages
- Bandwidth throttling to prevent network saturation
- Atomic staging with final commit to build cache
§VSIX Download and Validation
- Supports marketplace API authentication tokens
- Validates extension manifest before download
- Verifies package signature after download
- Extracts and validates contents before installation
§TODOs and Future Enhancements
§P2P Distribution (Planned)
- Peer-to-peer file sharing between Land instances
- BitTorrent-like protocol for large package distribution
- Chunk verification from multiple sources
- Swarm coordination for rapid downloads
§Chunked Downloads (In Progress)
- Parallel HTTP Range requests for large files
- Automatic chunk size optimization based on bandwidth
- Reassembly with integrity verification
- Dynamic chunk adjustment based on network conditions
§Bandwidth Limiting (In Progress)
- Per-download rate limiting
- Global bandwidth pool management
- Time-based bandwidth schedules (off-peak acceleration)
- QoS priorities for critical vs non-critical downloads
§Additional Features
- CDN integration for faster regional downloads
- Adaptive mirror selection based on latency
- Pre-fetching and caching of frequently accessed resources
- Download deduplication across the ecosystem
Structs§
- Download
Config - Download configuration with validation constraints
- Download
Manager - Download manager implementation with full resilience and capabilities
- Download
Result - Download result with full metadata
- Download
Statistics - Download statistics and analytics
- Download
Status - Download status with comprehensive tracking
- Queued
Download - Queued download with metadata
Enums§
- Download
Priority - Priority levels for download queuing
- Download
State - Download state with detailed progress
Type Aliases§
- Progress
Callback - Progress callback type