7
7
8
8
BitTorrent client and library in Go. Running in production at [ put.io] [ putio-link ] since 2019. Processing thousands of torrents every day.
9
9
10
+ ** High-performance BitTorrent client and library in Go.** Running in production at [ put.io] [ putio-link ] since 2019, processing thousands of torrents daily with minimal system resources.
11
+
10
12
[ ![ GoDoc] ( https://godoc.org/github.com/cenkalti/rain?status.svg )] ( https://pkg.go.dev/github.com/cenkalti/rain/torrent?tab=doc )
11
13
[ ![ GitHub Release] ( https://img.shields.io/github/release/cenkalti/rain.svg )] ( https://github.com/cenkalti/rain/releases )
12
14
[ ![ Coverage Status] ( https://coveralls.io/repos/github/cenkalti/rain/badge.svg )] ( https://coveralls.io/github/cenkalti/rain )
13
15
[ ![ Go Report Card] ( https://goreportcard.com/badge/github.com/cenkalti/rain )] ( https://goreportcard.com/report/github.com/cenkalti/rain )
14
16
15
17
Features
16
18
--------
19
+
20
+ ### Protocol Support
17
21
- [ Core protocol] ( http://bittorrent.org/beps/bep_0003.html )
18
22
- [ Fast extension] ( http://bittorrent.org/beps/bep_0006.html )
19
23
- [ Magnet links] ( http://bittorrent.org/beps/bep_0009.html )
@@ -23,11 +27,14 @@ Features
23
27
- [ PEX] ( http://bittorrent.org/beps/bep_0011.html )
24
28
- [ Message stream encryption] ( http://wiki.vuze.com/w/Message_Stream_Encryption )
25
29
- [ WebSeed] ( http://bittorrent.org/beps/bep_0019.html )
26
- - Fast resuming
27
- - IP blocklist
28
- - RPC server & client
29
- - Console UI
30
- - Tool for creating & reading .torrent files
30
+
31
+ ### Client Features
32
+ - Fast resuming with BoltDB persistence
33
+ - IP blocklist support
34
+ - JSON-RPC 2.0 server & client
35
+ - Interactive console UI
36
+ - Tools for creating & reading .torrent files
37
+ - Resource management (connections, memory, file handles)
31
38
32
39
Screenshot
33
40
----------
@@ -36,36 +43,82 @@ Screenshot
36
43
Installing
37
44
----------
38
45
39
- If you are on MacOS you can install from [ brew ] ( https://brew.sh/ ) :
46
+ ### macOS
40
47
``` sh
41
48
brew install cenkalti/rain/rain
42
49
```
43
50
44
- Otherwise, get the latest binary from [ releases page] ( https://github.com/cenkalti/rain/releases ) .
51
+ ### Other Platforms
52
+ Download the latest binary from the [ releases page] ( https://github.com/cenkalti/rain/releases ) .
53
+
54
+ ### From Source
55
+ ``` sh
56
+ go install github.com/cenkalti/rain/v2@latest
57
+ ```
58
+
59
+ Quick Start
60
+ -----------
61
+
62
+ Rain operates as a client-server application with a single binary.
63
+
64
+ ### 1. Start the Server
65
+ ``` sh
66
+ # Start Rain server (creates default config if none exists)
67
+ rain server
68
+ ```
69
+
70
+ ### 2. Add Your First Torrent
71
+ ``` sh
72
+ # Add a magnet link
73
+ rain client add " magnet:?xt=urn:btih:..."
74
+
75
+ # Or add a torrent file
76
+ rain client add /path/to/file.torrent
77
+
78
+ # Or add torrent from URL
79
+ rain client add " https://example.com/file.torrent"
80
+ ```
81
+
82
+ ### 3. Monitor Progress
83
+ ``` sh
84
+ # List all torrents
85
+ rain client list
86
+
87
+ # Watch progress in console UI
88
+ rain client console
89
+ ```
90
+
91
+ ### 4. Control Downloads
92
+ ``` sh
93
+ # Pause a torrent
94
+ rain client stop < torrent-id>
95
+
96
+ # Resume a torrent
97
+ rain client start < torrent-id>
45
98
46
- Usage as torrent client
47
- -----------------------
99
+ # Remove completed torrent
100
+ rain client remove < torrent-id>
101
+ ```
48
102
49
- Rain is distributed as single binary file.
50
- The main use case is running ` rain server ` command and operating the server with ` rain client <subcommand> ` commands.
51
- Server consists of a BitTorrent client and a RPC server.
52
- ` rain client ` is used to give commands to the server.
53
- There is also ` rain client console ` command which opens up a text based UI that you can view and manage the torrents on the server.
54
- Run ` rain help ` to see other commands.
103
+ Use ` rain help ` or ` rain help <command> ` for detailed information.
55
104
56
105
Usage as library
57
106
----------------
58
107
108
+ Rain can be embedded in Go applications as a powerful BitTorrent library.
109
+
59
110
``` go
60
111
import " github.com/cenkalti/rain/v2/torrent"
61
112
62
- // Create a session
113
+ // Create session with default config
63
114
ses , _ := torrent.NewSession (torrent.DefaultConfig )
115
+ defer ses.Close ()
64
116
65
- // Add magnet link
117
+ // Add a magnet link
118
+ magnetLink := " magnet:?xt=urn:btih:..."
66
119
tor , _ := ses.AddURI (magnetLink, nil )
67
120
68
- // Watch the progress
121
+ // Monitor download progress
69
122
for range time.Tick (time.Second ) {
70
123
s := tor.Stats ()
71
124
log.Printf (" Status: %s , Downloaded: %d , Peers: %d " , s.Status .String (), s.Bytes .Completed , s.Peers .Total )
@@ -79,17 +132,72 @@ See [package documentation](https://pkg.go.dev/github.com/cenkalti/rain/torrent?
79
132
Configuration
80
133
-------------
81
134
82
- All values have sensible defaults, so you can run Rain with an empty config but if you want to customize it's behavior,
83
- you can pass a YAML config with ` -config ` flag. Config keys must be in lowercase.
84
- See the description of values in here: [ config.go] ( https://github.com/cenkalti/rain/blob/master/torrent/config.go )
135
+ Rain works out of the box with sensible defaults, but can be customized with a YAML configuration file.
136
+
137
+ ### Basic Configuration
138
+
139
+ ** Default config location:** ` ~/rain/config.yaml ` (created automatically if missing)
140
+
141
+ ** Custom config:**
142
+ ``` sh
143
+ rain server -config /path/to/config.yaml
144
+ ```
145
+
146
+ ### Complete Reference
147
+
148
+ For all available configuration options, see [ config.go] ( https://github.com/cenkalti/rain/blob/master/torrent/config.go ) .
149
+
150
+ ** Note:** Configuration keys use dash-separated format (e.g., ` port-begin ` , not ` portbegin ` ) starting from v2.
151
+
152
+ Architecture
153
+ ------------
154
+
155
+ Rain's architecture is designed specifically for high-performance server environments, with several unique characteristics:
156
+
157
+ ### Unique Design Decisions
158
+
159
+ ** Separate Port Per Torrent:** Unlike other BitTorrent clients, Rain allocates a separate peer port for each torrent. This enables:
160
+ - Multiple downloads of the same torrent for different accounts on private trackers
161
+ - Accurate ratio tracking per account
162
+ - Better isolation between torrents
163
+
164
+ ** Server-First Design:** Rain prioritizes server-side performance over desktop features:
165
+ - Optimized for hundreds of concurrent torrents
166
+ - Minimal system resource usage
167
+ - Production-ready stability (running at put.io since 2019)
168
+ - JSON-RPC API for remote management
169
+
170
+ ### Project Structure
171
+ ```
172
+ rain/
173
+ ├── torrent/ # Core BitTorrent session and torrent logic
174
+ ├── rainrpc/ # Shared types for JSON-RPC 2.0 API
175
+ ├── internal/ # Internal packages (networking, protocol, storage, etc.)
176
+ └── main.go # Entry point
177
+ ```
178
+
179
+ ### Component Architecture
180
+
181
+ Rain follows a layered architecture with clear separation of concerns:
182
+
183
+ ** Core Layer:**
184
+ - ` torrent/session.go ` - Main orchestrator managing torrents, DHT, and shared resources
185
+ - ` torrent/torrent.go ` - Individual torrent lifecycle management
186
+
187
+ ** Protocol Layer:**
188
+ - BitTorrent protocol implementation (` internal/peerprotocol/ ` )
189
+ - Tracker communication (` internal/tracker/ ` , ` internal/announcer/ ` )
190
+ - DHT and PEX support (` internal/dht/ ` , ` internal/pex/ ` )
85
191
86
- Difference from other clients
87
- -----------------------------
192
+ ** Network Layer:**
193
+ - Connection management (` internal/peer/ ` , ` internal/peerconn/ ` )
194
+ - Message Stream Encryption (` internal/mse/ ` )
195
+ - Resource limiting (` internal/resourcemanager/ ` )
88
196
89
- Rain is the main BitTorrent client used at [ put.io ] [ putio-link ] .
90
- It is designed to handle hundreds of torrents while using low system resources.
91
- One notable difference from other clients is that Rain uses a separate peer port for each torrent.
92
- This allows Rain to download same torrent for multiple accounts in same private tracker and keep reporting their ratio correctly.
197
+ ** Storage Layer: **
198
+ - Piece management ( ` internal/piece/ ` , ` internal/piececache/ ` )
199
+ - File I/O optimization ( ` internal/storage/ ` )
200
+ - Resume data persistence with BoltDB
93
201
94
202
Missing features
95
203
----------------
0 commit comments