DLManDLMan
Core Engine

Download Engine

The dlman-core crate is the heart of DLMan. It handles all download operations and is shared between the desktop app and CLI.

Multi-Segment

Split files into up to 32 parallel segments

SQLite Persistence

Progress saved atomically after every chunk

Rate Limiting

Token bucket algorithm for smooth throttling

Queue Scheduler

Time-based start/stop with day-of-week rules

Auto-Retry

Exponential backoff with configurable retries

Crash-Safe

Resume from exact byte position after failures

Multi-Segment Downloads

When you download a file, DLMan splits it into multiple segments that download in parallel. Each segment uses its own HTTP connection with a Range header, writing directly to the correct file offset.

Download Process
1

Probe

HEAD request to get file size and check Accept-Ranges header

2

Plan

Calculate segment boundaries based on file size and settings

3

Spawn

Launch async segment worker tasks, each with its own HTTP connection

4

Stream

Stream data in 8KB chunks, writing to correct file offset with seek

5

Progress

Report progress every 100ms via broadcast channels

6

Complete

All segments done — verify file integrity if checksum available

Segment Sizing

Segment count is automatically calculated based on file size:

File SizeSegmentsPer Segment
< 1 MB1Full file
1 – 10 MB2~50%
10 – 100 MB4~25%
100 MB – 1 GB8~12.5%
> 1 GB16Variable

Pause & Resume

Pausing

  1. Cancel all segment worker tasks
  2. Save progress to SQLite immediately
  3. Record downloaded_bytes per segment

Resuming

  1. Load segment progress from SQLite
  2. Restart workers from last byte position
  3. Use Range: bytes=current-end header

Speed Limiting

DLMan uses a token bucket algorithm for smooth speed limiting. Tokens refill at the rate limit speed, and each segment must acquire tokens before downloading more data.

1

Per-download

Highest priority — overrides queue and global limits

2

Per-queue

Applied to all downloads in the queue

3

Global

App-wide limit across all downloads

Queue Scheduler

The QueueScheduler runs as a background task, checking schedules every 30 seconds. It automatically starts and stops queues based on configured times and active days.

Schedule Check (every 30s)
For each queue with schedule.enabled = true:
·→ Is current day in schedule.days? If not, skip.
·→ Is current time ≥ start_time? Start queue.
·→ Is current time ≥ stop_time? Stop queue.
·→ Calculate countdown to next scheduled start.

Retry Policy

SettingValue
Max retries5
Initial delay1s
BackoffExponential (1s, 2s, 4s, 8s, 16s)
Jitter±10%

Error Handling

All operations return Result<T, DlmanError>. Errors are logged with context, saved to the download record, surfaced to the UI, and retried when possible.

Network
IO
NotFound
InvalidUrl
ResumeNotSupported
Database

Post-Download Actions

When a queue completes all downloads, these actions can trigger:

Notify

Send OS notification

Sleep

Put computer to sleep

Shutdown

Shutdown the computer

Hibernate

Hibernate the computer

RunCommand

Execute a custom shell command