A sans-io proof-of-concept implementation of the torrent protocol, implemented in Rust as a programming challenge for recruitment purposes.
$ cargo run -- --help Usage: torrent-poc.exe <COMMAND> Commands: leech Connect to a known peer and start downloading a torrent seed Listen for incoming connections and start seeding a torrent help Print this message or the help of the given subcommand(s) Options: -h, --help Print help -V, --version Print version
-
Start a torrent "seeder" by running
cargo run -- seed --info-hash <info-hash> --port <port>
.It will listen on all interfaces by default, but you can specify a specific IP address with
--ip <ip>
. -
Start a torrent "leecher" by running
cargo run -- leech --info-hash <info-hash> --port <port> --ip <ip>
.The port and info hash must match the ones used by the seeder.
-
You should now see something similar to this:
$ cargo run -- seed --info-hash 018e50b58106b84a42c223ccf0494334f8d55958 --port 12345 2024-06-05T12:27:22.220504Z INFO torrent_poc: My peer ID: -Rp1121-THMZfvNhcurL 2024-06-05T12:27:22.220911Z INFO torrent_poc: Listening on 0.0.0.0:12345 2024-06-05T12:27:22.220982Z INFO torrent_poc: Info hash: b6ae8e98e360a3d5d547dd43d42548ee786845ff 2024-06-05T12:27:25.548916Z INFO torrent_poc::torrent::connection_actor: Connection established with peer -Rp1121-8gJCKF636JRe 2024-06-05T12:27:25.548922Z INFO torrent_poc::torrent::torrent_actor: TorrentActor added connection to peer -Rp1121-8gJCKF636JRe # 10 seconds later 2024-06-05T12:27:35.613601Z WARN torrent_poc::connections::std_io_connection: error reading from the connection: Os { code: 10054, kind: ConnectionReset, message: "An existing connection was forcibly closed by the remote host." } 2024-06-05T12:27:35.639136Z INFO torrent_poc::torrent::torrent_actor: TorrentActor removed connection to peer -Rp1121-8gJCKF636JRe
$ cargo run -- leech --info-hash 018e50b58106b84a42c223ccf0494334f8d55958 --port 12345 --ip 127.0.0.1 2024-06-05T12:27:25.542483Z INFO torrent_poc: My peer ID: -Rp1121-8gJCKF636JRe 2024-06-05T12:27:25.543401Z INFO torrent_poc: Connecting to peer at 127.0.0.1:12345 2024-06-05T12:27:25.543532Z INFO torrent_poc: Info hash: b6ae8e98e360a3d5d547dd43d42548ee786845ff 2024-06-05T12:27:25.549016Z INFO torrent_poc::torrent::connection_actor: Connection established with peer -Rp1121-THMZfvNhcurL 2024-06-05T12:27:25.549031Z INFO torrent_poc::torrent::torrent_actor: TorrentActor added connection to peer -Rp1121-THMZfvNhcurL # 10 seconds later 2024-06-05T12:27:35.613681Z WARN torrent_poc::connections::std_io_connection: error reading from the connection: Os { code: 10053, kind: ConnectionAborted, message: "An established connection was aborted by the software in your host machine." }