{"id":21665848,"url":"https://github.com/ivanbgd/codecrafters-bittorrent-rust","last_synced_at":"2025-03-20T06:28:29.559Z","repository":{"id":263392428,"uuid":"871651042","full_name":"ivanbgd/codecrafters-bittorrent-rust","owner":"ivanbgd","description":"A BitTorrent client (from a Codecrafters challenge)","archived":false,"fork":false,"pushed_at":"2024-12-04T11:03:58.000Z","size":307,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-25T08:09:22.679Z","etag":null,"topics":["bittorrent","codecrafters","codecrafters-bittorrent","p2p","peer-to-peer","peer2peer","rust","rust-lang"],"latest_commit_sha":null,"homepage":"https://app.codecrafters.io/courses/bittorrent/overview","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ivanbgd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-12T14:58:04.000Z","updated_at":"2024-12-04T11:04:02.000Z","dependencies_parsed_at":"2024-12-02T22:20:59.369Z","dependency_job_id":"cf35afb6-faf2-4d56-ac65-007de86ef8a9","html_url":"https://github.com/ivanbgd/codecrafters-bittorrent-rust","commit_stats":null,"previous_names":["ivanbgd/codecrafters-bittorrent-rust"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanbgd%2Fcodecrafters-bittorrent-rust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanbgd%2Fcodecrafters-bittorrent-rust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanbgd%2Fcodecrafters-bittorrent-rust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanbgd%2Fcodecrafters-bittorrent-rust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ivanbgd","download_url":"https://codeload.github.com/ivanbgd/codecrafters-bittorrent-rust/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244563562,"owners_count":20472880,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bittorrent","codecrafters","codecrafters-bittorrent","p2p","peer-to-peer","peer2peer","rust","rust-lang"],"created_at":"2024-11-25T11:18:05.835Z","updated_at":"2025-03-20T06:28:29.536Z","avatar_url":"https://github.com/ivanbgd.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![progress-banner](https://backend.codecrafters.io/progress/bittorrent/ca143921-9bbb-45ad-81e4-25927be2c7a8)](https://app.codecrafters.io/users/ivanbgd?r=2qF)\n\nThis is a starting point for Rust solutions to the\n[\"Build Your Own BitTorrent\" Challenge](https://app.codecrafters.io/courses/bittorrent/overview).\n\nIn this challenge, you’ll build a BitTorrent client that's capable of parsing a\n.torrent file and downloading a file from a peer. Along the way, we’ll learn\nabout how torrent files are structured, HTTP trackers, BitTorrent’s Peer\nProtocol, pipelining and more.\n\n**Note**: If you're viewing this repo on GitHub, head over to\n[codecrafters.io](https://codecrafters.io) to try the challenge.\n\n# Passing the first stage\n\nThe entry point for your BitTorrent implementation is in `src/main.rs`. Study\nand uncomment the relevant code, and push your changes to pass the first stage:\n\n```sh\ngit commit -am \"pass 1st stage\" # any msg\ngit push origin master\n```\n\nTime to move on to the next stage!\n\n# Stage 2 \u0026 beyond\n\nNote: This section is for stages 2 and beyond.\n\n1. Ensure you have `cargo (1.70)` installed locally\n2. Run `./your_bittorrent.sh` to run your program, which is implemented in\n   `src/main.rs`. This command compiles your Rust project, so it might be slow\n   the first time you run it. Subsequent runs will be fast.\n3. Commit your changes and run `git push origin master` to submit your solution\n   to CodeCrafters. Test output will be streamed to your terminal.\n\n# Running the Program\n\nTorrent files and magnet links are supported for downloading a single file.\n\n- `./your_bittorrent.sh decode \u003cencoded_value\u003e`\n- `./your_bittorrent.sh info \u003cpath_to_torrent_file\u003e`\n- `./your_bittorrent.sh peers \u003cpath_to_torrent_file\u003e`\n- `./your_bittorrent.sh handshake \u003cpath_to_torrent_file\u003e \u003cpeer_ip\u003e:\u003cpeer_port\u003e`\n    - Peer's IP address and port can be obtained by running the `peers` command and picking any peer from the list.\n- `./your_bittorrent.sh download_piece -o \u003cpath_to_output_file\u003e \u003cpath_to_torrent_file\u003e \u003cpiece_index\u003e`\n- `./your_bittorrent.sh download -o \u003cpath_to_output_file\u003e \u003cpath_to_torrent_file\u003e`\n- `./your_bittorrent.sh magnet_parse \"\u003cmagnet-link\u003e\"`\n- `./your_bittorrent.sh magnet_handshake \"\u003cmagnet-link\u003e\"`\n- `./your_bittorrent.sh magnet_info \"\u003cmagnet-link\u003e\"`\n- `./your_bittorrent.sh magnet_download_piece -o \u003cpath_to_output_file\u003e \"\u003cmagnet-link\u003e\" \u003cpiece_index\u003e`\n- `./your_bittorrent.sh magnet_download -o \u003cpath_to_output_file\u003e \"\u003cmagnet-link\u003e\"`\n\nWe can alternatively run it by `cargo run --release`, instead of `./your_bittorrent.sh`.\n\nTo enable the provided logging facility, first set the logging level by setting the `RUST_LOG` environment variable.  \nTo set it for the entire terminal session, execute `export RUST_LOG=debug`, for example, first.  \nOr, prepend the run command with a desired log level; for example:  \n`RUST_LOG=debug ./your_bittorrent.sh download -o \u003cpath_to_output_file\u003e \u003cpath_to_torrent_file\u003e`  \nChoose between:  \n`RUST_LOG=[trace | debug | info | warn]`  \n*Note*: Logging is fully enabled only for the `download_piece` and `download` commands. Some commands\ndon't have any log output.\n\nSample torrent files are provided in the root of the repository,\nas well as in the [test_samples](./test_samples) subdirectory.\n\n*Note:* The sample torrent files can be used for testing the code, and in this case they work, but these are **NOT**\nreal-world torrent files!\n\n# Limitations\n\nThis challenge is **NOT** production-ready!\n\nFirst, it only supports single-file torrents, but even they are not fully, i.e., properly supported,\nso even they don't work.\n\nSecondly, multi-file torrents are not supported at all. This solution has placeholders to support the functionality,\nbut it hasn't been implemented.\n\nWe only support compact mode, but that is the recommended mode in practice anyway, so it should be enough.  \nhttps://www.bittorrent.org/beps/bep_0023.html  \nThe assignment itself only supports the compact mode.\n\n# Improvements Over the Requirements\n\n- Optional application configuration, through the optional [config.json](config.json) file.\n- Logging.\n- Timing of the whole-file download.\n- We check the Bitfield message payload to see whether a peer has the piece that we need.  \n  The challenge doesn't require this as all their peers have all the required pieces during testing,\n  but in real life this is practically required.\n- We pipeline requests to a single peer for increased download speed.  \n  This was suggested as optional but is practically required because of the test timeout.  \n  This increases the download speed from a single peer significantly.\n- We also added working with multiple peers at once, on top of pipelining requests to a single peer.  \n  This was also suggested as optional, but not required.  \n  Still, this is something that is required in case of real-life torrents.\n  Namely, we cannot rely on a single peer having all pieces in real life. In the challenge's test suite, they do.  \n  We try to find a peer that has a piece, for every piece.\n\n# Possible Improvements\n\n- Make the application work for real-life single-file torrents.\n- Make the application work for real-life multiple-file torrents.\n- Send keep-alive messages to connected peers.\n- Discover new peers at regular time intervals, but this is not required in the challenge.\n- Whenever a piece is successfully downloaded and written to file, store the necessary information (work parameters)\n  in a file that can be used to resume download of the file when the application is restarted, if the file hasn't\n  been downloaded fully.\n- The [BitTorrent Economics Paper](http://bittorrent.org/bittorrentecon.pdf) (PDF) has more ideas,\n  but none of them are required in this challenge.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivanbgd%2Fcodecrafters-bittorrent-rust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fivanbgd%2Fcodecrafters-bittorrent-rust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivanbgd%2Fcodecrafters-bittorrent-rust/lists"}