From be2ddb7e4d78e4cbd6243a99afd9d4217a5c9372 Mon Sep 17 00:00:00 2001 From: Paul Saab Date: Mon, 29 Sep 2014 11:55:18 -0700 Subject: [PATCH] Fix IPv4 stats net.ParseIP() will return a v4mapped address which makes len(ip) == IPv6len and breaks stats for IPv4 requests. --- tracker/models/models.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tracker/models/models.go b/tracker/models/models.go index f74e17b..80156d3 100644 --- a/tracker/models/models.go +++ b/tracker/models/models.go @@ -51,7 +51,11 @@ func NewPeerKey(peerID string, ip net.IP) PeerKey { } func (pk PeerKey) IP() net.IP { - return net.ParseIP(strings.Split(string(pk), "//")[1]) + ip := net.ParseIP(strings.Split(string(pk), "//")[1]) + if rval := ip.To4(); rval != nil { + return rval + } + return ip } func (pk PeerKey) PeerID() string {