diff --git a/chihaya.go b/chihaya.go index f1ff4f5..0ee18dc 100644 --- a/chihaya.go +++ b/chihaya.go @@ -78,5 +78,10 @@ func Boot() { } http.Serve(cfg, tkr) + + if err := tkr.Close(); err != nil { + glog.Errorf("Failed to shut down tracker cleanly: %s", err.Error()) + } + glog.Info("Gracefully shut down") } diff --git a/config/config.go b/config/config.go index bd7ebc8..81c5673 100644 --- a/config/config.go +++ b/config/config.go @@ -89,17 +89,24 @@ type TrackerConfig struct { // HTTPConfig is the configuration for HTTP functionality. type HTTPConfig struct { - ListenAddr string `json:"http_listen_addr"` - RequestTimeout Duration `json:"http_request_timeout"` - HttpReadTimeout Duration `json:"http_read_timeout"` - HttpWriteTimeout Duration `json:"http_write_timeout"` - HttpListenLimit int `json:"http_listen_limit"` + HTTPListenAddr string `json:"http_listen_addr"` + HTTPRequestTimeout Duration `json:"http_request_timeout"` + HTTPReadTimeout Duration `json:"http_read_timeout"` + HTTPWriteTimeout Duration `json:"http_write_timeout"` + HTTPListenLimit int `json:"http_listen_limit"` +} + +// UDPConfig is the configuration for HTTP functionality. +type UDPConfig struct { + UDPListenAddr string `json:"udp_listen_addr"` + UDPReadBufferSize int `json:"udp_read_buffer_size"` } // Config is the global configuration for an instance of Chihaya. type Config struct { TrackerConfig HTTPConfig + UDPConfig DriverConfig StatsConfig } @@ -127,10 +134,14 @@ var DefaultConfig = Config{ }, HTTPConfig: HTTPConfig{ - ListenAddr: ":6881", - RequestTimeout: Duration{10 * time.Second}, - HttpReadTimeout: Duration{10 * time.Second}, - HttpWriteTimeout: Duration{10 * time.Second}, + HTTPListenAddr: ":6881", + HTTPRequestTimeout: Duration{10 * time.Second}, + HTTPReadTimeout: Duration{10 * time.Second}, + HTTPWriteTimeout: Duration{10 * time.Second}, + }, + + UDPConfig: UDPConfig{ + UDPListenAddr: ":6881", }, DriverConfig: DriverConfig{ diff --git a/http/http.go b/http/http.go index 967c7ce..06771c9 100644 --- a/http/http.go +++ b/http/http.go @@ -126,20 +126,20 @@ func Serve(cfg *config.Config, tkr *tracker.Tracker) { tracker: tkr, } - glog.V(0).Info("Starting on ", cfg.ListenAddr) - if cfg.HttpListenLimit != 0 { - glog.V(0).Info("Limiting connections to ", cfg.HttpListenLimit) + glog.V(0).Info("Starting HTTP on ", cfg.HTTPListenAddr) + if cfg.HTTPListenLimit != 0 { + glog.V(0).Info("Limiting connections to ", cfg.HTTPListenLimit) } grace := &graceful.Server{ - Timeout: cfg.RequestTimeout.Duration, + Timeout: cfg.HTTPRequestTimeout.Duration, ConnState: srv.connState, - ListenLimit: cfg.HttpListenLimit, + ListenLimit: cfg.HTTPListenLimit, Server: &http.Server{ - Addr: cfg.ListenAddr, + Addr: cfg.HTTPListenAddr, Handler: newRouter(srv), - ReadTimeout: cfg.HttpReadTimeout.Duration, - WriteTimeout: cfg.HttpWriteTimeout.Duration, + ReadTimeout: cfg.HTTPReadTimeout.Duration, + WriteTimeout: cfg.HTTPWriteTimeout.Duration, }, } @@ -150,8 +150,4 @@ func Serve(cfg *config.Config, tkr *tracker.Tracker) { glog.Errorf("Failed to gracefully run HTTP server: %s", err.Error()) } } - - if err := srv.tracker.Close(); err != nil { - glog.Errorf("Failed to shutdown tracker cleanly: %s", err.Error()) - } }