use std::sync::Arc;
use tracing::info;
use super::SeedInbound;
use crate::error::{Error, Result};
use crate::session::Session;
pub async fn run_seed(session: Arc<Session>) -> Result<()> {
session.announce_started().await;
let inbound = SeedInbound::new(Arc::clone(&session));
session
.client()
.register_inbound(session.info_hash(), inbound.as_handler())
.await;
let _rotator = inbound.spawn_upload_rotator();
info!(
name = %session.info().name,
hash = %session.info_hash().to_hex(),
port = session.config().listen_port,
"seeding via shared client listener"
);
while !session.is_stop_requested() {
tokio::time::sleep(std::time::Duration::from_millis(200)).await;
}
session
.client()
.unregister_inbound(session.info_hash())
.await;
session.announce_stopped().await;
Err(Error::Session("session stopped".into()))
}