Full-featured BitTorrent client package and utilities
Matt Joiner 499b2d8725 Fix race condition in Torrent.SetDisplayName 1 day ago
.circleci Cache go master, use existing go for bootstrap, and tighten some cache keys 2 months ago
bencode vgo get -u 1 day ago
cmd Adds more flags to torrent-create 2 weeks ago
fs Switch to goimports import sorting 4 months ago
internal/testutil Switch to goimports import sorting 4 months ago
iplist Switch to goimports import sorting 4 months ago
logonce Add a prefix to logonce logger output 6 months ago
metainfo metainfo: Fix test 3 months ago
mmap_span mmap_span: Synchronize access to memory maps to avoid race when unmapping 1 year ago
mse More sortimports 8 months ago
peer_protocol bencode: Fix marshalling of []byte(nil) 3 months ago
storage Switch to goimports import sorting 4 months ago
testdata Add the fs test torrent to the repo 1 year ago
tracker tracker: Fix network error handling in unit test 2 months ago
util/dirwatch Switch to goimports import sorting 4 months ago
LICENSE Update LICENSE 1 year ago
Peer.go Move IpPort to missinggo 4 months ago
Peers.go Switch to goimports import sorting 4 months ago
README.md Update README.md 1 year ago
TODO Update TODO file 11 months ago
bad_storage.go Some test tidying and improvements 1 year ago
bep40.go Move IpPort to missinggo 4 months ago
bep40_test.go Remove unnecessary blank line 1 month ago
client.go Make use of the new context parameter in conntrack Wait 1 week ago
client_test.go Report allocs in BenchmarkAddLargeTorrent 1 month ago
closewrapper.go Add initial connection tracking 4 months ago
config.go Bump protocol strings 4 months ago
conn_stats.go Track metadata chunks read with its own Count 8 months ago
connection.go Panic on chunk write errors 1 week ago
connection_test.go Move IpPort to missinggo 4 months ago
doc.go List implemented BEPs 2 years ago
example_test.go Add File.NewReader 1 year ago
file.go Remove unused code 3 months ago
file_test.go Add File.Cancel 3 years ago
global.go Remove unused code 3 months ago
go.mod vgo get -u 1 day ago
go.sum vgo get -u 1 day ago
handshake.go sortimports 8 months ago
handshake_test.go Support AllowedFast and enable fast extension 1 year ago
issue97_test.go Switch to goimports import sorting 4 months ago
issue211_test.go Switch to goimports import sorting 4 months ago
listen.go Remove unused code 3 months ago
main_test.go Fix TestSetMaxEstablishedConn and allow it to be run with -count > 1 1 year ago
misc.go Move IpPort to missinggo 4 months ago
misc_test.go Remove excess newline from log call 9 months ago
multiless.go Move multiless to missinggo 2 weeks ago
network_test.go Use the new firewall callback support in go-libutp 7 months ago
networks.go Improve network handling and only listen networks we will use 3 months ago
peerid.go Change a bunch of Stringer and status stuff 1 year ago
peerid_test.go Change a bunch of Stringer and status stuff 1 year ago
piece.go Reduce allocations for Piece.hash 1 month ago
piecestate.go Remove vestigial comment 10 months ago
portfwd.go Law of Demeter Client.mu 7 months ago
prioritized_peers.go Add tests for prioritizedPeers 11 months ago
prioritized_peers_test.go Move IpPort to missinggo 4 months ago
protocol.go Abstract out making a cancel message 1 year ago
ratelimitreader.go Fix download rate limiter and add test 1 year ago
reader.go Fix double quoting in a log statement 2 weeks ago
reader_test.go Switch to goimports import sorting 4 months ago
rlreader_test.go sortimports 1 year ago
socket.go Improve network handling and only listen networks we will use 3 months ago
spec.go Add error return value to metainfo.MetaInfo.UnmarshalInfo 2 years ago
t.go Fix race condition in Torrent.SetDisplayName 1 day ago
torrent.go Fix race condition in Torrent.SetDisplayName 1 day ago
torrent_stats.go Merge a bunch of stuff into ConnStats and refactor connection.upload 1 year ago
torrent_test.go Switch to goimports import sorting 4 months ago
tracker_scraper.go Switch to goimports import sorting 4 months ago
utp.go Add support for disabling IPv4 and IPv4 peers 1 year ago
utp_go.go Use the new firewall callback support in go-libutp 7 months ago
utp_libutp.go Use the new firewall callback support in go-libutp 7 months ago
utp_test.go Use the new firewall callback support in go-libutp 7 months ago
worst_conns.go Calculate peer priority lazily for worse conn comparison 8 months ago

