Full-featured BitTorrent client package and utilities
Matt Joiner d2400968fc Update CircleCI to use go1.12 instead of master 4 weeks ago
.circleci Update CircleCI to use go1.12 instead of master 4 weeks ago
bencode vgo get -u 2 months ago
cmd Adds more flags to torrent-create 2 months ago
fs torrentfs: fix a bug where the basenames of files are extracted incorrectly when listing the entries in a directory 4 weeks ago
internal/testutil Switch to goimports import sorting 6 months ago
iplist Switch to goimports import sorting 6 months ago
logonce Add a prefix to logonce logger output 8 months ago
metainfo metainfo: Fix test 5 months ago
mmap_span mmap_span: Synchronize access to memory maps to avoid race when unmapping 1 year ago
mse More sortimports 10 months ago
peer_protocol bencode: Fix marshalling of []byte(nil) 5 months ago
storage Switch to goimports import sorting 6 months ago
testdata Add the fs test torrent to the repo 1 year ago
tracker check if peer id exists 1 month ago
util/dirwatch Switch to goimports import sorting 6 months ago
LICENSE Update LICENSE 1 year ago
Peer.go Move IpPort to missinggo 6 months ago
Peers.go Switch to goimports import sorting 6 months ago
README.md add one downstream project (#315) 1 month ago
TODO Update TODO file 1 year ago
bad_storage.go Some test tidying and improvements 1 year ago
bep40.go Move IpPort to missinggo 6 months ago
bep40_test.go Remove unnecessary blank line 3 months ago
client.go Fix segfault on nil conntrack.EntryHandle instance when dialing 1 month ago
client_test.go Report allocs in BenchmarkAddLargeTorrent 3 months ago
closewrapper.go Add initial connection tracking 6 months ago
config.go Make the default conntracker instance unlimited for now 1 month ago
conn_stats.go Track metadata chunks read with its own Count 10 months ago
connection.go Panic on chunk write errors 2 months ago
connection_test.go Move IpPort to missinggo 6 months ago
doc.go List implemented BEPs 2 years ago
example_test.go Add File.NewReader 1 year ago
file.go Remove unused code 5 months ago
file_test.go Add File.Cancel 3 years ago
global.go Remove unused code 5 months ago
go.mod vgo get -u 2 months ago
go.sum vgo get -u 2 months ago
handshake.go sortimports 10 months ago
handshake_test.go Support AllowedFast and enable fast extension 1 year ago
issue97_test.go Switch to goimports import sorting 6 months ago
issue211_test.go Switch to goimports import sorting 6 months ago
listen.go Remove unused code 5 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 6 months ago
misc_test.go Remove excess newline from log call 11 months ago
multiless.go Move multiless to missinggo 2 months ago
network_test.go Use the new firewall callback support in go-libutp 10 months ago
networks.go Improve network handling and only listen networks we will use 5 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 3 months ago
piecestate.go Remove vestigial comment 1 year ago
portfwd.go Law of Demeter Client.mu 10 months ago
prioritized_peers.go Add tests for prioritizedPeers 1 year ago
prioritized_peers_test.go Move IpPort to missinggo 6 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 When failing to read stored data, try updating only the completion state for the failed piece 1 month ago
reader_test.go Switch to goimports import sorting 6 months ago
rlreader_test.go sortimports 1 year ago
socket.go Improve network handling and only listen networks we will use 5 months ago
spec.go Add error return value to metainfo.MetaInfo.UnmarshalInfo 2 years ago
t.go Fix race condition in Torrent.SetDisplayName 2 months ago
torrent.go When failing to read stored data, try updating only the completion state for the failed piece 1 month 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 6 months ago
tracker_scraper.go Switch to goimports import sorting 6 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 10 months ago
utp_libutp.go Use the new firewall callback support in go-libutp 10 months ago
utp_test.go Use the new firewall callback support in go-libutp 10 months ago
worst_conns.go Calculate peer priority lazily for worse conn comparison 10 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