pub struct LpdManager {
pub active_hashes: Arc<RwLock<HashSet<String>>>,
/* private fields */
}Expand description
Manages LPD operations for all active torrents.
Maintains a registry of known peers discovered via LPD, handles periodic announcements for active downloads, and coordinates with the download engine.
Fields§
§active_hashes: Arc<RwLock<HashSet<String>>>Track which info hashes we’re currently announcing
Implementations§
Source§impl LpdManager
impl LpdManager
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new LpdManager
Initializes the UDP socket, joins multicast group, and sets up internal state tracking.
Sourcepub fn with_interval(announce_interval_secs: u64) -> Result<Self, String>
pub fn with_interval(announce_interval_secs: u64) -> Result<Self, String>
Create LpdManager with custom configuration
Sourcepub async fn register_torrent(&self, info_hash: &str) -> Result<(), String>
pub async fn register_torrent(&self, info_hash: &str) -> Result<(), String>
Register a torrent for LPD announcements
Adds the info_hash to the active set so it gets periodically announced.
Sourcepub async fn unregister_torrent(&self, info_hash: &str)
pub async fn unregister_torrent(&self, info_hash: &str)
Unregister a torrent from LPD announcements
Sourcepub async fn announce_torrent(
&self,
info_hash: &str,
port: u16,
) -> Result<(), String>
pub async fn announce_torrent( &self, info_hash: &str, port: u16, ) -> Result<(), String>
Manual announce for a specific torrent
Sourcepub async fn discover_peers(
&self,
_info_hash: &str,
timeout_ms: Option<u64>,
) -> Vec<LpdPeer>
pub async fn discover_peers( &self, _info_hash: &str, timeout_ms: Option<u64>, ) -> Vec<LpdPeer>
Discover peers for a specific info_hash via LPD
Sourcepub async fn get_peers_for(&self, info_hash: &str) -> Vec<LpdPeer>
pub async fn get_peers_for(&self, info_hash: &str) -> Vec<LpdPeer>
Get all known peers for a given info_hash
Sourcepub fn start_background_announce(&mut self, port: u16) -> Option<JoinHandle<()>>
pub fn start_background_announce(&mut self, port: u16) -> Option<JoinHandle<()>>
Sourcepub fn stop_background_announce(&mut self)
pub fn stop_background_announce(&mut self)
Stop background announce task
Sourcepub async fn update_peers(&self, info_hash: &str, new_peers: Vec<LpdPeer>)
pub async fn update_peers(&self, info_hash: &str, new_peers: Vec<LpdPeer>)
Update peer registry with newly discovered peers
Sourcepub async fn cleanup_expired_peers(&self, max_age: Duration) -> usize
pub async fn cleanup_expired_peers(&self, max_age: Duration) -> usize
Clean up expired peers from all registries
Sourcepub fn is_available(&self) -> bool
pub fn is_available(&self) -> bool
Check if LPD is available and working