Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
feature: make supernode configurable for dfget with dfdaemon
Browse files Browse the repository at this point in the history
Signed-off-by: Starnop <starnop@163.com>
  • Loading branch information
starnop committed Apr 3, 2019
1 parent 3c48adb commit b88cc5d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
4 changes: 4 additions & 0 deletions cmd/dfdaemon/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ type Options struct {
// ConfigPath is the path of dfdaemon's configuration file.
// default value is: /etc/dragonfly/dfdaemon.yml
ConfigPath string

// SupernodeList specify supernode list.
SupernodeList []string
}

// NewOption returns the default options.
Expand Down Expand Up @@ -125,6 +128,7 @@ func (o *Options) AddFlags(fs *flag.FlagSet) {
fs.StringVar(&o.DownRule, "rule", "", "download the url by P2P if url matches the specified pattern,format:reg1,reg2,reg3")
fs.BoolVar(&o.Notbs, "notbs", true, "not try back source to download if throw exception")
fs.StringSliceVar(&o.TrustHosts, "trust-hosts", o.TrustHosts, "list of trusted hosts which dfdaemon forward their requests directly, comma separated.")
fs.StringSliceVar(&o.SupernodeList, "node", o.SupernodeList, "specify the addresses(IP:port) of supnernodes that will be passed to dfget.")

fs.StringVar(&o.ConfigPath, "config", constant.DefaultConfigPath,
"the path of dfdaemon's configuration file")
Expand Down
8 changes: 7 additions & 1 deletion dfdaemon/downloader/dfget/dfget.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,21 @@ type DFGetter struct {
callSystem string
// the notbs param of dfget
notbs bool

supernodes []string
}

var _ downloader.Interface = &DFGetter{}

// NewDFGetter returns the default DFGetter.
func NewDFGetter(dstDir, callSystem string, notbs bool, rateLimit, urlFilter string) *DFGetter {
func NewDFGetter(dstDir, callSystem string, notbs bool, rateLimit, urlFilter string, supernodes []string) *DFGetter {
return &DFGetter{
dstDir: dstDir,
callSystem: callSystem,
notbs: notbs,
rateLimit: rateLimit,
urlFilter: urlFilter,
supernodes: supernodes,
}
}

Expand Down Expand Up @@ -96,6 +99,9 @@ func (dfGetter *DFGetter) parseCommand(url string, header map[string][]string, n
args = append(append(args, "-s"), dfGetter.rateLimit)
args = append(append(args, "--totallimit"), dfGetter.rateLimit)
}
if dfGetter.supernodes != nil && len(dfGetter.supernodes) > 0 {
args = append(append(args, "--node"), strings.Join(dfGetter.supernodes, ","))
}

if header != nil {
for key, value := range header {
Expand Down
3 changes: 3 additions & 0 deletions dfdaemon/global/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ type CommandParam struct {
// TrustHosts includes the trusted hosts as keys of the map which dfdaemon forward their
// requests directly when dfdaemon is used to http_proxy mode.
TrustHosts map[string]string

// SupernodeList specify supernode list.
SupernodeList []string
}

var (
Expand Down
1 change: 1 addition & 0 deletions dfdaemon/handler/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func NewDFRoundTripper(cfg *tls.Config) *DFRoundTripper {
global.CommandLine.Notbs,
global.CommandLine.RateLimit,
global.CommandLine.URLFilter,
global.CommandLine.SupernodeList,
),
}
}
Expand Down
19 changes: 10 additions & 9 deletions dfdaemon/initializer/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,16 @@ func initParam(options *options.Options) {
// copy options to g.CommandLine so we do not break anything, but finally
// we should get rid of g.CommandLine totally.
g.CommandLine = global.CommandParam{
DfPath: options.DfPath,
DFRepo: options.DFRepo,
RateLimit: options.RateLimit,
CallSystem: options.CallSystem,
URLFilter: options.URLFilter,
Notbs: options.Notbs,
HostIP: options.HostIP,
Registry: options.Registry,
TrustHosts: parsedTrustHosts,
DfPath: options.DfPath,
DFRepo: options.DFRepo,
RateLimit: options.RateLimit,
CallSystem: options.CallSystem,
URLFilter: options.URLFilter,
Notbs: options.Notbs,
HostIP: options.HostIP,
Registry: options.Registry,
TrustHosts: parsedTrustHosts,
SupernodeList: options.SupernodeList,
}

initProperties(options)
Expand Down

0 comments on commit b88cc5d

Please sign in to comment.