Module Downloader

Module Downloader 

Source
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:

  1. Resilient Pattern: Circuit breaker with exponential backoff for retry logic
  2. Streaming Pattern: Progressive downloads with real-time progress tracking
  3. Verification Pattern: SHA-256 checksum validation for integrity assurance
  4. Resource Management: Parallel downloads controlled by bandwidth limits
  5. 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

  1. Extension host requests VSIX download from marketplace APIs
  2. DownloadManager validates VSIX manifest and signed content
  3. Download proceeds with progress callbacks to UI
  4. Checksum verification of signed .vsix package
  5. Atomic commit to extension installation directory

§Mountain Package Workflow

  1. Build system initiates dependency downloads
  2. DownloadManager validates package signatures
  3. Parallel chunk downloads for large packages
  4. Bandwidth throttling to prevent network saturation
  5. 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§

DownloadConfig
Download configuration with validation constraints
DownloadManager
Download manager implementation with full resilience and capabilities
DownloadResult
Download result with full metadata
DownloadStatistics
Download statistics and analytics
DownloadStatus
Download status with comprehensive tracking
QueuedDownload
Queued download with metadata

Enums§

DownloadPriority
Priority levels for download queuing
DownloadState
Download state with detailed progress

Type Aliases§

ProgressCallback
Progress callback type