feat(seeding): wire seed ratio/time lifecycle into the torrent daemon

SeedRatio/SeedTime were declared on TorrentConfig but never consumed, and
SeedEnabled was hardcoded false in both constructors — the daemon never
seeded, and if forced it seeded forever.

- config: [downloads] seed_enabled/seed_ratio/seed_time (opt-in, off by default)
- daemon: parse seed_time + wire all three; startup log per target shape
- engine: seedTargetReached() (pure) + seedAndDrop() background monitor on a
  downloader-scoped seedCtx (not the task ctx, which dies when Download returns);
  drops the torrent on ratio (uploaded/size) OR time, whichever first; no target
  = seed until shutdown. Configurable check interval (tests lower it).
- fix: cleanup() now always drops — previously leaked the handle on error paths
  when seeding was enabled.
- refactor: dropTracked() helper shared by cleanup + post-seeding drop.

Tests: TestSeedTargetReached (9 cases) + ctx/no-target branches + loopback
swarm smoke (-tags smoke). Roadmap hueco closed.
This commit is contained in:
Deivid Soto 2026-06-01 10:30:39 +02:00
parent 665ec0a34f
commit 132c88b3f0
8 changed files with 459 additions and 34 deletions

View file

@ -113,7 +113,9 @@ func runDownloadWithDeps(input, method string, deps downloadDeps) error {
MetadataTimeout: 15 * time.Minute,
StallTimeout: 10 * time.Minute,
MaxTimeout: 0, // unlimited
SeedEnabled: false,
// One-shot foreground download: leech then exit. Seeding only makes sense
// for the always-on daemon (see DownloadConfig.SeedEnabled).
SeedEnabled: false,
})
if err != nil {
return fmt.Errorf("create downloader: %w", err)