From 2bec1f323b2b5baa0d5f904654337d54fe935e20 Mon Sep 17 00:00:00 2001 From: Justin Li Date: Thu, 29 Jan 2015 12:07:11 -0500 Subject: [PATCH 1/3] deps: Update dependencies to Go 1.4 --- Godeps/Godeps.json | 12 ++++++------ Godeps/_workspace/.gitignore | 2 ++ .../p/go.net => golang.org/x/net}/netutil/listen.go | 0 .../x/net}/netutil/listen_test.go | 0 4 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 Godeps/_workspace/.gitignore rename Godeps/_workspace/src/{code.google.com/p/go.net => golang.org/x/net}/netutil/listen.go (100%) rename Godeps/_workspace/src/{code.google.com/p/go.net => golang.org/x/net}/netutil/listen_test.go (100%) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 4fd8a8c..92db914 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -1,12 +1,7 @@ { "ImportPath": "github.com/chihaya/chihaya", - "GoVersion": "go1.3.3", + "GoVersion": "go1.4.1", "Deps": [ - { - "ImportPath": "code.google.com/p/go.net/netutil", - "Comment": "null-164", - "Rev": "6122c8c304675f19800c917359e02dd68e760a5b" - }, { "ImportPath": "github.com/chihaya/bencode", "Rev": "1df51811f3440202aa39df93596654319ea5ff57" @@ -34,6 +29,11 @@ { "ImportPath": "github.com/stretchr/pat/stop", "Rev": "f7fe051f2b9bcaca162b38de4f93c9a8457160b9" + }, + { + "ImportPath": "golang.org/x/net/netutil", + "Comment": "null-204", + "Rev": "8fd8d3a0313cb59e495106ac76df5da29381fa24" } ] } diff --git a/Godeps/_workspace/.gitignore b/Godeps/_workspace/.gitignore new file mode 100644 index 0000000..f037d68 --- /dev/null +++ b/Godeps/_workspace/.gitignore @@ -0,0 +1,2 @@ +/pkg +/bin diff --git a/Godeps/_workspace/src/code.google.com/p/go.net/netutil/listen.go b/Godeps/_workspace/src/golang.org/x/net/netutil/listen.go similarity index 100% rename from Godeps/_workspace/src/code.google.com/p/go.net/netutil/listen.go rename to Godeps/_workspace/src/golang.org/x/net/netutil/listen.go diff --git a/Godeps/_workspace/src/code.google.com/p/go.net/netutil/listen_test.go b/Godeps/_workspace/src/golang.org/x/net/netutil/listen_test.go similarity index 100% rename from Godeps/_workspace/src/code.google.com/p/go.net/netutil/listen_test.go rename to Godeps/_workspace/src/golang.org/x/net/netutil/listen_test.go From da1528eeb808decc0d75491a9068d8c8dbadf6cd Mon Sep 17 00:00:00 2001 From: Justin Li Date: Thu, 29 Jan 2015 12:14:01 -0500 Subject: [PATCH 2/3] build: Run Go 1.4 on travis --- .travis.yml | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index e449886..7f10281 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: go -go: 1.3 +go: 1.4 before_install: - go get github.com/tools/godep diff --git a/README.md b/README.md index c06569c..8707526 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ use-cases). ## Building & Installing -Chihaya requires Go 1.3, [Godep], and a [Go environment] previously setup. +Chihaya requires Go 1.4, [Godep], and a [Go environment] previously setup. [Godep]: https://github.com/tools/godep [Go environment]: https://golang.org/doc/code.html From c4c678e7a9027c27f5f6fd6b5dc755351a20b321 Mon Sep 17 00:00:00 2001 From: Jimmy Zelinskie Date: Tue, 3 Feb 2015 02:53:20 -0500 Subject: [PATCH 3/3] http: add enough comments to pass go lint [ci skip] --- http/http.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/http/http.go b/http/http.go index 2b29820..9e3c461 100644 --- a/http/http.go +++ b/http/http.go @@ -19,13 +19,17 @@ import ( "github.com/chihaya/chihaya/tracker" ) +// ResponseHandler is an HTTP handler that returns a status code. type ResponseHandler func(http.ResponseWriter, *http.Request, httprouter.Params) (int, error) +// Server represents an HTTP serving torrent tracker. type Server struct { config *config.Config tracker *tracker.Tracker } +// makeHandler wraps our ResponseHandlers while timing requests, collecting, +// stats, logging, and handling errors. func makeHandler(handler ResponseHandler) httprouter.Handle { return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) { var msg string @@ -63,6 +67,7 @@ func makeHandler(handler ResponseHandler) httprouter.Handle { } } +// newRouter returns a router with all the routes. func newRouter(s *Server) *httprouter.Router { r := httprouter.New() @@ -91,6 +96,8 @@ func newRouter(s *Server) *httprouter.Router { return r } +// connState is used by graceful in order to gracefully shutdown. It also +// keeps track of connection stats. func (s *Server) connState(conn net.Conn, state http.ConnState) { switch state { case http.StateNew: @@ -102,14 +109,16 @@ func (s *Server) connState(conn net.Conn, state http.ConnState) { case http.StateHijacked: panic("connection impossibly hijacked") - case http.StateActive: // Ignore. - case http.StateIdle: // Ignore. + // Ignore the following cases. + case http.StateActive, http.StateIdle: default: glog.Errorf("Connection transitioned to unknown state %s (%d)", state, state) } } +// Serve creates a new Server and proceeds to block while handling requests +// until a graceful shutdown. func Serve(cfg *config.Config, tkr *tracker.Tracker) { srv := &Server{ config: cfg,