README.md

torrent

GoDoc CircleCI

This repository implements BitTorrent-related packages and command-line utilities in Go. The emphasis is on use as a library from other projects. It's been used 24/7 in production by downstream services since late 2014. The implementation was specifically created to explore Go's concurrency capabilities, and to include the ability to stream data directly from the BitTorrent network. To this end it supports seeking, readaheads and other features exposing torrents and their files with the various Go idiomatic io package interfaces. This is also demonstrated through torrentfs.

There is support for protocol encryption, DHT, PEX, uTP, and various extensions. There are several data storage backends provided: blob, file, bolt, and mmap, to name a few. You can write your own to store data for example on S3, or in a database.

Some noteworthy package dependencies that can be used for other purposes include:

Installation

Install the library package with go get github.com/anacrolix/torrent, or the provided cmds with go get github.com/anacrolix/torrent/cmd/....

Library examples

There are some small examples in the package documentation.

Downstream projects

There are several web-frontends and Android clients among the known public projects:

Help

Communication about the project is primarily through Gitter and the issue tracker.

Command packages

Here I'll describe what some of the packages in ./cmd do.

Note that the godo command which is invoked in the following examples builds and executes a Go import path, like go run. It's easier to use this convention than to spell out the install/invoke cycle for every single example.

torrent

Downloads torrents from the command-line. This first example does not use godo.

$ go get github.com/anacrolix/torrent/cmd/torrent
# Now 'torrent' should be in $GOPATH/bin, which should be in $PATH.
$ torrent 'magnet:?xt=urn:btih:KRWPCX3SJUM4IMM4YF5RPHL6ANPYTQPU'
ubuntu-14.04.2-desktop-amd64.iso [===================================================================>]  99% downloading (1.0 GB/1.0 GB)
2015/04/01 02:08:20 main.go:137: downloaded ALL the torrents
$ md5sum ubuntu-14.04.2-desktop-amd64.iso
1b305d585b1918f297164add46784116  ubuntu-14.04.2-desktop-amd64.iso
$ echo such amaze
wow

torrentfs

torrentfs mounts a FUSE filesystem at -mountDir. The contents are the torrents described by the torrent files and magnet links at -metainfoDir. Data for read requests is fetched only as required from the torrent network, and stored at -downloadDir.

$ mkdir mnt torrents
$ godo github.com/anacrolix/torrent/cmd/torrentfs -mountDir=mnt -metainfoDir=torrents &
$ cd torrents
$ wget http://releases.ubuntu.com/14.04.2/ubuntu-14.04.2-desktop-amd64.iso.torrent
$ cd ..
$ ls mnt
ubuntu-14.04.2-desktop-amd64.iso
$ pv mnt/ubuntu-14.04.2-desktop-amd64.iso | md5sum
996MB 0:04:40 [3.55MB/s] [========================================>] 100%
1b305d585b1918f297164add46784116  -

torrent-magnet

Creates a magnet link from a torrent file. Note the extracted trackers, display name, and info hash.

$ godo github.com/anacrolix/torrent/cmd/torrent-magnet < ubuntu-14.04.2-desktop-amd64.iso.torrent
magnet:?xt=urn:btih:546cf15f724d19c4319cc17b179d7e035f89c1f4&dn=ubuntu-14.04.2-desktop-amd64.iso&tr=http%3A%2F%2Ftorrent.ubuntu.com%3A6969%2Fannounce&tr=http%3A%2F%2Fipv6.torrent.ubuntu.com%3A6969%2Fannounce