Disable upload: do not expose in default builds, move under a feature flag.
This commit is contained in:
parent
b99a1e2b73
commit
990c5f866b
11 changed files with 45 additions and 16 deletions
|
|
@ -124,7 +124,8 @@ pub struct Session {
|
|||
|
||||
pub(crate) stats: SessionStats,
|
||||
|
||||
disable_upload: bool,
|
||||
#[cfg(feature = "disable-upload")]
|
||||
_disable_upload: bool,
|
||||
|
||||
// This is stored for all tasks to stop when session is dropped.
|
||||
_cancellation_token_drop_guard: DropGuard,
|
||||
|
|
@ -416,6 +417,7 @@ pub struct SessionOptions {
|
|||
// the root span to use. If not set will be None.
|
||||
pub root_span: Option<Span>,
|
||||
|
||||
#[cfg(feature = "disable-upload")]
|
||||
pub disable_upload: bool,
|
||||
}
|
||||
|
||||
|
|
@ -492,6 +494,7 @@ impl Session {
|
|||
let peer_id = opts.peer_id.unwrap_or_else(generate_peer_id);
|
||||
let token = opts.cancellation_token.take().unwrap_or_default();
|
||||
|
||||
#[cfg(feature = "disable-upload")]
|
||||
if opts.disable_upload {
|
||||
warn!("uploading disabled");
|
||||
}
|
||||
|
|
@ -629,7 +632,8 @@ impl Session {
|
|||
concurrent_initialize_semaphore: Arc::new(tokio::sync::Semaphore::new(
|
||||
opts.concurrent_init_limit.unwrap_or(3),
|
||||
)),
|
||||
disable_upload: opts.disable_upload,
|
||||
#[cfg(feature = "disable-upload")]
|
||||
_disable_upload: opts.disable_upload,
|
||||
});
|
||||
|
||||
if let Some(mut disk_write_rx) = disk_write_rx {
|
||||
|
|
@ -1170,7 +1174,8 @@ impl Session {
|
|||
allow_overwrite: opts.overwrite,
|
||||
output_folder,
|
||||
disk_write_queue: self.disk_write_tx.clone(),
|
||||
disable_upload: self.disable_upload,
|
||||
#[cfg(feature = "disable-upload")]
|
||||
_disable_upload: self._disable_upload,
|
||||
},
|
||||
connector: self.connector.clone(),
|
||||
session: Arc::downgrade(self),
|
||||
|
|
|
|||
|
|
@ -525,7 +525,7 @@ impl TorrentStateLive {
|
|||
let state = self;
|
||||
loop {
|
||||
let addr = peer_queue_rx.recv().await.context("torrent closed")?;
|
||||
if state.torrent.options.disable_upload && state.is_finished_and_no_active_streams() {
|
||||
if state.torrent.options.disable_upload() && state.is_finished_and_no_active_streams() {
|
||||
debug!("ignoring peer {} as we are finished", addr);
|
||||
state.peers.mark_peer_not_needed(addr);
|
||||
continue;
|
||||
|
|
@ -939,7 +939,7 @@ impl<'a> PeerConnectionHandler for &'a PeerHandler {
|
|||
}
|
||||
|
||||
fn should_send_bitfield(&self) -> bool {
|
||||
if self.state.torrent().options.disable_upload {
|
||||
if self.state.torrent().options.disable_upload() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -947,7 +947,7 @@ impl<'a> PeerConnectionHandler for &'a PeerHandler {
|
|||
}
|
||||
|
||||
fn should_transmit_have(&self, id: ValidPieceIndex) -> bool {
|
||||
if self.state.torrent.options.disable_upload {
|
||||
if self.state.torrent.options.disable_upload() {
|
||||
return false;
|
||||
}
|
||||
let have = self
|
||||
|
|
@ -1187,7 +1187,7 @@ impl PeerHandler {
|
|||
}
|
||||
|
||||
fn on_download_request(&self, request: Request) -> anyhow::Result<()> {
|
||||
if self.state.torrent().options.disable_upload {
|
||||
if self.state.torrent().options.disable_upload() {
|
||||
anyhow::bail!("upload disabled, but peer requested a piece")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -103,7 +103,20 @@ pub(crate) struct ManagedTorrentOptions {
|
|||
pub allow_overwrite: bool,
|
||||
pub output_folder: PathBuf,
|
||||
pub disk_write_queue: Option<DiskWorkQueueSender>,
|
||||
pub disable_upload: bool,
|
||||
#[cfg(feature = "disable-upload")]
|
||||
pub _disable_upload: bool,
|
||||
}
|
||||
|
||||
impl ManagedTorrentOptions {
|
||||
#[cfg(feature = "disable-upload")]
|
||||
pub fn disable_upload(&self) -> bool {
|
||||
self._disable_upload
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "disable-upload"))]
|
||||
pub const fn disable_upload(&self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/// Common information about torrent shared among all possible states.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue