Skip to content

Commit

Permalink
feat: change scheduler and cdn listen
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <gaius.qi@gmail.com>
  • Loading branch information
gaius-qi committed Mar 29, 2022
1 parent a53c9d6 commit e1c7aff
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
6 changes: 6 additions & 0 deletions cdn/rpcserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ type Config struct {
// By default, the first non-loop address is advertised.
AdvertiseIP string `yaml:"advertiseIP" mapstructure:"advertiseIP"`

// Listen stands listen interface, like: 0.0.0.0, 192.168.0.1
Listen string `yaml:"listen" mapstructure:"listen"`

// ListenPort is the port cdn server listens on.
// default: 8002
ListenPort int `yaml:"listenPort" mapstructure:"listenPort"`
Expand All @@ -46,6 +49,9 @@ func (c Config) applyDefaults() Config {
if c.AdvertiseIP == "" {
c.AdvertiseIP = iputils.IPv4
}
if c.Listen == "" {
c.Listen = "0.0.0.0"
}
if c.ListenPort == 0 {
c.ListenPort = DefaultListenPort
}
Expand Down
2 changes: 1 addition & 1 deletion cdn/rpcserver/rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func (css *Server) SyncPieceTasks(sync cdnsystem.Seeder_SyncPieceTasksServer) er

func (css *Server) ListenAndServe() error {
// Generate GRPC listener
lis, _, err := rpc.ListenWithPortRange(css.config.AdvertiseIP, css.config.ListenPort, css.config.ListenPort)
lis, _, err := rpc.ListenWithPortRange(css.config.Listen, css.config.ListenPort, css.config.ListenPort)
if err != nil {
return err
}
Expand Down
14 changes: 11 additions & 3 deletions scheduler/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ type Config struct {
func New() *Config {
return &Config{
Server: &ServerConfig{
IP: iputils.IPv4,
Host: hostutils.FQDNHostname,
Port: 8002,
IP: iputils.IPv4,
Host: hostutils.FQDNHostname,
Listen: "0.0.0.0",
Port: 8002,
},
Scheduler: &SchedulerConfig{
Algorithm: "default",
Expand Down Expand Up @@ -123,6 +124,10 @@ func (c *Config) Validate() error {
return errors.New("server requires parameter port")
}

if c.Server.Listen == "" {
return errors.New("server requires parameter listen")
}

if c.Scheduler.Algorithm == "" {
return errors.New("scheduler requires parameter algorithm")
}
Expand Down Expand Up @@ -213,6 +218,9 @@ type ServerConfig struct {
// Server hostname
Host string `yaml:"host" mapstructure:"host"`

// Listen stands listen interface, like: 0.0.0.0, 192.168.0.1
Listen string `yaml:"listen" mapstructure:"listen"`

// Server port
Port int `yaml:"port" mapstructure:"port"`

Expand Down
1 change: 1 addition & 0 deletions scheduler/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func TestConfig_Load(t *testing.T) {
Server: &ServerConfig{
IP: "127.0.0.1",
Host: "foo",
Listen: "0.0.0.0",
Port: 8002,
CacheDir: "foo",
LogDir: "bar",
Expand Down
1 change: 1 addition & 0 deletions scheduler/config/testdata/scheduler.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
server:
ip: 127.0.0.1
host: foo
listen: 0.0.0.0
port: 8002
cacheDir: foo
logDir: bar
Expand Down
2 changes: 1 addition & 1 deletion scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (s *Server) Serve() error {
}

// Generate GRPC limit listener
listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", s.config.Server.IP, s.config.Server.Port))
listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", s.config.Server.Listen, s.config.Server.Port))
if err != nil {
logger.Fatalf("net listener failed to start: %v", err)
}
Expand Down

0 comments on commit e1c7aff

Please sign in to comment.