Commit 9c0f9362 authored by Jeromy Johnson's avatar Jeromy Johnson Committed by GitHub

Merge pull request #4155 from ipfs/fix/reprovider-trigger

reprovide: fix ipfs bitswap reprovide when interval set to 0
parents 8c2166fa ffc9abb8
......@@ -283,20 +283,18 @@ func (n *IpfsNode) startLateOnlineServices(ctx context.Context) error {
}
n.Reprovider = rp.NewReprovider(ctx, n.Routing, keyProvider)
if cfg.Reprovider.Interval != "0" {
interval := kReprovideFrequency
if cfg.Reprovider.Interval != "" {
dur, err := time.ParseDuration(cfg.Reprovider.Interval)
if err != nil {
return err
}
interval = dur
reproviderInterval := kReprovideFrequency
if cfg.Reprovider.Interval != "" {
dur, err := time.ParseDuration(cfg.Reprovider.Interval)
if err != nil {
return err
}
go n.Reprovider.ProvideEvery(interval)
reproviderInterval = dur
}
go n.Reprovider.Run(reproviderInterval)
return nil
}
......
......@@ -38,14 +38,18 @@ func NewReprovider(ctx context.Context, rsys routing.ContentRouting, keyProvider
}
}
// ProvideEvery re-provides keys with 'tick' interval
func (rp *Reprovider) ProvideEvery(tick time.Duration) {
// Run re-provides keys with 'tick' interval or when triggered
func (rp *Reprovider) Run(tick time.Duration) {
// dont reprovide immediately.
// may have just started the daemon and shutting it down immediately.
// probability( up another minute | uptime ) increases with uptime.
after := time.After(time.Minute)
var done doneFunc
for {
if tick == 0 {
after = make(chan time.Time)
}
select {
case <-rp.ctx.Done():
return
......@@ -98,7 +102,7 @@ func (rp *Reprovider) Reprovide() error {
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 {
progressCtx, done := context.WithCancel(ctx)
......
......@@ -4,8 +4,9 @@ test_description="Test reprovider"
. lib/test-lib.sh
NUM_NODES=6
init_strategy() {
NUM_NODES=6
test_expect_success 'init iptb' '
iptb init -f -n $NUM_NODES --bootstrap=none --port=0
'
......@@ -19,7 +20,7 @@ init_strategy() {
ipfsi 0 config Reprovider.Strategy '$1'
'
startup_cluster 6 --debug
startup_cluster ${NUM_NODES}
}
findprovs_empty() {
......@@ -124,4 +125,29 @@ test_expect_success 'stop peer 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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment