mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 10:27:46 +08:00
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>
This commit is contained in:
parent
190524b050
commit
fd04905adb
@ -5,7 +5,7 @@ import (
|
||||
bitswap "github.com/ipfs/go-ipfs/exchange/bitswap"
|
||||
tn "github.com/ipfs/go-ipfs/exchange/bitswap/testnet"
|
||||
mockrouting "github.com/ipfs/go-ipfs/routing/mock"
|
||||
delay "github.com/ipfs/go-ipfs/thirdparty/delay"
|
||||
delay "gx/ipfs/QmRJVNatYJwTAHgdSM1Xef9QVQ1Ch3XHdmcrykjP5Y4soL/go-ipfs-delay"
|
||||
)
|
||||
|
||||
// Mocks returns |n| connected mock Blockservices
|
||||
|
||||
@ -10,15 +10,16 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"gx/ipfs/QmRJVNatYJwTAHgdSM1Xef9QVQ1Ch3XHdmcrykjP5Y4soL/go-ipfs-delay"
|
||||
|
||||
blockstore "github.com/ipfs/go-ipfs/blocks/blockstore"
|
||||
exchange "github.com/ipfs/go-ipfs/exchange"
|
||||
decision "github.com/ipfs/go-ipfs/exchange/bitswap/decision"
|
||||
bsmsg "github.com/ipfs/go-ipfs/exchange/bitswap/message"
|
||||
bsnet "github.com/ipfs/go-ipfs/exchange/bitswap/network"
|
||||
notifications "github.com/ipfs/go-ipfs/exchange/bitswap/notifications"
|
||||
flags "github.com/ipfs/go-ipfs/flags"
|
||||
"github.com/ipfs/go-ipfs/thirdparty/delay"
|
||||
|
||||
flags "gx/ipfs/QmRMGdC6HKdLsPDABL9aXPDidrpmEHzJqFWSvshkbn9Hj8/go-ipfs-flags"
|
||||
logging "gx/ipfs/QmRb5jh8z2E8hMGN2tkvs1yHynUanqnZ3UeKwgN1i9P1F8/go-log"
|
||||
metrics "gx/ipfs/QmRg1gKTHzc3CZXSKzem8aR4E3TubFhbgXwfVuWnSK5CC5/go-metrics-interface"
|
||||
process "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess"
|
||||
|
||||
@ -13,7 +13,7 @@ import (
|
||||
decision "github.com/ipfs/go-ipfs/exchange/bitswap/decision"
|
||||
tn "github.com/ipfs/go-ipfs/exchange/bitswap/testnet"
|
||||
mockrouting "github.com/ipfs/go-ipfs/routing/mock"
|
||||
delay "github.com/ipfs/go-ipfs/thirdparty/delay"
|
||||
delay "gx/ipfs/QmRJVNatYJwTAHgdSM1Xef9QVQ1Ch3XHdmcrykjP5Y4soL/go-ipfs-delay"
|
||||
|
||||
tu "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil"
|
||||
travis "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil/ci/travis"
|
||||
|
||||
@ -8,7 +8,7 @@ import (
|
||||
bsmsg "github.com/ipfs/go-ipfs/exchange/bitswap/message"
|
||||
bsnet "github.com/ipfs/go-ipfs/exchange/bitswap/network"
|
||||
mockrouting "github.com/ipfs/go-ipfs/routing/mock"
|
||||
delay "github.com/ipfs/go-ipfs/thirdparty/delay"
|
||||
delay "gx/ipfs/QmRJVNatYJwTAHgdSM1Xef9QVQ1Ch3XHdmcrykjP5Y4soL/go-ipfs-delay"
|
||||
testutil "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil"
|
||||
peer "gx/ipfs/QmZoWKhxUmZ2seW4BzX6fJkNR8hh9PsGModr7q171yq2SS/go-libp2p-peer"
|
||||
blocks "gx/ipfs/Qmej7nf81hi2x2tvjRBF3mcp74sQyuDH4VMYDGd1YtXjb2/go-block-format"
|
||||
|
||||
@ -8,7 +8,7 @@ import (
|
||||
bsmsg "github.com/ipfs/go-ipfs/exchange/bitswap/message"
|
||||
bsnet "github.com/ipfs/go-ipfs/exchange/bitswap/network"
|
||||
mockrouting "github.com/ipfs/go-ipfs/routing/mock"
|
||||
delay "github.com/ipfs/go-ipfs/thirdparty/delay"
|
||||
delay "gx/ipfs/QmRJVNatYJwTAHgdSM1Xef9QVQ1Ch3XHdmcrykjP5Y4soL/go-ipfs-delay"
|
||||
|
||||
logging "gx/ipfs/QmRb5jh8z2E8hMGN2tkvs1yHynUanqnZ3UeKwgN1i9P1F8/go-log"
|
||||
routing "gx/ipfs/QmTiWLZ6Fo5j4KcTVutZJ5KWRRJrbxzmxA4td8NfEdrPh7/go-libp2p-routing"
|
||||
|
||||
@ -7,7 +7,7 @@ import (
|
||||
blockstore "github.com/ipfs/go-ipfs/blocks/blockstore"
|
||||
tn "github.com/ipfs/go-ipfs/exchange/bitswap/testnet"
|
||||
datastore2 "github.com/ipfs/go-ipfs/thirdparty/datastore2"
|
||||
delay "github.com/ipfs/go-ipfs/thirdparty/delay"
|
||||
delay "gx/ipfs/QmRJVNatYJwTAHgdSM1Xef9QVQ1Ch3XHdmcrykjP5Y4soL/go-ipfs-delay"
|
||||
testutil "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil"
|
||||
|
||||
ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
|
||||
|
||||
@ -1,13 +0,0 @@
|
||||
package flags
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
|
||||
var LowMemMode bool
|
||||
|
||||
func init() {
|
||||
if os.Getenv("IPFS_LOW_MEM") != "" {
|
||||
LowMemMode = true
|
||||
}
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
package flags
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// This variable is initialized before flags init(), so we export the ENV variable here.
|
||||
var _lowMemOn = lowMemOn()
|
||||
|
||||
func lowMemOn() error {
|
||||
os.Setenv("IPFS_LOW_MEM", "true")
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestLowMemMode(t *testing.T) {
|
||||
if !LowMemMode {
|
||||
t.Fatal("LowMemMode does not turn on even with 'IPFS_LOW_MEM' ENV variable set.")
|
||||
}
|
||||
}
|
||||
12
package.json
12
package.json
@ -533,6 +533,18 @@
|
||||
"hash": "Qmf7HqcW7LtCi1W8y2bdx2eJpze74jkbKqpByxgXikdbLF",
|
||||
"name": "go-detect-race",
|
||||
"version": "1.0.1"
|
||||
},
|
||||
{
|
||||
"author": "hsanjuan",
|
||||
"hash": "QmRJVNatYJwTAHgdSM1Xef9QVQ1Ch3XHdmcrykjP5Y4soL",
|
||||
"name": "go-ipfs-delay",
|
||||
"version": "0.0.1"
|
||||
},
|
||||
{
|
||||
"author": "hector",
|
||||
"hash": "QmRMGdC6HKdLsPDABL9aXPDidrpmEHzJqFWSvshkbn9Hj8",
|
||||
"name": "go-ipfs-flags",
|
||||
"version": "0.0.1"
|
||||
}
|
||||
],
|
||||
"gxVersion": "0.10.0",
|
||||
|
||||
@ -5,7 +5,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
delay "github.com/ipfs/go-ipfs/thirdparty/delay"
|
||||
delay "gx/ipfs/QmRJVNatYJwTAHgdSM1Xef9QVQ1Ch3XHdmcrykjP5Y4soL/go-ipfs-delay"
|
||||
|
||||
u "gx/ipfs/QmNiJuT8Ja3hMVpBHXv3Q6dwmperaQ6JjLtpMQgMCD7xvx/go-ipfs-util"
|
||||
testutil "gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil"
|
||||
|
||||
@ -7,9 +7,8 @@ package mockrouting
|
||||
import (
|
||||
"context"
|
||||
|
||||
delay "github.com/ipfs/go-ipfs/thirdparty/delay"
|
||||
|
||||
ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
|
||||
delay "gx/ipfs/QmRJVNatYJwTAHgdSM1Xef9QVQ1Ch3XHdmcrykjP5Y4soL/go-ipfs-delay"
|
||||
routing "gx/ipfs/QmTiWLZ6Fo5j4KcTVutZJ5KWRRJrbxzmxA4td8NfEdrPh7/go-libp2p-routing"
|
||||
"gx/ipfs/QmVvkK7s5imCiq3JVbL3pGfnhcCnf3LrFJPF4GE2sAoGZf/go-testutil"
|
||||
peer "gx/ipfs/QmZoWKhxUmZ2seW4BzX6fJkNR8hh9PsGModr7q171yq2SS/go-libp2p-peer"
|
||||
|
||||
2
thirdparty/datastore2/delayed.go
vendored
2
thirdparty/datastore2/delayed.go
vendored
@ -4,7 +4,7 @@ import (
|
||||
ds "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore"
|
||||
dsq "gx/ipfs/QmPpegoMqhAEqjncrzArm7KVWAkCm78rqL2DPuNjhPrshg/go-datastore/query"
|
||||
|
||||
delay "github.com/ipfs/go-ipfs/thirdparty/delay"
|
||||
delay "gx/ipfs/QmRJVNatYJwTAHgdSM1Xef9QVQ1Ch3XHdmcrykjP5Y4soL/go-ipfs-delay"
|
||||
)
|
||||
|
||||
func WithDelay(ds ds.Datastore, delay delay.D) ds.Datastore {
|
||||
|
||||
105
thirdparty/delay/delay.go
vendored
105
thirdparty/delay/delay.go
vendored
@ -1,105 +0,0 @@
|
||||
package delay
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var sharedRNG = rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
|
||||
// Delay makes it easy to add (threadsafe) configurable delays to other
|
||||
// objects.
|
||||
type D interface {
|
||||
Set(time.Duration) time.Duration
|
||||
Wait()
|
||||
Get() time.Duration
|
||||
}
|
||||
|
||||
// Fixed returns a delay with fixed latency
|
||||
func Fixed(t time.Duration) D {
|
||||
return &delay{t: t}
|
||||
}
|
||||
|
||||
type delay struct {
|
||||
l sync.RWMutex
|
||||
t time.Duration
|
||||
}
|
||||
|
||||
func (d *delay) Set(t time.Duration) time.Duration {
|
||||
d.l.Lock()
|
||||
defer d.l.Unlock()
|
||||
prev := d.t
|
||||
d.t = t
|
||||
return prev
|
||||
}
|
||||
|
||||
func (d *delay) Wait() {
|
||||
d.l.RLock()
|
||||
defer d.l.RUnlock()
|
||||
time.Sleep(d.t)
|
||||
}
|
||||
|
||||
func (d *delay) Get() time.Duration {
|
||||
d.l.Lock()
|
||||
defer d.l.Unlock()
|
||||
return d.t
|
||||
}
|
||||
|
||||
// VariableNormal is a delay following a normal distribution
|
||||
// Notice that to implement the D interface Set can only change the mean delay
|
||||
// the standard deviation is set only at initialization
|
||||
func VariableNormal(t, std time.Duration, rng *rand.Rand) D {
|
||||
if rng == nil {
|
||||
rng = sharedRNG
|
||||
}
|
||||
|
||||
v := &variableNormal{
|
||||
std: std,
|
||||
rng: rng,
|
||||
}
|
||||
v.t = t
|
||||
return v
|
||||
}
|
||||
|
||||
type variableNormal struct {
|
||||
delay
|
||||
std time.Duration
|
||||
rng *rand.Rand
|
||||
}
|
||||
|
||||
func (d *variableNormal) Wait() {
|
||||
d.l.RLock()
|
||||
defer d.l.RUnlock()
|
||||
randomDelay := time.Duration(d.rng.NormFloat64() * float64(d.std))
|
||||
time.Sleep(randomDelay + d.t)
|
||||
}
|
||||
|
||||
// VariableUniform is a delay following a uniform distribution
|
||||
// Notice that to implement the D interface Set can only change the minimum delay
|
||||
// the delta is set only at initialization
|
||||
func VariableUniform(t, d time.Duration, rng *rand.Rand) D {
|
||||
if rng == nil {
|
||||
rng = sharedRNG
|
||||
}
|
||||
|
||||
v := &variableUniform{
|
||||
d: d,
|
||||
rng: rng,
|
||||
}
|
||||
v.t = t
|
||||
return v
|
||||
}
|
||||
|
||||
type variableUniform struct {
|
||||
delay
|
||||
d time.Duration // max delta
|
||||
rng *rand.Rand
|
||||
}
|
||||
|
||||
func (d *variableUniform) Wait() {
|
||||
d.l.RLock()
|
||||
defer d.l.RUnlock()
|
||||
randomDelay := time.Duration(d.rng.Float64() * float64(d.d))
|
||||
time.Sleep(randomDelay + d.t)
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user