All Projects → lbarasti → torrent_client

lbarasti / torrent_client

Licence: MIT License
A Bit Torrent downloader written in Crystal.

Programming Languages

crystal
512 projects
HTML
75241 projects
javascript
184084 projects - #8 most used programming language
CSS
56736 projects

Projects that are alternatives of or similar to torrent client

haze
A bittorrent client, for learning purposes
Stars: ✭ 103 (+347.83%)
Mutual labels:  bittorrent-client, bittorrent-protocol
vercors
The VerCors verification toolset for verifying parallel and concurrent software
Stars: ✭ 30 (+30.43%)
Mutual labels:  concurrency
gotopus
Gotopus is a minimalistic tool that runs arbitrary commands concurrently.
Stars: ✭ 17 (-26.09%)
Mutual labels:  concurrency
swoole-futures
⏳ Futures, Streams & Async/Await for PHP's Swoole asynchronous run-time.
Stars: ✭ 100 (+334.78%)
Mutual labels:  concurrency
gpool
gpool - a generic context-aware resizable goroutines pool to bound concurrency based on semaphore.
Stars: ✭ 84 (+265.22%)
Mutual labels:  concurrency
syncs
Concurrency and synchronization primitives
Stars: ✭ 81 (+252.17%)
Mutual labels:  concurrency
ring-election
A node js library with a distributed leader/follower algorithm ready to be used
Stars: ✭ 92 (+300%)
Mutual labels:  concurrency
async-oneshot
A fast, small, full-featured, no-std compatible oneshot channel
Stars: ✭ 55 (+139.13%)
Mutual labels:  concurrency
orc
Orc programming language implementation
Stars: ✭ 34 (+47.83%)
Mutual labels:  concurrency
context-propagation
Propagate snapshots of ThreadLocal values to another thread
Stars: ✭ 15 (-34.78%)
Mutual labels:  concurrency
chicken-gochan
Go-like Channels for Chicken Scheme
Stars: ✭ 18 (-21.74%)
Mutual labels:  concurrency
piker
#nontina, #paperhands,, #pwnzebotz, #tradezbyguille
Stars: ✭ 63 (+173.91%)
Mutual labels:  concurrency
MultiHttp
This is a high performance , very useful multi-curl tool written in php. 一个超级好用的并发CURL工具!!!(httpful,restful, concurrency)
Stars: ✭ 79 (+243.48%)
Mutual labels:  concurrency
JTK
JTK is a library designed for writing applications and libraries in C. It provides core utilities such as collections, unit testing, I/O streams, threads and much more.
Stars: ✭ 25 (+8.7%)
Mutual labels:  concurrency
trading sim
📈📆 Backtest trading strategies concurrently using historical chart data from various financial exchanges.
Stars: ✭ 21 (-8.7%)
Mutual labels:  concurrency
geeteventbus
An inprocess eventbus for highly concurrent Python applications
Stars: ✭ 17 (-26.09%)
Mutual labels:  concurrency
drone-cortexm
ARM® Cortex®-M platform crate for Drone, an Embedded Operating System.
Stars: ✭ 31 (+34.78%)
Mutual labels:  concurrency
AtomicKit
Concurrency made simple in Swift.
Stars: ✭ 88 (+282.61%)
Mutual labels:  concurrency
awaitchannel
Go-style concurrency and channels with Python 3.5 and asyncio
Stars: ✭ 21 (-8.7%)
Mutual labels:  concurrency
esm
Lightweight communicating state machine framework for embedded systems
Stars: ✭ 21 (-8.7%)
Mutual labels:  concurrency

torrent_client

A concurrent bit torrent downloader written in Crystal!

Background and design

This application is a Crystal port of Jesse Li's golang client. I recommend Jesse's companion article on how bit torrent works, which served as an inspiration for this project.

This project is meant for didactic purposes, and aims to illustrate differences in design choices and performance between Crystal and Go. The client can only download files, at the moment, but I'm planning on extending the functionality to support uploads, too.

Bit torrent downloader design: the main fiber contacts the tracker and starts a worker for each peer. Peers grab work out of a queue and send the downloaded torrent pieces to another queue. File parts are read off of the queue and stored on the file system. Once all parts are downloaded, a collector stores the consolidated file to the file system

Installation

shards install # install dependencies
crystal build -Dpreview_mt src/torrent_client.cr # compile with multi-threading support

Usage

CRYSTAL_WORKERS=<n-workers>  ./torrent_client <torrent_path> [options]

Options:

  -r, --replay                     Will replay events from the previous run. [type:Bool] [default:false]
  -o <destination_path>, --output=<destination_path>
                                    Download destination [type:String]
  -m <minimal|ncurses|web>, --mode=<minimal|ncurses|web>
                                    UI mode [type:String] [default:"minimal"]
  --help                           Show this help.

Arguments:

  01. torrent_path      The torrent file you want to download. [type:String]

Examples

CRYSTAL_WORKERS=8  ./torrent_client ./spec/testdata/debian.iso.torrent -o ./data/debian.iso
# sample output
Downloading debian-10.2.0-amd64-netinst.iso: 2 pieces of 1340 completed (8 peers)
CRYSTAL_WORKERS=8  ./torrent_client ./spec/testdata/debian.iso.torrent -m web

A web UI showing a table with peer information

CRYSTAL_WORKERS=8  ./torrent_client ./spec/testdata/debian.iso.torrent -m ncurses
# sample output
Downloading debian-10.2.0-amd64-netinst.iso: 8 pieces of 1340 completed (9 peers)
┌────────────────┬─────────────┬───────┬────────────┐
│ Peer           │ Status      │ Piece │ Downloaded │
├────────────────┼─────────────┼───────┼────────────┤
│ 163.172.10.185 │ downloading │ 15    │ 2          │
│ 163.172.43.117 │ finished    │ 7     │ 2          │
│ 185.45.195.169 │ downloading │ 10    │ 1          │
│ 176.9.45.212   │ downloading │ 12    │ 1          │
│ 78.62.187.199  │ downloading │ 4     │ 0          │
│ 185.148.3.52   │ downloading │ 13    │ 1          │
│ 84.2.20.22     │ downloading │ 14    │ 1          │
│ 91.239.69.64   │ downloading │ 9     │ 0          │
│ 203.220.135.51 │ downloading │ 11    │ 0          │
└────────────────┴─────────────┴───────┴────────────┘

Prometheus integration

A sample PromQL query and chart to report on downloaded KB/s The application exposes prometheus metrics at localhost:5000/metrics. See the crometheus documentation for further information.

Development

Replaying

To make local testing of UI and metrics collection simpler, you can start by downloading a file, e.g.

crystal src/torrent_client.cr ./spec/testdata/debian-10.2.0-amd64-netinst.iso.torrent

and then replay the download on the following runs.

crystal src/torrent_client.cr --replay

A replay does not initiate any connection to peers, but simply replays the events stored in history.log - you'll see this file popping up in the project root folder after the first download.

Running the specs

crystal specs

Contributing

  1. Fork it (https://github.com/lbarasti/torrent_client/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].