Skip to content

Commit 8437a72

Browse files
committed
update readme
1 parent 7ab5558 commit 8437a72

File tree

1 file changed

+158
-48
lines changed

1 file changed

+158
-48
lines changed

README.md

Lines changed: 158 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,38 @@
11
rain
22
====
33

4-
<img src="https://github.com/cenkalti/rain/raw/master/logo.png" width="100">
4+
<img src="logo.png" width="100">
55

66
---
77

8-
BitTorrent client and library in Go. Running in production at [put.io][putio-link] since 2019. Processing thousands of torrents every day.
8+
**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.
99

10-
[![GoDoc](https://godoc.org/github.com/cenkalti/rain?status.svg)](https://pkg.go.dev/github.com/cenkalti/rain/torrent?tab=doc)
10+
[![GoDoc](https://godoc.org/github.com/cenkalti/rain?status.svg)][docs-link]
1111
[![GitHub Release](https://img.shields.io/github/release/cenkalti/rain.svg)](https://github.com/cenkalti/rain/releases)
1212
[![Coverage Status](https://coveralls.io/repos/github/cenkalti/rain/badge.svg)](https://coveralls.io/github/cenkalti/rain)
1313
[![Go Report Card](https://goreportcard.com/badge/github.com/cenkalti/rain)](https://goreportcard.com/report/github.com/cenkalti/rain)
1414

1515
Features
1616
--------
17-
- [Core protocol](http://bittorrent.org/beps/bep_0003.html)
18-
- [Fast extension](http://bittorrent.org/beps/bep_0006.html)
19-
- [Magnet links](http://bittorrent.org/beps/bep_0009.html)
20-
- [Multiple trackers](http://bittorrent.org/beps/bep_0012.html)
21-
- [UDP trackers](http://bittorrent.org/beps/bep_0015.html)
22-
- [DHT](http://bittorrent.org/beps/bep_0005.html)
23-
- [PEX](http://bittorrent.org/beps/bep_0011.html)
17+
18+
### Protocol Support
19+
- [BEP-003: Core protocol](http://bittorrent.org/beps/bep_0003.html)
20+
- [BEP-006: Fast extension](http://bittorrent.org/beps/bep_0006.html)
21+
- [BEP-009: Magnet links](http://bittorrent.org/beps/bep_0009.html)
22+
- [BEP-012: Multiple trackers](http://bittorrent.org/beps/bep_0012.html)
23+
- [BEP-015: UDP trackers](http://bittorrent.org/beps/bep_0015.html)
24+
- [BEP-005: DHT](http://bittorrent.org/beps/bep_0005.html)
25+
- [BEP-011: PEX](http://bittorrent.org/beps/bep_0011.html)
26+
- [BEP-019: WebSeed](http://bittorrent.org/beps/bep_0019.html)
2427
- [Message stream encryption](http://wiki.vuze.com/w/Message_Stream_Encryption)
25-
- [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
28+
29+
### Client Features
30+
- Fast resuming with BoltDB persistence
31+
- IP blocklist support
32+
- JSON-RPC 2.0 server & client
33+
- Interactive console UI
34+
- Tools for creating & reading .torrent files
35+
- Resource management (connections, memory, file handles)
3136

3237
Screenshot
3338
----------
@@ -36,84 +41,189 @@ Screenshot
3641
Installing
3742
----------
3843

39-
If you are on MacOS you can install from [brew](https://brew.sh/):
44+
### macOS
4045
```sh
4146
brew install cenkalti/rain/rain
4247
```
4348

44-
Otherwise, get the latest binary from [releases page](https://github.com/cenkalti/rain/releases).
49+
### Other Platforms
50+
Download the latest binary from the [releases page](https://github.com/cenkalti/rain/releases).
51+
52+
### From Source
53+
```sh
54+
go install github.com/cenkalti/rain/v2@latest
55+
```
56+
57+
Quick Start
58+
-----------
59+
60+
Rain operates as a client-server application with a single binary.
61+
62+
### 1. Start the Server
63+
```sh
64+
# Start Rain server (using default config)
65+
rain server
66+
```
67+
68+
### 2. Add Your First Torrent
69+
```sh
70+
# Add a magnet link
71+
rain client add "magnet:?xt=urn:btih:..."
72+
73+
# Or add a torrent file
74+
rain client add /path/to/file.torrent
75+
76+
# Or add torrent from URL
77+
rain client add "https://example.com/file.torrent"
78+
```
79+
80+
### 3. Monitor Progress
81+
```sh
82+
# List all torrents
83+
rain client list
84+
85+
# Get stats for a torrent
86+
rain client stats --id <torrent-id>
87+
88+
# Watch progress in console UI
89+
rain client console
90+
```
91+
92+
### 4. Control Downloads
93+
```sh
94+
# Pause a torrent
95+
rain client stop --id <torrent-id>
96+
97+
# Resume a torrent
98+
rain client start --id <torrent-id>
4599

46-
Usage as torrent client
47-
-----------------------
100+
# Remove completed torrent
101+
rain client remove --id <torrent-id>
102+
```
48103

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.
104+
Use `rain help` or `rain help <command>` for detailed information.
55105

56106
Usage as library
57107
----------------
58108

109+
Rain can be embedded in Go applications as a powerful BitTorrent library.
110+
59111
```go
60112
import "github.com/cenkalti/rain/v2/torrent"
61113

62-
// Create a session
114+
// Create session with default config
63115
ses, _ := torrent.NewSession(torrent.DefaultConfig)
116+
defer ses.Close()
64117

65-
// Add magnet link
118+
// Add a magnet link
119+
magnetLink := "magnet:?xt=urn:btih:..."
66120
tor, _ := ses.AddURI(magnetLink, nil)
67121

68-
// Watch the progress
122+
// Monitor download progress
69123
for range time.Tick(time.Second) {
70124
s := tor.Stats()
71125
log.Printf("Status: %s, Downloaded: %d, Peers: %d", s.Status.String(), s.Bytes.Completed, s.Peers.Total)
72126
}
73127
```
74128

75-
More complete example can be found under `handleDownload` function at [main.go](https://github.com/cenkalti/rain/blob/master/main.go) file.
129+
More complete example can be found under `handleDownload` function at [main.go](main.go) file.
76130

77-
See [package documentation](https://pkg.go.dev/github.com/cenkalti/rain/torrent?tab=doc) for complete API.
131+
See [package documentation][docs-link] for complete API.
78132

79133
Configuration
80134
-------------
81135

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)
136+
Rain works out of the box with sensible defaults, but can be customized with a YAML configuration file.
137+
138+
### Basic Configuration
139+
140+
**Default config location:** `~/rain/config.yaml` (defaults are used if file is missing)
141+
142+
**Custom config:**
143+
```sh
144+
rain server --config /path/to/config.yaml
145+
```
146+
147+
### Complete Reference
148+
149+
For all available configuration options, see [config.go](torrent/config.go).
150+
151+
**Note:** Configuration keys use dash-separated format (e.g., `port-begin`, not `portbegin`) starting from v2.
152+
153+
Architecture
154+
------------
155+
156+
Rain's architecture is designed specifically for high-performance server environments, with several unique characteristics:
157+
158+
### Unique Design Decisions
159+
160+
**Separate Port Per Torrent:** Unlike other BitTorrent clients, Rain allocates a separate peer port for each torrent. This enables:
161+
- Multiple downloads of the same torrent for different accounts on private trackers
162+
- Accurate ratio tracking per account
163+
- Better isolation between torrents
164+
165+
**Server-First Design:** Rain prioritizes server-side performance over desktop features:
166+
- Optimized for hundreds of concurrent torrents
167+
- Minimal system resource usage
168+
- Production-ready stability (running at put.io since 2019)
169+
- JSON-RPC API for remote management
170+
171+
### Project Structure
172+
```
173+
rain/
174+
├── torrent/ # Core BitTorrent session and torrent logic
175+
├── rainrpc/ # Shared types for JSON-RPC 2.0 API
176+
├── internal/ # Internal packages (networking, protocol, storage, etc.)
177+
└── main.go # Entry point
178+
```
179+
180+
### Component Architecture
181+
182+
Rain follows a layered architecture with clear separation of concerns:
183+
184+
**Core Layer:**
185+
- `torrent/session.go` - Main orchestrator managing torrents, DHT, and shared resources
186+
- `torrent/torrent.go` - Individual torrent lifecycle management
187+
188+
**Protocol Layer:**
189+
- BitTorrent protocol implementation (`internal/peerprotocol/`)
190+
- Tracker communication (`internal/tracker/`, `internal/announcer/`)
191+
- DHT and PEX support (`internal/dht/`, `internal/pex/`)
85192

86-
Difference from other clients
87-
-----------------------------
193+
**Network Layer:**
194+
- Connection management (`internal/peer/`, `internal/peerconn/`)
195+
- Message Stream Encryption (`internal/mse/`)
196+
- Resource limiting (`internal/resourcemanager/`)
88197

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.
198+
**Storage Layer:**
199+
- Piece management (`internal/piece/`, `internal/piececache/`)
200+
- File I/O optimization (`internal/storage/`)
201+
- Resume data persistence with BoltDB
93202

94203
Missing features
95204
----------------
96205

97-
The following features are not implemented in Rain, and this list should not be considered as a roadmap. These features are intentionally omitted either because they don't provide sufficient value for our use case at [put.io][putio-link], or because implementing them would add unnecessary complexity to the codebase. We prefer to maintain a focused and efficient implementation that serves our specific needs.
206+
The following features are not implemented in Rain. This list should not be considered a roadmap, as these features are intentionally omitted either because they don't provide sufficient value for our use case at [put.io][putio-link], or because implementing them would add unnecessary complexity to the codebase. We prefer to maintain a focused and efficient implementation that serves our specific needs.
98207

99-
- [IPv6 tracker extension](http://bittorrent.org/beps/bep_0007.html)
100-
- [IPv6 extension for DHT](http://bittorrent.org/beps/bep_0032.html)
101-
- [uTorrent transport protocol](http://bittorrent.org/beps/bep_0029.html)
102-
- [Superseeding](http://bittorrent.org/beps/bep_0016.html)
103-
- [HTTP seeding](http://bittorrent.org/beps/bep_0017.html)
104-
- [Merkle tree torrent extension](http://bittorrent.org/beps/bep_0030.html)
208+
- [BEP-007: IPv6 tracker extension](http://bittorrent.org/beps/bep_0007.html)
209+
- [BEP-032: IPv6 extension for DHT](http://bittorrent.org/beps/bep_0032.html)
210+
- [BEP-029: uTorrent transport protocol](http://bittorrent.org/beps/bep_0029.html)
211+
- [BEP-016: Superseeding](http://bittorrent.org/beps/bep_0016.html)
212+
- [BEP-017: HTTP seeding](http://bittorrent.org/beps/bep_0017.html)
213+
- [BEP-030: Merkle tree torrent extension](http://bittorrent.org/beps/bep_0030.html)
105214
- uPnP port forwarding
106215
- Selective downloading
107216
- Sequential downloading
108217

109218
Contributing
110219
------------
111220

112-
Rain is primarily developed to serve the specific requirements of [put.io][putio-link]. Due to this focused purpose, feature requests that do not align with put.io's needs are likely to be rejected. Additionally, we maintain a strong preference for simplicity in implementation - complex solutions, even if technically superior, will generally not be accepted. Please keep these guidelines in mind when submitting issues or pull requests.
221+
Rain is primarily developed to serve the specific requirements of [put.io][putio-link]. Due to this focused purpose, feature requests that do not align with put.io's needs will likely be rejected. Additionally, we maintain a strong preference for simplicity in implementation. Complex solutions, even if technically superior, will generally not be accepted. Please keep these guidelines in mind when submitting issues or pull requests.
113222

114223
Star History
115224
------------
116225

117226
[![Star History Chart](https://api.star-history.com/svg?repos=cenkalti/rain&type=Date)](https://star-history.com/#cenkalti/rain&Date)
118227

119228
[putio-link]: https://put.io
229+
[docs-link]: https://pkg.go.dev/github.com/cenkalti/rain/torrent

0 commit comments

Comments
 (0)