0
0
Fork 0
mirror of https://codeberg.org/liliumstar/torrentz2.git synced 2026-04-21 07:20:26 +00:00
Torrent file creator and editor with v1/v2/hybrid support.
  • Rust 99.6%
  • Shell 0.4%
Find a file
2025-04-11 20:36:37 -07:00
.cargo Add option to use openssl over native rust hashing 2025-03-30 11:17:38 -07:00
build Use LFS for builds 2025-04-10 17:33:12 -07:00
config Implement edit functionality 2025-03-29 15:22:04 -07:00
examples Add build scripts, lint with clippy 2025-04-10 17:20:23 -07:00
scripts Use LFS for builds 2025-04-10 17:33:12 -07:00
src Fix Windows bug, add Windows cross-compilation directions 2025-04-10 22:28:09 -07:00
.gitattributes Use LFS for builds 2025-04-10 17:33:12 -07:00
.gitignore Add optional deps for GPU support 2025-03-23 14:12:16 -07:00
.rusty-hook.toml Add build scripts, lint with clippy 2025-04-10 17:20:23 -07:00
ARGS.md Add clap_stdin support 2025-04-07 12:17:09 -07:00
BEPs.md Add BEP support document 2025-04-11 20:36:37 -07:00
Cargo.lock Fix Windows bug, add Windows cross-compilation directions 2025-04-10 22:28:09 -07:00
Cargo.toml Fix Windows bug, add Windows cross-compilation directions 2025-04-10 22:28:09 -07:00
LICENSE Update license 2025-02-27 18:19:24 -08:00
README.md Add BEP support document 2025-04-11 20:36:37 -07:00

torrentz2

Torrent file creator and editor with v1/v2/hybrid support.

Description

torrentz2 (tz2) is an advanced, experimental utility for working with .torrent metadata files. It supports a wide array of BEPs and v1/v2/hybrid formats.

See here for details on BEP support.

Features

  • Create, Edit, or Verify torrent files
  • Convenient config file to define default options and trackers
  • Multithreaded hashing
  • Include/exclude files based on globs and if they are symlinks
  • Create a single torrent file from disparate input paths, provided they share a common root
  • Intelligent automatic piece size selection with support for up to 64 MiB
  • Digitally sign/verify embedded signatures with standard X.509 certificates utilizing RSA or EC signatures
    • Includes utility command to generate an appropriate root CA and leaf cert
  • Optionally include md5 or sha1 sums per-file with v1 torrents

Optional Features

  • CPU hardware accelerated hashing (on by default)
  • GPU accelerated hashing (coming soon, maybe hopefully)
  • Compile to a static binary

Pre-Built Binaries

If you do not want to build tz2 yourself, there are precompiled binaries available:

  • ./build/tz2_x64_openssl_gnu: recommended and fastest, requires openssl installed
  • ./build/tz2_x64_musl: slower static build, no openssl

Building

Prerequisites

  1. You will want rustup installed, and to add ~/.cargo/bin to your path. Depending on your installation method, you may need to initialize it as well. tz2 is currently tracking stable.
  2. Add targets: rustup target add x86_64-unknown-linux-gnu x86_64-unknown-linux-musl.
  3. Either openssl (for default build) or a C compiler.

Compiling

  1. Clone this repo: git clone https://codeberg.org/liliumstar/torrentz2.git && cd torrentz2
  2. Build and install with default configuration: cargo install --release

This will compile a executable linked to glibc and openssl, which has proven fasted in testing.

If you would prefer a static binary, you can use something like this: cargo build --release --target x86_64-unknown-linux-musl --features static.

Alternately, you can choose to not include openssl with: cargo build --release --target x86_64-unknown-linux-musl --no-default-features.

Feature Flags

default: ext

ext: Enable openssl for hashing instead of pure rust implementation, faster

static: If ext is enabled, compile and embed the openssl library into the binary, a bit slower versus dynamic linking in testing

gpu: Not currently implemented

Windows

It is possible to cross-compile for Windows with cargo build --release --target x86_64-pc-windows-gnu --features static. This requires the MinGW64 toolchain. This configuration works (in limited testing).

Configuration

The configuration file is in yaml format. There is an example file to work off of in ./config/example_config.yaml. Alternately you can use tz2 gen-config to create a default configuration in a suitable location.

The config file is loaded from locations in this order, where BINDIR is the location of the tz2 executable:

  1. $BINDIR/config/config.yaml
  2. $XDG_CONFIG_HOME/tz2/config.yaml
  3. $HOME/.config/tz2/config.yaml

All fields in the config are required, and correspond to associated CLI flags. The only nullable field is a certificate key, which indicates you are not in possession of the associated private key.

The comment and created_by default values of "default" are special, they will be replaced by tz2 specific values.

Usage

The binary is called tz2 by default, and should be on your path if you used cargo install. You can get help with tz2 --help.

Arguments

See here for details

Arguments specified on the CLI will override their corresponding config file counterparts.

Example Output

[*] torrentz2 0.1.0
[*] Found 1 groups of torrents to hash
[*] Beginning torrent hashing for /media/cache/temp...
 |  Num Files : 6
 |  Total Size: 6.0 GiB
 |  Piece Size: 4.0 MiB
 |  Num Pieces: 1535
 |  Version: Hybrid
[*] Finished hashing torrent and processing pieces in 00:00:02
[*] Operation complete!
 |  Output Directory: /media/some/place

Included in the ./examples directory are signed sample torrent files in each format.

Status

tz2 currently supports all of the intended features aside from GPU hashing. However, this project should be considered unstable. More features may be added, and the API/CLI may evolve over time.

ToDo

  • Add output to another serialization format
  • Test more signing/verifying types
  • Add check to ensure provided private key and cert match
  • Reimplement certificate date check
  • Investigate P521 implementation
  • Implement GPU hashing
  • Clean up CLI args and config file
  • Further testing

Supported Signature Methods

  • SHA256/512 with RSA Encryption
  • SHA-512 with ed25519
  • ECDSA with NIST P-256/P-384/P-521, secp256k1

More can be added upon request. Ideally they would have trusted pure rust implementations available.

I'm not entirely sure P-521 is implemented correctly. Please raise an issue if you find that is the case.

Contributions

Contributions are welcome. Open a PR with one, or raise an issue if you'd like to discuss a potential change.

License

This project is licensed under the GPL-3, you can find the full text here or in the license file.