/* swarm.h - reusable multi-peer download driver. * * naut_swarm is a small CLI wrapper around this API. Long-running applications * such as nautd own the worker thread and use callbacks for progress, control * commands, cancellation, and event delivery. */ #ifndef NAUT_SWARM_H #define NAUT_SWARM_H #include "naut/common.h" #include "naut/event.h" #include "naut/storage.h" typedef struct { uint64_t total_bytes; uint64_t bytes_done; uint32_t total_pieces; uint32_t pieces_done; uint32_t peers_total; /* discovered endpoints */ uint32_t peers_connecting; uint32_t peers_active; uint32_t peers_failed; double elapsed_seconds; } naut_swarm_stats; typedef void (*naut_swarm_progress_cb)(void *context, const naut_swarm_stats *stats); /* Called on the swarm owner thread. The callback may safely operate on storage, * including relocating completed files. */ typedef void (*naut_swarm_control_cb)(void *context, naut_storage *storage); typedef bool (*naut_swarm_stop_cb)(void *context); typedef struct { const char *source; /* .torrent path or magnet URI */ const char *output_dir; const char *const *peers; /* optional explicit ip:port endpoints */ size_t num_peers; uint64_t torrent_id; naut_event_bus *events; /* optional */ bool keep_alive; /* retain completed storage until stopped */ naut_swarm_progress_cb on_progress; naut_swarm_control_cb on_control; naut_swarm_stop_cb should_stop; void *context; } naut_swarm_config; /* Blocks until the torrent completes, is cancelled, or fails. */ naut_err naut_swarm_run(const naut_swarm_config *config); #endif /* NAUT_SWARM_H */