diff --git a/client/config/dynconfig_local.go b/client/config/dynconfig_local.go index fb11a538eae..6f2ab0cfc90 100644 --- a/client/config/dynconfig_local.go +++ b/client/config/dynconfig_local.go @@ -131,7 +131,7 @@ func (d *dynconfigLocal) Deregister(l Observer) { // Notify publishes new events to listeners. func (d *dynconfigLocal) Notify() error { - var data *DynconfigData + data := &DynconfigData{} for _, schedulerAddr := range d.config.Scheduler.NetAddrs { addr := schedulerAddr.Addr host, port, err := net.SplitHostPort(addr) diff --git a/client/config/peerhost.go b/client/config/peerhost.go index 5d21c8d2dca..d69fb354776 100644 --- a/client/config/peerhost.go +++ b/client/config/peerhost.go @@ -167,11 +167,10 @@ func (p *DaemonOption) Validate() error { if p.Scheduler.Manager.RefreshInterval == 0 { return errors.New("manager refreshInterval is not specified") } - return nil - } - - if len(p.Scheduler.NetAddrs) == 0 { - return errors.New("empty schedulers and config server is not specified") + } else { + if len(p.Scheduler.NetAddrs) == 0 { + return errors.New("empty schedulers and config server is not specified") + } } if int64(p.Download.TotalRateLimit.Limit) < DefaultMinRate.ToNumber() { diff --git a/client/config/peerhost_darwin.go b/client/config/peerhost_darwin.go index 25e884bf608..650e6bc726e 100644 --- a/client/config/peerhost_darwin.go +++ b/client/config/peerhost_darwin.go @@ -24,7 +24,6 @@ import ( "golang.org/x/time/rate" "d7y.io/dragonfly/v2/client/util" - "d7y.io/dragonfly/v2/pkg/dfnet" "d7y.io/dragonfly/v2/pkg/net/fqdn" "d7y.io/dragonfly/v2/pkg/rpc" "d7y.io/dragonfly/v2/pkg/types" @@ -48,12 +47,6 @@ var peerHostConfig = func() *DaemonOption { }, }, }, - NetAddrs: []dfnet.NetAddr{ - { - Type: dfnet.TCP, - Addr: "127.0.0.1:8002", - }, - }, ScheduleTimeout: util.Duration{Duration: DefaultScheduleTimeout}, }, Host: HostOption{ diff --git a/client/config/peerhost_linux.go b/client/config/peerhost_linux.go index ba2b40766be..133eab7b9b9 100644 --- a/client/config/peerhost_linux.go +++ b/client/config/peerhost_linux.go @@ -24,7 +24,6 @@ import ( "golang.org/x/time/rate" "d7y.io/dragonfly/v2/client/util" - "d7y.io/dragonfly/v2/pkg/dfnet" "d7y.io/dragonfly/v2/pkg/net/fqdn" "d7y.io/dragonfly/v2/pkg/rpc" "d7y.io/dragonfly/v2/pkg/types" @@ -48,12 +47,6 @@ var peerHostConfig = func() *DaemonOption { }, }, }, - NetAddrs: []dfnet.NetAddr{ - { - Type: dfnet.TCP, - Addr: "127.0.0.1:8002", - }, - }, ScheduleTimeout: util.Duration{Duration: DefaultScheduleTimeout}, }, Host: HostOption{ diff --git a/client/config/peerhost_test.go b/client/config/peerhost_test.go index 887e3a4f5ea..cda34445b59 100644 --- a/client/config/peerhost_test.go +++ b/client/config/peerhost_test.go @@ -534,7 +534,14 @@ func TestPeerHostOption_Validate(t *testing.T) { { name: "valid config", config: NewDaemonConfig(), - mock: func(cfg *DaemonConfig) {}, + mock: func(cfg *DaemonConfig) { + cfg.Scheduler.NetAddrs = []dfnet.NetAddr{ + { + Type: dfnet.TCP, + Addr: "127.0.0.1:8002", + }, + } + }, expect: func(t *testing.T, err error) { assert := assert.New(t) assert.NoError(err) @@ -585,6 +592,12 @@ func TestPeerHostOption_Validate(t *testing.T) { name: "download rate limit must be greater", config: NewDaemonConfig(), mock: func(cfg *DaemonConfig) { + cfg.Scheduler.NetAddrs = []dfnet.NetAddr{ + { + Type: dfnet.TCP, + Addr: "127.0.0.1:8002", + }, + } cfg.Download.TotalRateLimit.Limit = rate.Limit(10 * unit.MB) }, expect: func(t *testing.T, err error) { @@ -597,6 +610,12 @@ func TestPeerHostOption_Validate(t *testing.T) { name: "upload rate limit must be greater", config: NewDaemonConfig(), mock: func(cfg *DaemonConfig) { + cfg.Scheduler.NetAddrs = []dfnet.NetAddr{ + { + Type: dfnet.TCP, + Addr: "127.0.0.1:8002", + }, + } cfg.Upload.RateLimit.Limit = rate.Limit(10 * unit.MB) }, expect: func(t *testing.T, err error) { @@ -609,6 +628,12 @@ func TestPeerHostOption_Validate(t *testing.T) { name: "max replicas must be greater than 0", config: NewDaemonConfig(), mock: func(cfg *DaemonConfig) { + cfg.Scheduler.NetAddrs = []dfnet.NetAddr{ + { + Type: dfnet.TCP, + Addr: "127.0.0.1:8002", + }, + } cfg.ObjectStorage.Enable = true cfg.ObjectStorage.MaxReplicas = 0 }, @@ -621,6 +646,12 @@ func TestPeerHostOption_Validate(t *testing.T) { name: "reload interval too short, must great than 1 second", config: NewDaemonConfig(), mock: func(cfg *DaemonConfig) { + cfg.Scheduler.NetAddrs = []dfnet.NetAddr{ + { + Type: dfnet.TCP, + Addr: "127.0.0.1:8002", + }, + } cfg.Reload.Interval.Duration = time.Millisecond }, expect: func(t *testing.T, err error) { @@ -632,6 +663,12 @@ func TestPeerHostOption_Validate(t *testing.T) { name: "gcInterval must be greater than 0", config: NewDaemonConfig(), mock: func(cfg *DaemonConfig) { + cfg.Scheduler.NetAddrs = []dfnet.NetAddr{ + { + Type: dfnet.TCP, + Addr: "127.0.0.1:8002", + }, + } cfg.GCInterval.Duration = 0 }, expect: func(t *testing.T, err error) { @@ -643,6 +680,12 @@ func TestPeerHostOption_Validate(t *testing.T) { name: "security requires parameter caCert", config: NewDaemonConfig(), mock: func(cfg *DaemonConfig) { + cfg.Scheduler.NetAddrs = []dfnet.NetAddr{ + { + Type: dfnet.TCP, + Addr: "127.0.0.1:8002", + }, + } cfg.Security.AutoIssueCert = true cfg.Security.CACert = "" }, @@ -655,6 +698,12 @@ func TestPeerHostOption_Validate(t *testing.T) { name: "certSpec requires parameter ipAddresses", config: NewDaemonConfig(), mock: func(cfg *DaemonConfig) { + cfg.Scheduler.NetAddrs = []dfnet.NetAddr{ + { + Type: dfnet.TCP, + Addr: "127.0.0.1:8002", + }, + } cfg.Security.AutoIssueCert = true cfg.Security.CACert = "test" cfg.Security.CertSpec.IPAddresses = nil @@ -668,6 +717,12 @@ func TestPeerHostOption_Validate(t *testing.T) { name: "certSpec requires parameter dnsNames", config: NewDaemonConfig(), mock: func(cfg *DaemonConfig) { + cfg.Scheduler.NetAddrs = []dfnet.NetAddr{ + { + Type: dfnet.TCP, + Addr: "127.0.0.1:8002", + }, + } cfg.Security.AutoIssueCert = true cfg.Security.CACert = "test" cfg.Security.CertSpec.IPAddresses = []net.IP{net.ParseIP("127.0.0.1")} @@ -682,6 +737,12 @@ func TestPeerHostOption_Validate(t *testing.T) { name: "certSpec requires parameter validityPeriod", config: NewDaemonConfig(), mock: func(cfg *DaemonConfig) { + cfg.Scheduler.NetAddrs = []dfnet.NetAddr{ + { + Type: dfnet.TCP, + Addr: "127.0.0.1:8002", + }, + } cfg.Security.AutoIssueCert = true cfg.Security.CACert = "testcert" cfg.Security.CertSpec.ValidityPeriod = 0