提交 ffc9abb8 作者: Łukasz Magiera

reprovide: fix ipfs bitswap reprovide when interval set to 0

License: MIT
Signed-off-by: 's avatarŁukasz Magiera <magik6k@gmail.com>
上级 b6eb0850
...@@ -283,20 +283,18 @@ func (n *IpfsNode) startLateOnlineServices(ctx context.Context) error { ...@@ -283,20 +283,18 @@ func (n *IpfsNode) startLateOnlineServices(ctx context.Context) error {
} }
n.Reprovider = rp.NewReprovider(ctx, n.Routing, keyProvider) n.Reprovider = rp.NewReprovider(ctx, n.Routing, keyProvider)
if cfg.Reprovider.Interval != "0" { reproviderInterval := kReprovideFrequency
interval := kReprovideFrequency if cfg.Reprovider.Interval != "" {
if cfg.Reprovider.Interval != "" { dur, err := time.ParseDuration(cfg.Reprovider.Interval)
dur, err := time.ParseDuration(cfg.Reprovider.Interval) if err != nil {
if err != nil { return err
return err
}
interval = dur
} }
go n.Reprovider.ProvideEvery(interval) reproviderInterval = dur
} }
go n.Reprovider.Run(reproviderInterval)
return nil return nil
} }
......
...@@ -38,14 +38,18 @@ func NewReprovider(ctx context.Context, rsys routing.ContentRouting, keyProvider ...@@ -38,14 +38,18 @@ func NewReprovider(ctx context.Context, rsys routing.ContentRouting, keyProvider
} }
} }
// ProvideEvery re-provides keys with 'tick' interval // Run re-provides keys with 'tick' interval or when triggered
func (rp *Reprovider) ProvideEvery(tick time.Duration) { func (rp *Reprovider) Run(tick time.Duration) {
// dont reprovide immediately. // dont reprovide immediately.
// may have just started the daemon and shutting it down immediately. // may have just started the daemon and shutting it down immediately.
// probability( up another minute | uptime ) increases with uptime. // probability( up another minute | uptime ) increases with uptime.
after := time.After(time.Minute) after := time.After(time.Minute)
var done doneFunc var done doneFunc
for { for {
if tick == 0 {
after = make(chan time.Time)
}
select { select {
case <-rp.ctx.Done(): case <-rp.ctx.Done():
return return
...@@ -98,7 +102,7 @@ func (rp *Reprovider) Reprovide() error { ...@@ -98,7 +102,7 @@ func (rp *Reprovider) Reprovide() error {
return nil return nil
} }
// Trigger starts reprovision process in rp.ProvideEvery and waits for it // Trigger starts reprovision process in rp.Run and waits for it
func (rp *Reprovider) Trigger(ctx context.Context) error { func (rp *Reprovider) Trigger(ctx context.Context) error {
progressCtx, done := context.WithCancel(ctx) progressCtx, done := context.WithCancel(ctx)
......
...@@ -4,8 +4,9 @@ test_description="Test reprovider" ...@@ -4,8 +4,9 @@ test_description="Test reprovider"
. lib/test-lib.sh . lib/test-lib.sh
NUM_NODES=6
init_strategy() { init_strategy() {
NUM_NODES=6
test_expect_success 'init iptb' ' test_expect_success 'init iptb' '
iptb init -f -n $NUM_NODES --bootstrap=none --port=0 iptb init -f -n $NUM_NODES --bootstrap=none --port=0
' '
...@@ -19,7 +20,7 @@ init_strategy() { ...@@ -19,7 +20,7 @@ init_strategy() {
ipfsi 0 config Reprovider.Strategy '$1' ipfsi 0 config Reprovider.Strategy '$1'
' '
startup_cluster 6 --debug startup_cluster ${NUM_NODES}
} }
findprovs_empty() { findprovs_empty() {
...@@ -124,4 +125,29 @@ test_expect_success 'stop peer 1' ' ...@@ -124,4 +125,29 @@ test_expect_success 'stop peer 1' '
iptb stop 1 iptb stop 1
' '
# Test reprovider working with ticking disabled
test_expect_success 'init iptb' '
iptb init -f -n $NUM_NODES --bootstrap=none --port=0
'
test_expect_success 'peer ids' '
PEERID_0=$(iptb get id 0) &&
PEERID_1=$(iptb get id 1)
'
test_expect_success 'Disable reprovider ticking' '
ipfsi 0 config Reprovider.Interval 0
'
startup_cluster ${NUM_NODES}
test_expect_success 'add test object' '
HASH_0=$(echo "foo" | ipfsi 0 add -q --local)
'
findprovs_empty '$HASH_0'
reprovide
findprovs_expect '$HASH_0' '$PEERID_0'
test_done test_done
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论