Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: torrent seed config #599

Merged
merged 13 commits into from
Jul 30, 2024
6 changes: 2 additions & 4 deletions internal/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

type Controller struct {
GetConfig func(v any) bool
GetConfig func(v any)
ProxyConfig *base.DownloaderProxyConfig
FileController
//ContextDialer() (proxy.Dialer, error)
Expand All @@ -22,10 +22,8 @@ type DefaultFileController struct {

func NewController() *Controller {
return &Controller{
GetConfig: func(v any) {},
FileController: &DefaultFileController{},
GetConfig: func(v any) bool {
return false
},
}
}

Expand Down
15 changes: 11 additions & 4 deletions internal/fetcher/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ import (
)

// Fetcher defines the interface for a download protocol.
// One fetcher for each download task
// Each download task will have a corresponding Fetcher instance for the management of the download task
type Fetcher interface {
// Name return the name of the protocol.
Name() string

Setup(ctl *controller.Controller)
// Resolve resource info from request
Resolve(req *base.Request) error
Expand All @@ -31,6 +28,12 @@ type Fetcher interface {
Wait() error
}

type Uploader interface {
Upload() error
UploadedBytes() int64
WaitUpload() error
}

// FetcherMeta defines the meta information of a fetcher.
type FetcherMeta struct {
Req *base.Request `json:"req"`
Expand Down Expand Up @@ -70,11 +73,15 @@ func (m *FetcherMeta) RootDirPath() string {

// FetcherBuilder defines the interface for a fetcher builder.
type FetcherBuilder interface {
// Name return the name of the protocol.
Name() string
// Schemes returns the schemes supported by the fetcher.
Schemes() []string
// Build returns a new fetcher.
Build() Fetcher

// DefaultConfig returns the default configuration of the protocol.
DefaultConfig() any
// Store fetcher
Store(fetcher Fetcher) (any, error)
// Restore fetcher
Expand Down
6 changes: 6 additions & 0 deletions internal/protocol/bt/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@ package bt
type config struct {
ListenPort int `json:"listenPort"`
Trackers []string `json:"trackers"`
// SeedKeep is always keep seeding after downloading is complete, unless manually stopped.
SeedKeep bool `json:"seedKeep`
// SeedRatio is the ratio of uploaded data to downloaded data to seed.
SeedRatio float64 `json:"seedRatio"`
// SeedTime is the time in seconds to seed after downloading is complete.
SeedTime int64 `json:"seedTime"`
}
Loading
Loading