@cryptotaxi247 / kubo / commits / fd04905ad

Extract: flags and thirdparty/delay submodules

They have been moved to their own repositories: * github.com/ipfs/go-ipfs-delay * github.com/ipfs/go-ipfs-flags History has been preserved. They have been published with gx'ed. Imports have been updated and re-ordered accordingly. License: MIT Signed-off-by: Hector Sanjuan <hector@protocol.ai>

Hector Sanjuan committed Feb 9, 2018 at 14:36 UTC fd04905adbb9945582468909917761fe48b82597
13 files changed +23 -149
blockservice/test/mock.go
+1 -1
@@ -5,7 +5,7 @@ import (
5 bitswap "github.com/ipfs/go-ipfs/exchange/bitswap"
6 tn "github.com/ipfs/go-ipfs/exchange/bitswap/testnet"
7 mockrouting "github.com/ipfs/go-ipfs/routing/mock"
8 - delay "github.com/ipfs/go-ipfs/thirdparty/delay"
8 + delay "gx/ipfs/QmRJVNatYJwTAHgdSM1Xef9QVQ1Ch3XHdmcrykjP5Y4soL/go-ipfs-delay"
9 )
10
11 // Mocks returns |n| connected mock Blockservices
exchange/bitswap/bitswap.go
+3 -2
@@ -10,15 +10,16 @@ import (
10 "sync/atomic"
11 "time"
12
13 + "gx/ipfs/QmRJVNatYJwTAHgdSM1Xef9QVQ1Ch3XHdmcrykjP5Y4soL/go-ipfs-delay"
14 +
15 blockstore "github.com/ipfs/go-ipfs/blocks/blockstore"
16 exchange "github.com/ipfs/go-ipfs/exchange"
17 decision "github.com/ipfs/go-ipfs/exchange/bitswap/decision"
18 bsmsg "github.com/ipfs/go-ipfs/exchange/bitswap/message"
19 bsnet "github.com/ipfs/go-ipfs/exchange/bitswap/network"
20 notifications "github.com/ipfs/go-ipfs/exchange/bitswap/notifications"
19 - flags "github.com/ipfs/go-ipfs/flags"
20 - "github.com/ipfs/go-ipfs/thirdparty/delay"
21
22 + flags "gx/ipfs/QmRMGdC6HKdLsPDABL9aXPDidrpmEHzJqFWSvshkbn9Hj8/go-ipfs-flags"
23 logging "gx/ipfs/QmRb5jh8z2E8hMGN2tkvs1yHynUanqnZ3UeKwgN1i9P1F8/go-log"
24 metrics "gx/ipfs/QmRg1gKTHzc3CZXSKzem8aR4E3TubFhbgXwfVuWnSK5CC5/go-metrics-interface"
25 process "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess"
exchange/bitswap/bitswap_test.go
+1 -1
@@ -13,7 +13,7 @@ import (
13 decision "github.com/ipfs/go-ipfs/exchange/bitswap/decision"
14 tn "github.com/ipfs/go-ipfs/exchange/bitswap/testnet"
15 mockrouting "github.com/ipfs/go-ipfs/routing/mock"
16 - delay "github.com/ipfs/go-ipfs/thirdparty/delay"
16 + delay "gx/ipfs/QmRJVNatYJwTAHgdSM1Xef9QVQ1Ch3XHdmcrykjP5Y4soL/go-ipfs-delay"
17
18 tu "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil"
19 travis "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil/ci/travis"
exchange/bitswap/testnet/network_test.go
+1 -1
@@ -8,7 +8,7 @@ import (
8 bsmsg "github.com/ipfs/go-ipfs/exchange/bitswap/message"
9 bsnet "github.com/ipfs/go-ipfs/exchange/bitswap/network"
10 mockrouting "github.com/ipfs/go-ipfs/routing/mock"
11 - delay "github.com/ipfs/go-ipfs/thirdparty/delay"
11 + delay "gx/ipfs/QmRJVNatYJwTAHgdSM1Xef9QVQ1Ch3XHdmcrykjP5Y4soL/go-ipfs-delay"
12 testutil "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil"
13 peer "gx/ipfs/QmZoWKhxUmZ2seW4BzX6fJkNR8hh9PsGModr7q171yq2SS/go-libp2p-peer"
14 blocks "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format"
exchange/bitswap/testnet/virtual.go
+1 -1
@@ -8,7 +8,7 @@ import (
8 bsmsg "github.com/ipfs/go-ipfs/exchange/bitswap/message"
9 bsnet "github.com/ipfs/go-ipfs/exchange/bitswap/network"
10 mockrouting "github.com/ipfs/go-ipfs/routing/mock"
11 - delay "github.com/ipfs/go-ipfs/thirdparty/delay"
11 + delay "gx/ipfs/QmRJVNatYJwTAHgdSM1Xef9QVQ1Ch3XHdmcrykjP5Y4soL/go-ipfs-delay"
12
13 logging "gx/ipfs/QmRb5jh8z2E8hMGN2tkvs1yHynUanqnZ3UeKwgN1i9P1F8/go-log"
14 routing "gx/ipfs/QmTiWLZ6Fo5j4KcTVutZJ5KWRRJrbxzmxA4td8NfEdrPh7/go-libp2p-routing"
exchange/bitswap/testutils.go
+1 -1
@@ -7,7 +7,7 @@ import (
7 blockstore "github.com/ipfs/go-ipfs/blocks/blockstore"
8 tn "github.com/ipfs/go-ipfs/exchange/bitswap/testnet"
9 datastore2 "github.com/ipfs/go-ipfs/thirdparty/datastore2"
10 - delay "github.com/ipfs/go-ipfs/thirdparty/delay"
10 + delay "gx/ipfs/QmRJVNatYJwTAHgdSM1Xef9QVQ1Ch3XHdmcrykjP5Y4soL/go-ipfs-delay"
11 testutil "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil"
12
13 ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
flags/flags.go deleted
-13
@@ -1,13 +0,0 @@
1 -package flags
2 -
3 -import (
4 - "os"
5 -)
6 -
7 -var LowMemMode bool
8 -
9 -func init() {
10 - if os.Getenv("IPFS_LOW_MEM") != "" {
11 - LowMemMode = true
12 - }
13 -}
flags/flags_test.go deleted
-20
@@ -1,20 +0,0 @@
1 -package flags
2 -
3 -import (
4 - "os"
5 - "testing"
6 -)
7 -
8 -// This variable is initialized before flags init(), so we export the ENV variable here.
9 -var _lowMemOn = lowMemOn()
10 -
11 -func lowMemOn() error {
12 - os.Setenv("IPFS_LOW_MEM", "true")
13 - return nil
14 -}
15 -
16 -func TestLowMemMode(t *testing.T) {
17 - if !LowMemMode {
18 - t.Fatal("LowMemMode does not turn on even with 'IPFS_LOW_MEM' ENV variable set.")
19 - }
20 -}
package.json
+12
@@ -533,6 +533,18 @@
533 "hash": "Qmf7HqcW7LtCi1W8y2bdx2eJpze74jkbKqpByxgXikdbLF",
534 "name": "go-detect-race",
535 "version": "1.0.1"
536 + },
537 + {
538 + "author": "hsanjuan",
539 + "hash": "QmRJVNatYJwTAHgdSM1Xef9QVQ1Ch3XHdmcrykjP5Y4soL",
540 + "name": "go-ipfs-delay",
541 + "version": "0.0.1"
542 + },
543 + {
544 + "author": "hector",
545 + "hash": "QmRMGdC6HKdLsPDABL9aXPDidrpmEHzJqFWSvshkbn9Hj8",
546 + "name": "go-ipfs-flags",
547 + "version": "0.0.1"
548 }
549 ],
550 "gxVersion": "0.10.0",
routing/mock/centralized_test.go
+1 -1
@@ -5,7 +5,7 @@ import (
5 "testing"
6 "time"
7
8 - delay "github.com/ipfs/go-ipfs/thirdparty/delay"
8 + delay "gx/ipfs/QmRJVNatYJwTAHgdSM1Xef9QVQ1Ch3XHdmcrykjP5Y4soL/go-ipfs-delay"
9
10 u "gx/ipfs/QmNiJuT8Ja3hMVpBHXv3Q6dwmperaQ6JjLtpMQgMCD7xvx/go-ipfs-util"
11 testutil "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil"
routing/mock/interface.go
+1 -2
@@ -7,9 +7,8 @@ package mockrouting
7 import (
8 "context"
9
10 - delay "github.com/ipfs/go-ipfs/thirdparty/delay"
11 -
10 ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
11 + delay "gx/ipfs/QmRJVNatYJwTAHgdSM1Xef9QVQ1Ch3XHdmcrykjP5Y4soL/go-ipfs-delay"
12 routing "gx/ipfs/QmTiWLZ6Fo5j4KcTVutZJ5KWRRJrbxzmxA4td8NfEdrPh7/go-libp2p-routing"
13 "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil"
14 peer "gx/ipfs/QmZoWKhxUmZ2seW4BzX6fJkNR8hh9PsGModr7q171yq2SS/go-libp2p-peer"
thirdparty/datastore2/delayed.go
+1 -1
@@ -4,7 +4,7 @@ import (
4 ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
5 dsq "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/query"
6
7 - delay "github.com/ipfs/go-ipfs/thirdparty/delay"
7 + delay "gx/ipfs/QmRJVNatYJwTAHgdSM1Xef9QVQ1Ch3XHdmcrykjP5Y4soL/go-ipfs-delay"
8 )
9
10 func WithDelay(ds ds.Datastore, delay delay.D) ds.Datastore {
thirdparty/delay/delay.go deleted
-105
@@ -1,105 +0,0 @@
1 -package delay
2 -
3 -import (
4 - "math/rand"
5 - "sync"
6 - "time"
7 -)
8 -
9 -var sharedRNG = rand.New(rand.NewSource(time.Now().UnixNano()))
10 -
11 -// Delay makes it easy to add (threadsafe) configurable delays to other
12 -// objects.
13 -type D interface {
14 - Set(time.Duration) time.Duration
15 - Wait()
16 - Get() time.Duration
17 -}
18 -
19 -// Fixed returns a delay with fixed latency
20 -func Fixed(t time.Duration) D {
21 - return &delay{t: t}
22 -}
23 -
24 -type delay struct {
25 - l sync.RWMutex
26 - t time.Duration
27 -}
28 -
29 -func (d *delay) Set(t time.Duration) time.Duration {
30 - d.l.Lock()
31 - defer d.l.Unlock()
32 - prev := d.t
33 - d.t = t
34 - return prev
35 -}
36 -
37 -func (d *delay) Wait() {
38 - d.l.RLock()
39 - defer d.l.RUnlock()
40 - time.Sleep(d.t)
41 -}
42 -
43 -func (d *delay) Get() time.Duration {
44 - d.l.Lock()
45 - defer d.l.Unlock()
46 - return d.t
47 -}
48 -
49 -// VariableNormal is a delay following a normal distribution
50 -// Notice that to implement the D interface Set can only change the mean delay
51 -// the standard deviation is set only at initialization
52 -func VariableNormal(t, std time.Duration, rng *rand.Rand) D {
53 - if rng == nil {
54 - rng = sharedRNG
55 - }
56 -
57 - v := &variableNormal{
58 - std: std,
59 - rng: rng,
60 - }
61 - v.t = t
62 - return v
63 -}
64 -
65 -type variableNormal struct {
66 - delay
67 - std time.Duration
68 - rng *rand.Rand
69 -}
70 -
71 -func (d *variableNormal) Wait() {
72 - d.l.RLock()
73 - defer d.l.RUnlock()
74 - randomDelay := time.Duration(d.rng.NormFloat64() * float64(d.std))
75 - time.Sleep(randomDelay + d.t)
76 -}
77 -
78 -// VariableUniform is a delay following a uniform distribution
79 -// Notice that to implement the D interface Set can only change the minimum delay
80 -// the delta is set only at initialization
81 -func VariableUniform(t, d time.Duration, rng *rand.Rand) D {
82 - if rng == nil {
83 - rng = sharedRNG
84 - }
85 -
86 - v := &variableUniform{
87 - d: d,
88 - rng: rng,
89 - }
90 - v.t = t
91 - return v
92 -}
93 -
94 -type variableUniform struct {
95 - delay
96 - d time.Duration // max delta
97 - rng *rand.Rand
98 -}
99 -
100 -func (d *variableUniform) Wait() {
101 - d.l.RLock()
102 - defer d.l.RUnlock()
103 - randomDelay := time.Duration(d.rng.Float64() * float64(d.d))
104 - time.Sleep(randomDelay + d.t)
105 -}