Skip to content

Improve MagnetUri field types for spec compliance #168

@coderabbitai

Description

@coderabbitai

Context

As identified in PR #166 (comment: #166 (comment)), the MagnetUri struct in crates/libtortillas/src/metainfo/magnet.rs has several field type issues that should be addressed for better spec compliance:

Issues

  1. xl field type: Currently u32, but can exceed 4 GiB for large torrents. Should be u64 to prevent overflow.

  2. Multi-valued parameters: The following fields are currently Option<String> but can occur multiple times in magnet URIs:

    • as (source)
    • xs (exact_source)
    • x.pe (peer)

    These should be Vec<String> with default attribute to properly capture all values.

  3. Keywords handling: The kt field currently uses Vec<String> which works for repeated kt parameters, but doesn't split single values with "+" separators. May need a custom deserializer if that form is needed.

Suggested Changes

#[serde(rename = "xl")]
pub length: Option<u64>,  // was u32

#[serde(rename = "as", default)]
pub source: Vec<String>,  // was Option<String>

#[serde(rename = "xs", default)]
pub exact_source: Vec<String>,  // was Option<String>

#[serde(rename = "x.pe", default)]
pub peer: Vec<String>,  // was Option<String>

Requested by: @artrixdotdev
Related PR: #166

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions