From dfc31495b7460e41a3b778c99a8972a368dde1bc Mon Sep 17 00:00:00 2001 From: Justin Li Date: Thu, 24 Jul 2014 17:02:28 -0400 Subject: [PATCH] Fix splitting for IPv6 RemoteAddrs --- README.md | 4 ++-- http/tracker.go | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e68a2cf..a97da2e 100644 --- a/README.md +++ b/README.md @@ -34,9 +34,9 @@ Configuration is done in a JSON formatted file specified with the `-config` flag #### Drivers -Chihaya is designed to remain agnostic about the choice of data storage. Out of the box, we provide only the necessary drivers to run Chihaya in public mode ("memory" for tracker and "noop" for backend). If you're interested in creating a new driver, check out the section on [customizing chihaya]. +Chihaya is designed to remain agnostic about the choice of data storage. Out of the box, we provide only the necessary drivers to run Chihaya in public mode ("memory" for tracker and "noop" for backend). If you're interested in creating a new driver, check out the section on [customizing Chihaya]. -[customizing chihaya]: https://github.com/chihaya/chihaya#customizing-chihaya +[customizing Chihaya]: #customizing-chihaya ## Developing Chihaya diff --git a/http/tracker.go b/http/tracker.go index 6c571c1..5de8cfd 100644 --- a/http/tracker.go +++ b/http/tracker.go @@ -9,7 +9,6 @@ import ( "net" "net/http" "strconv" - "strings" "github.com/julienschmidt/httprouter" @@ -156,8 +155,11 @@ func requestedIP(q *query.Query, r *http.Request, cfg *config.NetConfig) (v4, v6 return } - if idx := strings.LastIndex(r.RemoteAddr, ":"); idx != -1 { - if v4, v6, done = getIPs(r.RemoteAddr[0:idx], v4, v6, cfg); done { + var host string + host, _, err = net.SplitHostPort(r.RemoteAddr) + + if err != nil && host != "" { + if v4, v6, done = getIPs(host, v4, v6, cfg); done { return } }