From e86bf92f317d6c55ea7447c7bf1a7a282914f040 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Wed, 18 May 2016 21:59:05 +0200 Subject: [PATCH 1/5] Migrate hamming to gx from Godeps License: MIT Signed-off-by: Jakub Sztandera --- Godeps/Godeps.json | 5 - .../steakknife/hamming/MIT-LICENSE.txt | 8 - .../github.com/steakknife/hamming/README.md | 44 ------ .../github.com/steakknife/hamming/hamming.go | 97 ------------ .../steakknife/hamming/hamming_test.go | 143 ------------------ blocks/bloom/filter.go | 2 +- package.json | 6 + 7 files changed, 7 insertions(+), 298 deletions(-) delete mode 100644 Godeps/_workspace/src/github.com/steakknife/hamming/MIT-LICENSE.txt delete mode 100644 Godeps/_workspace/src/github.com/steakknife/hamming/README.md delete mode 100644 Godeps/_workspace/src/github.com/steakknife/hamming/hamming.go delete mode 100644 Godeps/_workspace/src/github.com/steakknife/hamming/hamming_test.go diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 11284e14dab..9dea866967f 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -156,11 +156,6 @@ "ImportPath": "github.com/rs/cors", "Rev": "5e4ce6bc0ecd3472f6f943666d84876691be2ced" }, - { - "ImportPath": "github.com/steakknife/hamming", - "Comment": "0.0.10", - "Rev": "8bad99011016569c05320e51be39c648679c5b73" - }, { "ImportPath": "github.com/syndtr/goleveldb/leveldb", "Rev": "4875955338b0a434238a31165cb87255ab6e9e4a" diff --git a/Godeps/_workspace/src/github.com/steakknife/hamming/MIT-LICENSE.txt b/Godeps/_workspace/src/github.com/steakknife/hamming/MIT-LICENSE.txt deleted file mode 100644 index ccf77fe465c..00000000000 --- a/Godeps/_workspace/src/github.com/steakknife/hamming/MIT-LICENSE.txt +++ /dev/null @@ -1,8 +0,0 @@ -The MIT License (MIT) -Copyright © 2014, 2015 Barry Allard - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/Godeps/_workspace/src/github.com/steakknife/hamming/README.md b/Godeps/_workspace/src/github.com/steakknife/hamming/README.md deleted file mode 100644 index c7a791a1d8f..00000000000 --- a/Godeps/_workspace/src/github.com/steakknife/hamming/README.md +++ /dev/null @@ -1,44 +0,0 @@ -# hamming distance calculations in Go - -Copyright © 2014, 2015 Barry Allard - -[MIT license](MIT-LICENSE.txt) - -## Usage - -```go -import 'github.com/steakknife/hamming' - -// ... - -// hamming distance between values -hamming.Byte(0xFF, 0x00) // 8 -hamming.Byte(0x00, 0x00) // 0 - -// just count bits in a byte -hamming.CountBitsByte(0xA5), // 4 -``` - -See help in the [docs](https://godoc.org/github.com/steakknife/hamming) - -## Get - - go get -u github.com/steakknife/hamming # master is always stable - -## Source - -- On the web: https://github.com/steakknife/hamming - -- Git: `git clone https://github.com/steakknife/hamming` - -## Contact - -- [Feedback](mailto:barry.allard@gmail.com) - -- [Issues](https://github.com/steakknife/hamming/issues) - -## License - -[MIT license](MIT-LICENSE.txt) - -Copyright © 2014, 2015 Barry Allard diff --git a/Godeps/_workspace/src/github.com/steakknife/hamming/hamming.go b/Godeps/_workspace/src/github.com/steakknife/hamming/hamming.go deleted file mode 100644 index 311fcd9c5dc..00000000000 --- a/Godeps/_workspace/src/github.com/steakknife/hamming/hamming.go +++ /dev/null @@ -1,97 +0,0 @@ -// -// hamming distance calculations in Go -// -// https://github.com/steakknife/hamming -// -// Copyright © 2014, 2015 Barry Allard -// -// MIT license -// -// -// Usage -// -// The functions are named (CountBits)?(Byte|Uint64)s?. The plural forms are for slices. The CountBits.+ forms are Population Count only, where the bare-type forms are Hamming distance. -// -// import 'github.com/steakknife/hamming' -// -// // ... -// -// // hamming distance between values -// hamming.Byte(0xFF, 0x00) // 8 -// hamming.Byte(0x00, 0x00) // 0 -// -// // just count bits in a byte -// hamming.CountBitsByte(0xA5), // 4 -// -package hamming - -// SSE4.x PopCnt is 10x slower -// References: check out Hacker's Delight - -const ( - m1 uint64 = 0x5555555555555555 //binary: 0101... - m2 uint64 = 0x3333333333333333 //binary: 00110011.. - m4 uint64 = 0x0f0f0f0f0f0f0f0f //binary: 4 zeros, 4 ones ... - m8 uint64 = 0x00ff00ff00ff00ff //binary: 8 zeros, 8 ones ... - m16 uint64 = 0x0000ffff0000ffff //binary: 16 zeros, 16 ones ... - m32 uint64 = 0x00000000ffffffff //binary: 32 zeros, 32 ones - hff uint64 = 0xffffffffffffffff //binary: all ones - h01 uint64 = 0x0101010101010101 //the sum of 256 to the power of 0,1,2,3... -) - -var table = [256]byte{0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8} - -// hamming distance of two uint64's -func Uint64(x, y uint64) int { - return CountBitsUint64(x ^ y) -} - -// hamming distance of two uint64 buffers, of which the size of the first argument is used for both (panics if b1 is smaller than b0, does not compare b1 beyond length of b0) -func Uint64s(b0, b1 []uint64) int { - d := 0 - for i, x := range b0 { - d += Uint64(x, b1[i]) - } - return d -} - -// hamming distance of two bytes -func Byte(x, y byte) int { - return CountBitsByte(x ^ y) -} - -// hamming distance of two byte buffers, of which the size of the first argument is used for both (panics if b1 is smaller than b0, does not compare b1 beyond length of b0) -func Bytes(b0, b1 []byte) int { - d := 0 - for i, x := range b0 { - d += Byte(x, b1[i]) - } - return d -} - -func CountBitsUint64(x uint64) int { - x -= (x >> 1) & m1 // put count of each 2 bits into those 2 bits - x = (x & m2) + ((x >> 2) & m2) // put count of each 4 bits into those 4 bits - x = (x + (x >> 4)) & m4 // put count of each 8 bits into those 8 bits - return int((x * h01) >> 56) // returns left 8 bits of x + (x<<8) + (x<<16) + (x<<24) + ... -} - -func CountBitsUint64s(b []uint64) int { - c := 0 - for _, x := range b { - c += CountBitsUint64(x) - } - return c -} - -func CountBitsByte(x byte) int { - return int(table[x]) -} - -func CountBitsBytes(b []byte) int { - c := 0 - for _, x := range b { - c += CountBitsByte(x) - } - return c -} diff --git a/Godeps/_workspace/src/github.com/steakknife/hamming/hamming_test.go b/Godeps/_workspace/src/github.com/steakknife/hamming/hamming_test.go deleted file mode 100644 index 44723d2d6ed..00000000000 --- a/Godeps/_workspace/src/github.com/steakknife/hamming/hamming_test.go +++ /dev/null @@ -1,143 +0,0 @@ -// -// hamming distance calculations in Go -// -// https://github.com/steakknife/hamming -// -// Copyright © 2014, 2015 Barry Allard -// -// MIT license -// -package hamming - -import ( - "testing" -) - -type testCountBitsUint64Case struct { - x uint64 - n int -} - -type testCountBitsByteCase struct { - x byte - n int -} - -type testBytesCase struct { - b0, b1 []byte - n int -} - -type testUint64sCase struct { - b0, b1 []uint64 - n int -} - -var testCountBitsByteCases = []testCountBitsByteCase{ - {0x00, 0}, - {0x01, 1}, - {0x02, 1}, - {0x03, 2}, - {0xaa, 4}, - {0x55, 4}, - {0x7f, 7}, - {0xff, 8}, -} - -var testCountBitsUint64Cases = []testCountBitsUint64Case{ - {0x00, 0}, - {0x01, 1}, - {0x02, 1}, - {0x03, 2}, - {0xaa, 4}, - {0x55, 4}, - {0x7f, 7}, - {0xff, 8}, - {0xffff, 16}, - {0xffffffff, 32}, - {0x1ffffffff, 33}, - {0x3ffffffff, 34}, - {0x7ffffffff, 35}, - {0xfffffffff, 36}, - {0x3fffffffffffffff, 62}, - {0x7fffffffffffffff, 63}, - {0xffffffffffffffff, 64}, -} - -var testBytesCases = []testBytesCase{ - {[]byte{}, []byte{}, 0}, - {[]byte{1}, []byte{0}, 1}, - {[]byte{1}, []byte{2}, 2}, - {[]byte{1, 0}, []byte{0, 1}, 2}, - {[]byte{1, 0}, []byte{0, 1}, 2}, -} - -var testUint64sCases = []testUint64sCase{ - {[]uint64{}, []uint64{}, 0}, - {[]uint64{1}, []uint64{0}, 1}, - {[]uint64{1}, []uint64{2}, 2}, - {[]uint64{1, 0}, []uint64{0, 1}, 2}, - {[]uint64{1, 0}, []uint64{0, 1}, 2}, -} - -func TestCountBitByte(t *testing.T) { - for _, c := range testCountBitsByteCases { - if actualN := CountBitsByte(c.x); actualN != c.n { - t.Fatal("CountBitsByte(", c.x, ") = ", actualN, " != ", c.n) - } else { - t.Log("CountBitsByte(", c.x, ") == ", c.n) - } - } -} - -func TestBytes(t *testing.T) { - for _, c := range testBytesCases { - if actualN := Bytes(c.b0, c.b1); actualN != c.n { - t.Fatal("Bytes(", c.b0, ",", c.b1, ") = ", actualN, " != ", c.n) - } else { - t.Log("Bytes(", c.b0, ",", c.b1, ") == ", c.n) - } - } -} - -func TestUint64s(t *testing.T) { - for _, c := range testUint64sCases { - if actualN := Uint64s(c.b0, c.b1); actualN != c.n { - t.Fatal("Uint64s(", c.b0, ",", c.b1, ") = ", actualN, " != ", c.n) - } else { - t.Log("Uint64s(", c.b0, ",", c.b1, ") == ", c.n) - } - } -} - -func TestCountBitUint64(t *testing.T) { - for _, c := range testCountBitsUint64Cases { - if actualN := CountBitsUint64(c.x); actualN != c.n { - t.Fatal("CountBitsUint64(", c.x, ") = ", actualN, " != ", c.n) - } else { - t.Log("CountBitsUint64(", c.x, ") == ", c.n) - } - } -} - -func BenchmarkCountBitsUint64(b *testing.B) { - j := 0 - for i := 0; i < b.N; i++ { - CountBitsUint64(testCountBitsUint64Cases[j].x) - j++ - if j == len(testCountBitsUint64Cases) { - j = 0 - } - } -} - -func BenchmarkCountBitsByte(b *testing.B) { - j := 0 - for i := 0; i < b.N; i++ { - CountBitsByte(testCountBitsByteCases[j].x) - j++ - if j == len(testCountBitsByteCases) { - j = 0 - } - } -} diff --git a/blocks/bloom/filter.go b/blocks/bloom/filter.go index 64a2db04286..6b1b7485459 100644 --- a/blocks/bloom/filter.go +++ b/blocks/bloom/filter.go @@ -6,7 +6,7 @@ import ( "errors" // Non crypto hash, because speed "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/mtchavez/jenkins" - "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/steakknife/hamming" + "gx/ipfs/QmeWQMDa5dSdP4n8WDeoY5z8L2EKVqF4ZvK4VEHsLqXsGu/hamming" "hash" ) diff --git a/package.json b/package.json index b7a6d7f1e56..9b123e0df6f 100644 --- a/package.json +++ b/package.json @@ -75,6 +75,12 @@ "hash": "QmcyaFHbyiZfoX5GTpcqqCPYmbjYNAhRDekXSJPFHdYNSV", "name": "go.uuid", "version": "1.0.0" + }, + { + "author": "steakknife", + "hash": "QmeWQMDa5dSdP4n8WDeoY5z8L2EKVqF4ZvK4VEHsLqXsGu", + "name": "hamming", + "version": "0.0.10" } ], "gxVersion": "0.4.0", From 75dfff8305e5886063304cda40e3e32969322764 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Wed, 18 May 2016 23:09:15 +0200 Subject: [PATCH 2/5] Move backoff to gx from Godeps License: MIT Signed-off-by: Jakub Sztandera --- Godeps/Godeps.json | 4 - .../github.com/cenkalti/backoff/.gitignore | 22 --- .../github.com/cenkalti/backoff/.travis.yml | 2 - .../src/github.com/cenkalti/backoff/LICENSE | 20 --- .../src/github.com/cenkalti/backoff/README.md | 69 --------- .../github.com/cenkalti/backoff/backoff.go | 56 ------- .../cenkalti/backoff/backoff_test.go | 28 ---- .../cenkalti/backoff/exponential.go | 141 ------------------ .../cenkalti/backoff/exponential_test.go | 111 -------------- .../src/github.com/cenkalti/backoff/retry.go | 47 ------ .../github.com/cenkalti/backoff/retry_test.go | 34 ----- .../src/github.com/cenkalti/backoff/ticker.go | 105 ------------- .../cenkalti/backoff/ticker_test.go | 45 ------ exchange/reprovide/reprovide.go | 2 +- package.json | 6 + 15 files changed, 7 insertions(+), 685 deletions(-) delete mode 100644 Godeps/_workspace/src/github.com/cenkalti/backoff/.gitignore delete mode 100644 Godeps/_workspace/src/github.com/cenkalti/backoff/.travis.yml delete mode 100644 Godeps/_workspace/src/github.com/cenkalti/backoff/LICENSE delete mode 100644 Godeps/_workspace/src/github.com/cenkalti/backoff/README.md delete mode 100644 Godeps/_workspace/src/github.com/cenkalti/backoff/backoff.go delete mode 100644 Godeps/_workspace/src/github.com/cenkalti/backoff/backoff_test.go delete mode 100644 Godeps/_workspace/src/github.com/cenkalti/backoff/exponential.go delete mode 100644 Godeps/_workspace/src/github.com/cenkalti/backoff/exponential_test.go delete mode 100644 Godeps/_workspace/src/github.com/cenkalti/backoff/retry.go delete mode 100644 Godeps/_workspace/src/github.com/cenkalti/backoff/retry_test.go delete mode 100644 Godeps/_workspace/src/github.com/cenkalti/backoff/ticker.go delete mode 100644 Godeps/_workspace/src/github.com/cenkalti/backoff/ticker_test.go diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 9dea866967f..36229da174c 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -26,10 +26,6 @@ "ImportPath": "github.com/camlistore/lock", "Rev": "ae27720f340952636b826119b58130b9c1a847a0" }, - { - "ImportPath": "github.com/cenkalti/backoff", - "Rev": "9831e1e25c874e0a0601b6dc43641071414eec7a" - }, { "ImportPath": "github.com/cheggaaa/pb", "Rev": "d7729fd7ec1372c15b83db39834bf842bf2d69fb" diff --git a/Godeps/_workspace/src/github.com/cenkalti/backoff/.gitignore b/Godeps/_workspace/src/github.com/cenkalti/backoff/.gitignore deleted file mode 100644 index 00268614f04..00000000000 --- a/Godeps/_workspace/src/github.com/cenkalti/backoff/.gitignore +++ /dev/null @@ -1,22 +0,0 @@ -# Compiled Object files, Static and Dynamic libs (Shared Objects) -*.o -*.a -*.so - -# Folders -_obj -_test - -# Architecture specific extensions/prefixes -*.[568vq] -[568vq].out - -*.cgo1.go -*.cgo2.c -_cgo_defun.c -_cgo_gotypes.go -_cgo_export.* - -_testmain.go - -*.exe diff --git a/Godeps/_workspace/src/github.com/cenkalti/backoff/.travis.yml b/Godeps/_workspace/src/github.com/cenkalti/backoff/.travis.yml deleted file mode 100644 index ce9cb623335..00000000000 --- a/Godeps/_workspace/src/github.com/cenkalti/backoff/.travis.yml +++ /dev/null @@ -1,2 +0,0 @@ -language: go -go: 1.3.3 diff --git a/Godeps/_workspace/src/github.com/cenkalti/backoff/LICENSE b/Godeps/_workspace/src/github.com/cenkalti/backoff/LICENSE deleted file mode 100644 index 89b81799655..00000000000 --- a/Godeps/_workspace/src/github.com/cenkalti/backoff/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2014 Cenk Altı - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/Godeps/_workspace/src/github.com/cenkalti/backoff/README.md b/Godeps/_workspace/src/github.com/cenkalti/backoff/README.md deleted file mode 100644 index 8e2612e639b..00000000000 --- a/Godeps/_workspace/src/github.com/cenkalti/backoff/README.md +++ /dev/null @@ -1,69 +0,0 @@ -# backoff - -[![GoDoc](https://godoc.org/github.com/cenkalti/backoff?status.png)](https://godoc.org/github.com/cenkalti/backoff) -[![Build Status](https://travis-ci.org/cenkalti/backoff.png)](https://travis-ci.org/cenkalti/backoff) - -This is a Go port of the exponential backoff algorithm from -[google-http-java-client](https://code.google.com/p/google-http-java-client/wiki/ExponentialBackoff). - -[Exponential backoff](http://en.wikipedia.org/wiki/Exponential_backoff) -is an algorithm that uses feedback to multiplicatively decrease the rate of some process, -in order to gradually find an acceptable rate. -The retries exponentially increase and stop increasing when a certain threshold is met. - - - - -## Install - -```bash -go get github.com/cenkalti/backoff -``` - -## Example - -Simple retry helper that uses exponential back-off algorithm: - -```go -operation := func() error { - // An operation that might fail -} - -err := backoff.Retry(operation, backoff.NewExponentialBackOff()) -if err != nil { - // handle error -} - -// operation is successfull -``` - -Ticker example: - -```go -operation := func() error { - // An operation that may fail -} - -b := backoff.NewExponentialBackOff() -ticker := backoff.NewTicker(b) - -var err error - -// Ticks will continue to arrive when the previous operation is still running, -// so operations that take a while to fail could run in quick succession. -for t = range ticker.C { - if err = operation(); err != nil { - log.Println(err, "will retry...") - continue - } - - ticker.Stop() - break -} - -if err != nil { - // Operation has failed. -} - -// Operation is successfull. -``` diff --git a/Godeps/_workspace/src/github.com/cenkalti/backoff/backoff.go b/Godeps/_workspace/src/github.com/cenkalti/backoff/backoff.go deleted file mode 100644 index 25870d2fc89..00000000000 --- a/Godeps/_workspace/src/github.com/cenkalti/backoff/backoff.go +++ /dev/null @@ -1,56 +0,0 @@ -// Package backoff implements backoff algorithms for retrying operations. -// -// Also has a Retry() helper for retrying operations that may fail. -package backoff - -import "time" - -// Back-off policy when retrying an operation. -type BackOff interface { - // Gets the duration to wait before retrying the operation or - // backoff.Stop to indicate that no retries should be made. - // - // Example usage: - // - // duration := backoff.NextBackOff(); - // if (duration == backoff.Stop) { - // // do not retry operation - // } else { - // // sleep for duration and retry operation - // } - // - NextBackOff() time.Duration - - // Reset to initial state. - Reset() -} - -// Indicates that no more retries should be made for use in NextBackOff(). -const Stop time.Duration = -1 - -// ZeroBackOff is a fixed back-off policy whose back-off time is always zero, -// meaning that the operation is retried immediately without waiting. -type ZeroBackOff struct{} - -func (b *ZeroBackOff) Reset() {} - -func (b *ZeroBackOff) NextBackOff() time.Duration { return 0 } - -// StopBackOff is a fixed back-off policy that always returns backoff.Stop for -// NextBackOff(), meaning that the operation should not be retried. -type StopBackOff struct{} - -func (b *StopBackOff) Reset() {} - -func (b *StopBackOff) NextBackOff() time.Duration { return Stop } - -type ConstantBackOff struct { - Interval time.Duration -} - -func (b *ConstantBackOff) Reset() {} -func (b *ConstantBackOff) NextBackOff() time.Duration { return b.Interval } - -func NewConstantBackOff(d time.Duration) *ConstantBackOff { - return &ConstantBackOff{Interval: d} -} diff --git a/Godeps/_workspace/src/github.com/cenkalti/backoff/backoff_test.go b/Godeps/_workspace/src/github.com/cenkalti/backoff/backoff_test.go deleted file mode 100644 index 24c49947bbc..00000000000 --- a/Godeps/_workspace/src/github.com/cenkalti/backoff/backoff_test.go +++ /dev/null @@ -1,28 +0,0 @@ -package backoff - -import ( - "time" - - "testing" -) - -func TestNextBackOffMillis(t *testing.T) { - subtestNextBackOff(t, 0, new(ZeroBackOff)) - subtestNextBackOff(t, Stop, new(StopBackOff)) -} - -func subtestNextBackOff(t *testing.T, expectedValue time.Duration, backOffPolicy BackOff) { - for i := 0; i < 10; i++ { - next := backOffPolicy.NextBackOff() - if next != expectedValue { - t.Errorf("got: %d expected: %d", next, expectedValue) - } - } -} - -func TestConstantBackOff(t *testing.T) { - backoff := NewConstantBackOff(time.Second) - if backoff.NextBackOff() != time.Second { - t.Error("invalid interval") - } -} diff --git a/Godeps/_workspace/src/github.com/cenkalti/backoff/exponential.go b/Godeps/_workspace/src/github.com/cenkalti/backoff/exponential.go deleted file mode 100644 index de75e85847d..00000000000 --- a/Godeps/_workspace/src/github.com/cenkalti/backoff/exponential.go +++ /dev/null @@ -1,141 +0,0 @@ -package backoff - -import ( - "math/rand" - "time" -) - -/* -ExponentialBackOff is an implementation of BackOff that increases the back off -period for each retry attempt using a randomization function that grows exponentially. - -NextBackOff() is calculated using the following formula: - - randomized_interval = - retry_interval * (random value in range [1 - randomization_factor, 1 + randomization_factor]) - -In other words NextBackOff() will range between the randomization factor -percentage below and above the retry interval. For example, using 2 seconds as the base retry -interval and 0.5 as the randomization factor, the actual back off period used in the next retry -attempt will be between 1 and 3 seconds. - -NOTE: max_interval caps the retry_interval and not the randomized_interval. - -If the time elapsed since an ExponentialBackOff instance is created goes past the -max_elapsed_time then the method NextBackOff() starts returning backoff.Stop. -The elapsed time can be reset by calling Reset(). - -EXAMPLE: The default retry_interval is .5 seconds, default randomization_factor is 0.5, default -multiplier is 1.5 and the default max_interval is 1 minute. For 10 tries the sequence will be -(values in seconds) and assuming we go over the max_elapsed_time on the 10th try: - - request# retry_interval randomized_interval - - 1 0.5 [0.25, 0.75] - 2 0.75 [0.375, 1.125] - 3 1.125 [0.562, 1.687] - 4 1.687 [0.8435, 2.53] - 5 2.53 [1.265, 3.795] - 6 3.795 [1.897, 5.692] - 7 5.692 [2.846, 8.538] - 8 8.538 [4.269, 12.807] - 9 12.807 [6.403, 19.210] - 10 19.210 backoff.Stop - -Implementation is not thread-safe. -*/ -type ExponentialBackOff struct { - InitialInterval time.Duration - RandomizationFactor float64 - Multiplier float64 - MaxInterval time.Duration - // After MaxElapsedTime the ExponentialBackOff stops. - // It never stops if MaxElapsedTime == 0. - MaxElapsedTime time.Duration - Clock Clock - - currentInterval time.Duration - startTime time.Time -} - -// Clock is an interface that returns current time for BackOff. -type Clock interface { - Now() time.Time -} - -// Default values for ExponentialBackOff. -const ( - DefaultInitialInterval = 500 * time.Millisecond - DefaultRandomizationFactor = 0.5 - DefaultMultiplier = 1.5 - DefaultMaxInterval = 60 * time.Second - DefaultMaxElapsedTime = 15 * time.Minute -) - -// NewExponentialBackOff creates an instance of ExponentialBackOff using default values. -func NewExponentialBackOff() *ExponentialBackOff { - return &ExponentialBackOff{ - InitialInterval: DefaultInitialInterval, - RandomizationFactor: DefaultRandomizationFactor, - Multiplier: DefaultMultiplier, - MaxInterval: DefaultMaxInterval, - MaxElapsedTime: DefaultMaxElapsedTime, - Clock: SystemClock, - } -} - -type systemClock struct{} - -func (t systemClock) Now() time.Time { - return time.Now() -} - -// SystemClock implements Clock interface that uses time.Now(). -var SystemClock = systemClock{} - -// Reset the interval back to the initial retry interval and restarts the timer. -func (b *ExponentialBackOff) Reset() { - b.currentInterval = b.InitialInterval - b.startTime = b.Clock.Now() -} - -// NextBackOff calculates the next back off interval using the formula: -// randomized_interval = retry_interval +/- (randomization_factor * retry_interval) -func (b *ExponentialBackOff) NextBackOff() time.Duration { - // Make sure we have not gone over the maximum elapsed time. - if b.MaxElapsedTime != 0 && b.GetElapsedTime() > b.MaxElapsedTime { - return Stop - } - defer b.incrementCurrentInterval() - return getRandomValueFromInterval(b.RandomizationFactor, rand.Float64(), b.currentInterval) -} - -// GetElapsedTime returns the elapsed time since an ExponentialBackOff instance -// is created and is reset when Reset() is called. -// -// The elapsed time is computed using time.Now().UnixNano(). -func (b *ExponentialBackOff) GetElapsedTime() time.Duration { - return b.Clock.Now().Sub(b.startTime) -} - -// Increments the current interval by multiplying it with the multiplier. -func (b *ExponentialBackOff) incrementCurrentInterval() { - // Check for overflow, if overflow is detected set the current interval to the max interval. - if float64(b.currentInterval) >= float64(b.MaxInterval)/b.Multiplier { - b.currentInterval = b.MaxInterval - } else { - b.currentInterval = time.Duration(float64(b.currentInterval) * b.Multiplier) - } -} - -// Returns a random value from the interval: -// [randomizationFactor * currentInterval, randomizationFactor * currentInterval]. -func getRandomValueFromInterval(randomizationFactor, random float64, currentInterval time.Duration) time.Duration { - var delta = randomizationFactor * float64(currentInterval) - var minInterval = float64(currentInterval) - delta - var maxInterval = float64(currentInterval) + delta - // Get a random value from the range [minInterval, maxInterval]. - // The formula used below has a +1 because if the minInterval is 1 and the maxInterval is 3 then - // we want a 33% chance for selecting either 1, 2 or 3. - return time.Duration(minInterval + (random * (maxInterval - minInterval + 1))) -} diff --git a/Godeps/_workspace/src/github.com/cenkalti/backoff/exponential_test.go b/Godeps/_workspace/src/github.com/cenkalti/backoff/exponential_test.go deleted file mode 100644 index 2af22b8bd23..00000000000 --- a/Godeps/_workspace/src/github.com/cenkalti/backoff/exponential_test.go +++ /dev/null @@ -1,111 +0,0 @@ -package backoff - -import ( - "math" - "testing" - "time" -) - -func TestBackOff(t *testing.T) { - var ( - testInitialInterval = 500 * time.Millisecond - testRandomizationFactor = 0.1 - testMultiplier = 2.0 - testMaxInterval = 5 * time.Second - testMaxElapsedTime = 15 * time.Minute - ) - - exp := NewExponentialBackOff() - exp.InitialInterval = testInitialInterval - exp.RandomizationFactor = testRandomizationFactor - exp.Multiplier = testMultiplier - exp.MaxInterval = testMaxInterval - exp.MaxElapsedTime = testMaxElapsedTime - exp.Reset() - - var expectedResults = []time.Duration{500, 1000, 2000, 4000, 5000, 5000, 5000, 5000, 5000, 5000} - for i, d := range expectedResults { - expectedResults[i] = d * time.Millisecond - } - - for _, expected := range expectedResults { - assertEquals(t, expected, exp.currentInterval) - // Assert that the next back off falls in the expected range. - var minInterval = expected - time.Duration(testRandomizationFactor*float64(expected)) - var maxInterval = expected + time.Duration(testRandomizationFactor*float64(expected)) - var actualInterval = exp.NextBackOff() - if !(minInterval <= actualInterval && actualInterval <= maxInterval) { - t.Error("error") - } - } -} - -func TestGetRandomizedInterval(t *testing.T) { - // 33% chance of being 1. - assertEquals(t, 1, getRandomValueFromInterval(0.5, 0, 2)) - assertEquals(t, 1, getRandomValueFromInterval(0.5, 0.33, 2)) - // 33% chance of being 2. - assertEquals(t, 2, getRandomValueFromInterval(0.5, 0.34, 2)) - assertEquals(t, 2, getRandomValueFromInterval(0.5, 0.66, 2)) - // 33% chance of being 3. - assertEquals(t, 3, getRandomValueFromInterval(0.5, 0.67, 2)) - assertEquals(t, 3, getRandomValueFromInterval(0.5, 0.99, 2)) -} - -type TestClock struct { - i time.Duration - start time.Time -} - -func (c *TestClock) Now() time.Time { - t := c.start.Add(c.i) - c.i += time.Second - return t -} - -func TestGetElapsedTime(t *testing.T) { - var exp = NewExponentialBackOff() - exp.Clock = &TestClock{} - exp.Reset() - - var elapsedTime = exp.GetElapsedTime() - if elapsedTime != time.Second { - t.Errorf("elapsedTime=%d", elapsedTime) - } -} - -func TestMaxElapsedTime(t *testing.T) { - var exp = NewExponentialBackOff() - exp.Clock = &TestClock{start: time.Time{}.Add(10000 * time.Second)} - if exp.NextBackOff() != Stop { - t.Error("error2") - } - // Change the currentElapsedTime to be 0 ensuring that the elapsed time will be greater - // than the max elapsed time. - exp.startTime = time.Time{} - assertEquals(t, Stop, exp.NextBackOff()) -} - -func TestBackOffOverflow(t *testing.T) { - var ( - testInitialInterval time.Duration = math.MaxInt64 / 2 - testMaxInterval time.Duration = math.MaxInt64 - testMultiplier float64 = 2.1 - ) - - exp := NewExponentialBackOff() - exp.InitialInterval = testInitialInterval - exp.Multiplier = testMultiplier - exp.MaxInterval = testMaxInterval - exp.Reset() - - exp.NextBackOff() - // Assert that when an overflow is possible the current varerval time.Duration is set to the max varerval time.Duration . - assertEquals(t, testMaxInterval, exp.currentInterval) -} - -func assertEquals(t *testing.T, expected, value time.Duration) { - if expected != value { - t.Errorf("got: %d, expected: %d", value, expected) - } -} diff --git a/Godeps/_workspace/src/github.com/cenkalti/backoff/retry.go b/Godeps/_workspace/src/github.com/cenkalti/backoff/retry.go deleted file mode 100644 index 80c54776789..00000000000 --- a/Godeps/_workspace/src/github.com/cenkalti/backoff/retry.go +++ /dev/null @@ -1,47 +0,0 @@ -package backoff - -import "time" - -// Retry the function f until it does not return error or BackOff stops. -// f is guaranteed to be run at least once. -// It is the caller's responsibility to reset b after Retry returns. -// -// Retry sleeps the goroutine for the duration returned by BackOff after a -// failed operation returns. -// -// Usage: -// operation := func() error { -// // An operation that may fail -// } -// -// err := backoff.Retry(operation, backoff.NewExponentialBackOff()) -// if err != nil { -// // Operation has failed. -// } -// -// // Operation is successfull. -// -func Retry(f func() error, b BackOff) error { return RetryNotify(f, b, nil) } - -// RetryNotify calls notify function with the error and wait duration for each failed attempt before sleep. -func RetryNotify(f func() error, b BackOff, notify func(err error, wait time.Duration)) error { - var err error - var next time.Duration - - b.Reset() - for { - if err = f(); err == nil { - return nil - } - - if next = b.NextBackOff(); next == Stop { - return err - } - - if notify != nil { - notify(err, next) - } - - time.Sleep(next) - } -} diff --git a/Godeps/_workspace/src/github.com/cenkalti/backoff/retry_test.go b/Godeps/_workspace/src/github.com/cenkalti/backoff/retry_test.go deleted file mode 100644 index c0d25ab766e..00000000000 --- a/Godeps/_workspace/src/github.com/cenkalti/backoff/retry_test.go +++ /dev/null @@ -1,34 +0,0 @@ -package backoff - -import ( - "errors" - "log" - "testing" -) - -func TestRetry(t *testing.T) { - const successOn = 3 - var i = 0 - - // This function is successfull on "successOn" calls. - f := func() error { - i++ - log.Printf("function is called %d. time\n", i) - - if i == successOn { - log.Println("OK") - return nil - } - - log.Println("error") - return errors.New("error") - } - - err := Retry(f, NewExponentialBackOff()) - if err != nil { - t.Errorf("unexpected error: %s", err.Error()) - } - if i != successOn { - t.Errorf("invalid number of retries: %d", i) - } -} diff --git a/Godeps/_workspace/src/github.com/cenkalti/backoff/ticker.go b/Godeps/_workspace/src/github.com/cenkalti/backoff/ticker.go deleted file mode 100644 index 17ace566001..00000000000 --- a/Godeps/_workspace/src/github.com/cenkalti/backoff/ticker.go +++ /dev/null @@ -1,105 +0,0 @@ -package backoff - -import ( - "runtime" - "sync" - "time" -) - -// Ticker holds a channel that delivers `ticks' of a clock at times reported by a BackOff. -// -// Ticks will continue to arrive when the previous operation is still running, -// so operations that take a while to fail could run in quick succession. -// -// Usage: -// operation := func() error { -// // An operation that may fail -// } -// -// b := backoff.NewExponentialBackOff() -// ticker := backoff.NewTicker(b) -// -// var err error -// for _ = range ticker.C { -// if err = operation(); err != nil { -// log.Println(err, "will retry...") -// continue -// } -// -// ticker.Stop() -// break -// } -// -// if err != nil { -// // Operation has failed. -// } -// -// // Operation is successfull. -// -type Ticker struct { - C <-chan time.Time - c chan time.Time - b BackOff - stop chan struct{} - stopOnce sync.Once -} - -// NewTicker returns a new Ticker containing a channel that will send the time at times -// specified by the BackOff argument. Ticker is guaranteed to tick at least once. -// The channel is closed when Stop method is called or BackOff stops. -func NewTicker(b BackOff) *Ticker { - c := make(chan time.Time) - t := &Ticker{ - C: c, - c: c, - b: b, - stop: make(chan struct{}), - } - go t.run() - runtime.SetFinalizer(t, (*Ticker).Stop) - return t -} - -// Stop turns off a ticker. After Stop, no more ticks will be sent. -func (t *Ticker) Stop() { - t.stopOnce.Do(func() { close(t.stop) }) -} - -func (t *Ticker) run() { - c := t.c - defer close(c) - t.b.Reset() - - // Ticker is guaranteed to tick at least once. - afterC := t.send(time.Now()) - - for { - if afterC == nil { - return - } - - select { - case tick := <-afterC: - afterC = t.send(tick) - case <-t.stop: - t.c = nil // Prevent future ticks from being sent to the channel. - return - } - } -} - -func (t *Ticker) send(tick time.Time) <-chan time.Time { - select { - case t.c <- tick: - case <-t.stop: - return nil - } - - next := t.b.NextBackOff() - if next == Stop { - t.Stop() - return nil - } - - return time.After(next) -} diff --git a/Godeps/_workspace/src/github.com/cenkalti/backoff/ticker_test.go b/Godeps/_workspace/src/github.com/cenkalti/backoff/ticker_test.go deleted file mode 100644 index 7c392df46ce..00000000000 --- a/Godeps/_workspace/src/github.com/cenkalti/backoff/ticker_test.go +++ /dev/null @@ -1,45 +0,0 @@ -package backoff - -import ( - "errors" - "log" - "testing" -) - -func TestTicker(t *testing.T) { - const successOn = 3 - var i = 0 - - // This function is successfull on "successOn" calls. - f := func() error { - i++ - log.Printf("function is called %d. time\n", i) - - if i == successOn { - log.Println("OK") - return nil - } - - log.Println("error") - return errors.New("error") - } - - b := NewExponentialBackOff() - ticker := NewTicker(b) - - var err error - for _ = range ticker.C { - if err = f(); err != nil { - t.Log(err) - continue - } - - break - } - if err != nil { - t.Errorf("unexpected error: %s", err.Error()) - } - if i != successOn { - t.Errorf("invalid number of retries: %d", i) - } -} diff --git a/exchange/reprovide/reprovide.go b/exchange/reprovide/reprovide.go index 51809a74b2e..5cd3041b9ce 100644 --- a/exchange/reprovide/reprovide.go +++ b/exchange/reprovide/reprovide.go @@ -4,9 +4,9 @@ import ( "fmt" "time" - backoff "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/cenkalti/backoff" blocks "github.com/ipfs/go-ipfs/blocks/blockstore" routing "github.com/ipfs/go-ipfs/routing" + backoff "gx/ipfs/QmPJUtEJsm5YLUWhF6imvyCH8KZXRJa9Wup7FDMwTy5Ufz/backoff" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" logging "gx/ipfs/QmaDNZ4QMdBdku1YZWBysufYyoQt1negQGNav6PLYarbY8/go-log" ) diff --git a/package.json b/package.json index 9b123e0df6f..b92849a2eb3 100644 --- a/package.json +++ b/package.json @@ -81,6 +81,12 @@ "hash": "QmeWQMDa5dSdP4n8WDeoY5z8L2EKVqF4ZvK4VEHsLqXsGu", "name": "hamming", "version": "0.0.10" + }, + { + "author": "cenk", + "hash": "QmPJUtEJsm5YLUWhF6imvyCH8KZXRJa9Wup7FDMwTy5Ufz", + "name": "backoff", + "version": "1.0.0" } ], "gxVersion": "0.4.0", From c5e361a25fc86be25eab46f125a81d472e24a578 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Thu, 19 May 2016 12:17:18 +0200 Subject: [PATCH 3/5] Remove goautogen from Godeps.json License: MIT Signed-off-by: Jakub Sztandera --- Godeps/Godeps.json | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 36229da174c..56e17a6fac9 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -9,11 +9,6 @@ "ImportPath": "bazil.org/fuse", "Rev": "e4fcc9a2c7567d1c42861deebeb483315d222262" }, - { - "ImportPath": "bitbucket.org/ww/goautoneg", - "Comment": "null-5", - "Rev": "75cd24fc2f2c2a2088577d12123ddee5f54e0675" - }, { "ImportPath": "github.com/bren2010/proquint", "Rev": "5958552242606512f714d2e93513b380f43f9991" From f96bf86fe4dbf632d1c7e88eba9ddeb1a9368df7 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Thu, 19 May 2016 12:33:04 +0200 Subject: [PATCH 4/5] Move proquint from Godeps to gx License: MIT Signed-off-by: Jakub Sztandera --- Godeps/Godeps.json | 4 - .../github.com/bren2010/proquint/README.md | 6 - .../github.com/bren2010/proquint/proquint.go | 123 ------------------ namesys/proquint.go | 2 +- package.json | 14 +- 5 files changed, 11 insertions(+), 138 deletions(-) delete mode 100644 Godeps/_workspace/src/github.com/bren2010/proquint/README.md delete mode 100644 Godeps/_workspace/src/github.com/bren2010/proquint/proquint.go diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 56e17a6fac9..addb7c2436c 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -9,10 +9,6 @@ "ImportPath": "bazil.org/fuse", "Rev": "e4fcc9a2c7567d1c42861deebeb483315d222262" }, - { - "ImportPath": "github.com/bren2010/proquint", - "Rev": "5958552242606512f714d2e93513b380f43f9991" - }, { "ImportPath": "github.com/briantigerchow/pubsub", "Rev": "39ce5f556423a4c7223b370fa17a3bbd75b2d197" diff --git a/Godeps/_workspace/src/github.com/bren2010/proquint/README.md b/Godeps/_workspace/src/github.com/bren2010/proquint/README.md deleted file mode 100644 index 13e7b0b5eba..00000000000 --- a/Godeps/_workspace/src/github.com/bren2010/proquint/README.md +++ /dev/null @@ -1,6 +0,0 @@ -Proquint -------- - -Golang implementation of [Proquint Pronounceable Identifiers](https://github.com/deoxxa/proquint). - - diff --git a/Godeps/_workspace/src/github.com/bren2010/proquint/proquint.go b/Godeps/_workspace/src/github.com/bren2010/proquint/proquint.go deleted file mode 100644 index 60e1cf9816f..00000000000 --- a/Godeps/_workspace/src/github.com/bren2010/proquint/proquint.go +++ /dev/null @@ -1,123 +0,0 @@ -/* -Copyright (c) 2014 Brendan McMillion - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -package proquint - -import ( - "bytes" - "strings" - "regexp" -) - -var ( - conse = [...]byte{'b', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', - 'p', 'r', 's', 't', 'v', 'z'} - vowse = [...]byte{'a', 'i', 'o', 'u'} - - consd = map[byte] uint16 { - 'b' : 0, 'd' : 1, 'f' : 2, 'g' : 3, - 'h' : 4, 'j' : 5, 'k' : 6, 'l' : 7, - 'm' : 8, 'n' : 9, 'p' : 10, 'r' : 11, - 's' : 12, 't' : 13, 'v' : 14, 'z' : 15, - } - - vowsd = map[byte] uint16 { - 'a' : 0, 'i' : 1, 'o' : 2, 'u' : 3, - } -) - -/** -* Tests if a given string is a Proquint identifier -* -* @param {string} str The candidate string. -* -* @return {bool} Whether or not it qualifies. -* @return {error} Error -*/ -func IsProquint(str string) (bool, error) { - exp := "^([abdfghijklmnoprstuvz]{5}-)*[abdfghijklmnoprstuvz]{5}$" - ok, err := regexp.MatchString(exp, str) - - return ok, err -} - -/** -* Encodes an arbitrary byte slice into an identifier. -* -* @param {[]byte} buf Slice of bytes to encode. -* -* @return {string} The given byte slice as an identifier. -*/ -func Encode(buf []byte) string { - var out bytes.Buffer - - for i := 0; i < len(buf); i = i + 2 { - var n uint16 = (uint16(buf[i]) * 256) + uint16(buf[i + 1]) - - var ( - c1 = n & 0x0f - v1 = (n >> 4) & 0x03 - c2 = (n >> 6) & 0x0f - v2 = (n >> 10) & 0x03 - c3 = (n >> 12) & 0x0f - ) - - out.WriteByte(conse[c1]) - out.WriteByte(vowse[v1]) - out.WriteByte(conse[c2]) - out.WriteByte(vowse[v2]) - out.WriteByte(conse[c3]) - - if (i + 2) < len(buf) { - out.WriteByte('-') - } - } - - return out.String() -} - -/** -* Decodes an identifier into its corresponding byte slice. -* -* @param {string} str Identifier to convert. -* -* @return {[]byte} The identifier as a byte slice. -*/ -func Decode(str string) []byte { - var ( - out bytes.Buffer - bits []string = strings.Split(str, "-") - ) - - for i := 0; i < len(bits); i++ { - var x uint16 = consd[bits[i][0]] + - (vowsd[bits[i][1]] << 4) + - (consd[bits[i][2]] << 6) + - (vowsd[bits[i][3]] << 10) + - (consd[bits[i][4]] << 12) - - out.WriteByte(byte(x >> 8)) - out.WriteByte(byte(x)) - } - - return out.Bytes() -} diff --git a/namesys/proquint.go b/namesys/proquint.go index ce17181e83f..f90a4c8a1e1 100644 --- a/namesys/proquint.go +++ b/namesys/proquint.go @@ -3,8 +3,8 @@ package namesys import ( "errors" - proquint "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/bren2010/proquint" path "github.com/ipfs/go-ipfs/path" + proquint "gx/ipfs/QmYnf27kzqR2cxt6LFZdrAFJuQd6785fTkBvMuEj9EeRxM/proquint" context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context" ) diff --git a/package.json b/package.json index b92849a2eb3..ae0ae312f3f 100644 --- a/package.json +++ b/package.json @@ -75,18 +75,24 @@ "hash": "QmcyaFHbyiZfoX5GTpcqqCPYmbjYNAhRDekXSJPFHdYNSV", "name": "go.uuid", "version": "1.0.0" - }, - { + }, + { "author": "steakknife", "hash": "QmeWQMDa5dSdP4n8WDeoY5z8L2EKVqF4ZvK4VEHsLqXsGu", "name": "hamming", "version": "0.0.10" - }, - { + }, + { "author": "cenk", "hash": "QmPJUtEJsm5YLUWhF6imvyCH8KZXRJa9Wup7FDMwTy5Ufz", "name": "backoff", "version": "1.0.0" + }, + { + "author": "Bren2010", + "hash": "QmYnf27kzqR2cxt6LFZdrAFJuQd6785fTkBvMuEj9EeRxM", + "name": "proquint", + "version": "0.0.0" } ], "gxVersion": "0.4.0", From e1b6e3dd6acce84928f7e8e03fe4bc8132e3fc0b Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Thu, 19 May 2016 12:45:11 +0200 Subject: [PATCH 5/5] Remove blowfish from Godeps.json License: MIT Signed-off-by: Jakub Sztandera --- Godeps/Godeps.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index addb7c2436c..57e2264d5f4 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -175,10 +175,6 @@ "ImportPath": "github.com/whyrusleeping/multiaddr-filter", "Rev": "9e26222151125ecd3fc1fd190179b6bdd55f5608" }, - { - "ImportPath": "golang.org/x/crypto/blowfish", - "Rev": "c84e1f8e3a7e322d497cd16c0e8a13c7e127baf3" - }, { "ImportPath": "golang.org/x/crypto/sha3", "Rev": "c84e1f8e3a7e322d497cd16c0e8a13c7e127baf3"