From ae494b7f0c44c90dec43ab60bec92381784fcb09 Mon Sep 17 00:00:00 2001 From: mwnx Date: Sun, 20 May 2018 00:21:29 +0200 Subject: [PATCH 1/3] =?UTF-8?q?Fix=20ipv6=20parser=20error=20message=20("i?= =?UTF-8?q?p4"=20=E2=86=92=20"ip6")?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- transcoders.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/transcoders.go b/transcoders.go index f6739ed..7f7f645 100644 --- a/transcoders.go +++ b/transcoders.go @@ -49,7 +49,7 @@ func ip4StB(s string) ([]byte, error) { func ip6StB(s string) ([]byte, error) { i := net.ParseIP(s).To16() if i == nil { - return nil, fmt.Errorf("failed to parse ip4 addr: %s", s) + return nil, fmt.Errorf("failed to parse ip6 addr: %s", s) } return i, nil } From 7bf24dca814ab7840de3f01eb223a359abac0bb1 Mon Sep 17 00:00:00 2001 From: mwnx Date: Sat, 16 Jun 2018 18:06:48 +0200 Subject: [PATCH 2/3] Fix CodeToVarint []byte size We were missing a logarithm... CodeToVarint would previously allocate more bytes than necessary (exponentially) for the varint slice. This bug was silent but deserves to be fixed nonetheless. --- protocols.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/protocols.go b/protocols.go index 9f78f98..12cfb53 100644 --- a/protocols.go +++ b/protocols.go @@ -4,6 +4,7 @@ import ( "encoding/binary" "fmt" "strings" + "math/bits" ) // Protocol is a Multiaddr protocol description structure. @@ -117,7 +118,7 @@ func ProtocolsWithString(s string) ([]Protocol, error) { // CodeToVarint converts an integer to a varint-encoded []byte func CodeToVarint(num int) []byte { - buf := make([]byte, (num/7)+1) // varint package is uint64 + buf := make([]byte, bits.Len(uint(num))/7 + 1) n := binary.PutUvarint(buf, uint64(num)) return buf[:n] } From b9548e77d7171cd8c119a3cc90c06eaed727bb19 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Sat, 16 Jun 2018 13:35:24 -0700 Subject: [PATCH 3/3] bump minimum go version to 1.10 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6ce5865..8f187a8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ os: language: go go: - - 1.8 + - 1.10.x install: true