/* session.h — minimal torrent registry for the control plane. * * The control plane (RPC / plugins / scripts) refers to torrents by a stable * uint64 id; the engine refers to them by their storage. This registry is the * single map between the two, so a script-driven command like move_file can be * resolved to a concrete naut_storage and acted on. * * Threading: the registry is *owner-thread confined*. In nautd every call * (add/remove/move, all from RPC handlers and the move-drain) runs on the * daemon's main thread, so no internal locking is needed. Commands originating * on other threads (e.g. a script's naut.move_file) must be marshalled onto the * owner thread first — which is exactly what nautd's bounded move queue does. */ #ifndef NAUT_SESSION_H #define NAUT_SESSION_H #include "naut/common.h" #include "naut/storage.h" typedef struct naut_session naut_session; naut_session *naut_session_create(void); /* Closes every storage still registered. */ void naut_session_destroy(naut_session *s); /* Register `storage` under `id`; the session takes ownership and will close it * on remove/destroy. Fails with NAUT_ERR_INVAL if `id` is already present. */ naut_err naut_session_add(naut_session *s, uint64_t id, naut_storage *storage); /* Close and forget the torrent. NAUT_ERR_NOTFOUND if unknown. */ naut_err naut_session_remove(naut_session *s, uint64_t id); bool naut_session_has(const naut_session *s, uint64_t id); size_t naut_session_count(const naut_session *s); /* Resolve `id` and relocate one completed file to `dest` (the storage half of * "move files as they finish"). NAUT_ERR_NOTFOUND if the torrent is unknown. */ naut_err naut_session_move_file(naut_session *s, uint64_t id, uint32_t file_index, const char *dest); #endif /* NAUT_SESSION_H */