Update docs, cleanup for 4.0.0 release
This commit is contained in:
parent
3160f06f65
commit
006d83d6a7
29 changed files with 206 additions and 116 deletions
|
|
@ -2,6 +2,7 @@ use std::{cmp::Ordering, str::FromStr};
|
|||
|
||||
use serde::{Deserialize, Deserializer, Serialize};
|
||||
|
||||
/// A 20-byte hash used throughout librqbit, for torrent info hashes, peer ids etc.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Default)]
|
||||
pub struct Id20(pub [u8; 20]);
|
||||
|
||||
|
|
|
|||
|
|
@ -4,12 +4,14 @@ use anyhow::Context;
|
|||
|
||||
use crate::id20::Id20;
|
||||
|
||||
/// A parsed magnet link.
|
||||
pub struct Magnet {
|
||||
pub info_hash: Id20,
|
||||
pub trackers: Vec<String>,
|
||||
}
|
||||
|
||||
impl Magnet {
|
||||
/// Parse a magnet link.
|
||||
pub fn parse(url: &str) -> anyhow::Result<Magnet> {
|
||||
let url = url::Url::parse(url).context("magnet link must be a valid URL")?;
|
||||
if url.scheme() != "magnet" {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use tracing::{error, trace, Instrument};
|
||||
|
||||
/// Spawns a future with tracing instrumentation.
|
||||
pub fn spawn(
|
||||
span: tracing::Span,
|
||||
fut: impl std::future::Future<Output = anyhow::Result<()>> + Send + 'static,
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ struct ProgressSnapshot {
|
|||
instant: Instant,
|
||||
}
|
||||
|
||||
/// Estimates download speed in a sliding time window.
|
||||
pub struct SpeedEstimator {
|
||||
latest_per_second_snapshots: Mutex<VecDeque<ProgressSnapshot>>,
|
||||
download_bytes_per_second: AtomicU64,
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ use crate::id20::Id20;
|
|||
pub type TorrentMetaV1Borrowed<'a> = TorrentMetaV1<ByteBuf<'a>>;
|
||||
pub type TorrentMetaV1Owned = TorrentMetaV1<ByteString>;
|
||||
|
||||
/// Parse torrent metainfo from bytes.
|
||||
pub fn torrent_from_bytes<'de, ByteBuf: Deserialize<'de>>(
|
||||
buf: &'de [u8],
|
||||
) -> anyhow::Result<TorrentMetaV1<ByteBuf>> {
|
||||
|
|
@ -25,6 +26,7 @@ pub fn torrent_from_bytes<'de, ByteBuf: Deserialize<'de>>(
|
|||
Ok(t)
|
||||
}
|
||||
|
||||
/// A parsed .torrent file.
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
pub struct TorrentMetaV1<BufType> {
|
||||
pub announce: BufType,
|
||||
|
|
@ -51,6 +53,7 @@ impl<BufType> TorrentMetaV1<BufType> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Main torrent information, shared by .torrent files and magnet link contents.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||
pub struct TorrentMetaV1Info<BufType> {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue