Skip to content

Commit

Permalink
Merge pull request #4 from boypt/master
Browse files Browse the repository at this point in the history
sync
  • Loading branch information
cgnq authored Mar 8, 2021
2 parents 30d81c1 + aae3dad commit 0886975
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 37 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ This project is a re-branded fork of [cloud-torrent](https://github.com/jpillora
# Features

* Individual file download control (1.1.3+)
* Run extrenal program on tasks completed: `DoneCmd`
* Run external program on tasks completion: `DoneCmd`
* Stops task when seeding ratio reached: `SeedRatio`
* Download/Upload speed limiter: `UploadRate`/`DownloadRate`
* Detailed transfer stats in web UI.
* [Torrent Watcher](https://github.com/boypt/simple-torrent/wiki/Torrent-Watcher)
* K8s/docker health-check endpoint `/healthz`
* Extra trackers from extrenal source
* Extra trackers from external source
* Protocol Handler to `magnet:`
* Magnet RSS subscribing supported
* Flexible config file accepts multiple formats (.json/.yaml/.toml) ([by spf13/Viper](https://github.com/spf13/viper/)) (1.2.0+)
Expand All @@ -28,7 +28,7 @@ Also:
* Mobile-friendly
* Fast [content server](http://golang.org/pkg/net/http/#ServeContent)
* IPv6 out of the box
* Updated torrnet engine from [anacrolix/torrent](https://github.com/anacrolix/torrent)
* Updated torrent engine from [anacrolix/torrent](https://github.com/anacrolix/torrent)

# Install

Expand All @@ -49,6 +49,9 @@ The script install a systemd unit (under `scripts/cloud-torrent.service`) as ser
``` sh
$ docker run -d -p 3000:3000 -v /path/to/my/downloads:/downloads -v /path/to/my/torrents:/torrents boypt/cloud-torrent
```
When running as a container, keep in mind:
* You need also to expose your torrent incoming port (50007 by default) if you want to seed (`-p 50007:50007`). Also, you'll have to forward the port on your router.
* Automatic port forwarding on your router via UPnP IGD will not work unless run in `host` mode (`--net=host`).

## Source

Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
version: '3.3'
services:
cloud-torrent:
# network_mode: host
ports:
- '3000:3000'
# - '50007:50007'
volumes:
- '/path/to/my/downloads:/downloads'
- '/path/to/my/torrents:/torrents'
Expand Down
2 changes: 0 additions & 2 deletions engine/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ type Config struct {
EnableSeeding bool
IncomingPort int
DoneCmd string
DoneCmdThreshold string
SeedRatio float32
UploadRate string
DownloadRate string
Expand All @@ -66,7 +65,6 @@ func InitConf(specPath string) (*Config, error) {
viper.SetDefault("EnableUpload", true)
viper.SetDefault("AutoStart", true)
viper.SetDefault("DoneCmd", "")
viper.SetDefault("DoneCmdThreshold", "3s")
viper.SetDefault("SeedRatio", 0)
viper.SetDefault("ObfsPreferred", true)
viper.SetDefault("ObfsRequirePreferred", false)
Expand Down
39 changes: 8 additions & 31 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@ type Server interface {

//the Engine Cloud Torrent engine, backed by anacrolix/torrent
type Engine struct {
sync.RWMutex // race condition on ts,client
cldServer Server
cacheDir string
client *torrent.Client
closeSync chan struct{}
config Config
ts map[string]*Torrent
bttracker []string
doneThreshold time.Duration
sync.RWMutex // race condition on ts,client
cldServer Server
cacheDir string
client *torrent.Client
closeSync chan struct{}
config Config
ts map[string]*Torrent
bttracker []string
}

func New(s Server) *Engine {
Expand All @@ -66,12 +65,6 @@ func (e *Engine) Configure(c *Config) error {
c.TrackerListURL = defaultTrackerListURL
}

if th, err := time.ParseDuration(c.DoneCmdThreshold); err == nil {
e.doneThreshold = th
} else {
return fmt.Errorf("fail to parse DoneCmdThreshold %w", err)
}

e.Lock()
defer e.Unlock()
tc := torrent.NewDefaultClientConfig()
Expand Down Expand Up @@ -230,22 +223,6 @@ func (e *Engine) TaskRoutine() {
go e.StopTorrent(t.InfoHash)
}

// task started in `DoneCmdThreshold` (default 30s), won't call the DoneCmd below
if !t.IsDoneReady {
if t.StartedAt.IsZero() {
continue
}

if time.Since(t.StartedAt) > e.doneThreshold && !t.Done {
// after threshold and task is not done yet, is ready for DoneCmd
t.IsDoneReady = true
} else {
log.Println("[DoneCmd] not ready for DoneCmd yet, time before threshold, task was started at ", t.StartedAt)
}

continue
}

// call DoneCmd on task completed
if t.Done && !t.DoneCmdCalled {
t.DoneCmdCalled = true
Expand Down
1 change: 0 additions & 1 deletion engine/torrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ type Torrent struct {
Deleted bool
Done bool
DoneCmdCalled bool
IsDoneReady bool
Percent float32
DownloadRate float32
UploadRate float32
Expand Down

0 comments on commit 0886975

Please sign in to comment.