diff --git a/chihaya.go b/chihaya.go index 9245072..50336cb 100644 --- a/chihaya.go +++ b/chihaya.go @@ -91,7 +91,7 @@ func Boot() { go func() { defer wg.Done() - srv.Serve() + srv.Serve(cfg.HTTPListenAddr) }() } @@ -102,7 +102,7 @@ func Boot() { go func() { defer wg.Done() - srv.Serve() + srv.Serve(cfg.UDPListenAddr) }() } diff --git a/http/http.go b/http/http.go index 50d2dce..9e5c2e2 100644 --- a/http/http.go +++ b/http/http.go @@ -121,8 +121,8 @@ func (s *Server) connState(conn net.Conn, state http.ConnState) { } // Serve runs an HTTP server, blocking until the server has shut down. -func (s *Server) Serve() { - glog.V(0).Info("Starting HTTP on ", s.config.HTTPListenAddr) +func (s *Server) Serve(addr string) { + glog.V(0).Info("Starting HTTP on ", addr) if s.config.HTTPListenLimit != 0 { glog.V(0).Info("Limiting connections to ", s.config.HTTPListenLimit) @@ -133,7 +133,7 @@ func (s *Server) Serve() { ConnState: s.connState, ListenLimit: s.config.HTTPListenLimit, Server: &http.Server{ - Addr: s.config.HTTPListenAddr, + Addr: addr, Handler: newRouter(s), ReadTimeout: s.config.HTTPReadTimeout.Duration, WriteTimeout: s.config.HTTPWriteTimeout.Duration, diff --git a/tracker/tracker.go b/tracker/tracker.go index 2576f77..35eecbe 100644 --- a/tracker/tracker.go +++ b/tracker/tracker.go @@ -27,7 +27,7 @@ type Tracker struct { // Server represents a server for a given BitTorrent tracker protocol. type Server interface { // Serve runs the server and blocks until the server has shut down. - Serve() + Serve(addr string) // Stop cleanly shuts down the server in a non-blocking manner. Stop() diff --git a/udp/udp.go b/udp/udp.go index b838171..f19ce3a 100644 --- a/udp/udp.go +++ b/udp/udp.go @@ -25,13 +25,13 @@ type Server struct { done bool } -func (s *Server) serve() error { - listenAddr, err := net.ResolveUDPAddr("udp", s.config.UDPListenAddr) +func (s *Server) serve(listenAddr string) error { + udpAddr, err := net.ResolveUDPAddr("udp", listenAddr) if err != nil { return err } - sock, err := net.ListenUDP("udp", listenAddr) + sock, err := net.ListenUDP("udp", udpAddr) defer sock.Close() if err != nil { return err @@ -75,8 +75,8 @@ func (s *Server) serve() error { } // Serve runs a UDP server, blocking until the server has shut down. -func (s *Server) Serve() { - glog.V(0).Info("Starting UDP on ", s.config.UDPListenAddr) +func (s *Server) Serve(addr string) { + glog.V(0).Info("Starting UDP on ", addr) go func() { // Generate a new IV every hour. @@ -85,7 +85,7 @@ func (s *Server) Serve() { } }() - if err := s.serve(); err != nil { + if err := s.serve(addr); err != nil { glog.Errorf("Failed to run UDP server: %s", err.Error()) } else { glog.Info("UDP server shut down cleanly")